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

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

Issue 23731010: Move text_elider to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update3 Created 7 years, 3 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 | chrome/browser/chromeos/external_protocol_dialog.cc » ('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 "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 20 matching lines...) Expand all
31 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
32 #include "grit/ash_resources.h" 32 #include "grit/ash_resources.h"
33 #include "grit/ash_strings.h" 33 #include "grit/ash_strings.h"
34 #include "skia/ext/image_operations.h" 34 #include "skia/ext/image_operations.h"
35 #include "third_party/skia/include/core/SkCanvas.h" 35 #include "third_party/skia/include/core/SkCanvas.h"
36 #include "third_party/skia/include/core/SkPaint.h" 36 #include "third_party/skia/include/core/SkPaint.h"
37 #include "third_party/skia/include/core/SkPath.h" 37 #include "third_party/skia/include/core/SkPath.h"
38 #include "ui/aura/window.h" 38 #include "ui/aura/window.h"
39 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/base/text/text_elider.h"
42 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
43 #include "ui/gfx/font.h" 42 #include "ui/gfx/font.h"
44 #include "ui/gfx/image/image.h" 43 #include "ui/gfx/image/image.h"
45 #include "ui/gfx/image/image_skia_operations.h" 44 #include "ui/gfx/image/image_skia_operations.h"
46 #include "ui/gfx/insets.h" 45 #include "ui/gfx/insets.h"
47 #include "ui/gfx/range/range.h" 46 #include "ui/gfx/range/range.h"
48 #include "ui/gfx/rect.h" 47 #include "ui/gfx/rect.h"
49 #include "ui/gfx/render_text.h" 48 #include "ui/gfx/render_text.h"
50 #include "ui/gfx/size.h" 49 #include "ui/gfx/size.h"
51 #include "ui/gfx/skia_util.h" 50 #include "ui/gfx/skia_util.h"
51 #include "ui/gfx/text_elider.h"
52 #include "ui/views/border.h" 52 #include "ui/views/border.h"
53 #include "ui/views/bubble/tray_bubble_view.h" 53 #include "ui/views/bubble/tray_bubble_view.h"
54 #include "ui/views/controls/button/button.h" 54 #include "ui/views/controls/button/button.h"
55 #include "ui/views/controls/button/custom_button.h" 55 #include "ui/views/controls/button/custom_button.h"
56 #include "ui/views/controls/image_view.h" 56 #include "ui/views/controls/image_view.h"
57 #include "ui/views/controls/label.h" 57 #include "ui/views/controls/label.h"
58 #include "ui/views/controls/link.h" 58 #include "ui/views/controls/link.h"
59 #include "ui/views/controls/link_listener.h" 59 #include "ui/views/controls/link_listener.h"
60 #include "ui/views/corewm/shadow_types.h" 60 #include "ui/views/corewm/shadow_types.h"
61 #include "ui/views/layout/box_layout.h" 61 #include "ui/views/layout/box_layout.h"
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 445
446 void PublicAccountUserDetails::Layout() { 446 void PublicAccountUserDetails::Layout() {
447 lines_.clear(); 447 lines_.clear();
448 const gfx::Rect contents_area = GetContentsBounds(); 448 const gfx::Rect contents_area = GetContentsBounds();
449 if (contents_area.IsEmpty()) 449 if (contents_area.IsEmpty())
450 return; 450 return;
451 451
452 // Word-wrap the label text. 452 // Word-wrap the label text.
453 const gfx::Font font; 453 const gfx::Font font;
454 std::vector<base::string16> lines; 454 std::vector<base::string16> lines;
455 ui::ElideRectangleText(text_, font, contents_area.width(), 455 gfx::ElideRectangleText(text_, font, contents_area.width(),
456 contents_area.height(), ui::ELIDE_LONG_WORDS, &lines); 456 contents_area.height(), gfx::ELIDE_LONG_WORDS,
457 &lines);
457 // Loop through the lines, creating a renderer for each. 458 // Loop through the lines, creating a renderer for each.
458 gfx::Point position = contents_area.origin(); 459 gfx::Point position = contents_area.origin();
459 gfx::Range display_name(gfx::Range::InvalidRange()); 460 gfx::Range display_name(gfx::Range::InvalidRange());
460 for (std::vector<base::string16>::const_iterator it = lines.begin(); 461 for (std::vector<base::string16>::const_iterator it = lines.begin();
461 it != lines.end(); ++it) { 462 it != lines.end(); ++it) {
462 gfx::RenderText* line = gfx::RenderText::CreateInstance(); 463 gfx::RenderText* line = gfx::RenderText::CreateInstance();
463 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); 464 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI);
464 line->SetText(*it); 465 line->SetText(*it);
465 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); 466 const gfx::Size size(contents_area.width(), line->GetStringSize().height());
466 line->SetDisplayRect(gfx::Rect(position, size)); 467 line->SetDisplayRect(gfx::Rect(position, size));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 bubble_view->GetMaximumSize().width() - (used_width + insets.width())); 544 bubble_view->GetMaximumSize().width() - (used_width + insets.width()));
544 // Do a binary search for the minimum width that ensures no more than three 545 // Do a binary search for the minimum width that ensures no more than three
545 // lines are needed. The lower bound is the minimum of the current bubble 546 // lines are needed. The lower bound is the minimum of the current bubble
546 // width and the width of the link (as no wrapping is permitted inside the 547 // width and the width of the link (as no wrapping is permitted inside the
547 // link). The upper bound is the maximum of the largest allowed bubble width 548 // link). The upper bound is the maximum of the largest allowed bubble width
548 // and the sum of the label text and link widths when put on a single line. 549 // and the sum of the label text and link widths when put on a single line.
549 std::vector<base::string16> lines; 550 std::vector<base::string16> lines;
550 while (min_width < max_width) { 551 while (min_width < max_width) {
551 lines.clear(); 552 lines.clear();
552 const int width = (min_width + max_width) / 2; 553 const int width = (min_width + max_width) / 2;
553 const bool too_narrow = ui::ElideRectangleText( 554 const bool too_narrow = gfx::ElideRectangleText(
554 text_, font, width, INT_MAX, ui::TRUNCATE_LONG_WORDS, &lines) != 0; 555 text_, font, width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0;
555 int line_count = lines.size(); 556 int line_count = lines.size();
556 if (!too_narrow && line_count == 3 && 557 if (!too_narrow && line_count == 3 &&
557 width - font.GetStringWidth(lines.back()) <= 558 width - font.GetStringWidth(lines.back()) <=
558 space_width + link_size.width()) { 559 space_width + link_size.width()) {
559 ++line_count; 560 ++line_count;
560 } 561 }
561 if (too_narrow || line_count > 3) 562 if (too_narrow || line_count > 3)
562 min_width = width + 1; 563 min_width = width + 1;
563 else 564 else
564 max_width = width; 565 max_width = width;
565 } 566 }
566 567
567 // Calculate the corresponding height and set the preferred size. 568 // Calculate the corresponding height and set the preferred size.
568 lines.clear(); 569 lines.clear();
569 ui::ElideRectangleText( 570 gfx::ElideRectangleText(
570 text_, font, min_width, INT_MAX, ui::TRUNCATE_LONG_WORDS, &lines); 571 text_, font, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines);
571 int line_count = lines.size(); 572 int line_count = lines.size();
572 if (min_width - font.GetStringWidth(lines.back()) <= 573 if (min_width - font.GetStringWidth(lines.back()) <=
573 space_width + link_size.width()) { 574 space_width + link_size.width()) {
574 ++line_count; 575 ++line_count;
575 } 576 }
576 const int line_height = font.GetHeight(); 577 const int line_height = font.GetHeight();
577 const int link_extra_height = std::max( 578 const int link_extra_height = std::max(
578 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); 579 link_size.height() - learn_more_->GetInsets().top() - line_height, 0);
579 preferred_size_ = gfx::Size( 580 preferred_size_ = gfx::Size(
580 min_width + insets.width(), 581 min_width + insets.width(),
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 kUserIconLargeSize : kUserIconSize; 1283 kUserIconLargeSize : kUserIconSize;
1283 1284
1284 avatar_->SetImage( 1285 avatar_->SetImage(
1285 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( 1286 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage(
1286 multiprofile_index_), 1287 multiprofile_index_),
1287 gfx::Size(icon_size, icon_size)); 1288 gfx::Size(icon_size, icon_size));
1288 } 1289 }
1289 1290
1290 } // namespace internal 1291 } // namespace internal
1291 } // namespace ash 1292 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/external_protocol_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698