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"
22 #include "chrome/browser/shell_integration.h"
27 class ImmersiveFullscreenController
;
31 class ExtensionKeybindingRegistryViews
;
34 class AppWindowFrameView
;
43 namespace extensions
{
56 class NativeAppWindowViews
: public apps::NativeAppWindow
,
57 public content::WebContentsObserver
,
58 public views::ContextMenuController
,
59 public views::WidgetDelegateView
,
60 public views::WidgetObserver
{
62 NativeAppWindowViews();
63 virtual ~NativeAppWindowViews();
64 void Init(apps::AppWindow
* app_window
,
65 const apps::AppWindow::CreateParams
& create_params
);
67 SkRegion
* shape() { return shape_
.get(); }
70 // Called before views::Widget::Init() to allow subclasses to customize
71 // the InitParams that would be passed.
72 virtual void OnBeforeWidgetInit(views::Widget::InitParams
* init_params
,
73 views::Widget
* widget
);
75 // ui::BaseWindow implementation that subclasses may override.
76 virtual void Show() OVERRIDE
;
77 virtual void Activate() OVERRIDE
;
79 content::BrowserContext
* browser_context() {
80 return app_window_
->browser_context();
83 const extensions::Extension
* extension() { return app_window_
->extension(); }
86 friend class ShapedAppWindowTargeterTest
;
88 void InitializeDefaultWindow(
89 const apps::AppWindow::CreateParams
& create_params
);
90 void InitializePanelWindow(
91 const apps::AppWindow::CreateParams
& create_params
);
92 void OnViewWasResized();
94 bool ShouldUseChromeStyleFrame() const;
96 // Caller owns the returned object.
97 apps::AppWindowFrameView
* CreateAppWindowFrameView();
100 void OnShortcutInfoLoaded(
101 const ShellIntegration::ShortcutInfo
& shortcut_info
);
102 HWND
GetNativeAppWindowHWND() const;
105 // ui::BaseWindow implementation.
106 virtual bool IsActive() const OVERRIDE
;
107 virtual bool IsMaximized() const OVERRIDE
;
108 virtual bool IsMinimized() const OVERRIDE
;
109 virtual bool IsFullscreen() const OVERRIDE
;
110 virtual gfx::NativeWindow
GetNativeWindow() OVERRIDE
;
111 virtual gfx::Rect
GetRestoredBounds() const OVERRIDE
;
112 virtual ui::WindowShowState
GetRestoredState() const OVERRIDE
;
113 virtual gfx::Rect
GetBounds() const OVERRIDE
;
114 virtual void ShowInactive() OVERRIDE
;
115 virtual void Hide() OVERRIDE
;
116 virtual void Close() OVERRIDE
;
117 virtual void Deactivate() OVERRIDE
;
118 virtual void Maximize() OVERRIDE
;
119 virtual void Minimize() OVERRIDE
;
120 virtual void Restore() OVERRIDE
;
121 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
122 virtual void FlashFrame(bool flash
) OVERRIDE
;
123 virtual bool IsAlwaysOnTop() const OVERRIDE
;
124 virtual void SetAlwaysOnTop(bool always_on_top
) OVERRIDE
;
126 // Overridden from views::ContextMenuController:
127 virtual void ShowContextMenuForView(views::View
* source
,
129 ui::MenuSourceType source_type
) OVERRIDE
;
131 // WidgetDelegate implementation.
132 virtual void OnWidgetMove() OVERRIDE
;
133 virtual views::View
* GetInitiallyFocusedView() OVERRIDE
;
134 virtual bool CanResize() const OVERRIDE
;
135 virtual bool CanMaximize() const OVERRIDE
;
136 virtual base::string16
GetWindowTitle() const OVERRIDE
;
137 virtual bool ShouldShowWindowTitle() const OVERRIDE
;
138 virtual gfx::ImageSkia
GetWindowAppIcon() OVERRIDE
;
139 virtual gfx::ImageSkia
GetWindowIcon() OVERRIDE
;
140 virtual bool ShouldShowWindowIcon() const OVERRIDE
;
141 virtual void SaveWindowPlacement(const gfx::Rect
& bounds
,
142 ui::WindowShowState show_state
) OVERRIDE
;
143 virtual void DeleteDelegate() OVERRIDE
;
144 virtual views::Widget
* GetWidget() OVERRIDE
;
145 virtual const views::Widget
* GetWidget() const OVERRIDE
;
146 virtual views::View
* GetContentsView() OVERRIDE
;
147 virtual views::NonClientFrameView
* CreateNonClientFrameView(
148 views::Widget
* widget
) OVERRIDE
;
149 virtual bool WidgetHasHitTestMask() const OVERRIDE
;
150 virtual void GetWidgetHitTestMask(gfx::Path
* mask
) const OVERRIDE
;
151 virtual bool ShouldDescendIntoChildForEventHandling(
152 gfx::NativeView child
,
153 const gfx::Point
& location
) OVERRIDE
;
155 // WidgetObserver implementation.
156 virtual void OnWidgetVisibilityChanged(views::Widget
* widget
,
157 bool visible
) OVERRIDE
;
158 virtual void OnWidgetActivationChanged(views::Widget
* widget
,
159 bool active
) OVERRIDE
;
161 // WebContentsObserver implementation.
162 virtual void RenderViewCreated(
163 content::RenderViewHost
* render_view_host
) OVERRIDE
;
164 virtual void RenderViewHostChanged(
165 content::RenderViewHost
* old_host
,
166 content::RenderViewHost
* new_host
) OVERRIDE
;
168 // views::View implementation.
169 virtual void Layout() OVERRIDE
;
170 virtual void ViewHierarchyChanged(
171 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
172 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
173 virtual gfx::Size
GetMinimumSize() OVERRIDE
;
174 virtual gfx::Size
GetMaximumSize() OVERRIDE
;
175 virtual void OnFocus() OVERRIDE
;
176 virtual bool AcceleratorPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
178 // NativeAppWindow implementation.
179 virtual void SetFullscreen(int fullscreen_types
) OVERRIDE
;
180 virtual bool IsFullscreenOrPending() const OVERRIDE
;
181 virtual bool IsDetached() const OVERRIDE
;
182 virtual void UpdateWindowIcon() OVERRIDE
;
183 virtual void UpdateWindowTitle() OVERRIDE
;
184 virtual void UpdateBadgeIcon() OVERRIDE
;
185 virtual void UpdateDraggableRegions(
186 const std::vector
<extensions::DraggableRegion
>& regions
) OVERRIDE
;
187 virtual SkRegion
* GetDraggableRegion() OVERRIDE
;
188 virtual void UpdateShape(scoped_ptr
<SkRegion
> region
) OVERRIDE
;
189 virtual void HandleKeyboardEvent(
190 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
191 virtual bool IsFrameless() const OVERRIDE
;
192 virtual gfx::Insets
GetFrameInsets() const OVERRIDE
;
193 virtual void HideWithApp() OVERRIDE
;
194 virtual void ShowWithApp() OVERRIDE
;
195 virtual void UpdateWindowMinMaxSize() OVERRIDE
;
197 // web_modal::WebContentsModalDialogHost implementation.
198 virtual gfx::NativeView
GetHostView() const OVERRIDE
;
199 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) OVERRIDE
;
200 virtual gfx::Size
GetMaximumDialogSize() OVERRIDE
;
201 virtual void AddObserver(
202 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
203 virtual void RemoveObserver(
204 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
206 content::WebContents
* web_contents() { return app_window_
->web_contents(); }
208 apps::AppWindow
* app_window_
; // Not owned.
209 views::WebView
* web_view_
;
210 views::Widget
* window_
;
213 // Custom shape of the window. If this is not set then the window has a
214 // default shape, usually rectangular.
215 scoped_ptr
<SkRegion
> shape_
;
217 scoped_ptr
<SkRegion
> draggable_region_
;
220 bool transparent_background_
;
221 gfx::Size preferred_size_
;
224 // The class that registers for keyboard shortcuts for extension commands.
225 scoped_ptr
<ExtensionKeybindingRegistryViews
> extension_keybinding_registry_
;
227 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_
;
230 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In
231 // immersive fullscreen, the window header (title bar and window controls)
232 // slides onscreen as an overlay when the mouse is hovered at the top of the
234 scoped_ptr
<ash::ImmersiveFullscreenController
>
235 immersive_fullscreen_controller_
;
238 ObserverList
<web_modal::ModalDialogHostObserver
> observer_list_
;
240 base::WeakPtrFactory
<NativeAppWindowViews
> weak_ptr_factory_
;
242 // Used to show the system menu.
243 scoped_ptr
<views::MenuRunner
> menu_runner_
;
245 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews
);
248 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_