OLD | NEW |
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return true; | 170 return true; |
171 } | 171 } |
172 | 172 |
173 /////////////////////////////////////////////////////////////////////////////// | 173 /////////////////////////////////////////////////////////////////////////////// |
174 // MessageBoxView, private: | 174 // MessageBoxView, private: |
175 | 175 |
176 void MessageBoxView::Init(const InitParams& params) { | 176 void MessageBoxView::Init(const InitParams& params) { |
177 if (params.options & DETECT_DIRECTIONALITY) { | 177 if (params.options & DETECT_DIRECTIONALITY) { |
178 std::vector<base::string16> texts; | 178 std::vector<base::string16> texts; |
179 SplitStringIntoParagraphs(params.message, &texts); | 179 SplitStringIntoParagraphs(params.message, &texts); |
180 // If the text originates from a web page, its alignment is based on its | |
181 // first character with strong directionality. | |
182 base::i18n::TextDirection message_direction = | |
183 base::i18n::GetFirstStrongCharacterDirection(params.message); | |
184 gfx::HorizontalAlignment alignment = | |
185 (message_direction == base::i18n::RIGHT_TO_LEFT) ? | |
186 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; | |
187 for (size_t i = 0; i < texts.size(); ++i) { | 180 for (size_t i = 0; i < texts.size(); ++i) { |
188 Label* message_label = new Label(texts[i]); | 181 Label* message_label = new Label(texts[i]); |
189 // Don't set multi-line to true if the text is empty, else the label will | 182 // Avoid empty multi-line labels, which have a height of 0. |
190 // have a height of 0. | |
191 message_label->SetMultiLine(!texts[i].empty()); | 183 message_label->SetMultiLine(!texts[i].empty()); |
192 message_label->SetAllowCharacterBreak(true); | 184 message_label->SetAllowCharacterBreak(true); |
193 message_label->set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 185 message_label->set_directionality_mode(gfx::DIRECTIONALITY_FROM_TEXT); |
194 message_label->SetHorizontalAlignment(alignment); | 186 message_label->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
195 message_labels_.push_back(message_label); | 187 message_labels_.push_back(message_label); |
196 } | 188 } |
197 } else { | 189 } else { |
198 Label* message_label = new Label(params.message); | 190 Label* message_label = new Label(params.message); |
199 message_label->SetMultiLine(true); | 191 message_label->SetMultiLine(true); |
200 message_label->SetAllowCharacterBreak(true); | 192 message_label->SetAllowCharacterBreak(true); |
201 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 193 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
202 message_labels_.push_back(message_label); | 194 message_labels_.push_back(message_label); |
203 } | 195 } |
204 | 196 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 262 } |
271 | 263 |
272 if (link_) { | 264 if (link_) { |
273 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 265 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
274 layout->StartRow(0, extra_column_view_set_id); | 266 layout->StartRow(0, extra_column_view_set_id); |
275 layout->AddView(link_); | 267 layout->AddView(link_); |
276 } | 268 } |
277 } | 269 } |
278 | 270 |
279 } // namespace views | 271 } // namespace views |
OLD | NEW |