summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 23:49:18 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 23:49:18 +0000
commit478ff2ed6a244658c0a30d6cbfff1a9046b9ba9d (patch)
treef995985b8749bd31da7cbb73ec73cfce24e97987 /chrome/views
parent69e38eca8034fe35c22744f59bee77f987ae8755 (diff)
downloadchromium_src-478ff2ed6a244658c0a30d6cbfff1a9046b9ba9d.zip
chromium_src-478ff2ed6a244658c0a30d6cbfff1a9046b9ba9d.tar.gz
chromium_src-478ff2ed6a244658c0a30d6cbfff1a9046b9ba9d.tar.bz2
Reland r14146 which refactors DialogButton into cross platform
code. This is the same as the last change except I renamed class MessageBox to class MessageBoxFlags to avoid conflicting with the same name in windows.h. Review URL: http://codereview.chromium.org/87065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14159 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/controls/message_box_view.cc4
-rw-r--r--chrome/views/view_unittest.cc6
-rw-r--r--chrome/views/window/dialog_client_view.cc50
-rw-r--r--chrome/views/window/dialog_delegate.cc16
-rw-r--r--chrome/views/window/dialog_delegate.h52
5 files changed, 64 insertions, 64 deletions
diff --git a/chrome/views/controls/message_box_view.cc b/chrome/views/controls/message_box_view.cc
index 7fc4a26..35bd80a 100644
--- a/chrome/views/controls/message_box_view.cc
+++ b/chrome/views/controls/message_box_view.cc
@@ -93,7 +93,7 @@ void MessageBoxView::ViewHierarchyChanged(bool is_add,
void MessageBoxView::Init(int dialog_flags,
const std::wstring& default_prompt) {
message_label_->SetMultiLine(true);
- if (dialog_flags & MessageBox::kAutoDetectAlignment) {
+ if (dialog_flags & MessageBoxFlags::kAutoDetectAlignment) {
// Determine the alignment and directionality based on the first character
// with strong directionality.
l10n_util::TextDirection direction =
@@ -112,7 +112,7 @@ void MessageBoxView::Init(int dialog_flags,
message_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
}
- if (dialog_flags & MessageBox::kFlagHasPromptField) {
+ if (dialog_flags & MessageBoxFlags::kFlagHasPromptField) {
prompt_field_ = new views::TextField;
prompt_field_->SetText(default_prompt);
}
diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc
index 9fbf481..010474a6 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 MessageBoxFlags::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..f7fbcad 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) {
+ MessageBoxFlags::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,
+ MessageBoxFlags::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 MessageBoxFlags::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 & MessageBoxFlags::DIALOGBUTTON_OK && !ok_button_) {
std::wstring label =
- dd->GetDialogButtonLabel(DialogDelegate::DIALOGBUTTON_OK);
+ dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_OK);
if (label.empty())
label = l10n_util::GetString(IDS_OK);
bool is_default_button =
- (dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_OK) != 0;
+ (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0;
ok_button_ = new DialogButton(this, window(),
- DialogDelegate::DIALOGBUTTON_OK, label,
+ MessageBoxFlags::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 & MessageBoxFlags::DIALOGBUTTON_CANCEL))
ok_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false));
AddChildView(ok_button_);
}
- if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL && !cancel_button_) {
+ if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) {
std::wstring label =
- dd->GetDialogButtonLabel(DialogDelegate::DIALOGBUTTON_CANCEL);
+ dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL);
if (label.empty()) {
- if (buttons & DialogDelegate::DIALOGBUTTON_OK) {
+ if (buttons & MessageBoxFlags::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() & MessageBoxFlags::DIALOGBUTTON_CANCEL)
!= 0;
cancel_button_ = new DialogButton(this, window(),
- DialogDelegate::DIALOGBUTTON_CANCEL,
+ MessageBoxFlags::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() & MessageBoxFlags::DIALOGBUTTON_OK) != 0)
new_default_button = ok_button_;
- if ((dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_CANCEL)
+ if ((dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL)
!= 0)
new_default_button = cancel_button_;
}
@@ -188,11 +188,13 @@ void DialogClientView::UpdateDialogButtons() {
DialogDelegate* dd = GetDialogDelegate();
int buttons = dd->GetDialogButtons();
- if (buttons & DialogDelegate::DIALOGBUTTON_OK)
- UpdateButtonHelper(ok_button_, dd, DialogDelegate::DIALOGBUTTON_OK);
+ if (buttons & MessageBoxFlags::DIALOGBUTTON_OK)
+ UpdateButtonHelper(ok_button_, dd, MessageBoxFlags::DIALOGBUTTON_OK);
- if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL)
- UpdateButtonHelper(cancel_button_, dd, DialogDelegate::DIALOGBUTTON_CANCEL);
+ if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL) {
+ UpdateButtonHelper(cancel_button_, dd,
+ MessageBoxFlags::DIALOGBUTTON_CANCEL);
+ }
LayoutDialogButtons();
SchedulePaint();
@@ -224,9 +226,9 @@ bool DialogClientView::CanClose() const {
if (!accepted_) {
DialogDelegate* dd = GetDialogDelegate();
int buttons = dd->GetDialogButtons();
- if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL)
+ if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)
return dd->Cancel();
- if (buttons & DialogDelegate::DIALOGBUTTON_OK)
+ if (buttons & MessageBoxFlags::DIALOGBUTTON_OK)
return dd->Accept(true);
}
return true;
@@ -352,7 +354,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<MessageBoxFlags::DialogButton>(button));
int string_width = dialog_button_font_->GetStringWidth(button_label);
return std::max(string_width + kDialogButtonLabelSpacing,
kDialogMinButtonWidth);
@@ -372,7 +374,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(MessageBoxFlags::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 +385,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(MessageBoxFlags::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..bc4f1fd8 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() & MessageBoxFlags::DIALOGBUTTON_OK)
+ return MessageBoxFlags::DIALOGBUTTON_OK;
+ if (GetDialogButtons() & MessageBoxFlags::DIALOGBUTTON_CANCEL)
+ return MessageBoxFlags::DIALOGBUTTON_CANCEL;
+ return MessageBoxFlags::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 == MessageBoxFlags::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 & MessageBoxFlags::DIALOGBUTTON_OK)
return dcv->ok_button();
- if (default_button & DIALOGBUTTON_CANCEL)
+ if (default_button & MessageBoxFlags::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..8add450 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,22 @@ class DialogDelegate : public WindowDelegate {
//
// To use the extra button you need to override GetDialogButtons()
virtual int GetDialogButtons() const {
- return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL;
+ return MessageBoxFlags::DIALOGBUTTON_OK |
+ MessageBoxFlags::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(MessageBoxFlags::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(
+ MessageBoxFlags::DialogButton button) const {
+ // empty string results in defaults for MessageBoxFlags::DIALOGBUTTON_OK,
+ // MessageBoxFlags::DIALOGBUTTON_CANCEL.
return L"";
}
@@ -60,20 +59,23 @@ 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
+ // MessageBoxFlags::DIALOGBUTTON_NONE if there is no default. Default
+ // behavior is to return MessageBoxFlags::DIALOGBUTTON_OK or
+ // MessageBoxFlags::DIALOGBUTTON_CANCEL (in that order) if they are
+ // present, MessageBoxFlags::DIALOGBUTTON_NONE otherwise.
virtual int GetDefaultDialogButton() const;
// Returns whether the specified dialog button is enabled.
- virtual bool IsDialogButtonEnabled(DialogButton button) const {
+ virtual bool IsDialogButtonEnabled(
+ MessageBoxFlags::DialogButton button) const {
return true;
}
// Returns whether the specified dialog button is visible.
- virtual bool IsDialogButtonVisible(DialogButton button) const {
+ virtual bool IsDialogButtonVisible(
+ MessageBoxFlags::DialogButton button) const {
return true;
}
@@ -85,13 +87,13 @@ class DialogDelegate : public WindowDelegate {
virtual bool Cancel() { return true; }
// For Dialog boxes, this is called when the user presses the "OK" button,
- // or the Enter key. Can also be called on Esc key or close button presses if
- // there is no "Cancel" button. This function should return true if the window
- // can be closed after the window can be closed after it returns, or false if
- // it must remain open. If |window_closing| is true, it means that this
- // handler is being called because the window is being closed (e.g. by
- // Window::Close) and there is no Cancel handler, so Accept is being called
- // instead.
+ // or the Enter key. Can also be called on Esc key or close button
+ // presses if there is no "Cancel" button. This function should return
+ // true if the window can be closed after the window can be closed after
+ // it returns, or false if it must remain open. If |window_closing| is
+ // true, it means that this handler is being called because the window is
+ // being closed (e.g. by Window::Close) and there is no Cancel handler,
+ // so Accept is being called instead.
virtual bool Accept(bool window_closing) { return Accept(); }
virtual bool Accept() { return true; }