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_PRIVATE_H_ 6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_PRIVATE_H_ 7 8 #include "base/strings/string16.h" 9 #include "ui/base/ui_base_types.h" 10 #include "ui/gfx/native_widget_types.h" 11 #include "ui/views/ime/input_method_delegate.h" 12 #include "ui/views/widget/native_widget.h" 13 14 namespace gfx { 15 class ImageSkia; 16 class Rect; 17 } 18 19 namespace ui { 20 class NativeTheme; 21 class OSExchangeData; 22 } 23 24 namespace views { 25 class InputMethod; 26 class TooltipManager; 27 namespace internal { 28 29 //////////////////////////////////////////////////////////////////////////////// 30 // NativeWidgetPrivate interface 31 // 32 // A NativeWidget subclass internal to views that provides Widget a conduit for 33 // communication with a backend-specific native widget implementation. 34 // 35 // Many of the methods here are pass-thrus for Widget, and as such there is no 36 // documentation for them here. In that case, see methods of the same name in 37 // widget.h. 38 // 39 // IMPORTANT: This type is intended for use only by the views system and for 40 // NativeWidget implementations. This file should not be included 41 // in code that does not fall into one of these use cases. 42 // 43 class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget { 44 public: 45 virtual ~NativeWidgetPrivate() {} 46 47 // Creates an appropriate default NativeWidgetPrivate implementation for the 48 // current OS/circumstance. 49 static NativeWidgetPrivate* CreateNativeWidget( 50 internal::NativeWidgetDelegate* delegate); 51 52 static NativeWidgetPrivate* GetNativeWidgetForNativeView( 53 gfx::NativeView native_view); 54 static NativeWidgetPrivate* GetNativeWidgetForNativeWindow( 55 gfx::NativeWindow native_window); 56 57 // Retrieves the top NativeWidgetPrivate in the hierarchy containing the given 58 // NativeView, or NULL if there is no NativeWidgetPrivate that contains it. 59 static NativeWidgetPrivate* GetTopLevelNativeWidget( 60 gfx::NativeView native_view); 61 62 static void GetAllChildWidgets(gfx::NativeView native_view, 63 Widget::Widgets* children); 64 static void ReparentNativeView(gfx::NativeView native_view, 65 gfx::NativeView new_parent); 66 67 // Returns true if any mouse button is currently down. 68 static bool IsMouseButtonDown(); 69 70 // Returns true if any touch device is currently down. 71 static bool IsTouchDown(); 72 73 // Initializes the NativeWidget. 74 virtual void InitNativeWidget(const Widget::InitParams& params) = 0; 75 76 // Returns a NonClientFrameView for the widget's NonClientView, or NULL if 77 // the NativeWidget wants no special NonClientFrameView. 78 virtual NonClientFrameView* CreateNonClientFrameView() = 0; 79 80 virtual bool ShouldUseNativeFrame() const = 0; 81 virtual void FrameTypeChanged() = 0; 82 83 // Returns the Widget associated with this NativeWidget. This function is 84 // guaranteed to return non-NULL for the lifetime of the NativeWidget. 85 virtual Widget* GetWidget() = 0; 86 virtual const Widget* GetWidget() const = 0; 87 88 // Returns the NativeView/Window associated with this NativeWidget. 89 virtual gfx::NativeView GetNativeView() const = 0; 90 virtual gfx::NativeWindow GetNativeWindow() const = 0; 91 92 // Returns the topmost Widget in a hierarchy. 93 virtual Widget* GetTopLevelWidget() = 0; 94 95 // Returns the Compositor, or NULL if there isn't one associated with this 96 // NativeWidget. 97 virtual const ui::Compositor* GetCompositor() const = 0; 98 virtual ui::Compositor* GetCompositor() = 0; 99 100 // Returns the NativeWidget's layer, if any. 101 virtual ui::Layer* GetLayer() = 0; 102 103 // Reorders the widget's child NativeViews which are associated to the view 104 // tree (eg via a NativeViewHost) to match the z-order of the views in the 105 // view tree. The z-order of views with layers relative to views with 106 // associated NativeViews is used to reorder the NativeView layers. This 107 // method assumes that the widget's child layers which are owned by a view are 108 // already in the correct z-order relative to each other and does no 109 // reordering if there are no views with an associated NativeView. 110 virtual void ReorderNativeViews() = 0; 111 112 // Notifies the NativeWidget that a view was removed from the Widget's view 113 // hierarchy. 114 virtual void ViewRemoved(View* view) = 0; 115 116 // Sets/Gets a native window property on the underlying native window object. 117 // Returns NULL if the property does not exist. Setting the property value to 118 // NULL removes the property. 119 virtual void SetNativeWindowProperty(const char* name, void* value) = 0; 120 virtual void* GetNativeWindowProperty(const char* name) const = 0; 121 122 // Returns the native widget's tooltip manager. Called from the View hierarchy 123 // to update tooltips. 124 virtual TooltipManager* GetTooltipManager() const = 0; 125 126 // Sets or releases event capturing for this native widget. 127 virtual void SetCapture() = 0; 128 virtual void ReleaseCapture() = 0; 129 130 // Returns true if this native widget is capturing events. 131 virtual bool HasCapture() const = 0; 132 133 // Returns the InputMethod for this native widget. 134 // Note that all widgets in a widget hierarchy share the same input method. 135 // TODO(suzhe): rename to GetInputMethod() when NativeWidget implementation 136 // class doesn't inherit Widget anymore. 137 virtual InputMethod* CreateInputMethod() = 0; 138 139 // Returns the InputMethodDelegate for this native widget. 140 virtual InputMethodDelegate* GetInputMethodDelegate() = 0; 141 142 143 // Centers the window and sizes it to the specified size. 144 virtual void CenterWindow(const gfx::Size& size) = 0; 145 146 // Retrieves the window's current restored bounds and "show" state, for 147 // persisting. 148 virtual void GetWindowPlacement( 149 gfx::Rect* bounds, 150 ui::WindowShowState* show_state) const = 0; 151 152 // Sets the NativeWindow title. 153 virtual void SetWindowTitle(const string16& title) = 0; 154 155 // Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in 156 // a title bar. |app_icon| is a larger size for use in the host environment 157 // app switching UI. 158 virtual void SetWindowIcons(const gfx::ImageSkia& window_icon, 159 const gfx::ImageSkia& app_icon) = 0; 160 161 // Initializes the modal type of the window to |modal_type|. Called from 162 // NativeWidgetDelegate::OnNativeWidgetCreated() before the widget is 163 // initially parented. 164 virtual void InitModalType(ui::ModalType modal_type) = 0; 165 166 // See method documentation in Widget. 167 virtual gfx::Rect GetWindowBoundsInScreen() const = 0; 168 virtual gfx::Rect GetClientAreaBoundsInScreen() const = 0; 169 virtual gfx::Rect GetRestoredBounds() const = 0; 170 virtual void SetBounds(const gfx::Rect& bounds) = 0; 171 virtual void SetSize(const gfx::Size& size) = 0; 172 virtual void StackAbove(gfx::NativeView native_view) = 0; 173 virtual void StackAtTop() = 0; 174 virtual void StackBelow(gfx::NativeView native_view) = 0; 175 virtual void SetShape(gfx::NativeRegion shape) = 0; 176 virtual void Close() = 0; 177 virtual void CloseNow() = 0; 178 virtual void Show() = 0; 179 virtual void Hide() = 0; 180 // Invoked if the initial show should maximize the window. |restored_bounds| 181 // is the bounds of the window when not maximized. 182 virtual void ShowMaximizedWithBounds(const gfx::Rect& restored_bounds) = 0; 183 virtual void ShowWithWindowState(ui::WindowShowState show_state) = 0; 184 virtual bool IsVisible() const = 0; 185 virtual void Activate() = 0; 186 virtual void Deactivate() = 0; 187 virtual bool IsActive() const = 0; 188 virtual void SetAlwaysOnTop(bool always_on_top) = 0; 189 virtual void Maximize() = 0; 190 virtual void Minimize() = 0; 191 virtual bool IsMaximized() const = 0; 192 virtual bool IsMinimized() const = 0; 193 virtual void Restore() = 0; 194 virtual void SetFullscreen(bool fullscreen) = 0; 195 virtual bool IsFullscreen() const = 0; 196 virtual void SetOpacity(unsigned char opacity) = 0; 197 virtual void SetUseDragFrame(bool use_drag_frame) = 0; 198 virtual void FlashFrame(bool flash) = 0; 199 virtual void RunShellDrag(View* view, 200 const ui::OSExchangeData& data, 201 const gfx::Point& location, 202 int operation, 203 ui::DragDropTypes::DragEventSource source) = 0; 204 virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0; 205 virtual void SetCursor(gfx::NativeCursor cursor) = 0; 206 virtual bool IsMouseEventsEnabled() const = 0; 207 virtual void ClearNativeFocus() = 0; 208 virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0; 209 virtual void SetInactiveRenderingDisabled(bool value) = 0; 210 virtual Widget::MoveLoopResult RunMoveLoop( 211 const gfx::Vector2d& drag_offset, 212 Widget::MoveLoopSource source) = 0; 213 virtual void EndMoveLoop() = 0; 214 virtual void SetVisibilityChangedAnimationsEnabled(bool value) = 0; 215 virtual ui::NativeTheme* GetNativeTheme() const = 0; 216 217 // Overridden from NativeWidget: 218 virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() OVERRIDE; 219 virtual ui::EventHandler* GetEventHandler() = 0; 220 }; 221 222 } // namespace internal 223 } // namespace views 224 225 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_PRIVATE_H_ 226