diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-04 19:22:27 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-04 19:22:27 +0000 |
commit | ef062ba24b2916071e286d1abdfbfe3de4d1f52a (patch) | |
tree | 675703f6b36f24f58c74781724d9bffb518c8430 /views | |
parent | 5b2532dde2c9114ceb9f15d756246a1710ccff4e (diff) | |
download | chromium_src-ef062ba24b2916071e286d1abdfbfe3de4d1f52a.zip chromium_src-ef062ba24b2916071e286d1abdfbfe3de4d1f52a.tar.gz chromium_src-ef062ba24b2916071e286d1abdfbfe3de4d1f52a.tar.bz2 |
views: Move DialogButton enum into ui/base/ and put it into the ui namespace.
R=sky@chromium.org
Review URL: http://codereview.chromium.org/8334041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/view_unittest.cc | 2 | ||||
-rw-r--r-- | views/window/dialog_client_view.cc | 55 | ||||
-rw-r--r-- | views/window/dialog_delegate.cc | 50 | ||||
-rw-r--r-- | views/window/dialog_delegate.h | 42 |
4 files changed, 68 insertions, 81 deletions
diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 9b949b5..03b7cfe 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -1253,7 +1253,7 @@ class TestDialog : public DialogDelegate, public ButtonListener { // DialogDelegate implementation: virtual int GetDefaultDialogButton() const OVERRIDE { - return ui::MessageBoxFlags::DIALOGBUTTON_OK; + return ui::DIALOG_BUTTON_OK; } virtual View* GetContentsView() OVERRIDE { diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index 4320308..4040085 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -36,15 +36,13 @@ #include "views/window/hit_test.h" #endif -using ui::MessageBoxFlags; - namespace views { namespace { // Updates any of the standard buttons according to the delegate. void UpdateButtonHelper(NativeTextButton* button_view, DialogDelegate* delegate, - MessageBoxFlags::DialogButton button) { + ui::DialogButton button) { string16 label = delegate->GetDialogButtonLabel(button); if (!label.empty()) button_view->SetText(label); @@ -69,7 +67,7 @@ class DialogButton : public NativeTextButton { public: DialogButton(ButtonListener* listener, Widget* owner, - MessageBoxFlags::DialogButton type, + ui::DialogButton type, const string16& title, bool is_default) : NativeTextButton(listener, title), @@ -89,7 +87,7 @@ class DialogButton : public NativeTextButton { private: Widget* owner_; - const MessageBoxFlags::DialogButton type_; + const ui::DialogButton type_; DISALLOW_COPY_AND_ASSIGN(DialogButton); }; @@ -129,41 +127,41 @@ DialogClientView::~DialogClientView() { void DialogClientView::ShowDialogButtons() { DialogDelegate* dd = GetDialogDelegate(); int buttons = dd->GetDialogButtons(); - if (buttons & MessageBoxFlags::DIALOGBUTTON_OK && !ok_button_) { - string16 label = dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_OK); + if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { + string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); if (label.empty()) label = l10n_util::GetStringUTF16(IDS_APP_OK); bool is_default_button = - (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0; + (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; ok_button_ = new DialogButton(this, GetWidget(), - MessageBoxFlags::DIALOGBUTTON_OK, + ui::DIALOG_BUTTON_OK, label, is_default_button); ok_button_->SetGroup(kButtonGroup); if (is_default_button) default_button_ = ok_button_; - if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)) + if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) ok_button_->AddAccelerator(Accelerator(ui::VKEY_ESCAPE, false, false, false)); AddChildView(ok_button_); } - if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) { + if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { string16 label = - dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL); + dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); if (label.empty()) { - if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) { + if (buttons & ui::DIALOG_BUTTON_OK) { label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); } else { label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); } } bool is_default_button = - (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) + (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) != 0; cancel_button_ = new DialogButton(this, GetWidget(), - MessageBoxFlags::DIALOGBUTTON_CANCEL, + ui::DIALOG_BUTTON_CANCEL, label, is_default_button); cancel_button_->SetGroup(kButtonGroup); @@ -202,9 +200,9 @@ void DialogClientView::FocusWillChange(View* focused_before, // The focused view is not a button, get the default button from the // delegate. DialogDelegate* dd = GetDialogDelegate(); - if ((dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0) + if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) new_default_button = ok_button_; - if ((dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) + if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) != 0) new_default_button = cancel_button_; } @@ -216,12 +214,11 @@ void DialogClientView::UpdateDialogButtons() { DialogDelegate* dd = GetDialogDelegate(); int buttons = dd->GetDialogButtons(); - if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) - UpdateButtonHelper(ok_button_, dd, MessageBoxFlags::DIALOGBUTTON_OK); + if (buttons & ui::DIALOG_BUTTON_OK) + UpdateButtonHelper(ok_button_, dd, ui::DIALOG_BUTTON_OK); - if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL) { - UpdateButtonHelper(cancel_button_, dd, - MessageBoxFlags::DIALOGBUTTON_CANCEL); + if (buttons & ui::DIALOG_BUTTON_CANCEL) { + UpdateButtonHelper(cancel_button_, dd, ui::DIALOG_BUTTON_CANCEL); } LayoutDialogButtons(); @@ -279,9 +276,9 @@ bool DialogClientView::CanClose() { DialogDelegate* dd = GetDialogDelegate(); int buttons = dd->GetDialogButtons(); bool close = true; - if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL) + if (buttons & ui::DIALOG_BUTTON_CANCEL) close = dd->Cancel(); - else if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) + else if (buttons & ui::DIALOG_BUTTON_OK) close = dd->Accept(true); notified_delegate_ = close; return close; @@ -381,9 +378,9 @@ gfx::Size DialogClientView::GetPreferredSize() { // the contents. int width = 0; if (cancel_button_) - width += GetButtonWidth(MessageBoxFlags::DIALOGBUTTON_CANCEL); + width += GetButtonWidth(ui::DIALOG_BUTTON_CANCEL); if (ok_button_) { - width += GetButtonWidth(MessageBoxFlags::DIALOGBUTTON_OK); + width += GetButtonWidth(ui::DIALOG_BUTTON_OK); if (cancel_button_) width += kRelatedButtonHSpacing; } @@ -466,7 +463,7 @@ void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { int DialogClientView::GetButtonWidth(int button) const { DialogDelegate* dd = GetDialogDelegate(); string16 button_label = dd->GetDialogButtonLabel( - static_cast<MessageBoxFlags::DialogButton>(button)); + static_cast<ui::DialogButton>(button)); int string_width = dialog_button_font_->GetStringWidth(button_label); return std::max(string_width + kDialogButtonLabelSpacing, kDialogMinButtonWidth); @@ -493,7 +490,7 @@ void DialogClientView::LayoutDialogButtons() { if (cancel_button_) { gfx::Size ps = cancel_button_->GetPreferredSize(); int button_width = std::max( - GetButtonWidth(MessageBoxFlags::DIALOGBUTTON_CANCEL), ps.width()); + GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); int button_x = lb.right() - button_width - kButtonHEdgeMargin; int button_y = bottom_y - ps.height(); cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); @@ -505,7 +502,7 @@ void DialogClientView::LayoutDialogButtons() { if (ok_button_) { gfx::Size ps = ok_button_->GetPreferredSize(); int button_width = std::max( - GetButtonWidth(MessageBoxFlags::DIALOGBUTTON_OK), ps.width()); + GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); int ok_button_right = lb.right() - kButtonHEdgeMargin; if (cancel_button_) ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; diff --git a/views/window/dialog_delegate.cc b/views/window/dialog_delegate.cc index 895ba81..fc24f90 100644 --- a/views/window/dialog_delegate.cc +++ b/views/window/dialog_delegate.cc @@ -16,47 +16,41 @@ namespace views { DialogDelegate* DialogDelegate::AsDialogDelegate() { return this; } int DialogDelegate::GetDialogButtons() const { - return ui::MessageBoxFlags::DIALOGBUTTON_OK | - ui::MessageBoxFlags::DIALOGBUTTON_CANCEL; + return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; } -bool DialogDelegate::AreAcceleratorsEnabled( - ui::MessageBoxFlags::DialogButton button) { - return true; +int DialogDelegate::GetDefaultDialogButton() const { + if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) + return ui::DIALOG_BUTTON_OK; + if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) + return ui::DIALOG_BUTTON_CANCEL; + return ui::DIALOG_BUTTON_NONE; } -string16 DialogDelegate::GetDialogButtonLabel( - ui::MessageBoxFlags::DialogButton button) const { +string16 DialogDelegate::GetDialogButtonLabel(ui::DialogButton button) const { // Empty string results in defaults for - // ui::MessageBoxFlags::DIALOGBUTTON_OK - // ui::MessageBoxFlags::DIALOGBUTTON_CANCEL. + // ui::DIALOG_BUTTON_OK or ui::DIALOG_BUTTON_CANCEL. return string16(); } -View* DialogDelegate::GetExtraView() { - return NULL; +bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const { + return true; } -bool DialogDelegate::GetSizeExtraViewHeightToButtons() { - return false; +bool DialogDelegate::IsDialogButtonVisible(ui::DialogButton button) const { + return true; } -int DialogDelegate::GetDefaultDialogButton() const { - if (GetDialogButtons() & ui::MessageBoxFlags::DIALOGBUTTON_OK) - return ui::MessageBoxFlags::DIALOGBUTTON_OK; - if (GetDialogButtons() & ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) - return ui::MessageBoxFlags::DIALOGBUTTON_CANCEL; - return ui::MessageBoxFlags::DIALOGBUTTON_NONE; +bool DialogDelegate::AreAcceleratorsEnabled(ui::DialogButton button) { + return true; } -bool DialogDelegate::IsDialogButtonEnabled( - ui::MessageBoxFlags::DialogButton button) const { - return true; +View* DialogDelegate::GetExtraView() { + return NULL; } -bool DialogDelegate::IsDialogButtonVisible( - ui::MessageBoxFlags::DialogButton button) const { - return true; +bool DialogDelegate::GetSizeExtraViewHeightToButtons() { + return false; } bool DialogDelegate::Cancel() { @@ -75,7 +69,7 @@ View* DialogDelegate::GetInitiallyFocusedView() { // Focus the default button if any. const DialogClientView* dcv = GetDialogClientView(); int default_button = GetDefaultDialogButton(); - if (default_button == ui::MessageBoxFlags::DIALOGBUTTON_NONE) + if (default_button == ui::DIALOG_BUTTON_NONE) return NULL; if ((default_button & GetDialogButtons()) == 0) { @@ -84,9 +78,9 @@ View* DialogDelegate::GetInitiallyFocusedView() { return NULL; } - if (default_button & ui::MessageBoxFlags::DIALOGBUTTON_OK) + if (default_button & ui::DIALOG_BUTTON_OK) return dcv->ok_button(); - if (default_button & ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) + if (default_button & ui::DIALOG_BUTTON_CANCEL) return dcv->cancel_button(); return NULL; } diff --git a/views/window/dialog_delegate.h b/views/window/dialog_delegate.h index 7ce10d4..dc38c00 100644 --- a/views/window/dialog_delegate.h +++ b/views/window/dialog_delegate.h @@ -8,7 +8,7 @@ #include "base/string16.h" #include "ui/base/accessibility/accessibility_types.h" -#include "ui/base/message_box_flags.h" +#include "ui/base/ui_base_types.h" #include "views/widget/widget_delegate.h" #include "views/window/dialog_client_view.h" @@ -39,15 +39,27 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { // To use the extra button you need to override GetDialogButtons() 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; + + // Returns whether the specified dialog button is visible. + virtual bool IsDialogButtonVisible(ui::DialogButton button) const; + // Returns whether accelerators are enabled on the button. This is invoked // when an accelerator is pressed, not at construction time. This // returns true. - virtual bool AreAcceleratorsEnabled( - ui::MessageBoxFlags::DialogButton button); - - // Returns the label of the specified DialogButton. - virtual string16 GetDialogButtonLabel( - ui::MessageBoxFlags::DialogButton button) const; + virtual bool AreAcceleratorsEnabled(ui::DialogButton button); // Override this function if with a view which will be shown in the same // row as the OK and CANCEL buttons but flush to the left and extending @@ -60,22 +72,6 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { // max(extra_view preferred height, buttons preferred height). virtual bool GetSizeExtraViewHeightToButtons(); - // Returns the default dialog button. This should not be a mask as only - // one button should ever be the default button. Return - // ui::MessageBoxFlags::DIALOGBUTTON_NONE if there is no default. Default - // behavior is to return ui::MessageBoxFlags::DIALOGBUTTON_OK or - // ui::MessageBoxFlags::DIALOGBUTTON_CANCEL (in that order) if they are - // present, ui::MessageBoxFlags::DIALOGBUTTON_NONE otherwise. - virtual int GetDefaultDialogButton() const; - - // Returns whether the specified dialog button is enabled. - virtual bool IsDialogButtonEnabled( - ui::MessageBoxFlags::DialogButton button) const; - - // Returns whether the specified dialog button is visible. - virtual bool IsDialogButtonVisible( - ui::MessageBoxFlags::DialogButton button) const; - // For Dialog boxes, if there is a "Cancel" button, this is called when the // user presses the "Cancel" button or the Close button on the window or // in the system menu, or presses the Esc key. This function should return |