Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / apps / native_app_window_views.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_
7
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"
20
21 #if defined(USE_ASH)
22 namespace ash {
23 class ImmersiveFullscreenController;
24 }
25 #endif
26
27 class ExtensionKeybindingRegistryViews;
28
29 namespace apps {
30 class AppWindowFrameView;
31 }
32
33 namespace content {
34 class BrowserContext;
35 class RenderViewHost;
36 class WebContents;
37 }
38
39 namespace extensions {
40 class Extension;
41 }
42
43 namespace ui {
44 class MenuModel;
45 }
46
47 namespace views {
48 class MenuRunner;
49 class WebView;
50 }
51
52 class NativeAppWindowViews : public apps::NativeAppWindow,
53                              public content::WebContentsObserver,
54                              public views::ContextMenuController,
55                              public views::WidgetDelegateView,
56                              public views::WidgetObserver {
57  public:
58   NativeAppWindowViews();
59   virtual ~NativeAppWindowViews();
60   void Init(apps::AppWindow* app_window,
61             const apps::AppWindow::CreateParams& create_params);
62
63   SkRegion* shape() { return shape_.get(); }
64
65  protected:
66   // Called before views::Widget::Init() to allow subclasses to customize
67   // the InitParams that would be passed.
68   virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params,
69                                   views::Widget* widget);
70
71   // ui::BaseWindow implementation that subclasses may override.
72   virtual void Show() OVERRIDE;
73   virtual void Activate() OVERRIDE;
74
75   content::BrowserContext* browser_context() {
76     return app_window_->browser_context();
77   }
78
79   const extensions::Extension* extension() { return app_window_->extension(); }
80   const views::Widget* window() const { return window_; }
81
82   virtual void InitializeDefaultWindow(
83       const apps::AppWindow::CreateParams& create_params);
84   virtual void InitializePanelWindow(
85       const apps::AppWindow::CreateParams& create_params);
86
87  private:
88   friend class ShapedAppWindowTargeterTest;
89   FRIEND_TEST_ALL_PREFIXES(ShapedAppWindowTargeterTest,
90                            ResizeInsetsWithinBounds);
91
92   void OnViewWasResized();
93
94   bool ShouldUseChromeStyleFrame() const;
95
96   // Installs an EasyResizeWindowTargeter on the containing window, which
97   // allows the window to be resized from within |kResizeInsideBoundsSize|
98   // pixels inside the window bounds.
99   void InstallEasyResizeTargeterOnContainer() const;
100
101   // Caller owns the returned object.
102   apps::AppWindowFrameView* CreateAppWindowFrameView();
103
104   // ui::BaseWindow implementation.
105   virtual bool IsActive() const OVERRIDE;
106   virtual bool IsMaximized() const OVERRIDE;
107   virtual bool IsMinimized() const OVERRIDE;
108   virtual bool IsFullscreen() const OVERRIDE;
109   virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
110   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
111   virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
112   virtual gfx::Rect GetBounds() const OVERRIDE;
113   virtual void ShowInactive() OVERRIDE;
114   virtual void Hide() OVERRIDE;
115   virtual void Close() OVERRIDE;
116   virtual void Deactivate() OVERRIDE;
117   virtual void Maximize() OVERRIDE;
118   virtual void Minimize() OVERRIDE;
119   virtual void Restore() OVERRIDE;
120   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
121   virtual void FlashFrame(bool flash) OVERRIDE;
122   virtual bool IsAlwaysOnTop() const OVERRIDE;
123   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
124
125   // Overridden from views::ContextMenuController:
126   virtual void ShowContextMenuForView(views::View* source,
127                                       const gfx::Point& p,
128                                       ui::MenuSourceType source_type) OVERRIDE;
129
130   // WidgetDelegate implementation.
131   virtual void OnWidgetMove() OVERRIDE;
132   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
133   virtual bool CanResize() const OVERRIDE;
134   virtual bool CanMaximize() const OVERRIDE;
135   virtual base::string16 GetWindowTitle() const OVERRIDE;
136   virtual bool ShouldShowWindowTitle() const OVERRIDE;
137   virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
138   virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
139   virtual bool ShouldShowWindowIcon() const OVERRIDE;
140   virtual void SaveWindowPlacement(const gfx::Rect& bounds,
141                                    ui::WindowShowState show_state) OVERRIDE;
142   virtual void DeleteDelegate() OVERRIDE;
143   virtual views::Widget* GetWidget() OVERRIDE;
144   virtual const views::Widget* GetWidget() const OVERRIDE;
145   virtual views::View* GetContentsView() OVERRIDE;
146   virtual views::NonClientFrameView* CreateNonClientFrameView(
147       views::Widget* widget) OVERRIDE;
148   virtual bool WidgetHasHitTestMask() const OVERRIDE;
149   virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE;
150   virtual bool ShouldDescendIntoChildForEventHandling(
151       gfx::NativeView child,
152       const gfx::Point& location) OVERRIDE;
153
154   // WidgetObserver implementation.
155   virtual void OnWidgetVisibilityChanged(views::Widget* widget,
156                                          bool visible) OVERRIDE;
157   virtual void OnWidgetActivationChanged(views::Widget* widget,
158                                          bool active) OVERRIDE;
159
160   // WebContentsObserver implementation.
161   virtual void RenderViewCreated(
162       content::RenderViewHost* render_view_host) OVERRIDE;
163   virtual void RenderViewHostChanged(
164       content::RenderViewHost* old_host,
165       content::RenderViewHost* new_host) OVERRIDE;
166
167   // views::View implementation.
168   virtual void Layout() OVERRIDE;
169   virtual void ViewHierarchyChanged(
170       const ViewHierarchyChangedDetails& details) OVERRIDE;
171   virtual gfx::Size GetPreferredSize() OVERRIDE;
172   virtual gfx::Size GetMinimumSize() OVERRIDE;
173   virtual gfx::Size GetMaximumSize() OVERRIDE;
174   virtual void OnFocus() OVERRIDE;
175   virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
176
177   // NativeAppWindow implementation.
178   virtual void SetFullscreen(int fullscreen_types) OVERRIDE;
179   virtual bool IsFullscreenOrPending() const OVERRIDE;
180   virtual bool IsDetached() const OVERRIDE;
181   virtual void UpdateWindowIcon() OVERRIDE;
182   virtual void UpdateWindowTitle() OVERRIDE;
183   virtual void UpdateBadgeIcon() OVERRIDE;
184   virtual void UpdateDraggableRegions(
185       const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
186   virtual SkRegion* GetDraggableRegion() OVERRIDE;
187   virtual void UpdateShape(scoped_ptr<SkRegion> region) OVERRIDE;
188   virtual void HandleKeyboardEvent(
189       const content::NativeWebKeyboardEvent& event) OVERRIDE;
190   virtual bool IsFrameless() const OVERRIDE;
191   virtual gfx::Insets GetFrameInsets() const OVERRIDE;
192   virtual void HideWithApp() OVERRIDE;
193   virtual void ShowWithApp() OVERRIDE;
194   virtual void UpdateWindowMinMaxSize() OVERRIDE;
195
196   // web_modal::WebContentsModalDialogHost implementation.
197   virtual gfx::NativeView GetHostView() const OVERRIDE;
198   virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
199   virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
200   virtual void AddObserver(
201       web_modal::ModalDialogHostObserver* observer) OVERRIDE;
202   virtual void RemoveObserver(
203       web_modal::ModalDialogHostObserver* observer) OVERRIDE;
204
205   content::WebContents* web_contents() { return app_window_->web_contents(); }
206
207   apps::AppWindow* app_window_;  // Not owned.
208   views::WebView* web_view_;
209   views::Widget* window_;
210   bool is_fullscreen_;
211
212   // Custom shape of the window. If this is not set then the window has a
213   // default shape, usually rectangular.
214   scoped_ptr<SkRegion> shape_;
215
216   scoped_ptr<SkRegion> draggable_region_;
217
218   bool frameless_;
219   bool transparent_background_;
220   gfx::Size preferred_size_;
221   bool resizable_;
222
223   // The class that registers for keyboard shortcuts for extension commands.
224   scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_;
225
226   views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
227
228 #if defined(USE_ASH)
229   // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In
230   // immersive fullscreen, the window header (title bar and window controls)
231   // slides onscreen as an overlay when the mouse is hovered at the top of the
232   // screen.
233   scoped_ptr<ash::ImmersiveFullscreenController>
234       immersive_fullscreen_controller_;
235 #endif
236
237   ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
238
239   base::WeakPtrFactory<NativeAppWindowViews> weak_ptr_factory_;
240
241   // Used to show the system menu.
242   scoped_ptr<views::MenuRunner> menu_runner_;
243
244   DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews);
245 };
246
247 #endif  // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_