Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / views / widget / widget.h
blob59e7b1dbded4f852138fd25b6fbc2e147e98c56a
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_
8 #include <set>
9 #include <stack>
10 #include <vector>
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"
26 #if defined(OS_WIN)
27 // Windows headers define macros for these function names which screw with us.
28 #if defined(IsMaximized)
29 #undef IsMaximized
30 #endif
31 #if defined(IsMinimized)
32 #undef IsMinimized
33 #endif
34 #if defined(CreateWindow)
35 #undef CreateWindow
36 #endif
37 #endif
39 namespace base {
40 class TimeDelta;
43 namespace gfx {
44 class Canvas;
45 class Point;
46 class Rect;
49 namespace ui {
50 class Accelerator;
51 class Compositor;
52 class DefaultThemeProvider;
53 class InputMethod;
54 class Layer;
55 class NativeTheme;
56 class OSExchangeData;
57 class ThemeProvider;
60 namespace views {
62 class DesktopWindowTreeHost;
63 class InputMethod;
64 class NativeWidget;
65 class NonClientFrameView;
66 class TooltipManager;
67 class View;
68 class WidgetDelegate;
69 class WidgetObserver;
70 class WidgetRemovalsObserver;
72 namespace internal {
73 class NativeWidgetPrivate;
74 class RootView;
77 ////////////////////////////////////////////////////////////////////////////////
78 // Widget class
80 // Encapsulates the platform-specific rendering, event receiving and widget
81 // management aspects of the UI framework.
83 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
84 // Widget is a platform-independent type that communicates with a platform or
85 // context specific NativeWidget implementation.
87 // A special note on ownership:
89 // Depending on the value of the InitParams' ownership field, the Widget
90 // either owns or is owned by its NativeWidget:
92 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default)
93 // The Widget instance is owned by its NativeWidget. When the NativeWidget
94 // is destroyed (in response to a native destruction message), it deletes
95 // the Widget from its destructor.
96 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default)
97 // The Widget instance owns its NativeWidget. This state implies someone
98 // else wants to control the lifetime of this object. When they destroy
99 // the Widget it is responsible for destroying the NativeWidget (from its
100 // destructor).
102 class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
103 public ui::EventSource,
104 public FocusTraversable,
105 public ui::NativeThemeObserver {
106 public:
107 typedef std::set<Widget*> Widgets;
109 enum FrameType {
110 FRAME_TYPE_DEFAULT, // Use whatever the default would be.
111 FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame.
112 FRAME_TYPE_FORCE_NATIVE // Force the native frame.
115 // Result from RunMoveLoop().
116 enum MoveLoopResult {
117 // The move loop completed successfully.
118 MOVE_LOOP_SUCCESSFUL,
120 // The user canceled the move loop.
121 MOVE_LOOP_CANCELED
124 // Source that initiated the move loop.
125 enum MoveLoopSource {
126 MOVE_LOOP_SOURCE_MOUSE,
127 MOVE_LOOP_SOURCE_TOUCH,
130 // Behavior when escape is pressed during a move loop.
131 enum MoveLoopEscapeBehavior {
132 // Indicates the window should be hidden.
133 MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE,
135 // Indicates the window should not be hidden.
136 MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE,
139 // Type of visibility change transition that should animate.
140 enum VisibilityTransition {
141 ANIMATE_SHOW = 0x1,
142 ANIMATE_HIDE = 0x2,
143 ANIMATE_BOTH = ANIMATE_SHOW | ANIMATE_HIDE,
144 ANIMATE_NONE = 0x4,
147 struct VIEWS_EXPORT InitParams {
148 enum Type {
149 TYPE_WINDOW, // A decorated Window, like a frame window.
150 // Widgets of TYPE_WINDOW will have a NonClientView.
151 TYPE_PANEL, // Always on top window managed by PanelManager.
152 // Widgets of TYPE_PANEL will have a NonClientView.
153 TYPE_WINDOW_FRAMELESS,
154 // An undecorated Window.
155 TYPE_CONTROL, // A control, like a button.
156 TYPE_POPUP, // An undecorated Window, with transient properties.
157 TYPE_MENU, // An undecorated Window, with transient properties
158 // specialized to menus.
159 TYPE_TOOLTIP,
160 TYPE_BUBBLE,
161 TYPE_DRAG, // An undecorated Window, used during a drag-and-drop to
162 // show the drag image.
165 enum WindowOpacity {
166 // Infer fully opaque or not. For WinAura, top-level windows that are not
167 // of TYPE_WINDOW are translucent so that they can be made to fade in. In
168 // all other cases, windows are fully opaque.
169 INFER_OPACITY,
170 // Fully opaque.
171 OPAQUE_WINDOW,
172 // Possibly translucent/transparent.
173 TRANSLUCENT_WINDOW,
176 enum Activatable {
177 // Infer whether the window should be activatable from the window type.
178 ACTIVATABLE_DEFAULT,
180 ACTIVATABLE_YES,
181 ACTIVATABLE_NO
184 enum Ownership {
185 // Default. Creator is not responsible for managing the lifetime of the
186 // Widget, it is destroyed when the corresponding NativeWidget is
187 // destroyed.
188 NATIVE_WIDGET_OWNS_WIDGET,
189 // Used when the Widget is owned by someone other than the NativeWidget,
190 // e.g. a scoped_ptr in tests.
191 WIDGET_OWNS_NATIVE_WIDGET
194 enum ShadowType {
195 SHADOW_TYPE_DEFAULT, // Use default shadow setting. It will be one of
196 // the settings below depending on InitParams::type
197 // and the native widget's type.
198 SHADOW_TYPE_NONE, // Don't draw any shadow.
199 SHADOW_TYPE_DROP, // Draw a drop shadow that emphasizes Z-order
200 // relationship to other windows.
203 InitParams();
204 explicit InitParams(Type type);
205 ~InitParams();
207 Type type;
208 // If NULL, a default implementation will be constructed.
209 WidgetDelegate* delegate;
210 bool child;
211 // If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
212 // Translucent windows may not always be supported. Use
213 // IsTranslucentWindowOpacitySupported to determine if translucent windows
214 // are supported.
215 // If OPAQUE_WINDOW, we can perform optimizations based on the widget being
216 // fully opaque. Defaults to TRANSLUCENT_WINDOW if
217 // ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
218 // non-window widgets.
219 WindowOpacity opacity;
220 bool accept_events;
221 Activatable activatable;
222 bool keep_on_top;
223 bool visible_on_all_workspaces;
224 Ownership ownership;
225 bool mirror_origin_in_rtl;
226 ShadowType shadow_type;
227 // Specifies that the system default caption and icon should not be
228 // rendered, and that the client area should be equivalent to the window
229 // area. Only used on some platforms (Windows and Linux).
230 bool remove_standard_frame;
231 // Only used by ShellWindow on Windows. Specifies that the default icon of
232 // packaged app should be the system default icon.
233 bool use_system_default_icon;
234 // Whether the widget should be maximized or minimized.
235 ui::WindowShowState show_state;
236 gfx::NativeView parent;
237 // Specifies the initial bounds of the Widget. Default is empty, which means
238 // the NativeWidget may specify a default size. If the parent is specified,
239 // |bounds| is in the parent's coordinate system. If the parent is not
240 // specified, it's in screen's global coordinate system.
241 gfx::Rect bounds;
242 // When set, this value is used as the Widget's NativeWidget implementation.
243 // The Widget will not construct a default one. Default is NULL.
244 NativeWidget* native_widget;
245 // Aura-only. Provides a DesktopWindowTreeHost implementation to use instead
246 // of the default one.
247 // TODO(beng): Figure out if there's a better way to expose this, e.g. get
248 // rid of NW subclasses and do this all via message handling.
249 DesktopWindowTreeHost* desktop_window_tree_host;
250 // Only used by NativeWidgetAura. Specifies the type of layer for the
251 // aura::Window. Default is ui::LAYER_TEXTURED.
252 ui::LayerType layer_type;
253 // Only used by Aura. Provides a context window whose RootWindow is
254 // consulted during widget creation to determine where in the Window
255 // hierarchy this widget should be placed. (This is separate from |parent|;
256 // if you pass a RootWindow to |parent|, your window will be parented to
257 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
258 // where it wants your window placed.) NULL is not allowed if you are using
259 // aura.
260 gfx::NativeWindow context;
261 // If true, forces the window to be shown in the taskbar, even for window
262 // types that do not appear in the taskbar by default (popup and bubble).
263 bool force_show_in_taskbar;
264 // Only used by X11, for root level windows. Specifies the res_name and
265 // res_class fields, respectively, of the WM_CLASS window property. Controls
266 // window grouping and desktop file matching in Linux window managers.
267 std::string wm_role_name;
268 std::string wm_class_name;
269 std::string wm_class_class;
272 Widget();
273 ~Widget() override;
275 // Creates a toplevel window with no context. These methods should only be
276 // used in cases where there is no contextual information because we're
277 // creating a toplevel window connected to no other event.
279 // If you have any parenting or context information, or can pass that
280 // information, prefer the WithParent or WithContext versions of these
281 // methods.
282 static Widget* CreateWindow(WidgetDelegate* delegate);
283 static Widget* CreateWindowWithBounds(WidgetDelegate* delegate,
284 const gfx::Rect& bounds);
286 // Creates a decorated window Widget with the specified properties.
287 static Widget* CreateWindowWithParent(WidgetDelegate* delegate,
288 gfx::NativeView parent);
289 static Widget* CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
290 gfx::NativeView parent,
291 const gfx::Rect& bounds);
293 // Creates a decorated window Widget in the same desktop context as |context|.
294 static Widget* CreateWindowWithContext(WidgetDelegate* delegate,
295 gfx::NativeWindow context);
296 static Widget* CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
297 gfx::NativeWindow context,
298 const gfx::Rect& bounds);
300 // Closes all Widgets that aren't identified as "secondary widgets". Called
301 // during application shutdown when the last non-secondary widget is closed.
302 static void CloseAllSecondaryWidgets();
304 // Converts a rectangle from one Widget's coordinate system to another's.
305 // Returns false if the conversion couldn't be made, because either these two
306 // Widgets do not have a common ancestor or they are not on the screen yet.
307 // The value of |*rect| won't be changed when false is returned.
308 static bool ConvertRect(const Widget* source,
309 const Widget* target,
310 gfx::Rect* rect);
312 // Retrieves the Widget implementation associated with the given
313 // NativeView or Window, or NULL if the supplied handle has no associated
314 // Widget.
315 static Widget* GetWidgetForNativeView(gfx::NativeView native_view);
316 static Widget* GetWidgetForNativeWindow(gfx::NativeWindow native_window);
318 // Retrieves the top level widget in a native view hierarchy
319 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW,
320 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own
321 // focus manager. This may be itself if the |native_view| is top level,
322 // or NULL if there is no toplevel in a native view hierarchy.
323 static Widget* GetTopLevelWidgetForNativeView(gfx::NativeView native_view);
325 // Returns all Widgets in |native_view|'s hierarchy, including itself if
326 // it is one.
327 static void GetAllChildWidgets(gfx::NativeView native_view,
328 Widgets* children);
330 // Returns all Widgets owned by |native_view| (including child widgets, but
331 // not including itself).
332 static void GetAllOwnedWidgets(gfx::NativeView native_view,
333 Widgets* owned);
335 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
336 // of the change.
337 static void ReparentNativeView(gfx::NativeView native_view,
338 gfx::NativeView new_parent);
340 // Returns the preferred size of the contents view of this window based on
341 // its localized size data. The width in cols is held in a localized string
342 // resource identified by |col_resource_id|, the height in the same fashion.
343 // TODO(beng): This should eventually live somewhere else, probably closer to
344 // ClientView.
345 static int GetLocalizedContentsWidth(int col_resource_id);
346 static int GetLocalizedContentsHeight(int row_resource_id);
347 static gfx::Size GetLocalizedContentsSize(int col_resource_id,
348 int row_resource_id);
350 // Returns true if the specified type requires a NonClientView.
351 static bool RequiresNonClientView(InitParams::Type type);
353 void Init(const InitParams& params);
355 // Returns the gfx::NativeView associated with this Widget.
356 gfx::NativeView GetNativeView() const;
358 // Returns the gfx::NativeWindow associated with this Widget. This may return
359 // NULL on some platforms if the widget was created with a type other than
360 // TYPE_WINDOW or TYPE_PANEL.
361 gfx::NativeWindow GetNativeWindow() const;
363 // Add/remove observer.
364 void AddObserver(WidgetObserver* observer);
365 void RemoveObserver(WidgetObserver* observer);
366 bool HasObserver(const WidgetObserver* observer) const;
368 // Add/remove removals observer.
369 void AddRemovalsObserver(WidgetRemovalsObserver* observer);
370 void RemoveRemovalsObserver(WidgetRemovalsObserver* observer);
371 bool HasRemovalsObserver(const WidgetRemovalsObserver* observer) const;
373 // Returns the accelerator given a command id. Returns false if there is
374 // no accelerator associated with a given id, which is a common condition.
375 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator) const;
377 // Forwarded from the RootView so that the widget can do any cleanup.
378 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails& details);
380 // Called right before changing the widget's parent NativeView to do any
381 // cleanup.
382 void NotifyNativeViewHierarchyWillChange();
384 // Called after changing the widget's parent NativeView. Notifies the RootView
385 // about the change.
386 void NotifyNativeViewHierarchyChanged();
388 // Called immediately before removing |view| from this widget.
389 void NotifyWillRemoveView(View* view);
391 // Returns the top level widget in a hierarchy (see is_top_level() for
392 // the definition of top level widget.) Will return NULL if called
393 // before the widget is attached to the top level widget's hierarchy.
394 Widget* GetTopLevelWidget();
395 const Widget* GetTopLevelWidget() const;
397 // Gets/Sets the WidgetDelegate.
398 WidgetDelegate* widget_delegate() const { return widget_delegate_; }
400 // Sets the specified view as the contents of this Widget. There can only
401 // be one contents view child of this Widget's RootView. This view is sized to
402 // fit the entire size of the RootView. The RootView takes ownership of this
403 // View, unless it is set as not being parent-owned.
404 void SetContentsView(View* view);
405 View* GetContentsView();
407 // Returns the bounds of the Widget in screen coordinates.
408 gfx::Rect GetWindowBoundsInScreen() const;
410 // Returns the bounds of the Widget's client area in screen coordinates.
411 gfx::Rect GetClientAreaBoundsInScreen() const;
413 // Retrieves the restored bounds for the window.
414 gfx::Rect GetRestoredBounds() const;
416 // Sizes and/or places the widget to the specified bounds, size or position.
417 void SetBounds(const gfx::Rect& bounds);
418 void SetSize(const gfx::Size& size);
420 // Sizes the window to the specified size and centerizes it.
421 void CenterWindow(const gfx::Size& size);
423 // Like SetBounds(), but ensures the Widget is fully visible on screen,
424 // resizing and/or repositioning as necessary. This is only useful for
425 // non-child widgets.
426 void SetBoundsConstrained(const gfx::Rect& bounds);
428 // Sets whether animations that occur when visibility is changed are enabled.
429 // Default is true.
430 void SetVisibilityChangedAnimationsEnabled(bool value);
432 // Sets the duration of visibility change animations.
433 void SetVisibilityAnimationDuration(const base::TimeDelta& duration);
435 // Sets the visibility transitions that should animate.
436 // Default behavior is to animate both show and hide.
437 void SetVisibilityAnimationTransition(VisibilityTransition transition);
439 // Starts a nested message loop that moves the window. This can be used to
440 // start a window move operation from a mouse or touch event. This returns
441 // when the move completes. |drag_offset| is the offset from the top left
442 // corner of the window to the point where the cursor is dragging, and is used
443 // to offset the bounds of the window from the cursor.
444 MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset,
445 MoveLoopSource source,
446 MoveLoopEscapeBehavior escape_behavior);
448 // Stops a previously started move loop. This is not immediate.
449 void EndMoveLoop();
451 // Places the widget in front of the specified widget in z-order.
452 void StackAboveWidget(Widget* widget);
453 void StackAbove(gfx::NativeView native_view);
454 void StackAtTop();
456 // Places the widget below the specified NativeView.
457 void StackBelow(gfx::NativeView native_view);
459 // Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
460 // be rectangular. Takes ownership of |shape|.
461 void SetShape(gfx::NativeRegion shape);
463 // Hides the widget then closes it after a return to the message loop.
464 virtual void Close();
466 // TODO(beng): Move off public API.
467 // Closes the widget immediately. Compare to |Close|. This will destroy the
468 // window handle associated with this Widget, so should not be called from
469 // any code that expects it to be valid beyond this call.
470 void CloseNow();
472 // Whether the widget has been asked to close itself. In particular this is
473 // set to true after Close() has been invoked on the NativeWidget.
474 bool IsClosed() const;
476 // Shows the widget. The widget is activated if during initialization the
477 // can_activate flag in the InitParams structure is set to true.
478 virtual void Show();
479 // Hides the widget.
480 void Hide();
482 // Like Show(), but does not activate the window.
483 void ShowInactive();
485 // Activates the widget, assuming it already exists and is visible.
486 void Activate();
488 // Deactivates the widget, making the next window in the Z order the active
489 // window.
490 void Deactivate();
492 // Returns whether the Widget is the currently active window.
493 virtual bool IsActive() const;
495 // Prevents the window from being rendered as deactivated. This state is
496 // reset automatically as soon as the window becomes activated again. There is
497 // no ability to control the state through this API as this leads to sync
498 // problems.
499 void DisableInactiveRendering();
501 // Sets the widget to be on top of all other widgets in the windowing system.
502 void SetAlwaysOnTop(bool on_top);
504 // Returns whether the widget has been set to be on top of most other widgets
505 // in the windowing system.
506 bool IsAlwaysOnTop() const;
508 // Sets the widget to be visible on all work spaces.
509 void SetVisibleOnAllWorkspaces(bool always_visible);
511 // Maximizes/minimizes/restores the window.
512 void Maximize();
513 void Minimize();
514 void Restore();
516 // Whether or not the window is maximized or minimized.
517 virtual bool IsMaximized() const;
518 bool IsMinimized() const;
520 // Accessors for fullscreen state.
521 void SetFullscreen(bool fullscreen);
522 bool IsFullscreen() const;
524 // Sets the opacity of the widget. This may allow widgets behind the widget
525 // in the Z-order to become visible, depending on the capabilities of the
526 // underlying windowing system.
527 void SetOpacity(unsigned char opacity);
529 // Sets whether or not the window should show its frame as a "transient drag
530 // frame" - slightly transparent and without the standard window controls.
531 void SetUseDragFrame(bool use_drag_frame);
533 // Flashes the frame of the window to draw attention to it. Currently only
534 // implemented on Windows for non-Aura.
535 void FlashFrame(bool flash);
537 // Returns the View at the root of the View hierarchy contained by this
538 // Widget.
539 View* GetRootView();
540 const View* GetRootView() const;
542 // A secondary widget is one that is automatically closed (via Close()) when
543 // all non-secondary widgets are closed.
544 // Default is true.
545 // TODO(beng): This is an ugly API, should be handled implicitly via
546 // transience.
547 void set_is_secondary_widget(bool is_secondary_widget) {
548 is_secondary_widget_ = is_secondary_widget;
550 bool is_secondary_widget() const { return is_secondary_widget_; }
552 // Returns whether the Widget is visible to the user.
553 virtual bool IsVisible() const;
555 // Returns the ThemeProvider that provides theme resources for this Widget.
556 virtual ui::ThemeProvider* GetThemeProvider() const;
558 ui::NativeTheme* GetNativeTheme() {
559 return const_cast<ui::NativeTheme*>(
560 const_cast<const Widget*>(this)->GetNativeTheme());
562 const ui::NativeTheme* GetNativeTheme() const;
564 // Returns the FocusManager for this widget.
565 // Note that all widgets in a widget hierarchy share the same focus manager.
566 FocusManager* GetFocusManager();
567 const FocusManager* GetFocusManager() const;
569 // Returns the focused text input client within this widget.
570 ui::TextInputClient* GetFocusedTextInputClient();
572 // Returns the InputMethod for this widget.
573 // Note that all widgets in a widget hierarchy share the same input method.
574 InputMethod* GetInputMethod();
575 const InputMethod* GetInputMethod() const;
577 // Returns the ui::InputMethod for this widget.
578 // TODO(yukishiino): Rename this method to GetInputMethod once we remove
579 // views::InputMethod.
580 ui::InputMethod* GetHostInputMethod();
582 // Starts a drag operation for the specified view. This blocks until the drag
583 // operation completes. |view| can be NULL.
584 // If the view is non-NULL it can be accessed during the drag by calling
585 // dragged_view(). If the view has not been deleted during the drag,
586 // OnDragDone() is called on it. |location| is in the widget's coordinate
587 // system.
588 void RunShellDrag(View* view,
589 const ui::OSExchangeData& data,
590 const gfx::Point& location,
591 int operation,
592 ui::DragDropTypes::DragEventSource source);
594 // Returns the view that requested the current drag operation via
595 // RunShellDrag(), or NULL if there is no such view or drag operation.
596 View* dragged_view() { return dragged_view_; }
598 // Adds the specified |rect| in client area coordinates to the rectangle to be
599 // redrawn.
600 virtual void SchedulePaintInRect(const gfx::Rect& rect);
602 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
603 // before the current is restored.
604 void SetCursor(gfx::NativeCursor cursor);
606 // Returns true if and only if mouse events are enabled.
607 bool IsMouseEventsEnabled() const;
609 // Sets/Gets a native window property on the underlying native window object.
610 // Returns NULL if the property does not exist. Setting the property value to
611 // NULL removes the property.
612 void SetNativeWindowProperty(const char* name, void* value);
613 void* GetNativeWindowProperty(const char* name) const;
615 // Tell the window to update its title from the delegate.
616 void UpdateWindowTitle();
618 // Tell the window to update its icon from the delegate.
619 void UpdateWindowIcon();
621 // Retrieves the focus traversable for this widget.
622 FocusTraversable* GetFocusTraversable();
624 // Notifies the view hierarchy contained in this widget that theme resources
625 // changed.
626 void ThemeChanged();
628 // Notifies the view hierarchy contained in this widget that locale resources
629 // changed.
630 void LocaleChanged();
632 // Notifies the view hierarchy contained in this widget that the device scale
633 // factor changed.
634 void DeviceScaleFactorChanged(float device_scale_factor);
636 void SetFocusTraversableParent(FocusTraversable* parent);
637 void SetFocusTraversableParentView(View* parent_view);
639 // Clear native focus set to the Widget's NativeWidget.
640 void ClearNativeFocus();
642 void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; }
643 FrameType frame_type() const { return frame_type_; }
645 // Creates an appropriate NonClientFrameView for this widget. The
646 // WidgetDelegate is given the first opportunity to create one, followed by
647 // the NativeWidget implementation. If both return NULL, a default one is
648 // created.
649 virtual NonClientFrameView* CreateNonClientFrameView();
651 // Whether we should be using a native frame.
652 bool ShouldUseNativeFrame() const;
654 // Determines whether the window contents should be rendered transparently
655 // (for example, so that they can overhang onto the window title bar).
656 bool ShouldWindowContentsBeTransparent() const;
658 // Forces the frame into the alternate frame type (custom or native) depending
659 // on its current state.
660 void DebugToggleFrameType();
662 // Tell the window that something caused the frame type to change.
663 void FrameTypeChanged();
665 NonClientView* non_client_view() {
666 return const_cast<NonClientView*>(
667 const_cast<const Widget*>(this)->non_client_view());
669 const NonClientView* non_client_view() const {
670 return non_client_view_;
673 ClientView* client_view() {
674 return const_cast<ClientView*>(
675 const_cast<const Widget*>(this)->client_view());
677 const ClientView* client_view() const {
678 // non_client_view_ may be NULL, especially during creation.
679 return non_client_view_ ? non_client_view_->client_view() : NULL;
682 ui::Compositor* GetCompositor() {
683 return const_cast<ui::Compositor*>(
684 const_cast<const Widget*>(this)->GetCompositor());
686 const ui::Compositor* GetCompositor() const;
688 // Returns the widget's layer, if any.
689 ui::Layer* GetLayer() {
690 return const_cast<ui::Layer*>(
691 const_cast<const Widget*>(this)->GetLayer());
693 const ui::Layer* GetLayer() const;
695 // Reorders the widget's child NativeViews which are associated to the view
696 // tree (eg via a NativeViewHost) to match the z-order of the views in the
697 // view tree. The z-order of views with layers relative to views with
698 // associated NativeViews is used to reorder the NativeView layers. This
699 // method assumes that the widget's child layers which are owned by a view are
700 // already in the correct z-order relative to each other and does no
701 // reordering if there are no views with an associated NativeView.
702 void ReorderNativeViews();
704 // Schedules an update to the root layers. The actual processing occurs when
705 // GetRootLayers() is invoked.
706 void UpdateRootLayers();
708 const NativeWidget* native_widget() const;
709 NativeWidget* native_widget();
711 internal::NativeWidgetPrivate* native_widget_private() {
712 return native_widget_;
714 const internal::NativeWidgetPrivate* native_widget_private() const {
715 return native_widget_;
718 // Sets capture to the specified view. This makes it so that all mouse, touch
719 // and gesture events go to |view|. If |view| is NULL, the widget still
720 // obtains event capture, but the events will go to the view they'd normally
721 // go to.
722 void SetCapture(View* view);
724 // Releases capture.
725 void ReleaseCapture();
727 // Returns true if the widget has capture.
728 bool HasCapture();
730 void set_auto_release_capture(bool auto_release_capture) {
731 auto_release_capture_ = auto_release_capture;
734 // Returns the font used for tooltips.
735 TooltipManager* GetTooltipManager();
736 const TooltipManager* GetTooltipManager() const;
738 void set_focus_on_creation(bool focus_on_creation) {
739 focus_on_creation_ = focus_on_creation;
742 // True if the widget is considered top level widget. Top level widget
743 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE,
744 // POPUP or MENU, and has a focus manager and input method object associated
745 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
746 bool is_top_level() const { return is_top_level_; }
748 // True when window movement via mouse interaction with the frame is disabled.
749 bool movement_disabled() const { return movement_disabled_; }
750 void set_movement_disabled(bool disabled) { movement_disabled_ = disabled; }
752 // Returns the work area bounds of the screen the Widget belongs to.
753 gfx::Rect GetWorkAreaBoundsInScreen() const;
755 // Creates and dispatches synthesized mouse move event using the current
756 // mouse location to refresh hovering status in the widget.
757 void SynthesizeMouseMoveEvent();
759 // Called by our RootView after it has performed a Layout. Used to forward
760 // window sizing information to the window server on some platforms.
761 void OnRootViewLayout();
763 // Whether the widget supports translucency.
764 bool IsTranslucentWindowOpacitySupported() const;
766 // Called when the delegate's CanResize or CanMaximize changes.
767 void OnSizeConstraintsChanged();
769 // Notification that our owner is closing.
770 // NOTE: this is not invoked for aura as it's currently not needed there.
771 // Under aura menus close by way of activation getting reset when the owner
772 // closes.
773 virtual void OnOwnerClosing();
775 // Overridden from NativeWidgetDelegate:
776 bool IsModal() const override;
777 bool IsDialogBox() const override;
778 bool CanActivate() const override;
779 bool IsInactiveRenderingDisabled() const override;
780 void EnableInactiveRendering() override;
781 void OnNativeWidgetActivationChanged(bool active) override;
782 void OnNativeFocus() override;
783 void OnNativeBlur() override;
784 void OnNativeWidgetVisibilityChanging(bool visible) override;
785 void OnNativeWidgetVisibilityChanged(bool visible) override;
786 void OnNativeWidgetCreated(bool desktop_widget) override;
787 void OnNativeWidgetDestroying() override;
788 void OnNativeWidgetDestroyed() override;
789 gfx::Size GetMinimumSize() const override;
790 gfx::Size GetMaximumSize() const override;
791 void OnNativeWidgetMove() override;
792 void OnNativeWidgetSizeChanged(const gfx::Size& new_size) override;
793 void OnNativeWidgetWindowShowStateChanged() override;
794 void OnNativeWidgetBeginUserBoundsChange() override;
795 void OnNativeWidgetEndUserBoundsChange() override;
796 bool HasFocusManager() const override;
797 bool OnNativeWidgetPaintAccelerated(const gfx::Rect& dirty_region) override;
798 void OnNativeWidgetPaint(const ui::PaintContext& context) override;
799 int GetNonClientComponent(const gfx::Point& point) override;
800 void OnKeyEvent(ui::KeyEvent* event) override;
801 void OnMouseEvent(ui::MouseEvent* event) override;
802 void OnMouseCaptureLost() override;
803 void OnScrollEvent(ui::ScrollEvent* event) override;
804 void OnGestureEvent(ui::GestureEvent* event) override;
805 bool ExecuteCommand(int command_id) override;
806 InputMethod* GetInputMethodDirect() override;
807 const std::vector<ui::Layer*>& GetRootLayers() override;
808 bool HasHitTestMask() const override;
809 void GetHitTestMask(gfx::Path* mask) const override;
810 Widget* AsWidget() override;
811 const Widget* AsWidget() const override;
812 bool SetInitialFocus(ui::WindowShowState show_state) override;
814 // Overridden from ui::EventSource:
815 ui::EventProcessor* GetEventProcessor() override;
817 // Overridden from FocusTraversable:
818 FocusSearch* GetFocusSearch() override;
819 FocusTraversable* GetFocusTraversableParent() override;
820 View* GetFocusTraversableParentView() override;
822 // Overridden from ui::NativeThemeObserver:
823 void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
825 protected:
826 // Creates the RootView to be used within this Widget. Subclasses may override
827 // to create custom RootViews that do specialized event processing.
828 // TODO(beng): Investigate whether or not this is needed.
829 virtual internal::RootView* CreateRootView();
831 // Provided to allow the NativeWidget implementations to destroy the RootView
832 // _before_ the focus manager/tooltip manager.
833 // TODO(beng): remove once we fold those objects onto this one.
834 void DestroyRootView();
836 // Notification that a drag will start. Default implementation does nothing.
837 virtual void OnDragWillStart();
839 // Notification that the drag performed by RunShellDrag() has completed.
840 virtual void OnDragComplete();
842 private:
843 friend class ComboboxTest;
844 friend class TextfieldTest;
846 // Sets the value of |disable_inactive_rendering_|. If the value changes,
847 // both the NonClientView and WidgetDelegate are notified.
848 void SetInactiveRenderingDisabled(bool value);
850 // Persists the window's restored position and "show" state using the
851 // window delegate.
852 void SaveWindowPlacement();
854 // Invokes SaveWindowPlacement() if the native widget has been initialized.
855 // This is called at times when the native widget may not have been
856 // initialized.
857 void SaveWindowPlacementIfInitialized();
859 // Sizes and positions the window just after it is created.
860 void SetInitialBounds(const gfx::Rect& bounds);
862 // Sizes and positions the frameless window just after it is created.
863 void SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds);
865 // Returns the bounds and "show" state from the delegate. Returns true if
866 // the delegate wants to use a specified bounds.
867 bool GetSavedWindowPlacement(gfx::Rect* bounds,
868 ui::WindowShowState* show_state);
870 // Creates and initializes a new InputMethod and returns it, otherwise null.
871 scoped_ptr<InputMethod> CreateInputMethod();
873 // Sets a different InputMethod instance to this widget. The instance
874 // must not be initialized, the ownership will be assumed by the widget.
875 // It's only for testing purpose.
876 void ReplaceInputMethod(InputMethod* input_method);
878 internal::NativeWidgetPrivate* native_widget_;
880 ObserverList<WidgetObserver> observers_;
882 ObserverList<WidgetRemovalsObserver> removals_observers_;
884 // Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
885 // to Init() a default WidgetDelegate is created.
886 WidgetDelegate* widget_delegate_;
888 // The root of the View hierarchy attached to this window.
889 // WARNING: see warning in tooltip_manager_ for ordering dependencies with
890 // this and tooltip_manager_.
891 scoped_ptr<internal::RootView> root_view_;
893 // The View that provides the non-client area of the window (title bar,
894 // window controls, sizing borders etc). To use an implementation other than
895 // the default, this class must be sub-classed and this value set to the
896 // desired implementation before calling |InitWindow()|.
897 NonClientView* non_client_view_;
899 // The focus manager keeping track of focus for this Widget and any of its
900 // children. NULL for non top-level widgets.
901 // WARNING: RootView's destructor calls into the FocusManager. As such, this
902 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView().
903 scoped_ptr<FocusManager> focus_manager_;
905 // A theme provider to use when no other theme provider is specified.
906 scoped_ptr<ui::DefaultThemeProvider> default_theme_provider_;
908 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
909 // started from.
910 View* dragged_view_;
912 // See class documentation for Widget above for a note about ownership.
913 InitParams::Ownership ownership_;
915 // See set_is_secondary_widget().
916 bool is_secondary_widget_;
918 // The current frame type in use by this window. Defaults to
919 // FRAME_TYPE_DEFAULT.
920 FrameType frame_type_;
922 // True when the window should be rendered as active, regardless of whether
923 // or not it actually is.
924 bool disable_inactive_rendering_;
926 // Set to true if the widget is in the process of closing.
927 bool widget_closed_;
929 // The saved "show" state for this window. See note in SetInitialBounds
930 // that explains why we save this.
931 ui::WindowShowState saved_show_state_;
933 // The restored bounds used for the initial show. This is only used if
934 // |saved_show_state_| is maximized.
935 gfx::Rect initial_restored_bounds_;
937 // Focus is automatically set to the view provided by the delegate
938 // when the widget is shown. Set this value to false to override
939 // initial focus for the widget.
940 bool focus_on_creation_;
942 mutable scoped_ptr<InputMethod> input_method_;
944 // See |is_top_level()| accessor.
945 bool is_top_level_;
947 // Tracks whether native widget has been initialized.
948 bool native_widget_initialized_;
950 // Whether native widget has been destroyed.
951 bool native_widget_destroyed_;
953 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
954 // If true, the mouse is currently down.
955 bool is_mouse_button_pressed_;
957 // True if capture losses should be ignored.
958 bool ignore_capture_loss_;
960 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
961 // The following are used to detect duplicate mouse move events and not
962 // deliver them. Displaying a window may result in the system generating
963 // duplicate move events even though the mouse hasn't moved.
964 bool last_mouse_event_was_move_;
965 gfx::Point last_mouse_event_position_;
967 // True if event capture should be released on a mouse up event. Default is
968 // true.
969 bool auto_release_capture_;
971 // See description in GetRootLayers().
972 std::vector<ui::Layer*> root_layers_;
974 // Is |root_layers_| out of date?
975 bool root_layers_dirty_;
977 // True when window movement via mouse interaction with the frame should be
978 // disabled.
979 bool movement_disabled_;
981 ScopedObserver<ui::NativeTheme, ui::NativeThemeObserver> observer_manager_;
983 DISALLOW_COPY_AND_ASSIGN(Widget);
986 } // namespace views
988 #endif // UI_VIEWS_WIDGET_WIDGET_H_