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

Side by Side Diff: ui/views/controls/message_box_view.cc

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years 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
« no previous file with comments | « ui/views/controls/message_box_view.h ('k') | ui/views/controls/prefix_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/message_box_view.h" 5 #include "ui/views/controls/message_box_view.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 26 matching lines...) Expand all
37 // 0085 ; B # Cc <control-0085> 37 // 0085 ; B # Cc <control-0085>
38 // 2029 ; B # Zp PARAGRAPH SEPARATOR 38 // 2029 ; B # Zp PARAGRAPH SEPARATOR
39 bool IsParagraphSeparator(char16 c) { 39 bool IsParagraphSeparator(char16 c) {
40 return ( c == 0x000A || c == 0x000D || c == 0x001C || c == 0x001D || 40 return ( c == 0x000A || c == 0x000D || c == 0x001C || c == 0x001D ||
41 c == 0x001E || c == 0x0085 || c == 0x2029); 41 c == 0x001E || c == 0x0085 || c == 0x2029);
42 } 42 }
43 43
44 // Splits |text| into a vector of paragraphs. 44 // Splits |text| into a vector of paragraphs.
45 // Given an example "\nabc\ndef\n\n\nhij\n", the split results should be: 45 // Given an example "\nabc\ndef\n\n\nhij\n", the split results should be:
46 // "", "abc", "def", "", "", "hij", and "". 46 // "", "abc", "def", "", "", "hij", and "".
47 void SplitStringIntoParagraphs(const string16& text, 47 void SplitStringIntoParagraphs(const base::string16& text,
48 std::vector<string16>* paragraphs) { 48 std::vector<base::string16>* paragraphs) {
49 paragraphs->clear(); 49 paragraphs->clear();
50 50
51 size_t start = 0; 51 size_t start = 0;
52 for (size_t i = 0; i < text.length(); ++i) { 52 for (size_t i = 0; i < text.length(); ++i) {
53 if (IsParagraphSeparator(text[i])) { 53 if (IsParagraphSeparator(text[i])) {
54 paragraphs->push_back(text.substr(start, i - start)); 54 paragraphs->push_back(text.substr(start, i - start));
55 start = i + 1; 55 start = i + 1;
56 } 56 }
57 } 57 }
58 paragraphs->push_back(text.substr(start, text.length() - start)); 58 paragraphs->push_back(text.substr(start, text.length() - start));
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 namespace views { 63 namespace views {
64 64
65 /////////////////////////////////////////////////////////////////////////////// 65 ///////////////////////////////////////////////////////////////////////////////
66 // MessageBoxView, public: 66 // MessageBoxView, public:
67 67
68 MessageBoxView::InitParams::InitParams(const string16& message) 68 MessageBoxView::InitParams::InitParams(const base::string16& message)
69 : options(NO_OPTIONS), 69 : options(NO_OPTIONS),
70 message(message), 70 message(message),
71 message_width(kDefaultMessageWidth), 71 message_width(kDefaultMessageWidth),
72 inter_row_vertical_spacing(kRelatedControlVerticalSpacing) {} 72 inter_row_vertical_spacing(kRelatedControlVerticalSpacing) {}
73 73
74 MessageBoxView::InitParams::~InitParams() { 74 MessageBoxView::InitParams::~InitParams() {
75 } 75 }
76 76
77 MessageBoxView::MessageBoxView(const InitParams& params) 77 MessageBoxView::MessageBoxView(const InitParams& params)
78 : prompt_field_(NULL), 78 : prompt_field_(NULL),
79 icon_(NULL), 79 icon_(NULL),
80 checkbox_(NULL), 80 checkbox_(NULL),
81 link_(NULL), 81 link_(NULL),
82 message_width_(params.message_width) { 82 message_width_(params.message_width) {
83 Init(params); 83 Init(params);
84 } 84 }
85 85
86 MessageBoxView::~MessageBoxView() {} 86 MessageBoxView::~MessageBoxView() {}
87 87
88 string16 MessageBoxView::GetInputText() { 88 base::string16 MessageBoxView::GetInputText() {
89 return prompt_field_ ? prompt_field_->text() : string16(); 89 return prompt_field_ ? prompt_field_->text() : base::string16();
90 } 90 }
91 91
92 bool MessageBoxView::IsCheckBoxSelected() { 92 bool MessageBoxView::IsCheckBoxSelected() {
93 return checkbox_ ? checkbox_->checked() : false; 93 return checkbox_ ? checkbox_->checked() : false;
94 } 94 }
95 95
96 void MessageBoxView::SetIcon(const gfx::ImageSkia& icon) { 96 void MessageBoxView::SetIcon(const gfx::ImageSkia& icon) {
97 if (!icon_) 97 if (!icon_)
98 icon_ = new ImageView(); 98 icon_ = new ImageView();
99 icon_->SetImage(icon); 99 icon_->SetImage(icon);
100 icon_->SetBounds(0, 0, icon.width(), icon.height()); 100 icon_->SetBounds(0, 0, icon.width(), icon.height());
101 ResetLayoutManager(); 101 ResetLayoutManager();
102 } 102 }
103 103
104 void MessageBoxView::SetCheckBoxLabel(const string16& label) { 104 void MessageBoxView::SetCheckBoxLabel(const base::string16& label) {
105 if (!checkbox_) 105 if (!checkbox_)
106 checkbox_ = new Checkbox(label); 106 checkbox_ = new Checkbox(label);
107 else 107 else
108 checkbox_->SetText(label); 108 checkbox_->SetText(label);
109 ResetLayoutManager(); 109 ResetLayoutManager();
110 } 110 }
111 111
112 void MessageBoxView::SetCheckBoxSelected(bool selected) { 112 void MessageBoxView::SetCheckBoxSelected(bool selected) {
113 if (!checkbox_) 113 if (!checkbox_)
114 return; 114 return;
115 checkbox_->SetChecked(selected); 115 checkbox_->SetChecked(selected);
116 } 116 }
117 117
118 void MessageBoxView::SetLink(const string16& text, LinkListener* listener) { 118 void MessageBoxView::SetLink(const base::string16& text,
119 LinkListener* listener) {
119 if (text.empty()) { 120 if (text.empty()) {
120 DCHECK(!listener); 121 DCHECK(!listener);
121 delete link_; 122 delete link_;
122 link_ = NULL; 123 link_ = NULL;
123 } else { 124 } else {
124 DCHECK(listener); 125 DCHECK(listener);
125 if (!link_) { 126 if (!link_) {
126 link_ = new Link(); 127 link_ = new Link();
127 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 128 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
128 } 129 }
(...skipping 26 matching lines...) Expand all
155 156
156 // We must not intercept Ctrl-C when we have a text box and it's focused. 157 // We must not intercept Ctrl-C when we have a text box and it's focused.
157 if (prompt_field_ && prompt_field_->HasFocus()) 158 if (prompt_field_ && prompt_field_->HasFocus())
158 return false; 159 return false;
159 160
160 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); 161 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
161 if (!clipboard) 162 if (!clipboard)
162 return false; 163 return false;
163 164
164 ui::ScopedClipboardWriter scw(clipboard, ui::CLIPBOARD_TYPE_COPY_PASTE); 165 ui::ScopedClipboardWriter scw(clipboard, ui::CLIPBOARD_TYPE_COPY_PASTE);
165 string16 text = message_labels_[0]->text(); 166 base::string16 text = message_labels_[0]->text();
166 for (size_t i = 1; i < message_labels_.size(); ++i) 167 for (size_t i = 1; i < message_labels_.size(); ++i)
167 text += message_labels_[i]->text(); 168 text += message_labels_[i]->text();
168 scw.WriteText(text); 169 scw.WriteText(text);
169 return true; 170 return true;
170 } 171 }
171 172
172 /////////////////////////////////////////////////////////////////////////////// 173 ///////////////////////////////////////////////////////////////////////////////
173 // MessageBoxView, private: 174 // MessageBoxView, private:
174 175
175 void MessageBoxView::Init(const InitParams& params) { 176 void MessageBoxView::Init(const InitParams& params) {
176 if (params.options & DETECT_DIRECTIONALITY) { 177 if (params.options & DETECT_DIRECTIONALITY) {
177 std::vector<string16> texts; 178 std::vector<base::string16> texts;
178 SplitStringIntoParagraphs(params.message, &texts); 179 SplitStringIntoParagraphs(params.message, &texts);
179 // If the text originates from a web page, its alignment is based on its 180 // If the text originates from a web page, its alignment is based on its
180 // first character with strong directionality. 181 // first character with strong directionality.
181 base::i18n::TextDirection message_direction = 182 base::i18n::TextDirection message_direction =
182 base::i18n::GetFirstStrongCharacterDirection(params.message); 183 base::i18n::GetFirstStrongCharacterDirection(params.message);
183 gfx::HorizontalAlignment alignment = 184 gfx::HorizontalAlignment alignment =
184 (message_direction == base::i18n::RIGHT_TO_LEFT) ? 185 (message_direction == base::i18n::RIGHT_TO_LEFT) ?
185 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; 186 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
186 for (size_t i = 0; i < texts.size(); ++i) { 187 for (size_t i = 0; i < texts.size(); ++i) {
187 Label* message_label = new Label(texts[i]); 188 Label* message_label = new Label(texts[i]);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 270 }
270 271
271 if (link_) { 272 if (link_) {
272 layout->AddPaddingRow(0, inter_row_vertical_spacing_); 273 layout->AddPaddingRow(0, inter_row_vertical_spacing_);
273 layout->StartRow(0, extra_column_view_set_id); 274 layout->StartRow(0, extra_column_view_set_id);
274 layout->AddView(link_); 275 layout->AddView(link_);
275 } 276 }
276 } 277 }
277 278
278 } // namespace views 279 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/message_box_view.h ('k') | ui/views/controls/prefix_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698