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