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

Side by Side Diff: ash/system/user/tray_user.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 7 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
« no previous file with comments | « no previous file | ui/gfx/canvas.h » ('j') | ui/gfx/canvas.h » ('J')
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 "ash/system/user/tray_user.h" 5 #include "ash/system/user/tray_user.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <climits> 8 #include <climits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 448
449 void PublicAccountUserDetails::Layout() { 449 void PublicAccountUserDetails::Layout() {
450 lines_.clear(); 450 lines_.clear();
451 const gfx::Rect contents_area = GetContentsBounds(); 451 const gfx::Rect contents_area = GetContentsBounds();
452 if (contents_area.IsEmpty()) 452 if (contents_area.IsEmpty())
453 return; 453 return;
454 454
455 // Word-wrap the label text. 455 // Word-wrap the label text.
456 const gfx::Font font; 456 const gfx::Font font;
457 std::vector<base::string16> lines; 457 std::vector<base::string16> lines;
458 gfx::ElideRectangleText(text_, font, contents_area.width(), 458 gfx::ElideRectangleText(text_,
459 contents_area.height(), gfx::ELIDE_LONG_WORDS, 459 font,
460 static_cast<float>(contents_area.width()),
msw 2013/09/27 21:54:48 Won't int->float implicit type conversion work her
jianli 2013/10/01 00:32:58 Reverted. Changed INT_MAX to FLT_MAX in the follow
461 static_cast<float>(contents_area.height()),
462 gfx::ELIDE_LONG_WORDS,
460 &lines); 463 &lines);
461 // Loop through the lines, creating a renderer for each. 464 // Loop through the lines, creating a renderer for each.
462 gfx::Point position = contents_area.origin(); 465 gfx::Point position = contents_area.origin();
463 gfx::Range display_name(gfx::Range::InvalidRange()); 466 gfx::Range display_name(gfx::Range::InvalidRange());
464 for (std::vector<base::string16>::const_iterator it = lines.begin(); 467 for (std::vector<base::string16>::const_iterator it = lines.begin();
465 it != lines.end(); ++it) { 468 it != lines.end(); ++it) {
466 gfx::RenderText* line = gfx::RenderText::CreateInstance(); 469 gfx::RenderText* line = gfx::RenderText::CreateInstance();
467 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); 470 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI);
468 line->SetText(*it); 471 line->SetText(*it);
469 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); 472 const gfx::Size size(contents_area.width(), line->GetStringSize().height());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // Do a binary search for the minimum width that ensures no more than three 551 // Do a binary search for the minimum width that ensures no more than three
549 // lines are needed. The lower bound is the minimum of the current bubble 552 // lines are needed. The lower bound is the minimum of the current bubble
550 // width and the width of the link (as no wrapping is permitted inside the 553 // width and the width of the link (as no wrapping is permitted inside the
551 // link). The upper bound is the maximum of the largest allowed bubble width 554 // link). The upper bound is the maximum of the largest allowed bubble width
552 // and the sum of the label text and link widths when put on a single line. 555 // and the sum of the label text and link widths when put on a single line.
553 std::vector<base::string16> lines; 556 std::vector<base::string16> lines;
554 while (min_width < max_width) { 557 while (min_width < max_width) {
555 lines.clear(); 558 lines.clear();
556 const int width = (min_width + max_width) / 2; 559 const int width = (min_width + max_width) / 2;
557 const bool too_narrow = gfx::ElideRectangleText( 560 const bool too_narrow = gfx::ElideRectangleText(
558 text_, font, width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0; 561 text_, font, static_cast<float>(width), static_cast<float>(INT_MAX),
562 gfx::TRUNCATE_LONG_WORDS, &lines) != 0;
559 int line_count = lines.size(); 563 int line_count = lines.size();
560 if (!too_narrow && line_count == 3 && 564 if (!too_narrow && line_count == 3 &&
561 width - font.GetStringWidth(lines.back()) <= 565 width - font.GetStringWidth(lines.back()) <=
562 space_width + link_size.width()) { 566 space_width + link_size.width()) {
563 ++line_count; 567 ++line_count;
564 } 568 }
565 if (too_narrow || line_count > 3) 569 if (too_narrow || line_count > 3)
566 min_width = width + 1; 570 min_width = width + 1;
567 else 571 else
568 max_width = width; 572 max_width = width;
569 } 573 }
570 574
571 // Calculate the corresponding height and set the preferred size. 575 // Calculate the corresponding height and set the preferred size.
572 lines.clear(); 576 lines.clear();
573 gfx::ElideRectangleText( 577 gfx::ElideRectangleText(
574 text_, font, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); 578 text_, font, static_cast<float>(min_width), static_cast<float>(INT_MAX),
579 gfx::TRUNCATE_LONG_WORDS, &lines);
575 int line_count = lines.size(); 580 int line_count = lines.size();
576 if (min_width - font.GetStringWidth(lines.back()) <= 581 if (min_width - font.GetStringWidth(lines.back()) <=
577 space_width + link_size.width()) { 582 space_width + link_size.width()) {
578 ++line_count; 583 ++line_count;
579 } 584 }
580 const int line_height = font.GetHeight(); 585 const int line_height = font.GetHeight();
581 const int link_extra_height = std::max( 586 const int link_extra_height = std::max(
582 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); 587 link_size.height() - learn_more_->GetInsets().top() - line_height, 0);
583 preferred_size_ = gfx::Size( 588 preferred_size_ = gfx::Size(
584 min_width + insets.width(), 589 min_width + insets.width(),
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 kUserIconLargeSize : kUserIconSize; 1296 kUserIconLargeSize : kUserIconSize;
1292 1297
1293 avatar_->SetImage( 1298 avatar_->SetImage(
1294 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( 1299 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage(
1295 multiprofile_index_), 1300 multiprofile_index_),
1296 gfx::Size(icon_size, icon_size)); 1301 gfx::Size(icon_size, icon_size));
1297 } 1302 }
1298 1303
1299 } // namespace internal 1304 } // namespace internal
1300 } // namespace ash 1305 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/canvas.h » ('j') | ui/gfx/canvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698