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