diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 23:49:18 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 23:49:18 +0000 |
commit | 478ff2ed6a244658c0a30d6cbfff1a9046b9ba9d (patch) | |
tree | f995985b8749bd31da7cbb73ec73cfce24e97987 | |
parent | 69e38eca8034fe35c22744f59bee77f987ae8755 (diff) | |
download | chromium_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
68 files changed, 287 insertions, 297 deletions
diff --git a/chrome/browser/app_modal_dialog_gtk.cc b/chrome/browser/app_modal_dialog_gtk.cc index 1108762..f0c50c61 100644 --- a/chrome/browser/app_modal_dialog_gtk.cc +++ b/chrome/browser/app_modal_dialog_gtk.cc @@ -46,12 +46,12 @@ void AppModalDialog::CreateAndShowDialog() { GtkButtonsType buttons = GTK_BUTTONS_NONE; GtkMessageType message_type = GTK_MESSAGE_OTHER; switch (dialog_flags_) { - case MessageBox::kIsJavascriptAlert: + case MessageBoxFlags::kIsJavascriptAlert: buttons = GTK_BUTTONS_OK; message_type = GTK_MESSAGE_WARNING; break; - case MessageBox::kIsJavascriptConfirm: + case MessageBoxFlags::kIsJavascriptConfirm: if (is_before_unload_dialog_) { // onbeforeunload also uses a confirm prompt, it just has custom // buttons. We add the buttons using gtk_dialog_add_button below. @@ -62,7 +62,7 @@ void AppModalDialog::CreateAndShowDialog() { message_type = GTK_MESSAGE_QUESTION; break; - case MessageBox::kIsJavascriptPrompt: + case MessageBoxFlags::kIsJavascriptPrompt: // We need to make a custom message box for javascript prompts. For now // just have an OK button and send back an empty string. Maybe we can // cram a GtkEntry into the content area of the message box via diff --git a/chrome/browser/app_modal_dialog_mac.mm b/chrome/browser/app_modal_dialog_mac.mm index f72a5ee..77823824 100644 --- a/chrome/browser/app_modal_dialog_mac.mm +++ b/chrome/browser/app_modal_dialog_mac.mm @@ -49,10 +49,10 @@ void AppModalDialog::CreateAndShowDialog() { NSString* default_button = NSLocalizedString(@"OK", nil); NSString* other_button = NSLocalizedString(@"Cancel", nil); switch (dialog_flags_) { - case MessageBox::kIsJavascriptAlert: + case MessageBoxFlags::kIsJavascriptAlert: // OK & Cancel are fine for these types of alerts. break; - case MessageBox::kIsJavascriptConfirm: + case MessageBoxFlags::kIsJavascriptConfirm: if (is_before_unload_dialog_) { std::string button_text = l10n_util::GetStringUTF8( IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL); @@ -62,7 +62,7 @@ void AppModalDialog::CreateAndShowDialog() { other_button = base::SysUTF8ToNSString(button_text); } break; - case MessageBox::kIsJavascriptPrompt: + case MessageBoxFlags::kIsJavascriptPrompt: // We need to make a custom message box for javascript prompts. Not // sure how to handle this... NOTIMPLEMENTED(); diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 8383feb..1a5fd90 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -28,6 +28,7 @@ #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/message_box_flags.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/platform_util.h" #include "chrome/common/pref_service.h" @@ -46,7 +47,6 @@ #include "chrome/browser/printing/print_job.h" #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/browser/views/location_bar_view.h" -#include "chrome/views/window/dialog_delegate.h" #include "chrome/views/window/window.h" #endif // defined(OS_WIN) @@ -1297,9 +1297,6 @@ void AutomationProvider::GetBrowserWindowCount(int* window_count) { *window_count = static_cast<int>(BrowserList::size()); } -#if defined(OS_WIN) -// TODO(port): Move the views::DialogDelegate::DialogButton enum out into a -// common place then remove the OS_WIN guard. void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, int* dialog_button) { AppModalDialog* dialog_delegate = AppModalDialogQueue::active_dialog(); @@ -1307,7 +1304,7 @@ void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, if (*showing_dialog) *dialog_button = dialog_delegate->GetDialogButtons(); else - *dialog_button = views::DialogDelegate::DIALOGBUTTON_NONE; + *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; } void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { @@ -1316,20 +1313,19 @@ void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { AppModalDialog* dialog_delegate = AppModalDialogQueue::active_dialog(); if (dialog_delegate && (dialog_delegate->GetDialogButtons() & button) == button) { - if ((button & views::DialogDelegate::DIALOGBUTTON_OK) == - views::DialogDelegate::DIALOGBUTTON_OK) { + if ((button & MessageBoxFlags::DIALOGBUTTON_OK) == + MessageBoxFlags::DIALOGBUTTON_OK) { dialog_delegate->AcceptWindow(); *success = true; } - if ((button & views::DialogDelegate::DIALOGBUTTON_CANCEL) == - views::DialogDelegate::DIALOGBUTTON_CANCEL) { + if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) == + MessageBoxFlags::DIALOGBUTTON_CANCEL) { DCHECK(!*success) << "invalid param, OK and CANCEL specified"; dialog_delegate->CancelWindow(); *success = true; } } } -#endif void AutomationProvider::GetBrowserWindow(int index, int* handle) { *handle = 0; diff --git a/chrome/browser/download/download_request_dialog_delegate_win.cc b/chrome/browser/download/download_request_dialog_delegate_win.cc index 3f359ca..bc68b990 100644 --- a/chrome/browser/download/download_request_dialog_delegate_win.cc +++ b/chrome/browser/download/download_request_dialog_delegate_win.cc @@ -23,7 +23,7 @@ DownloadRequestDialogDelegateWin::DownloadRequestDialogDelegateWin( DownloadRequestManager::TabDownloadState* host) : DownloadRequestDialogDelegate(host) { message_view_ = new MessageBoxView( - MessageBox::kIsConfirmMessageBox, + MessageBoxFlags::kIsConfirmMessageBox, l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING), std::wstring()); window_ = tab->CreateConstrainedDialog(this, message_view_); @@ -46,10 +46,10 @@ views::View* DownloadRequestDialogDelegateWin::GetContentsView() { } std::wstring DownloadRequestDialogDelegateWin::GetDialogButtonLabel( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING_ALLOW); - if (button == DIALOGBUTTON_CANCEL) + if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) return l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING_DENY); return std::wstring(); } diff --git a/chrome/browser/download/download_request_dialog_delegate_win.h b/chrome/browser/download/download_request_dialog_delegate_win.h index 7e5f83f..f0167e6 100644 --- a/chrome/browser/download/download_request_dialog_delegate_win.h +++ b/chrome/browser/download/download_request_dialog_delegate_win.h @@ -32,9 +32,10 @@ class DownloadRequestDialogDelegateWin : public DownloadRequestDialogDelegate, virtual bool Cancel(); virtual bool Accept(); virtual views::View* GetContentsView(); - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual int GetDefaultDialogButton() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } virtual void DeleteDelegate(); diff --git a/chrome/browser/download/download_uitest.cc b/chrome/browser/download/download_uitest.cc index debf209..5310252 100644 --- a/chrome/browser/download/download_uitest.cc +++ b/chrome/browser/download/download_uitest.cc @@ -5,6 +5,11 @@ #include <sstream> #include <string> +#include "build/build_config.h" +#if defined(OS_WIN) +#include <shlwapi.h> +#endif + #include "base/command_line.h" #include "base/file_util.h" #include "base/path_service.h" diff --git a/chrome/browser/jsmessage_box_handler.cc b/chrome/browser/jsmessage_box_handler.cc index 6c43fbf..e0e2637 100644 --- a/chrome/browser/jsmessage_box_handler.cc +++ b/chrome/browser/jsmessage_box_handler.cc @@ -31,7 +31,7 @@ std::wstring MakeTextSafe(const std::wstring& text) { std::wstring GetWindowTitle(WebContents* web_contents, const GURL& frame_url, int dialog_flags) { - bool is_alert = (dialog_flags == MessageBox::kIsJavascriptAlert); + bool is_alert = (dialog_flags == MessageBoxFlags::kIsJavascriptAlert); if (!frame_url.has_host()) return l10n_util::GetString( is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE @@ -81,6 +81,6 @@ void RunBeforeUnloadDialog(WebContents* web_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); AppModalDialogQueue::AddDialog(new AppModalDialog( web_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), - MessageBox::kIsJavascriptConfirm, MakeTextSafe(message_text), + MessageBoxFlags::kIsJavascriptConfirm, MakeTextSafe(message_text), std::wstring(), false, true, reply_msg)); } diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc index c7b30c9..fcf9696 100644 --- a/chrome/browser/login_prompt.cc +++ b/chrome/browser/login_prompt.cc @@ -128,8 +128,9 @@ class LoginHandlerImpl : public LoginHandler, } // views::DialogDelegate methods: - virtual std::wstring GetDialogButtonLabel(DialogButton button) const { - if (button == DIALOGBUTTON_OK) + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); return DialogDelegate::GetDialogButtonLabel(button); } diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index c0f189b..c11b79c 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -1079,7 +1079,7 @@ std::wstring TaskManager::GetWindowName() const { } int TaskManager::GetDialogButtons() const { - return DIALOGBUTTON_NONE; + return MessageBoxFlags::DIALOGBUTTON_NONE; } void TaskManager::WindowClosing() { diff --git a/chrome/browser/unload_uitest.cc b/chrome/browser/unload_uitest.cc index a0e5a24..fe394c4 100644 --- a/chrome/browser/unload_uitest.cc +++ b/chrome/browser/unload_uitest.cc @@ -136,9 +136,9 @@ class UnloadTest : public UITest { EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); } - void ClickModalDialogButton(views::DialogDelegate::DialogButton button) { + void ClickModalDialogButton(MessageBoxFlags::DialogButton button) { bool modal_dialog_showing = false; - views::DialogDelegate::DialogButton available_buttons; + MessageBoxFlags::DialogButton available_buttons; EXPECT_TRUE(automation()->WaitForAppModalDialog(3000)); EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &available_buttons)); @@ -221,7 +221,7 @@ TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); CloseBrowserAsync(browser.get()); - ClickModalDialogButton(views::DialogDelegate::DIALOGBUTTON_OK); + ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); WaitForBrowserClosed(); EXPECT_FALSE(IsBrowserRunning()); } @@ -233,12 +233,12 @@ TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); CloseBrowserAsync(browser.get()); - ClickModalDialogButton(views::DialogDelegate::DIALOGBUTTON_CANCEL); + ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_CANCEL); WaitForBrowserClosed(); EXPECT_TRUE(IsBrowserRunning()); CloseBrowserAsync(browser.get()); - ClickModalDialogButton(views::DialogDelegate::DIALOGBUTTON_OK); + ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); WaitForBrowserClosed(); EXPECT_FALSE(IsBrowserRunning()); } diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc index df605ab..131d9e0 100644 --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -603,15 +603,11 @@ void AboutChromeView::ViewHierarchyChanged(bool is_add, //////////////////////////////////////////////////////////////////////////////// // AboutChromeView, views::DialogDelegate implementation: -int AboutChromeView::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; -} - std::wstring AboutChromeView::GetDialogButtonLabel( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) { + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return l10n_util::GetString(IDS_ABOUT_CHROME_UPDATE_CHECK); - } else if (button == DIALOGBUTTON_CANCEL) { + } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) { // The OK button (which is the default button) has been re-purposed to be // 'Check for Updates' so we want the Cancel button should have the label // OK but act like a Cancel button in all other ways. @@ -622,16 +618,22 @@ std::wstring AboutChromeView::GetDialogButtonLabel( return L""; } -bool AboutChromeView::IsDialogButtonEnabled(DialogButton button) const { - if (button == DIALOGBUTTON_OK && check_button_status_ != CHECKBUTTON_ENABLED) +bool AboutChromeView::IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK && + check_button_status_ != CHECKBUTTON_ENABLED) { return false; + } return true; } -bool AboutChromeView::IsDialogButtonVisible(DialogButton button) const { - if (button == DIALOGBUTTON_OK && check_button_status_ == CHECKBUTTON_HIDDEN) +bool AboutChromeView::IsDialogButtonVisible( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK && + check_button_status_ == CHECKBUTTON_HIDDEN) { return false; + } return true; } diff --git a/chrome/browser/views/about_chrome_view.h b/chrome/browser/views/about_chrome_view.h index 2118e76..d4cc3fd 100644 --- a/chrome/browser/views/about_chrome_view.h +++ b/chrome/browser/views/about_chrome_view.h @@ -47,10 +47,12 @@ class AboutChromeView : public views::View, views::View* child); // Overridden from views::DialogDelegate: - virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; - virtual bool IsDialogButtonEnabled(DialogButton button) const; - virtual bool IsDialogButtonVisible(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; + virtual bool IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const; + virtual bool IsDialogButtonVisible( + MessageBoxFlags::DialogButton button) const; virtual bool CanResize() const; virtual bool CanMaximize() const; virtual bool IsAlwaysOnTop() const; diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index b5a2f6d..eb00198 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -80,8 +80,9 @@ void BookmarkEditorView::Show(HWND parent_hwnd, editor->Show(parent_hwnd); } -bool BookmarkEditorView::IsDialogButtonEnabled(DialogButton button) const { - if (button == DIALOGBUTTON_OK) { +bool BookmarkEditorView::IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { const GURL url(GetInputURL()); return bb_model_->IsLoaded() && url.is_valid(); } @@ -96,7 +97,7 @@ std::wstring BookmarkEditorView::GetWindowTitle() const { } bool BookmarkEditorView::Accept() { - if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) { + if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { // The url is invalid, focus the url field. url_tf_.SelectAll(); url_tf_.RequestFocus(); @@ -107,7 +108,8 @@ bool BookmarkEditorView::Accept() { return true; } -bool BookmarkEditorView::AreAcceleratorsEnabled(DialogButton button) { +bool BookmarkEditorView::AreAcceleratorsEnabled( + MessageBoxFlags::DialogButton button) { return !show_tree_ || !tree_view_->GetEditingNode(); } diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h index a307277..6b472d2 100644 --- a/chrome/browser/views/bookmark_editor_view.h +++ b/chrome/browser/views/bookmark_editor_view.h @@ -86,11 +86,12 @@ class BookmarkEditorView : public views::View, Handler* handler); // DialogDelegate methods: - virtual bool IsDialogButtonEnabled(DialogButton button) const; + virtual bool IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const; virtual bool IsModal() const; virtual std::wstring GetWindowTitle() const; virtual bool Accept(); - virtual bool AreAcceleratorsEnabled(DialogButton button); + virtual bool AreAcceleratorsEnabled(MessageBoxFlags::DialogButton button); virtual views::View* GetContentsView(); // View methods. diff --git a/chrome/browser/views/bug_report_view.cc b/chrome/browser/views/bug_report_view.cc index 647dfc1..33dd6d7 100644 --- a/chrome/browser/views/bug_report_view.cc +++ b/chrome/browser/views/bug_report_view.cc @@ -266,8 +266,9 @@ bool BugReportView::HandleKeystroke(views::TextField* sender, return false; } -std::wstring BugReportView::GetDialogButtonLabel(DialogButton button) const { - if (button == DIALOGBUTTON_OK) { +std::wstring BugReportView::GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { if (problem_type_ == BugReportComboBoxModel::PHISHING_PAGE) return l10n_util::GetString(IDS_BUGREPORT_SEND_PHISHING_REPORT); else @@ -278,7 +279,7 @@ std::wstring BugReportView::GetDialogButtonLabel(DialogButton button) const { } int BugReportView::GetDefaultDialogButton() const { - return DIALOGBUTTON_NONE; + return MessageBoxFlags::DIALOGBUTTON_NONE; } bool BugReportView::CanResize() const { @@ -306,7 +307,7 @@ std::wstring BugReportView::GetWindowTitle() const { } bool BugReportView::Accept() { - if (IsDialogButtonEnabled(DIALOGBUTTON_OK)) { + if (IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { if (problem_type_ == BugReportComboBoxModel::PHISHING_PAGE) ReportPhishing(); else diff --git a/chrome/browser/views/bug_report_view.h b/chrome/browser/views/bug_report_view.h index 22a2c42..d17e569 100644 --- a/chrome/browser/views/bug_report_view.h +++ b/chrome/browser/views/bug_report_view.h @@ -61,7 +61,8 @@ class BugReportView : public views::View, int new_index); // Overridden from views::DialogDelegate: - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual int GetDefaultDialogButton() const; virtual bool CanResize() const; virtual bool CanMaximize() const; diff --git a/chrome/browser/views/clear_browsing_data.cc b/chrome/browser/views/clear_browsing_data.cc index 5a0df99..0b00f6a 100644 --- a/chrome/browser/views/clear_browsing_data.cc +++ b/chrome/browser/views/clear_browsing_data.cc @@ -236,21 +236,22 @@ void ClearBrowsingDataView::ViewHierarchyChanged(bool is_add, // ClearBrowsingDataView, views::DialogDelegate implementation: std::wstring ClearBrowsingDataView::GetDialogButtonLabel( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) { + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return l10n_util::GetString(IDS_CLEAR_BROWSING_DATA_COMMIT); - } else if (button == DIALOGBUTTON_CANCEL) { + } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) { return l10n_util::GetString(IDS_CLOSE); } else { return std::wstring(); } } -bool ClearBrowsingDataView::IsDialogButtonEnabled(DialogButton button) const { +bool ClearBrowsingDataView::IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const { if (delete_in_progress_) return false; - if (button == DIALOGBUTTON_OK) { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return del_history_checkbox_->checked() || del_downloads_checkbox_->checked() || del_cache_checkbox_->checked() || @@ -287,7 +288,7 @@ std::wstring ClearBrowsingDataView::GetWindowTitle() const { } bool ClearBrowsingDataView::Accept() { - if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) { + if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { return false; } diff --git a/chrome/browser/views/clear_browsing_data.h b/chrome/browser/views/clear_browsing_data.h index 18912fc..de4ea31 100644 --- a/chrome/browser/views/clear_browsing_data.h +++ b/chrome/browser/views/clear_browsing_data.h @@ -50,8 +50,9 @@ class ClearBrowsingDataView : public views::View, views::View* child); // Overridden from views::DialogDelegate: - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; - virtual bool IsDialogButtonEnabled(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; + virtual bool IsDialogButtonEnabled(MessageBoxFlags::DialogButton button) const; virtual bool CanResize() const; virtual bool CanMaximize() const; virtual bool IsAlwaysOnTop() const; diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_keyword_controller.cc index 1463777d..8173849 100644 --- a/chrome/browser/views/edit_keyword_controller.cc +++ b/chrome/browser/views/edit_keyword_controller.cc @@ -77,12 +77,9 @@ std::wstring EditKeywordController::GetWindowTitle() const { IDS_SEARCH_ENGINES_EDITOR_NEW_WINDOW_TITLE); } -int EditKeywordController::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; -} - -bool EditKeywordController::IsDialogButtonEnabled(DialogButton button) const { - if (button == DIALOGBUTTON_OK) { +bool EditKeywordController::IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return (IsKeywordValid() && !title_tf_->GetText().empty() && IsURLValid()); } return true; diff --git a/chrome/browser/views/edit_keyword_controller.h b/chrome/browser/views/edit_keyword_controller.h index 00a76fe..e9a8f36 100644 --- a/chrome/browser/views/edit_keyword_controller.h +++ b/chrome/browser/views/edit_keyword_controller.h @@ -44,8 +44,8 @@ class EditKeywordController : public views::TextField::Controller, // DialogDelegate overrides. virtual bool IsModal() const; virtual std::wstring GetWindowTitle() const; - virtual int GetDialogButtons() const; - virtual bool IsDialogButtonEnabled(DialogButton button) const; + virtual bool IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const; virtual void DeleteDelegate(); virtual bool Cancel(); virtual bool Accept(); diff --git a/chrome/browser/views/external_protocol_dialog.cc b/chrome/browser/views/external_protocol_dialog.cc index 50cdce3..2852b60 100644 --- a/chrome/browser/views/external_protocol_dialog.cc +++ b/chrome/browser/views/external_protocol_dialog.cc @@ -43,17 +43,13 @@ ExternalProtocolDialog::~ExternalProtocolDialog() { ////////////////////////////////////////////////////////////////////////////// // ExternalProtocolDialog, views::DialogDelegate implementation: -int ExternalProtocolDialog::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; -} - int ExternalProtocolDialog::GetDefaultDialogButton() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } std::wstring ExternalProtocolDialog::GetDialogButtonLabel( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT); // Set the button to have a default name. @@ -104,7 +100,7 @@ ExternalProtocolDialog::ExternalProtocolDialog(TabContents* tab_contents, message_text += l10n_util::GetString(IDS_EXTERNAL_PROTOCOL_WARNING); - message_box_view_ = new MessageBoxView(MessageBox::kIsConfirmMessageBox, + message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox, message_text, L"", kMessageWidth); diff --git a/chrome/browser/views/external_protocol_dialog.h b/chrome/browser/views/external_protocol_dialog.h index 3936556..7392cbb 100644 --- a/chrome/browser/views/external_protocol_dialog.h +++ b/chrome/browser/views/external_protocol_dialog.h @@ -35,9 +35,9 @@ class ExternalProtocolDialog : public views::DialogDelegate { virtual ~ExternalProtocolDialog(); // views::DialogDelegate Methods: - virtual int GetDialogButtons() const; virtual int GetDefaultDialogButton() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual std::wstring GetWindowTitle() const; virtual void DeleteDelegate(); virtual bool Accept(); diff --git a/chrome/browser/views/first_run_customize_view.cc b/chrome/browser/views/first_run_customize_view.cc index 1d0b469..a4dbe5d 100644 --- a/chrome/browser/views/first_run_customize_view.cc +++ b/chrome/browser/views/first_run_customize_view.cc @@ -178,7 +178,7 @@ views::View* FirstRunCustomizeView::GetContentsView() { } bool FirstRunCustomizeView::Accept() { - if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) + if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) return false; DisableButtons(); diff --git a/chrome/browser/views/first_run_view.cc b/chrome/browser/views/first_run_view.cc index 24f5e11..0c94020 100644 --- a/chrome/browser/views/first_run_view.cc +++ b/chrome/browser/views/first_run_view.cc @@ -171,7 +171,7 @@ views::View* FirstRunView::GetContentsView() { } bool FirstRunView::Accept() { - if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) + if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) return false; DisableButtons(); diff --git a/chrome/browser/views/first_run_view_base.cc b/chrome/browser/views/first_run_view_base.cc index c3df0e2..08f30d3 100644 --- a/chrome/browser/views/first_run_view_base.cc +++ b/chrome/browser/views/first_run_view_base.cc @@ -151,8 +151,9 @@ bool FirstRunViewBase::HasAlwaysOnTopMenu() const { return false; } -std::wstring FirstRunViewBase::GetDialogButtonLabel(DialogButton button) const { - if (DIALOGBUTTON_OK == button) +std::wstring FirstRunViewBase::GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (MessageBoxFlags::DIALOGBUTTON_OK == button) return l10n_util::GetString(IDS_FIRSTRUN_DLG_OK); // The other buttons get the default text. return std::wstring(); diff --git a/chrome/browser/views/first_run_view_base.h b/chrome/browser/views/first_run_view_base.h index d4a08f7..365f6dd 100644 --- a/chrome/browser/views/first_run_view_base.h +++ b/chrome/browser/views/first_run_view_base.h @@ -39,7 +39,7 @@ class FirstRunViewBase : public views::View, virtual bool HasAlwaysOnTopMenu() const; // Overridden from views::DialogDelegate. - std::wstring GetDialogButtonLabel(DialogButton button) const; + std::wstring GetDialogButtonLabel(MessageBoxFlags::DialogButton button) const; protected: // Returns the items that the first run process is required to import diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 6cee57d..8652d7f 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -221,14 +221,15 @@ class DownloadInProgressConfirmDialogDelegate : public views::DialogDelegate, // DialogDelegate implementation: virtual int GetDefaultDialogButton() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } - virtual std::wstring GetDialogButtonLabel(DialogButton button) const { - if (button == DIALOGBUTTON_OK) + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); - DCHECK_EQ(DIALOGBUTTON_CANCEL, button); + DCHECK_EQ(MessageBoxFlags::DIALOGBUTTON_CANCEL, button); return l10n_util::GetString( IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); } diff --git a/chrome/browser/views/hung_renderer_view.cc b/chrome/browser/views/hung_renderer_view.cc index 9d239e4..9b7b8ec8 100644 --- a/chrome/browser/views/hung_renderer_view.cc +++ b/chrome/browser/views/hung_renderer_view.cc @@ -126,7 +126,7 @@ class HungRendererWarningView : public views::View, virtual void WindowClosing(); virtual int GetDialogButtons() const; virtual std::wstring GetDialogButtonLabel( - views::DialogDelegate::DialogButton button) const; + MessageBoxFlags::DialogButton button) const; virtual views::View* GetExtraView(); virtual bool Accept(bool window_closing); virtual views::View* GetContentsView(); @@ -272,12 +272,12 @@ int HungRendererWarningView::GetDialogButtons() const { // the OK button to wait for responsiveness (and close the dialog) and our // additional button (which we create) to kill the process (which will result // in the dialog being destroyed). - return DIALOGBUTTON_OK; + return MessageBoxFlags::DIALOGBUTTON_OK; } std::wstring HungRendererWarningView::GetDialogButtonLabel( - views::DialogDelegate::DialogButton button) const { - if (button == DIALOGBUTTON_OK) + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT); return std::wstring(); } diff --git a/chrome/browser/views/importer_lock_view.cc b/chrome/browser/views/importer_lock_view.cc index 7c6b809..06aef04 100644 --- a/chrome/browser/views/importer_lock_view.cc +++ b/chrome/browser/views/importer_lock_view.cc @@ -46,10 +46,10 @@ void ImporterLockView::Layout() { } std::wstring ImporterLockView::GetDialogButtonLabel( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) { + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return l10n_util::GetString(IDS_IMPORTER_LOCK_OK); - } else if (button == DIALOGBUTTON_CANCEL) { + } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) { return l10n_util::GetString(IDS_IMPORTER_LOCK_CANCEL); } return std::wstring(); diff --git a/chrome/browser/views/importer_lock_view.h b/chrome/browser/views/importer_lock_view.h index e513bd4..7b17e78 100644 --- a/chrome/browser/views/importer_lock_view.h +++ b/chrome/browser/views/importer_lock_view.h @@ -28,7 +28,8 @@ class ImporterLockView : public views::View, virtual void Layout(); // Overridden from views::DialogDelegate: - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual bool IsModal() const; virtual std::wstring GetWindowTitle() const; virtual bool Accept(); diff --git a/chrome/browser/views/importer_view.cc b/chrome/browser/views/importer_view.cc index c3dbbf0..f3a2d11 100644 --- a/chrome/browser/views/importer_view.cc +++ b/chrome/browser/views/importer_view.cc @@ -99,8 +99,8 @@ void ImporterView::Layout() { } std::wstring ImporterView::GetDialogButtonLabel( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) { + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return l10n_util::GetString(IDS_IMPORT_COMMIT); } else { return std::wstring(); @@ -116,7 +116,7 @@ std::wstring ImporterView::GetWindowTitle() const { } bool ImporterView::Accept() { - if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) { + if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { return false; } diff --git a/chrome/browser/views/importer_view.h b/chrome/browser/views/importer_view.h index 9c6e7a8..903764f 100644 --- a/chrome/browser/views/importer_view.h +++ b/chrome/browser/views/importer_view.h @@ -37,7 +37,8 @@ class ImporterView : public views::View, virtual void Layout(); // Overridden from views::DialogDelegate: - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual bool IsModal() const; virtual std::wstring GetWindowTitle() const; virtual bool Accept(); diff --git a/chrome/browser/views/importing_progress_view.cc b/chrome/browser/views/importing_progress_view.cc index d7dcf81..cac8043 100644 --- a/chrome/browser/views/importing_progress_view.cc +++ b/chrome/browser/views/importing_progress_view.cc @@ -182,12 +182,12 @@ void ImportingProgressView::ViewHierarchyChanged(bool is_add, // ImportingProgressView, views::DialogDelegate implementation: int ImportingProgressView::GetDialogButtons() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } std::wstring ImportingProgressView::GetDialogButtonLabel( - DialogButton button) const { - DCHECK(button == DIALOGBUTTON_CANCEL); + MessageBoxFlags::DialogButton button) const { + DCHECK(button == MessageBoxFlags::DIALOGBUTTON_CANCEL); return l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_CANCEL); } diff --git a/chrome/browser/views/importing_progress_view.h b/chrome/browser/views/importing_progress_view.h index 3ff77a5..3de6cfc 100644 --- a/chrome/browser/views/importing_progress_view.h +++ b/chrome/browser/views/importing_progress_view.h @@ -39,7 +39,8 @@ class ImportingProgressView : public views::View, // Overridden from views::DialogDelegate: virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual bool IsModal() const; virtual std::wstring GetWindowTitle() const; virtual bool Cancel(); diff --git a/chrome/browser/views/input_window.cc b/chrome/browser/views/input_window.cc index 8d8c24f..2bc2363 100644 --- a/chrome/browser/views/input_window.cc +++ b/chrome/browser/views/input_window.cc @@ -33,7 +33,8 @@ class ContentView : public views::View, } // views::DialogDelegate overrides: - virtual bool IsDialogButtonEnabled(DialogButton button) const; + virtual bool IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const; virtual bool Accept(); virtual bool Cancel(); virtual void WindowClosing(); @@ -77,9 +78,12 @@ class ContentView : public views::View, /////////////////////////////////////////////////////////////////////////////// // ContentView, views::DialogDelegate implementation: -bool ContentView::IsDialogButtonEnabled(DialogButton button) const { - if (button == DIALOGBUTTON_OK && !delegate_->IsValid(text_field_->GetText())) +bool ContentView::IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK && + !delegate_->IsValid(text_field_->GetText())) { return false; + } return true; } diff --git a/chrome/browser/views/jsmessage_box_dialog.cc b/chrome/browser/views/jsmessage_box_dialog.cc index bd0c7f2..b42c2d4 100644 --- a/chrome/browser/views/jsmessage_box_dialog.cc +++ b/chrome/browser/views/jsmessage_box_dialog.cc @@ -20,7 +20,7 @@ JavascriptMessageBoxDialog::JavascriptMessageBoxDialog( : parent_(parent), dialog_(NULL), message_box_view_(new MessageBoxView( - parent->dialog_flags() | MessageBox::kAutoDetectAlignment, + parent->dialog_flags() | MessageBoxFlags::kAutoDetectAlignment, message_text, default_prompt_text)) { DCHECK(message_box_view_); @@ -59,11 +59,11 @@ void JavascriptMessageBoxDialog::CloseModalDialog() { int JavascriptMessageBoxDialog::GetDialogButtons() const { int dialog_buttons = 0; - if (parent_->dialog_flags() & MessageBox::kFlagHasOKButton) - dialog_buttons = DIALOGBUTTON_OK; + if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasOKButton) + dialog_buttons = MessageBoxFlags::DIALOGBUTTON_OK; - if (parent_->dialog_flags() & MessageBox::kFlagHasCancelButton) - dialog_buttons |= DIALOGBUTTON_CANCEL; + if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasCancelButton) + dialog_buttons |= MessageBoxFlags::DIALOGBUTTON_CANCEL; return dialog_buttons; } @@ -96,11 +96,11 @@ bool JavascriptMessageBoxDialog::Accept() { } std::wstring JavascriptMessageBoxDialog::GetDialogButtonLabel( - DialogButton button) const { + MessageBoxFlags::DialogButton button) const { if (parent_->is_before_unload_dialog()) { - if (button == DialogDelegate::DIALOGBUTTON_OK) { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { return l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL); - } else if (button == DialogDelegate::DIALOGBUTTON_CANCEL) { + } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) { return l10n_util::GetString( IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); } diff --git a/chrome/browser/views/jsmessage_box_dialog.h b/chrome/browser/views/jsmessage_box_dialog.h index 7195904..e86e8ac 100644 --- a/chrome/browser/views/jsmessage_box_dialog.h +++ b/chrome/browser/views/jsmessage_box_dialog.h @@ -37,7 +37,8 @@ class JavascriptMessageBoxDialog : public views::DialogDelegate { virtual void DeleteDelegate(); virtual bool Cancel(); virtual bool Accept(); - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; // views::WindowDelegate Methods: virtual bool IsModal() const { return true; } diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index 4a4f064..b972144 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -444,7 +444,7 @@ std::wstring KeywordEditorView::GetWindowTitle() const { } int KeywordEditorView::GetDialogButtons() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } bool KeywordEditorView::Accept() { diff --git a/chrome/browser/views/new_profile_dialog.cc b/chrome/browser/views/new_profile_dialog.cc index fbb9c8e..cf9551d1 100644 --- a/chrome/browser/views/new_profile_dialog.cc +++ b/chrome/browser/views/new_profile_dialog.cc @@ -30,9 +30,9 @@ NewProfileDialog::NewProfileDialog() { IDS_NEW_PROFILE_DIALOG_LABEL_TEXT); const int kDialogWidth = views::Window::GetLocalizedContentsWidth( IDS_NEW_PROFILE_DIALOG_WIDTH_CHARS); - const int kMessageBoxFlags = MessageBox::kFlagHasOKButton | - MessageBox::kFlagHasCancelButton | - MessageBox::kFlagHasPromptField; + const int kMessageBoxFlags = MessageBoxFlags::kFlagHasOKButton | + MessageBoxFlags::kFlagHasCancelButton | + MessageBoxFlags::kFlagHasPromptField; message_box_view_ = new MessageBoxView(kMessageBoxFlags, message_text.c_str(), std::wstring(), @@ -46,10 +46,6 @@ NewProfileDialog::NewProfileDialog() { NewProfileDialog::~NewProfileDialog() { } -int NewProfileDialog::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; -} - views::View* NewProfileDialog::GetInitiallyFocusedView() { views::TextField* text_box = message_box_view_->text_box(); DCHECK(text_box); @@ -57,8 +53,8 @@ views::View* NewProfileDialog::GetInitiallyFocusedView() { } bool NewProfileDialog::IsDialogButtonEnabled( - DialogButton button) const { - if (button == DIALOGBUTTON_OK) { + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { std::wstring profile_name = message_box_view_->GetInputText(); // TODO(munjal): Refactor the function ReplaceIllegalCharacters in // file_util to something that just checks if there are illegal chars diff --git a/chrome/browser/views/new_profile_dialog.h b/chrome/browser/views/new_profile_dialog.h index 868480e..4564ec2 100644 --- a/chrome/browser/views/new_profile_dialog.h +++ b/chrome/browser/views/new_profile_dialog.h @@ -30,9 +30,9 @@ class NewProfileDialog : public views::DialogDelegate, // views::DialogDelegate methods. virtual bool Accept(); - virtual int GetDialogButtons() const; virtual views::View* GetInitiallyFocusedView(); - virtual bool IsDialogButtonEnabled(DialogButton button) const; + virtual bool IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const; virtual std::wstring GetWindowTitle() const; virtual void DeleteDelegate(); diff --git a/chrome/browser/views/options/advanced_page_view.cc b/chrome/browser/views/options/advanced_page_view.cc index fcf083b..20d8616 100644 --- a/chrome/browser/views/options/advanced_page_view.cc +++ b/chrome/browser/views/options/advanced_page_view.cc @@ -36,14 +36,12 @@ class ResetDefaultsConfirmBox : public views::DialogDelegate { protected: // views::DialogDelegate - virtual int GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; - } - virtual std::wstring GetDialogButtonLabel(DialogButton button) const { + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { switch (button) { - case DIALOGBUTTON_OK: + case MessageBoxFlags::DIALOGBUTTON_OK: return l10n_util::GetString(IDS_OPTIONS_RESET_OKLABEL); - case DIALOGBUTTON_CANCEL: + case MessageBoxFlags::DIALOGBUTTON_CANCEL: return l10n_util::GetString(IDS_OPTIONS_RESET_CANCELLABEL); default: break; @@ -69,7 +67,7 @@ class ResetDefaultsConfirmBox : public views::DialogDelegate { const int kDialogWidth = 400; // Also deleted when the window closes. message_box_view_ = new MessageBoxView( - MessageBox::kFlagHasMessage | MessageBox::kFlagHasOKButton, + MessageBoxFlags::kFlagHasMessage | MessageBoxFlags::kFlagHasOKButton, l10n_util::GetString(IDS_OPTIONS_RESET_MESSAGE).c_str(), std::wstring(), kDialogWidth); diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h index 2baed44..c05bce7 100644 --- a/chrome/browser/views/options/cookies_view.h +++ b/chrome/browser/views/options/cookies_view.h @@ -55,9 +55,11 @@ class CookiesView : public views::View, UINT flags); // views::WindowDelegate implementation: - virtual int GetDialogButtons() const { return DIALOGBUTTON_CANCEL; } + virtual int GetDialogButtons() const { + return MessageBoxFlags::DIALOGBUTTON_CANCEL; + } virtual views::View* GetInitiallyFocusedView() { - return search_field_; + return search_field_; } virtual bool CanResize() const { return true; } virtual std::wstring GetWindowTitle() const; diff --git a/chrome/browser/views/options/options_window_view.cc b/chrome/browser/views/options/options_window_view.cc index f7f492f..d163640 100644 --- a/chrome/browser/views/options/options_window_view.cc +++ b/chrome/browser/views/options/options_window_view.cc @@ -42,7 +42,9 @@ class OptionsWindowView : public views::View, void ShowOptionsPage(OptionsPage page, OptionsGroup highlight_group); // views::DialogDelegate implementation: - virtual int GetDialogButtons() const { return DIALOGBUTTON_CANCEL; } + virtual int GetDialogButtons() const { + return MessageBoxFlags::DIALOGBUTTON_CANCEL; + } virtual std::wstring GetWindowTitle() const; virtual void WindowClosing(); virtual bool Cancel(); diff --git a/chrome/browser/views/options/passwords_exceptions_window_view.cc b/chrome/browser/views/options/passwords_exceptions_window_view.cc index 9bf44b4..4ea100f 100644 --- a/chrome/browser/views/options/passwords_exceptions_window_view.cc +++ b/chrome/browser/views/options/passwords_exceptions_window_view.cc @@ -65,7 +65,7 @@ void PasswordsExceptionsWindowView::ViewHierarchyChanged( // PasswordsExceptionsWindowView, views::DisloagDelegate implementations int PasswordsExceptionsWindowView::GetDialogButtons() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } std::wstring PasswordsExceptionsWindowView::GetWindowTitle() const { diff --git a/chrome/browser/views/page_info_window.cc b/chrome/browser/views/page_info_window.cc index ecc3ef8..5fa345e 100644 --- a/chrome/browser/views/page_info_window.cc +++ b/chrome/browser/views/page_info_window.cc @@ -597,7 +597,7 @@ void PageInfoWindow::Show() { } int PageInfoWindow::GetDialogButtons() const { - return DIALOGBUTTON_CANCEL; + return MessageBoxFlags::DIALOGBUTTON_CANCEL; } std::wstring PageInfoWindow::GetWindowTitle() const { diff --git a/chrome/browser/views/repost_form_warning_view.cc b/chrome/browser/views/repost_form_warning_view.cc index b8e9153..97e33fd 100644 --- a/chrome/browser/views/repost_form_warning_view.cc +++ b/chrome/browser/views/repost_form_warning_view.cc @@ -25,7 +25,7 @@ RepostFormWarningView::RepostFormWarningView( : navigation_controller_(navigation_controller), message_box_view_(NULL) { message_box_view_ = new MessageBoxView( - MessageBox::kIsConfirmMessageBox, + MessageBoxFlags::kIsConfirmMessageBox, l10n_util::GetString(IDS_HTTP_POST_WARNING), L""); // TODO(beng): fix this - this dialog box should be shown by a method on the @@ -57,10 +57,10 @@ std::wstring RepostFormWarningView::GetWindowTitle() const { } std::wstring RepostFormWarningView::GetDialogButtonLabel( - DialogButton button) const { - if (button == DialogDelegate::DIALOGBUTTON_OK) + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_HTTP_POST_WARNING_RESEND); - if (button == DialogDelegate::DIALOGBUTTON_CANCEL) + if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) return l10n_util::GetString(IDS_HTTP_POST_WARNING_CANCEL); return L""; } diff --git a/chrome/browser/views/repost_form_warning_view.h b/chrome/browser/views/repost_form_warning_view.h index a653922..809b7b5 100644 --- a/chrome/browser/views/repost_form_warning_view.h +++ b/chrome/browser/views/repost_form_warning_view.h @@ -23,7 +23,8 @@ class RepostFormWarningView : public views::DialogDelegate, // views::DialogDelegate Methods: virtual std::wstring GetWindowTitle() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual void DeleteDelegate(); virtual bool Cancel(); virtual bool Accept(); diff --git a/chrome/browser/views/restart_message_box.cc b/chrome/browser/views/restart_message_box.cc index e61e23f..e9728cb 100644 --- a/chrome/browser/views/restart_message_box.cc +++ b/chrome/browser/views/restart_message_box.cc @@ -21,12 +21,12 @@ void RestartMessageBox::ShowMessageBox(HWND parent_hwnd) { } int RestartMessageBox::GetDialogButtons() const { - return DialogDelegate::DIALOGBUTTON_OK; + return MessageBoxFlags::DIALOGBUTTON_OK; } -std::wstring RestartMessageBox::GetDialogButtonLabel(DialogButton button) - const { - DCHECK(button == DIALOGBUTTON_OK); +std::wstring RestartMessageBox::GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + DCHECK(button == MessageBoxFlags::DIALOGBUTTON_OK); return l10n_util::GetString(IDS_OK); } @@ -53,7 +53,7 @@ RestartMessageBox::RestartMessageBox(HWND parent_hwnd) { const int kDialogWidth = 400; // Also deleted when the window closes. message_box_view_ = new MessageBoxView( - MessageBox::kFlagHasMessage | MessageBox::kFlagHasOKButton, + MessageBoxFlags::kFlagHasMessage | MessageBoxFlags::kFlagHasOKButton, l10n_util::GetString(IDS_OPTIONS_RESTART_REQUIRED).c_str(), std::wstring(), kDialogWidth); diff --git a/chrome/browser/views/restart_message_box.h b/chrome/browser/views/restart_message_box.h index 893bf43..8180de4 100644 --- a/chrome/browser/views/restart_message_box.h +++ b/chrome/browser/views/restart_message_box.h @@ -20,7 +20,8 @@ class RestartMessageBox : public views::DialogDelegate { protected: // views::DialogDelegate: virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual std::wstring GetWindowTitle() const; // views::WindowDelegate: diff --git a/chrome/browser/views/select_profile_dialog.cc b/chrome/browser/views/select_profile_dialog.cc index b10c262..3a5c6d2 100644 --- a/chrome/browser/views/select_profile_dialog.cc +++ b/chrome/browser/views/select_profile_dialog.cc @@ -66,10 +66,6 @@ void SelectProfileDialog::Layout() { GetLayoutManager()->Layout(this); } -int SelectProfileDialog::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; -} - views::View* SelectProfileDialog::GetInitiallyFocusedView() { return profile_combobox_; } diff --git a/chrome/browser/views/select_profile_dialog.h b/chrome/browser/views/select_profile_dialog.h index a761623..723efb2 100644 --- a/chrome/browser/views/select_profile_dialog.h +++ b/chrome/browser/views/select_profile_dialog.h @@ -50,7 +50,6 @@ class SelectProfileDialog virtual bool Accept(); virtual bool Cancel(); virtual views::View* GetContentsView(); - virtual int GetDialogButtons() const; virtual views::View* GetInitiallyFocusedView(); virtual std::wstring GetWindowTitle() const; virtual bool IsModal() const { return false; } diff --git a/chrome/browser/views/shelf_item_dialog.cc b/chrome/browser/views/shelf_item_dialog.cc index 68050b1..bb05c44 100644 --- a/chrome/browser/views/shelf_item_dialog.cc +++ b/chrome/browser/views/shelf_item_dialog.cc @@ -375,8 +375,9 @@ bool ShelfItemDialog::IsModal() const { return true; } -std::wstring ShelfItemDialog::GetDialogButtonLabel(DialogButton button) const { - if (button == DialogDelegate::DIALOGBUTTON_OK) +std::wstring ShelfItemDialog::GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return l10n_util::GetString(IDS_ASI_ADD); return std::wstring(); } @@ -426,7 +427,7 @@ void ShelfItemDialog::ContentsChanged(views::TextField* sender, } bool ShelfItemDialog::Accept() { - if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) { + if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { if (!GetInputURL().is_valid()) url_field_->RequestFocus(); else if (title_field_) @@ -437,8 +438,9 @@ bool ShelfItemDialog::Accept() { return true; } -bool ShelfItemDialog::IsDialogButtonEnabled(DialogButton button) const { - if (button == DIALOGBUTTON_OK) +bool ShelfItemDialog::IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) return GetInputURL().is_valid(); return true; } diff --git a/chrome/browser/views/shelf_item_dialog.h b/chrome/browser/views/shelf_item_dialog.h index 9e5520d..e1c932e 100644 --- a/chrome/browser/views/shelf_item_dialog.h +++ b/chrome/browser/views/shelf_item_dialog.h @@ -59,9 +59,10 @@ class ShelfItemDialog : public views::View, // DialogDelegate. virtual std::wstring GetWindowTitle() const; virtual bool IsModal() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual bool Accept(); - virtual bool IsDialogButtonEnabled(DialogButton button) const; + virtual bool IsDialogButtonEnabled(MessageBoxFlags::DialogButton button) const; virtual views::View* GetContentsView(); // TextField::Controller. diff --git a/chrome/browser/views/uninstall_dialog.cc b/chrome/browser/views/uninstall_dialog.cc index da54ca8..51e7023 100644 --- a/chrome/browser/views/uninstall_dialog.cc +++ b/chrome/browser/views/uninstall_dialog.cc @@ -30,10 +30,6 @@ bool UninstallDialog::Cancel() { return true; } -int UninstallDialog::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; -} - std::wstring UninstallDialog::GetWindowTitle() const { return l10n_util::GetString(IDS_UNINSTALL_CHROME); } @@ -50,7 +46,8 @@ UninstallDialog::UninstallDialog(int& user_selection) : user_selection_(user_selection) { // Also deleted when the window closes. message_box_view_ = new MessageBoxView( - MessageBox::kIsConfirmMessageBox | MessageBox::kAutoDetectAlignment, + MessageBoxFlags::kIsConfirmMessageBox | + MessageBoxFlags::kAutoDetectAlignment, l10n_util::GetString(IDS_UNINSTALL_VERIFY).c_str(), std::wstring()); message_box_view_->SetCheckBoxLabel( diff --git a/chrome/browser/views/uninstall_dialog.h b/chrome/browser/views/uninstall_dialog.h index 0874db6..bf9a6c9 100644 --- a/chrome/browser/views/uninstall_dialog.h +++ b/chrome/browser/views/uninstall_dialog.h @@ -20,7 +20,6 @@ class UninstallDialog : public views::DialogDelegate { // Overridden from views::DialogDelegate: virtual bool Accept(); virtual bool Cancel(); - virtual int GetDialogButtons() const; virtual std::wstring GetWindowTitle() const; // Overridden from views::WindowDelegate: diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc index 3598950..79bcd4e 100644 --- a/chrome/browser/views/user_data_dir_dialog.cc +++ b/chrome/browser/views/user_data_dir_dialog.cc @@ -27,7 +27,7 @@ UserDataDirDialog::UserDataDirDialog(const std::wstring& user_data_dir) std::wstring message_text = l10n_util::GetStringF( IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY, user_data_dir); const int kDialogWidth = 400; - message_box_view_ = new MessageBoxView(MessageBox::kIsConfirmMessageBox, + message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox, message_text.c_str(), std::wstring(), kDialogWidth); views::Window::CreateChromeWindow(NULL, gfx::Rect(), this)->Show(); @@ -37,19 +37,14 @@ UserDataDirDialog::~UserDataDirDialog() { select_file_dialog_->ListenerDestroyed(); } -int UserDataDirDialog::GetDialogButtons() const { - return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; - -} - std::wstring UserDataDirDialog::GetDialogButtonLabel( - DialogButton button) const { + MessageBoxFlags::DialogButton button) const { switch (button) { - case DIALOGBUTTON_OK: + case MessageBoxFlags::DIALOGBUTTON_OK: return l10n_util::GetString( IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON); - case DIALOGBUTTON_CANCEL: + case MessageBoxFlags::DIALOGBUTTON_CANCEL: return l10n_util::GetString(IDS_CANT_WRITE_USER_DIRECTORY_EXIT_BUTTON); default: NOTREACHED(); diff --git a/chrome/browser/views/user_data_dir_dialog.h b/chrome/browser/views/user_data_dir_dialog.h index 78192ce..7408132 100644 --- a/chrome/browser/views/user_data_dir_dialog.h +++ b/chrome/browser/views/user_data_dir_dialog.h @@ -32,8 +32,8 @@ class UserDataDirDialog : public views::DialogDelegate, std::wstring user_data_dir() { return user_data_dir_; } // views::DialogDelegate Methods: - virtual int GetDialogButtons() const; - virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; virtual std::wstring GetWindowTitle() const; virtual void DeleteDelegate(); virtual bool Accept(); diff --git a/chrome/common/message_box_flags.h b/chrome/common/message_box_flags.h index 40047d9..8520c56 100644 --- a/chrome/common/message_box_flags.h +++ b/chrome/common/message_box_flags.h @@ -10,7 +10,7 @@ // This class contains flags used to communicate the type of message box // to show. E.g., the renderer can request the browser to show a // javascript alert or a javascript confirm message. -class MessageBox { +class MessageBoxFlags { public: static const int kFlagHasOKButton = 0x1; static const int kFlagHasCancelButton = 0x2; @@ -42,9 +42,16 @@ class MessageBox { static const int kIsJavascriptPrompt = kIsJavascriptConfirm | kFlagHasPromptField; + // Dialog button identifiers used to specify which buttons to show the user. + 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). + private: - MessageBox() {} - DISALLOW_COPY_AND_ASSIGN(MessageBox); + MessageBoxFlags() {} + DISALLOW_COPY_AND_ASSIGN(MessageBoxFlags); }; #endif // CHROME_COMMON_MESSAGE_BOX_FLAGS_H_ diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 8d2fbff..4dcb220 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -119,16 +119,6 @@ void AutomationProvider::OnMessageFromExternalHost( NOTIMPLEMENTED(); } -void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, - int* dialog_button) { - NOTIMPLEMENTED(); -} - -void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { - *success = false; - NOTIMPLEMENTED(); -} - //-------------------------------------------------------------------------- bool ShellIntegration::SetAsDefaultBrowser() { diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 9523e7a..771fa8a 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -1628,7 +1628,7 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction( void RenderView::RunJavaScriptAlert(WebFrame* webframe, const std::wstring& message) { - RunJavaScriptMessage(MessageBox::kIsJavascriptAlert, + RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, message, std::wstring(), webframe->GetURL(), @@ -1637,7 +1637,7 @@ void RenderView::RunJavaScriptAlert(WebFrame* webframe, bool RenderView::RunJavaScriptConfirm(WebFrame* webframe, const std::wstring& message) { - return RunJavaScriptMessage(MessageBox::kIsJavascriptConfirm, + return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, message, std::wstring(), webframe->GetURL(), @@ -1648,7 +1648,7 @@ bool RenderView::RunJavaScriptPrompt(WebFrame* webframe, const std::wstring& message, const std::wstring& default_value, std::wstring* result) { - return RunJavaScriptMessage(MessageBox::kIsJavascriptPrompt, + return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, message, default_value, webframe->GetURL(), diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 5715aac..c6b1bb9 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -318,11 +318,9 @@ bool AutomationProxy::WaitForWindowCountToBecome(int count, return false; } -#if defined(OS_WIN) -// TODO(port): Port when DialogDelegate is ported. bool AutomationProxy::GetShowingAppModalDialog( bool* showing_app_modal_dialog, - views::DialogDelegate::DialogButton* button) { + MessageBoxFlags::DialogButton* button) { if (!showing_app_modal_dialog || !button) { NOTREACHED(); return false; @@ -338,12 +336,12 @@ bool AutomationProxy::GetShowingAppModalDialog( return false; } - *button = static_cast<views::DialogDelegate::DialogButton>(button_int); + *button = static_cast<MessageBoxFlags::DialogButton>(button_int); return true; } bool AutomationProxy::ClickAppModalDialogButton( - views::DialogDelegate::DialogButton button) { + MessageBoxFlags::DialogButton button) { bool succeeded = false; if (!SendWithTimeout( @@ -361,8 +359,7 @@ bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) { const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); while (TimeTicks::Now() - start < timeout) { bool dialog_shown = false; - views::DialogDelegate::DialogButton button = - views::DialogDelegate::DIALOGBUTTON_NONE; + MessageBoxFlags::DialogButton button = MessageBoxFlags::DIALOGBUTTON_NONE; bool succeeded = GetShowingAppModalDialog(&dialog_shown, &button); if (!succeeded) { // Try again next round, but log it. @@ -370,12 +367,11 @@ bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) { } else if (dialog_shown) { return true; } - Sleep(automation::kSleepTime); + PlatformThread::Sleep(automation::kSleepTime); } // Dialog never shown. return false; } -#endif // defined(OS_WIN) bool AutomationProxy::WaitForURLDisplayed(GURL url, int wait_timeout) { const TimeTicks start = TimeTicks::Now(); diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index e9d55d1..5c2cb22 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -16,14 +16,10 @@ #include "chrome/common/ipc_channel_proxy.h" #include "chrome/common/ipc_message.h" #include "chrome/common/ipc_sync_channel.h" +#include "chrome/common/message_box_flags.h" #include "chrome/test/automation/automation_handle_tracker.h" #include "chrome/test/automation/automation_messages.h" -#if defined(OS_WIN) -// TODO(port): Enable this or equivalent. -#include "chrome/views/window/dialog_delegate.h" -#endif - class AutomationRequest; class BrowserProxy; class TabProxy; @@ -98,17 +94,13 @@ class AutomationProxy : public IPC::Channel::Listener, // Returns true on success. bool WaitForWindowCountToBecome(int target_count, int wait_timeout); -#if defined(OS_WIN) - // TODO(port): Enable when we have portable DialogDelegate. - // Returns whether an app modal dialog window is showing right now (i.e., a // javascript alert), and what buttons it contains. bool GetShowingAppModalDialog(bool* showing_app_modal_dialog, - views::DialogDelegate::DialogButton* button); + MessageBoxFlags::DialogButton* button); // Simulates a click on a dialog button. - bool ClickAppModalDialogButton(views::DialogDelegate::DialogButton button); -#endif // defined(OS_WIN) + bool ClickAppModalDialogButton(MessageBoxFlags::DialogButton button); // Block the thread until a modal dialog is displayed. Returns true on // success. diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index 464fa81..0454611 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -1005,12 +1005,11 @@ TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { ASSERT_TRUE(tab.get()); bool modal_dialog_showing = false; - views::DialogDelegate::DialogButton button = - views::DialogDelegate::DIALOGBUTTON_NONE; + MessageBoxFlags::DialogButton button = MessageBoxFlags::DIALOGBUTTON_NONE; EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_FALSE(modal_dialog_showing); - EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_NONE, button); + EXPECT_EQ(MessageBoxFlags::DIALOGBUTTON_NONE, button); // Show a simple alert. std::string content = @@ -1022,19 +1021,19 @@ TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_TRUE(modal_dialog_showing); - EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_OK, button); + EXPECT_EQ(MessageBoxFlags::DIALOGBUTTON_OK, button); // Test that clicking missing button fails graciously and does not close the // dialog. EXPECT_FALSE(automation()->ClickAppModalDialogButton( - views::DialogDelegate::DIALOGBUTTON_CANCEL)); + MessageBoxFlags::DIALOGBUTTON_CANCEL)); EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_TRUE(modal_dialog_showing); // Now click OK, that should close the dialog. EXPECT_TRUE(automation()->ClickAppModalDialogButton( - views::DialogDelegate::DIALOGBUTTON_OK)); + MessageBoxFlags::DIALOGBUTTON_OK)); EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_FALSE(modal_dialog_showing); @@ -1049,12 +1048,12 @@ TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_TRUE(modal_dialog_showing); - EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_OK | - views::DialogDelegate::DIALOGBUTTON_CANCEL, button); + EXPECT_EQ(MessageBoxFlags::DIALOGBUTTON_OK | + MessageBoxFlags::DIALOGBUTTON_CANCEL, button); // Click OK. EXPECT_TRUE(automation()->ClickAppModalDialogButton( - views::DialogDelegate::DIALOGBUTTON_OK)); + MessageBoxFlags::DIALOGBUTTON_OK)); EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_FALSE(modal_dialog_showing); @@ -1069,12 +1068,12 @@ TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_TRUE(modal_dialog_showing); - EXPECT_EQ(views::DialogDelegate::DIALOGBUTTON_OK | - views::DialogDelegate::DIALOGBUTTON_CANCEL, button); + EXPECT_EQ(MessageBoxFlags::DIALOGBUTTON_OK | + MessageBoxFlags::DIALOGBUTTON_CANCEL, button); // Click Cancel this time. EXPECT_TRUE(automation()->ClickAppModalDialogButton( - views::DialogDelegate::DIALOGBUTTON_CANCEL)); + MessageBoxFlags::DIALOGBUTTON_CANCEL)); EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, &button)); EXPECT_FALSE(modal_dialog_showing); 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; } |