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