diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 23:07:30 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 23:07:30 +0000 |
commit | 2e4bdcdc8cdbffe656700a4028679f0569ad6245 (patch) | |
tree | 633b08aad2d776a54eda7296bf2af2ee6aa52e0c /chrome | |
parent | 698835d3e64c96bb5e7a29ab66d2ecbee375fc63 (diff) | |
download | chromium_src-2e4bdcdc8cdbffe656700a4028679f0569ad6245.zip chromium_src-2e4bdcdc8cdbffe656700a4028679f0569ad6245.tar.gz chromium_src-2e4bdcdc8cdbffe656700a4028679f0569ad6245.tar.bz2 |
Move message flags into a separate header that can be used
outside the views system. Mac will need this as well when
implementing message boxes.
Review URL: http://codereview.chromium.org/56026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/download/download_request_dialog_delegate_win.cc | 3 | ||||
-rw-r--r-- | chrome/browser/js_before_unload_handler_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler_win.cc | 7 | ||||
-rw-r--r-- | chrome/browser/views/external_protocol_dialog.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/new_profile_dialog.cc | 7 | ||||
-rw-r--r-- | chrome/browser/views/options/advanced_page_view.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/repost_form_warning_view.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/restart_message_box.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/user_data_dir_dialog.cc | 3 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/common/common.vcproj | 4 | ||||
-rw-r--r-- | chrome/common/message_box_flags.h | 50 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 32 | ||||
-rw-r--r-- | chrome/views/controls/message_box_view.cc | 5 | ||||
-rw-r--r-- | chrome/views/controls/message_box_view.h | 31 |
15 files changed, 84 insertions, 75 deletions
diff --git a/chrome/browser/download/download_request_dialog_delegate_win.cc b/chrome/browser/download/download_request_dialog_delegate_win.cc index 2ff9a24..3f359ca 100644 --- a/chrome/browser/download/download_request_dialog_delegate_win.cc +++ b/chrome/browser/download/download_request_dialog_delegate_win.cc @@ -7,6 +7,7 @@ #include "chrome/browser/tab_contents/constrained_window.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/views/controls/message_box_view.h" #include "grit/generated_resources.h" @@ -22,7 +23,7 @@ DownloadRequestDialogDelegateWin::DownloadRequestDialogDelegateWin( DownloadRequestManager::TabDownloadState* host) : DownloadRequestDialogDelegate(host) { message_view_ = new MessageBoxView( - MessageBoxView::kIsConfirmMessageBox, + MessageBox::kIsConfirmMessageBox, l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING), std::wstring()); window_ = tab->CreateConstrainedDialog(this, message_view_); diff --git a/chrome/browser/js_before_unload_handler_win.cc b/chrome/browser/js_before_unload_handler_win.cc index e550018..f97620d 100644 --- a/chrome/browser/js_before_unload_handler_win.cc +++ b/chrome/browser/js_before_unload_handler_win.cc @@ -6,7 +6,7 @@ #include "chrome/browser/app_modal_dialog_queue.h" #include "chrome/common/l10n_util.h" -#include "chrome/views/controls/message_box_view.h" +#include "chrome/common/message_box_flags.h" #include "grit/generated_resources.h" void RunBeforeUnloadDialog(WebContents* web_contents, @@ -31,7 +31,7 @@ JavascriptBeforeUnloadHandler::JavascriptBeforeUnloadHandler( IPC::Message* reply_msg) : JavascriptMessageBoxHandler(web_contents, frame_url, - MessageBoxView::kIsJavascriptConfirm, + MessageBox::kIsJavascriptConfirm, message_text, std::wstring(), false, diff --git a/chrome/browser/jsmessage_box_handler_win.cc b/chrome/browser/jsmessage_box_handler_win.cc index 1b6ef07..847f7cf 100644 --- a/chrome/browser/jsmessage_box_handler_win.cc +++ b/chrome/browser/jsmessage_box_handler_win.cc @@ -11,6 +11,7 @@ #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/gfx/text_elider.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "chrome/common/pref_names.h" @@ -47,7 +48,7 @@ JavascriptMessageBoxHandler::JavascriptMessageBoxHandler( dialog_flags_(dialog_flags), dialog_(NULL), message_box_view_(new MessageBoxView( - dialog_flags | MessageBoxView::kAutoDetectAlignment, + dialog_flags | MessageBox::kAutoDetectAlignment, message_text, default_prompt_text)) { DCHECK(message_box_view_); DCHECK(reply_msg_); @@ -73,10 +74,10 @@ JavascriptMessageBoxHandler::~JavascriptMessageBoxHandler() { int JavascriptMessageBoxHandler::GetDialogButtons() const { int dialog_buttons = 0; - if (dialog_flags_ & MessageBoxView::kFlagHasOKButton) + if (dialog_flags_ & MessageBox::kFlagHasOKButton) dialog_buttons = DIALOGBUTTON_OK; - if (dialog_flags_ & MessageBoxView::kFlagHasCancelButton) + if (dialog_flags_ & MessageBox::kFlagHasCancelButton) dialog_buttons |= DIALOGBUTTON_CANCEL; return dialog_buttons; diff --git a/chrome/browser/views/external_protocol_dialog.cc b/chrome/browser/views/external_protocol_dialog.cc index 99ee16a..50cdce3 100644 --- a/chrome/browser/views/external_protocol_dialog.cc +++ b/chrome/browser/views/external_protocol_dialog.cc @@ -12,6 +12,7 @@ #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/views/controls/message_box_view.h" #include "chrome/views/window/window.h" #include "grit/chromium_strings.h" @@ -103,7 +104,7 @@ ExternalProtocolDialog::ExternalProtocolDialog(TabContents* tab_contents, message_text += l10n_util::GetString(IDS_EXTERNAL_PROTOCOL_WARNING); - message_box_view_ = new MessageBoxView(MessageBoxView::kIsConfirmMessageBox, + message_box_view_ = new MessageBoxView(MessageBox::kIsConfirmMessageBox, message_text, L"", kMessageWidth); diff --git a/chrome/browser/views/new_profile_dialog.cc b/chrome/browser/views/new_profile_dialog.cc index 8b2faea..fbb9c8e 100644 --- a/chrome/browser/views/new_profile_dialog.cc +++ b/chrome/browser/views/new_profile_dialog.cc @@ -10,6 +10,7 @@ #include "base/file_util.h" #include "chrome/browser/user_data_manager.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/views/controls/message_box_view.h" #include "chrome/views/controls/text_field.h" #include "chrome/views/view.h" @@ -29,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 = MessageBoxView::kFlagHasOKButton | - MessageBoxView::kFlagHasCancelButton | - MessageBoxView::kFlagHasPromptField; + const int kMessageBoxFlags = MessageBox::kFlagHasOKButton | + MessageBox::kFlagHasCancelButton | + MessageBox::kFlagHasPromptField; message_box_view_ = new MessageBoxView(kMessageBoxFlags, message_text.c_str(), std::wstring(), diff --git a/chrome/browser/views/options/advanced_page_view.cc b/chrome/browser/views/options/advanced_page_view.cc index fc258f6..fcf083b 100644 --- a/chrome/browser/views/options/advanced_page_view.cc +++ b/chrome/browser/views/options/advanced_page_view.cc @@ -11,6 +11,7 @@ #include "chrome/browser/views/standard_layout.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/views/controls/message_box_view.h" @@ -68,7 +69,7 @@ class ResetDefaultsConfirmBox : public views::DialogDelegate { const int kDialogWidth = 400; // Also deleted when the window closes. message_box_view_ = new MessageBoxView( - MessageBoxView::kFlagHasMessage | MessageBoxView::kFlagHasOKButton, + MessageBox::kFlagHasMessage | MessageBox::kFlagHasOKButton, l10n_util::GetString(IDS_OPTIONS_RESET_MESSAGE).c_str(), std::wstring(), kDialogWidth); diff --git a/chrome/browser/views/repost_form_warning_view.cc b/chrome/browser/views/repost_form_warning_view.cc index 583de4c..b8e9153 100644 --- a/chrome/browser/views/repost_form_warning_view.cc +++ b/chrome/browser/views/repost_form_warning_view.cc @@ -7,6 +7,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/common/notification_service.h" #include "chrome/views/controls/message_box_view.h" #include "chrome/views/window/window.h" @@ -24,7 +25,7 @@ RepostFormWarningView::RepostFormWarningView( : navigation_controller_(navigation_controller), message_box_view_(NULL) { message_box_view_ = new MessageBoxView( - MessageBoxView::kIsConfirmMessageBox, + MessageBox::kIsConfirmMessageBox, l10n_util::GetString(IDS_HTTP_POST_WARNING), L""); // TODO(beng): fix this - this dialog box should be shown by a method on the diff --git a/chrome/browser/views/restart_message_box.cc b/chrome/browser/views/restart_message_box.cc index 42f734d..e61e23f 100644 --- a/chrome/browser/views/restart_message_box.cc +++ b/chrome/browser/views/restart_message_box.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/restart_message_box.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/views/controls/message_box_view.h" #include "chrome/views/window/window.h" #include "grit/chromium_strings.h" @@ -52,7 +53,7 @@ RestartMessageBox::RestartMessageBox(HWND parent_hwnd) { const int kDialogWidth = 400; // Also deleted when the window closes. message_box_view_ = new MessageBoxView( - MessageBoxView::kFlagHasMessage | MessageBoxView::kFlagHasOKButton, + MessageBox::kFlagHasMessage | MessageBox::kFlagHasOKButton, l10n_util::GetString(IDS_OPTIONS_RESTART_REQUIRED).c_str(), std::wstring(), kDialogWidth); diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc index f303f37..041ae8a 100644 --- a/chrome/browser/views/user_data_dir_dialog.cc +++ b/chrome/browser/views/user_data_dir_dialog.cc @@ -5,6 +5,7 @@ #include "base/logging.h" #include "chrome/browser/views/user_data_dir_dialog.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/views/controls/message_box_view.h" #include "chrome/views/widget/widget.h" #include "chrome/views/window/window.h" @@ -26,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(MessageBoxView::kIsConfirmMessageBox, + message_box_view_ = new MessageBoxView(MessageBox::kIsConfirmMessageBox, message_text.c_str(), std::wstring(), kDialogWidth); views::Window::CreateChromeWindow(NULL, gfx::Rect(), this)->Show(); diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 3f1b847..db1fca9 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -209,6 +209,7 @@ 'common/mach_message_source_mac.cc', 'common/mach_message_source_mac.h', 'common/main_function_params.h', + 'common/message_box_flags.h', 'common/message_router.cc', 'common/message_router.h', 'common/modal_dialog_event.h', diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj index c5ea93a..1a99f60 100644 --- a/chrome/common/common.vcproj +++ b/chrome/common/common.vcproj @@ -542,6 +542,10 @@ > </File> <File + RelativePath=".\message_box_flags.h" + > + </File> + <File RelativePath=".\message_router.cc" > </File> diff --git a/chrome/common/message_box_flags.h b/chrome/common/message_box_flags.h new file mode 100644 index 0000000..40047d9 --- /dev/null +++ b/chrome/common/message_box_flags.h @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_MESSAGE_BOX_FLAGS_H_ +#define CHROME_COMMON_MESSAGE_BOX_FLAGS_H_ + +#include "base/basictypes.h" + +// 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 { + public: + static const int kFlagHasOKButton = 0x1; + static const int kFlagHasCancelButton = 0x2; + static const int kFlagHasPromptField = 0x4; + static const int kFlagHasMessage = 0x8; + + // The following flag is used to indicate whether the message's alignment + // should be autodetected or inherited from Chrome UI. Callers should pass + // the correct flag based on the origin of the message. If the message is + // from a web page (such as the JavaScript alert message), its alignment and + // directionality are based on the first character with strong directionality + // in the message. Chrome UI strings are localized string and therefore they + // should have the same alignment and directionality as those of the Chrome + // UI. For example, in RTL locales, even though some strings might begin with + // an English character, they should still be right aligned and be displayed + // Right-To-Left. + // + // TODO(xji): If the message is from a web page, then the message + // directionality should be determined based on the directionality of the web + // page. Please refer to http://crbug.com/7166 for more information. + static const int kAutoDetectAlignment = 0x10; + + static const int kIsConfirmMessageBox = kFlagHasMessage | + kFlagHasOKButton | + kFlagHasCancelButton; + static const int kIsJavascriptAlert = kFlagHasOKButton | kFlagHasMessage; + static const int kIsJavascriptConfirm = kIsJavascriptAlert | + kFlagHasCancelButton; + static const int kIsJavascriptPrompt = kIsJavascriptConfirm | + kFlagHasPromptField; + + private: + MessageBox() {} + DISALLOW_COPY_AND_ASSIGN(MessageBox); +}; + +#endif // CHROME_COMMON_MESSAGE_BOX_FLAGS_H_ diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 1109750..ecffb48 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -20,6 +20,7 @@ #include "chrome/common/gfx/color_utils.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/common/page_zoom.h" #include "chrome/common/render_messages.h" #include "chrome/common/resource_bundle.h" @@ -77,7 +78,6 @@ #include "base/gfx/native_theme.h" #include "chrome/common/gfx/emf.h" #include "chrome/renderer/renderer_logging.h" -#include "chrome/views/controls/message_box_view.h" #include "skia/ext/vector_canvas.h" #endif @@ -1595,33 +1595,9 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction( return disposition; } -#if defined(OS_POSIX) -// TODO(port): remove this massive hack -// WARNING: massive hack. We can't include message_box_view.h because that -// tries to pull in the rest of views. So we just define a fake MessageBoxView -// here with the constants that we require. - -class MessageBoxView { - public: - static const int kFlagHasOKButton = 0x1; - static const int kFlagHasCancelButton = 0x2; - static const int kFlagHasPromptField = 0x4; - static const int kFlagHasMessage = 0x8; - - static const int kIsConfirmMessageBox = kFlagHasMessage | - kFlagHasOKButton | - kFlagHasCancelButton; - static const int kIsJavascriptAlert = kFlagHasOKButton | kFlagHasMessage; - static const int kIsJavascriptConfirm = kIsJavascriptAlert | - kFlagHasCancelButton; - static const int kIsJavascriptPrompt = kIsJavascriptConfirm | - kFlagHasPromptField; -}; -#endif - void RenderView::RunJavaScriptAlert(WebFrame* webframe, const std::wstring& message) { - RunJavaScriptMessage(MessageBoxView::kIsJavascriptAlert, + RunJavaScriptMessage(MessageBox::kIsJavascriptAlert, message, std::wstring(), webframe->GetURL(), @@ -1630,7 +1606,7 @@ void RenderView::RunJavaScriptAlert(WebFrame* webframe, bool RenderView::RunJavaScriptConfirm(WebFrame* webframe, const std::wstring& message) { - return RunJavaScriptMessage(MessageBoxView::kIsJavascriptConfirm, + return RunJavaScriptMessage(MessageBox::kIsJavascriptConfirm, message, std::wstring(), webframe->GetURL(), @@ -1641,7 +1617,7 @@ bool RenderView::RunJavaScriptPrompt(WebFrame* webframe, const std::wstring& message, const std::wstring& default_value, std::wstring* result) { - return RunJavaScriptMessage(MessageBoxView::kIsJavascriptPrompt, + return RunJavaScriptMessage(MessageBox::kIsJavascriptPrompt, message, default_value, webframe->GetURL(), diff --git a/chrome/views/controls/message_box_view.cc b/chrome/views/controls/message_box_view.cc index 6a57480..7fc4a26 100644 --- a/chrome/views/controls/message_box_view.cc +++ b/chrome/views/controls/message_box_view.cc @@ -8,6 +8,7 @@ #include "base/string_util.h" #include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" #include "chrome/views/controls/button/checkbox.h" #include "chrome/views/window/client_view.h" #include "grit/generated_resources.h" @@ -92,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 & kAutoDetectAlignment) { + if (dialog_flags & MessageBox::kAutoDetectAlignment) { // Determine the alignment and directionality based on the first character // with strong directionality. l10n_util::TextDirection direction = @@ -111,7 +112,7 @@ void MessageBoxView::Init(int dialog_flags, message_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); } - if (dialog_flags & kFlagHasPromptField) { + if (dialog_flags & MessageBox::kFlagHasPromptField) { prompt_field_ = new views::TextField; prompt_field_->SetText(default_prompt); } diff --git a/chrome/views/controls/message_box_view.h b/chrome/views/controls/message_box_view.h index 43589a9..819b56a 100644 --- a/chrome/views/controls/message_box_view.h +++ b/chrome/views/controls/message_box_view.h @@ -22,37 +22,6 @@ class Checkbox; // and Cancel buttons. class MessageBoxView : public views::View { public: - // flags - static const int kFlagHasOKButton = 0x1; - static const int kFlagHasCancelButton = 0x2; - static const int kFlagHasPromptField = 0x4; - static const int kFlagHasMessage = 0x8; - - // The following flag is used to indicate whether the message's alignment - // should be autodetected or inherited from Chrome UI. Callers should pass - // the correct flag based on the origin of the message. If the message is - // from a web page (such as the JavaScript alert message), its alignment and - // directionality are based on the first character with strong directionality - // in the message. Chrome UI strings are localized string and therefore they - // should have the same alignment and directionality as those of the Chrome - // UI. For example, in RTL locales, even though some strings might begin with - // an English character, they should still be right aligned and be displayed - // Right-To-Left. - // - // TODO(xji): If the message is from a web page, then the message - // directionality should be determined based on the directionality of the web - // page. Please refer to http://crbug.com/7166 for more information. - static const int kAutoDetectAlignment = 0x10; - - static const int kIsConfirmMessageBox = kFlagHasMessage | - kFlagHasOKButton | - kFlagHasCancelButton; - static const int kIsJavascriptAlert = kFlagHasOKButton | kFlagHasMessage; - static const int kIsJavascriptConfirm = kIsJavascriptAlert | - kFlagHasCancelButton; - static const int kIsJavascriptPrompt = kIsJavascriptConfirm | - kFlagHasPromptField; - MessageBoxView(int dialog_flags, const std::wstring& message, const std::wstring& default_prompt, |