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/app_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"
23 class ImmersiveFullscreenController
;
27 class ExtensionKeybindingRegistryViews
;
30 class AppWindowFrameView
;
39 namespace extensions
{
52 class NativeAppWindowViews
: public apps::NativeAppWindow
,
53 public content::WebContentsObserver
,
54 public views::ContextMenuController
,
55 public views::WidgetDelegateView
,
56 public views::WidgetObserver
{
58 NativeAppWindowViews();
59 virtual ~NativeAppWindowViews();
60 void Init(apps::AppWindow
* app_window
,
61 const apps::AppWindow::CreateParams
& create_params
);
63 SkRegion
* shape() { return shape_
.get(); }
66 // Called before views::Widget::Init() to allow subclasses to customize
67 // the InitParams that would be passed.
68 virtual void OnBeforeWidgetInit(views::Widget::InitParams
* init_params
,
69 views::Widget
* widget
);
71 // ui::BaseWindow implementation that subclasses may override.
72 virtual void Show() OVERRIDE
;
73 virtual void Activate() OVERRIDE
;
75 content::BrowserContext
* browser_context() {
76 return app_window_
->browser_context();
79 const extensions::Extension
* extension() { return app_window_
->extension(); }
80 const views::Widget
* window() const { return window_
; }
82 virtual void InitializeDefaultWindow(
83 const apps::AppWindow::CreateParams
& create_params
);
84 virtual void InitializePanelWindow(
85 const apps::AppWindow::CreateParams
& create_params
);
88 friend class ShapedAppWindowTargeterTest
;
89 FRIEND_TEST_ALL_PREFIXES(ShapedAppWindowTargeterTest
,
90 ResizeInsetsWithinBounds
);
92 void OnViewWasResized();
94 bool ShouldUseChromeStyleFrame() const;
96 // Installs an EasyResizeWindowTargeter on the containing window, which
97 // allows the window to be resized from within |kResizeInsideBoundsSize|
98 // pixels inside the window bounds.
99 void InstallEasyResizeTargeterOnContainer() const;
101 // Caller owns the returned object.
102 apps::AppWindowFrameView
* CreateAppWindowFrameView();
104 // 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
;
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
;
123 virtual void SetAlwaysOnTop(bool always_on_top
) OVERRIDE
;
125 // Overridden from views::ContextMenuController:
126 virtual void ShowContextMenuForView(views::View
* source
,
128 ui::MenuSourceType source_type
) OVERRIDE
;
130 // 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
;
138 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(
147 views::Widget
* widget
) OVERRIDE
;
148 virtual bool WidgetHasHitTestMask() const OVERRIDE
;
149 virtual void GetWidgetHitTestMask(gfx::Path
* mask
) const OVERRIDE
;
150 virtual bool ShouldDescendIntoChildForEventHandling(
151 gfx::NativeView child
,
152 const gfx::Point
& location
) OVERRIDE
;
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
;
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
;
167 // views::View implementation.
168 virtual void Layout() OVERRIDE
;
169 virtual void ViewHierarchyChanged(
170 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
171 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
;
177 // NativeAppWindow implementation.
178 virtual void SetFullscreen(int fullscreen_types
) OVERRIDE
;
179 virtual bool IsFullscreenOrPending() const OVERRIDE
;
180 virtual bool IsDetached() const OVERRIDE
;
181 virtual void UpdateWindowIcon() OVERRIDE
;
182 virtual void UpdateWindowTitle() OVERRIDE
;
183 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
;
188 virtual void HandleKeyboardEvent(
189 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
190 virtual bool IsFrameless() const OVERRIDE
;
191 virtual gfx::Insets
GetFrameInsets() const OVERRIDE
;
192 virtual void HideWithApp() OVERRIDE
;
193 virtual void ShowWithApp() OVERRIDE
;
194 virtual void UpdateWindowMinMaxSize() OVERRIDE
;
196 // web_modal::WebContentsModalDialogHost implementation.
197 virtual gfx::NativeView
GetHostView() const OVERRIDE
;
198 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) OVERRIDE
;
199 virtual gfx::Size
GetMaximumDialogSize() OVERRIDE
;
200 virtual void AddObserver(
201 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
202 virtual void RemoveObserver(
203 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
205 content::WebContents
* web_contents() { return app_window_
->web_contents(); }
207 apps::AppWindow
* app_window_
; // Not owned.
208 views::WebView
* web_view_
;
209 views::Widget
* window_
;
212 // Custom shape of the window. If this is not set then the window has a
213 // default shape, usually rectangular.
214 scoped_ptr
<SkRegion
> shape_
;
216 scoped_ptr
<SkRegion
> draggable_region_
;
219 bool transparent_background_
;
220 gfx::Size preferred_size_
;
223 // The class that registers for keyboard shortcuts for extension commands.
224 scoped_ptr
<ExtensionKeybindingRegistryViews
> extension_keybinding_registry_
;
226 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_
;
229 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In
230 // immersive fullscreen, the window header (title bar and window controls)
231 // slides onscreen as an overlay when the mouse is hovered at the top of the
233 scoped_ptr
<ash::ImmersiveFullscreenController
>
234 immersive_fullscreen_controller_
;
237 ObserverList
<web_modal::ModalDialogHostObserver
> observer_list_
;
239 base::WeakPtrFactory
<NativeAppWindowViews
> weak_ptr_factory_
;
241 // Used to show the system menu.
242 scoped_ptr
<views::MenuRunner
> menu_runner_
;
244 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews
);
247 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_