OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ |
James Cook
2014/02/20 22:41:31
I intentionally didn't rename this file (yet) so t
| |
6 #define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ |
7 | 7 |
8 #include "apps/app_window.h" | 8 #include "apps/ui/views/native_app_window_views.h" |
9 #include "apps/ui/native_app_window.h" | 9 #include "base/memory/scoped_ptr.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" | 10 #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" | |
20 | 11 |
21 #if defined(USE_ASH) | 12 #if defined(USE_ASH) |
22 namespace ash { | 13 namespace ash { |
23 class ImmersiveFullscreenController; | 14 class ImmersiveFullscreenController; |
24 } | 15 } |
25 #endif | 16 #endif |
26 | 17 |
27 class ExtensionKeybindingRegistryViews; | 18 class ExtensionKeybindingRegistryViews; |
28 | 19 |
29 namespace apps { | 20 namespace views { |
30 class AppWindowFrameView; | 21 class MenuRunner; |
31 } | 22 } |
32 | 23 |
33 namespace content { | 24 class ChromeNativeAppWindowViews : public NativeAppWindowViews, |
34 class BrowserContext; | 25 public views::ContextMenuController { |
35 class RenderViewHost; | |
36 class WebContents; | |
37 } | |
38 | |
39 namespace extensions { | |
40 class Extension; | |
41 } | |
42 | |
43 namespace ui { | |
44 class MenuModel; | |
45 } | |
46 | |
47 namespace views { | |
48 class MenuRunner; | |
49 class WebView; | |
50 } | |
51 | |
52 class NativeAppWindowViews : public apps::NativeAppWindow, | |
53 public content::WebContentsObserver, | |
54 public views::ContextMenuController, | |
55 public views::WidgetDelegateView, | |
56 public views::WidgetObserver { | |
57 public: | 26 public: |
58 NativeAppWindowViews(); | 27 ChromeNativeAppWindowViews(); |
59 virtual ~NativeAppWindowViews(); | 28 virtual ~ChromeNativeAppWindowViews(); |
60 void Init(apps::AppWindow* app_window, | |
61 const apps::AppWindow::CreateParams& create_params); | |
62 | |
63 SkRegion* shape() { return shape_.get(); } | |
64 | 29 |
65 protected: | 30 protected: |
66 // Called before views::Widget::Init() to allow subclasses to customize | 31 // Called before views::Widget::Init() to allow subclasses to customize |
67 // the InitParams that would be passed. | 32 // the InitParams that would be passed. |
68 virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params, | 33 virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params, |
69 views::Widget* widget); | 34 views::Widget* widget); |
70 | 35 |
71 // ui::BaseWindow implementation that subclasses may override. | |
72 virtual void Show() OVERRIDE; | |
73 virtual void Activate() OVERRIDE; | |
74 | |
75 content::BrowserContext* browser_context() { | |
76 return app_window_->browser_context(); | |
77 } | |
78 | |
79 const extensions::Extension* extension() { return app_window_->extension(); } | |
80 const views::Widget* window() const { return window_; } | |
81 | |
82 virtual void InitializeDefaultWindow( | 36 virtual void InitializeDefaultWindow( |
83 const apps::AppWindow::CreateParams& create_params); | 37 const apps::AppWindow::CreateParams& create_params); |
84 virtual void InitializePanelWindow( | 38 virtual void InitializePanelWindow( |
85 const apps::AppWindow::CreateParams& create_params); | 39 const apps::AppWindow::CreateParams& create_params); |
86 | 40 |
87 private: | 41 // ui::BaseWindow implementation. |
88 friend class ShapedAppWindowTargeterTest; | 42 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; |
43 virtual bool IsAlwaysOnTop() const OVERRIDE; | |
89 | 44 |
90 void OnViewWasResized(); | 45 // views::ContextMenuController implementation. |
91 | |
92 bool ShouldUseChromeStyleFrame() const; | |
93 | |
94 // Caller owns the returned object. | |
95 apps::AppWindowFrameView* CreateAppWindowFrameView(); | |
96 | |
97 // ui::BaseWindow implementation. | |
98 virtual bool IsActive() const OVERRIDE; | |
99 virtual bool IsMaximized() const OVERRIDE; | |
100 virtual bool IsMinimized() const OVERRIDE; | |
101 virtual bool IsFullscreen() const OVERRIDE; | |
102 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; | |
103 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; | |
104 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; | |
105 virtual gfx::Rect GetBounds() const OVERRIDE; | |
106 virtual void ShowInactive() OVERRIDE; | |
107 virtual void Hide() OVERRIDE; | |
108 virtual void Close() OVERRIDE; | |
109 virtual void Deactivate() OVERRIDE; | |
110 virtual void Maximize() OVERRIDE; | |
111 virtual void Minimize() OVERRIDE; | |
112 virtual void Restore() OVERRIDE; | |
113 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | |
114 virtual void FlashFrame(bool flash) OVERRIDE; | |
115 virtual bool IsAlwaysOnTop() const OVERRIDE; | |
116 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; | |
117 | |
118 // Overridden from views::ContextMenuController: | |
119 virtual void ShowContextMenuForView(views::View* source, | 46 virtual void ShowContextMenuForView(views::View* source, |
120 const gfx::Point& p, | 47 const gfx::Point& p, |
121 ui::MenuSourceType source_type) OVERRIDE; | 48 ui::MenuSourceType source_type) OVERRIDE; |
122 | 49 |
123 // WidgetDelegate implementation. | 50 // WidgetDelegate implementation. |
124 virtual void OnWidgetMove() OVERRIDE; | |
125 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | |
126 virtual bool CanResize() const OVERRIDE; | |
127 virtual bool CanMaximize() const OVERRIDE; | |
128 virtual base::string16 GetWindowTitle() const OVERRIDE; | |
129 virtual bool ShouldShowWindowTitle() const OVERRIDE; | |
130 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; | 51 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; |
131 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; | 52 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; |
132 virtual bool ShouldShowWindowIcon() const OVERRIDE; | |
133 virtual void SaveWindowPlacement(const gfx::Rect& bounds, | |
134 ui::WindowShowState show_state) OVERRIDE; | |
135 virtual void DeleteDelegate() OVERRIDE; | |
136 virtual views::Widget* GetWidget() OVERRIDE; | |
137 virtual const views::Widget* GetWidget() const OVERRIDE; | |
138 virtual views::View* GetContentsView() OVERRIDE; | |
139 virtual views::NonClientFrameView* CreateNonClientFrameView( | 53 virtual views::NonClientFrameView* CreateNonClientFrameView( |
140 views::Widget* widget) OVERRIDE; | 54 views::Widget* widget) OVERRIDE; |
141 virtual bool WidgetHasHitTestMask() const OVERRIDE; | |
142 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE; | |
143 virtual bool ShouldDescendIntoChildForEventHandling( | |
144 gfx::NativeView child, | |
145 const gfx::Point& location) OVERRIDE; | |
146 | |
147 // WidgetObserver implementation. | |
148 virtual void OnWidgetVisibilityChanged(views::Widget* widget, | |
149 bool visible) OVERRIDE; | |
150 virtual void OnWidgetActivationChanged(views::Widget* widget, | |
151 bool active) OVERRIDE; | |
152 | |
153 // WebContentsObserver implementation. | |
154 virtual void RenderViewCreated( | |
155 content::RenderViewHost* render_view_host) OVERRIDE; | |
156 virtual void RenderViewHostChanged( | |
157 content::RenderViewHost* old_host, | |
158 content::RenderViewHost* new_host) OVERRIDE; | |
159 | 55 |
160 // views::View implementation. | 56 // views::View implementation. |
161 virtual void Layout() OVERRIDE; | |
162 virtual void ViewHierarchyChanged( | |
163 const ViewHierarchyChangedDetails& details) OVERRIDE; | |
164 virtual gfx::Size GetPreferredSize() OVERRIDE; | 57 virtual gfx::Size GetPreferredSize() OVERRIDE; |
165 virtual gfx::Size GetMinimumSize() OVERRIDE; | |
166 virtual gfx::Size GetMaximumSize() OVERRIDE; | |
167 virtual void OnFocus() OVERRIDE; | |
168 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 58 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
169 | 59 |
170 // NativeAppWindow implementation. | 60 // NativeAppWindow implementation. |
171 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; | 61 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; |
172 virtual bool IsFullscreenOrPending() const OVERRIDE; | 62 virtual bool IsFullscreenOrPending() const OVERRIDE; |
173 virtual bool IsDetached() const OVERRIDE; | 63 virtual bool IsDetached() const OVERRIDE; |
174 virtual void UpdateWindowIcon() OVERRIDE; | |
175 virtual void UpdateWindowTitle() OVERRIDE; | |
176 virtual void UpdateBadgeIcon() OVERRIDE; | 64 virtual void UpdateBadgeIcon() OVERRIDE; |
177 virtual void UpdateDraggableRegions( | |
178 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; | |
179 virtual SkRegion* GetDraggableRegion() OVERRIDE; | |
180 virtual void UpdateShape(scoped_ptr<SkRegion> region) OVERRIDE; | |
181 virtual void HandleKeyboardEvent( | |
182 const content::NativeWebKeyboardEvent& event) OVERRIDE; | |
183 virtual bool IsFrameless() const OVERRIDE; | |
184 virtual gfx::Insets GetFrameInsets() const OVERRIDE; | |
185 virtual void HideWithApp() OVERRIDE; | |
186 virtual void ShowWithApp() OVERRIDE; | |
187 virtual void UpdateWindowMinMaxSize() OVERRIDE; | |
188 | 65 |
189 // web_modal::WebContentsModalDialogHost implementation. | 66 // NativeAppWindowViews implementation. |
190 virtual gfx::NativeView GetHostView() const OVERRIDE; | 67 virtual void InitializeWindow( |
191 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE; | 68 apps::AppWindow* app_window, |
192 virtual gfx::Size GetMaximumDialogSize() OVERRIDE; | 69 const apps::AppWindow::CreateParams& create_params) OVERRIDE; |
193 virtual void AddObserver( | |
194 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
195 virtual void RemoveObserver( | |
196 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
197 | 70 |
198 content::WebContents* web_contents() { return app_window_->web_contents(); } | 71 private: |
72 bool ShouldUseChromeStyleFrame() const; | |
benwells
2014/02/21 07:12:39
Note: I'm about to commit a change which changes t
| |
199 | 73 |
200 apps::AppWindow* app_window_; // Not owned. | 74 // Caller owns the returned object. |
201 views::WebView* web_view_; | 75 apps::AppWindowFrameView* CreateAppWindowFrameView(); |
202 views::Widget* window_; | 76 |
77 // True if the window is fullscreen or fullscreen is pending. | |
203 bool is_fullscreen_; | 78 bool is_fullscreen_; |
204 | 79 |
205 // Custom shape of the window. If this is not set then the window has a | 80 // Only panel windows have an explicit preferred size. |
206 // default shape, usually rectangular. | |
207 scoped_ptr<SkRegion> shape_; | |
208 | |
209 scoped_ptr<SkRegion> draggable_region_; | |
210 | |
211 bool frameless_; | |
212 bool transparent_background_; | |
213 gfx::Size preferred_size_; | 81 gfx::Size preferred_size_; |
214 bool resizable_; | |
215 | 82 |
216 // The class that registers for keyboard shortcuts for extension commands. | 83 // The class that registers for keyboard shortcuts for extension commands. |
217 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; | 84 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; |
218 | 85 |
219 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | |
220 | |
221 #if defined(USE_ASH) | 86 #if defined(USE_ASH) |
222 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In | 87 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In |
223 // immersive fullscreen, the window header (title bar and window controls) | 88 // immersive fullscreen, the window header (title bar and window controls) |
224 // slides onscreen as an overlay when the mouse is hovered at the top of the | 89 // slides onscreen as an overlay when the mouse is hovered at the top of the |
225 // screen. | 90 // screen. |
226 scoped_ptr<ash::ImmersiveFullscreenController> | 91 scoped_ptr<ash::ImmersiveFullscreenController> |
227 immersive_fullscreen_controller_; | 92 immersive_fullscreen_controller_; |
228 #endif | 93 #endif // defined(USE_ASH) |
229 | |
230 ObserverList<web_modal::ModalDialogHostObserver> observer_list_; | |
231 | |
232 base::WeakPtrFactory<NativeAppWindowViews> weak_ptr_factory_; | |
233 | 94 |
234 // Used to show the system menu. | 95 // Used to show the system menu. |
235 scoped_ptr<views::MenuRunner> menu_runner_; | 96 scoped_ptr<views::MenuRunner> menu_runner_; |
236 | 97 |
237 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews); | 98 DISALLOW_COPY_AND_ASSIGN(ChromeNativeAppWindowViews); |
238 }; | 99 }; |
239 | 100 |
240 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 101 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ |
OLD | NEW |