/source/third_party/chromium/views/widget/widget_delegate.h

https://github.com/snowlesswinter/framework · C Header · 181 lines · 75 code · 47 blank · 59 comment · 0 complexity · 7bf524640cdf27e535a64e4d9eb32f0d MD5 · raw file

  1. // Copyright (c) 2011 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 VIEWS_WIDGET_WIDGET_DELEGATE_H_
  5. #define VIEWS_WIDGET_WIDGET_DELEGATE_H_
  6. #pragma once
  7. #include <string>
  8. #include "base/memory/scoped_ptr.h"
  9. #include "ui/base/accessibility/accessibility_types.h"
  10. #include "ui/base/ui_base_types.h"
  11. #include "views/view.h"
  12. class SkBitmap;
  13. namespace gfx {
  14. class Rect;
  15. }
  16. namespace views {
  17. class BubbleDelegate;
  18. class ClientView;
  19. class DialogDelegate;
  20. class NonClientFrameView;
  21. class View;
  22. class Widget;
  23. // WidgetDelegate interface
  24. // Handles events on Widgets in context-specific ways.
  25. class VIEWS_EXPORT WidgetDelegate {
  26. public:
  27. WidgetDelegate();
  28. // Called whenever the widget's position changes.
  29. virtual void OnWidgetMove();
  30. // Called with the display changes (color depth or resolution).
  31. virtual void OnDisplayChanged();
  32. // Called when the work area (the desktop area minus task bars,
  33. // menu bars, etc.) changes in size.
  34. virtual void OnWorkAreaChanged();
  35. // Returns the view that should have the focus when the widget is shown. If
  36. // NULL no view is focused.
  37. virtual View* GetInitiallyFocusedView();
  38. // Moved from WindowDelegate: ------------------------------------------------
  39. // TODO(beng): sort
  40. virtual BubbleDelegate* AsBubbleDelegate();
  41. virtual DialogDelegate* AsDialogDelegate();
  42. // Returns true if the window can ever be resized.
  43. virtual bool CanResize() const;
  44. // Returns true if the window can ever be maximized.
  45. virtual bool CanMaximize() const;
  46. // Returns true if the window can be activated.
  47. virtual bool CanActivate() const;
  48. // Returns true if the dialog should be displayed modally to the window that
  49. // opened it. Only windows with WindowType == DIALOG can be modal.
  50. virtual bool IsModal() const;
  51. virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const;
  52. virtual ui::AccessibilityTypes::State GetAccessibleWindowState() const;
  53. // Returns the title to be read with screen readers.
  54. virtual string16 GetAccessibleWindowTitle() const;
  55. // Returns the text to be displayed in the window title.
  56. virtual string16 GetWindowTitle() const;
  57. // Returns true if the window should show a title in the title bar.
  58. virtual bool ShouldShowWindowTitle() const;
  59. // Returns true if the window's client view wants a client edge.
  60. virtual bool ShouldShowClientEdge() const;
  61. // Returns the app icon for the window. On Windows, this is the ICON_BIG used
  62. // in Alt-Tab list and Win7's taskbar.
  63. virtual SkBitmap GetWindowAppIcon();
  64. // Returns the icon to be displayed in the window.
  65. virtual SkBitmap GetWindowIcon();
  66. // Returns true if a window icon should be shown.
  67. virtual bool ShouldShowWindowIcon() const;
  68. // Execute a command in the window's controller. Returns true if the command
  69. // was handled, false if it was not.
  70. virtual bool ExecuteWindowsCommand(int command_id);
  71. // Returns the window's name identifier. Used to identify this window for
  72. // state restoration.
  73. virtual std::string GetWindowName() const;
  74. // Saves the window's bounds and "show" state. By default this uses the
  75. // process' local state keyed by window name (See GetWindowName above). This
  76. // behavior can be overridden to provide additional functionality.
  77. virtual void SaveWindowPlacement(const gfx::Rect& bounds,
  78. ui::WindowShowState show_state);
  79. // Retrieves the window's bounds and "show" states.
  80. // This behavior can be overridden to provide additional functionality.
  81. virtual bool GetSavedWindowPlacement(gfx::Rect* bounds,
  82. ui::WindowShowState* show_state) const;
  83. // Returns true if the window's size should be restored. If this is false,
  84. // only the window's origin is restored and the window is given its
  85. // preferred size.
  86. // Default is true.
  87. virtual bool ShouldRestoreWindowSize() const;
  88. // Called when the window closes. The delegate MUST NOT delete itself during
  89. // this call, since it can be called afterwards. See DeleteDelegate().
  90. virtual void WindowClosing() {}
  91. // Called when the window is destroyed. No events must be sent or received
  92. // after this point. The delegate can use this opportunity to delete itself at
  93. // this time if necessary.
  94. virtual void DeleteDelegate() {}
  95. // Called when the user begins/ends to change the bounds of the window.
  96. virtual void OnWindowBeginUserBoundsChange() {}
  97. virtual void OnWindowEndUserBoundsChange() {}
  98. // Returns the Widget associated with this delegate.
  99. virtual Widget* GetWidget() = 0;
  100. virtual const Widget* GetWidget() const = 0;
  101. // Returns the View that is contained within this Widget.
  102. virtual View* GetContentsView();
  103. // Called by the Widget to create the Client View used to host the contents
  104. // of the widget.
  105. virtual ClientView* CreateClientView(Widget* widget);
  106. // Called by the Widget to create the NonClient Frame View for this widget.
  107. // Return NULL to use the default one.
  108. virtual NonClientFrameView* CreateNonClientFrameView();
  109. // Returns true if the window can be notified with the work area change.
  110. // Otherwise, the work area change for the top window will be processed by
  111. // the default window manager. In some cases, like panel, we would like to
  112. // manage the positions by ourselves.
  113. virtual bool WillProcessWorkAreaChange() const;
  114. protected:
  115. virtual ~WidgetDelegate() {}
  116. private:
  117. View* default_contents_view_;
  118. DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
  119. };
  120. // A WidgetDelegate implementation that is-a View. Used to override GetWidget()
  121. // to call View's GetWidget() for the common case where a WidgetDelegate
  122. // implementation is-a View.
  123. class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
  124. public:
  125. WidgetDelegateView();
  126. virtual ~WidgetDelegateView();
  127. // Overridden from WidgetDelegate:
  128. virtual Widget* GetWidget() OVERRIDE;
  129. virtual const Widget* GetWidget() const OVERRIDE;
  130. private:
  131. DISALLOW_COPY_AND_ASSIGN(WidgetDelegateView);
  132. };
  133. } // namespace views
  134. #endif // VIEWS_WIDGET_WIDGET_DELEGATE_H_