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
3 // found in the LICENSE file.
5 #ifndef APPS_UI_VIEWS_NATIVE_APP_WINDOW_VIEWS_H_
6 #define APPS_UI_VIEWS_NATIVE_APP_WINDOW_VIEWS_H_
8 #include "apps/size_constraints.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 "ui/gfx/rect.h"
13 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/widget/widget_delegate.h"
16 #include "ui/views/widget/widget_observer.h"
26 namespace extensions
{
41 class AppWindowFrameView
;
43 // A NativeAppWindow backed by a views::Widget. This class may be used alone
44 // as a stub or subclassed (for example, ChromeNativeAppWindowViews).
45 class NativeAppWindowViews
: public NativeAppWindow
,
46 public content::WebContentsObserver
,
47 public views::WidgetDelegateView
,
48 public views::WidgetObserver
{
50 NativeAppWindowViews();
51 virtual ~NativeAppWindowViews();
52 void Init(AppWindow
* app_window
,
53 const AppWindow::CreateParams
& create_params
);
55 views::Widget
* widget() { return widget_
; }
57 void set_window_for_testing(views::Widget
* window
) { widget_
= window
; }
58 void set_web_view_for_testing(views::WebView
* view
) { web_view_
= view
; }
61 AppWindow
* app_window() { return app_window_
; }
62 const AppWindow
* app_window() const { return app_window_
; }
64 const views::Widget
* widget() const { return widget_
; }
66 views::WebView
* web_view() { return web_view_
; }
68 // Initializes |widget_| for |app_window|.
69 virtual void InitializeWindow(AppWindow
* app_window
,
70 const AppWindow::CreateParams
& create_params
);
72 // ui::BaseWindow implementation.
73 virtual bool IsActive() const OVERRIDE
;
74 virtual bool IsMaximized() const OVERRIDE
;
75 virtual bool IsMinimized() const OVERRIDE
;
76 virtual bool IsFullscreen() const OVERRIDE
;
77 virtual gfx::NativeWindow
GetNativeWindow() OVERRIDE
;
78 virtual gfx::Rect
GetRestoredBounds() const OVERRIDE
;
79 virtual ui::WindowShowState
GetRestoredState() const OVERRIDE
;
80 virtual gfx::Rect
GetBounds() const OVERRIDE
;
81 virtual void Show() OVERRIDE
;
82 virtual void ShowInactive() OVERRIDE
;
83 virtual void Hide() OVERRIDE
;
84 virtual void Close() OVERRIDE
;
85 virtual void Activate() OVERRIDE
;
86 virtual void Deactivate() OVERRIDE
;
87 virtual void Maximize() OVERRIDE
;
88 virtual void Minimize() OVERRIDE
;
89 virtual void Restore() OVERRIDE
;
90 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
91 virtual void FlashFrame(bool flash
) OVERRIDE
;
92 virtual bool IsAlwaysOnTop() const OVERRIDE
;
93 virtual void SetAlwaysOnTop(bool always_on_top
) OVERRIDE
;
95 // WidgetDelegate implementation.
96 virtual void OnWidgetMove() OVERRIDE
;
97 virtual views::View
* GetInitiallyFocusedView() OVERRIDE
;
98 virtual bool CanResize() const OVERRIDE
;
99 virtual bool CanMaximize() const OVERRIDE
;
100 virtual base::string16
GetWindowTitle() const OVERRIDE
;
101 virtual bool ShouldShowWindowTitle() const OVERRIDE
;
102 virtual bool ShouldShowWindowIcon() const OVERRIDE
;
103 virtual void SaveWindowPlacement(const gfx::Rect
& bounds
,
104 ui::WindowShowState show_state
) OVERRIDE
;
105 virtual void DeleteDelegate() OVERRIDE
;
106 virtual views::Widget
* GetWidget() OVERRIDE
;
107 virtual const views::Widget
* GetWidget() const OVERRIDE
;
108 virtual views::View
* GetContentsView() OVERRIDE
;
109 virtual bool ShouldDescendIntoChildForEventHandling(
110 gfx::NativeView child
,
111 const gfx::Point
& location
) OVERRIDE
;
113 // WidgetObserver implementation.
114 virtual void OnWidgetVisibilityChanged(views::Widget
* widget
,
115 bool visible
) OVERRIDE
;
116 virtual void OnWidgetActivationChanged(views::Widget
* widget
,
117 bool active
) OVERRIDE
;
119 // WebContentsObserver implementation.
120 virtual void RenderViewCreated(
121 content::RenderViewHost
* render_view_host
) OVERRIDE
;
122 virtual void RenderViewHostChanged(
123 content::RenderViewHost
* old_host
,
124 content::RenderViewHost
* new_host
) OVERRIDE
;
126 // views::View implementation.
127 virtual void Layout() OVERRIDE
;
128 virtual void ViewHierarchyChanged(
129 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
130 virtual gfx::Size
GetMinimumSize() const OVERRIDE
;
131 virtual gfx::Size
GetMaximumSize() const OVERRIDE
;
132 virtual void OnFocus() OVERRIDE
;
134 // NativeAppWindow implementation.
135 virtual void SetFullscreen(int fullscreen_types
) OVERRIDE
;
136 virtual bool IsFullscreenOrPending() const OVERRIDE
;
137 virtual bool IsDetached() const OVERRIDE
;
138 virtual void UpdateWindowIcon() OVERRIDE
;
139 virtual void UpdateWindowTitle() OVERRIDE
;
140 virtual void UpdateBadgeIcon() OVERRIDE
;
141 virtual void UpdateDraggableRegions(
142 const std::vector
<extensions::DraggableRegion
>& regions
) OVERRIDE
;
143 virtual SkRegion
* GetDraggableRegion() OVERRIDE
;
144 virtual void UpdateShape(scoped_ptr
<SkRegion
> region
) OVERRIDE
;
145 virtual void HandleKeyboardEvent(
146 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
147 virtual bool IsFrameless() const OVERRIDE
;
148 virtual bool HasFrameColor() const OVERRIDE
;
149 virtual SkColor
ActiveFrameColor() const OVERRIDE
;
150 virtual SkColor
InactiveFrameColor() const OVERRIDE
;
151 virtual gfx::Insets
GetFrameInsets() const OVERRIDE
;
152 virtual void HideWithApp() OVERRIDE
;
153 virtual void ShowWithApp() OVERRIDE
;
154 virtual void UpdateShelfMenu() OVERRIDE
;
155 virtual gfx::Size
GetContentMinimumSize() const OVERRIDE
;
156 virtual gfx::Size
GetContentMaximumSize() const OVERRIDE
;
157 virtual void SetContentSizeConstraints(const gfx::Size
& min_size
,
158 const gfx::Size
& max_size
) OVERRIDE
;
160 // web_modal::WebContentsModalDialogHost implementation.
161 virtual gfx::NativeView
GetHostView() const OVERRIDE
;
162 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) OVERRIDE
;
163 virtual gfx::Size
GetMaximumDialogSize() OVERRIDE
;
164 virtual void AddObserver(
165 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
166 virtual void RemoveObserver(
167 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
170 // Informs modal dialogs that they need to update their positions.
171 void OnViewWasResized();
173 AppWindow
* app_window_
; // Not owned.
174 views::WebView
* web_view_
;
175 views::Widget
* widget_
;
177 scoped_ptr
<SkRegion
> draggable_region_
;
180 bool transparent_background_
;
182 apps::SizeConstraints size_constraints_
;
184 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_
;
186 ObserverList
<web_modal::ModalDialogHostObserver
> observer_list_
;
188 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews
);
193 #endif // APPS_UI_VIEWS_NATIVE_APP_WINDOW_VIEWS_H_