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