widget_delegate.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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.
4
5#ifndef UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
6#define UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
7
8#include <string>
9
10#include "ui/base/accessibility/accessibility_types.h"
11#include "ui/base/ui_base_types.h"
12#include "ui/views/view.h"
13
14namespace gfx {
15class ImageSkia;
16class Rect;
17}
18
19namespace views {
20class BubbleDelegateView;
21class ClientView;
22class DialogDelegate;
23class NonClientFrameView;
24class View;
25class Widget;
26
27// Handles events on Widgets in context-specific ways.
28class VIEWS_EXPORT WidgetDelegate {
29 public:
30  WidgetDelegate();
31
32  // Called whenever the widget's position changes.
33  virtual void OnWidgetMove();
34
35  // Called with the display changes (color depth or resolution).
36  virtual void OnDisplayChanged();
37
38  // Called when the work area (the desktop area minus task bars,
39  // menu bars, etc.) changes in size.
40  virtual void OnWorkAreaChanged();
41
42  // Returns the view that should have the focus when the widget is shown.  If
43  // NULL no view is focused.
44  virtual View* GetInitiallyFocusedView();
45
46  virtual BubbleDelegateView* AsBubbleDelegate();
47  virtual DialogDelegate* AsDialogDelegate();
48
49  // Returns true if the window can ever be resized.
50  virtual bool CanResize() const;
51
52  // Returns true if the window can ever be maximized.
53  virtual bool CanMaximize() const;
54
55  // Returns true if the window can be activated.
56  virtual bool CanActivate() const;
57
58  // Returns the modal type that applies to the widget. Default is
59  // ui::MODAL_TYPE_NONE (not modal).
60  virtual ui::ModalType GetModalType() const;
61
62  virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const;
63
64  virtual ui::AccessibilityTypes::State GetAccessibleWindowState() const;
65
66  // Returns the title to be read with screen readers.
67  virtual string16 GetAccessibleWindowTitle() const;
68
69  // Returns the text to be displayed in the window title.
70  virtual string16 GetWindowTitle() const;
71
72  // Returns true if the window should show a title in the title bar.
73  virtual bool ShouldShowWindowTitle() const;
74
75  // Returns the app icon for the window. On Windows, this is the ICON_BIG used
76  // in Alt-Tab list and Win7's taskbar.
77  virtual gfx::ImageSkia GetWindowAppIcon();
78
79  // Returns the icon to be displayed in the window.
80  virtual gfx::ImageSkia GetWindowIcon();
81
82  // Returns true if a window icon should be shown.
83  virtual bool ShouldShowWindowIcon() const;
84
85  // Execute a command in the window's controller. Returns true if the command
86  // was handled, false if it was not.
87  virtual bool ExecuteWindowsCommand(int command_id);
88
89  // Returns the window's name identifier. Used to identify this window for
90  // state restoration.
91  virtual std::string GetWindowName() const;
92
93  // Saves the window's bounds and "show" state. By default this uses the
94  // process' local state keyed by window name (See GetWindowName above). This
95  // behavior can be overridden to provide additional functionality.
96  virtual void SaveWindowPlacement(const gfx::Rect& bounds,
97                                   ui::WindowShowState show_state);
98
99  // Retrieves the window's bounds and "show" states.
100  // This behavior can be overridden to provide additional functionality.
101  virtual bool GetSavedWindowPlacement(gfx::Rect* bounds,
102                                       ui::WindowShowState* show_state) const;
103
104  // Returns true if the window's size should be restored. If this is false,
105  // only the window's origin is restored and the window is given its
106  // preferred size.
107  // Default is true.
108  virtual bool ShouldRestoreWindowSize() const;
109
110  // Called when the window closes. The delegate MUST NOT delete itself during
111  // this call, since it can be called afterwards. See DeleteDelegate().
112  virtual void WindowClosing() {}
113
114  // Called when the window is destroyed. No events must be sent or received
115  // after this point. The delegate can use this opportunity to delete itself at
116  // this time if necessary.
117  virtual void DeleteDelegate() {}
118
119  // Called when the user begins/ends to change the bounds of the window.
120  virtual void OnWindowBeginUserBoundsChange() {}
121  virtual void OnWindowEndUserBoundsChange() {}
122
123  // Returns the Widget associated with this delegate.
124  virtual Widget* GetWidget() = 0;
125  virtual const Widget* GetWidget() const = 0;
126
127  // Returns the View that is contained within this Widget.
128  virtual View* GetContentsView();
129
130  // Called by the Widget to create the Client View used to host the contents
131  // of the widget.
132  virtual ClientView* CreateClientView(Widget* widget);
133
134  // Called by the Widget to create the NonClient Frame View for this widget.
135  // Return NULL to use the default one.
136  virtual NonClientFrameView* CreateNonClientFrameView(Widget* widget);
137
138  // Returns true if the window can be notified with the work area change.
139  // Otherwise, the work area change for the top window will be processed by
140  // the default window manager. In some cases, like panel, we would like to
141  // manage the positions by ourselves.
142  virtual bool WillProcessWorkAreaChange() const;
143
144  // Returns true if window has a hit-test mask.
145  virtual bool WidgetHasHitTestMask() const;
146
147  // Provides the hit-test mask if HasHitTestMask above returns true.
148  virtual void GetWidgetHitTestMask(gfx::Path* mask) const;
149
150  // Returns true if event handling should descend into |child|.
151  // |location| is in terms of the Window.
152  virtual bool ShouldDescendIntoChildForEventHandling(
153      gfx::NativeView child,
154      const gfx::Point& location);
155
156 protected:
157  virtual ~WidgetDelegate() {}
158
159 private:
160  View* default_contents_view_;
161
162  DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
163};
164
165// A WidgetDelegate implementation that is-a View. Used to override GetWidget()
166// to call View's GetWidget() for the common case where a WidgetDelegate
167// implementation is-a View.
168class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
169 public:
170  WidgetDelegateView();
171  virtual ~WidgetDelegateView();
172
173  // Overridden from WidgetDelegate:
174  virtual Widget* GetWidget() OVERRIDE;
175  virtual const Widget* GetWidget() const OVERRIDE;
176
177 private:
178  DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
179};
180
181}  // namespace views
182
183#endif  // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
184