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/base/ui_base_types.h"
16 #include "ui/compositor/layer_type.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 DesktopRootWindowHost;
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.
146 // Infer fully opaque or not. For WinAura, top-level windows that are not
147 // of TYPE_WINDOW are translucent so that they can be made to fade in. In
148 // all other cases, windows are fully opaque.
152 // Possibly translucent/transparent.
157 // Default. Creator is not responsible for managing the lifetime of the
158 // Widget, it is destroyed when the corresponding NativeWidget is
160 NATIVE_WIDGET_OWNS_WIDGET,
161 // Used when the Widget is owned by someone other than the NativeWidget,
162 // e.g. a scoped_ptr in tests.
163 WIDGET_OWNS_NATIVE_WIDGET
167 explicit InitParams(Type type);
169 // Will return the first of the following that isn't NULL: the native view,
170 // |parent|, |context|.
171 gfx::NativeView GetContext() const;
174 // If NULL, a default implementation will be constructed.
175 WidgetDelegate* delegate;
177 // If TRANSLUCENT_WINDOW, the widget may be fully or partially transparent.
178 // If OPAQUE_WINDOW, we can perform optimizations based on the widget being
179 // fully opaque. Defaults to TRANSLUCENT_WINDOW if
180 // ViewsDelegate::UseTransparentWindows(). Defaults to OPAQUE_WINDOW for
181 // non-window widgets.
182 WindowOpacity opacity;
187 bool mirror_origin_in_rtl;
189 // Only used by Windows. Specifies that the system default caption and icon
190 // should not be rendered, and that the client area should be equivalent to
192 bool remove_standard_frame;
193 // Only used by ShellWindow on Windows. Specifies that the default icon of
194 // packaged app should be the system default icon.
195 bool use_system_default_icon;
196 // Whether the widget should be maximized or minimized.
197 ui::WindowShowState show_state;
198 // Should the widget be double buffered? Default is false.
200 gfx::NativeView parent;
201 // Specifies the initial bounds of the Widget. Default is empty, which means
202 // the NativeWidget may specify a default size. If the parent is specified,
203 // |bounds| is in the parent's coordinate system. If the parent is not
204 // specified, it's in screen's global coordinate system.
206 // When set, this value is used as the Widget's NativeWidget implementation.
207 // The Widget will not construct a default one. Default is NULL.
208 NativeWidget* native_widget;
209 // Aura-only. Provides a DesktopRootWindowHost implementation to use instead
210 // of the default one.
211 // TODO(beng): Figure out if there's a better way to expose this, e.g. get
212 // rid of NW subclasses and do this all via message handling.
213 DesktopRootWindowHost* desktop_root_window_host;
214 // Whether this window is intended to be a toplevel window with no
215 // attachment to any other window. (This may be a transient window if
218 // Only used by NativeWidgetAura. Specifies the type of layer for the
219 // aura::Window. Default is LAYER_TEXTURED.
220 ui::LayerType layer_type;
221 // Only used by Aura. Provides a context window whose RootWindow is
222 // consulted during widget creation to determine where in the Window
223 // hierarchy this widget should be placed. (This is separate from |parent|;
224 // if you pass a RootWindow to |parent|, your window will be parented to
225 // |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
226 // where it wants your window placed.) NULL is not allowed if you are using
228 gfx::NativeView context;
229 // Only used by X11, for root level windows. Specifies the res_name and
230 // res_class fields, respectively, of the WM_CLASS window property. Controls
231 // window grouping and desktop file matching in Linux window managers.
232 std::string wm_class_name;
233 std::string wm_class_class;
234 // Only used by X11, for root level windows. Specifies the PID set in
235 // _NET_WM_PID window property.
242 // Creates a toplevel window with no context. These methods should only be
243 // used in cases where there is no contextual information because we're
244 // creating a toplevel window connected to no other event.
246 // If you have any parenting or context information, or can pass that
247 // information, prefer the WithParent or WithContext versions of these
249 static Widget* CreateWindow(WidgetDelegate* delegate);
250 static Widget* CreateWindowWithBounds(WidgetDelegate* delegate,
251 const gfx::Rect& bounds);
253 // Creates a decorated window Widget with the specified properties.
254 static Widget* CreateWindowWithParent(WidgetDelegate* delegate,
255 gfx::NativeWindow parent);
256 static Widget* CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
257 gfx::NativeWindow parent,
258 const gfx::Rect& bounds);
260 // Creates a decorated window Widget in the same desktop context as
262 static Widget* CreateWindowWithContext(WidgetDelegate* delegate,
263 gfx::NativeView context);
264 static Widget* CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
265 gfx::NativeView context,
266 const gfx::Rect& bounds);
268 // Creates an undecorated child window Widget. |new_style_parent| is the
269 // parent to use for new style dialogs, |parent| for currently-styled dialogs.
271 // TODO(wittman): use a single parent parameter once we move fully to
272 // new-style dialogs.
273 static Widget* CreateWindowAsFramelessChild(WidgetDelegate* widget_delegate,
274 gfx::NativeView parent,
275 gfx::NativeView new_style_parent);
277 // Enumerates all windows pertaining to us and notifies their
278 // view hierarchies that the locale has changed.
279 // TODO(beng): remove post-Aurafication of ChromeOS.
280 static void NotifyLocaleChanged();
282 // Closes all Widgets that aren't identified as "secondary widgets". Called
283 // during application shutdown when the last non-secondary widget is closed.
284 static void CloseAllSecondaryWidgets();
286 // Converts a rectangle from one Widget's coordinate system to another's.
287 // Returns false if the conversion couldn't be made, because either these two
288 // Widgets do not have a common ancestor or they are not on the screen yet.
289 // The value of |*rect| won't be changed when false is returned.
290 static bool ConvertRect(const Widget* source,
291 const Widget* target,
294 // Retrieves the Widget implementation associated with the given
295 // NativeView or Window, or NULL if the supplied handle has no associated
297 static Widget* GetWidgetForNativeView(gfx::NativeView native_view);
298 static Widget* GetWidgetForNativeWindow(gfx::NativeWindow native_window);
300 // Retrieves the top level widget in a native view hierarchy
301 // starting at |native_view|. Top level widget is a widget with TYPE_WINDOW,
302 // TYPE_PANEL, TYPE_WINDOW_FRAMELESS, POPUP or MENU and has its own
303 // focus manager. This may be itself if the |native_view| is top level,
304 // or NULL if there is no toplevel in a native view hierarchy.
305 static Widget* GetTopLevelWidgetForNativeView(gfx::NativeView native_view);
307 // Returns all Widgets in |native_view|'s hierarchy, including itself if
309 static void GetAllChildWidgets(gfx::NativeView native_view,
312 // Returns all non-child Widgets owned by |native_view|.
313 static void GetAllOwnedWidgets(gfx::NativeView native_view,
316 // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
318 static void ReparentNativeView(gfx::NativeView native_view,
319 gfx::NativeView new_parent);
321 // Returns the preferred size of the contents view of this window based on
322 // its localized size data. The width in cols is held in a localized string
323 // resource identified by |col_resource_id|, the height in the same fashion.
324 // TODO(beng): This should eventually live somewhere else, probably closer to
326 static int GetLocalizedContentsWidth(int col_resource_id);
327 static int GetLocalizedContentsHeight(int row_resource_id);
328 static gfx::Size GetLocalizedContentsSize(int col_resource_id,
329 int row_resource_id);
331 // Returns true if the specified type requires a NonClientView.
332 static bool RequiresNonClientView(InitParams::Type type);
334 void Init(const InitParams& params);
336 // Returns the gfx::NativeView associated with this Widget.
337 gfx::NativeView GetNativeView() const;
339 // Returns the gfx::NativeWindow associated with this Widget. This may return
340 // NULL on some platforms if the widget was created with a type other than
341 // TYPE_WINDOW or TYPE_PANEL.
342 gfx::NativeWindow GetNativeWindow() const;
344 // Add/remove observer.
345 void AddObserver(WidgetObserver* observer);
346 void RemoveObserver(WidgetObserver* observer);
347 bool HasObserver(WidgetObserver* observer);
349 // Returns the accelerator given a command id. Returns false if there is
350 // no accelerator associated with a given id, which is a common condition.
351 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
353 // Forwarded from the RootView so that the widget can do any cleanup.
354 void ViewHierarchyChanged(const View::ViewHierarchyChangedDetails& details);
356 // Called right before changing the widget's parent NativeView to do any
358 void NotifyNativeViewHierarchyWillChange();
360 // Called after changing the widget's parent NativeView. Notifies the RootView
362 void NotifyNativeViewHierarchyChanged();
364 // Returns the top level widget in a hierarchy (see is_top_level() for
365 // the definition of top level widget.) Will return NULL if called
366 // before the widget is attached to the top level widget's hierarchy.
367 Widget* GetTopLevelWidget();
368 const Widget* GetTopLevelWidget() const;
370 // Gets/Sets the WidgetDelegate.
371 WidgetDelegate* widget_delegate() const { return widget_delegate_; }
373 // Sets the specified view as the contents of this Widget. There can only
374 // be one contents view child of this Widget's RootView. This view is sized to
375 // fit the entire size of the RootView. The RootView takes ownership of this
376 // View, unless it is set as not being parent-owned.
377 void SetContentsView(View* view);
378 View* GetContentsView();
380 // Returns the bounds of the Widget in screen coordinates.
381 gfx::Rect GetWindowBoundsInScreen() const;
383 // Returns the bounds of the Widget's client area in screen coordinates.
384 gfx::Rect GetClientAreaBoundsInScreen() const;
386 // Retrieves the restored bounds for the window.
387 gfx::Rect GetRestoredBounds() const;
389 // Sizes and/or places the widget to the specified bounds, size or position.
390 void SetBounds(const gfx::Rect& bounds);
391 void SetSize(const gfx::Size& size);
393 // Sizes the window to the specified size and centerizes it.
394 void CenterWindow(const gfx::Size& size);
396 // Like SetBounds(), but ensures the Widget is fully visible on screen,
397 // resizing and/or repositioning as necessary. This is only useful for
398 // non-child widgets.
399 void SetBoundsConstrained(const gfx::Rect& bounds);
401 // Sets whether animations that occur when visibility is changed are enabled.
403 void SetVisibilityChangedAnimationsEnabled(bool value);
405 // Starts a nested message loop that moves the window. This can be used to
406 // start a window move operation from a mouse or touch event. This returns
407 // when the move completes. |drag_offset| is the offset from the top left
408 // corner of the window to the point where the cursor is dragging, and is used
409 // to offset the bounds of the window from the cursor.
410 MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset,
411 MoveLoopSource source,
412 MoveLoopEscapeBehavior escape_behavior);
414 // Stops a previously started move loop. This is not immediate.
417 // Places the widget in front of the specified widget in z-order.
418 void StackAboveWidget(Widget* widget);
419 void StackAbove(gfx::NativeView native_view);
422 // Places the widget below the specified NativeView.
423 void StackBelow(gfx::NativeView native_view);
425 // Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
426 // be rectangular. Takes ownership of |shape|.
427 void SetShape(gfx::NativeRegion shape);
429 // Hides the widget then closes it after a return to the message loop.
430 virtual void Close();
432 // TODO(beng): Move off public API.
433 // Closes the widget immediately. Compare to |Close|. This will destroy the
434 // window handle associated with this Widget, so should not be called from
435 // any code that expects it to be valid beyond this call.
438 // Whether the widget has been asked to close itself. In particular this is
439 // set to true after Close() has been invoked on the NativeWidget.
440 bool IsClosed() const;
442 // Shows or hides the widget, without changing activation state.
446 // Like Show(), but does not activate the window.
449 // Activates the widget, assuming it already exists and is visible.
452 // Deactivates the widget, making the next window in the Z order the active
456 // Returns whether the Widget is the currently active window.
457 virtual bool IsActive() const;
459 // Prevents the window from being rendered as deactivated. This state is
460 // reset automatically as soon as the window becomes activated again. There is
461 // no ability to control the state through this API as this leads to sync
463 void DisableInactiveRendering();
465 // Sets the widget to be on top of all other widgets in the windowing system.
466 void SetAlwaysOnTop(bool on_top);
468 // Returns whether the widget has been set to be on top of most other widgets
469 // in the windowing system.
470 bool IsAlwaysOnTop() const;
472 // Maximizes/minimizes/restores the window.
477 // Whether or not the window is maximized or minimized.
478 virtual bool IsMaximized() const;
479 bool IsMinimized() const;
481 // Accessors for fullscreen state.
482 void SetFullscreen(bool fullscreen);
483 bool IsFullscreen() const;
485 // Sets the opacity of the widget. This may allow widgets behind the widget
486 // in the Z-order to become visible, depending on the capabilities of the
487 // underlying windowing system.
488 void SetOpacity(unsigned char opacity);
490 // Sets whether or not the window should show its frame as a "transient drag
491 // frame" - slightly transparent and without the standard window controls.
492 void SetUseDragFrame(bool use_drag_frame);
494 // Flashes the frame of the window to draw attention to it. Currently only
495 // implemented on Windows for non-Aura.
496 void FlashFrame(bool flash);
498 // Returns the View at the root of the View hierarchy contained by this
501 const View* GetRootView() const;
503 // A secondary widget is one that is automatically closed (via Close()) when
504 // all non-secondary widgets are closed.
506 // TODO(beng): This is an ugly API, should be handled implicitly via
508 void set_is_secondary_widget(bool is_secondary_widget) {
509 is_secondary_widget_ = is_secondary_widget;
511 bool is_secondary_widget() const { return is_secondary_widget_; }
513 // Returns whether the Widget is visible to the user.
514 virtual bool IsVisible() const;
516 // Returns the ThemeProvider that provides theme resources for this Widget.
517 virtual ui::ThemeProvider* GetThemeProvider() const;
519 ui::NativeTheme* GetNativeTheme() {
520 return const_cast<ui::NativeTheme*>(
521 const_cast<const Widget*>(this)->GetNativeTheme());
523 const ui::NativeTheme* GetNativeTheme() const;
525 // Returns the FocusManager for this widget.
526 // Note that all widgets in a widget hierarchy share the same focus manager.
527 FocusManager* GetFocusManager();
528 const FocusManager* GetFocusManager() const;
530 // Returns the InputMethod for this widget.
531 // Note that all widgets in a widget hierarchy share the same input method.
532 InputMethod* GetInputMethod();
533 const InputMethod* GetInputMethod() const;
535 // Starts a drag operation for the specified view. This blocks until the drag
536 // operation completes. |view| can be NULL.
537 // If the view is non-NULL it can be accessed during the drag by calling
538 // dragged_view(). If the view has not been deleted during the drag,
539 // OnDragDone() is called on it. |location| is in the widget's coordinate
541 void RunShellDrag(View* view,
542 const ui::OSExchangeData& data,
543 const gfx::Point& location,
545 ui::DragDropTypes::DragEventSource source);
547 // Returns the view that requested the current drag operation via
548 // RunShellDrag(), or NULL if there is no such view or drag operation.
549 View* dragged_view() { return dragged_view_; }
551 // Adds the specified |rect| in client area coordinates to the rectangle to be
553 virtual void SchedulePaintInRect(const gfx::Rect& rect);
555 // Sets the currently visible cursor. If |cursor| is NULL, the cursor used
556 // before the current is restored.
557 void SetCursor(gfx::NativeCursor cursor);
559 // Returns true if and only if mouse events are enabled.
560 bool IsMouseEventsEnabled() const;
562 // Sets/Gets a native window property on the underlying native window object.
563 // Returns NULL if the property does not exist. Setting the property value to
564 // NULL removes the property.
565 void SetNativeWindowProperty(const char* name, void* value);
566 void* GetNativeWindowProperty(const char* name) const;
568 // Tell the window to update its title from the delegate.
569 void UpdateWindowTitle();
571 // Tell the window to update its icon from the delegate.
572 void UpdateWindowIcon();
574 // Retrieves the focus traversable for this widget.
575 FocusTraversable* GetFocusTraversable();
577 // Notifies the view hierarchy contained in this widget that theme resources
581 // Notifies the view hierarchy contained in this widget that locale resources
583 void LocaleChanged();
585 void SetFocusTraversableParent(FocusTraversable* parent);
586 void SetFocusTraversableParentView(View* parent_view);
588 // Clear native focus set to the Widget's NativeWidget.
589 void ClearNativeFocus();
591 void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; }
592 FrameType frame_type() const { return frame_type_; }
594 // Creates an appropriate NonClientFrameView for this widget. The
595 // WidgetDelegate is given the first opportunity to create one, followed by
596 // the NativeWidget implementation. If both return NULL, a default one is
598 virtual NonClientFrameView* CreateNonClientFrameView();
600 // Whether we should be using a native frame.
601 bool ShouldUseNativeFrame() const;
603 // Forces the frame into the alternate frame type (custom or native) depending
604 // on its current state.
605 void DebugToggleFrameType();
607 // Tell the window that something caused the frame type to change.
608 void FrameTypeChanged();
610 NonClientView* non_client_view() {
611 return const_cast<NonClientView*>(
612 const_cast<const Widget*>(this)->non_client_view());
614 const NonClientView* non_client_view() const {
615 return non_client_view_;
618 ClientView* client_view() {
619 return const_cast<ClientView*>(
620 const_cast<const Widget*>(this)->client_view());
622 const ClientView* client_view() const {
623 // non_client_view_ may be NULL, especially during creation.
624 return non_client_view_ ? non_client_view_->client_view() : NULL;
627 const ui::Compositor* GetCompositor() const;
628 ui::Compositor* GetCompositor();
630 // Returns the widget's layer, if any.
631 ui::Layer* GetLayer();
633 // Reorders the widget's child NativeViews which are associated to the view
634 // tree (eg via a NativeViewHost) to match the z-order of the views in the
635 // view tree. The z-order of views with layers relative to views with
636 // associated NativeViews is used to reorder the NativeView layers. This
637 // method assumes that the widget's child layers which are owned by a view are
638 // already in the correct z-order relative to each other and does no
639 // reordering if there are no views with an associated NativeView.
640 void ReorderNativeViews();
642 // Schedules an update to the root layers. The actual processing occurs when
643 // GetRootLayers() is invoked.
644 void UpdateRootLayers();
646 const NativeWidget* native_widget() const;
647 NativeWidget* native_widget();
649 internal::NativeWidgetPrivate* native_widget_private() {
650 return native_widget_;
652 const internal::NativeWidgetPrivate* native_widget_private() const {
653 return native_widget_;
656 // Sets capture to the specified view. This makes it so that all mouse, touch
657 // and gesture events go to |view|. If |view| is NULL, the widget still
658 // obtains event capture, but the events will go to the view they'd normally
660 void SetCapture(View* view);
663 void ReleaseCapture();
665 // Returns true if the widget has capture.
668 void set_auto_release_capture(bool auto_release_capture) {
669 auto_release_capture_ = auto_release_capture;
672 // Returns the font used for tooltips.
673 TooltipManager* GetTooltipManager();
674 const TooltipManager* GetTooltipManager() const;
676 // Sets-up the focus manager with the view that should have focus when the
677 // window is shown the first time. Returns true if the initial focus has been
678 // set or the widget should not set the initial focus, or false if the caller
679 // should set the initial focus (if any).
680 bool SetInitialFocus();
682 void set_focus_on_creation(bool focus_on_creation) {
683 focus_on_creation_ = focus_on_creation;
686 // True if the widget is considered top level widget. Top level widget
687 // is a widget of TYPE_WINDOW, TYPE_PANEL, TYPE_WINDOW_FRAMELESS, BUBBLE,
688 // POPUP or MENU, and has a focus manager and input method object associated
689 // with it. TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
690 bool is_top_level() const { return is_top_level_; }
692 // True when window movement via mouse interaction with the frame is disabled.
693 bool movement_disabled() const { return movement_disabled_; }
694 void set_movement_disabled(bool disabled) { movement_disabled_ = disabled; }
696 // Returns the work area bounds of the screen the Widget belongs to.
697 gfx::Rect GetWorkAreaBoundsInScreen() const;
699 // Creates and dispatches synthesized mouse move event using the current
700 // mouse location to refresh hovering status in the widget.
701 void SynthesizeMouseMoveEvent();
703 // Called by our RootView after it has performed a Layout. Used to forward
704 // window sizing information to the window server on some platforms.
705 void OnRootViewLayout();
707 // Notification that our owner is closing.
708 // NOTE: this is not invoked for aura as it's currently not needed there.
709 // Under aura menus close by way of activation getting reset when the owner
711 virtual void OnOwnerClosing();
713 // Overridden from NativeWidgetDelegate:
714 virtual bool IsModal() const OVERRIDE;
715 virtual bool IsDialogBox() const OVERRIDE;
716 virtual bool CanActivate() const OVERRIDE;
717 virtual bool IsInactiveRenderingDisabled() const OVERRIDE;
718 virtual void EnableInactiveRendering() OVERRIDE;
719 virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE;
720 virtual void OnNativeFocus(gfx::NativeView old_focused_view) OVERRIDE;
721 virtual void OnNativeBlur(gfx::NativeView new_focused_view) OVERRIDE;
722 virtual void OnNativeWidgetVisibilityChanging(bool visible) OVERRIDE;
723 virtual void OnNativeWidgetVisibilityChanged(bool visible) OVERRIDE;
724 virtual void OnNativeWidgetCreated(bool desktop_widget) OVERRIDE;
725 virtual void OnNativeWidgetDestroying() OVERRIDE;
726 virtual void OnNativeWidgetDestroyed() OVERRIDE;
727 virtual gfx::Size GetMinimumSize() OVERRIDE;
728 virtual gfx::Size GetMaximumSize() OVERRIDE;
729 virtual void OnNativeWidgetMove() OVERRIDE;
730 virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE;
731 virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE;
732 virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE;
733 virtual bool HasFocusManager() const OVERRIDE;
734 virtual bool OnNativeWidgetPaintAccelerated(
735 const gfx::Rect& dirty_region) OVERRIDE;
736 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) OVERRIDE;
737 virtual int GetNonClientComponent(const gfx::Point& point) OVERRIDE;
738 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
739 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
740 virtual void OnMouseCaptureLost() OVERRIDE;
741 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
742 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
743 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
744 virtual bool ExecuteCommand(int command_id) OVERRIDE;
745 virtual InputMethod* GetInputMethodDirect() OVERRIDE;
746 virtual const std::vector<ui::Layer*>& GetRootLayers() OVERRIDE;
747 virtual bool HasHitTestMask() const OVERRIDE;
748 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
749 virtual Widget* AsWidget() OVERRIDE;
750 virtual const Widget* AsWidget() const OVERRIDE;
752 // Overridden from FocusTraversable:
753 virtual FocusSearch* GetFocusSearch() OVERRIDE;
754 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE;
755 virtual View* GetFocusTraversableParentView() OVERRIDE;
758 // Creates the RootView to be used within this Widget. Subclasses may override
759 // to create custom RootViews that do specialized event processing.
760 // TODO(beng): Investigate whether or not this is needed.
761 virtual internal::RootView* CreateRootView();
763 // Provided to allow the NativeWidget implementations to destroy the RootView
764 // _before_ the focus manager/tooltip manager.
765 // TODO(beng): remove once we fold those objects onto this one.
766 void DestroyRootView();
769 friend class ComboboxTest;
770 friend class NativeTextfieldViewsTest;
772 // Sets the value of |disable_inactive_rendering_|. If the value changes,
773 // both the NonClientView and WidgetDelegate are notified.
774 void SetInactiveRenderingDisabled(bool value);
776 // Persists the window's restored position and "show" state using the
778 void SaveWindowPlacement();
780 // Sizes and positions the window just after it is created.
781 void SetInitialBounds(const gfx::Rect& bounds);
783 // Sizes and positions the frameless window just after it is created.
784 void SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds);
786 // Returns the bounds and "show" state from the delegate. Returns true if
787 // the delegate wants to use a specified bounds.
788 bool GetSavedWindowPlacement(gfx::Rect* bounds,
789 ui::WindowShowState* show_state);
791 // Creates and initializes a new InputMethod and returns it, otherwise null.
792 scoped_ptr<InputMethod> CreateInputMethod();
794 // Sets a different InputMethod instance to this widget. The instance
795 // must not be initialized, the ownership will be assumed by the widget.
796 // It's only for testing purpose.
797 void ReplaceInputMethod(InputMethod* input_method);
799 internal::NativeWidgetPrivate* native_widget_;
801 ObserverList<WidgetObserver> observers_;
803 // Non-owned pointer to the Widget's delegate. If a NULL delegate is supplied
804 // to Init() a default WidgetDelegate is created.
805 WidgetDelegate* widget_delegate_;
807 // The root of the View hierarchy attached to this window.
808 // WARNING: see warning in tooltip_manager_ for ordering dependencies with
809 // this and tooltip_manager_.
810 scoped_ptr<internal::RootView> root_view_;
812 // The View that provides the non-client area of the window (title bar,
813 // window controls, sizing borders etc). To use an implementation other than
814 // the default, this class must be sub-classed and this value set to the
815 // desired implementation before calling |InitWindow()|.
816 NonClientView* non_client_view_;
818 // The focus manager keeping track of focus for this Widget and any of its
819 // children. NULL for non top-level widgets.
820 // WARNING: RootView's destructor calls into the FocusManager. As such, this
821 // must be destroyed AFTER root_view_. This is enforced in DestroyRootView().
822 scoped_ptr<FocusManager> focus_manager_;
824 // A theme provider to use when no other theme provider is specified.
825 scoped_ptr<ui::DefaultThemeProvider> default_theme_provider_;
827 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
831 // See class documentation for Widget above for a note about ownership.
832 InitParams::Ownership ownership_;
834 // See set_is_secondary_widget().
835 bool is_secondary_widget_;
837 // The current frame type in use by this window. Defaults to
838 // FRAME_TYPE_DEFAULT.
839 FrameType frame_type_;
841 // True when the window should be rendered as active, regardless of whether
842 // or not it actually is.
843 bool disable_inactive_rendering_;
845 // Set to true if the widget is in the process of closing.
848 // The saved "show" state for this window. See note in SetInitialBounds
849 // that explains why we save this.
850 ui::WindowShowState saved_show_state_;
852 // The restored bounds used for the initial show. This is only used if
853 // |saved_show_state_| is maximized.
854 gfx::Rect initial_restored_bounds_;
856 // Focus is automatically set to the view provided by the delegate
857 // when the widget is shown. Set this value to false to override
858 // initial focus for the widget.
859 bool focus_on_creation_;
861 mutable scoped_ptr<InputMethod> input_method_;
863 // See |is_top_level()| accessor.
866 // Tracks whether native widget has been initialized.
867 bool native_widget_initialized_;
869 // Whether native widget has been destroyed.
870 bool native_widget_destroyed_;
872 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
873 // If true, the mouse is currently down.
874 bool is_mouse_button_pressed_;
876 // If true, a touch device is currently down.
879 // TODO(beng): Remove NativeWidgetGtk's dependence on these:
880 // The following are used to detect duplicate mouse move events and not
881 // deliver them. Displaying a window may result in the system generating
882 // duplicate move events even though the mouse hasn't moved.
883 bool last_mouse_event_was_move_;
884 gfx::Point last_mouse_event_position_;
886 // True if event capture should be released on a mouse up event. Default is
888 bool auto_release_capture_;
890 // See description in GetRootLayers().
891 std::vector<ui::Layer*> root_layers_;
893 // Is |root_layers_| out of date?
894 bool root_layers_dirty_;
896 // True when window movement via mouse interaction with the frame should be
898 bool movement_disabled_;
900 DISALLOW_COPY_AND_ASSIGN(Widget);
905 #endif // UI_VIEWS_WIDGET_WIDGET_H_