OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ |
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" | 11 |
17 #include "ui/views/widget/widget.h" | 12 class ExtensionKeybindingRegistryViews; |
18 #include "ui/views/widget/widget_delegate.h" | |
19 #include "ui/views/widget/widget_observer.h" | |
20 | 13 |
21 #if defined(USE_ASH) | 14 #if defined(USE_ASH) |
22 namespace ash { | 15 namespace ash { |
23 class ImmersiveFullscreenController; | 16 class ImmersiveFullscreenController; |
24 } | 17 } |
25 #endif | 18 #endif |
26 | 19 |
27 class ExtensionKeybindingRegistryViews; | 20 namespace views { |
28 | 21 class MenuRunner; |
29 namespace apps { | |
30 class AppWindowFrameView; | |
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. | 36 // Initializes a normal, non-panel app 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_; } | |
81 | |
82 virtual void InitializeDefaultWindow( | 37 virtual void InitializeDefaultWindow( |
83 const apps::AppWindow::CreateParams& create_params); | 38 const apps::AppWindow::CreateParams& create_params); |
| 39 |
| 40 // Initializes a panel window. |
84 virtual void InitializePanelWindow( | 41 virtual void InitializePanelWindow( |
85 const apps::AppWindow::CreateParams& create_params); | 42 const apps::AppWindow::CreateParams& create_params); |
86 | 43 |
87 private: | 44 private: |
88 friend class ShapedAppWindowTargeterTest; | 45 // ui::BaseWindow overrides: |
| 46 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; |
| 47 virtual bool IsAlwaysOnTop() const OVERRIDE; |
89 | 48 |
90 void OnViewWasResized(); | 49 // views::ContextMenuController overrides: |
| 50 virtual void ShowContextMenuForView(views::View* source, |
| 51 const gfx::Point& p, |
| 52 ui::MenuSourceType source_type) OVERRIDE; |
| 53 |
| 54 // views::WidgetDelegate overrides: |
| 55 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; |
| 56 virtual views::NonClientFrameView* CreateNonClientFrameView( |
| 57 views::Widget* widget) OVERRIDE; |
| 58 |
| 59 // views::View overrides: |
| 60 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 61 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 62 |
| 63 // NativeAppWindow overrides: |
| 64 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; |
| 65 virtual bool IsFullscreenOrPending() const OVERRIDE; |
| 66 virtual bool IsDetached() const OVERRIDE; |
| 67 virtual void UpdateBadgeIcon() OVERRIDE; |
| 68 |
| 69 // NativeAppWindowViews overrides: |
| 70 void InitializeWindow(apps::AppWindow* app_window, |
| 71 const apps::AppWindow::CreateParams& create_params) |
| 72 OVERRIDE; |
91 | 73 |
92 bool ShouldUseChromeStyleFrame() const; | 74 bool ShouldUseChromeStyleFrame() const; |
93 | 75 |
94 // Caller owns the returned object. | 76 // Caller owns the returned object. |
95 apps::AppWindowFrameView* CreateAppWindowFrameView(); | 77 apps::AppWindowFrameView* CreateAppWindowFrameView(); |
96 | 78 |
97 // ui::BaseWindow implementation. | 79 // True if the window is fullscreen or fullscreen is pending. |
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, | |
120 const gfx::Point& p, | |
121 ui::MenuSourceType source_type) OVERRIDE; | |
122 | |
123 // 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; | |
131 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( | |
140 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 | |
160 // views::View implementation. | |
161 virtual void Layout() OVERRIDE; | |
162 virtual void ViewHierarchyChanged( | |
163 const ViewHierarchyChangedDetails& details) OVERRIDE; | |
164 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; | |
169 | |
170 // NativeAppWindow implementation. | |
171 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; | |
172 virtual bool IsFullscreenOrPending() const OVERRIDE; | |
173 virtual bool IsDetached() const OVERRIDE; | |
174 virtual void UpdateWindowIcon() OVERRIDE; | |
175 virtual void UpdateWindowTitle() OVERRIDE; | |
176 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 | |
189 // web_modal::WebContentsModalDialogHost implementation. | |
190 virtual gfx::NativeView GetHostView() const OVERRIDE; | |
191 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE; | |
192 virtual gfx::Size GetMaximumDialogSize() OVERRIDE; | |
193 virtual void AddObserver( | |
194 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
195 virtual void RemoveObserver( | |
196 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
197 | |
198 content::WebContents* web_contents() { return app_window_->web_contents(); } | |
199 | |
200 apps::AppWindow* app_window_; // Not owned. | |
201 views::WebView* web_view_; | |
202 views::Widget* window_; | |
203 bool is_fullscreen_; | 80 bool is_fullscreen_; |
204 | 81 |
205 // Custom shape of the window. If this is not set then the window has a | |
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_; | |
214 bool resizable_; | |
215 | |
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_; | |
220 | |
221 #if defined(USE_ASH) | 82 #if defined(USE_ASH) |
222 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In | 83 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In |
223 // immersive fullscreen, the window header (title bar and window controls) | 84 // 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 | 85 // slides onscreen as an overlay when the mouse is hovered at the top of the |
225 // screen. | 86 // screen. |
226 scoped_ptr<ash::ImmersiveFullscreenController> | 87 scoped_ptr<ash::ImmersiveFullscreenController> |
227 immersive_fullscreen_controller_; | 88 immersive_fullscreen_controller_; |
228 #endif | 89 #endif // defined(USE_ASH) |
229 | 90 |
230 ObserverList<web_modal::ModalDialogHostObserver> observer_list_; | 91 // Only panel windows have an explicit preferred size. |
| 92 gfx::Size preferred_size_; |
231 | 93 |
232 base::WeakPtrFactory<NativeAppWindowViews> weak_ptr_factory_; | 94 // The class that registers for keyboard shortcuts for extension commands. |
| 95 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; |
233 | 96 |
234 // Used to show the system menu. | 97 // Used to show the system menu. |
235 scoped_ptr<views::MenuRunner> menu_runner_; | 98 scoped_ptr<views::MenuRunner> menu_runner_; |
236 | 99 |
237 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews); | 100 DISALLOW_COPY_AND_ASSIGN(ChromeNativeAppWindowViews); |
238 }; | 101 }; |
239 | 102 |
240 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 103 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ |
OLD | NEW |