Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / apps / native_app_window_views.h
blob62d5d2ae060d5f64ece36357046050ade23fa974
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_
8 #include "apps/shell_window.h"
9 #include "apps/ui/native_app_window.h"
10 #include "base/observer_list.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/views/context_menu_controller.h"
16 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_delegate.h"
19 #include "ui/views/widget/widget_observer.h"
21 #if defined(OS_WIN)
22 #include "chrome/browser/shell_integration.h"
23 #endif
25 #if defined(USE_ASH)
26 namespace ash {
27 class ImmersiveFullscreenController;
29 #endif
31 class ExtensionKeybindingRegistryViews;
32 class Profile;
34 namespace apps {
35 class ShellWindowFrameView;
38 namespace content {
39 class RenderViewHost;
40 class WebContents;
43 namespace extensions {
44 class Extension;
47 namespace ui {
48 class MenuModel;
51 namespace views {
52 class MenuRunner;
53 class WebView;
56 class NativeAppWindowViews : public apps::NativeAppWindow,
57 public content::WebContentsObserver,
58 public views::ContextMenuController,
59 public views::WidgetDelegateView,
60 public views::WidgetObserver {
61 public:
62 NativeAppWindowViews();
63 virtual ~NativeAppWindowViews();
64 void Init(apps::ShellWindow* shell_window,
65 const apps::ShellWindow::CreateParams& create_params);
67 SkRegion* shape() { return shape_.get(); }
69 protected:
70 // Called before views::Widget::Init() to allow subclasses to customize
71 // the InitParams that would be passed.
72 virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params,
73 views::Widget* widget);
75 // ui::BaseWindow implementation that subclasses may override.
76 virtual void Show() OVERRIDE;
77 virtual void Activate() OVERRIDE;
79 Profile* profile() { return shell_window_->profile(); }
80 const extensions::Extension* extension() {
81 return shell_window_->extension();
84 private:
85 void InitializeDefaultWindow(
86 const apps::ShellWindow::CreateParams& create_params);
87 void InitializePanelWindow(
88 const apps::ShellWindow::CreateParams& create_params);
89 void OnViewWasResized();
91 bool ShouldUseChromeStyleFrame() const;
93 // Caller owns the returned object.
94 apps::ShellWindowFrameView* CreateShellWindowFrameView();
96 #if defined(OS_WIN)
97 void OnShortcutInfoLoaded(
98 const ShellIntegration::ShortcutInfo& shortcut_info);
99 HWND GetNativeAppWindowHWND() const;
100 #endif
102 // ui::BaseWindow implementation.
103 virtual bool IsActive() const OVERRIDE;
104 virtual bool IsMaximized() const OVERRIDE;
105 virtual bool IsMinimized() const OVERRIDE;
106 virtual bool IsFullscreen() const OVERRIDE;
107 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
108 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
109 virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
110 virtual gfx::Rect GetBounds() const OVERRIDE;
111 virtual void ShowInactive() OVERRIDE;
112 virtual void Hide() OVERRIDE;
113 virtual void Close() OVERRIDE;
114 virtual void Deactivate() OVERRIDE;
115 virtual void Maximize() OVERRIDE;
116 virtual void Minimize() OVERRIDE;
117 virtual void Restore() OVERRIDE;
118 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
119 virtual void FlashFrame(bool flash) OVERRIDE;
120 virtual bool IsAlwaysOnTop() const OVERRIDE;
121 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
123 // Overridden from views::ContextMenuController:
124 virtual void ShowContextMenuForView(views::View* source,
125 const gfx::Point& p,
126 ui::MenuSourceType source_type) OVERRIDE;
128 // WidgetDelegate implementation.
129 virtual void OnWidgetMove() OVERRIDE;
130 virtual views::View* GetInitiallyFocusedView() OVERRIDE;
131 virtual bool CanResize() const OVERRIDE;
132 virtual bool CanMaximize() const OVERRIDE;
133 virtual base::string16 GetWindowTitle() const OVERRIDE;
134 virtual bool ShouldShowWindowTitle() const OVERRIDE;
135 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
136 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
137 virtual bool ShouldShowWindowIcon() const OVERRIDE;
138 virtual void SaveWindowPlacement(const gfx::Rect& bounds,
139 ui::WindowShowState show_state) OVERRIDE;
140 virtual void DeleteDelegate() OVERRIDE;
141 virtual views::Widget* GetWidget() OVERRIDE;
142 virtual const views::Widget* GetWidget() const OVERRIDE;
143 virtual views::View* GetContentsView() OVERRIDE;
144 virtual views::NonClientFrameView* CreateNonClientFrameView(
145 views::Widget* widget) OVERRIDE;
146 virtual bool WidgetHasHitTestMask() const OVERRIDE;
147 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE;
148 virtual bool ShouldDescendIntoChildForEventHandling(
149 gfx::NativeView child,
150 const gfx::Point& location) OVERRIDE;
152 // WidgetObserver implementation.
153 virtual void OnWidgetVisibilityChanged(views::Widget* widget,
154 bool visible) OVERRIDE;
155 virtual void OnWidgetActivationChanged(views::Widget* widget,
156 bool active) OVERRIDE;
158 // WebContentsObserver implementation.
159 virtual void RenderViewCreated(
160 content::RenderViewHost* render_view_host) OVERRIDE;
161 virtual void RenderViewHostChanged(
162 content::RenderViewHost* old_host,
163 content::RenderViewHost* new_host) OVERRIDE;
165 // views::View implementation.
166 virtual void Layout() OVERRIDE;
167 virtual void ViewHierarchyChanged(
168 const ViewHierarchyChangedDetails& details) OVERRIDE;
169 virtual gfx::Size GetPreferredSize() OVERRIDE;
170 virtual gfx::Size GetMinimumSize() OVERRIDE;
171 virtual gfx::Size GetMaximumSize() OVERRIDE;
172 virtual void OnFocus() OVERRIDE;
173 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
175 // NativeAppWindow implementation.
176 virtual void SetFullscreen(int fullscreen_types) OVERRIDE;
177 virtual bool IsFullscreenOrPending() const OVERRIDE;
178 virtual bool IsDetached() const OVERRIDE;
179 virtual void UpdateWindowIcon() OVERRIDE;
180 virtual void UpdateWindowTitle() OVERRIDE;
181 virtual void UpdateDraggableRegions(
182 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
183 virtual SkRegion* GetDraggableRegion() OVERRIDE;
184 virtual void UpdateShape(scoped_ptr<SkRegion> region) OVERRIDE;
185 virtual void HandleKeyboardEvent(
186 const content::NativeWebKeyboardEvent& event) OVERRIDE;
187 virtual bool IsFrameless() const OVERRIDE;
188 virtual gfx::Insets GetFrameInsets() const OVERRIDE;
189 virtual void HideWithApp() OVERRIDE;
190 virtual void ShowWithApp() OVERRIDE;
191 virtual void UpdateWindowMinMaxSize() OVERRIDE;
193 // web_modal::WebContentsModalDialogHost implementation.
194 virtual gfx::NativeView GetHostView() const OVERRIDE;
195 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
196 virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
197 virtual void AddObserver(
198 web_modal::ModalDialogHostObserver* observer) OVERRIDE;
199 virtual void RemoveObserver(
200 web_modal::ModalDialogHostObserver* observer) OVERRIDE;
202 content::WebContents* web_contents() {
203 return shell_window_->web_contents();
206 apps::ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow.
207 views::WebView* web_view_;
208 views::Widget* window_;
209 bool is_fullscreen_;
211 // Custom shape of the window. If this is not set then the window has a
212 // default shape, usually rectangular.
213 scoped_ptr<SkRegion> shape_;
215 scoped_ptr<SkRegion> draggable_region_;
217 bool frameless_;
218 bool transparent_background_;
219 gfx::Size preferred_size_;
220 bool resizable_;
222 // The class that registers for keyboard shortcuts for extension commands.
223 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_;
225 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
227 #if defined(USE_ASH)
228 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In
229 // immersive fullscreen, the window header (title bar and window controls)
230 // slides onscreen as an overlay when the mouse is hovered at the top of the
231 // screen.
232 scoped_ptr<ash::ImmersiveFullscreenController>
233 immersive_fullscreen_controller_;
234 #endif
236 ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
238 base::WeakPtrFactory<NativeAppWindowViews> weak_ptr_factory_;
240 // Used to show the system menu.
241 scoped_ptr<views::MenuRunner> menu_runner_;
243 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews);
246 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_