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/aura/window_layer_type.h"
17 #include "ui/base/ui_base_types.h"
18 #include "ui/events/event_source.h"
19 #include "ui/gfx/native_widget_types.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/native_theme/native_theme_observer.h"
22 #include "ui/views/focus/focus_manager.h"
23 #include "ui/views/widget/native_widget_delegate.h"
24 #include "ui/views/window/client_view.h"
25 #include "ui/views/window/non_client_view.h"
28 // Windows headers define macros for these function names which screw with us.
29 #if defined(IsMaximized)
32 #if defined(IsMinimized)
35 #if defined(CreateWindow)
49 class DefaultThemeProvider
;
59 class DesktopWindowTreeHost
;
62 class NonClientFrameView
;
67 class WidgetRemovalsObserver
;
70 class NativeWidgetPrivate
;
74 ////////////////////////////////////////////////////////////////////////////////
77 // Encapsulates the platform-specific rendering, event receiving and widget
78 // management aspects of the UI framework.
80 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
81 // Widget is a platform-independent type that communicates with a platform or
82 // context specific NativeWidget implementation.
84 // A special note on ownership:
86 // Depending on the value of the InitParams' ownership field, the Widget
87 // either owns or is owned by its NativeWidget:
89 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default)
90 // The Widget instance is owned by its NativeWidget. When the NativeWidget
91 // is destroyed (in response to a native destruction message), it deletes
92 // the Widget from its destructor.
93 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default)
94 // The Widget instance owns its NativeWidget. This state implies someone
95 // else wants to control the lifetime of this object. When they destroy
96 // the Widget it is responsible for destroying the NativeWidget (from its
99 class VIEWS_EXPORT Widget
: public internal::NativeWidgetDelegate
,
100 public ui::EventSource
,
101 public FocusTraversable
,
102 public ui::NativeThemeObserver
{
104 typedef std::set
<Widget
*> Widgets
;
107 FRAME_TYPE_DEFAULT
, // Use whatever the default would be.
108 FRAME_TYPE_FORCE_CUSTOM
, // Force the custom frame.
109 FRAME_TYPE_FORCE_NATIVE
// Force the native frame.
112 // Result from RunMoveLoop().
113 enum MoveLoopResult
{
114 // The move loop completed successfully.
115 MOVE_LOOP_SUCCESSFUL
,
117 // The user canceled the move loop.
121 // Source that initiated the move loop.
122 enum MoveLoopSource
{
123 MOVE_LOOP_SOURCE_MOUSE
,
124 MOVE_LOOP_SOURCE_TOUCH
,
127 // Behavior when escape is pressed during a move loop.
128 enum MoveLoopEscapeBehavior
{
129 // Indicates the window should be hidden.
130 MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE
,
132 // Indicates the window should not be hidden.
133 MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE
,
136 struct VIEWS_EXPORT InitParams
{
138 TYPE_WINDOW
, // A decorated Window, like a frame window.
139 // Widgets of TYPE_WINDOW will have a NonClientView.
140 TYPE_PANEL
, // Always on top window managed by PanelManager.
141 // Widgets of TYPE_PANEL will have a NonClientView.
142 TYPE_WINDOW_FRAMELESS
,
143 // An undecorated Window.
144 TYPE_CONTROL
, // A control, like a button.
145 TYPE_POPUP
, // An undecorated Window, with transient properties.
146 TYPE_MENU
, // An undecorated Window, with transient properties
147 // specialized to menus.
150 TYPE_DRAG
, // An undecorated Window, used during a drag-and-drop to
151 // show the drag image.
155 // Infer fully opaque or not. For WinAura, top-level windows that are not
156 // of TYPE_WINDOW are translucent so that they can be made to fade in. In
157 // all other cases, windows are fully opaque.
161 // Possibly translucent/transparent.
166 // Infer whether the window should be activatable from the window type.
174 // Default. Creator is not responsible for managing the lifetime of the
175 // Widget, it is destroyed when the corresponding NativeWidget is
177 NATIVE_WIDGET_OWNS_WIDGET
,
178 // Used when the Widget is owned by someone other than the NativeWidget,
179 // e.g. a scoped_ptr in tests.
180 WIDGET_OWNS_NATIVE_WIDGET
184 SHADOW_TYPE_DEFAULT
, // Use default shadow setting. It will be one of
185 // the settings below depending on InitParams::type
186 // and the native widget's type.
187 SHADOW_TYPE_NONE
, // Don't draw any shadow.
188 SHADOW_TYPE_DROP
, // Draw a drop shadow that emphasizes Z-order
189 // relationship to other windows.
193 explicit InitParams(Type type
);
197 // If NULL, a default implementation will be constructed.
198 WidgetDelegate
* delegate
;
200 // If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
201 // Translucent windows may not always be supported. Use
202 // IsTranslucentWindowOpacitySupported to determine if translucent windows
204 // If OPAQUE_WINDOW, we can perform optimizations based on the widget being
205 // fully opaque. Defaults to TRANSLUCENT_WINDOW if
206 // ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
207 // non-window widgets.
208 WindowOpacity opacity
;
210 Activatable activatable
;
212 bool visible_on_all_workspaces
;
214 bool mirror_origin_in_rtl
;
215 ShadowType shadow_type
;
216 // Specifies that the system default caption and icon should not be
217 // rendered, and that the client area should be equivalent to the window
218 // area. Only used on some platforms (Windows and Linux).
219 bool remove_standard_frame
;
220 // Only used by ShellWindow on Windows. Specifies that the default icon of
221 // packaged app should be the system default icon.
222 bool use_system_default_icon
;
223 // Whether the widget should be maximized or minimized.
224 ui::WindowShowState show_state
;
225 // Should the widget be double buffered? Default is false.
227 gfx::NativeView parent
;
228 // Specifies the initial bounds of the Widget. Default is empty, which means
229 // the NativeWidget may specify a default size. If the parent is specified,
230 // |bounds| is in the parent's coordinate system. If the parent is not
231 // specified, it's in screen's global coordinate system.
233 // When set, this value is used as the Widget's NativeWidget implementation.
234 // The Widget will not construct a default one. Default is NULL.
235 NativeWidget
* native_widget
;
236 // Aura-only. Provides a DesktopWindowTreeHost implementation to use instead
237 // of the default one.
238 // TODO(beng): Figure out if there's a better way to expose this, e.g. get
239 // rid of NW subclasses and do this all via message handling.
240 DesktopWindowTreeHost
* desktop_window_tree_host
;
241 // Only used by NativeWidgetAura. Specifies the type of layer for the
242 // aura::Window. Default is WINDOW_LAYER_TEXTURED.
243 aura::WindowLayerType layer_type
;
244 // Only used by Aura. Provides a context window whose RootWindow is
245 // consulted during widget creation to determine where in the Window
246 // hierarchy this widget should be placed. (This is separate from |parent|;
247 // if you pass a RootWindow to |parent|, your window will be parented to
248 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
249 // where it wants your window placed.) NULL is not allowed if you are using
251 gfx::NativeWindow context
;
252 // If true, forces the window to be shown in the taskbar, even for window
253 // types that do not appear in the taskbar by default (popup and bubble).
254 bool force_show_in_taskbar
;
255 // Only used by X11, for root level windows. Specifies the res_name and
256 // res_class fields, respectively, of the WM_CLASS window property. Controls
257 // window grouping and desktop file matching in Linux window managers.
258 std::string wm_role_name
;
259 std::string wm_class_name
;
260 std::string wm_class_class
;
266 // Creates a toplevel window with no context. These methods should only be
267 // used in cases where there is no contextual information because we're
268 // creating a toplevel window connected to no other event.
270 // If you have any parenting or context information, or can pass that
271 // information, prefer the WithParent or WithContext versions of these
273 static Widget
* CreateWindow(WidgetDelegate
* delegate
);
274 static Widget
* CreateWindowWithBounds(WidgetDelegate
* delegate
,
275 const gfx::Rect
& bounds
);
277 // Creates a decorated window Widget with the specified properties.
278 static Widget
* CreateWindowWithParent(WidgetDelegate
* delegate
,
279 gfx::NativeView parent
);
280 static Widget
* CreateWindowWithParentAndBounds(WidgetDelegate
* delegate
,
281 gfx::NativeView parent
,
282 const gfx::Rect
& bounds
);
284 // Creates a decorated window Widget in the same desktop context as |context|.
285 static Widget
* CreateWindowWithContext(WidgetDelegate
* delegate
,
286 gfx::NativeWindow context
);
287 static Widget
* CreateWindowWithContextAndBounds(WidgetDelegate
* delegate
,
288 gfx::NativeWindow context
,
289 const gfx::Rect
& bounds
);
291 // Closes all Widgets that aren't identified as "secondary widgets". Called
292 // during application shutdown when the last non-secondary widget is closed.
293 static void CloseAllSecondaryWidgets();
295 // Converts a rectangle from one Widget's coordinate system to another's.
296 // Returns false if the conversion couldn't be made, because either these two
297 // Widgets do not have a common ancestor or they are not on the screen yet.
298 // The value of |*rect| won't be changed when false is returned.
299 static bool ConvertRect(const Widget
* source
,
300 const Widget
* target
,
303 // Retrieves the Widget implementation associated with the given
304 // NativeView or Window, or NULL if the supplied handle has no associated
306 static Widget
* GetWidgetForNativeView(gfx::NativeView native_view
);
307 static Widget
* GetWidgetForNativeWindow(gfx::NativeWindow native_window
);
309 // Retrieves the top level widget in a native view hierarchy
310 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW,
311 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own
312 // focus manager. This may be itself if the |native_view| is top level,
313 // or NULL if there is no toplevel in a native view hierarchy.
314 static Widget
* GetTopLevelWidgetForNativeView(gfx::NativeView native_view
);
316 // Returns all Widgets in |native_view|'s hierarchy, including itself if
318 static void GetAllChildWidgets(gfx::NativeView native_view
,
321 // Returns all Widgets owned by |native_view| (including child widgets, but
322 // not including itself).
323 static void GetAllOwnedWidgets(gfx::NativeView native_view
,
326 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
328 static void ReparentNativeView(gfx::NativeView native_view
,
329 gfx::NativeView new_parent
);
331 // Returns the preferred size of the contents view of this window based on
332 // its localized size data. The width in cols is held in a localized string
333 // resource identified by |col_resource_id|, the height in the same fashion.
334 // TODO(beng): This should eventually live somewhere else, probably closer to
336 static int GetLocalizedContentsWidth(int col_resource_id
);
337 static int GetLocalizedContentsHeight(int row_resource_id
);
338 static gfx::Size
GetLocalizedContentsSize(int col_resource_id
,
339 int row_resource_id
);
341 // Returns true if the specified type requires a NonClientView.
342 static bool RequiresNonClientView(InitParams::Type type
);
344 void Init(const InitParams
& params
);
346 // Returns the gfx::NativeView associated with this Widget.
347 gfx::NativeView
GetNativeView() const;
349 // Returns the gfx::NativeWindow associated with this Widget. This may return
350 // NULL on some platforms if the widget was created with a type other than
351 // TYPE_WINDOW or TYPE_PANEL.
352 gfx::NativeWindow
GetNativeWindow() const;
354 // Add/remove observer.
355 void AddObserver(WidgetObserver
* observer
);
356 void RemoveObserver(WidgetObserver
* observer
);
357 bool HasObserver(WidgetObserver
* observer
);
359 // Add/remove removals observer.
360 void AddRemovalsObserver(WidgetRemovalsObserver
* observer
);
361 void RemoveRemovalsObserver(WidgetRemovalsObserver
* observer
);
362 bool HasRemovalsObserver(WidgetRemovalsObserver
* observer
);
364 // Returns the accelerator given a command id. Returns false if there is
365 // no accelerator associated with a given id, which is a common condition.
366 virtual bool GetAccelerator(int cmd_id
, ui::Accelerator
* accelerator
) const;
368 // Forwarded from the RootView so that the widget can do any cleanup.
369 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails
& details
);
371 // Called right before changing the widget's parent NativeView to do any
373 void NotifyNativeViewHierarchyWillChange();
375 // Called after changing the widget's parent NativeView. Notifies the RootView
377 void NotifyNativeViewHierarchyChanged();
379 // Called immediately before removing |view| from this widget.
380 void NotifyWillRemoveView(View
* view
);
382 // Returns the top level widget in a hierarchy (see is_top_level() for
383 // the definition of top level widget.) Will return NULL if called
384 // before the widget is attached to the top level widget's hierarchy.
385 Widget
* GetTopLevelWidget();
386 const Widget
* GetTopLevelWidget() const;
388 // Gets/Sets the WidgetDelegate.
389 WidgetDelegate
* widget_delegate() const { return widget_delegate_
; }
391 // Sets the specified view as the contents of this Widget. There can only
392 // be one contents view child of this Widget's RootView. This view is sized to
393 // fit the entire size of the RootView. The RootView takes ownership of this
394 // View, unless it is set as not being parent-owned.
395 void SetContentsView(View
* view
);
396 View
* GetContentsView();
398 // Returns the bounds of the Widget in screen coordinates.
399 gfx::Rect
GetWindowBoundsInScreen() const;
401 // Returns the bounds of the Widget's client area in screen coordinates.
402 gfx::Rect
GetClientAreaBoundsInScreen() const;
404 // Retrieves the restored bounds for the window.
405 gfx::Rect
GetRestoredBounds() const;
407 // Sizes and/or places the widget to the specified bounds, size or position.
408 void SetBounds(const gfx::Rect
& bounds
);
409 void SetSize(const gfx::Size
& size
);
411 // Sizes the window to the specified size and centerizes it.
412 void CenterWindow(const gfx::Size
& size
);
414 // Like SetBounds(), but ensures the Widget is fully visible on screen,
415 // resizing and/or repositioning as necessary. This is only useful for
416 // non-child widgets.
417 void SetBoundsConstrained(const gfx::Rect
& bounds
);
419 // Sets whether animations that occur when visibility is changed are enabled.
421 void SetVisibilityChangedAnimationsEnabled(bool value
);
423 // Starts a nested message loop that moves the window. This can be used to
424 // start a window move operation from a mouse or touch event. This returns
425 // when the move completes. |drag_offset| is the offset from the top left
426 // corner of the window to the point where the cursor is dragging, and is used
427 // to offset the bounds of the window from the cursor.
428 MoveLoopResult
RunMoveLoop(const gfx::Vector2d
& drag_offset
,
429 MoveLoopSource source
,
430 MoveLoopEscapeBehavior escape_behavior
);
432 // Stops a previously started move loop. This is not immediate.
435 // Places the widget in front of the specified widget in z-order.
436 void StackAboveWidget(Widget
* widget
);
437 void StackAbove(gfx::NativeView native_view
);
440 // Places the widget below the specified NativeView.
441 void StackBelow(gfx::NativeView native_view
);
443 // Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
444 // be rectangular. Takes ownership of |shape|.
445 void SetShape(gfx::NativeRegion shape
);
447 // Hides the widget then closes it after a return to the message loop.
448 virtual void Close();
450 // TODO(beng): Move off public API.
451 // Closes the widget immediately. Compare to |Close|. This will destroy the
452 // window handle associated with this Widget, so should not be called from
453 // any code that expects it to be valid beyond this call.
456 // Whether the widget has been asked to close itself. In particular this is
457 // set to true after Close() has been invoked on the NativeWidget.
458 bool IsClosed() const;
460 // Shows the widget. The widget is activated if during initialization the
461 // can_activate flag in the InitParams structure is set to true.
466 // Like Show(), but does not activate the window.
469 // Activates the widget, assuming it already exists and is visible.
472 // Deactivates the widget, making the next window in the Z order the active
476 // Returns whether the Widget is the currently active window.
477 virtual bool IsActive() const;
479 // Prevents the window from being rendered as deactivated. This state is
480 // reset automatically as soon as the window becomes activated again. There is
481 // no ability to control the state through this API as this leads to sync
483 void DisableInactiveRendering();
485 // Sets the widget to be on top of all other widgets in the windowing system.
486 void SetAlwaysOnTop(bool on_top
);
488 // Returns whether the widget has been set to be on top of most other widgets
489 // in the windowing system.
490 bool IsAlwaysOnTop() const;
492 // Sets the widget to be visible on all work spaces.
493 void SetVisibleOnAllWorkspaces(bool always_visible
);
495 // Maximizes/minimizes/restores the window.
500 // Whether or not the window is maximized or minimized.
501 virtual bool IsMaximized() const;
502 bool IsMinimized() const;
504 // Accessors for fullscreen state.
505 void SetFullscreen(bool fullscreen
);
506 bool IsFullscreen() const;
508 // Sets the opacity of the widget. This may allow widgets behind the widget
509 // in the Z-order to become visible, depending on the capabilities of the
510 // underlying windowing system.
511 void SetOpacity(unsigned char opacity
);
513 // Sets whether or not the window should show its frame as a "transient drag
514 // frame" - slightly transparent and without the standard window controls.
515 void SetUseDragFrame(bool use_drag_frame
);
517 // Flashes the frame of the window to draw attention to it. Currently only
518 // implemented on Windows for non-Aura.
519 void FlashFrame(bool flash
);
521 // Returns the View at the root of the View hierarchy contained by this
524 const View
* GetRootView() const;
526 // A secondary widget is one that is automatically closed (via Close()) when
527 // all non-secondary widgets are closed.
529 // TODO(beng): This is an ugly API, should be handled implicitly via
531 void set_is_secondary_widget(bool is_secondary_widget
) {
532 is_secondary_widget_
= is_secondary_widget
;
534 bool is_secondary_widget() const { return is_secondary_widget_
; }
536 // Returns whether the Widget is visible to the user.
537 virtual bool IsVisible() const;
539 // Returns the ThemeProvider that provides theme resources for this Widget.
540 virtual ui::ThemeProvider
* GetThemeProvider() const;
542 ui::NativeTheme
* GetNativeTheme() {
543 return const_cast<ui::NativeTheme
*>(
544 const_cast<const Widget
*>(this)->GetNativeTheme());
546 const ui::NativeTheme
* GetNativeTheme() const;
548 // Returns the FocusManager for this widget.
549 // Note that all widgets in a widget hierarchy share the same focus manager.
550 FocusManager
* GetFocusManager();
551 const FocusManager
* GetFocusManager() const;
553 // Returns the InputMethod for this widget.
554 // Note that all widgets in a widget hierarchy share the same input method.
555 InputMethod
* GetInputMethod();
556 const InputMethod
* GetInputMethod() const;
558 // Returns the ui::InputMethod for this widget.
559 // TODO(yukishiino): Rename this method to GetInputMethod once we remove
560 // views::InputMethod.
561 ui::InputMethod
* GetHostInputMethod();
563 // Starts a drag operation for the specified view. This blocks until the drag
564 // operation completes. |view| can be NULL.
565 // If the view is non-NULL it can be accessed during the drag by calling
566 // dragged_view(). If the view has not been deleted during the drag,
567 // OnDragDone() is called on it. |location| is in the widget's coordinate
569 void RunShellDrag(View
* view
,
570 const ui::OSExchangeData
& data
,
571 const gfx::Point
& location
,
573 ui::DragDropTypes::DragEventSource source
);
575 // Returns the view that requested the current drag operation via
576 // RunShellDrag(), or NULL if there is no such view or drag operation.
577 View
* dragged_view() { return dragged_view_
; }
579 // Adds the specified |rect| in client area coordinates to the rectangle to be
581 virtual void SchedulePaintInRect(const gfx::Rect
& rect
);
583 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
584 // before the current is restored.
585 void SetCursor(gfx::NativeCursor cursor
);
587 // Returns true if and only if mouse events are enabled.
588 bool IsMouseEventsEnabled() const;
590 // Sets/Gets a native window property on the underlying native window object.
591 // Returns NULL if the property does not exist. Setting the property value to
592 // NULL removes the property.
593 void SetNativeWindowProperty(const char* name
, void* value
);
594 void* GetNativeWindowProperty(const char* name
) const;
596 // Tell the window to update its title from the delegate.
597 void UpdateWindowTitle();
599 // Tell the window to update its icon from the delegate.
600 void UpdateWindowIcon();
602 // Retrieves the focus traversable for this widget.
603 FocusTraversable
* GetFocusTraversable();
605 // Notifies the view hierarchy contained in this widget that theme resources
609 // Notifies the view hierarchy contained in this widget that locale resources
611 void LocaleChanged();
613 void SetFocusTraversableParent(FocusTraversable
* parent
);
614 void SetFocusTraversableParentView(View
* parent_view
);
616 // Clear native focus set to the Widget's NativeWidget.
617 void ClearNativeFocus();
619 void set_frame_type(FrameType frame_type
) { frame_type_
= frame_type
; }
620 FrameType
frame_type() const { return frame_type_
; }
622 // Creates an appropriate NonClientFrameView for this widget. The
623 // WidgetDelegate is given the first opportunity to create one, followed by
624 // the NativeWidget implementation. If both return NULL, a default one is
626 virtual NonClientFrameView
* CreateNonClientFrameView();
628 // Whether we should be using a native frame.
629 bool ShouldUseNativeFrame() const;
631 // Determines whether the window contents should be rendered transparently
632 // (for example, so that they can overhang onto the window title bar).
633 bool ShouldWindowContentsBeTransparent() const;
635 // Forces the frame into the alternate frame type (custom or native) depending
636 // on its current state.
637 void DebugToggleFrameType();
639 // Tell the window that something caused the frame type to change.
640 void FrameTypeChanged();
642 NonClientView
* non_client_view() {
643 return const_cast<NonClientView
*>(
644 const_cast<const Widget
*>(this)->non_client_view());
646 const NonClientView
* non_client_view() const {
647 return non_client_view_
;
650 ClientView
* client_view() {
651 return const_cast<ClientView
*>(
652 const_cast<const Widget
*>(this)->client_view());
654 const ClientView
* client_view() const {
655 // non_client_view_ may be NULL, especially during creation.
656 return non_client_view_
? non_client_view_
->client_view() : NULL
;
659 const ui::Compositor
* GetCompositor() const;
660 ui::Compositor
* GetCompositor();
662 // Returns the widget's layer, if any.
663 ui::Layer
* GetLayer();
665 // Reorders the widget's child NativeViews which are associated to the view
666 // tree (eg via a NativeViewHost) to match the z-order of the views in the
667 // view tree. The z-order of views with layers relative to views with
668 // associated NativeViews is used to reorder the NativeView layers. This
669 // method assumes that the widget's child layers which are owned by a view are
670 // already in the correct z-order relative to each other and does no
671 // reordering if there are no views with an associated NativeView.
672 void ReorderNativeViews();
674 // Schedules an update to the root layers. The actual processing occurs when
675 // GetRootLayers() is invoked.
676 void UpdateRootLayers();
678 const NativeWidget
* native_widget() const;
679 NativeWidget
* native_widget();
681 internal::NativeWidgetPrivate
* native_widget_private() {
682 return native_widget_
;
684 const internal::NativeWidgetPrivate
* native_widget_private() const {
685 return native_widget_
;
688 // Sets capture to the specified view. This makes it so that all mouse, touch
689 // and gesture events go to |view|. If |view| is NULL, the widget still
690 // obtains event capture, but the events will go to the view they'd normally
692 void SetCapture(View
* view
);
695 void ReleaseCapture();
697 // Returns true if the widget has capture.
700 void set_auto_release_capture(bool auto_release_capture
) {
701 auto_release_capture_
= auto_release_capture
;
704 // Returns the font used for tooltips.
705 TooltipManager
* GetTooltipManager();
706 const TooltipManager
* GetTooltipManager() const;
708 void set_focus_on_creation(bool focus_on_creation
) {
709 focus_on_creation_
= focus_on_creation
;
712 // True if the widget is considered top level widget. Top level widget
713 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE,
714 // POPUP or MENU, and has a focus manager and input method object associated
715 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
716 bool is_top_level() const { return is_top_level_
; }
718 // True when window movement via mouse interaction with the frame is disabled.
719 bool movement_disabled() const { return movement_disabled_
; }
720 void set_movement_disabled(bool disabled
) { movement_disabled_
= disabled
; }
722 // Returns the work area bounds of the screen the Widget belongs to.
723 gfx::Rect
GetWorkAreaBoundsInScreen() const;
725 // Creates and dispatches synthesized mouse move event using the current
726 // mouse location to refresh hovering status in the widget.
727 void SynthesizeMouseMoveEvent();
729 // Called by our RootView after it has performed a Layout. Used to forward
730 // window sizing information to the window server on some platforms.
731 void OnRootViewLayout();
733 // Whether the widget supports translucency.
734 bool IsTranslucentWindowOpacitySupported() const;
736 // Called when the delegate's CanResize or CanMaximize changes.
737 void OnSizeConstraintsChanged();
739 // Notification that our owner is closing.
740 // NOTE: this is not invoked for aura as it's currently not needed there.
741 // Under aura menus close by way of activation getting reset when the owner
743 virtual void OnOwnerClosing();
745 // Overridden from NativeWidgetDelegate:
746 virtual bool IsModal() const override
;
747 virtual bool IsDialogBox() const override
;
748 virtual bool CanActivate() const override
;
749 virtual bool IsInactiveRenderingDisabled() const override
;
750 virtual void EnableInactiveRendering() override
;
751 virtual void OnNativeWidgetActivationChanged(bool active
) override
;
752 virtual void OnNativeFocus(gfx::NativeView old_focused_view
) override
;
753 virtual void OnNativeBlur(gfx::NativeView new_focused_view
) override
;
754 virtual void OnNativeWidgetVisibilityChanging(bool visible
) override
;
755 virtual void OnNativeWidgetVisibilityChanged(bool visible
) override
;
756 virtual void OnNativeWidgetCreated(bool desktop_widget
) override
;
757 virtual void OnNativeWidgetDestroying() override
;
758 virtual void OnNativeWidgetDestroyed() override
;
759 virtual gfx::Size
GetMinimumSize() const override
;
760 virtual gfx::Size
GetMaximumSize() const override
;
761 virtual void OnNativeWidgetMove() override
;
762 virtual void OnNativeWidgetSizeChanged(const gfx::Size
& new_size
) override
;
763 virtual void OnNativeWidgetWindowShowStateChanged() override
;
764 virtual void OnNativeWidgetBeginUserBoundsChange() override
;
765 virtual void OnNativeWidgetEndUserBoundsChange() override
;
766 virtual bool HasFocusManager() const override
;
767 virtual bool OnNativeWidgetPaintAccelerated(
768 const gfx::Rect
& dirty_region
) override
;
769 virtual void OnNativeWidgetPaint(gfx::Canvas
* canvas
) override
;
770 virtual int GetNonClientComponent(const gfx::Point
& point
) override
;
771 virtual void OnKeyEvent(ui::KeyEvent
* event
) override
;
772 virtual void OnMouseEvent(ui::MouseEvent
* event
) override
;
773 virtual void OnMouseCaptureLost() override
;
774 virtual void OnScrollEvent(ui::ScrollEvent
* event
) override
;
775 virtual void OnGestureEvent(ui::GestureEvent
* event
) override
;
776 virtual bool ExecuteCommand(int command_id
) override
;
777 virtual InputMethod
* GetInputMethodDirect() override
;
778 virtual const std::vector
<ui::Layer
*>& GetRootLayers() override
;
779 virtual bool HasHitTestMask() const override
;
780 virtual void GetHitTestMask(gfx::Path
* mask
) const override
;
781 virtual Widget
* AsWidget() override
;
782 virtual const Widget
* AsWidget() const override
;
783 virtual bool SetInitialFocus(ui::WindowShowState show_state
) override
;
785 // Overridden from ui::EventSource:
786 virtual ui::EventProcessor
* GetEventProcessor() override
;
788 // Overridden from FocusTraversable:
789 virtual FocusSearch
* GetFocusSearch() override
;
790 virtual FocusTraversable
* GetFocusTraversableParent() override
;
791 virtual View
* GetFocusTraversableParentView() override
;
793 // Overridden from ui::NativeThemeObserver:
794 virtual void OnNativeThemeUpdated(ui::NativeTheme
* observed_theme
) override
;
797 // Creates the RootView to be used within this Widget. Subclasses may override
798 // to create custom RootViews that do specialized event processing.
799 // TODO(beng): Investigate whether or not this is needed.
800 virtual internal::RootView
* CreateRootView();
802 // Provided to allow the NativeWidget implementations to destroy the RootView
803 // _before_ the focus manager/tooltip manager.
804 // TODO(beng): remove once we fold those objects onto this one.
805 void DestroyRootView();
807 // Notification that a drag will start. Default implementation does nothing.
808 virtual void OnDragWillStart();
810 // Notification that the drag performed by RunShellDrag() has completed.
811 virtual void OnDragComplete();
814 friend class ComboboxTest
;
815 friend class TextfieldTest
;
817 // Sets the value of |disable_inactive_rendering_|. If the value changes,
818 // both the NonClientView and WidgetDelegate are notified.
819 void SetInactiveRenderingDisabled(bool value
);
821 // Persists the window's restored position and "show" state using the
823 void SaveWindowPlacement();
825 // Invokes SaveWindowPlacement() if the native widget has been initialized.
826 // This is called at times when the native widget may not have been
828 void SaveWindowPlacementIfInitialized();
830 // Sizes and positions the window just after it is created.
831 void SetInitialBounds(const gfx::Rect
& bounds
);
833 // Sizes and positions the frameless window just after it is created.
834 void SetInitialBoundsForFramelessWindow(const gfx::Rect
& bounds
);
836 // Returns the bounds and "show" state from the delegate. Returns true if
837 // the delegate wants to use a specified bounds.
838 bool GetSavedWindowPlacement(gfx::Rect
* bounds
,
839 ui::WindowShowState
* show_state
);
841 // Creates and initializes a new InputMethod and returns it, otherwise null.
842 scoped_ptr
<InputMethod
> CreateInputMethod();
844 // Sets a different InputMethod instance to this widget. The instance
845 // must not be initialized, the ownership will be assumed by the widget.
846 // It's only for testing purpose.
847 void ReplaceInputMethod(InputMethod
* input_method
);
849 internal::NativeWidgetPrivate
* native_widget_
;
851 ObserverList
<WidgetObserver
> observers_
;
853 ObserverList
<WidgetRemovalsObserver
> removals_observers_
;
855 // Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
856 // to Init() a default WidgetDelegate is created.
857 WidgetDelegate
* widget_delegate_
;
859 // The root of the View hierarchy attached to this window.
860 // WARNING: see warning in tooltip_manager_ for ordering dependencies with
861 // this and tooltip_manager_.
862 scoped_ptr
<internal::RootView
> root_view_
;
864 // The View that provides the non-client area of the window (title bar,
865 // window controls, sizing borders etc). To use an implementation other than
866 // the default, this class must be sub-classed and this value set to the
867 // desired implementation before calling |InitWindow()|.
868 NonClientView
* non_client_view_
;
870 // The focus manager keeping track of focus for this Widget and any of its
871 // children. NULL for non top-level widgets.
872 // WARNING: RootView's destructor calls into the FocusManager. As such, this
873 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView().
874 scoped_ptr
<FocusManager
> focus_manager_
;
876 // A theme provider to use when no other theme provider is specified.
877 scoped_ptr
<ui::DefaultThemeProvider
> default_theme_provider_
;
879 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
883 // See class documentation for Widget above for a note about ownership.
884 InitParams::Ownership ownership_
;
886 // See set_is_secondary_widget().
887 bool is_secondary_widget_
;
889 // The current frame type in use by this window. Defaults to
890 // FRAME_TYPE_DEFAULT.
891 FrameType frame_type_
;
893 // True when the window should be rendered as active, regardless of whether
894 // or not it actually is.
895 bool disable_inactive_rendering_
;
897 // Set to true if the widget is in the process of closing.
900 // The saved "show" state for this window. See note in SetInitialBounds
901 // that explains why we save this.
902 ui::WindowShowState saved_show_state_
;
904 // The restored bounds used for the initial show. This is only used if
905 // |saved_show_state_| is maximized.
906 gfx::Rect initial_restored_bounds_
;
908 // Focus is automatically set to the view provided by the delegate
909 // when the widget is shown. Set this value to false to override
910 // initial focus for the widget.
911 bool focus_on_creation_
;
913 mutable scoped_ptr
<InputMethod
> input_method_
;
915 // See |is_top_level()| accessor.
918 // Tracks whether native widget has been initialized.
919 bool native_widget_initialized_
;
921 // Whether native widget has been destroyed.
922 bool native_widget_destroyed_
;
924 // True if capture losses should be ignored.
925 bool ignore_capture_loss_
;
927 // The following are used to detect duplicate mouse move events and not
928 // deliver them. Displaying a window may result in the system generating
929 // duplicate move events even though the mouse hasn't moved.
930 // TODO(tdanderson): We may be able to remove these members.
931 bool last_mouse_event_was_move_
;
932 gfx::Point last_mouse_event_position_
;
934 // True if event capture should be released on a mouse up event. Default is
936 bool auto_release_capture_
;
938 // See description in GetRootLayers().
939 std::vector
<ui::Layer
*> root_layers_
;
941 // Is |root_layers_| out of date?
942 bool root_layers_dirty_
;
944 // True when window movement via mouse interaction with the frame should be
946 bool movement_disabled_
;
948 ScopedObserver
<ui::NativeTheme
, ui::NativeThemeObserver
> observer_manager_
;
950 DISALLOW_COPY_AND_ASSIGN(Widget
);
955 #endif // UI_VIEWS_WIDGET_WIDGET_H_