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#include <vector>
10
11#include "ui/base/accessibility/accessibility_types.h"
12#include "ui/base/ui_base_types.h"
13#include "ui/views/view.h"
14
15namespace gfx {
16class ImageSkia;
17class Rect;
18}
19
20namespace views {
21class BubbleDelegateView;
22class ClientView;
23class DialogDelegate;
24class NonClientFrameView;
25class View;
26class Widget;
27
28// Handles events on Widgets in context-specific ways.
29class VIEWS_EXPORT WidgetDelegate {
30 public:
31  WidgetDelegate();
32
33  // Called whenever the widget's position changes.
34  virtual void OnWidgetMove();
35
36  // Called with the display changes (color depth or resolution).
37  virtual void OnDisplayChanged();
38
39  // Called when the work area (the desktop area minus task bars,
40  // menu bars, etc.) changes in size.
41  virtual void OnWorkAreaChanged();
42
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();
46
47  virtual BubbleDelegateView* AsBubbleDelegate();
48  virtual DialogDelegate* AsDialogDelegate();
49
50  // Returns true if the window can ever be resized.
51  virtual bool CanResize() const;
52
53  // Returns true if the window can ever be maximized.
54  virtual bool CanMaximize() const;
55
56  // Returns true if the window can be activated.
57  virtual bool CanActivate() const;
58
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;
62
63  virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const;
64
65  // Returns the title to be read with screen readers.
66  virtual string16 GetAccessibleWindowTitle() const;
67
68  // Returns the text to be displayed in the window title.
69  virtual string16 GetWindowTitle() const;
70
71  // Returns true if the window should show a title in the title bar.
72  virtual bool ShouldShowWindowTitle() const;
73
74  // Returns true if the window should show a close button in the title bar.
75  virtual bool ShouldShowCloseButton() const;
76
77  // Returns true if the window should handle standard system commands, such as
78  // close, minimize, maximize.
79  virtual bool ShouldHandleSystemCommands() const;
80
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();
84
85  // Returns the icon to be displayed in the window.
86  virtual gfx::ImageSkia GetWindowIcon();
87
88  // Returns true if a window icon should be shown.
89  virtual bool ShouldShowWindowIcon() const;
90
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);
94
95  // Returns the window's name identifier. Used to identify this window for
96  // state restoration.
97  virtual std::string GetWindowName() const;
98
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);
104
105  // Retrieves the window's bounds and "show" states.
106  // This behavior can be overridden to provide additional functionality.
107  virtual bool GetSavedWindowPlacement(gfx::Rect* bounds,
108                                       ui::WindowShowState* show_state) const;
109
110  // Returns true if the window's size should be restored. If this is false,
111  // only the window's origin is restored and the window is given its
112  // preferred size.
113  // Default is true.
114  virtual bool ShouldRestoreWindowSize() const;
115
116  // Called when the window closes. The delegate MUST NOT delete itself during
117  // this call, since it can be called afterwards. See DeleteDelegate().
118  virtual void WindowClosing() {}
119
120  // Called when the window is destroyed. No events must be sent or received
121  // after this point. The delegate can use this opportunity to delete itself at
122  // this time if necessary.
123  virtual void DeleteDelegate() {}
124
125  // Called when the user begins/ends to change the bounds of the window.
126  virtual void OnWindowBeginUserBoundsChange() {}
127  virtual void OnWindowEndUserBoundsChange() {}
128
129  // Returns the Widget associated with this delegate.
130  virtual Widget* GetWidget() = 0;
131  virtual const Widget* GetWidget() const = 0;
132
133  // Returns the View that is contained within this Widget.
134  virtual View* GetContentsView();
135
136  // Called by the Widget to create the Client View used to host the contents
137  // of the widget.
138  virtual ClientView* CreateClientView(Widget* widget);
139
140  // Called by the Widget to create the NonClient Frame View for this widget.
141  // Return NULL to use the default one.
142  virtual NonClientFrameView* CreateNonClientFrameView(Widget* widget);
143
144  // Called by the Widget to create the overlay View for this widget. Return
145  // NULL for no overlay. The overlay View will fill the Widget and sit on top
146  // of the ClientView and NonClientFrameView (both visually and wrt click
147  // targeting).
148  virtual View* CreateOverlayView();
149
150  // Returns true if the window can be notified with the work area change.
151  // Otherwise, the work area change for the top window will be processed by
152  // the default window manager. In some cases, like panel, we would like to
153  // manage the positions by ourselves.
154  virtual bool WillProcessWorkAreaChange() const;
155
156  // Returns true if window has a hit-test mask.
157  virtual bool WidgetHasHitTestMask() const;
158
159  // Provides the hit-test mask if HasHitTestMask above returns true.
160  virtual void GetWidgetHitTestMask(gfx::Path* mask) const;
161
162  // Returns true if event handling should descend into |child|.
163  // |location| is in terms of the Window.
164  virtual bool ShouldDescendIntoChildForEventHandling(
165      gfx::NativeView child,
166      const gfx::Point& location);
167
168  // Populates |panes| with accessible panes in this window that can
169  // be cycled through with keyboard focus.
170  virtual void GetAccessiblePanes(std::vector<View*>* panes) {}
171
172 protected:
173  virtual ~WidgetDelegate() {}
174
175 private:
176  View* default_contents_view_;
177
178  DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
179};
180
181// A WidgetDelegate implementation that is-a View. Used to override GetWidget()
182// to call View's GetWidget() for the common case where a WidgetDelegate
183// implementation is-a View. Note that WidgetDelegateView is not owned by
184// view's hierarchy and is expected to be deleted on DeleteDelegate call.
185class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
186 public:
187  WidgetDelegateView();
188  virtual ~WidgetDelegateView();
189
190  // Overridden from WidgetDelegate:
191  virtual void DeleteDelegate() OVERRIDE;
192  virtual Widget* GetWidget() OVERRIDE;
193  virtual const Widget* GetWidget() const OVERRIDE;
194
195 private:
196  DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
197};
198
199}  // namespace views
200
201#endif  // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
202