More class names for views class.
[chromium-blink-merge.git] / ui / views / widget / widget_delegate.h
blob2219699940b0bde6d4f6a71995d16af2fc71d42d
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_
8 #include <string>
9 #include <vector>
11 #include "ui/accessibility/ax_enums.h"
12 #include "ui/base/ui_base_types.h"
13 #include "ui/views/view.h"
15 namespace gfx {
16 class ImageSkia;
17 class Rect;
20 namespace views {
21 class BubbleDelegateView;
22 class ClientView;
23 class DialogDelegate;
24 class NonClientFrameView;
25 class View;
26 class Widget;
28 // Handles events on Widgets in context-specific ways.
29 class VIEWS_EXPORT WidgetDelegate {
30 public:
31 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 be resized.
56 virtual bool CanResize() const;
58 // Returns true if the window can be maximized.
59 virtual bool CanMaximize() const;
61 // Returns true if the window can be minimized.
62 virtual bool CanMinimize() const;
64 // Returns true if the window can be activated.
65 virtual bool CanActivate() const;
67 // Returns the modal type that applies to the widget. Default is
68 // ui::MODAL_TYPE_NONE (not modal).
69 virtual ui::ModalType GetModalType() const;
71 virtual ui::AXRole GetAccessibleWindowRole() const;
73 // Returns the title to be read with screen readers.
74 virtual base::string16 GetAccessibleWindowTitle() const;
76 // Returns the text to be displayed in the window title.
77 virtual base::string16 GetWindowTitle() const;
79 // Returns true if the window should show a title in the title bar.
80 virtual bool ShouldShowWindowTitle() const;
82 // Returns true if the window should show a close button in the title bar.
83 virtual bool ShouldShowCloseButton() const;
85 // Returns true if the window should handle standard system commands, such as
86 // close, minimize, maximize.
87 virtual bool ShouldHandleSystemCommands() const;
89 // Returns the app icon for the window. On Windows, this is the ICON_BIG used
90 // in Alt-Tab list and Win7's taskbar.
91 virtual gfx::ImageSkia GetWindowAppIcon();
93 // Returns the icon to be displayed in the window.
94 virtual gfx::ImageSkia GetWindowIcon();
96 // Returns true if a window icon should be shown.
97 virtual bool ShouldShowWindowIcon() const;
99 // Execute a command in the window's controller. Returns true if the command
100 // was handled, false if it was not.
101 virtual bool ExecuteWindowsCommand(int command_id);
103 // Returns the window's name identifier. Used to identify this window for
104 // state restoration.
105 virtual std::string GetWindowName() const;
107 // Saves the window's bounds and "show" state. By default this uses the
108 // process' local state keyed by window name (See GetWindowName above). This
109 // behavior can be overridden to provide additional functionality.
110 virtual void SaveWindowPlacement(const gfx::Rect& bounds,
111 ui::WindowShowState show_state);
113 // Retrieves the window's bounds and "show" states.
114 // This behavior can be overridden to provide additional functionality.
115 virtual bool GetSavedWindowPlacement(const Widget* widget,
116 gfx::Rect* bounds,
117 ui::WindowShowState* show_state) const;
119 // Returns true if the window's size should be restored. If this is false,
120 // only the window's origin is restored and the window is given its
121 // preferred size.
122 // Default is true.
123 virtual bool ShouldRestoreWindowSize() const;
125 // Called when the window closes. The delegate MUST NOT delete itself during
126 // this call, since it can be called afterwards. See DeleteDelegate().
127 virtual void WindowClosing() {}
129 // Called when the window is destroyed. No events must be sent or received
130 // after this point. The delegate can use this opportunity to delete itself at
131 // this time if necessary.
132 virtual void DeleteDelegate() {}
134 // Called when the user begins/ends to change the bounds of the window.
135 virtual void OnWindowBeginUserBoundsChange() {}
136 virtual void OnWindowEndUserBoundsChange() {}
138 // Returns the Widget associated with this delegate.
139 virtual Widget* GetWidget() = 0;
140 virtual const Widget* GetWidget() const = 0;
142 // Returns the View that is contained within this Widget.
143 virtual View* GetContentsView();
145 // Called by the Widget to create the Client View used to host the contents
146 // of the widget.
147 virtual ClientView* CreateClientView(Widget* widget);
149 // Called by the Widget to create the NonClient Frame View for this widget.
150 // Return NULL to use the default one.
151 virtual NonClientFrameView* CreateNonClientFrameView(Widget* widget);
153 // Called by the Widget to create the overlay View for this widget. Return
154 // NULL for no overlay. The overlay View will fill the Widget and sit on top
155 // of the ClientView and NonClientFrameView (both visually and wrt click
156 // targeting).
157 virtual View* CreateOverlayView();
159 // Returns true if the window can be notified with the work area change.
160 // Otherwise, the work area change for the top window will be processed by
161 // the default window manager. In some cases, like panel, we would like to
162 // manage the positions by ourselves.
163 virtual bool WillProcessWorkAreaChange() const;
165 // Returns true if window has a hit-test mask.
166 virtual bool WidgetHasHitTestMask() const;
168 // Provides the hit-test mask if HasHitTestMask above returns true.
169 virtual void GetWidgetHitTestMask(gfx::Path* mask) const;
171 // Returns true if focus should advance to the top level widget when
172 // tab/shift-tab is hit and on the last/first focusable view. Default returns
173 // false, which means tab/shift-tab never advance to the top level Widget.
174 virtual bool ShouldAdvanceFocusToTopLevelWidget() const;
176 // Returns true if event handling should descend into |child|.
177 // |location| is in terms of the Window.
178 virtual bool ShouldDescendIntoChildForEventHandling(
179 gfx::NativeView child,
180 const gfx::Point& location);
182 // Populates |panes| with accessible panes in this window that can
183 // be cycled through with keyboard focus.
184 virtual void GetAccessiblePanes(std::vector<View*>* panes) {}
186 protected:
187 virtual ~WidgetDelegate() {}
189 private:
190 View* default_contents_view_;
192 bool can_activate_;
194 DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
197 // A WidgetDelegate implementation that is-a View. Used to override GetWidget()
198 // to call View's GetWidget() for the common case where a WidgetDelegate
199 // implementation is-a View. Note that WidgetDelegateView is not owned by
200 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
201 class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
202 public:
203 // Internal class name.
204 static const char kViewClassName[];
206 WidgetDelegateView();
207 ~WidgetDelegateView() override;
209 // WidgetDelegate:
210 void DeleteDelegate() override;
211 Widget* GetWidget() override;
212 const Widget* GetWidget() const override;
214 // View:
215 const char* GetClassName() const override;
217 private:
218 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
221 } // namespace views
223 #endif // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_