| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 5 #ifndef APPS_UI_VIEWS_BASE_NATIVE_APP_WINDOW_VIEWS_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 6 #define APPS_UI_VIEWS_BASE_NATIVE_APP_WINDOW_VIEWS_H_ |
| 7 | 7 |
| 8 #include "apps/app_window.h" | |
| 9 #include "apps/ui/native_app_window.h" | 8 #include "apps/ui/native_app_window.h" |
| 10 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 10 #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" | 11 #include "ui/gfx/rect.h" |
| 15 #include "ui/views/context_menu_controller.h" | |
| 16 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 12 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
| 17 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/widget/widget_delegate.h" | 14 #include "ui/views/widget/widget_delegate.h" |
| 19 #include "ui/views/widget/widget_observer.h" | 15 #include "ui/views/widget/widget_observer.h" |
| 20 | 16 |
| 21 #if defined(USE_ASH) | 17 class SkRegion; |
| 22 namespace ash { | |
| 23 class ImmersiveFullscreenController; | |
| 24 } | |
| 25 #endif | |
| 26 | |
| 27 class ExtensionKeybindingRegistryViews; | |
| 28 | 18 |
| 29 namespace apps { | 19 namespace apps { |
| 30 class AppWindowFrameView; | 20 class AppWindowFrameView; |
| 31 } | 21 } |
| 32 | 22 |
| 33 namespace content { | 23 namespace content { |
| 34 class BrowserContext; | 24 class BrowserContext; |
| 35 class RenderViewHost; | 25 class RenderViewHost; |
| 36 class WebContents; | 26 class WebContents; |
| 37 } | 27 } |
| 38 | 28 |
| 39 namespace extensions { | 29 namespace extensions { |
| 40 class Extension; | 30 class Extension; |
| 41 } | 31 } |
| 42 | 32 |
| 43 namespace ui { | 33 namespace ui { |
| 44 class MenuModel; | 34 class MenuModel; |
| 45 } | 35 } |
| 46 | 36 |
| 47 namespace views { | 37 namespace views { |
| 48 class MenuRunner; | 38 class MenuRunner; |
| 49 class WebView; | 39 class WebView; |
| 50 } | 40 } |
| 51 | 41 |
| 52 class NativeAppWindowViews : public apps::NativeAppWindow, | 42 // A NativeAppWindow backed by a views::Widget. This class may be used alone |
| 53 public content::WebContentsObserver, | 43 // as a stub or subclassed (for example, NativeAppWindowViews in Chrome). |
| 54 public views::ContextMenuController, | 44 class BaseNativeAppWindowViews : public apps::NativeAppWindow, |
| 55 public views::WidgetDelegateView, | 45 public content::WebContentsObserver, |
| 56 public views::WidgetObserver { | 46 public views::WidgetDelegateView, |
| 47 public views::WidgetObserver { |
| 57 public: | 48 public: |
| 58 NativeAppWindowViews(); | 49 BaseNativeAppWindowViews(); |
| 59 virtual ~NativeAppWindowViews(); | 50 virtual ~BaseNativeAppWindowViews(); |
| 60 void Init(apps::AppWindow* app_window, | 51 void Init(apps::AppWindow* app_window, |
| 61 const apps::AppWindow::CreateParams& create_params); | 52 const apps::AppWindow::CreateParams& create_params); |
| 62 | 53 |
| 63 SkRegion* shape() { return shape_.get(); } | 54 void set_window_for_testing(views::Widget* window) { window_ = window; } |
| 55 void set_web_view_for_testing(views::WebView* view) { web_view_ = view; } |
| 64 | 56 |
| 65 protected: | 57 protected: |
| 66 // Called before views::Widget::Init() to allow subclasses to customize | 58 apps::AppWindow* app_window() { return app_window_; } |
| 67 // the InitParams that would be passed. | 59 const apps::AppWindow* app_window() const { return app_window_; } |
| 68 virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params, | |
| 69 views::Widget* widget); | |
| 70 | 60 |
| 71 // ui::BaseWindow implementation that subclasses may override. | 61 views::Widget* window() { return window_; } |
| 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_; } | 62 const views::Widget* window() const { return window_; } |
| 81 | 63 |
| 82 virtual void InitializeDefaultWindow( | 64 views::WebView* web_view() { return web_view_; } |
| 65 |
| 66 // Initializes |window_| for |app_window|. |
| 67 virtual void InitializeWindow( |
| 68 apps::AppWindow* app_window, |
| 83 const apps::AppWindow::CreateParams& create_params); | 69 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 ShouldUseNativeFrame() 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 | 70 |
| 104 // ui::BaseWindow implementation. | 71 // ui::BaseWindow implementation. |
| 105 virtual bool IsActive() const OVERRIDE; | 72 virtual bool IsActive() const OVERRIDE; |
| 106 virtual bool IsMaximized() const OVERRIDE; | 73 virtual bool IsMaximized() const OVERRIDE; |
| 107 virtual bool IsMinimized() const OVERRIDE; | 74 virtual bool IsMinimized() const OVERRIDE; |
| 108 virtual bool IsFullscreen() const OVERRIDE; | 75 virtual bool IsFullscreen() const OVERRIDE; |
| 109 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; | 76 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; |
| 110 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; | 77 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; |
| 111 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; | 78 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; |
| 112 virtual gfx::Rect GetBounds() const OVERRIDE; | 79 virtual gfx::Rect GetBounds() const OVERRIDE; |
| 80 virtual void Show() OVERRIDE; |
| 113 virtual void ShowInactive() OVERRIDE; | 81 virtual void ShowInactive() OVERRIDE; |
| 114 virtual void Hide() OVERRIDE; | 82 virtual void Hide() OVERRIDE; |
| 115 virtual void Close() OVERRIDE; | 83 virtual void Close() OVERRIDE; |
| 84 virtual void Activate() OVERRIDE; |
| 116 virtual void Deactivate() OVERRIDE; | 85 virtual void Deactivate() OVERRIDE; |
| 117 virtual void Maximize() OVERRIDE; | 86 virtual void Maximize() OVERRIDE; |
| 118 virtual void Minimize() OVERRIDE; | 87 virtual void Minimize() OVERRIDE; |
| 119 virtual void Restore() OVERRIDE; | 88 virtual void Restore() OVERRIDE; |
| 120 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | 89 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
| 121 virtual void FlashFrame(bool flash) OVERRIDE; | 90 virtual void FlashFrame(bool flash) OVERRIDE; |
| 122 virtual bool IsAlwaysOnTop() const OVERRIDE; | 91 virtual bool IsAlwaysOnTop() const OVERRIDE; |
| 123 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; | 92 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; |
| 124 | 93 |
| 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. | 94 // WidgetDelegate implementation. |
| 131 virtual void OnWidgetMove() OVERRIDE; | 95 virtual void OnWidgetMove() OVERRIDE; |
| 132 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | 96 virtual views::View* GetInitiallyFocusedView() OVERRIDE; |
| 133 virtual bool CanResize() const OVERRIDE; | 97 virtual bool CanResize() const OVERRIDE; |
| 134 virtual bool CanMaximize() const OVERRIDE; | 98 virtual bool CanMaximize() const OVERRIDE; |
| 135 virtual base::string16 GetWindowTitle() const OVERRIDE; | 99 virtual base::string16 GetWindowTitle() const OVERRIDE; |
| 136 virtual bool ShouldShowWindowTitle() const OVERRIDE; | 100 virtual bool ShouldShowWindowTitle() const OVERRIDE; |
| 137 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; | |
| 138 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; | |
| 139 virtual bool ShouldShowWindowIcon() const OVERRIDE; | 101 virtual bool ShouldShowWindowIcon() const OVERRIDE; |
| 140 virtual void SaveWindowPlacement(const gfx::Rect& bounds, | 102 virtual void SaveWindowPlacement(const gfx::Rect& bounds, |
| 141 ui::WindowShowState show_state) OVERRIDE; | 103 ui::WindowShowState show_state) OVERRIDE; |
| 142 virtual void DeleteDelegate() OVERRIDE; | 104 virtual void DeleteDelegate() OVERRIDE; |
| 143 virtual views::Widget* GetWidget() OVERRIDE; | 105 virtual views::Widget* GetWidget() OVERRIDE; |
| 144 virtual const views::Widget* GetWidget() const OVERRIDE; | 106 virtual const views::Widget* GetWidget() const OVERRIDE; |
| 145 virtual views::View* GetContentsView() OVERRIDE; | 107 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( | 108 virtual bool ShouldDescendIntoChildForEventHandling( |
| 151 gfx::NativeView child, | 109 gfx::NativeView child, |
| 152 const gfx::Point& location) OVERRIDE; | 110 const gfx::Point& location) OVERRIDE; |
| 153 | 111 |
| 154 // WidgetObserver implementation. | 112 // WidgetObserver implementation. |
| 155 virtual void OnWidgetVisibilityChanged(views::Widget* widget, | 113 virtual void OnWidgetVisibilityChanged(views::Widget* widget, |
| 156 bool visible) OVERRIDE; | 114 bool visible) OVERRIDE; |
| 157 virtual void OnWidgetActivationChanged(views::Widget* widget, | 115 virtual void OnWidgetActivationChanged(views::Widget* widget, |
| 158 bool active) OVERRIDE; | 116 bool active) OVERRIDE; |
| 159 | 117 |
| 160 // WebContentsObserver implementation. | 118 // WebContentsObserver implementation. |
| 161 virtual void RenderViewCreated( | 119 virtual void RenderViewCreated( |
| 162 content::RenderViewHost* render_view_host) OVERRIDE; | 120 content::RenderViewHost* render_view_host) OVERRIDE; |
| 163 virtual void RenderViewHostChanged( | 121 virtual void RenderViewHostChanged( |
| 164 content::RenderViewHost* old_host, | 122 content::RenderViewHost* old_host, |
| 165 content::RenderViewHost* new_host) OVERRIDE; | 123 content::RenderViewHost* new_host) OVERRIDE; |
| 166 | 124 |
| 167 // views::View implementation. | 125 // views::View implementation. |
| 168 virtual void Layout() OVERRIDE; | 126 virtual void Layout() OVERRIDE; |
| 169 virtual void ViewHierarchyChanged( | 127 virtual void ViewHierarchyChanged( |
| 170 const ViewHierarchyChangedDetails& details) OVERRIDE; | 128 const ViewHierarchyChangedDetails& details) OVERRIDE; |
| 171 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 172 virtual gfx::Size GetMinimumSize() OVERRIDE; | 129 virtual gfx::Size GetMinimumSize() OVERRIDE; |
| 173 virtual gfx::Size GetMaximumSize() OVERRIDE; | 130 virtual gfx::Size GetMaximumSize() OVERRIDE; |
| 174 virtual void OnFocus() OVERRIDE; | 131 virtual void OnFocus() OVERRIDE; |
| 175 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
| 176 | 132 |
| 177 // NativeAppWindow implementation. | 133 // NativeAppWindow implementation. |
| 178 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; | 134 virtual void SetFullscreen(int fullscreen_types) OVERRIDE; |
| 179 virtual bool IsFullscreenOrPending() const OVERRIDE; | 135 virtual bool IsFullscreenOrPending() const OVERRIDE; |
| 180 virtual bool IsDetached() const OVERRIDE; | 136 virtual bool IsDetached() const OVERRIDE; |
| 181 virtual void UpdateWindowIcon() OVERRIDE; | 137 virtual void UpdateWindowIcon() OVERRIDE; |
| 182 virtual void UpdateWindowTitle() OVERRIDE; | 138 virtual void UpdateWindowTitle() OVERRIDE; |
| 183 virtual void UpdateBadgeIcon() OVERRIDE; | 139 virtual void UpdateBadgeIcon() OVERRIDE; |
| 184 virtual void UpdateDraggableRegions( | 140 virtual void UpdateDraggableRegions( |
| 185 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; | 141 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 197 | 153 |
| 198 // web_modal::WebContentsModalDialogHost implementation. | 154 // web_modal::WebContentsModalDialogHost implementation. |
| 199 virtual gfx::NativeView GetHostView() const OVERRIDE; | 155 virtual gfx::NativeView GetHostView() const OVERRIDE; |
| 200 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE; | 156 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE; |
| 201 virtual gfx::Size GetMaximumDialogSize() OVERRIDE; | 157 virtual gfx::Size GetMaximumDialogSize() OVERRIDE; |
| 202 virtual void AddObserver( | 158 virtual void AddObserver( |
| 203 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | 159 web_modal::ModalDialogHostObserver* observer) OVERRIDE; |
| 204 virtual void RemoveObserver( | 160 virtual void RemoveObserver( |
| 205 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | 161 web_modal::ModalDialogHostObserver* observer) OVERRIDE; |
| 206 | 162 |
| 207 content::WebContents* web_contents() { return app_window_->web_contents(); } | 163 private: |
| 164 // Informs modal dialogs that they need to update their positions. |
| 165 void OnViewWasResized(); |
| 208 | 166 |
| 209 apps::AppWindow* app_window_; // Not owned. | 167 apps::AppWindow* app_window_; // Not owned. |
| 210 views::WebView* web_view_; | 168 views::WebView* web_view_; |
| 211 views::Widget* window_; | 169 views::Widget* window_; |
| 212 bool is_fullscreen_; | |
| 213 | |
| 214 // Custom shape of the window. If this is not set then the window has a | |
| 215 // default shape, usually rectangular. | |
| 216 scoped_ptr<SkRegion> shape_; | |
| 217 | 170 |
| 218 scoped_ptr<SkRegion> draggable_region_; | 171 scoped_ptr<SkRegion> draggable_region_; |
| 219 | 172 |
| 220 bool frameless_; | 173 bool frameless_; |
| 221 bool has_frame_color_; | |
| 222 SkColor frame_color_; | |
| 223 bool transparent_background_; | 174 bool transparent_background_; |
| 224 gfx::Size preferred_size_; | |
| 225 bool resizable_; | 175 bool resizable_; |
| 226 | 176 |
| 227 // The class that registers for keyboard shortcuts for extension commands. | |
| 228 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; | |
| 229 | |
| 230 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 177 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
| 231 | 178 |
| 232 #if defined(USE_ASH) | |
| 233 // Used to put non-frameless windows into immersive fullscreen on ChromeOS. In | |
| 234 // immersive fullscreen, the window header (title bar and window controls) | |
| 235 // slides onscreen as an overlay when the mouse is hovered at the top of the | |
| 236 // screen. | |
| 237 scoped_ptr<ash::ImmersiveFullscreenController> | |
| 238 immersive_fullscreen_controller_; | |
| 239 #endif | |
| 240 | |
| 241 ObserverList<web_modal::ModalDialogHostObserver> observer_list_; | 179 ObserverList<web_modal::ModalDialogHostObserver> observer_list_; |
| 242 | 180 |
| 243 base::WeakPtrFactory<NativeAppWindowViews> weak_ptr_factory_; | 181 DISALLOW_COPY_AND_ASSIGN(BaseNativeAppWindowViews); |
| 244 | |
| 245 // Used to show the system menu. | |
| 246 scoped_ptr<views::MenuRunner> menu_runner_; | |
| 247 | |
| 248 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews); | |
| 249 }; | 182 }; |
| 250 | 183 |
| 251 #endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_H_ | 184 #endif // APPS_UI_VIEWS_BASE_NATIVE_APP_WINDOW_VIEWS_H_ |
| OLD | NEW |