diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 22:17:33 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 22:17:33 +0000 |
commit | 806aeb954d302328cc75bda71331474d8634675b (patch) | |
tree | 9565300c48ab1ea34b66624222ef979734f68b00 /chrome/views | |
parent | 8f0a23470f47090c601078952b77c5b520c595c2 (diff) | |
download | chromium_src-806aeb954d302328cc75bda71331474d8634675b.zip chromium_src-806aeb954d302328cc75bda71331474d8634675b.tar.gz chromium_src-806aeb954d302328cc75bda71331474d8634675b.tar.bz2 |
Refactor DialogDelegate so the DialogButton enum is in cross platform
code.
This is mostly a find & replace in our code to use the new location
of the enum.
I also deleted some GetDialogButtons methods in child classes
because they were identical to the parent version in DialogDelegate.
This will allow more code to be enabled on linux/mac in the
automation provider.
Review URL: http://codereview.chromium.org/88008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r-- | chrome/views/view_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/views/window/dialog_client_view.cc | 48 | ||||
-rw-r--r-- | chrome/views/window/dialog_delegate.cc | 16 | ||||
-rw-r--r-- | chrome/views/window/dialog_delegate.h | 35 |
4 files changed, 50 insertions, 55 deletions
diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc index 9fbf481..432a47b 100644 --- a/chrome/views/view_unittest.cc +++ b/chrome/views/view_unittest.cc @@ -843,12 +843,8 @@ class TestDialogView : public views::View, } // views::DialogDelegate implementation: - virtual int GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; - } - virtual int GetDefaultDialogButton() const { - return DIALOGBUTTON_OK; + return MessageBox::DIALOGBUTTON_OK; } virtual View* GetContentsView() { diff --git a/chrome/views/window/dialog_client_view.cc b/chrome/views/window/dialog_client_view.cc index 542439d..0a8294f 100644 --- a/chrome/views/window/dialog_client_view.cc +++ b/chrome/views/window/dialog_client_view.cc @@ -27,7 +27,7 @@ namespace { // Updates any of the standard buttons according to the delegate. void UpdateButtonHelper(NativeButton* button_view, DialogDelegate* delegate, - DialogDelegate::DialogButton button) { + MessageBox::DialogButton button) { std::wstring label = delegate->GetDialogButtonLabel(button); if (!label.empty()) button_view->SetLabel(label); @@ -50,7 +50,7 @@ class DialogButton : public NativeButton { public: DialogButton(ButtonListener* listener, Window* owner, - DialogDelegate::DialogButton type, + MessageBox::DialogButton type, const std::wstring& title, bool is_default) : NativeButton(listener, title), @@ -70,7 +70,7 @@ class DialogButton : public NativeButton { private: Window* owner_; - const DialogDelegate::DialogButton type_; + const MessageBox::DialogButton type_; DISALLOW_COPY_AND_ASSIGN(DialogButton); }; @@ -106,38 +106,38 @@ DialogClientView::~DialogClientView() { void DialogClientView::ShowDialogButtons() { DialogDelegate* dd = GetDialogDelegate(); int buttons = dd->GetDialogButtons(); - if (buttons & DialogDelegate::DIALOGBUTTON_OK && !ok_button_) { + if (buttons & MessageBox::DIALOGBUTTON_OK && !ok_button_) { std::wstring label = - dd->GetDialogButtonLabel(DialogDelegate::DIALOGBUTTON_OK); + dd->GetDialogButtonLabel(MessageBox::DIALOGBUTTON_OK); if (label.empty()) label = l10n_util::GetString(IDS_OK); bool is_default_button = - (dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_OK) != 0; + (dd->GetDefaultDialogButton() & MessageBox::DIALOGBUTTON_OK) != 0; ok_button_ = new DialogButton(this, window(), - DialogDelegate::DIALOGBUTTON_OK, label, + MessageBox::DIALOGBUTTON_OK, label, is_default_button); ok_button_->SetGroup(kButtonGroup); if (is_default_button) default_button_ = ok_button_; - if (!(buttons & DialogDelegate::DIALOGBUTTON_CANCEL)) + if (!(buttons & MessageBox::DIALOGBUTTON_CANCEL)) ok_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); AddChildView(ok_button_); } - if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL && !cancel_button_) { + if (buttons & MessageBox::DIALOGBUTTON_CANCEL && !cancel_button_) { std::wstring label = - dd->GetDialogButtonLabel(DialogDelegate::DIALOGBUTTON_CANCEL); + dd->GetDialogButtonLabel(MessageBox::DIALOGBUTTON_CANCEL); if (label.empty()) { - if (buttons & DialogDelegate::DIALOGBUTTON_OK) { + if (buttons & MessageBox::DIALOGBUTTON_OK) { label = l10n_util::GetString(IDS_CANCEL); } else { label = l10n_util::GetString(IDS_CLOSE); } } bool is_default_button = - (dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_CANCEL) + (dd->GetDefaultDialogButton() & MessageBox::DIALOGBUTTON_CANCEL) != 0; cancel_button_ = new DialogButton(this, window(), - DialogDelegate::DIALOGBUTTON_CANCEL, + MessageBox::DIALOGBUTTON_CANCEL, label, is_default_button); cancel_button_->SetGroup(kButtonGroup); cancel_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); @@ -174,9 +174,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() & DialogDelegate::DIALOGBUTTON_OK) != 0) + if ((dd->GetDefaultDialogButton() & MessageBox::DIALOGBUTTON_OK) != 0) new_default_button = ok_button_; - if ((dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_CANCEL) + if ((dd->GetDefaultDialogButton() & MessageBox::DIALOGBUTTON_CANCEL) != 0) new_default_button = cancel_button_; } @@ -188,11 +188,11 @@ void DialogClientView::UpdateDialogButtons() { DialogDelegate* dd = GetDialogDelegate(); int buttons = dd->GetDialogButtons(); - if (buttons & DialogDelegate::DIALOGBUTTON_OK) - UpdateButtonHelper(ok_button_, dd, DialogDelegate::DIALOGBUTTON_OK); + if (buttons & MessageBox::DIALOGBUTTON_OK) + UpdateButtonHelper(ok_button_, dd, MessageBox::DIALOGBUTTON_OK); - if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL) - UpdateButtonHelper(cancel_button_, dd, DialogDelegate::DIALOGBUTTON_CANCEL); + if (buttons & MessageBox::DIALOGBUTTON_CANCEL) + UpdateButtonHelper(cancel_button_, dd, MessageBox::DIALOGBUTTON_CANCEL); LayoutDialogButtons(); SchedulePaint(); @@ -224,9 +224,9 @@ bool DialogClientView::CanClose() const { if (!accepted_) { DialogDelegate* dd = GetDialogDelegate(); int buttons = dd->GetDialogButtons(); - if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL) + if (buttons & MessageBox::DIALOGBUTTON_CANCEL) return dd->Cancel(); - if (buttons & DialogDelegate::DIALOGBUTTON_OK) + if (buttons & MessageBox::DIALOGBUTTON_OK) return dd->Accept(true); } return true; @@ -352,7 +352,7 @@ void DialogClientView::PaintSizeBox(ChromeCanvas* canvas) { int DialogClientView::GetButtonWidth(int button) const { DialogDelegate* dd = GetDialogDelegate(); std::wstring button_label = dd->GetDialogButtonLabel( - static_cast<DialogDelegate::DialogButton>(button)); + static_cast<MessageBox::DialogButton>(button)); int string_width = dialog_button_font_->GetStringWidth(button_label); return std::max(string_width + kDialogButtonLabelSpacing, kDialogMinButtonWidth); @@ -372,7 +372,7 @@ void DialogClientView::LayoutDialogButtons() { if (cancel_button_) { gfx::Size ps = cancel_button_->GetPreferredSize(); gfx::Rect lb = GetLocalBounds(false); - int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_CANCEL); + int button_width = GetButtonWidth(MessageBox::DIALOGBUTTON_CANCEL); int button_x = lb.right() - button_width - kButtonHEdgeMargin; int button_y = lb.bottom() - ps.height() - kButtonVEdgeMargin; cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); @@ -383,7 +383,7 @@ void DialogClientView::LayoutDialogButtons() { if (ok_button_) { gfx::Size ps = ok_button_->GetPreferredSize(); gfx::Rect lb = GetLocalBounds(false); - int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_OK); + int button_width = GetButtonWidth(MessageBox::DIALOGBUTTON_OK); int ok_button_right = lb.right() - kButtonHEdgeMargin; if (cancel_button_) ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; diff --git a/chrome/views/window/dialog_delegate.cc b/chrome/views/window/dialog_delegate.cc index 9778066..80d0e8b 100644 --- a/chrome/views/window/dialog_delegate.cc +++ b/chrome/views/window/dialog_delegate.cc @@ -13,18 +13,18 @@ namespace views { // Overridden from WindowDelegate: int DialogDelegate::GetDefaultDialogButton() const { - if (GetDialogButtons() & DIALOGBUTTON_OK) - return DIALOGBUTTON_OK; - if (GetDialogButtons() & DIALOGBUTTON_CANCEL) - return DIALOGBUTTON_CANCEL; - return DIALOGBUTTON_NONE; + if (GetDialogButtons() & MessageBox::DIALOGBUTTON_OK) + return MessageBox::DIALOGBUTTON_OK; + if (GetDialogButtons() & MessageBox::DIALOGBUTTON_CANCEL) + return MessageBox::DIALOGBUTTON_CANCEL; + return MessageBox::DIALOGBUTTON_NONE; } View* DialogDelegate::GetInitiallyFocusedView() { // Focus the default button if any. DialogClientView* dcv = GetDialogClientView(); int default_button = GetDefaultDialogButton(); - if (default_button == DIALOGBUTTON_NONE) + if (default_button == MessageBox::DIALOGBUTTON_NONE) return NULL; if ((default_button & GetDialogButtons()) == 0) { @@ -33,9 +33,9 @@ View* DialogDelegate::GetInitiallyFocusedView() { return NULL; } - if (default_button & DIALOGBUTTON_OK) + if (default_button & MessageBox::DIALOGBUTTON_OK) return dcv->ok_button(); - if (default_button & DIALOGBUTTON_CANCEL) + if (default_button & MessageBox::DIALOGBUTTON_CANCEL) return dcv->cancel_button(); return NULL; } diff --git a/chrome/views/window/dialog_delegate.h b/chrome/views/window/dialog_delegate.h index b8b2d1b..0705703 100644 --- a/chrome/views/window/dialog_delegate.h +++ b/chrome/views/window/dialog_delegate.h @@ -5,6 +5,7 @@ #ifndef CHROME_VIEWS_WINDOW_DIALOG_DELEGATE_H_ #define CHROME_VIEWS_WINDOW_DIALOG_DELEGATE_H_ +#include "chrome/common/message_box_flags.h" #include "chrome/views/window/dialog_client_view.h" #include "chrome/views/window/window_delegate.h" @@ -26,12 +27,6 @@ class DialogDelegate : public WindowDelegate { public: virtual DialogDelegate* AsDialogDelegate() { return this; } - enum DialogButton { - DIALOGBUTTON_NONE = 0, // No dialog buttons, for WindowType == WINDOW. - DIALOGBUTTON_OK = 1, // Has an OK button. - DIALOGBUTTON_CANCEL = 2, // Has a Cancel button (becomes a Close button if - }; // no OK button). - // Returns a mask specifying which of the available DialogButtons are visible // for the dialog. Note: If an OK button is provided, you should provide a // CANCEL button. A dialog box with just an OK button is frowned upon and @@ -40,18 +35,21 @@ class DialogDelegate : public WindowDelegate { // // To use the extra button you need to override GetDialogButtons() virtual int GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; + return MessageBox::DIALOGBUTTON_OK | MessageBox::DIALOGBUTTON_CANCEL; } // 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(DialogButton button) { return true; } + virtual bool AreAcceleratorsEnabled(MessageBox::DialogButton button) { + return true; + } // Returns the label of the specified DialogButton. - virtual std::wstring GetDialogButtonLabel(DialogButton button) const { - // empty string results in defaults for DIALOGBUTTON_OK, - // DIALOGBUTTON_CANCEL. + virtual std::wstring GetDialogButtonLabel( + MessageBox::DialogButton button) const { + // empty string results in defaults for MessageBox::DIALOGBUTTON_OK, + // MessageBox::DIALOGBUTTON_CANCEL. return L""; } @@ -60,20 +58,21 @@ class DialogDelegate : public WindowDelegate { // up to the buttons. virtual View* GetExtraView() { return NULL; } - // Returns the default dialog button. This should not be a mask as only one - // button should ever be the default button. Return DIALOGBUTTON_NONE if - // there is no default. Default behavior is to return DIALOGBUTTON_OK or - // DIALOGBUTTON_CANCEL (in that order) if they are present, DIALOGBUTTON_NONE - // otherwise. + // Returns the default dialog button. This should not be a mask as only + // one button should ever be the default button. Return + // MessageBox::DIALOGBUTTON_NONE if there is no default. Default behavior + // is to return MessageBox::DIALOGBUTTON_OK or + // MessageBox::DIALOGBUTTON_CANCEL (in that order) if they are present, + // MessageBox::DIALOGBUTTON_NONE otherwise. virtual int GetDefaultDialogButton() const; // Returns whether the specified dialog button is enabled. - virtual bool IsDialogButtonEnabled(DialogButton button) const { + virtual bool IsDialogButtonEnabled(MessageBox::DialogButton button) const { return true; } // Returns whether the specified dialog button is visible. - virtual bool IsDialogButtonVisible(DialogButton button) const { + virtual bool IsDialogButtonVisible(MessageBox::DialogButton button) const { return true; } |