Home | History | Annotate | Download | only in widget
      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 
     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   // 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(const Widget* widget,
    108                                        gfx::Rect* bounds,
    109                                        ui::WindowShowState* show_state) const;
    110 
    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
    113   // preferred size.
    114   // Default is true.
    115   virtual bool ShouldRestoreWindowSize() const;
    116 
    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() {}
    120 
    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() {}
    125 
    126   // Called when the user begins/ends to change the bounds of the window.
    127   virtual void OnWindowBeginUserBoundsChange() {}
    128   virtual void OnWindowEndUserBoundsChange() {}
    129 
    130   // Returns the Widget associated with this delegate.
    131   virtual Widget* GetWidget() = 0;
    132   virtual const Widget* GetWidget() const = 0;
    133 
    134   // Returns the View that is contained within this Widget.
    135   virtual View* GetContentsView();
    136 
    137   // Called by the Widget to create the Client View used to host the contents
    138   // of the widget.
    139   virtual ClientView* CreateClientView(Widget* widget);
    140 
    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);
    144 
    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
    148   // targeting).
    149   virtual View* CreateOverlayView();
    150 
    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;
    156 
    157   // Returns true if window has a hit-test mask.
    158   virtual bool WidgetHasHitTestMask() const;
    159 
    160   // Provides the hit-test mask if HasHitTestMask above returns true.
    161   virtual void GetWidgetHitTestMask(gfx::Path* mask) const;
    162 
    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;
    167 
    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);
    173 
    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) {}
    177 
    178  protected:
    179   virtual ~WidgetDelegate() {}
    180 
    181  private:
    182   View* default_contents_view_;
    183 
    184   DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
    185 };
    186 
    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 {
    192  public:
    193   WidgetDelegateView();
    194   virtual ~WidgetDelegateView();
    195 
    196   // Overridden from WidgetDelegate:
    197   virtual void DeleteDelegate() OVERRIDE;
    198   virtual Widget* GetWidget() OVERRIDE;
    199   virtual const Widget* GetWidget() const OVERRIDE;
    200 
    201  private:
    202   DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
    203 };
    204 
    205 }  // namespace views
    206 
    207 #endif  // UI_VIEWS_WIDGET_WIDGET_DELEGATE_H_
    208