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_DELEGATE_H_
6 #define UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
11 #include "ui/accessibility/ax_enums.h"
12 #include "ui/base/ui_base_types.h"
13 #include "ui/views/view.h"
21 class BubbleDelegateView
;
24 class NonClientFrameView
;
28 // Handles events on Widgets in context-specific ways.
29 class VIEWS_EXPORT WidgetDelegate
{
33 // Sets the return value of CanActivate(). Default is true.
34 void set_can_activate(bool can_activate
) {
35 can_activate_
= can_activate
;
38 // Called whenever the widget's position changes.
39 virtual void OnWidgetMove();
41 // Called with the display changes (color depth or resolution).
42 virtual void OnDisplayChanged();
44 // Called when the work area (the desktop area minus task bars,
45 // menu bars, etc.) changes in size.
46 virtual void OnWorkAreaChanged();
48 // Returns the view that should have the focus when the widget is shown. If
49 // NULL no view is focused.
50 virtual View
* GetInitiallyFocusedView();
52 virtual BubbleDelegateView
* AsBubbleDelegate();
53 virtual DialogDelegate
* AsDialogDelegate();
55 // Returns true if the window can ever be resized.
56 virtual bool CanResize() const;
58 // Returns true if the window can ever be maximized.
59 virtual bool CanMaximize() const;
61 // Returns true if the window can be activated.
62 virtual bool CanActivate() const;
64 // Returns the modal type that applies to the widget. Default is
65 // ui::MODAL_TYPE_NONE (not modal).
66 virtual ui::ModalType
GetModalType() const;
68 virtual ui::AXRole
GetAccessibleWindowRole() const;
70 // Returns the title to be read with screen readers.
71 virtual base::string16
GetAccessibleWindowTitle() const;
73 // Returns the text to be displayed in the window title.
74 virtual base::string16
GetWindowTitle() const;
76 // Returns true if the window should show a title in the title bar.
77 virtual bool ShouldShowWindowTitle() const;
79 // Returns true if the window should show a close button in the title bar.
80 virtual bool ShouldShowCloseButton() const;
82 // Returns true if the window should handle standard system commands, such as
83 // close, minimize, maximize.
84 virtual bool ShouldHandleSystemCommands() const;
86 // Returns the app icon for the window. On Windows, this is the ICON_BIG used
87 // in Alt-Tab list and Win7's taskbar.
88 virtual gfx::ImageSkia
GetWindowAppIcon();
90 // Returns the icon to be displayed in the window.
91 virtual gfx::ImageSkia
GetWindowIcon();
93 // Returns true if a window icon should be shown.
94 virtual bool ShouldShowWindowIcon() const;
96 // Execute a command in the window's controller. Returns true if the command
97 // was handled, false if it was not.
98 virtual bool ExecuteWindowsCommand(int command_id
);
100 // Returns the window's name identifier. Used to identify this window for
101 // state restoration.
102 virtual std::string
GetWindowName() const;
104 // Saves the window's bounds and "show" state. By default this uses the
105 // process' local state keyed by window name (See GetWindowName above). This
106 // behavior can be overridden to provide additional functionality.
107 virtual void SaveWindowPlacement(const gfx::Rect
& bounds
,
108 ui::WindowShowState show_state
);
110 // Retrieves the window's bounds and "show" states.
111 // This behavior can be overridden to provide additional functionality.
112 virtual bool GetSavedWindowPlacement(const Widget
* widget
,
114 ui::WindowShowState
* show_state
) const;
116 // Returns true if the window's size should be restored. If this is false,
117 // only the window's origin is restored and the window is given its
120 virtual bool ShouldRestoreWindowSize() const;
122 // Called when the window closes. The delegate MUST NOT delete itself during
123 // this call, since it can be called afterwards. See DeleteDelegate().
124 virtual void WindowClosing() {}
126 // Called when the window is destroyed. No events must be sent or received
127 // after this point. The delegate can use this opportunity to delete itself at
128 // this time if necessary.
129 virtual void DeleteDelegate() {}
131 // Called when the user begins/ends to change the bounds of the window.
132 virtual void OnWindowBeginUserBoundsChange() {}
133 virtual void OnWindowEndUserBoundsChange() {}
135 // Returns the Widget associated with this delegate.
136 virtual Widget
* GetWidget() = 0;
137 virtual const Widget
* GetWidget() const = 0;
139 // Returns the View that is contained within this Widget.
140 virtual View
* GetContentsView();
142 // Called by the Widget to create the Client View used to host the contents
144 virtual ClientView
* CreateClientView(Widget
* widget
);
146 // Called by the Widget to create the NonClient Frame View for this widget.
147 // Return NULL to use the default one.
148 virtual NonClientFrameView
* CreateNonClientFrameView(Widget
* widget
);
150 // Called by the Widget to create the overlay View for this widget. Return
151 // NULL for no overlay. The overlay View will fill the Widget and sit on top
152 // of the ClientView and NonClientFrameView (both visually and wrt click
154 virtual View
* CreateOverlayView();
156 // Returns true if the window can be notified with the work area change.
157 // Otherwise, the work area change for the top window will be processed by
158 // the default window manager. In some cases, like panel, we would like to
159 // manage the positions by ourselves.
160 virtual bool WillProcessWorkAreaChange() const;
162 // Returns true if window has a hit-test mask.
163 virtual bool WidgetHasHitTestMask() const;
165 // Provides the hit-test mask if HasHitTestMask above returns true.
166 virtual void GetWidgetHitTestMask(gfx::Path
* mask
) const;
168 // Returns true if focus should advance to the top level widget when
169 // tab/shift-tab is hit and on the last/first focusable view. Default returns
170 // false, which means tab/shift-tab never advance to the top level Widget.
171 virtual bool ShouldAdvanceFocusToTopLevelWidget() const;
173 // Returns true if event handling should descend into |child|.
174 // |location| is in terms of the Window.
175 virtual bool ShouldDescendIntoChildForEventHandling(
176 gfx::NativeView child
,
177 const gfx::Point
& location
);
179 // Populates |panes| with accessible panes in this window that can
180 // be cycled through with keyboard focus.
181 virtual void GetAccessiblePanes(std::vector
<View
*>* panes
) {}
184 virtual ~WidgetDelegate() {}
187 View
* default_contents_view_
;
191 DISALLOW_COPY_AND_ASSIGN(WidgetDelegate
);
194 // A WidgetDelegate implementation that is-a View. Used to override GetWidget()
195 // to call View's GetWidget() for the common case where a WidgetDelegate
196 // implementation is-a View. Note that WidgetDelegateView is not owned by
197 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
198 class VIEWS_EXPORT WidgetDelegateView
: public WidgetDelegate
, public View
{
200 WidgetDelegateView();
201 virtual ~WidgetDelegateView();
203 // Overridden from WidgetDelegate:
204 virtual void DeleteDelegate() OVERRIDE
;
205 virtual Widget
* GetWidget() OVERRIDE
;
206 virtual const Widget
* GetWidget() const OVERRIDE
;
209 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView
);
214 #endif // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_