diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 05:22:19 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 05:22:19 +0000 |
commit | 1de34568e66c2302b6911f3d8d7bb550974df312 (patch) | |
tree | 0d80c1af65449208d0bd3b42d39d42a55d294b1f /ui | |
parent | dc23e7206f2fd743296914b57caba3b592af5186 (diff) | |
download | chromium_src-1de34568e66c2302b6911f3d8d7bb550974df312.zip chromium_src-1de34568e66c2302b6911f3d8d7bb550974df312.tar.gz chromium_src-1de34568e66c2302b6911f3d8d7bb550974df312.tar.bz2 |
ui: Refactor views::DialogDelegate to create a ui::DialogModel.
BUG=none
R=ben@chromium.org
Review URL: https://codereview.chromium.org/15150002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199916 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/models/dialog_model.cc | 12 | ||||
-rw-r--r-- | ui/base/models/dialog_model.h | 51 | ||||
-rw-r--r-- | ui/ui.gyp | 2 | ||||
-rw-r--r-- | ui/views/window/dialog_delegate.cc | 63 | ||||
-rw-r--r-- | ui/views/window/dialog_delegate.h | 32 |
5 files changed, 118 insertions, 42 deletions
diff --git a/ui/base/models/dialog_model.cc b/ui/base/models/dialog_model.cc new file mode 100644 index 0000000..310bff0 --- /dev/null +++ b/ui/base/models/dialog_model.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/models/dialog_model.h" + +namespace ui { + +DialogModel::~DialogModel() { +} + +} // namespace ui diff --git a/ui/base/models/dialog_model.h b/ui/base/models/dialog_model.h new file mode 100644 index 0000000..0649f0b --- /dev/null +++ b/ui/base/models/dialog_model.h @@ -0,0 +1,51 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_MODELS_DIALOG_MODEL_H_ +#define UI_BASE_MODELS_DIALOG_MODEL_H_ + +#include "base/string16.h" +#include "ui/base/ui_base_types.h" +#include "ui/base/ui_export.h" + +namespace ui { + +// A model representing a dialog window. The model provides the content to show +// to the user (i.e. label, title), and the ways the user can interact with it +// (i.e. the buttons). +class UI_EXPORT DialogModel { + public: + virtual ~DialogModel(); + + // Returns the text of show in the dialog. + virtual base::string16 GetDialogLabel() const = 0; + + // Returns the title of the dialog. + virtual base::string16 GetDialogTitle() const = 0; + + // Returns a mask specifying which of the available DialogButtons are visible + // for the dialog. Note: Dialogs with just an OK button are frowned upon. + virtual int GetDialogButtons() const = 0; + + // Returns the default dialog button. This should not be a mask as only + // one button should ever be the default button. Return + // ui::DIALOG_BUTTON_NONE if there is no default. Default + // behavior is to return ui::DIALOG_BUTTON_OK or + // ui::DIALOG_BUTTON_CANCEL (in that order) if they are + // present, ui::DIALOG_BUTTON_NONE otherwise. + virtual int GetDefaultDialogButton() const = 0; + + // Returns the label of the specified dialog button. + virtual base::string16 GetDialogButtonLabel(DialogButton button) const = 0; + + // Returns whether the specified dialog button is enabled. + virtual bool IsDialogButtonEnabled(DialogButton button) const = 0; + + // Returns true if the dialog should be closed. Returns false otherwise. + virtual bool OnDialogButtonActivated(DialogButton button) = 0; +}; + +} // namespace ui + +#endif // UI_BASE_MODELS_DIALOG_MODEL_H_ @@ -244,6 +244,8 @@ 'base/models/button_menu_item_model.h', 'base/models/combobox_model.cc', 'base/models/combobox_model.h', + 'base/models/dialog_model.cc', + 'base/models/dialog_model.h', 'base/models/list_model.h', 'base/models/list_model_observer.h', 'base/models/list_selection_model.cc', diff --git a/ui/views/window/dialog_delegate.cc b/ui/views/window/dialog_delegate.cc index a6d2185..66f965f 100644 --- a/ui/views/window/dialog_delegate.cc +++ b/ui/views/window/dialog_delegate.cc @@ -57,6 +57,38 @@ Widget* DialogDelegate::CreateDialogWidget(DialogDelegate* dialog, return widget; } +View* DialogDelegate::CreateExtraView() { + return NULL; +} + +View* DialogDelegate::CreateTitlebarExtraView() { + return NULL; +} + +View* DialogDelegate::CreateFootnoteView() { + return NULL; +} + +bool DialogDelegate::Cancel() { + return true; +} + +bool DialogDelegate::Accept(bool window_closing) { + return Accept(); +} + +bool DialogDelegate::Accept() { + return true; +} + +base::string16 DialogDelegate::GetDialogLabel() const { + return base::string16(); +} + +base::string16 DialogDelegate::GetDialogTitle() const { + return base::string16(); +} + int DialogDelegate::GetDialogButtons() const { return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; } @@ -69,7 +101,8 @@ int DialogDelegate::GetDefaultDialogButton() const { return ui::DIALOG_BUTTON_NONE; } -string16 DialogDelegate::GetDialogButtonLabel(ui::DialogButton button) const { +base::string16 DialogDelegate::GetDialogButtonLabel( + ui::DialogButton button) const { if (button == ui::DIALOG_BUTTON_OK) return l10n_util::GetStringUTF16(IDS_APP_OK); if (button == ui::DIALOG_BUTTON_CANCEL) { @@ -78,34 +111,18 @@ string16 DialogDelegate::GetDialogButtonLabel(ui::DialogButton button) const { return l10n_util::GetStringUTF16(IDS_APP_CLOSE); } NOTREACHED(); - return string16(); + return base::string16(); } bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const { return true; } -View* DialogDelegate::CreateExtraView() { - return NULL; -} - -View* DialogDelegate::CreateTitlebarExtraView() { - return NULL; -} - -View* DialogDelegate::CreateFootnoteView() { - return NULL; -} - -bool DialogDelegate::Cancel() { - return true; -} - -bool DialogDelegate::Accept(bool window_closing) { - return Accept(); -} - -bool DialogDelegate::Accept() { +bool DialogDelegate::OnDialogButtonActivated(ui::DialogButton button) { + if (button == ui::DIALOG_BUTTON_OK) + return Accept(); + if (button == ui::DIALOG_BUTTON_CANCEL) + return Cancel(); return true; } diff --git a/ui/views/window/dialog_delegate.h b/ui/views/window/dialog_delegate.h index 49f4b8e..401456e 100644 --- a/ui/views/window/dialog_delegate.h +++ b/ui/views/window/dialog_delegate.h @@ -8,6 +8,7 @@ #include "base/compiler_specific.h" #include "base/string16.h" #include "ui/base/accessibility/accessibility_types.h" +#include "ui/base/models/dialog_model.h" #include "ui/base/ui_base_types.h" #include "ui/views/widget/widget_delegate.h" @@ -25,7 +26,8 @@ class DialogClientView; // certain events. // /////////////////////////////////////////////////////////////////////////////// -class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { +class VIEWS_EXPORT DialogDelegate : public ui::DialogModel, + public WidgetDelegate { public: virtual ~DialogDelegate(); @@ -37,24 +39,6 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { gfx::NativeWindow context, gfx::NativeWindow parent); - // Returns a mask specifying which of the available DialogButtons are visible - // for the dialog. Note: Dialogs with just an OK button are frowned upon. - virtual int GetDialogButtons() const; - - // Returns the default dialog button. This should not be a mask as only - // one button should ever be the default button. Return - // ui::DIALOG_BUTTON_NONE if there is no default. Default - // behavior is to return ui::DIALOG_BUTTON_OK or - // ui::DIALOG_BUTTON_CANCEL (in that order) if they are - // present, ui::DIALOG_BUTTON_NONE otherwise. - virtual int GetDefaultDialogButton() const; - - // Returns the label of the specified dialog button. - virtual string16 GetDialogButtonLabel(ui::DialogButton button) const; - - // Returns whether the specified dialog button is enabled. - virtual bool IsDialogButtonEnabled(ui::DialogButton button) const; - // Override this function to display an extra view adjacent to the buttons. // Overrides may construct the view; this will only be called once per dialog. virtual View* CreateExtraView(); @@ -85,6 +69,16 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { virtual bool Accept(bool window_closing); virtual bool Accept(); + // Overridden from ui::DialogModel: + virtual base::string16 GetDialogLabel() const OVERRIDE; + virtual base::string16 GetDialogTitle() const OVERRIDE; + virtual int GetDialogButtons() const OVERRIDE; + virtual int GetDefaultDialogButton() const OVERRIDE; + virtual base::string16 GetDialogButtonLabel( + ui::DialogButton button) const OVERRIDE; + virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; + virtual bool OnDialogButtonActivated(ui::DialogButton button) OVERRIDE; + // Overridden from WidgetDelegate: virtual View* GetInitiallyFocusedView() OVERRIDE; virtual DialogDelegate* AsDialogDelegate() OVERRIDE; |