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