Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / components / native_app_window / native_app_window_views.h
blob80737944d94a231a98d6818019c2dd22ce7ce999
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 EXTENSIONS_COMPONENTS_NATIVE_APP_WINDOW_NATIVE_APP_WINDOW_VIEWS_H_
6 #define EXTENSIONS_COMPONENTS_NATIVE_APP_WINDOW_NATIVE_APP_WINDOW_VIEWS_H_
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/geometry/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"
19 class SkRegion;
21 namespace content {
22 class BrowserContext;
23 class RenderViewHost;
24 class WebContents;
27 namespace extensions {
28 class Extension;
31 namespace ui {
32 class MenuModel;
35 namespace views {
36 class MenuRunner;
37 class WebView;
40 namespace native_app_window {
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 ~NativeAppWindowViews() override;
51 void Init(extensions::AppWindow* app_window,
52 const extensions::AppWindow::CreateParams& create_params);
54 // Signal that CanHaveTransparentBackground has changed.
55 void OnCanHaveAlphaEnabledChanged();
57 extensions::AppWindow* app_window() { return app_window_; }
58 const extensions::AppWindow* app_window() const { return app_window_; }
60 views::WebView* web_view() { return web_view_; }
61 const views::WebView* web_view() const { return web_view_; }
63 views::Widget* widget() { return widget_; }
64 const views::Widget* widget() const { return widget_; }
66 void set_window_for_testing(views::Widget* window) { widget_ = window; }
67 void set_web_view_for_testing(views::WebView* view) { web_view_ = view; }
69 protected:
70 // Initializes |widget_| for |app_window|.
71 virtual void InitializeWindow(
72 extensions::AppWindow* app_window,
73 const extensions::AppWindow::CreateParams& create_params);
75 // ui::BaseWindow implementation.
76 bool IsActive() const override;
77 bool IsMaximized() const override;
78 bool IsMinimized() const override;
79 bool IsFullscreen() const override;
80 gfx::NativeWindow GetNativeWindow() const override;
81 gfx::Rect GetRestoredBounds() const override;
82 ui::WindowShowState GetRestoredState() const override;
83 gfx::Rect GetBounds() const override;
84 void Show() override;
85 void ShowInactive() override;
86 void Hide() override;
87 void Close() override;
88 void Activate() override;
89 void Deactivate() override;
90 void Maximize() override;
91 void Minimize() override;
92 void Restore() override;
93 void SetBounds(const gfx::Rect& bounds) override;
94 void FlashFrame(bool flash) override;
95 bool IsAlwaysOnTop() const override;
96 void SetAlwaysOnTop(bool always_on_top) override;
98 // WidgetDelegate implementation.
99 void OnWidgetMove() override;
100 views::View* GetInitiallyFocusedView() override;
101 bool CanResize() const override;
102 bool CanMaximize() const override;
103 bool CanMinimize() const override;
104 base::string16 GetWindowTitle() const override;
105 bool ShouldShowWindowTitle() const override;
106 bool ShouldShowWindowIcon() const override;
107 void SaveWindowPlacement(const gfx::Rect& bounds,
108 ui::WindowShowState show_state) override;
109 void DeleteDelegate() override;
110 views::Widget* GetWidget() override;
111 const views::Widget* GetWidget() const override;
112 views::View* GetContentsView() override;
113 bool ShouldDescendIntoChildForEventHandling(
114 gfx::NativeView child,
115 const gfx::Point& location) override;
117 // WidgetObserver implementation.
118 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
119 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
121 // WebContentsObserver implementation.
122 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
123 void RenderViewHostChanged(content::RenderViewHost* old_host,
124 content::RenderViewHost* new_host) override;
126 // views::View implementation.
127 void Layout() override;
128 void ViewHierarchyChanged(
129 const ViewHierarchyChangedDetails& details) override;
130 gfx::Size GetMinimumSize() const override;
131 gfx::Size GetMaximumSize() const override;
132 void OnFocus() override;
134 // NativeAppWindow implementation.
135 void SetFullscreen(int fullscreen_types) override;
136 bool IsFullscreenOrPending() const override;
137 void UpdateWindowIcon() override;
138 void UpdateWindowTitle() override;
139 void UpdateDraggableRegions(
140 const std::vector<extensions::DraggableRegion>& regions) override;
141 SkRegion* GetDraggableRegion() override;
142 void UpdateShape(scoped_ptr<SkRegion> region) override;
143 void HandleKeyboardEvent(
144 const content::NativeWebKeyboardEvent& event) override;
145 bool IsFrameless() const override;
146 bool HasFrameColor() const override;
147 SkColor ActiveFrameColor() const override;
148 SkColor InactiveFrameColor() const override;
149 gfx::Insets GetFrameInsets() const override;
150 void HideWithApp() override;
151 void ShowWithApp() override;
152 gfx::Size GetContentMinimumSize() const override;
153 gfx::Size GetContentMaximumSize() const override;
154 void SetContentSizeConstraints(const gfx::Size& min_size,
155 const gfx::Size& max_size) override;
156 bool CanHaveAlphaEnabled() const override;
157 void SetVisibleOnAllWorkspaces(bool always_visible) override;
159 // web_modal::WebContentsModalDialogHost implementation.
160 gfx::NativeView GetHostView() const override;
161 gfx::Point GetDialogPosition(const gfx::Size& size) override;
162 gfx::Size GetMaximumDialogSize() override;
163 void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
164 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;
166 private:
167 // Informs modal dialogs that they need to update their positions.
168 void OnViewWasResized();
170 extensions::AppWindow* app_window_; // Not owned.
171 views::WebView* web_view_;
172 views::Widget* widget_;
174 scoped_ptr<SkRegion> draggable_region_;
176 bool frameless_;
177 bool resizable_;
178 extensions::SizeConstraints size_constraints_;
180 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
182 base::ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
184 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews);
187 } // namespace native_app_window
189 #endif // EXTENSIONS_COMPONENTS_NATIVE_APP_WINDOW_NATIVE_APP_WINDOW_VIEWS_H_