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/geometry/rect.h"
20 #include "ui/gfx/native_widget_types.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)
53 class DefaultThemeProvider
;
63 class DesktopWindowTreeHost
;
66 class NonClientFrameView
;
71 class WidgetRemovalsObserver
;
74 class NativeWidgetPrivate
;
78 ////////////////////////////////////////////////////////////////////////////////
81 // Encapsulates the platform-specific rendering, event receiving and widget
82 // management aspects of the UI framework.
84 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
85 // Widget is a platform-independent type that communicates with a platform or
86 // context specific NativeWidget implementation.
88 // A special note on ownership:
90 // Depending on the value of the InitParams' ownership field, the Widget
91 // either owns or is owned by its NativeWidget:
93 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default)
94 // The Widget instance is owned by its NativeWidget. When the NativeWidget
95 // is destroyed (in response to a native destruction message), it deletes
96 // the Widget from its destructor.
97 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default)
98 // The Widget instance owns its NativeWidget. This state implies someone
99 // else wants to control the lifetime of this object. When they destroy
100 // the Widget it is responsible for destroying the NativeWidget (from its
103 class VIEWS_EXPORT Widget
: public internal::NativeWidgetDelegate
,
104 public ui::EventSource
,
105 public FocusTraversable
,
106 public ui::NativeThemeObserver
{
108 typedef std::set
<Widget
*> Widgets
;
111 FRAME_TYPE_DEFAULT
, // Use whatever the default would be.
112 FRAME_TYPE_FORCE_CUSTOM
, // Force the custom frame.
113 FRAME_TYPE_FORCE_NATIVE
// Force the native frame.
116 // Result from RunMoveLoop().
117 enum MoveLoopResult
{
118 // The move loop completed successfully.
119 MOVE_LOOP_SUCCESSFUL
,
121 // The user canceled the move loop.
125 // Source that initiated the move loop.
126 enum MoveLoopSource
{
127 MOVE_LOOP_SOURCE_MOUSE
,
128 MOVE_LOOP_SOURCE_TOUCH
,
131 // Behavior when escape is pressed during a move loop.
132 enum MoveLoopEscapeBehavior
{
133 // Indicates the window should be hidden.
134 MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE
,
136 // Indicates the window should not be hidden.
137 MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE
,
140 // Type of visibility change transition that should animate.
141 enum VisibilityTransition
{
144 ANIMATE_BOTH
= ANIMATE_SHOW
| ANIMATE_HIDE
,
148 struct VIEWS_EXPORT InitParams
{
150 TYPE_WINDOW
, // A decorated Window, like a frame window.
151 // Widgets of TYPE_WINDOW will have a NonClientView.
152 TYPE_PANEL
, // Always on top window managed by PanelManager.
153 // Widgets of TYPE_PANEL will have a NonClientView.
154 TYPE_WINDOW_FRAMELESS
,
155 // An undecorated Window.
156 TYPE_CONTROL
, // A control, like a button.
157 TYPE_POPUP
, // An undecorated Window, with transient properties.
158 TYPE_MENU
, // An undecorated Window, with transient properties
159 // specialized to menus.
162 TYPE_DRAG
, // An undecorated Window, used during a drag-and-drop to
163 // show the drag image.
167 // Infer fully opaque or not. For WinAura, top-level windows that are not
168 // of TYPE_WINDOW are translucent so that they can be made to fade in. In
169 // all other cases, windows are fully opaque.
173 // Possibly translucent/transparent.
178 // Infer whether the window should be activatable from the window type.
186 // Default. Creator is not responsible for managing the lifetime of the
187 // Widget, it is destroyed when the corresponding NativeWidget is
189 NATIVE_WIDGET_OWNS_WIDGET
,
190 // Used when the Widget is owned by someone other than the NativeWidget,
191 // e.g. a scoped_ptr in tests.
192 WIDGET_OWNS_NATIVE_WIDGET
196 SHADOW_TYPE_DEFAULT
, // Use default shadow setting. It will be one of
197 // the settings below depending on InitParams::type
198 // and the native widget's type.
199 SHADOW_TYPE_NONE
, // Don't draw any shadow.
200 SHADOW_TYPE_DROP
, // Draw a drop shadow that emphasizes Z-order
201 // relationship to other windows.
205 explicit InitParams(Type type
);
209 // If NULL, a default implementation will be constructed.
210 WidgetDelegate
* delegate
;
212 // If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
213 // Translucent windows may not always be supported. Use
214 // IsTranslucentWindowOpacitySupported to determine if translucent windows
216 // If OPAQUE_WINDOW, we can perform optimizations based on the widget being
217 // fully opaque. Defaults to TRANSLUCENT_WINDOW if
218 // ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
219 // non-window widgets.
220 WindowOpacity opacity
;
222 Activatable activatable
;
224 bool visible_on_all_workspaces
;
226 bool mirror_origin_in_rtl
;
227 ShadowType shadow_type
;
228 // Specifies that the system default caption and icon should not be
229 // rendered, and that the client area should be equivalent to the window
230 // area. Only used on some platforms (Windows and Linux).
231 bool remove_standard_frame
;
232 // Only used by ShellWindow on Windows. Specifies that the default icon of
233 // packaged app should be the system default icon.
234 bool use_system_default_icon
;
235 // Whether the widget should be maximized or minimized.
236 ui::WindowShowState show_state
;
237 gfx::NativeView parent
;
238 // Specifies the initial bounds of the Widget. Default is empty, which means
239 // the NativeWidget may specify a default size. If the parent is specified,
240 // |bounds| is in the parent's coordinate system. If the parent is not
241 // specified, it's in screen's global coordinate system.
243 // When set, this value is used as the Widget's NativeWidget implementation.
244 // The Widget will not construct a default one. Default is NULL.
245 NativeWidget
* native_widget
;
246 // Aura-only. Provides a DesktopWindowTreeHost implementation to use instead
247 // of the default one.
248 // TODO(beng): Figure out if there's a better way to expose this, e.g. get
249 // rid of NW subclasses and do this all via message handling.
250 DesktopWindowTreeHost
* desktop_window_tree_host
;
251 // Only used by NativeWidgetAura. Specifies the type of layer for the
252 // aura::Window. Default is WINDOW_LAYER_TEXTURED.
253 aura::WindowLayerType layer_type
;
254 // Only used by Aura. Provides a context window whose RootWindow is
255 // consulted during widget creation to determine where in the Window
256 // hierarchy this widget should be placed. (This is separate from |parent|;
257 // if you pass a RootWindow to |parent|, your window will be parented to
258 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
259 // where it wants your window placed.) NULL is not allowed if you are using
261 gfx::NativeWindow context
;
262 // If true, forces the window to be shown in the taskbar, even for window
263 // types that do not appear in the taskbar by default (popup and bubble).
264 bool force_show_in_taskbar
;
265 // Only used by X11, for root level windows. Specifies the res_name and
266 // res_class fields, respectively, of the WM_CLASS window property. Controls
267 // window grouping and desktop file matching in Linux window managers.
268 std::string wm_role_name
;
269 std::string wm_class_name
;
270 std::string wm_class_class
;
276 // Creates a toplevel window with no context. These methods should only be
277 // used in cases where there is no contextual information because we're
278 // creating a toplevel window connected to no other event.
280 // If you have any parenting or context information, or can pass that
281 // information, prefer the WithParent or WithContext versions of these
283 static Widget
* CreateWindow(WidgetDelegate
* delegate
);
284 static Widget
* CreateWindowWithBounds(WidgetDelegate
* delegate
,
285 const gfx::Rect
& bounds
);
287 // Creates a decorated window Widget with the specified properties.
288 static Widget
* CreateWindowWithParent(WidgetDelegate
* delegate
,
289 gfx::NativeView parent
);
290 static Widget
* CreateWindowWithParentAndBounds(WidgetDelegate
* delegate
,
291 gfx::NativeView parent
,
292 const gfx::Rect
& bounds
);
294 // Creates a decorated window Widget in the same desktop context as |context|.
295 static Widget
* CreateWindowWithContext(WidgetDelegate
* delegate
,
296 gfx::NativeWindow context
);
297 static Widget
* CreateWindowWithContextAndBounds(WidgetDelegate
* delegate
,
298 gfx::NativeWindow context
,
299 const gfx::Rect
& bounds
);
301 // Closes all Widgets that aren't identified as "secondary widgets". Called
302 // during application shutdown when the last non-secondary widget is closed.
303 static void CloseAllSecondaryWidgets();
305 // Converts a rectangle from one Widget's coordinate system to another's.
306 // Returns false if the conversion couldn't be made, because either these two
307 // Widgets do not have a common ancestor or they are not on the screen yet.
308 // The value of |*rect| won't be changed when false is returned.
309 static bool ConvertRect(const Widget
* source
,
310 const Widget
* target
,
313 // Retrieves the Widget implementation associated with the given
314 // NativeView or Window, or NULL if the supplied handle has no associated
316 static Widget
* GetWidgetForNativeView(gfx::NativeView native_view
);
317 static Widget
* GetWidgetForNativeWindow(gfx::NativeWindow native_window
);
319 // Retrieves the top level widget in a native view hierarchy
320 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW,
321 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own
322 // focus manager. This may be itself if the |native_view| is top level,
323 // or NULL if there is no toplevel in a native view hierarchy.
324 static Widget
* GetTopLevelWidgetForNativeView(gfx::NativeView native_view
);
326 // Returns all Widgets in |native_view|'s hierarchy, including itself if
328 static void GetAllChildWidgets(gfx::NativeView native_view
,
331 // Returns all Widgets owned by |native_view| (including child widgets, but
332 // not including itself).
333 static void GetAllOwnedWidgets(gfx::NativeView native_view
,
336 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
338 static void ReparentNativeView(gfx::NativeView native_view
,
339 gfx::NativeView new_parent
);
341 // Returns the preferred size of the contents view of this window based on
342 // its localized size data. The width in cols is held in a localized string
343 // resource identified by |col_resource_id|, the height in the same fashion.
344 // TODO(beng): This should eventually live somewhere else, probably closer to
346 static int GetLocalizedContentsWidth(int col_resource_id
);
347 static int GetLocalizedContentsHeight(int row_resource_id
);
348 static gfx::Size
GetLocalizedContentsSize(int col_resource_id
,
349 int row_resource_id
);
351 // Returns true if the specified type requires a NonClientView.
352 static bool RequiresNonClientView(InitParams::Type type
);
354 void Init(const InitParams
& params
);
356 // Returns the gfx::NativeView associated with this Widget.
357 gfx::NativeView
GetNativeView() const;
359 // Returns the gfx::NativeWindow associated with this Widget. This may return
360 // NULL on some platforms if the widget was created with a type other than
361 // TYPE_WINDOW or TYPE_PANEL.
362 gfx::NativeWindow
GetNativeWindow() const;
364 // Add/remove observer.
365 void AddObserver(WidgetObserver
* observer
);
366 void RemoveObserver(WidgetObserver
* observer
);
367 bool HasObserver(const WidgetObserver
* observer
) const;
369 // Add/remove removals observer.
370 void AddRemovalsObserver(WidgetRemovalsObserver
* observer
);
371 void RemoveRemovalsObserver(WidgetRemovalsObserver
* observer
);
372 bool HasRemovalsObserver(const WidgetRemovalsObserver
* observer
) const;
374 // Returns the accelerator given a command id. Returns false if there is
375 // no accelerator associated with a given id, which is a common condition.
376 virtual bool GetAccelerator(int cmd_id
, ui::Accelerator
* accelerator
) const;
378 // Forwarded from the RootView so that the widget can do any cleanup.
379 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails
& details
);
381 // Called right before changing the widget's parent NativeView to do any
383 void NotifyNativeViewHierarchyWillChange();
385 // Called after changing the widget's parent NativeView. Notifies the RootView
387 void NotifyNativeViewHierarchyChanged();
389 // Called immediately before removing |view| from this widget.
390 void NotifyWillRemoveView(View
* view
);
392 // Returns the top level widget in a hierarchy (see is_top_level() for
393 // the definition of top level widget.) Will return NULL if called
394 // before the widget is attached to the top level widget's hierarchy.
395 Widget
* GetTopLevelWidget();
396 const Widget
* GetTopLevelWidget() const;
398 // Gets/Sets the WidgetDelegate.
399 WidgetDelegate
* widget_delegate() const { return widget_delegate_
; }
401 // Sets the specified view as the contents of this Widget. There can only
402 // be one contents view child of this Widget's RootView. This view is sized to
403 // fit the entire size of the RootView. The RootView takes ownership of this
404 // View, unless it is set as not being parent-owned.
405 void SetContentsView(View
* view
);
406 View
* GetContentsView();
408 // Returns the bounds of the Widget in screen coordinates.
409 gfx::Rect
GetWindowBoundsInScreen() const;
411 // Returns the bounds of the Widget's client area in screen coordinates.
412 gfx::Rect
GetClientAreaBoundsInScreen() const;
414 // Retrieves the restored bounds for the window.
415 gfx::Rect
GetRestoredBounds() const;
417 // Sizes and/or places the widget to the specified bounds, size or position.
418 void SetBounds(const gfx::Rect
& bounds
);
419 void SetSize(const gfx::Size
& size
);
421 // Sizes the window to the specified size and centerizes it.
422 void CenterWindow(const gfx::Size
& size
);
424 // Like SetBounds(), but ensures the Widget is fully visible on screen,
425 // resizing and/or repositioning as necessary. This is only useful for
426 // non-child widgets.
427 void SetBoundsConstrained(const gfx::Rect
& bounds
);
429 // Sets whether animations that occur when visibility is changed are enabled.
431 void SetVisibilityChangedAnimationsEnabled(bool value
);
433 // Sets the duration of visibility change animations.
434 void SetVisibilityAnimationDuration(const base::TimeDelta
& duration
);
436 // Sets the visibility transitions that should animate.
437 // Default behavior is to animate both show and hide.
438 void SetVisibilityAnimationTransition(VisibilityTransition transition
);
440 // Starts a nested message loop that moves the window. This can be used to
441 // start a window move operation from a mouse or touch event. This returns
442 // when the move completes. |drag_offset| is the offset from the top left
443 // corner of the window to the point where the cursor is dragging, and is used
444 // to offset the bounds of the window from the cursor.
445 MoveLoopResult
RunMoveLoop(const gfx::Vector2d
& drag_offset
,
446 MoveLoopSource source
,
447 MoveLoopEscapeBehavior escape_behavior
);
449 // Stops a previously started move loop. This is not immediate.
452 // Places the widget in front of the specified widget in z-order.
453 void StackAboveWidget(Widget
* widget
);
454 void StackAbove(gfx::NativeView native_view
);
457 // Places the widget below the specified NativeView.
458 void StackBelow(gfx::NativeView native_view
);
460 // Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
461 // be rectangular. Takes ownership of |shape|.
462 void SetShape(gfx::NativeRegion shape
);
464 // Hides the widget then closes it after a return to the message loop.
465 virtual void Close();
467 // TODO(beng): Move off public API.
468 // Closes the widget immediately. Compare to |Close|. This will destroy the
469 // window handle associated with this Widget, so should not be called from
470 // any code that expects it to be valid beyond this call.
473 // Whether the widget has been asked to close itself. In particular this is
474 // set to true after Close() has been invoked on the NativeWidget.
475 bool IsClosed() const;
477 // Shows the widget. The widget is activated if during initialization the
478 // can_activate flag in the InitParams structure is set to true.
483 // Like Show(), but does not activate the window.
486 // Activates the widget, assuming it already exists and is visible.
489 // Deactivates the widget, making the next window in the Z order the active
493 // Returns whether the Widget is the currently active window.
494 virtual bool IsActive() const;
496 // Prevents the window from being rendered as deactivated. This state is
497 // reset automatically as soon as the window becomes activated again. There is
498 // no ability to control the state through this API as this leads to sync
500 void DisableInactiveRendering();
502 // Sets the widget to be on top of all other widgets in the windowing system.
503 void SetAlwaysOnTop(bool on_top
);
505 // Returns whether the widget has been set to be on top of most other widgets
506 // in the windowing system.
507 bool IsAlwaysOnTop() const;
509 // Sets the widget to be visible on all work spaces.
510 void SetVisibleOnAllWorkspaces(bool always_visible
);
512 // Maximizes/minimizes/restores the window.
517 // Whether or not the window is maximized or minimized.
518 virtual bool IsMaximized() const;
519 bool IsMinimized() const;
521 // Accessors for fullscreen state.
522 void SetFullscreen(bool fullscreen
);
523 bool IsFullscreen() const;
525 // Sets the opacity of the widget. This may allow widgets behind the widget
526 // in the Z-order to become visible, depending on the capabilities of the
527 // underlying windowing system.
528 void SetOpacity(unsigned char opacity
);
530 // Sets whether or not the window should show its frame as a "transient drag
531 // frame" - slightly transparent and without the standard window controls.
532 void SetUseDragFrame(bool use_drag_frame
);
534 // Flashes the frame of the window to draw attention to it. Currently only
535 // implemented on Windows for non-Aura.
536 void FlashFrame(bool flash
);
538 // Returns the View at the root of the View hierarchy contained by this
541 const View
* GetRootView() const;
543 // A secondary widget is one that is automatically closed (via Close()) when
544 // all non-secondary widgets are closed.
546 // TODO(beng): This is an ugly API, should be handled implicitly via
548 void set_is_secondary_widget(bool is_secondary_widget
) {
549 is_secondary_widget_
= is_secondary_widget
;
551 bool is_secondary_widget() const { return is_secondary_widget_
; }
553 // Returns whether the Widget is visible to the user.
554 virtual bool IsVisible() const;
556 // Returns the ThemeProvider that provides theme resources for this Widget.
557 virtual ui::ThemeProvider
* GetThemeProvider() const;
559 ui::NativeTheme
* GetNativeTheme() {
560 return const_cast<ui::NativeTheme
*>(
561 const_cast<const Widget
*>(this)->GetNativeTheme());
563 const ui::NativeTheme
* GetNativeTheme() const;
565 // Returns the FocusManager for this widget.
566 // Note that all widgets in a widget hierarchy share the same focus manager.
567 FocusManager
* GetFocusManager();
568 const FocusManager
* GetFocusManager() const;
570 // Returns the focused text input client within this widget.
571 ui::TextInputClient
* GetFocusedTextInputClient();
573 // Returns the InputMethod for this widget.
574 // Note that all widgets in a widget hierarchy share the same input method.
575 InputMethod
* GetInputMethod();
576 const InputMethod
* GetInputMethod() const;
578 // Returns the ui::InputMethod for this widget.
579 // TODO(yukishiino): Rename this method to GetInputMethod once we remove
580 // views::InputMethod.
581 ui::InputMethod
* GetHostInputMethod();
583 // Starts a drag operation for the specified view. This blocks until the drag
584 // operation completes. |view| can be NULL.
585 // If the view is non-NULL it can be accessed during the drag by calling
586 // dragged_view(). If the view has not been deleted during the drag,
587 // OnDragDone() is called on it. |location| is in the widget's coordinate
589 void RunShellDrag(View
* view
,
590 const ui::OSExchangeData
& data
,
591 const gfx::Point
& location
,
593 ui::DragDropTypes::DragEventSource source
);
595 // Returns the view that requested the current drag operation via
596 // RunShellDrag(), or NULL if there is no such view or drag operation.
597 View
* dragged_view() { return dragged_view_
; }
599 // Adds the specified |rect| in client area coordinates to the rectangle to be
601 virtual void SchedulePaintInRect(const gfx::Rect
& rect
);
603 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
604 // before the current is restored.
605 void SetCursor(gfx::NativeCursor cursor
);
607 // Returns true if and only if mouse events are enabled.
608 bool IsMouseEventsEnabled() const;
610 // Sets/Gets a native window property on the underlying native window object.
611 // Returns NULL if the property does not exist. Setting the property value to
612 // NULL removes the property.
613 void SetNativeWindowProperty(const char* name
, void* value
);
614 void* GetNativeWindowProperty(const char* name
) const;
616 // Tell the window to update its title from the delegate.
617 void UpdateWindowTitle();
619 // Tell the window to update its icon from the delegate.
620 void UpdateWindowIcon();
622 // Retrieves the focus traversable for this widget.
623 FocusTraversable
* GetFocusTraversable();
625 // Notifies the view hierarchy contained in this widget that theme resources
629 // Notifies the view hierarchy contained in this widget that locale resources
631 void LocaleChanged();
633 // Notifies the view hierarchy contained in this widget that the device scale
635 void DeviceScaleFactorChanged(float device_scale_factor
);
637 void SetFocusTraversableParent(FocusTraversable
* parent
);
638 void SetFocusTraversableParentView(View
* parent_view
);
640 // Clear native focus set to the Widget's NativeWidget.
641 void ClearNativeFocus();
643 void set_frame_type(FrameType frame_type
) { frame_type_
= frame_type
; }
644 FrameType
frame_type() const { return frame_type_
; }
646 // Creates an appropriate NonClientFrameView for this widget. The
647 // WidgetDelegate is given the first opportunity to create one, followed by
648 // the NativeWidget implementation. If both return NULL, a default one is
650 virtual NonClientFrameView
* CreateNonClientFrameView();
652 // Whether we should be using a native frame.
653 bool ShouldUseNativeFrame() const;
655 // Determines whether the window contents should be rendered transparently
656 // (for example, so that they can overhang onto the window title bar).
657 bool ShouldWindowContentsBeTransparent() const;
659 // Forces the frame into the alternate frame type (custom or native) depending
660 // on its current state.
661 void DebugToggleFrameType();
663 // Tell the window that something caused the frame type to change.
664 void FrameTypeChanged();
666 NonClientView
* non_client_view() {
667 return const_cast<NonClientView
*>(
668 const_cast<const Widget
*>(this)->non_client_view());
670 const NonClientView
* non_client_view() const {
671 return non_client_view_
;
674 ClientView
* client_view() {
675 return const_cast<ClientView
*>(
676 const_cast<const Widget
*>(this)->client_view());
678 const ClientView
* client_view() const {
679 // non_client_view_ may be NULL, especially during creation.
680 return non_client_view_
? non_client_view_
->client_view() : NULL
;
683 ui::Compositor
* GetCompositor() {
684 return const_cast<ui::Compositor
*>(
685 const_cast<const Widget
*>(this)->GetCompositor());
687 const ui::Compositor
* GetCompositor() const;
689 // Returns the widget's layer, if any.
690 ui::Layer
* GetLayer() {
691 return const_cast<ui::Layer
*>(
692 const_cast<const Widget
*>(this)->GetLayer());
694 const ui::Layer
* GetLayer() const;
696 // Reorders the widget's child NativeViews which are associated to the view
697 // tree (eg via a NativeViewHost) to match the z-order of the views in the
698 // view tree. The z-order of views with layers relative to views with
699 // associated NativeViews is used to reorder the NativeView layers. This
700 // method assumes that the widget's child layers which are owned by a view are
701 // already in the correct z-order relative to each other and does no
702 // reordering if there are no views with an associated NativeView.
703 void ReorderNativeViews();
705 // Schedules an update to the root layers. The actual processing occurs when
706 // GetRootLayers() is invoked.
707 void UpdateRootLayers();
709 const NativeWidget
* native_widget() const;
710 NativeWidget
* native_widget();
712 internal::NativeWidgetPrivate
* native_widget_private() {
713 return native_widget_
;
715 const internal::NativeWidgetPrivate
* native_widget_private() const {
716 return native_widget_
;
719 // Sets capture to the specified view. This makes it so that all mouse, touch
720 // and gesture events go to |view|. If |view| is NULL, the widget still
721 // obtains event capture, but the events will go to the view they'd normally
723 void SetCapture(View
* view
);
726 void ReleaseCapture();
728 // Returns true if the widget has capture.
731 void set_auto_release_capture(bool auto_release_capture
) {
732 auto_release_capture_
= auto_release_capture
;
735 // Returns the font used for tooltips.
736 TooltipManager
* GetTooltipManager();
737 const TooltipManager
* GetTooltipManager() const;
739 void set_focus_on_creation(bool focus_on_creation
) {
740 focus_on_creation_
= focus_on_creation
;
743 // True if the widget is considered top level widget. Top level widget
744 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE,
745 // POPUP or MENU, and has a focus manager and input method object associated
746 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
747 bool is_top_level() const { return is_top_level_
; }
749 // True when window movement via mouse interaction with the frame is disabled.
750 bool movement_disabled() const { return movement_disabled_
; }
751 void set_movement_disabled(bool disabled
) { movement_disabled_
= disabled
; }
753 // Returns the work area bounds of the screen the Widget belongs to.
754 gfx::Rect
GetWorkAreaBoundsInScreen() const;
756 // Creates and dispatches synthesized mouse move event using the current
757 // mouse location to refresh hovering status in the widget.
758 void SynthesizeMouseMoveEvent();
760 // Called by our RootView after it has performed a Layout. Used to forward
761 // window sizing information to the window server on some platforms.
762 void OnRootViewLayout();
764 // Whether the widget supports translucency.
765 bool IsTranslucentWindowOpacitySupported() const;
767 // Called when the delegate's CanResize or CanMaximize changes.
768 void OnSizeConstraintsChanged();
770 // Notification that our owner is closing.
771 // NOTE: this is not invoked for aura as it's currently not needed there.
772 // Under aura menus close by way of activation getting reset when the owner
774 virtual void OnOwnerClosing();
776 // Overridden from NativeWidgetDelegate:
777 bool IsModal() const override
;
778 bool IsDialogBox() const override
;
779 bool CanActivate() const override
;
780 bool IsInactiveRenderingDisabled() const override
;
781 void EnableInactiveRendering() override
;
782 void OnNativeWidgetActivationChanged(bool active
) override
;
783 void OnNativeFocus(gfx::NativeView old_focused_view
) override
;
784 void OnNativeBlur(gfx::NativeView new_focused_view
) override
;
785 void OnNativeWidgetVisibilityChanging(bool visible
) override
;
786 void OnNativeWidgetVisibilityChanged(bool visible
) override
;
787 void OnNativeWidgetCreated(bool desktop_widget
) override
;
788 void OnNativeWidgetDestroying() override
;
789 void OnNativeWidgetDestroyed() override
;
790 gfx::Size
GetMinimumSize() const override
;
791 gfx::Size
GetMaximumSize() const override
;
792 void OnNativeWidgetMove() override
;
793 void OnNativeWidgetSizeChanged(const gfx::Size
& new_size
) override
;
794 void OnNativeWidgetWindowShowStateChanged() override
;
795 void OnNativeWidgetBeginUserBoundsChange() override
;
796 void OnNativeWidgetEndUserBoundsChange() override
;
797 bool HasFocusManager() const override
;
798 bool OnNativeWidgetPaintAccelerated(const gfx::Rect
& dirty_region
) override
;
799 void OnNativeWidgetPaint(gfx::Canvas
* canvas
) override
;
800 int GetNonClientComponent(const gfx::Point
& point
) override
;
801 void OnKeyEvent(ui::KeyEvent
* event
) override
;
802 void OnMouseEvent(ui::MouseEvent
* event
) override
;
803 void OnMouseCaptureLost() override
;
804 void OnScrollEvent(ui::ScrollEvent
* event
) override
;
805 void OnGestureEvent(ui::GestureEvent
* event
) override
;
806 bool ExecuteCommand(int command_id
) override
;
807 InputMethod
* GetInputMethodDirect() override
;
808 const std::vector
<ui::Layer
*>& GetRootLayers() override
;
809 bool HasHitTestMask() const override
;
810 void GetHitTestMask(gfx::Path
* mask
) const override
;
811 Widget
* AsWidget() override
;
812 const Widget
* AsWidget() const override
;
813 bool SetInitialFocus(ui::WindowShowState show_state
) override
;
815 // Overridden from ui::EventSource:
816 ui::EventProcessor
* GetEventProcessor() override
;
818 // Overridden from FocusTraversable:
819 FocusSearch
* GetFocusSearch() override
;
820 FocusTraversable
* GetFocusTraversableParent() override
;
821 View
* GetFocusTraversableParentView() override
;
823 // Overridden from ui::NativeThemeObserver:
824 void OnNativeThemeUpdated(ui::NativeTheme
* observed_theme
) override
;
827 // Creates the RootView to be used within this Widget. Subclasses may override
828 // to create custom RootViews that do specialized event processing.
829 // TODO(beng): Investigate whether or not this is needed.
830 virtual internal::RootView
* CreateRootView();
832 // Provided to allow the NativeWidget implementations to destroy the RootView
833 // _before_ the focus manager/tooltip manager.
834 // TODO(beng): remove once we fold those objects onto this one.
835 void DestroyRootView();
837 // Notification that a drag will start. Default implementation does nothing.
838 virtual void OnDragWillStart();
840 // Notification that the drag performed by RunShellDrag() has completed.
841 virtual void OnDragComplete();
844 friend class ComboboxTest
;
845 friend class TextfieldTest
;
847 // Sets the value of |disable_inactive_rendering_|. If the value changes,
848 // both the NonClientView and WidgetDelegate are notified.
849 void SetInactiveRenderingDisabled(bool value
);
851 // Persists the window's restored position and "show" state using the
853 void SaveWindowPlacement();
855 // Invokes SaveWindowPlacement() if the native widget has been initialized.
856 // This is called at times when the native widget may not have been
858 void SaveWindowPlacementIfInitialized();
860 // Sizes and positions the window just after it is created.
861 void SetInitialBounds(const gfx::Rect
& bounds
);
863 // Sizes and positions the frameless window just after it is created.
864 void SetInitialBoundsForFramelessWindow(const gfx::Rect
& bounds
);
866 // Returns the bounds and "show" state from the delegate. Returns true if
867 // the delegate wants to use a specified bounds.
868 bool GetSavedWindowPlacement(gfx::Rect
* bounds
,
869 ui::WindowShowState
* show_state
);
871 // Creates and initializes a new InputMethod and returns it, otherwise null.
872 scoped_ptr
<InputMethod
> CreateInputMethod();
874 // Sets a different InputMethod instance to this widget. The instance
875 // must not be initialized, the ownership will be assumed by the widget.
876 // It's only for testing purpose.
877 void ReplaceInputMethod(InputMethod
* input_method
);
879 internal::NativeWidgetPrivate
* native_widget_
;
881 ObserverList
<WidgetObserver
> observers_
;
883 ObserverList
<WidgetRemovalsObserver
> removals_observers_
;
885 // Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
886 // to Init() a default WidgetDelegate is created.
887 WidgetDelegate
* widget_delegate_
;
889 // The root of the View hierarchy attached to this window.
890 // WARNING: see warning in tooltip_manager_ for ordering dependencies with
891 // this and tooltip_manager_.
892 scoped_ptr
<internal::RootView
> root_view_
;
894 // The View that provides the non-client area of the window (title bar,
895 // window controls, sizing borders etc). To use an implementation other than
896 // the default, this class must be sub-classed and this value set to the
897 // desired implementation before calling |InitWindow()|.
898 NonClientView
* non_client_view_
;
900 // The focus manager keeping track of focus for this Widget and any of its
901 // children. NULL for non top-level widgets.
902 // WARNING: RootView's destructor calls into the FocusManager. As such, this
903 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView().
904 scoped_ptr
<FocusManager
> focus_manager_
;
906 // A theme provider to use when no other theme provider is specified.
907 scoped_ptr
<ui::DefaultThemeProvider
> default_theme_provider_
;
909 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
913 // See class documentation for Widget above for a note about ownership.
914 InitParams::Ownership ownership_
;
916 // See set_is_secondary_widget().
917 bool is_secondary_widget_
;
919 // The current frame type in use by this window. Defaults to
920 // FRAME_TYPE_DEFAULT.
921 FrameType frame_type_
;
923 // True when the window should be rendered as active, regardless of whether
924 // or not it actually is.
925 bool disable_inactive_rendering_
;
927 // Set to true if the widget is in the process of closing.
930 // The saved "show" state for this window. See note in SetInitialBounds
931 // that explains why we save this.
932 ui::WindowShowState saved_show_state_
;
934 // The restored bounds used for the initial show. This is only used if
935 // |saved_show_state_| is maximized.
936 gfx::Rect initial_restored_bounds_
;
938 // Focus is automatically set to the view provided by the delegate
939 // when the widget is shown. Set this value to false to override
940 // initial focus for the widget.
941 bool focus_on_creation_
;
943 mutable scoped_ptr
<InputMethod
> input_method_
;
945 // See |is_top_level()| accessor.
948 // Tracks whether native widget has been initialized.
949 bool native_widget_initialized_
;
951 // Whether native widget has been destroyed.
952 bool native_widget_destroyed_
;
954 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
955 // If true, the mouse is currently down.
956 bool is_mouse_button_pressed_
;
958 // True if capture losses should be ignored.
959 bool ignore_capture_loss_
;
961 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
962 // The following are used to detect duplicate mouse move events and not
963 // deliver them. Displaying a window may result in the system generating
964 // duplicate move events even though the mouse hasn't moved.
965 bool last_mouse_event_was_move_
;
966 gfx::Point last_mouse_event_position_
;
968 // True if event capture should be released on a mouse up event. Default is
970 bool auto_release_capture_
;
972 // See description in GetRootLayers().
973 std::vector
<ui::Layer
*> root_layers_
;
975 // Is |root_layers_| out of date?
976 bool root_layers_dirty_
;
978 // True when window movement via mouse interaction with the frame should be
980 bool movement_disabled_
;
982 ScopedObserver
<ui::NativeTheme
, ui::NativeThemeObserver
> observer_manager_
;
984 DISALLOW_COPY_AND_ASSIGN(Widget
);
989 #endif // UI_VIEWS_WIDGET_WIDGET_H_