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 "ui/aura/window_layer_type.h"
16 #include "ui/base/ui_base_types.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/views/focus/focus_manager.h"
20 #include "ui/views/widget/native_widget_delegate.h"
21 #include "ui/views/window/client_view.h"
22 #include "ui/views/window/non_client_view.h"
25 // Windows headers define macros for these function names which screw with us.
26 #if defined(IsMaximized)
29 #if defined(IsMinimized)
32 #if defined(CreateWindow)
46 class DefaultThemeProvider;
55 class DesktopWindowTreeHost;
58 class NonClientFrameView;
65 class NativeWidgetPrivate;
69 ////////////////////////////////////////////////////////////////////////////////
72 // Encapsulates the platform-specific rendering, event receiving and widget
73 // management aspects of the UI framework.
75 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
76 // Widget is a platform-independent type that communicates with a platform or
77 // context specific NativeWidget implementation.
79 // A special note on ownership:
81 // Depending on the value of the InitParams' ownership field, the Widget
82 // either owns or is owned by its NativeWidget:
84 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default)
85 // The Widget instance is owned by its NativeWidget. When the NativeWidget
86 // is destroyed (in response to a native destruction message), it deletes
87 // the Widget from its destructor.
88 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default)
89 // The Widget instance owns its NativeWidget. This state implies someone
90 // else wants to control the lifetime of this object. When they destroy
91 // the Widget it is responsible for destroying the NativeWidget (from its
94 class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
95 public FocusTraversable {
97 typedef std::set<Widget*> Widgets;
100 FRAME_TYPE_DEFAULT, // Use whatever the default would be.
101 FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame.
102 FRAME_TYPE_FORCE_NATIVE // Force the native frame.
105 // Result from RunMoveLoop().
106 enum MoveLoopResult {
107 // The move loop completed successfully.
108 MOVE_LOOP_SUCCESSFUL,
110 // The user canceled the move loop.
114 // Source that initiated the move loop.
115 enum MoveLoopSource {
116 MOVE_LOOP_SOURCE_MOUSE,
117 MOVE_LOOP_SOURCE_TOUCH,
120 // Behavior when escape is pressed during a move loop.
121 enum MoveLoopEscapeBehavior {
122 // Indicates the window should be hidden.
123 MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE,
125 // Indicates the window should not be hidden.
126 MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE,
129 struct VIEWS_EXPORT InitParams {
131 TYPE_WINDOW, // A decorated Window, like a frame window.
132 // Widgets of TYPE_WINDOW will have a NonClientView.
133 TYPE_PANEL, // Always on top window managed by PanelManager.
134 // Widgets of TYPE_PANEL will have a NonClientView.
135 TYPE_WINDOW_FRAMELESS,
136 // An undecorated Window.
137 TYPE_CONTROL, // A control, like a button.
138 TYPE_POPUP, // An undecorated Window, with transient properties.
139 TYPE_MENU, // An undecorated Window, with transient properties
140 // specialized to menus.
143 TYPE_DRAG, // An undecorated Window, used during a drag-and-drop to
144 // show the drag image.
148 // Infer fully opaque or not. For WinAura, top-level windows that are not
149 // of TYPE_WINDOW are translucent so that they can be made to fade in. In
150 // all other cases, windows are fully opaque.
154 // Possibly translucent/transparent.
159 // Default. Creator is not responsible for managing the lifetime of the
160 // Widget, it is destroyed when the corresponding NativeWidget is
162 NATIVE_WIDGET_OWNS_WIDGET,
163 // Used when the Widget is owned by someone other than the NativeWidget,
164 // e.g. a scoped_ptr in tests.
165 WIDGET_OWNS_NATIVE_WIDGET
169 explicit InitParams(Type type);
173 // If NULL, a default implementation will be constructed.
174 WidgetDelegate* delegate;
176 // If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
177 // If OPAQUE_WINDOW, we can perform optimizations based on the widget being
178 // fully opaque. Defaults to TRANSLUCENT_WINDOW if
179 // ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
180 // non-window widgets.
181 WindowOpacity opacity;
186 bool mirror_origin_in_rtl;
188 // Specifies that the system default caption and icon should not be
189 // rendered, and that the client area should be equivalent to the window
190 // area. Only used on some platforms (Windows and Linux).
191 bool remove_standard_frame;
192 // Only used by ShellWindow on Windows. Specifies that the default icon of
193 // packaged app should be the system default icon.
194 bool use_system_default_icon;
195 // Whether the widget should be maximized or minimized.
196 ui::WindowShowState show_state;
197 // Should the widget be double buffered? Default is false.
199 gfx::NativeView parent;
200 // Specifies the initial bounds of the Widget. Default is empty, which means
201 // the NativeWidget may specify a default size. If the parent is specified,
202 // |bounds| is in the parent's coordinate system. If the parent is not
203 // specified, it's in screen's global coordinate system.
205 // When set, this value is used as the Widget's NativeWidget implementation.
206 // The Widget will not construct a default one. Default is NULL.
207 NativeWidget* native_widget;
208 // Aura-only. Provides a DesktopWindowTreeHost implementation to use instead
209 // of the default one.
210 // TODO(beng): Figure out if there's a better way to expose this, e.g. get
211 // rid of NW subclasses and do this all via message handling.
212 DesktopWindowTreeHost* desktop_root_window_host;
213 // Whether this window is intended to be a toplevel window with no
214 // attachment to any other window. (This may be a transient window if
217 // Only used by NativeWidgetAura. Specifies the type of layer for the
218 // aura::Window. Default is WINDOW_LAYER_TEXTURED.
219 aura::WindowLayerType layer_type;
220 // Only used by Aura. Provides a context window whose RootWindow is
221 // consulted during widget creation to determine where in the Window
222 // hierarchy this widget should be placed. (This is separate from |parent|;
223 // if you pass a RootWindow to |parent|, your window will be parented to
224 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
225 // where it wants your window placed.) NULL is not allowed if you are using
227 gfx::NativeView context;
228 // If true, forces the window to be shown in the taskbar, even for window
229 // types that do not appear in the taskbar by default (popup and bubble).
230 bool force_show_in_taskbar;
231 // Only used by X11, for root level windows. Specifies the res_name and
232 // res_class fields, respectively, of the WM_CLASS window property. Controls
233 // window grouping and desktop file matching in Linux window managers.
234 std::string wm_role_name;
235 std::string wm_class_name;
236 std::string wm_class_class;
237 // Only used by X11, for root level windows. Specifies the PID set in
238 // _NET_WM_PID window property.
245 // Creates a toplevel window with no context. These methods should only be
246 // used in cases where there is no contextual information because we're
247 // creating a toplevel window connected to no other event.
249 // If you have any parenting or context information, or can pass that
250 // information, prefer the WithParent or WithContext versions of these
252 static Widget* CreateWindow(WidgetDelegate* delegate);
253 static Widget* CreateWindowWithBounds(WidgetDelegate* delegate,
254 const gfx::Rect& bounds);
256 // Creates a decorated window Widget with the specified properties.
257 static Widget* CreateWindowWithParent(WidgetDelegate* delegate,
258 gfx::NativeWindow parent);
259 static Widget* CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
260 gfx::NativeWindow parent,
261 const gfx::Rect& bounds);
263 // Creates a decorated window Widget in the same desktop context as |context|.
264 static Widget* CreateWindowWithContext(WidgetDelegate* delegate,
265 gfx::NativeView context);
266 static Widget* CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
267 gfx::NativeView context,
268 const gfx::Rect& bounds);
270 // Creates an undecorated child window Widget parented to |parent|.
271 static Widget* CreateWindowAsFramelessChild(WidgetDelegate* widget_delegate,
272 gfx::NativeView parent);
274 // Closes all Widgets that aren't identified as "secondary widgets". Called
275 // during application shutdown when the last non-secondary widget is closed.
276 static void CloseAllSecondaryWidgets();
278 // Converts a rectangle from one Widget's coordinate system to another's.
279 // Returns false if the conversion couldn't be made, because either these two
280 // Widgets do not have a common ancestor or they are not on the screen yet.
281 // The value of |*rect| won't be changed when false is returned.
282 static bool ConvertRect(const Widget* source,
283 const Widget* target,
286 // Retrieves the Widget implementation associated with the given
287 // NativeView or Window, or NULL if the supplied handle has no associated
289 static Widget* GetWidgetForNativeView(gfx::NativeView native_view);
290 static Widget* GetWidgetForNativeWindow(gfx::NativeWindow native_window);
292 // Retrieves the top level widget in a native view hierarchy
293 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW,
294 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own
295 // focus manager. This may be itself if the |native_view| is top level,
296 // or NULL if there is no toplevel in a native view hierarchy.
297 static Widget* GetTopLevelWidgetForNativeView(gfx::NativeView native_view);
299 // Returns all Widgets in |native_view|'s hierarchy, including itself if
301 static void GetAllChildWidgets(gfx::NativeView native_view,
304 // Returns all non-child Widgets owned by |native_view|.
305 static void GetAllOwnedWidgets(gfx::NativeView native_view,
308 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
310 static void ReparentNativeView(gfx::NativeView native_view,
311 gfx::NativeView new_parent);
313 // Returns the preferred size of the contents view of this window based on
314 // its localized size data. The width in cols is held in a localized string
315 // resource identified by |col_resource_id|, the height in the same fashion.
316 // TODO(beng): This should eventually live somewhere else, probably closer to
318 static int GetLocalizedContentsWidth(int col_resource_id);
319 static int GetLocalizedContentsHeight(int row_resource_id);
320 static gfx::Size GetLocalizedContentsSize(int col_resource_id,
321 int row_resource_id);
323 // Returns true if the specified type requires a NonClientView.
324 static bool RequiresNonClientView(InitParams::Type type);
326 void Init(const InitParams& params);
328 // Returns the gfx::NativeView associated with this Widget.
329 gfx::NativeView GetNativeView() const;
331 // Returns the gfx::NativeWindow associated with this Widget. This may return
332 // NULL on some platforms if the widget was created with a type other than
333 // TYPE_WINDOW or TYPE_PANEL.
334 gfx::NativeWindow GetNativeWindow() const;
336 // Add/remove observer.
337 void AddObserver(WidgetObserver* observer);
338 void RemoveObserver(WidgetObserver* observer);
339 bool HasObserver(WidgetObserver* observer);
341 // Returns the accelerator given a command id. Returns false if there is
342 // no accelerator associated with a given id, which is a common condition.
343 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
345 // Forwarded from the RootView so that the widget can do any cleanup.
346 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails& details);
348 // Called right before changing the widget's parent NativeView to do any
350 void NotifyNativeViewHierarchyWillChange();
352 // Called after changing the widget's parent NativeView. Notifies the RootView
354 void NotifyNativeViewHierarchyChanged();
356 // Returns the top level widget in a hierarchy (see is_top_level() for
357 // the definition of top level widget.) Will return NULL if called
358 // before the widget is attached to the top level widget's hierarchy.
359 Widget* GetTopLevelWidget();
360 const Widget* GetTopLevelWidget() const;
362 // Gets/Sets the WidgetDelegate.
363 WidgetDelegate* widget_delegate() const { return widget_delegate_; }
365 // Sets the specified view as the contents of this Widget. There can only
366 // be one contents view child of this Widget's RootView. This view is sized to
367 // fit the entire size of the RootView. The RootView takes ownership of this
368 // View, unless it is set as not being parent-owned.
369 void SetContentsView(View* view);
370 View* GetContentsView();
372 // Returns the bounds of the Widget in screen coordinates.
373 gfx::Rect GetWindowBoundsInScreen() const;
375 // Returns the bounds of the Widget's client area in screen coordinates.
376 gfx::Rect GetClientAreaBoundsInScreen() const;
378 // Retrieves the restored bounds for the window.
379 gfx::Rect GetRestoredBounds() const;
381 // Sizes and/or places the widget to the specified bounds, size or position.
382 void SetBounds(const gfx::Rect& bounds);
383 void SetSize(const gfx::Size& size);
385 // Sizes the window to the specified size and centerizes it.
386 void CenterWindow(const gfx::Size& size);
388 // Like SetBounds(), but ensures the Widget is fully visible on screen,
389 // resizing and/or repositioning as necessary. This is only useful for
390 // non-child widgets.
391 void SetBoundsConstrained(const gfx::Rect& bounds);
393 // Sets whether animations that occur when visibility is changed are enabled.
395 void SetVisibilityChangedAnimationsEnabled(bool value);
397 // Starts a nested message loop that moves the window. This can be used to
398 // start a window move operation from a mouse or touch event. This returns
399 // when the move completes. |drag_offset| is the offset from the top left
400 // corner of the window to the point where the cursor is dragging, and is used
401 // to offset the bounds of the window from the cursor.
402 MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset,
403 MoveLoopSource source,
404 MoveLoopEscapeBehavior escape_behavior);
406 // Stops a previously started move loop. This is not immediate.
409 // Places the widget in front of the specified widget in z-order.
410 void StackAboveWidget(Widget* widget);
411 void StackAbove(gfx::NativeView native_view);
414 // Places the widget below the specified NativeView.
415 void StackBelow(gfx::NativeView native_view);
417 // Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
418 // be rectangular. Takes ownership of |shape|.
419 void SetShape(gfx::NativeRegion shape);
421 // Hides the widget then closes it after a return to the message loop.
422 virtual void Close();
424 // TODO(beng): Move off public API.
425 // Closes the widget immediately. Compare to |Close|. This will destroy the
426 // window handle associated with this Widget, so should not be called from
427 // any code that expects it to be valid beyond this call.
430 // Whether the widget has been asked to close itself. In particular this is
431 // set to true after Close() has been invoked on the NativeWidget.
432 bool IsClosed() const;
434 // Shows the widget. The widget is activated if during initialization the
435 // can_activate flag in the InitParams structure is set to true.
440 // Like Show(), but does not activate the window.
443 // Activates the widget, assuming it already exists and is visible.
446 // Deactivates the widget, making the next window in the Z order the active
450 // Returns whether the Widget is the currently active window.
451 virtual bool IsActive() const;
453 // Prevents the window from being rendered as deactivated. This state is
454 // reset automatically as soon as the window becomes activated again. There is
455 // no ability to control the state through this API as this leads to sync
457 void DisableInactiveRendering();
459 // Sets the widget to be on top of all other widgets in the windowing system.
460 void SetAlwaysOnTop(bool on_top);
462 // Returns whether the widget has been set to be on top of most other widgets
463 // in the windowing system.
464 bool IsAlwaysOnTop() const;
466 // Maximizes/minimizes/restores the window.
471 // Whether or not the window is maximized or minimized.
472 virtual bool IsMaximized() const;
473 bool IsMinimized() const;
475 // Accessors for fullscreen state.
476 void SetFullscreen(bool fullscreen);
477 bool IsFullscreen() const;
479 // Sets the opacity of the widget. This may allow widgets behind the widget
480 // in the Z-order to become visible, depending on the capabilities of the
481 // underlying windowing system.
482 void SetOpacity(unsigned char opacity);
484 // Sets whether or not the window should show its frame as a "transient drag
485 // frame" - slightly transparent and without the standard window controls.
486 void SetUseDragFrame(bool use_drag_frame);
488 // Flashes the frame of the window to draw attention to it. Currently only
489 // implemented on Windows for non-Aura.
490 void FlashFrame(bool flash);
492 // Returns the View at the root of the View hierarchy contained by this
495 const View* GetRootView() const;
497 // A secondary widget is one that is automatically closed (via Close()) when
498 // all non-secondary widgets are closed.
500 // TODO(beng): This is an ugly API, should be handled implicitly via
502 void set_is_secondary_widget(bool is_secondary_widget) {
503 is_secondary_widget_ = is_secondary_widget;
505 bool is_secondary_widget() const { return is_secondary_widget_; }
507 // Returns whether the Widget is visible to the user.
508 virtual bool IsVisible() const;
510 // Returns the ThemeProvider that provides theme resources for this Widget.
511 virtual ui::ThemeProvider* GetThemeProvider() const;
513 ui::NativeTheme* GetNativeTheme() {
514 return const_cast<ui::NativeTheme*>(
515 const_cast<const Widget*>(this)->GetNativeTheme());
517 const ui::NativeTheme* GetNativeTheme() const;
519 // Returns the FocusManager for this widget.
520 // Note that all widgets in a widget hierarchy share the same focus manager.
521 FocusManager* GetFocusManager();
522 const FocusManager* GetFocusManager() const;
524 // Returns the InputMethod for this widget.
525 // Note that all widgets in a widget hierarchy share the same input method.
526 InputMethod* GetInputMethod();
527 const InputMethod* GetInputMethod() const;
529 // Starts a drag operation for the specified view. This blocks until the drag
530 // operation completes. |view| can be NULL.
531 // If the view is non-NULL it can be accessed during the drag by calling
532 // dragged_view(). If the view has not been deleted during the drag,
533 // OnDragDone() is called on it. |location| is in the widget's coordinate
535 void RunShellDrag(View* view,
536 const ui::OSExchangeData& data,
537 const gfx::Point& location,
539 ui::DragDropTypes::DragEventSource source);
541 // Returns the view that requested the current drag operation via
542 // RunShellDrag(), or NULL if there is no such view or drag operation.
543 View* dragged_view() { return dragged_view_; }
545 // Adds the specified |rect| in client area coordinates to the rectangle to be
547 virtual void SchedulePaintInRect(const gfx::Rect& rect);
549 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
550 // before the current is restored.
551 void SetCursor(gfx::NativeCursor cursor);
553 // Returns true if and only if mouse events are enabled.
554 bool IsMouseEventsEnabled() const;
556 // Sets/Gets a native window property on the underlying native window object.
557 // Returns NULL if the property does not exist. Setting the property value to
558 // NULL removes the property.
559 void SetNativeWindowProperty(const char* name, void* value);
560 void* GetNativeWindowProperty(const char* name) const;
562 // Tell the window to update its title from the delegate.
563 void UpdateWindowTitle();
565 // Tell the window to update its icon from the delegate.
566 void UpdateWindowIcon();
568 // Retrieves the focus traversable for this widget.
569 FocusTraversable* GetFocusTraversable();
571 // Notifies the view hierarchy contained in this widget that theme resources
575 // Notifies the view hierarchy contained in this widget that locale resources
577 void LocaleChanged();
579 void SetFocusTraversableParent(FocusTraversable* parent);
580 void SetFocusTraversableParentView(View* parent_view);
582 // Clear native focus set to the Widget's NativeWidget.
583 void ClearNativeFocus();
585 void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; }
586 FrameType frame_type() const { return frame_type_; }
588 // Creates an appropriate NonClientFrameView for this widget. The
589 // WidgetDelegate is given the first opportunity to create one, followed by
590 // the NativeWidget implementation. If both return NULL, a default one is
592 virtual NonClientFrameView* CreateNonClientFrameView();
594 // Whether we should be using a native frame.
595 bool ShouldUseNativeFrame() const;
597 // Forces the frame into the alternate frame type (custom or native) depending
598 // on its current state.
599 void DebugToggleFrameType();
601 // Tell the window that something caused the frame type to change.
602 void FrameTypeChanged();
604 NonClientView* non_client_view() {
605 return const_cast<NonClientView*>(
606 const_cast<const Widget*>(this)->non_client_view());
608 const NonClientView* non_client_view() const {
609 return non_client_view_;
612 ClientView* client_view() {
613 return const_cast<ClientView*>(
614 const_cast<const Widget*>(this)->client_view());
616 const ClientView* client_view() const {
617 // non_client_view_ may be NULL, especially during creation.
618 return non_client_view_ ? non_client_view_->client_view() : NULL;
621 const ui::Compositor* GetCompositor() const;
622 ui::Compositor* GetCompositor();
624 // Returns the widget's layer, if any.
625 ui::Layer* GetLayer();
627 // Reorders the widget's child NativeViews which are associated to the view
628 // tree (eg via a NativeViewHost) to match the z-order of the views in the
629 // view tree. The z-order of views with layers relative to views with
630 // associated NativeViews is used to reorder the NativeView layers. This
631 // method assumes that the widget's child layers which are owned by a view are
632 // already in the correct z-order relative to each other and does no
633 // reordering if there are no views with an associated NativeView.
634 void ReorderNativeViews();
636 // Schedules an update to the root layers. The actual processing occurs when
637 // GetRootLayers() is invoked.
638 void UpdateRootLayers();
640 const NativeWidget* native_widget() const;
641 NativeWidget* native_widget();
643 internal::NativeWidgetPrivate* native_widget_private() {
644 return native_widget_;
646 const internal::NativeWidgetPrivate* native_widget_private() const {
647 return native_widget_;
650 // Sets capture to the specified view. This makes it so that all mouse, touch
651 // and gesture events go to |view|. If |view| is NULL, the widget still
652 // obtains event capture, but the events will go to the view they'd normally
654 void SetCapture(View* view);
657 void ReleaseCapture();
659 // Returns true if the widget has capture.
662 void set_auto_release_capture(bool auto_release_capture) {
663 auto_release_capture_ = auto_release_capture;
666 // Returns the font used for tooltips.
667 TooltipManager* GetTooltipManager();
668 const TooltipManager* GetTooltipManager() const;
670 void set_focus_on_creation(bool focus_on_creation) {
671 focus_on_creation_ = focus_on_creation;
674 // True if the widget is considered top level widget. Top level widget
675 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE,
676 // POPUP or MENU, and has a focus manager and input method object associated
677 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
678 bool is_top_level() const { return is_top_level_; }
680 // True when window movement via mouse interaction with the frame is disabled.
681 bool movement_disabled() const { return movement_disabled_; }
682 void set_movement_disabled(bool disabled) { movement_disabled_ = disabled; }
684 // Returns the work area bounds of the screen the Widget belongs to.
685 gfx::Rect GetWorkAreaBoundsInScreen() const;
687 // Creates and dispatches synthesized mouse move event using the current
688 // mouse location to refresh hovering status in the widget.
689 void SynthesizeMouseMoveEvent();
691 // Called by our RootView after it has performed a Layout. Used to forward
692 // window sizing information to the window server on some platforms.
693 void OnRootViewLayout();
695 // Notification that our owner is closing.
696 // NOTE: this is not invoked for aura as it's currently not needed there.
697 // Under aura menus close by way of activation getting reset when the owner
699 virtual void OnOwnerClosing();
701 // Overridden from NativeWidgetDelegate:
702 virtual bool IsModal() const OVERRIDE;
703 virtual bool IsDialogBox() const OVERRIDE;
704 virtual bool CanActivate() const OVERRIDE;
705 virtual bool IsInactiveRenderingDisabled() const OVERRIDE;
706 virtual void EnableInactiveRendering() OVERRIDE;
707 virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE;
708 virtual void OnNativeFocus(gfx::NativeView old_focused_view) OVERRIDE;
709 virtual void OnNativeBlur(gfx::NativeView new_focused_view) OVERRIDE;
710 virtual void OnNativeWidgetVisibilityChanging(bool visible) OVERRIDE;
711 virtual void OnNativeWidgetVisibilityChanged(bool visible) OVERRIDE;
712 virtual void OnNativeWidgetCreated(bool desktop_widget) OVERRIDE;
713 virtual void OnNativeWidgetDestroying() OVERRIDE;
714 virtual void OnNativeWidgetDestroyed() OVERRIDE;
715 virtual gfx::Size GetMinimumSize() OVERRIDE;
716 virtual gfx::Size GetMaximumSize() OVERRIDE;
717 virtual void OnNativeWidgetMove() OVERRIDE;
718 virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE;
719 virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE;
720 virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE;
721 virtual bool HasFocusManager() const OVERRIDE;
722 virtual bool OnNativeWidgetPaintAccelerated(
723 const gfx::Rect& dirty_region) OVERRIDE;
724 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) OVERRIDE;
725 virtual int GetNonClientComponent(const gfx::Point& point) OVERRIDE;
726 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
727 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
728 virtual void OnMouseCaptureLost() OVERRIDE;
729 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
730 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
731 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
732 virtual bool ExecuteCommand(int command_id) OVERRIDE;
733 virtual InputMethod* GetInputMethodDirect() OVERRIDE;
734 virtual const std::vector<ui::Layer*>& GetRootLayers() OVERRIDE;
735 virtual bool HasHitTestMask() const OVERRIDE;
736 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
737 virtual Widget* AsWidget() OVERRIDE;
738 virtual const Widget* AsWidget() const OVERRIDE;
739 virtual bool SetInitialFocus(ui::WindowShowState show_state) OVERRIDE;
741 // Overridden from FocusTraversable:
742 virtual FocusSearch* GetFocusSearch() OVERRIDE;
743 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE;
744 virtual View* GetFocusTraversableParentView() OVERRIDE;
747 // Creates the RootView to be used within this Widget. Subclasses may override
748 // to create custom RootViews that do specialized event processing.
749 // TODO(beng): Investigate whether or not this is needed.
750 virtual internal::RootView* CreateRootView();
752 // Provided to allow the NativeWidget implementations to destroy the RootView
753 // _before_ the focus manager/tooltip manager.
754 // TODO(beng): remove once we fold those objects onto this one.
755 void DestroyRootView();
758 friend class ComboboxTest;
759 friend class TextfieldTest;
761 // Sets the value of |disable_inactive_rendering_|. If the value changes,
762 // both the NonClientView and WidgetDelegate are notified.
763 void SetInactiveRenderingDisabled(bool value);
765 // Persists the window's restored position and "show" state using the
767 void SaveWindowPlacement();
769 // Sizes and positions the window just after it is created.
770 void SetInitialBounds(const gfx::Rect& bounds);
772 // Sizes and positions the frameless window just after it is created.
773 void SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds);
775 // Returns the bounds and "show" state from the delegate. Returns true if
776 // the delegate wants to use a specified bounds.
777 bool GetSavedWindowPlacement(gfx::Rect* bounds,
778 ui::WindowShowState* show_state);
780 // Creates and initializes a new InputMethod and returns it, otherwise null.
781 scoped_ptr<InputMethod> CreateInputMethod();
783 // Sets a different InputMethod instance to this widget. The instance
784 // must not be initialized, the ownership will be assumed by the widget.
785 // It's only for testing purpose.
786 void ReplaceInputMethod(InputMethod* input_method);
788 internal::NativeWidgetPrivate* native_widget_;
790 ObserverList<WidgetObserver> observers_;
792 // Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
793 // to Init() a default WidgetDelegate is created.
794 WidgetDelegate* widget_delegate_;
796 // The root of the View hierarchy attached to this window.
797 // WARNING: see warning in tooltip_manager_ for ordering dependencies with
798 // this and tooltip_manager_.
799 scoped_ptr<internal::RootView> root_view_;
801 // The View that provides the non-client area of the window (title bar,
802 // window controls, sizing borders etc). To use an implementation other than
803 // the default, this class must be sub-classed and this value set to the
804 // desired implementation before calling |InitWindow()|.
805 NonClientView* non_client_view_;
807 // The focus manager keeping track of focus for this Widget and any of its
808 // children. NULL for non top-level widgets.
809 // WARNING: RootView's destructor calls into the FocusManager. As such, this
810 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView().
811 scoped_ptr<FocusManager> focus_manager_;
813 // A theme provider to use when no other theme provider is specified.
814 scoped_ptr<ui::DefaultThemeProvider> default_theme_provider_;
816 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
820 // See class documentation for Widget above for a note about ownership.
821 InitParams::Ownership ownership_;
823 // See set_is_secondary_widget().
824 bool is_secondary_widget_;
826 // The current frame type in use by this window. Defaults to
827 // FRAME_TYPE_DEFAULT.
828 FrameType frame_type_;
830 // True when the window should be rendered as active, regardless of whether
831 // or not it actually is.
832 bool disable_inactive_rendering_;
834 // Set to true if the widget is in the process of closing.
837 // The saved "show" state for this window. See note in SetInitialBounds
838 // that explains why we save this.
839 ui::WindowShowState saved_show_state_;
841 // The restored bounds used for the initial show. This is only used if
842 // |saved_show_state_| is maximized.
843 gfx::Rect initial_restored_bounds_;
845 // Focus is automatically set to the view provided by the delegate
846 // when the widget is shown. Set this value to false to override
847 // initial focus for the widget.
848 bool focus_on_creation_;
850 mutable scoped_ptr<InputMethod> input_method_;
852 // See |is_top_level()| accessor.
855 // Tracks whether native widget has been initialized.
856 bool native_widget_initialized_;
858 // Whether native widget has been destroyed.
859 bool native_widget_destroyed_;
861 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
862 // If true, the mouse is currently down.
863 bool is_mouse_button_pressed_;
865 // If true, a touch device is currently down.
868 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
869 // The following are used to detect duplicate mouse move events and not
870 // deliver them. Displaying a window may result in the system generating
871 // duplicate move events even though the mouse hasn't moved.
872 bool last_mouse_event_was_move_;
873 gfx::Point last_mouse_event_position_;
875 // True if event capture should be released on a mouse up event. Default is
877 bool auto_release_capture_;
879 // See description in GetRootLayers().
880 std::vector<ui::Layer*> root_layers_;
882 // Is |root_layers_| out of date?
883 bool root_layers_dirty_;
885 // True when window movement via mouse interaction with the frame should be
887 bool movement_disabled_;
889 DISALLOW_COPY_AND_ASSIGN(Widget);
894 #endif // UI_VIEWS_WIDGET_WIDGET_H_