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