OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef APPS_UI_VIEWS_NATIVE_APP_WINDOW_VIEWS_H_ | |
6 #define APPS_UI_VIEWS_NATIVE_APP_WINDOW_VIEWS_H_ | |
7 | |
8 #include "base/observer_list.h" | |
9 #include "content/public/browser/web_contents_observer.h" | |
10 #include "extensions/browser/app_window/app_window.h" | |
11 #include "extensions/browser/app_window/native_app_window.h" | |
12 #include "extensions/browser/app_window/size_constraints.h" | |
13 #include "ui/gfx/rect.h" | |
14 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | |
15 #include "ui/views/widget/widget.h" | |
16 #include "ui/views/widget/widget_delegate.h" | |
17 #include "ui/views/widget/widget_observer.h" | |
18 | |
19 class SkRegion; | |
20 | |
21 namespace content { | |
22 class BrowserContext; | |
23 class RenderViewHost; | |
24 class WebContents; | |
25 } | |
26 | |
27 namespace extensions { | |
28 class Extension; | |
29 } | |
30 | |
31 namespace ui { | |
32 class MenuModel; | |
33 } | |
34 | |
35 namespace views { | |
36 class MenuRunner; | |
37 class WebView; | |
38 } | |
39 | |
40 namespace apps { | |
41 | |
42 class AppWindowFrameView; | |
43 | |
44 // A NativeAppWindow backed by a views::Widget. This class may be used alone | |
45 // as a stub or subclassed (for example, ChromeNativeAppWindowViews). | |
46 class NativeAppWindowViews : public extensions::NativeAppWindow, | |
47 public content::WebContentsObserver, | |
48 public views::WidgetDelegateView, | |
49 public views::WidgetObserver { | |
50 public: | |
51 NativeAppWindowViews(); | |
52 virtual ~NativeAppWindowViews(); | |
53 void Init(extensions::AppWindow* app_window, | |
54 const extensions::AppWindow::CreateParams& create_params); | |
55 | |
56 // Signal that CanHaveTransparentBackground has changed. | |
57 void OnCanHaveAlphaEnabledChanged(); | |
58 | |
59 views::Widget* widget() { return widget_; } | |
60 | |
61 void set_window_for_testing(views::Widget* window) { widget_ = window; } | |
62 void set_web_view_for_testing(views::WebView* view) { web_view_ = view; } | |
63 | |
64 protected: | |
65 extensions::AppWindow* app_window() { return app_window_; } | |
66 const extensions::AppWindow* app_window() const { return app_window_; } | |
67 | |
68 const views::Widget* widget() const { return widget_; } | |
69 | |
70 views::WebView* web_view() { return web_view_; } | |
71 | |
72 // Initializes |widget_| for |app_window|. | |
73 virtual void InitializeWindow( | |
74 extensions::AppWindow* app_window, | |
75 const extensions::AppWindow::CreateParams& create_params); | |
76 | |
77 // ui::BaseWindow implementation. | |
78 virtual bool IsActive() const OVERRIDE; | |
79 virtual bool IsMaximized() const OVERRIDE; | |
80 virtual bool IsMinimized() const OVERRIDE; | |
81 virtual bool IsFullscreen() const OVERRIDE; | |
82 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; | |
83 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; | |
84 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; | |
85 virtual gfx::Rect GetBounds() const OVERRIDE; | |
86 virtual void Show() OVERRIDE; | |
87 virtual void ShowInactive() OVERRIDE; | |
88 virtual void Hide() OVERRIDE; | |
89 virtual void Close() OVERRIDE; | |
90 virtual void Activate() OVERRIDE; | |
91 virtual void Deactivate() OVERRIDE; | |
92 virtual void Maximize() OVERRIDE; | |
93 virtual void Minimize() OVERRIDE; | |
94 virtual void Restore() OVERRIDE; | |
95 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | |
96 virtual void FlashFrame(bool flash) OVERRIDE; | |
97 virtual bool IsAlwaysOnTop() const OVERRIDE; | |
98 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; | |
99 | |
100 // WidgetDelegate implementation. | |
101 virtual void OnWidgetMove() OVERRIDE; | |
102 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | |
103 virtual bool CanResize() const OVERRIDE; | |
104 virtual bool CanMaximize() const OVERRIDE; | |
105 virtual base::string16 GetWindowTitle() const OVERRIDE; | |
106 virtual bool ShouldShowWindowTitle() const OVERRIDE; | |
107 virtual bool ShouldShowWindowIcon() const OVERRIDE; | |
108 virtual void SaveWindowPlacement(const gfx::Rect& bounds, | |
109 ui::WindowShowState show_state) OVERRIDE; | |
110 virtual void DeleteDelegate() OVERRIDE; | |
111 virtual views::Widget* GetWidget() OVERRIDE; | |
112 virtual const views::Widget* GetWidget() const OVERRIDE; | |
113 virtual views::View* GetContentsView() OVERRIDE; | |
114 virtual bool ShouldDescendIntoChildForEventHandling( | |
115 gfx::NativeView child, | |
116 const gfx::Point& location) OVERRIDE; | |
117 | |
118 // WidgetObserver implementation. | |
119 virtual void OnWidgetVisibilityChanged(views::Widget* widget, | |
120 bool visible) OVERRIDE; | |
121 virtual void OnWidgetActivationChanged(views::Widget* widget, | |
122 bool active) OVERRIDE; | |
123 | |
124 // WebContentsObserver implementation. | |
125 virtual void RenderViewCreated( | |
126 content::RenderViewHost* render_view_host) OVERRIDE; | |
127 virtual void RenderViewHostChanged( | |
128 content::RenderViewHost* old_host, | |
129 content::RenderViewHost* new_host) OVERRIDE; | |
130 | |
131 // views::View implementation. | |
132 virtual void Layout() OVERRIDE; | |
133 virtual void ViewHierarchyChanged( | |
134 const ViewHierarchyChangedDetails& details) OVERRIDE; | |
135 virtual gfx::Size GetMinimumSize() const OVERRIDE; | |
136 virtual gfx::Size GetMaximumSize() const OVERRIDE; | |
137 virtual void OnFocus() OVERRIDE; | |
138 | |
139 // NativeAppWindow implementation. | |
140 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; | |
141 virtual bool IsFullscreenOrPending() const OVERRIDE; | |
142 virtual void UpdateWindowIcon() OVERRIDE; | |
143 virtual void UpdateWindowTitle() OVERRIDE; | |
144 virtual void UpdateBadgeIcon() OVERRIDE; | |
145 virtual void UpdateDraggableRegions( | |
146 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; | |
147 virtual SkRegion* GetDraggableRegion() OVERRIDE; | |
148 virtual void UpdateShape(scoped_ptr<SkRegion> region) OVERRIDE; | |
149 virtual void HandleKeyboardEvent( | |
150 const content::NativeWebKeyboardEvent& event) OVERRIDE; | |
151 virtual bool IsFrameless() const OVERRIDE; | |
152 virtual bool HasFrameColor() const OVERRIDE; | |
153 virtual SkColor ActiveFrameColor() const OVERRIDE; | |
154 virtual SkColor InactiveFrameColor() const OVERRIDE; | |
155 virtual gfx::Insets GetFrameInsets() const OVERRIDE; | |
156 virtual void HideWithApp() OVERRIDE; | |
157 virtual void ShowWithApp() OVERRIDE; | |
158 virtual void UpdateShelfMenu() OVERRIDE; | |
159 virtual gfx::Size GetContentMinimumSize() const OVERRIDE; | |
160 virtual gfx::Size GetContentMaximumSize() const OVERRIDE; | |
161 virtual void SetContentSizeConstraints(const gfx::Size& min_size, | |
162 const gfx::Size& max_size) OVERRIDE; | |
163 virtual bool CanHaveAlphaEnabled() const OVERRIDE; | |
164 virtual void SetVisibleOnAllWorkspaces(bool always_visible) OVERRIDE; | |
165 | |
166 // web_modal::WebContentsModalDialogHost implementation. | |
167 virtual gfx::NativeView GetHostView() const OVERRIDE; | |
168 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE; | |
169 virtual gfx::Size GetMaximumDialogSize() OVERRIDE; | |
170 virtual void AddObserver( | |
171 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
172 virtual void RemoveObserver( | |
173 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
174 | |
175 private: | |
176 // Informs modal dialogs that they need to update their positions. | |
177 void OnViewWasResized(); | |
178 | |
179 extensions::AppWindow* app_window_; // Not owned. | |
180 views::WebView* web_view_; | |
181 views::Widget* widget_; | |
182 | |
183 scoped_ptr<SkRegion> draggable_region_; | |
184 | |
185 bool frameless_; | |
186 bool resizable_; | |
187 extensions::SizeConstraints size_constraints_; | |
188 | |
189 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | |
190 | |
191 ObserverList<web_modal::ModalDialogHostObserver> observer_list_; | |
192 | |
193 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews); | |
194 }; | |
195 | |
196 } // namespace apps | |
197 | |
198 #endif // APPS_UI_VIEWS_NATIVE_APP_WINDOW_VIEWS_H_ | |
OLD | NEW |