• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/accessibility/ax_enums.h"
12 #include "ui/base/ui_base_types.h"
13 #include "ui/views/view.h"
14 
15 namespace gfx {
16 class ImageSkia;
17 class Rect;
18 }
19 
20 namespace views {
21 class BubbleDelegateView;
22 class ClientView;
23 class DialogDelegate;
24 class NonClientFrameView;
25 class View;
26 class Widget;
27 
28 // Handles events on Widgets in context-specific ways.
29 class VIEWS_EXPORT WidgetDelegate {
30  public:
31   WidgetDelegate();
32 
33   // Sets the return value of CanActivate(). Default is true.
set_can_activate(bool can_activate)34   void set_can_activate(bool can_activate) {
35     can_activate_ = can_activate;
36   }
37 
38   // Called whenever the widget's position changes.
39   virtual void OnWidgetMove();
40 
41   // Called with the display changes (color depth or resolution).
42   virtual void OnDisplayChanged();
43 
44   // Called when the work area (the desktop area minus task bars,
45   // menu bars, etc.) changes in size.
46   virtual void OnWorkAreaChanged();
47 
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();
51 
52   virtual BubbleDelegateView* AsBubbleDelegate();
53   virtual DialogDelegate* AsDialogDelegate();
54 
55   // Returns true if the window can be resized.
56   virtual bool CanResize() const;
57 
58   // Returns true if the window can be maximized.
59   virtual bool CanMaximize() const;
60 
61   // Returns true if the window can be minimized.
62   virtual bool CanMinimize() const;
63 
64   // Returns true if the window can be activated.
65   virtual bool CanActivate() const;
66 
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;
70 
71   virtual ui::AXRole GetAccessibleWindowRole() const;
72 
73   // Returns the title to be read with screen readers.
74   virtual base::string16 GetAccessibleWindowTitle() const;
75 
76   // Returns the text to be displayed in the window title.
77   virtual base::string16 GetWindowTitle() const;
78 
79   // Returns true if the window should show a title in the title bar.
80   virtual bool ShouldShowWindowTitle() const;
81 
82   // Returns true if the window should show a close button in the title bar.
83   virtual bool ShouldShowCloseButton() const;
84 
85   // Returns true if the window should handle standard system commands, such as
86   // close, minimize, maximize.
87   virtual bool ShouldHandleSystemCommands() const;
88 
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();
92 
93   // Returns the icon to be displayed in the window.
94   virtual gfx::ImageSkia GetWindowIcon();
95 
96   // Returns true if a window icon should be shown.
97   virtual bool ShouldShowWindowIcon() const;
98 
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);
102 
103   // Returns the window's name identifier. Used to identify this window for
104   // state restoration.
105   virtual std::string GetWindowName() const;
106 
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);
112 
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;
118 
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;
124 
125   // Called when the window closes. The delegate MUST NOT delete itself during
126   // this call, since it can be called afterwards. See DeleteDelegate().
WindowClosing()127   virtual void WindowClosing() {}
128 
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.
DeleteDelegate()132   virtual void DeleteDelegate() {}
133 
134   // Called when the user begins/ends to change the bounds of the window.
OnWindowBeginUserBoundsChange()135   virtual void OnWindowBeginUserBoundsChange() {}
OnWindowEndUserBoundsChange()136   virtual void OnWindowEndUserBoundsChange() {}
137 
138   // Returns the Widget associated with this delegate.
139   virtual Widget* GetWidget() = 0;
140   virtual const Widget* GetWidget() const = 0;
141 
142   // Returns the View that is contained within this Widget.
143   virtual View* GetContentsView();
144 
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);
148 
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);
152 
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();
158 
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;
164 
165   // Returns true if window has a hit-test mask.
166   virtual bool WidgetHasHitTestMask() const;
167 
168   // Provides the hit-test mask if HasHitTestMask above returns true.
169   virtual void GetWidgetHitTestMask(gfx::Path* mask) const;
170 
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;
175 
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);
181 
182   // Populates |panes| with accessible panes in this window that can
183   // be cycled through with keyboard focus.
GetAccessiblePanes(std::vector<View * > * panes)184   virtual void GetAccessiblePanes(std::vector<View*>* panes) {}
185 
186  protected:
~WidgetDelegate()187   virtual ~WidgetDelegate() {}
188 
189  private:
190   View* default_contents_view_;
191 
192   bool can_activate_;
193 
194   DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
195 };
196 
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   WidgetDelegateView();
204   virtual ~WidgetDelegateView();
205 
206   // Overridden from WidgetDelegate:
207   virtual void DeleteDelegate() OVERRIDE;
208   virtual Widget* GetWidget() OVERRIDE;
209   virtual const Widget* GetWidget() const OVERRIDE;
210 
211  private:
212   DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
213 };
214 
215 }  // namespace views
216 
217 #endif  // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
218