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/base/accessibility/accessibility_types.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 // Called whenever the widget's position changes.
34 virtual void OnWidgetMove();
36 // Called with the display changes (color depth or resolution).
37 virtual void OnDisplayChanged();
39 // Called when the work area (the desktop area minus task bars,
40 // menu bars, etc.) changes in size.
41 virtual void OnWorkAreaChanged();
43 // Returns the view that should have the focus when the widget is shown. If
44 // NULL no view is focused.
45 virtual View* GetInitiallyFocusedView();
47 virtual BubbleDelegateView* AsBubbleDelegate();
48 virtual DialogDelegate* AsDialogDelegate();
50 // Returns true if the window can ever be resized.
51 virtual bool CanResize() const;
53 // Returns true if the window can ever be maximized.
54 virtual bool CanMaximize() const;
56 // Returns true if the window can be activated.
57 virtual bool CanActivate() const;
59 // Returns the modal type that applies to the widget. Default is
60 // ui::MODAL_TYPE_NONE (not modal).
61 virtual ui::ModalType GetModalType() const;
63 virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const;
65 // Returns the title to be read with screen readers.
66 virtual string16 GetAccessibleWindowTitle() const;
68 // Returns the text to be displayed in the window title.
69 virtual string16 GetWindowTitle() const;
71 // Returns true if the window should show a title in the title bar.
72 virtual bool ShouldShowWindowTitle() const;
74 // Returns true if the window should show a close button in the title bar.
75 virtual bool ShouldShowCloseButton() const;
77 // Returns true if the window should handle standard system commands, such as
78 // close, minimize, maximize.
79 virtual bool ShouldHandleSystemCommands() const;
81 // Returns the app icon for the window. On Windows, this is the ICON_BIG used
82 // in Alt-Tab list and Win7's taskbar.
83 virtual gfx::ImageSkia GetWindowAppIcon();
85 // Returns the icon to be displayed in the window.
86 virtual gfx::ImageSkia GetWindowIcon();
88 // Returns true if a window icon should be shown.
89 virtual bool ShouldShowWindowIcon() const;
91 // Execute a command in the window's controller. Returns true if the command
92 // was handled, false if it was not.
93 virtual bool ExecuteWindowsCommand(int command_id);
95 // Returns the window's name identifier. Used to identify this window for
97 virtual std::string GetWindowName() const;
99 // Saves the window's bounds and "show" state. By default this uses the
100 // process' local state keyed by window name (See GetWindowName above). This
101 // behavior can be overridden to provide additional functionality.
102 virtual void SaveWindowPlacement(const gfx::Rect& bounds,
103 ui::WindowShowState show_state);
105 // Retrieves the window's bounds and "show" states.
106 // This behavior can be overridden to provide additional functionality.
107 virtual bool GetSavedWindowPlacement(const Widget* widget,
109 ui::WindowShowState* show_state) const;
111 // Returns true if the window's size should be restored. If this is false,
112 // only the window's origin is restored and the window is given its
115 virtual bool ShouldRestoreWindowSize() const;
117 // Called when the window closes. The delegate MUST NOT delete itself during
118 // this call, since it can be called afterwards. See DeleteDelegate().
119 virtual void WindowClosing() {}
121 // Called when the window is destroyed. No events must be sent or received
122 // after this point. The delegate can use this opportunity to delete itself at
123 // this time if necessary.
124 virtual void DeleteDelegate() {}
126 // Called when the user begins/ends to change the bounds of the window.
127 virtual void OnWindowBeginUserBoundsChange() {}
128 virtual void OnWindowEndUserBoundsChange() {}
130 // Returns the Widget associated with this delegate.
131 virtual Widget* GetWidget() = 0;
132 virtual const Widget* GetWidget() const = 0;
134 // Returns the View that is contained within this Widget.
135 virtual View* GetContentsView();
137 // Called by the Widget to create the Client View used to host the contents
139 virtual ClientView* CreateClientView(Widget* widget);
141 // Called by the Widget to create the NonClient Frame View for this widget.
142 // Return NULL to use the default one.
143 virtual NonClientFrameView* CreateNonClientFrameView(Widget* widget);
145 // Called by the Widget to create the overlay View for this widget. Return
146 // NULL for no overlay. The overlay View will fill the Widget and sit on top
147 // of the ClientView and NonClientFrameView (both visually and wrt click
149 virtual View* CreateOverlayView();
151 // Returns true if the window can be notified with the work area change.
152 // Otherwise, the work area change for the top window will be processed by
153 // the default window manager. In some cases, like panel, we would like to
154 // manage the positions by ourselves.
155 virtual bool WillProcessWorkAreaChange() const;
157 // Returns true if window has a hit-test mask.
158 virtual bool WidgetHasHitTestMask() const;
160 // Provides the hit-test mask if HasHitTestMask above returns true.
161 virtual void GetWidgetHitTestMask(gfx::Path* mask) const;
163 // Returns true if focus should advance to the top level widget when
164 // tab/shift-tab is hit and on the last/first focusable view. Default returns
165 // false, which means tab/shift-tab never advance to the top level Widget.
166 virtual bool ShouldAdvanceFocusToTopLevelWidget() const;
168 // Returns true if event handling should descend into |child|.
169 // |location| is in terms of the Window.
170 virtual bool ShouldDescendIntoChildForEventHandling(
171 gfx::NativeView child,
172 const gfx::Point& location);
174 // Populates |panes| with accessible panes in this window that can
175 // be cycled through with keyboard focus.
176 virtual void GetAccessiblePanes(std::vector<View*>* panes) {}
179 virtual ~WidgetDelegate() {}
182 View* default_contents_view_;
184 DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
187 // A WidgetDelegate implementation that is-a View. Used to override GetWidget()
188 // to call View's GetWidget() for the common case where a WidgetDelegate
189 // implementation is-a View. Note that WidgetDelegateView is not owned by
190 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
191 class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
193 WidgetDelegateView();
194 virtual ~WidgetDelegateView();
196 // Overridden from WidgetDelegate:
197 virtual void DeleteDelegate() OVERRIDE;
198 virtual Widget* GetWidget() OVERRIDE;
199 virtual const Widget* GetWidget() const OVERRIDE;
202 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
207 #endif // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_