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.
5 #ifndef UI_VIEWS_WIDGET_WIDGET_H_
6 #define UI_VIEWS_WIDGET_WIDGET_H_
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/scoped_observer.h"
16 #include "ui/base/ui_base_types.h"
17 #include "ui/events/event_source.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/native_widget_types.h"
20 #include "ui/native_theme/native_theme_observer.h"
21 #include "ui/views/focus/focus_manager.h"
22 #include "ui/views/widget/native_widget_delegate.h"
23 #include "ui/views/window/client_view.h"
24 #include "ui/views/window/non_client_view.h"
27 // Windows headers define macros for these function names which screw with us.
28 #if defined(IsMaximized)
31 #if defined(IsMinimized)
34 #if defined(CreateWindow)
52 class DefaultThemeProvider
;
62 class DesktopWindowTreeHost
;
64 class NonClientFrameView
;
69 class WidgetRemovalsObserver
;
72 class NativeWidgetPrivate
;
76 ////////////////////////////////////////////////////////////////////////////////
79 // Encapsulates the platform-specific rendering, event receiving and widget
80 // management aspects of the UI framework.
82 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
83 // Widget is a platform-independent type that communicates with a platform or
84 // context specific NativeWidget implementation.
86 // A special note on ownership:
88 // Depending on the value of the InitParams' ownership field, the Widget
89 // either owns or is owned by its NativeWidget:
91 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default)
92 // The Widget instance is owned by its NativeWidget. When the NativeWidget
93 // is destroyed (in response to a native destruction message), it deletes
94 // the Widget from its destructor.
95 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default)
96 // The Widget instance owns its NativeWidget. This state implies someone
97 // else wants to control the lifetime of this object. When they destroy
98 // the Widget it is responsible for destroying the NativeWidget (from its
101 class VIEWS_EXPORT Widget
: public internal::NativeWidgetDelegate
,
102 public ui::EventSource
,
103 public FocusTraversable
,
104 public ui::NativeThemeObserver
{
106 typedef std::set
<Widget
*> Widgets
;
109 FRAME_TYPE_DEFAULT
, // Use whatever the default would be.
110 FRAME_TYPE_FORCE_CUSTOM
, // Force the custom frame.
111 FRAME_TYPE_FORCE_NATIVE
// Force the native frame.
114 // Result from RunMoveLoop().
115 enum MoveLoopResult
{
116 // The move loop completed successfully.
117 MOVE_LOOP_SUCCESSFUL
,
119 // The user canceled the move loop.
123 // Source that initiated the move loop.
124 enum MoveLoopSource
{
125 MOVE_LOOP_SOURCE_MOUSE
,
126 MOVE_LOOP_SOURCE_TOUCH
,
129 // Behavior when escape is pressed during a move loop.
130 enum MoveLoopEscapeBehavior
{
131 // Indicates the window should be hidden.
132 MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE
,
134 // Indicates the window should not be hidden.
135 MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE
,
138 // Type of visibility change transition that should animate.
139 enum VisibilityTransition
{
142 ANIMATE_BOTH
= ANIMATE_SHOW
| ANIMATE_HIDE
,
146 struct VIEWS_EXPORT InitParams
{
148 TYPE_WINDOW
, // A decorated Window, like a frame window.
149 // Widgets of TYPE_WINDOW will have a NonClientView.
150 TYPE_PANEL
, // Always on top window managed by PanelManager.
151 // Widgets of TYPE_PANEL will have a NonClientView.
152 TYPE_WINDOW_FRAMELESS
,
153 // An undecorated Window.
154 TYPE_CONTROL
, // A control, like a button.
155 TYPE_POPUP
, // An undecorated Window, with transient properties.
156 TYPE_MENU
, // An undecorated Window, with transient properties
157 // specialized to menus.
160 TYPE_DRAG
, // An undecorated Window, used during a drag-and-drop to
161 // show the drag image.
165 // Infer fully opaque or not. For WinAura, top-level windows that are not
166 // of TYPE_WINDOW are translucent so that they can be made to fade in. In
167 // all other cases, windows are fully opaque.
171 // Possibly translucent/transparent.
176 // Infer whether the window should be activatable from the window type.
184 // Default. Creator is not responsible for managing the lifetime of the
185 // Widget, it is destroyed when the corresponding NativeWidget is
187 NATIVE_WIDGET_OWNS_WIDGET
,
188 // Used when the Widget is owned by someone other than the NativeWidget,
189 // e.g. a scoped_ptr in tests.
190 WIDGET_OWNS_NATIVE_WIDGET
194 SHADOW_TYPE_DEFAULT
, // Use default shadow setting. It will be one of
195 // the settings below depending on InitParams::type
196 // and the native widget's type.
197 SHADOW_TYPE_NONE
, // Don't draw any shadow.
198 SHADOW_TYPE_DROP
, // Draw a drop shadow that emphasizes Z-order
199 // relationship to other windows.
203 explicit InitParams(Type type
);
207 // If NULL, a default implementation will be constructed.
208 WidgetDelegate
* delegate
;
210 // If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
211 // Translucent windows may not always be supported. Use
212 // IsTranslucentWindowOpacitySupported to determine if translucent windows
214 // If OPAQUE_WINDOW, we can perform optimizations based on the widget being
215 // fully opaque. Defaults to TRANSLUCENT_WINDOW if
216 // ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
217 // non-window widgets.
218 WindowOpacity opacity
;
220 Activatable activatable
;
222 bool visible_on_all_workspaces
;
224 bool mirror_origin_in_rtl
;
225 ShadowType shadow_type
;
226 // Specifies that the system default caption and icon should not be
227 // rendered, and that the client area should be equivalent to the window
228 // area. Only used on some platforms (Windows and Linux).
229 bool remove_standard_frame
;
230 // Only used by ShellWindow on Windows. Specifies that the default icon of
231 // packaged app should be the system default icon.
232 bool use_system_default_icon
;
233 // Whether the widget should be maximized or minimized.
234 ui::WindowShowState show_state
;
235 gfx::NativeView parent
;
236 // Specifies the initial bounds of the Widget. Default is empty, which means
237 // the NativeWidget may specify a default size. If the parent is specified,
238 // |bounds| is in the parent's coordinate system. If the parent is not
239 // specified, it's in screen's global coordinate system.
241 // When set, this value is used as the Widget's NativeWidget implementation.
242 // The Widget will not construct a default one. Default is NULL.
243 NativeWidget
* native_widget
;
244 // Aura-only. Provides a DesktopWindowTreeHost implementation to use instead
245 // of the default one.
246 // TODO(beng): Figure out if there's a better way to expose this, e.g. get
247 // rid of NW subclasses and do this all via message handling.
248 DesktopWindowTreeHost
* desktop_window_tree_host
;
249 // Only used by NativeWidgetAura. Specifies the type of layer for the
250 // aura::Window. Default is ui::LAYER_TEXTURED.
251 ui::LayerType layer_type
;
252 // Only used by Aura. Provides a context window whose RootWindow is
253 // consulted during widget creation to determine where in the Window
254 // hierarchy this widget should be placed. (This is separate from |parent|;
255 // if you pass a RootWindow to |parent|, your window will be parented to
256 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
257 // where it wants your window placed.) NULL is not allowed if you are using
259 gfx::NativeWindow context
;
260 // If true, forces the window to be shown in the taskbar, even for window
261 // types that do not appear in the taskbar by default (popup and bubble).
262 bool force_show_in_taskbar
;
263 // Only used by X11, for root level windows. Specifies the res_name and
264 // res_class fields, respectively, of the WM_CLASS window property. Controls
265 // window grouping and desktop file matching in Linux window managers.
266 std::string wm_role_name
;
267 std::string wm_class_name
;
268 std::string wm_class_class
;
274 // Creates a toplevel window with no context. These methods should only be
275 // used in cases where there is no contextual information because we're
276 // creating a toplevel window connected to no other event.
278 // If you have any parenting or context information, or can pass that
279 // information, prefer the WithParent or WithContext versions of these
281 static Widget
* CreateWindow(WidgetDelegate
* delegate
);
282 static Widget
* CreateWindowWithBounds(WidgetDelegate
* delegate
,
283 const gfx::Rect
& bounds
);
285 // Creates a decorated window Widget with the specified properties.
286 static Widget
* CreateWindowWithParent(WidgetDelegate
* delegate
,
287 gfx::NativeView parent
);
288 static Widget
* CreateWindowWithParentAndBounds(WidgetDelegate
* delegate
,
289 gfx::NativeView parent
,
290 const gfx::Rect
& bounds
);
292 // Creates a decorated window Widget in the same desktop context as |context|.
293 static Widget
* CreateWindowWithContext(WidgetDelegate
* delegate
,
294 gfx::NativeWindow context
);
295 static Widget
* CreateWindowWithContextAndBounds(WidgetDelegate
* delegate
,
296 gfx::NativeWindow context
,
297 const gfx::Rect
& bounds
);
299 // Closes all Widgets that aren't identified as "secondary widgets". Called
300 // during application shutdown when the last non-secondary widget is closed.
301 static void CloseAllSecondaryWidgets();
303 // Converts a rectangle from one Widget's coordinate system to another's.
304 // Returns false if the conversion couldn't be made, because either these two
305 // Widgets do not have a common ancestor or they are not on the screen yet.
306 // The value of |*rect| won't be changed when false is returned.
307 static bool ConvertRect(const Widget
* source
,
308 const Widget
* target
,
311 // Retrieves the Widget implementation associated with the given
312 // NativeView or Window, or NULL if the supplied handle has no associated
314 static Widget
* GetWidgetForNativeView(gfx::NativeView native_view
);
315 static Widget
* GetWidgetForNativeWindow(gfx::NativeWindow native_window
);
317 // Retrieves the top level widget in a native view hierarchy
318 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW,
319 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own
320 // focus manager. This may be itself if the |native_view| is top level,
321 // or NULL if there is no toplevel in a native view hierarchy.
322 static Widget
* GetTopLevelWidgetForNativeView(gfx::NativeView native_view
);
324 // Returns all Widgets in |native_view|'s hierarchy, including itself if
326 static void GetAllChildWidgets(gfx::NativeView native_view
,
329 // Returns all Widgets owned by |native_view| (including child widgets, but
330 // not including itself).
331 static void GetAllOwnedWidgets(gfx::NativeView native_view
,
334 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
336 static void ReparentNativeView(gfx::NativeView native_view
,
337 gfx::NativeView new_parent
);
339 // Returns the preferred size of the contents view of this window based on
340 // its localized size data. The width in cols is held in a localized string
341 // resource identified by |col_resource_id|, the height in the same fashion.
342 // TODO(beng): This should eventually live somewhere else, probably closer to
344 static int GetLocalizedContentsWidth(int col_resource_id
);
345 static int GetLocalizedContentsHeight(int row_resource_id
);
346 static gfx::Size
GetLocalizedContentsSize(int col_resource_id
,
347 int row_resource_id
);
349 // Returns true if the specified type requires a NonClientView.
350 static bool RequiresNonClientView(InitParams::Type type
);
352 void Init(const InitParams
& params
);
354 // Returns the gfx::NativeView associated with this Widget.
355 gfx::NativeView
GetNativeView() const;
357 // Returns the gfx::NativeWindow associated with this Widget. This may return
358 // NULL on some platforms if the widget was created with a type other than
359 // TYPE_WINDOW or TYPE_PANEL.
360 gfx::NativeWindow
GetNativeWindow() const;
362 // Add/remove observer.
363 void AddObserver(WidgetObserver
* observer
);
364 void RemoveObserver(WidgetObserver
* observer
);
365 bool HasObserver(const WidgetObserver
* observer
) const;
367 // Add/remove removals observer.
368 void AddRemovalsObserver(WidgetRemovalsObserver
* observer
);
369 void RemoveRemovalsObserver(WidgetRemovalsObserver
* observer
);
370 bool HasRemovalsObserver(const WidgetRemovalsObserver
* observer
) const;
372 // Returns the accelerator given a command id. Returns false if there is
373 // no accelerator associated with a given id, which is a common condition.
374 virtual bool GetAccelerator(int cmd_id
, ui::Accelerator
* accelerator
) const;
376 // Forwarded from the RootView so that the widget can do any cleanup.
377 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails
& details
);
379 // Called right before changing the widget's parent NativeView to do any
381 void NotifyNativeViewHierarchyWillChange();
383 // Called after changing the widget's parent NativeView. Notifies the RootView
385 void NotifyNativeViewHierarchyChanged();
387 // Called immediately before removing |view| from this widget.
388 void NotifyWillRemoveView(View
* view
);
390 // Returns the top level widget in a hierarchy (see is_top_level() for
391 // the definition of top level widget.) Will return NULL if called
392 // before the widget is attached to the top level widget's hierarchy.
393 Widget
* GetTopLevelWidget();
394 const Widget
* GetTopLevelWidget() const;
396 // Gets/Sets the WidgetDelegate.
397 WidgetDelegate
* widget_delegate() const { return widget_delegate_
; }
399 // Sets the specified view as the contents of this Widget. There can only
400 // be one contents view child of this Widget's RootView. This view is sized to
401 // fit the entire size of the RootView. The RootView takes ownership of this
402 // View, unless it is set as not being parent-owned.
403 void SetContentsView(View
* view
);
404 View
* GetContentsView();
406 // Returns the bounds of the Widget in screen coordinates.
407 gfx::Rect
GetWindowBoundsInScreen() const;
409 // Returns the bounds of the Widget's client area in screen coordinates.
410 gfx::Rect
GetClientAreaBoundsInScreen() const;
412 // Retrieves the restored bounds for the window.
413 gfx::Rect
GetRestoredBounds() const;
415 // Sizes and/or places the widget to the specified bounds, size or position.
416 void SetBounds(const gfx::Rect
& bounds
);
417 void SetSize(const gfx::Size
& size
);
419 // Sizes the window to the specified size and centerizes it.
420 void CenterWindow(const gfx::Size
& size
);
422 // Like SetBounds(), but ensures the Widget is fully visible on screen,
423 // resizing and/or repositioning as necessary. This is only useful for
424 // non-child widgets.
425 void SetBoundsConstrained(const gfx::Rect
& bounds
);
427 // Sets whether animations that occur when visibility is changed are enabled.
429 void SetVisibilityChangedAnimationsEnabled(bool value
);
431 // Sets the duration of visibility change animations.
432 void SetVisibilityAnimationDuration(const base::TimeDelta
& duration
);
434 // Sets the visibility transitions that should animate.
435 // Default behavior is to animate both show and hide.
436 void SetVisibilityAnimationTransition(VisibilityTransition transition
);
438 // Starts a nested message loop that moves the window. This can be used to
439 // start a window move operation from a mouse or touch event. This returns
440 // when the move completes. |drag_offset| is the offset from the top left
441 // corner of the window to the point where the cursor is dragging, and is used
442 // to offset the bounds of the window from the cursor.
443 MoveLoopResult
RunMoveLoop(const gfx::Vector2d
& drag_offset
,
444 MoveLoopSource source
,
445 MoveLoopEscapeBehavior escape_behavior
);
447 // Stops a previously started move loop. This is not immediate.
450 // Places the widget in front of the specified widget in z-order.
451 void StackAboveWidget(Widget
* widget
);
452 void StackAbove(gfx::NativeView native_view
);
455 // Places the widget below the specified NativeView.
456 void StackBelow(gfx::NativeView native_view
);
458 // Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
459 // be rectangular. Takes ownership of |shape|.
460 void SetShape(SkRegion
* shape
);
462 // Hides the widget then closes it after a return to the message loop.
463 virtual void Close();
465 // TODO(beng): Move off public API.
466 // Closes the widget immediately. Compare to |Close|. This will destroy the
467 // window handle associated with this Widget, so should not be called from
468 // any code that expects it to be valid beyond this call.
471 // Whether the widget has been asked to close itself. In particular this is
472 // set to true after Close() has been invoked on the NativeWidget.
473 bool IsClosed() const;
475 // Shows the widget. The widget is activated if during initialization the
476 // can_activate flag in the InitParams structure is set to true.
481 // Like Show(), but does not activate the window.
484 // Activates the widget, assuming it already exists and is visible.
487 // Deactivates the widget, making the next window in the Z order the active
491 // Returns whether the Widget is the currently active window.
492 virtual bool IsActive() const;
494 // Prevents the window from being rendered as deactivated. This state is
495 // reset automatically as soon as the window becomes activated again. There is
496 // no ability to control the state through this API as this leads to sync
498 void DisableInactiveRendering();
500 // Sets the widget to be on top of all other widgets in the windowing system.
501 void SetAlwaysOnTop(bool on_top
);
503 // Returns whether the widget has been set to be on top of most other widgets
504 // in the windowing system.
505 bool IsAlwaysOnTop() const;
507 // Sets the widget to be visible on all work spaces.
508 void SetVisibleOnAllWorkspaces(bool always_visible
);
510 // Maximizes/minimizes/restores the window.
515 // Whether or not the window is maximized or minimized.
516 virtual bool IsMaximized() const;
517 bool IsMinimized() const;
519 // Accessors for fullscreen state.
520 void SetFullscreen(bool fullscreen
);
521 bool IsFullscreen() const;
523 // Sets the opacity of the widget. This may allow widgets behind the widget
524 // in the Z-order to become visible, depending on the capabilities of the
525 // underlying windowing system.
526 void SetOpacity(unsigned char opacity
);
528 // Sets whether or not the window should show its frame as a "transient drag
529 // frame" - slightly transparent and without the standard window controls.
530 void SetUseDragFrame(bool use_drag_frame
);
532 // Flashes the frame of the window to draw attention to it. Currently only
533 // implemented on Windows for non-Aura.
534 void FlashFrame(bool flash
);
536 // Returns the View at the root of the View hierarchy contained by this
539 const View
* GetRootView() const;
541 // A secondary widget is one that is automatically closed (via Close()) when
542 // all non-secondary widgets are closed.
544 // TODO(beng): This is an ugly API, should be handled implicitly via
546 void set_is_secondary_widget(bool is_secondary_widget
) {
547 is_secondary_widget_
= is_secondary_widget
;
549 bool is_secondary_widget() const { return is_secondary_widget_
; }
551 // Returns whether the Widget is visible to the user.
552 virtual bool IsVisible() const;
554 // Returns the ThemeProvider that provides theme resources for this Widget.
555 virtual ui::ThemeProvider
* GetThemeProvider() const;
557 ui::NativeTheme
* GetNativeTheme() {
558 return const_cast<ui::NativeTheme
*>(
559 const_cast<const Widget
*>(this)->GetNativeTheme());
561 const ui::NativeTheme
* GetNativeTheme() const;
563 // Returns the FocusManager for this widget.
564 // Note that all widgets in a widget hierarchy share the same focus manager.
565 FocusManager
* GetFocusManager();
566 const FocusManager
* GetFocusManager() const;
568 // Returns the ui::InputMethod for this widget.
569 ui::InputMethod
* GetInputMethod();
571 // Starts a drag operation for the specified view. This blocks until the drag
572 // operation completes. |view| can be NULL.
573 // If the view is non-NULL it can be accessed during the drag by calling
574 // dragged_view(). If the view has not been deleted during the drag,
575 // OnDragDone() is called on it. |location| is in the widget's coordinate
577 void RunShellDrag(View
* view
,
578 const ui::OSExchangeData
& data
,
579 const gfx::Point
& location
,
581 ui::DragDropTypes::DragEventSource source
);
583 // Returns the view that requested the current drag operation via
584 // RunShellDrag(), or NULL if there is no such view or drag operation.
585 View
* dragged_view() { return dragged_view_
; }
587 // Adds the specified |rect| in client area coordinates to the rectangle to be
589 virtual void SchedulePaintInRect(const gfx::Rect
& rect
);
591 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
592 // before the current is restored.
593 void SetCursor(gfx::NativeCursor cursor
);
595 // Returns true if and only if mouse events are enabled.
596 bool IsMouseEventsEnabled() const;
598 // Sets/Gets a native window property on the underlying native window object.
599 // Returns NULL if the property does not exist. Setting the property value to
600 // NULL removes the property.
601 void SetNativeWindowProperty(const char* name
, void* value
);
602 void* GetNativeWindowProperty(const char* name
) const;
604 // Tell the window to update its title from the delegate.
605 void UpdateWindowTitle();
607 // Tell the window to update its icon from the delegate.
608 void UpdateWindowIcon();
610 // Retrieves the focus traversable for this widget.
611 FocusTraversable
* GetFocusTraversable();
613 // Notifies the view hierarchy contained in this widget that theme resources
617 // Notifies the view hierarchy contained in this widget that locale resources
619 void LocaleChanged();
621 // Notifies the view hierarchy contained in this widget that the device scale
623 void DeviceScaleFactorChanged(float device_scale_factor
);
625 void SetFocusTraversableParent(FocusTraversable
* parent
);
626 void SetFocusTraversableParentView(View
* parent_view
);
628 // Clear native focus set to the Widget's NativeWidget.
629 void ClearNativeFocus();
631 void set_frame_type(FrameType frame_type
) { frame_type_
= frame_type
; }
632 FrameType
frame_type() const { return frame_type_
; }
634 // Creates an appropriate NonClientFrameView for this widget. The
635 // WidgetDelegate is given the first opportunity to create one, followed by
636 // the NativeWidget implementation. If both return NULL, a default one is
638 virtual NonClientFrameView
* CreateNonClientFrameView();
640 // Whether we should be using a native frame.
641 bool ShouldUseNativeFrame() const;
643 // Determines whether the window contents should be rendered transparently
644 // (for example, so that they can overhang onto the window title bar).
645 bool ShouldWindowContentsBeTransparent() const;
647 // Forces the frame into the alternate frame type (custom or native) depending
648 // on its current state.
649 void DebugToggleFrameType();
651 // Tell the window that something caused the frame type to change.
652 void FrameTypeChanged();
654 NonClientView
* non_client_view() {
655 return const_cast<NonClientView
*>(
656 const_cast<const Widget
*>(this)->non_client_view());
658 const NonClientView
* non_client_view() const {
659 return non_client_view_
;
662 ClientView
* client_view() {
663 return const_cast<ClientView
*>(
664 const_cast<const Widget
*>(this)->client_view());
666 const ClientView
* client_view() const {
667 // non_client_view_ may be NULL, especially during creation.
668 return non_client_view_
? non_client_view_
->client_view() : NULL
;
671 ui::Compositor
* GetCompositor() {
672 return const_cast<ui::Compositor
*>(
673 const_cast<const Widget
*>(this)->GetCompositor());
675 const ui::Compositor
* GetCompositor() const;
677 // Returns the widget's layer, if any.
678 ui::Layer
* GetLayer() {
679 return const_cast<ui::Layer
*>(
680 const_cast<const Widget
*>(this)->GetLayer());
682 const ui::Layer
* GetLayer() const;
684 // Reorders the widget's child NativeViews which are associated to the view
685 // tree (eg via a NativeViewHost) to match the z-order of the views in the
686 // view tree. The z-order of views with layers relative to views with
687 // associated NativeViews is used to reorder the NativeView layers. This
688 // method assumes that the widget's child layers which are owned by a view are
689 // already in the correct z-order relative to each other and does no
690 // reordering if there are no views with an associated NativeView.
691 void ReorderNativeViews();
693 // Schedules an update to the root layers. The actual processing occurs when
694 // GetRootLayers() is invoked.
695 void UpdateRootLayers();
697 const NativeWidget
* native_widget() const;
698 NativeWidget
* native_widget();
700 internal::NativeWidgetPrivate
* native_widget_private() {
701 return native_widget_
;
703 const internal::NativeWidgetPrivate
* native_widget_private() const {
704 return native_widget_
;
707 // Sets capture to the specified view. This makes it so that all mouse, touch
708 // and gesture events go to |view|. If |view| is NULL, the widget still
709 // obtains event capture, but the events will go to the view they'd normally
711 void SetCapture(View
* view
);
714 void ReleaseCapture();
716 // Returns true if the widget has capture.
719 void set_auto_release_capture(bool auto_release_capture
) {
720 auto_release_capture_
= auto_release_capture
;
723 // Returns the font used for tooltips.
724 TooltipManager
* GetTooltipManager();
725 const TooltipManager
* GetTooltipManager() const;
727 void set_focus_on_creation(bool focus_on_creation
) {
728 focus_on_creation_
= focus_on_creation
;
731 // True if the widget is considered top level widget. Top level widget
732 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE,
733 // POPUP or MENU, and has a focus manager and input method object associated
734 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
735 bool is_top_level() const { return is_top_level_
; }
737 // True when window movement via mouse interaction with the frame is disabled.
738 bool movement_disabled() const { return movement_disabled_
; }
739 void set_movement_disabled(bool disabled
) { movement_disabled_
= disabled
; }
741 // Returns the work area bounds of the screen the Widget belongs to.
742 gfx::Rect
GetWorkAreaBoundsInScreen() const;
744 // Creates and dispatches synthesized mouse move event using the current
745 // mouse location to refresh hovering status in the widget.
746 void SynthesizeMouseMoveEvent();
748 // Called by our RootView after it has performed a Layout. Used to forward
749 // window sizing information to the window server on some platforms.
750 void OnRootViewLayout();
752 // Whether the widget supports translucency.
753 bool IsTranslucentWindowOpacitySupported() const;
755 // Called when the delegate's CanResize or CanMaximize changes.
756 void OnSizeConstraintsChanged();
758 // Notification that our owner is closing.
759 // NOTE: this is not invoked for aura as it's currently not needed there.
760 // Under aura menus close by way of activation getting reset when the owner
762 virtual void OnOwnerClosing();
764 // Overridden from NativeWidgetDelegate:
765 bool IsModal() const override
;
766 bool IsDialogBox() const override
;
767 bool CanActivate() const override
;
768 bool IsInactiveRenderingDisabled() const override
;
769 void EnableInactiveRendering() override
;
770 void OnNativeWidgetActivationChanged(bool active
) override
;
771 void OnNativeFocus() override
;
772 void OnNativeBlur() override
;
773 void OnNativeWidgetVisibilityChanging(bool visible
) override
;
774 void OnNativeWidgetVisibilityChanged(bool visible
) override
;
775 void OnNativeWidgetCreated(bool desktop_widget
) override
;
776 void OnNativeWidgetDestroying() override
;
777 void OnNativeWidgetDestroyed() override
;
778 gfx::Size
GetMinimumSize() const override
;
779 gfx::Size
GetMaximumSize() const override
;
780 void OnNativeWidgetMove() override
;
781 void OnNativeWidgetSizeChanged(const gfx::Size
& new_size
) override
;
782 void OnNativeWidgetWindowShowStateChanged() override
;
783 void OnNativeWidgetBeginUserBoundsChange() override
;
784 void OnNativeWidgetEndUserBoundsChange() override
;
785 bool HasFocusManager() const override
;
786 void OnNativeWidgetPaint(const ui::PaintContext
& context
) override
;
787 int GetNonClientComponent(const gfx::Point
& point
) override
;
788 void OnKeyEvent(ui::KeyEvent
* event
) override
;
789 void OnMouseEvent(ui::MouseEvent
* event
) override
;
790 void OnMouseCaptureLost() override
;
791 void OnScrollEvent(ui::ScrollEvent
* event
) override
;
792 void OnGestureEvent(ui::GestureEvent
* event
) override
;
793 bool ExecuteCommand(int command_id
) override
;
794 const std::vector
<ui::Layer
*>& GetRootLayers() override
;
795 bool HasHitTestMask() const override
;
796 void GetHitTestMask(gfx::Path
* mask
) const override
;
797 Widget
* AsWidget() override
;
798 const Widget
* AsWidget() const override
;
799 bool SetInitialFocus(ui::WindowShowState show_state
) override
;
801 // Overridden from ui::EventSource:
802 ui::EventProcessor
* GetEventProcessor() override
;
804 // Overridden from FocusTraversable:
805 FocusSearch
* GetFocusSearch() override
;
806 FocusTraversable
* GetFocusTraversableParent() override
;
807 View
* GetFocusTraversableParentView() override
;
809 // Overridden from ui::NativeThemeObserver:
810 void OnNativeThemeUpdated(ui::NativeTheme
* observed_theme
) override
;
813 // Creates the RootView to be used within this Widget. Subclasses may override
814 // to create custom RootViews that do specialized event processing.
815 // TODO(beng): Investigate whether or not this is needed.
816 virtual internal::RootView
* CreateRootView();
818 // Provided to allow the NativeWidget implementations to destroy the RootView
819 // _before_ the focus manager/tooltip manager.
820 // TODO(beng): remove once we fold those objects onto this one.
821 void DestroyRootView();
823 // Notification that a drag will start. Default implementation does nothing.
824 virtual void OnDragWillStart();
826 // Notification that the drag performed by RunShellDrag() has completed.
827 virtual void OnDragComplete();
830 friend class ComboboxTest
;
831 friend class TextfieldTest
;
833 // Sets the value of |disable_inactive_rendering_|. If the value changes,
834 // both the NonClientView and WidgetDelegate are notified.
835 void SetInactiveRenderingDisabled(bool value
);
837 // Persists the window's restored position and "show" state using the
839 void SaveWindowPlacement();
841 // Invokes SaveWindowPlacement() if the native widget has been initialized.
842 // This is called at times when the native widget may not have been
844 void SaveWindowPlacementIfInitialized();
846 // Sizes and positions the window just after it is created.
847 void SetInitialBounds(const gfx::Rect
& bounds
);
849 // Sizes and positions the frameless window just after it is created.
850 void SetInitialBoundsForFramelessWindow(const gfx::Rect
& bounds
);
852 // Returns the bounds and "show" state from the delegate. Returns true if
853 // the delegate wants to use a specified bounds.
854 bool GetSavedWindowPlacement(gfx::Rect
* bounds
,
855 ui::WindowShowState
* show_state
);
857 internal::NativeWidgetPrivate
* native_widget_
;
859 base::ObserverList
<WidgetObserver
> observers_
;
861 base::ObserverList
<WidgetRemovalsObserver
> removals_observers_
;
863 // Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
864 // to Init() a default WidgetDelegate is created.
865 WidgetDelegate
* widget_delegate_
;
867 // The root of the View hierarchy attached to this window.
868 // WARNING: see warning in tooltip_manager_ for ordering dependencies with
869 // this and tooltip_manager_.
870 scoped_ptr
<internal::RootView
> root_view_
;
872 // The View that provides the non-client area of the window (title bar,
873 // window controls, sizing borders etc). To use an implementation other than
874 // the default, this class must be sub-classed and this value set to the
875 // desired implementation before calling |InitWindow()|.
876 NonClientView
* non_client_view_
;
878 // The focus manager keeping track of focus for this Widget and any of its
879 // children. NULL for non top-level widgets.
880 // WARNING: RootView's destructor calls into the FocusManager. As such, this
881 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView().
882 scoped_ptr
<FocusManager
> focus_manager_
;
884 // A theme provider to use when no other theme provider is specified.
885 scoped_ptr
<ui::DefaultThemeProvider
> default_theme_provider_
;
887 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
891 // See class documentation for Widget above for a note about ownership.
892 InitParams::Ownership ownership_
;
894 // See set_is_secondary_widget().
895 bool is_secondary_widget_
;
897 // The current frame type in use by this window. Defaults to
898 // FRAME_TYPE_DEFAULT.
899 FrameType frame_type_
;
901 // True when the window should be rendered as active, regardless of whether
902 // or not it actually is.
903 bool disable_inactive_rendering_
;
905 // Set to true if the widget is in the process of closing.
908 // The saved "show" state for this window. See note in SetInitialBounds
909 // that explains why we save this.
910 ui::WindowShowState saved_show_state_
;
912 // The restored bounds used for the initial show. This is only used if
913 // |saved_show_state_| is maximized.
914 gfx::Rect initial_restored_bounds_
;
916 // Focus is automatically set to the view provided by the delegate
917 // when the widget is shown. Set this value to false to override
918 // initial focus for the widget.
919 bool focus_on_creation_
;
921 // See |is_top_level()| accessor.
924 // Tracks whether native widget has been initialized.
925 bool native_widget_initialized_
;
927 // Whether native widget has been destroyed.
928 bool native_widget_destroyed_
;
930 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
931 // If true, the mouse is currently down.
932 bool is_mouse_button_pressed_
;
934 // True if capture losses should be ignored.
935 bool ignore_capture_loss_
;
937 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
938 // The following are used to detect duplicate mouse move events and not
939 // deliver them. Displaying a window may result in the system generating
940 // duplicate move events even though the mouse hasn't moved.
941 bool last_mouse_event_was_move_
;
942 gfx::Point last_mouse_event_position_
;
944 // True if event capture should be released on a mouse up event. Default is
946 bool auto_release_capture_
;
948 // See description in GetRootLayers().
949 std::vector
<ui::Layer
*> root_layers_
;
951 // Is |root_layers_| out of date?
952 bool root_layers_dirty_
;
954 // True when window movement via mouse interaction with the frame should be
956 bool movement_disabled_
;
958 ScopedObserver
<ui::NativeTheme
, ui::NativeThemeObserver
> observer_manager_
;
960 DISALLOW_COPY_AND_ASSIGN(Widget
);
965 #endif // UI_VIEWS_WIDGET_WIDGET_H_