1 // Copyright (c) 2012 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_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_ 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "ui/aura/client/activation_change_observer.h" 10 #include "ui/aura/client/activation_delegate.h" 11 #include "ui/aura/client/drag_drop_delegate.h" 12 #include "ui/aura/client/focus_change_observer.h" 13 #include "ui/aura/root_window_observer.h" 14 #include "ui/aura/window_delegate.h" 15 #include "ui/base/cursor/cursor.h" 16 #include "ui/views/ime/input_method_delegate.h" 17 #include "ui/views/widget/native_widget_private.h" 18 19 namespace aura { 20 class RootWindow; 21 namespace client { 22 class DragDropClient; 23 class FocusClient; 24 class ScreenPositionClient; 25 class WindowTreeClient; 26 } 27 } 28 29 namespace views { 30 31 namespace corewm { 32 class CompoundEventFilter; 33 class CursorManager; 34 class FocusController; 35 class InputMethodEventFilter; 36 class ShadowController; 37 class TooltipController; 38 class VisibilityController; 39 class WindowModalityController; 40 } 41 42 class DesktopCaptureClient; 43 class DesktopDispatcherClient; 44 class DesktopEventClient; 45 class DesktopRootWindowHost; 46 class DropHelper; 47 class FocusManagerEventHandler; 48 class TooltipManagerAura; 49 class WindowReorderer; 50 51 class VIEWS_EXPORT DesktopNativeWidgetAura 52 : public internal::NativeWidgetPrivate, 53 public aura::WindowDelegate, 54 public aura::client::ActivationDelegate, 55 public aura::client::ActivationChangeObserver, 56 public aura::client::FocusChangeObserver, 57 public views::internal::InputMethodDelegate, 58 public aura::client::DragDropDelegate, 59 public aura::RootWindowObserver { 60 public: 61 explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate* delegate); 62 virtual ~DesktopNativeWidgetAura(); 63 64 // Maps from window to DesktopNativeWidgetAura. 65 static DesktopNativeWidgetAura* ForWindow(aura::Window* window); 66 67 // Called by our DesktopRootWindowHost after it has deleted native resources; 68 // this is the signal that we should start our shutdown. 69 virtual void OnHostClosed(); 70 71 // Called from ~DesktopRootWindowHost. This takes the RootWindow as by the 72 // time we get here |root_window_| is NULL. 73 virtual void OnDesktopRootWindowHostDestroyed(aura::RootWindow* root); 74 75 corewm::InputMethodEventFilter* input_method_event_filter() { 76 return input_method_event_filter_.get(); 77 } 78 corewm::CompoundEventFilter* root_window_event_filter() { 79 return root_window_event_filter_; 80 } 81 82 // Overridden from NativeWidget: 83 virtual ui::EventHandler* GetEventHandler() OVERRIDE; 84 85 // Ensures that the correct window is activated/deactivated based on whether 86 // we are being activated/deactivated. 87 void HandleActivationChanged(bool active); 88 89 protected: 90 // Overridden from internal::NativeWidgetPrivate: 91 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; 92 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE; 93 virtual bool ShouldUseNativeFrame() const OVERRIDE; 94 virtual void FrameTypeChanged() OVERRIDE; 95 virtual Widget* GetWidget() OVERRIDE; 96 virtual const Widget* GetWidget() const OVERRIDE; 97 virtual gfx::NativeView GetNativeView() const OVERRIDE; 98 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; 99 virtual Widget* GetTopLevelWidget() OVERRIDE; 100 virtual const ui::Compositor* GetCompositor() const OVERRIDE; 101 virtual ui::Compositor* GetCompositor() OVERRIDE; 102 virtual ui::Layer* GetLayer() OVERRIDE; 103 virtual void ReorderNativeViews() OVERRIDE; 104 virtual void ViewRemoved(View* view) OVERRIDE; 105 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; 106 virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE; 107 virtual TooltipManager* GetTooltipManager() const OVERRIDE; 108 virtual void SetCapture() OVERRIDE; 109 virtual void ReleaseCapture() OVERRIDE; 110 virtual bool HasCapture() const OVERRIDE; 111 virtual InputMethod* CreateInputMethod() OVERRIDE; 112 virtual internal::InputMethodDelegate* GetInputMethodDelegate() OVERRIDE; 113 virtual void CenterWindow(const gfx::Size& size) OVERRIDE; 114 virtual void GetWindowPlacement( 115 gfx::Rect* bounds, 116 ui::WindowShowState* maximized) const OVERRIDE; 117 virtual bool SetWindowTitle(const string16& title) OVERRIDE; 118 virtual void SetWindowIcons(const gfx::ImageSkia& window_icon, 119 const gfx::ImageSkia& app_icon) OVERRIDE; 120 virtual void InitModalType(ui::ModalType modal_type) OVERRIDE; 121 virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE; 122 virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE; 123 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; 124 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; 125 virtual void SetSize(const gfx::Size& size) OVERRIDE; 126 virtual void StackAbove(gfx::NativeView native_view) OVERRIDE; 127 virtual void StackAtTop() OVERRIDE; 128 virtual void StackBelow(gfx::NativeView native_view) OVERRIDE; 129 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; 130 virtual void Close() OVERRIDE; 131 virtual void CloseNow() OVERRIDE; 132 virtual void Show() OVERRIDE; 133 virtual void Hide() OVERRIDE; 134 virtual void ShowMaximizedWithBounds( 135 const gfx::Rect& restored_bounds) OVERRIDE; 136 virtual void ShowWithWindowState(ui::WindowShowState state) OVERRIDE; 137 virtual bool IsVisible() const OVERRIDE; 138 virtual void Activate() OVERRIDE; 139 virtual void Deactivate() OVERRIDE; 140 virtual bool IsActive() const OVERRIDE; 141 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; 142 virtual bool IsAlwaysOnTop() const OVERRIDE; 143 virtual void Maximize() OVERRIDE; 144 virtual void Minimize() OVERRIDE; 145 virtual bool IsMaximized() const OVERRIDE; 146 virtual bool IsMinimized() const OVERRIDE; 147 virtual void Restore() OVERRIDE; 148 virtual void SetFullscreen(bool fullscreen) OVERRIDE; 149 virtual bool IsFullscreen() const OVERRIDE; 150 virtual void SetOpacity(unsigned char opacity) OVERRIDE; 151 virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE; 152 virtual void FlashFrame(bool flash_frame) OVERRIDE; 153 virtual void RunShellDrag(View* view, 154 const ui::OSExchangeData& data, 155 const gfx::Point& location, 156 int operation, 157 ui::DragDropTypes::DragEventSource source) OVERRIDE; 158 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; 159 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; 160 virtual bool IsMouseEventsEnabled() const OVERRIDE; 161 virtual void ClearNativeFocus() OVERRIDE; 162 virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; 163 virtual Widget::MoveLoopResult RunMoveLoop( 164 const gfx::Vector2d& drag_offset, 165 Widget::MoveLoopSource source, 166 Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE; 167 virtual void EndMoveLoop() OVERRIDE; 168 virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; 169 virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE; 170 virtual void OnRootViewLayout() const OVERRIDE; 171 172 // Overridden from aura::WindowDelegate: 173 virtual gfx::Size GetMinimumSize() const OVERRIDE; 174 virtual gfx::Size GetMaximumSize() const OVERRIDE; 175 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 176 const gfx::Rect& new_bounds) OVERRIDE {} 177 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE; 178 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; 179 virtual bool ShouldDescendIntoChildForEventHandling( 180 aura::Window* child, 181 const gfx::Point& location) OVERRIDE; 182 virtual bool CanFocus() OVERRIDE; 183 virtual void OnCaptureLost() OVERRIDE; 184 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 185 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 186 virtual void OnWindowDestroying() OVERRIDE; 187 virtual void OnWindowDestroyed() OVERRIDE; 188 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE; 189 virtual bool HasHitTestMask() const OVERRIDE; 190 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; 191 virtual void DidRecreateLayer(ui::Layer* old_layer, 192 ui::Layer* new_layer) OVERRIDE; 193 194 // Overridden from ui::EventHandler: 195 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 196 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 197 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; 198 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 199 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 200 201 // Overridden from aura::client::ActivationDelegate: 202 virtual bool ShouldActivate() const OVERRIDE; 203 204 // Overridden from aura::client::ActivationChangeObserver: 205 virtual void OnWindowActivated(aura::Window* gained_active, 206 aura::Window* lost_active) OVERRIDE; 207 208 // Overridden from aura::client::FocusChangeObserver: 209 virtual void OnWindowFocused(aura::Window* gained_focus, 210 aura::Window* lost_focus) OVERRIDE; 211 212 // Overridden from views::internal::InputMethodDelegate: 213 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE; 214 215 // Overridden from aura::client::DragDropDelegate: 216 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE; 217 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; 218 virtual void OnDragExited() OVERRIDE; 219 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; 220 221 // Overridden from aura::RootWindowObserver: 222 virtual void OnRootWindowHostCloseRequested( 223 const aura::RootWindow* root) OVERRIDE; 224 virtual void OnRootWindowHostResized(const aura::RootWindow* root) OVERRIDE; 225 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, 226 const gfx::Point& new_origin) OVERRIDE; 227 228 private: 229 friend class FocusManagerEventHandler; 230 231 // Installs the input method filter. 232 void InstallInputMethodEventFilter(); 233 234 // To save a clear on platforms where the window is never transparent, the 235 // window is only set as transparent when the glass frame is in use. 236 void UpdateWindowTransparency(); 237 238 // See class documentation for Widget in widget.h for a note about ownership. 239 Widget::InitParams::Ownership ownership_; 240 241 scoped_ptr<DesktopCaptureClient> capture_client_; 242 243 // The NativeWidget owns the RootWindow. Required because the RootWindow owns 244 // its RootWindowHost, so DesktopRootWindowHost can't own it. 245 scoped_ptr<aura::RootWindow> root_window_; 246 247 // The following factory is used for calls to close the NativeWidgetAura 248 // instance. 249 base::WeakPtrFactory<DesktopNativeWidgetAura> close_widget_factory_; 250 251 // Can we be made active? 252 bool can_activate_; 253 254 // Ownership passed to RootWindow on Init. 255 DesktopRootWindowHost* desktop_root_window_host_; 256 257 // Child of the root, contains |content_window_|. 258 aura::Window* content_window_container_; 259 260 // Child of |content_window_container_|. This is the return value from 261 // GetNativeView(). 262 // WARNING: this may be NULL, in particular during shutdown it becomes NULL. 263 aura::Window* content_window_; 264 265 internal::NativeWidgetDelegate* native_widget_delegate_; 266 267 scoped_ptr<corewm::FocusController> focus_client_; 268 scoped_ptr<DesktopDispatcherClient> dispatcher_client_; 269 scoped_ptr<views::corewm::CursorManager> cursor_client_; 270 scoped_ptr<aura::client::ScreenPositionClient> position_client_; 271 scoped_ptr<aura::client::DragDropClient> drag_drop_client_; 272 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; 273 scoped_ptr<DesktopEventClient> event_client_; 274 scoped_ptr<FocusManagerEventHandler> focus_manager_event_handler_; 275 276 // Toplevel event filter which dispatches to other event filters. 277 corewm::CompoundEventFilter* root_window_event_filter_; 278 279 scoped_ptr<corewm::InputMethodEventFilter> input_method_event_filter_; 280 281 scoped_ptr<DropHelper> drop_helper_; 282 int last_drop_operation_; 283 284 scoped_ptr<corewm::TooltipController> tooltip_controller_; 285 scoped_ptr<TooltipManagerAura> tooltip_manager_; 286 287 scoped_ptr<views::corewm::VisibilityController> visibility_controller_; 288 289 scoped_ptr<views::corewm::WindowModalityController> 290 window_modality_controller_; 291 292 // See comments in OnLostActive(). 293 bool restore_focus_on_activate_; 294 295 gfx::NativeCursor cursor_; 296 297 scoped_ptr<corewm::ShadowController> shadow_controller_; 298 299 // Reorders child windows of |window_| associated with a view based on the 300 // order of the associated views in the widget's view hierarchy. 301 scoped_ptr<WindowReorderer> window_reorderer_; 302 303 // See class documentation for Widget in widget.h for a note about type. 304 Widget::InitParams::Type widget_type_; 305 306 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura); 307 }; 308 309 } // namespace views 310 311 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_ 312