| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/system/user/user_card_view.h" | 5 #include "ash/system/user/user_card_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/session/session_state_delegate.h" | 10 #include "ash/session/session_state_delegate.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 // Word-wrap the label text. | 197 // Word-wrap the label text. |
| 198 const gfx::FontList font_list; | 198 const gfx::FontList font_list; |
| 199 std::vector<base::string16> lines; | 199 std::vector<base::string16> lines; |
| 200 gfx::ElideRectangleText(text_, | 200 gfx::ElideRectangleText(text_, |
| 201 font_list, | 201 font_list, |
| 202 contents_area.width(), | 202 contents_area.width(), |
| 203 contents_area.height(), | 203 contents_area.height(), |
| 204 gfx::ELIDE_LONG_WORDS, | 204 gfx::ELIDE_LONG_WORDS, |
| 205 &lines); | 205 &lines, |
| 206 nullptr); |
| 206 // Loop through the lines, creating a renderer for each. | 207 // Loop through the lines, creating a renderer for each. |
| 207 gfx::Point position = contents_area.origin(); | 208 gfx::Point position = contents_area.origin(); |
| 208 gfx::Range display_name(gfx::Range::InvalidRange()); | 209 gfx::Range display_name(gfx::Range::InvalidRange()); |
| 209 for (std::vector<base::string16>::const_iterator it = lines.begin(); | 210 for (std::vector<base::string16>::const_iterator it = lines.begin(); |
| 210 it != lines.end(); | 211 it != lines.end(); |
| 211 ++it) { | 212 ++it) { |
| 212 gfx::RenderText* line = gfx::RenderText::CreateInstance(); | 213 gfx::RenderText* line = gfx::RenderText::CreateInstance(); |
| 213 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); | 214 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); |
| 214 line->SetText(*it); | 215 line->SetText(*it); |
| 215 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); | 216 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // and the sum of the label text and link widths when put on a single line. | 297 // and the sum of the label text and link widths when put on a single line. |
| 297 std::vector<base::string16> lines; | 298 std::vector<base::string16> lines; |
| 298 while (min_width < max_width) { | 299 while (min_width < max_width) { |
| 299 lines.clear(); | 300 lines.clear(); |
| 300 const int width = (min_width + max_width) / 2; | 301 const int width = (min_width + max_width) / 2; |
| 301 const bool too_narrow = gfx::ElideRectangleText(text_, | 302 const bool too_narrow = gfx::ElideRectangleText(text_, |
| 302 font_list, | 303 font_list, |
| 303 width, | 304 width, |
| 304 INT_MAX, | 305 INT_MAX, |
| 305 gfx::TRUNCATE_LONG_WORDS, | 306 gfx::TRUNCATE_LONG_WORDS, |
| 306 &lines) != 0; | 307 &lines, |
| 308 nullptr) != 0; |
| 307 int line_count = lines.size(); | 309 int line_count = lines.size(); |
| 308 if (!too_narrow && line_count == 3 && | 310 if (!too_narrow && line_count == 3 && |
| 309 width - gfx::GetStringWidth(lines.back(), font_list) <= | 311 width - gfx::GetStringWidth(lines.back(), font_list) <= |
| 310 space_width + link_size.width()) | 312 space_width + link_size.width()) |
| 311 ++line_count; | 313 ++line_count; |
| 312 if (too_narrow || line_count > 3) | 314 if (too_narrow || line_count > 3) |
| 313 min_width = width + 1; | 315 min_width = width + 1; |
| 314 else | 316 else |
| 315 max_width = width; | 317 max_width = width; |
| 316 } | 318 } |
| 317 | 319 |
| 318 // Calculate the corresponding height and set the preferred size. | 320 // Calculate the corresponding height and set the preferred size. |
| 319 lines.clear(); | 321 lines.clear(); |
| 320 gfx::ElideRectangleText( | 322 gfx::ElideRectangleText(text_, |
| 321 text_, font_list, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); | 323 font_list, |
| 324 min_width, |
| 325 INT_MAX, |
| 326 gfx::TRUNCATE_LONG_WORDS, |
| 327 &lines, |
| 328 nullptr); |
| 322 int line_count = lines.size(); | 329 int line_count = lines.size(); |
| 323 if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= | 330 if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= |
| 324 space_width + link_size.width()) { | 331 space_width + link_size.width()) { |
| 325 ++line_count; | 332 ++line_count; |
| 326 } | 333 } |
| 327 const int line_height = font_list.GetHeight(); | 334 const int line_height = font_list.GetHeight(); |
| 328 const int link_extra_height = std::max( | 335 const int link_extra_height = std::max( |
| 329 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 336 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
| 330 preferred_size_ = | 337 preferred_size_ = |
| 331 gfx::Size(min_width + insets.width(), | 338 gfx::Size(min_width + insets.width(), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 content::BrowserContext* context = | 476 content::BrowserContext* context = |
| 470 delegate->GetBrowserContextByIndex(multiprofile_index); | 477 delegate->GetBrowserContextByIndex(multiprofile_index); |
| 471 icon->SetImage(delegate->GetUserInfo(context)->GetImage(), | 478 icon->SetImage(delegate->GetUserInfo(context)->GetImage(), |
| 472 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 479 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
| 473 } | 480 } |
| 474 return icon; | 481 return icon; |
| 475 } | 482 } |
| 476 | 483 |
| 477 } // namespace tray | 484 } // namespace tray |
| 478 } // namespace ash | 485 } // namespace ash |
| OLD | NEW |