Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/views/confirm_message_box_dialog.cc

Issue 270081: Facelifts to sync UI (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/views/confirm_message_box_dialog.h" 5 #include "chrome/browser/views/confirm_message_box_dialog.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/message_box_flags.h" 8 #include "app/message_box_flags.h"
9 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
10 #include "grit/locale_settings.h" 10 #include "grit/locale_settings.h"
11 #include "views/standard_layout.h" 11 #include "views/standard_layout.h"
12 #include "views/widget/widget.h" 12 #include "views/widget/widget.h"
13 #include "views/window/window.h" 13 #include "views/window/window.h"
14 14
15 // static 15 // static
16 void ConfirmMessageBoxDialog::Run(gfx::NativeWindow parent, 16 void ConfirmMessageBoxDialog::Run(gfx::NativeWindow parent,
17 ConfirmMessageBoxObserver* observer, 17 ConfirmMessageBoxObserver* observer,
18 const std::wstring& message_text, 18 const std::wstring& message_text,
19 const std::wstring& window_title) { 19 const std::wstring& window_title) {
20 DCHECK(observer); 20 DCHECK(observer);
21 ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(observer, 21 ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(observer,
22 message_text, window_title); 22 message_text, window_title);
23 views::Window* window = views::Window::CreateChromeWindow( 23 views::Window* window = views::Window::CreateChromeWindow(
24 parent, gfx::Rect(), dialog); 24 parent, gfx::Rect(), dialog);
25 window->Show(); 25 window->Show();
26 } 26 }
27 27
28 // static
29 void ConfirmMessageBoxDialog::RunWithCustomConfiguration(
30 gfx::NativeWindow parent,
31 ConfirmMessageBoxObserver* observer,
32 const std::wstring& message_text,
33 const std::wstring& window_title,
34 const std::wstring& confirm_label,
35 const std::wstring& reject_label,
36 const gfx::Size& preferred_size) {
37 DCHECK(observer);
38 ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(observer,
39 message_text, window_title);
40 dialog->preferred_size_ = preferred_size;
41 dialog->confirm_label_ = confirm_label;
42 dialog->reject_label_ = reject_label;
43 views::Window* window = views::Window::CreateChromeWindow(
44 parent, gfx::Rect(), dialog);
45 window->Show();
46 }
47
28 ConfirmMessageBoxDialog::ConfirmMessageBoxDialog( 48 ConfirmMessageBoxDialog::ConfirmMessageBoxDialog(
29 ConfirmMessageBoxObserver* observer, const std::wstring& message_text, 49 ConfirmMessageBoxObserver* observer, const std::wstring& message_text,
30 const std::wstring& window_title) 50 const std::wstring& window_title)
31 : observer_(observer), 51 : observer_(observer),
32 window_title_(window_title) { 52 window_title_(window_title),
53 preferred_size_(gfx::Size(views::Window::GetLocalizedContentsSize(
54 IDS_CONFIRM_MESSAGE_BOX_DEFAULT_WIDTH_CHARS,
55 IDS_CONFIRM_MESSAGE_BOX_DEFAULT_HEIGHT_LINES))),
56 confirm_label_(l10n_util::GetString(
57 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)),
58 reject_label_(l10n_util::GetString(
59 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)) {
33 message_label_ = new views::Label(message_text); 60 message_label_ = new views::Label(message_text);
34 message_label_->SetMultiLine(true); 61 message_label_->SetMultiLine(true);
35 l10n_util::TextDirection direction = 62 l10n_util::TextDirection direction =
36 l10n_util::GetFirstStrongCharacterDirection(message_label_->GetText()); 63 l10n_util::GetFirstStrongCharacterDirection(message_label_->GetText());
37 views::Label::Alignment alignment; 64 views::Label::Alignment alignment;
38 if (direction == l10n_util::RIGHT_TO_LEFT) 65 if (direction == l10n_util::RIGHT_TO_LEFT)
39 alignment = views::Label::ALIGN_RIGHT; 66 alignment = views::Label::ALIGN_RIGHT;
40 else 67 else
41 alignment = views::Label::ALIGN_LEFT; 68 alignment = views::Label::ALIGN_LEFT;
42 // In addition, we should set the RTL alignment mode as 69 // In addition, we should set the RTL alignment mode as
43 // AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around 70 // AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around
44 // in RTL locales. 71 // in RTL locales.
45 message_label_->SetRTLAlignmentMode(views::Label::AUTO_DETECT_ALIGNMENT); 72 message_label_->SetRTLAlignmentMode(views::Label::AUTO_DETECT_ALIGNMENT);
46 message_label_->SetHorizontalAlignment(alignment); 73 message_label_->SetHorizontalAlignment(alignment);
47 AddChildView(message_label_); 74 AddChildView(message_label_);
48 } 75 }
49 76
50 int ConfirmMessageBoxDialog::GetDialogButtons() const { 77 int ConfirmMessageBoxDialog::GetDialogButtons() const {
51 return MessageBoxFlags::DIALOGBUTTON_OK | 78 return MessageBoxFlags::DIALOGBUTTON_OK |
52 MessageBoxFlags::DIALOGBUTTON_CANCEL; 79 MessageBoxFlags::DIALOGBUTTON_CANCEL;
53 } 80 }
54 81
55 std::wstring ConfirmMessageBoxDialog::GetWindowTitle() const { 82 std::wstring ConfirmMessageBoxDialog::GetWindowTitle() const {
56 return window_title_; 83 return window_title_;
57 } 84 }
58 85
59 std::wstring ConfirmMessageBoxDialog::GetDialogButtonLabel( 86 std::wstring ConfirmMessageBoxDialog::GetDialogButtonLabel(
60 MessageBoxFlags::DialogButton button) const { 87 MessageBoxFlags::DialogButton button) const {
61 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { 88 if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
62 return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); 89 return confirm_label_;
63 } 90 }
64 if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) 91 if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL)
65 return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); 92 return reject_label_;
66 return DialogDelegate::GetDialogButtonLabel(button); 93 return DialogDelegate::GetDialogButtonLabel(button);
67 } 94 }
68 95
69 bool ConfirmMessageBoxDialog::Accept() { 96 bool ConfirmMessageBoxDialog::Accept() {
70 observer_->OnConfirmMessageAccept(); 97 observer_->OnConfirmMessageAccept();
71 return true; // Dialog may now be closed. 98 return true; // Dialog may now be closed.
72 } 99 }
73 100
74 bool ConfirmMessageBoxDialog::Cancel() { 101 bool ConfirmMessageBoxDialog::Cancel() {
75 observer_->OnConfirmMessageCancel(); 102 observer_->OnConfirmMessageCancel();
76 return true; // Dialog may now be closed. 103 return true; // Dialog may now be closed.
77 } 104 }
78 105
79 void ConfirmMessageBoxDialog::Layout() { 106 void ConfirmMessageBoxDialog::Layout() {
80 gfx::Size sz = message_label_->GetPreferredSize(); 107 gfx::Size sz = message_label_->GetPreferredSize();
81 message_label_->SetBounds(kPanelHorizMargin, kPanelVertMargin, 108 message_label_->SetBounds(kPanelHorizMargin, kPanelVertMargin,
82 width() - 2 * kPanelHorizMargin, 109 width() - 2 * kPanelHorizMargin,
83 sz.height()); 110 sz.height());
84 } 111 }
85 112
86 gfx::Size ConfirmMessageBoxDialog::GetPreferredSize() { 113 gfx::Size ConfirmMessageBoxDialog::GetPreferredSize() {
87 return gfx::Size(views::Window::GetLocalizedContentsSize( 114 return preferred_size_;
88 IDS_CONFIRM_MESSAGE_BOX_DEFAULT_WIDTH_CHARS,
89 IDS_CONFIRM_MESSAGE_BOX_DEFAULT_HEIGHT_LINES));
90 } 115 }
OLDNEW
« no previous file with comments | « chrome/browser/views/confirm_message_box_dialog.h ('k') | chrome/browser/views/options/content_page_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698