diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-31 20:08:27 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-31 20:08:27 +0000 |
commit | 3e1a05ab9d6496e84879518d974320fbc561465c (patch) | |
tree | d814a827227ae6da31f9190382d91fae6c858668 /views | |
parent | f01338eeb06ed685095be2b39cedb664692feda0 (diff) | |
download | chromium_src-3e1a05ab9d6496e84879518d974320fbc561465c.zip chromium_src-3e1a05ab9d6496e84879518d974320fbc561465c.tar.gz chromium_src-3e1a05ab9d6496e84879518d974320fbc561465c.tar.bz2 |
Move methods from WindowDelegate onto WidgetDelegate.
BUG=72040
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/7078008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87349 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/widget/widget_delegate.cc | 116 | ||||
-rw-r--r-- | views/widget/widget_delegate.h | 115 | ||||
-rw-r--r-- | views/window/window_delegate.cc | 112 | ||||
-rw-r--r-- | views/window/window_delegate.h | 110 |
4 files changed, 232 insertions, 221 deletions
diff --git a/views/widget/widget_delegate.cc b/views/widget/widget_delegate.cc index c5ba764..5e86035 100644 --- a/views/widget/widget_delegate.cc +++ b/views/widget/widget_delegate.cc @@ -5,9 +5,16 @@ #include "views/widget/widget_delegate.h" #include "views/view.h" +#include "views/views_delegate.h" +#include "views/window/client_view.h" +#include "views/window/window.h" +#include "third_party/skia/include/core/SkBitmap.h" namespace views { +WidgetDelegate::WidgetDelegate() : window_(NULL) { +} + void WidgetDelegate::OnWidgetActivated(bool active) { } @@ -24,5 +31,114 @@ View* WidgetDelegate::GetInitiallyFocusedView() { return NULL; } +DialogDelegate* WidgetDelegate::AsDialogDelegate() { + return NULL; +} + +bool WidgetDelegate::CanResize() const { + return false; +} + +bool WidgetDelegate::CanMaximize() const { + return false; +} + +bool WidgetDelegate::CanActivate() const { + return true; +} + +bool WidgetDelegate::IsModal() const { + return false; +} + +ui::AccessibilityTypes::Role WidgetDelegate::GetAccessibleWindowRole() const { + return ui::AccessibilityTypes::ROLE_WINDOW; +} + +ui::AccessibilityTypes::State WidgetDelegate::GetAccessibleWindowState() const { + return 0; +} + +std::wstring WidgetDelegate::GetAccessibleWindowTitle() const { + return GetWindowTitle(); +} + +std::wstring WidgetDelegate::GetWindowTitle() const { + return L""; +} + +bool WidgetDelegate::ShouldShowWindowTitle() const { + return true; +} + +bool WidgetDelegate::ShouldShowClientEdge() const { + return true; +} + +SkBitmap WidgetDelegate::GetWindowAppIcon() { + // Use the window icon as app icon by default. + return GetWindowIcon(); +} + +// Returns the icon to be displayed in the window. +SkBitmap WidgetDelegate::GetWindowIcon() { + return SkBitmap(); +} + +bool WidgetDelegate::ShouldShowWindowIcon() const { + return false; +} + +bool WidgetDelegate::ExecuteWindowsCommand(int command_id) { + return false; +} + +std::wstring WidgetDelegate::GetWindowName() const { + return std::wstring(); +} + +void WidgetDelegate::SaveWindowPlacement(const gfx::Rect& bounds, + bool maximized) { + DCHECK(window_); + std::wstring window_name = GetWindowName(); + if (!ViewsDelegate::views_delegate || window_name.empty()) + return; + + ViewsDelegate::views_delegate->SaveWindowPlacement( + window_, window_name, bounds, maximized); +} + +bool WidgetDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const { + DCHECK(window_); + std::wstring window_name = GetWindowName(); + if (!ViewsDelegate::views_delegate || window_name.empty()) + return false; + + return ViewsDelegate::views_delegate->GetSavedWindowBounds( + window_, window_name, bounds); +} + +bool WidgetDelegate::GetSavedMaximizedState(bool* maximized) const { + DCHECK(window_); + std::wstring window_name = GetWindowName(); + if (!ViewsDelegate::views_delegate || window_name.empty()) + return false; + + return ViewsDelegate::views_delegate->GetSavedMaximizedState( + window_, window_name, maximized); +} + +bool WidgetDelegate::ShouldRestoreWindowSize() const { + return true; +} + +View* WidgetDelegate::GetContentsView() { + return NULL; +} + +ClientView* WidgetDelegate::CreateClientView(Window* window) { + return new ClientView(window, GetContentsView()); +} + } // namespace views diff --git a/views/widget/widget_delegate.h b/views/widget/widget_delegate.h index ad1f251..a6aab4e 100644 --- a/views/widget/widget_delegate.h +++ b/views/widget/widget_delegate.h @@ -6,14 +6,29 @@ #define VIEWS_WIDGET_WIDGET_DELEGATE_H_ #pragma once -namespace views { +#include <string> + +#include "base/memory/scoped_ptr.h" +#include "ui/base/accessibility/accessibility_types.h" + +class SkBitmap; +namespace gfx { +class Rect; +} + +namespace views { +class ClientView; +class DialogDelegate; class View; +class Window; // WidgetDelegate interface // Handles events on Widgets in context-specific ways. class WidgetDelegate { public: + WidgetDelegate(); + // Called whenever the widget is activated or deactivated. // TODO(beng): This should be consolidated with // WindowDelegate::OnWindowActivationChanged(). @@ -33,8 +48,106 @@ class WidgetDelegate { // NULL no view is focused. virtual View* GetInitiallyFocusedView(); + // Moved from WindowDelegate: ------------------------------------------------ + // TODO(beng): sort + + virtual DialogDelegate* AsDialogDelegate(); + + // Returns true if the window can ever be resized. + virtual bool CanResize() const; + + // Returns true if the window can ever be maximized. + virtual bool CanMaximize() const; + + // Returns true if the window can be activated. + virtual bool CanActivate() const; + + // Returns true if the dialog should be displayed modally to the window that + // opened it. Only windows with WindowType == DIALOG can be modal. + virtual bool IsModal() const; + + virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const; + + virtual ui::AccessibilityTypes::State GetAccessibleWindowState() const; + + // Returns the title to be read with screen readers. + virtual std::wstring GetAccessibleWindowTitle() const; + + // Returns the text to be displayed in the window title. + virtual std::wstring GetWindowTitle() const; + + // Returns true if the window should show a title in the title bar. + virtual bool ShouldShowWindowTitle() const; + + // Returns true if the window's client view wants a client edge. + virtual bool ShouldShowClientEdge() const; + + // Returns the app icon for the window. On Windows, this is the ICON_BIG used + // in Alt-Tab list and Win7's taskbar. + virtual SkBitmap GetWindowAppIcon(); + + // Returns the icon to be displayed in the window. + virtual SkBitmap GetWindowIcon(); + + // Returns true if a window icon should be shown. + virtual bool ShouldShowWindowIcon() const; + + // Execute a command in the window's controller. Returns true if the command + // was handled, false if it was not. + virtual bool ExecuteWindowsCommand(int command_id); + + // Returns the window's name identifier. Used to identify this window for + // state restoration. + virtual std::wstring GetWindowName() const; + + // Saves the window's bounds and maximized states. By default this uses the + // process' local state keyed by window name (See GetWindowName above). This + // behavior can be overridden to provide additional functionality. + virtual void SaveWindowPlacement(const gfx::Rect& bounds, bool maximized); + + // Retrieves the window's bounds and maximized states. + // This behavior can be overridden to provide additional functionality. + virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const; + virtual bool GetSavedMaximizedState(bool* maximized) const; + + // Returns true if the window's size should be restored. If this is false, + // only the window's origin is restored and the window is given its + // preferred size. + // Default is true. + virtual bool ShouldRestoreWindowSize() const; + + // Called when the window closes. The delegate MUST NOT delete itself during + // this call, since it can be called afterwards. See DeleteDelegate(). + virtual void WindowClosing() {} + + // Called when the window is destroyed. No events must be sent or received + // after this point. The delegate can use this opportunity to delete itself at + // this time if necessary. + virtual void DeleteDelegate() {} + + // Called when the window's activation state changes. + virtual void OnWindowActivationChanged(bool active) {} + + // Called when the user begins/ends to change the bounds of the window. + virtual void OnWindowBeginUserBoundsChange() {} + virtual void OnWindowEndUserBoundsChange() {} + + // Returns the View that is contained within this Window. + virtual View* GetContentsView(); + + // Called by the Window to create the Client View used to host the contents + // of the window. + virtual ClientView* CreateClientView(Window* window); + + Window* window() const { return window_; } + protected: virtual ~WidgetDelegate() {} + + private: + friend class Window; + // The Window this delegate is bound to. Weak reference. + Window* window_; }; } // namespace views diff --git a/views/window/window_delegate.cc b/views/window/window_delegate.cc index 30ad955..d75f881 100644 --- a/views/window/window_delegate.cc +++ b/views/window/window_delegate.cc @@ -3,123 +3,13 @@ // found in the LICENSE file. #include "views/window/window_delegate.h" -#include "views/views_delegate.h" -#include "views/window/client_view.h" -#include "views/window/window.h" -#include "third_party/skia/include/core/SkBitmap.h" namespace views { -WindowDelegate::WindowDelegate() : window_(NULL) { +WindowDelegate::WindowDelegate() { } WindowDelegate::~WindowDelegate() { } -DialogDelegate* WindowDelegate::AsDialogDelegate() { - return NULL; -} - -bool WindowDelegate::CanResize() const { - return false; -} - -bool WindowDelegate::CanMaximize() const { - return false; -} - -bool WindowDelegate::CanActivate() const { - return true; -} - -bool WindowDelegate::IsModal() const { - return false; -} - -ui::AccessibilityTypes::Role WindowDelegate::GetAccessibleWindowRole() const { - return ui::AccessibilityTypes::ROLE_WINDOW; -} - -ui::AccessibilityTypes::State WindowDelegate::GetAccessibleWindowState() const { - return 0; -} - -std::wstring WindowDelegate::GetAccessibleWindowTitle() const { - return GetWindowTitle(); -} - -std::wstring WindowDelegate::GetWindowTitle() const { - return L""; -} - -bool WindowDelegate::ShouldShowWindowTitle() const { - return true; -} - -bool WindowDelegate::ShouldShowClientEdge() const { - return true; -} - -SkBitmap WindowDelegate::GetWindowAppIcon() { - // Use the window icon as app icon by default. - return GetWindowIcon(); -} - -// Returns the icon to be displayed in the window. -SkBitmap WindowDelegate::GetWindowIcon() { - return SkBitmap(); -} - -bool WindowDelegate::ShouldShowWindowIcon() const { - return false; -} - -bool WindowDelegate::ExecuteWindowsCommand(int command_id) { - return false; -} - -std::wstring WindowDelegate::GetWindowName() const { - return std::wstring(); -} - -void WindowDelegate::SaveWindowPlacement(const gfx::Rect& bounds, - bool maximized) { - std::wstring window_name = GetWindowName(); - if (!ViewsDelegate::views_delegate || window_name.empty()) - return; - - ViewsDelegate::views_delegate->SaveWindowPlacement( - window_, window_name, bounds, maximized); -} - -bool WindowDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const { - std::wstring window_name = GetWindowName(); - if (!ViewsDelegate::views_delegate || window_name.empty()) - return false; - - return ViewsDelegate::views_delegate->GetSavedWindowBounds( - window_, window_name, bounds); -} - -bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const { - std::wstring window_name = GetWindowName(); - if (!ViewsDelegate::views_delegate || window_name.empty()) - return false; - - return ViewsDelegate::views_delegate->GetSavedMaximizedState( - window_, window_name, maximized); -} - -bool WindowDelegate::ShouldRestoreWindowSize() const { - return true; -} - -View* WindowDelegate::GetContentsView() { - return NULL; -} - -ClientView* WindowDelegate::CreateClientView(Window* window) { - return new ClientView(window, GetContentsView()); -} - } // namespace views diff --git a/views/window/window_delegate.h b/views/window/window_delegate.h index e6b3ac0..a7715ab 100644 --- a/views/window/window_delegate.h +++ b/views/window/window_delegate.h @@ -6,25 +6,10 @@ #define VIEWS_WINDOW_WINDOW_DELEGATE_H_ #pragma once -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "ui/base/accessibility/accessibility_types.h" #include "views/widget/widget_delegate.h" -class SkBitmap; - -namespace gfx { -class Rect; -} - namespace views { -class ClientView; -class DialogDelegate; -class View; -class Window; - /////////////////////////////////////////////////////////////////////////////// // // WindowDelegate @@ -33,106 +18,13 @@ class Window; // Window. The window that is displayed uses this interface to determine how // it should be displayed and notify the delegate object of certain events. // -/////////////////////////////////////////////////////////////////////////////// class WindowDelegate : public WidgetDelegate { public: WindowDelegate(); virtual ~WindowDelegate(); - virtual DialogDelegate* AsDialogDelegate(); - - // Returns true if the window can ever be resized. - virtual bool CanResize() const; - - // Returns true if the window can ever be maximized. - virtual bool CanMaximize() const; - - // Returns true if the window can be activated. - virtual bool CanActivate() const; - - // Returns true if the dialog should be displayed modally to the window that - // opened it. Only windows with WindowType == DIALOG can be modal. - virtual bool IsModal() const; - - virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const; - - virtual ui::AccessibilityTypes::State GetAccessibleWindowState() const; - - // Returns the title to be read with screen readers. - virtual std::wstring GetAccessibleWindowTitle() const; - - // Returns the text to be displayed in the window title. - virtual std::wstring GetWindowTitle() const; - - // Returns true if the window should show a title in the title bar. - virtual bool ShouldShowWindowTitle() const; - - // Returns true if the window's client view wants a client edge. - virtual bool ShouldShowClientEdge() const; - - // Returns the app icon for the window. On Windows, this is the ICON_BIG used - // in Alt-Tab list and Win7's taskbar. - virtual SkBitmap GetWindowAppIcon(); - - // Returns the icon to be displayed in the window. - virtual SkBitmap GetWindowIcon(); - - // Returns true if a window icon should be shown. - virtual bool ShouldShowWindowIcon() const; - - // Execute a command in the window's controller. Returns true if the command - // was handled, false if it was not. - virtual bool ExecuteWindowsCommand(int command_id); - - // Returns the window's name identifier. Used to identify this window for - // state restoration. - virtual std::wstring GetWindowName() const; - - // Saves the window's bounds and maximized states. By default this uses the - // process' local state keyed by window name (See GetWindowName above). This - // behavior can be overridden to provide additional functionality. - virtual void SaveWindowPlacement(const gfx::Rect& bounds, bool maximized); - - // Retrieves the window's bounds and maximized states. - // This behavior can be overridden to provide additional functionality. - virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const; - virtual bool GetSavedMaximizedState(bool* maximized) const; - - // Returns true if the window's size should be restored. If this is false, - // only the window's origin is restored and the window is given its - // preferred size. - // Default is true. - virtual bool ShouldRestoreWindowSize() const; - - // Called when the window closes. The delegate MUST NOT delete itself during - // this call, since it can be called afterwards. See DeleteDelegate(). - virtual void WindowClosing() {} - - // Called when the window is destroyed. No events must be sent or received - // after this point. The delegate can use this opportunity to delete itself at - // this time if necessary. - virtual void DeleteDelegate() {} - - // Called when the window's activation state changes. - virtual void OnWindowActivationChanged(bool active) {} - - // Called when the user begins/ends to change the bounds of the window. - virtual void OnWindowBeginUserBoundsChange() {} - virtual void OnWindowEndUserBoundsChange() {} - - // Returns the View that is contained within this Window. - virtual View* GetContentsView(); - - // Called by the Window to create the Client View used to host the contents - // of the window. - virtual ClientView* CreateClientView(Window* window); - - Window* window() const { return window_; } - private: - friend class Window; - // The Window this delegate is bound to. Weak reference. - Window* window_; + DISALLOW_COPY_AND_ASSIGN(WindowDelegate); }; } // namespace views |