| 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; |
| 180 for (size_t i = 0; i < texts.size(); ++i) { | 187 for (size_t i = 0; i < texts.size(); ++i) { |
| 181 Label* message_label = new Label(texts[i]); | 188 Label* message_label = new Label(texts[i]); |
| 182 // Avoid empty multi-line labels, which have a height of 0. | 189 // Don't set multi-line to true if the text is empty, else the label will |
| 190 // have a height of 0. |
| 183 message_label->SetMultiLine(!texts[i].empty()); | 191 message_label->SetMultiLine(!texts[i].empty()); |
| 184 message_label->SetAllowCharacterBreak(true); | 192 message_label->SetAllowCharacterBreak(true); |
| 185 message_label->set_directionality_mode(gfx::DIRECTIONALITY_FROM_TEXT); | 193 message_label->set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 186 message_label->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | 194 message_label->SetHorizontalAlignment(alignment); |
| 187 message_labels_.push_back(message_label); | 195 message_labels_.push_back(message_label); |
| 188 } | 196 } |
| 189 } else { | 197 } else { |
| 190 Label* message_label = new Label(params.message); | 198 Label* message_label = new Label(params.message); |
| 191 message_label->SetMultiLine(true); | 199 message_label->SetMultiLine(true); |
| 192 message_label->SetAllowCharacterBreak(true); | 200 message_label->SetAllowCharacterBreak(true); |
| 193 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 201 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 194 message_labels_.push_back(message_label); | 202 message_labels_.push_back(message_label); |
| 195 } | 203 } |
| 196 | 204 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 270 } |
| 263 | 271 |
| 264 if (link_) { | 272 if (link_) { |
| 265 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 273 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 266 layout->StartRow(0, extra_column_view_set_id); | 274 layout->StartRow(0, extra_column_view_set_id); |
| 267 layout->AddView(link_); | 275 layout->AddView(link_); |
| 268 } | 276 } |
| 269 } | 277 } |
| 270 | 278 |
| 271 } // namespace views | 279 } // namespace views |
| OLD | NEW |