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