PageRenderTime 30ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/ui/views/widget/widget_delegate.h

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