| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 UI_VIEWS_WIDGET_ANDROID_NATIVE_WIDGET_ANDROID_H_ | |
| 6 #define UI_VIEWS_WIDGET_ANDROID_NATIVE_WIDGET_ANDROID_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "ui/aura/client/focus_change_observer.h" | |
| 12 #include "ui/aura/window_delegate.h" | |
| 13 #include "ui/aura/window_observer.h" | |
| 14 #include "ui/aura/window_tree_host_observer.h" | |
| 15 #include "ui/base/cursor/cursor.h" | |
| 16 #include "ui/events/event_constants.h" | |
| 17 #include "ui/views/views_export.h" | |
| 18 #include "ui/views/widget/native_widget_private.h" | |
| 19 #include "ui/wm/public/activation_change_observer.h" | |
| 20 #include "ui/wm/public/activation_delegate.h" | |
| 21 #include "ui/wm/public/drag_drop_delegate.h" | |
| 22 | |
| 23 namespace aura { | |
| 24 class Window; | |
| 25 class WindowTreeHost; | |
| 26 namespace client { | |
| 27 class DefaultCaptureClient; | |
| 28 class DispatcherClient; | |
| 29 class ScreenPositionClient; | |
| 30 class WindowTreeClient; | |
| 31 } | |
| 32 } | |
| 33 namespace gfx { | |
| 34 class FontList; | |
| 35 } | |
| 36 namespace wm { | |
| 37 class FocusController; | |
| 38 } | |
| 39 | |
| 40 namespace views { | |
| 41 | |
| 42 class TooltipManagerAura; | |
| 43 class WindowReorderer; | |
| 44 | |
| 45 // NativeWidgetAndroid creates and hosts the Widget in an Android native window. | |
| 46 // It is used to create a top level window on Android platform. | |
| 47 class VIEWS_EXPORT NativeWidgetAndroid | |
| 48 : public internal::NativeWidgetPrivate, | |
| 49 public aura::WindowDelegate, | |
| 50 public aura::client::ActivationDelegate, | |
| 51 public aura::client::ActivationChangeObserver, | |
| 52 public aura::client::FocusChangeObserver, | |
| 53 public aura::client::DragDropDelegate, | |
| 54 public aura::WindowTreeHostObserver { | |
| 55 public: | |
| 56 explicit NativeWidgetAndroid(internal::NativeWidgetDelegate* delegate); | |
| 57 | |
| 58 aura::WindowTreeHost* host() { return host_.get(); } | |
| 59 | |
| 60 // Overridden from internal::NativeWidgetPrivate: | |
| 61 void InitNativeWidget(const Widget::InitParams& params) override; | |
| 62 void OnWidgetInitDone() override; | |
| 63 NonClientFrameView* CreateNonClientFrameView() override; | |
| 64 bool ShouldUseNativeFrame() const override; | |
| 65 bool ShouldWindowContentsBeTransparent() const override; | |
| 66 void FrameTypeChanged() override; | |
| 67 Widget* GetWidget() override; | |
| 68 const Widget* GetWidget() const override; | |
| 69 gfx::NativeView GetNativeView() const override; | |
| 70 gfx::NativeWindow GetNativeWindow() const override; | |
| 71 Widget* GetTopLevelWidget() override; | |
| 72 const ui::Compositor* GetCompositor() const override; | |
| 73 const ui::Layer* GetLayer() const override; | |
| 74 void ReorderNativeViews() override; | |
| 75 void ViewRemoved(View* view) override; | |
| 76 void SetNativeWindowProperty(const char* name, void* value) override; | |
| 77 void* GetNativeWindowProperty(const char* name) const override; | |
| 78 TooltipManager* GetTooltipManager() const override; | |
| 79 void SetCapture() override; | |
| 80 void ReleaseCapture() override; | |
| 81 bool HasCapture() const override; | |
| 82 ui::InputMethod* GetInputMethod() override; | |
| 83 void CenterWindow(const gfx::Size& size) override; | |
| 84 void GetWindowPlacement(gfx::Rect* bounds, | |
| 85 ui::WindowShowState* maximized) const override; | |
| 86 bool SetWindowTitle(const base::string16& title) override; | |
| 87 void SetWindowIcons(const gfx::ImageSkia& window_icon, | |
| 88 const gfx::ImageSkia& app_icon) override; | |
| 89 void InitModalType(ui::ModalType modal_type) override; | |
| 90 gfx::Rect GetWindowBoundsInScreen() const override; | |
| 91 gfx::Rect GetClientAreaBoundsInScreen() const override; | |
| 92 gfx::Rect GetRestoredBounds() const override; | |
| 93 void SetBounds(const gfx::Rect& bounds) override; | |
| 94 void SetSize(const gfx::Size& size) override; | |
| 95 void StackAbove(gfx::NativeView native_view) override; | |
| 96 void StackAtTop() override; | |
| 97 void StackBelow(gfx::NativeView native_view) override; | |
| 98 void SetShape(SkRegion* shape) override; | |
| 99 void Close() override; | |
| 100 void CloseNow() override; | |
| 101 void Show() override; | |
| 102 void Hide() override; | |
| 103 void ShowMaximizedWithBounds(const gfx::Rect& restored_bounds) override; | |
| 104 void ShowWithWindowState(ui::WindowShowState state) override; | |
| 105 bool IsVisible() const override; | |
| 106 void Activate() override; | |
| 107 void Deactivate() override; | |
| 108 bool IsActive() const override; | |
| 109 void SetAlwaysOnTop(bool always_on_top) override; | |
| 110 bool IsAlwaysOnTop() const override; | |
| 111 void SetVisibleOnAllWorkspaces(bool always_visible) override; | |
| 112 void Maximize() override; | |
| 113 void Minimize() override; | |
| 114 bool IsMaximized() const override; | |
| 115 bool IsMinimized() const override; | |
| 116 void Restore() override; | |
| 117 void SetFullscreen(bool fullscreen) override; | |
| 118 bool IsFullscreen() const override; | |
| 119 void SetOpacity(unsigned char opacity) override; | |
| 120 void SetUseDragFrame(bool use_drag_frame) override; | |
| 121 void FlashFrame(bool flash_frame) override; | |
| 122 void RunShellDrag(View* view, | |
| 123 const ui::OSExchangeData& data, | |
| 124 const gfx::Point& location, | |
| 125 int operation, | |
| 126 ui::DragDropTypes::DragEventSource source) override; | |
| 127 void SchedulePaintInRect(const gfx::Rect& rect) override; | |
| 128 void SetCursor(gfx::NativeCursor cursor) override; | |
| 129 bool IsMouseEventsEnabled() const override; | |
| 130 void ClearNativeFocus() override; | |
| 131 gfx::Rect GetWorkAreaBoundsInScreen() const override; | |
| 132 Widget::MoveLoopResult RunMoveLoop( | |
| 133 const gfx::Vector2d& drag_offset, | |
| 134 Widget::MoveLoopSource source, | |
| 135 Widget::MoveLoopEscapeBehavior escape_behavior) override; | |
| 136 void EndMoveLoop() override; | |
| 137 void SetVisibilityChangedAnimationsEnabled(bool value) override; | |
| 138 void SetVisibilityAnimationDuration(const base::TimeDelta& duration) override; | |
| 139 void SetVisibilityAnimationTransition( | |
| 140 Widget::VisibilityTransition transition) override; | |
| 141 ui::NativeTheme* GetNativeTheme() const override; | |
| 142 void OnRootViewLayout() override; | |
| 143 bool IsTranslucentWindowOpacitySupported() const override; | |
| 144 void OnSizeConstraintsChanged() override; | |
| 145 void RepostNativeEvent(gfx::NativeEvent native_event) override; | |
| 146 | |
| 147 // Overridden from aura::WindowDelegate: | |
| 148 gfx::Size GetMinimumSize() const override; | |
| 149 gfx::Size GetMaximumSize() const override; | |
| 150 void OnBoundsChanged(const gfx::Rect& old_bounds, | |
| 151 const gfx::Rect& new_bounds) override; | |
| 152 gfx::NativeCursor GetCursor(const gfx::Point& point) override; | |
| 153 int GetNonClientComponent(const gfx::Point& point) const override; | |
| 154 bool ShouldDescendIntoChildForEventHandling( | |
| 155 aura::Window* child, | |
| 156 const gfx::Point& location) override; | |
| 157 bool CanFocus() override; | |
| 158 void OnCaptureLost() override; | |
| 159 void OnPaint(const ui::PaintContext& context) override; | |
| 160 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | |
| 161 void OnWindowDestroying(aura::Window* window) override; | |
| 162 void OnWindowDestroyed(aura::Window* window) override; | |
| 163 void OnWindowTargetVisibilityChanged(bool visible) override; | |
| 164 bool HasHitTestMask() const override; | |
| 165 void GetHitTestMask(gfx::Path* mask) const override; | |
| 166 | |
| 167 // Overridden from ui::EventHandler: | |
| 168 void OnKeyEvent(ui::KeyEvent* event) override; | |
| 169 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 170 void OnScrollEvent(ui::ScrollEvent* event) override; | |
| 171 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 172 | |
| 173 // Overridden from aura::client::ActivationDelegate: | |
| 174 bool ShouldActivate() const override; | |
| 175 | |
| 176 // Overridden from aura::client::ActivationChangeObserver: | |
| 177 void OnWindowActivated( | |
| 178 aura::client::ActivationChangeObserver::ActivationReason reason, | |
| 179 aura::Window* gained_active, | |
| 180 aura::Window* lost_active) override; | |
| 181 | |
| 182 // Overridden from aura::client::FocusChangeObserver: | |
| 183 void OnWindowFocused(aura::Window* gained_focus, | |
| 184 aura::Window* lost_focus) override; | |
| 185 | |
| 186 // Overridden from aura::client::DragDropDelegate: | |
| 187 void OnDragEntered(const ui::DropTargetEvent& event) override; | |
| 188 int OnDragUpdated(const ui::DropTargetEvent& event) override; | |
| 189 void OnDragExited() override; | |
| 190 int OnPerformDrop(const ui::DropTargetEvent& event) override; | |
| 191 | |
| 192 // Overridden from aura::WindowTreeHostObserver: | |
| 193 void OnHostCloseRequested(const aura::WindowTreeHost* host) override; | |
| 194 void OnHostResized(const aura::WindowTreeHost* host) override; | |
| 195 void OnHostMoved(const aura::WindowTreeHost* host, | |
| 196 const gfx::Point& new_origin) override; | |
| 197 | |
| 198 protected: | |
| 199 ~NativeWidgetAndroid() override; | |
| 200 | |
| 201 internal::NativeWidgetDelegate* delegate() { return delegate_; } | |
| 202 | |
| 203 private: | |
| 204 class ActiveWindowObserver; | |
| 205 | |
| 206 bool IsDocked() const; | |
| 207 void SetInitialFocus(ui::WindowShowState show_state); | |
| 208 | |
| 209 internal::NativeWidgetDelegate* delegate_; | |
| 210 | |
| 211 // WARNING: set to NULL when destroyed. As the Widget is not necessarily | |
| 212 // destroyed along with |window_| all usage of |window_| should first verify | |
| 213 // non-NULL. | |
| 214 aura::Window* window_; | |
| 215 | |
| 216 // See class documentation for Widget in widget.h for a note about ownership. | |
| 217 Widget::InitParams::Ownership ownership_; | |
| 218 | |
| 219 // Are we in the destructor? | |
| 220 bool destroying_; | |
| 221 | |
| 222 gfx::NativeCursor cursor_; | |
| 223 | |
| 224 // The saved window state for exiting full screen state. | |
| 225 ui::WindowShowState saved_window_state_; | |
| 226 | |
| 227 scoped_ptr<TooltipManagerAura> tooltip_manager_; | |
| 228 | |
| 229 // Reorders child windows of |window_| associated with a view based on the | |
| 230 // order of the associated views in the widget's view hierarchy. | |
| 231 scoped_ptr<WindowReorderer> window_reorderer_; | |
| 232 | |
| 233 scoped_ptr<aura::WindowTreeHost> host_; | |
| 234 scoped_ptr<wm::FocusController> focus_client_; | |
| 235 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | |
| 236 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; | |
| 237 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; | |
| 238 scoped_ptr<aura::client::DispatcherClient> dispatcher_client_; | |
| 239 | |
| 240 // The following factory is used for calls to close the | |
| 241 // NativeWidgetAndroid instance. | |
| 242 base::WeakPtrFactory<NativeWidgetAndroid> close_widget_factory_; | |
| 243 | |
| 244 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAndroid); | |
| 245 }; | |
| 246 | |
| 247 } // namespace views | |
| 248 | |
| 249 #endif // UI_VIEWS_WIDGET_ANDROID_NATIVE_WIDGET_ANDROID_H_ | |
| OLD | NEW |