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

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

Issue 24012002: Move Range code to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d 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/input_method/textinput_surroundingtext_browsertest.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 19 matching lines...) Expand all
30 #include "base/strings/string_util.h" 30 #include "base/strings/string_util.h"
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/range/range.h"
41 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
42 #include "ui/base/text/text_elider.h" 41 #include "ui/base/text/text_elider.h"
43 #include "ui/gfx/canvas.h" 42 #include "ui/gfx/canvas.h"
44 #include "ui/gfx/font.h" 43 #include "ui/gfx/font.h"
45 #include "ui/gfx/image/image.h" 44 #include "ui/gfx/image/image.h"
46 #include "ui/gfx/image/image_skia_operations.h" 45 #include "ui/gfx/image/image_skia_operations.h"
47 #include "ui/gfx/insets.h" 46 #include "ui/gfx/insets.h"
47 #include "ui/gfx/range/range.h"
48 #include "ui/gfx/rect.h" 48 #include "ui/gfx/rect.h"
49 #include "ui/gfx/render_text.h" 49 #include "ui/gfx/render_text.h"
50 #include "ui/gfx/size.h" 50 #include "ui/gfx/size.h"
51 #include "ui/gfx/skia_util.h" 51 #include "ui/gfx/skia_util.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"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ui::ElideRectangleText(text_, font, contents_area.width(),
456 contents_area.height(), ui::ELIDE_LONG_WORDS, &lines); 456 contents_area.height(), ui::ELIDE_LONG_WORDS, &lines);
457 // Loop through the lines, creating a renderer for each. 457 // Loop through the lines, creating a renderer for each.
458 gfx::Point position = contents_area.origin(); 458 gfx::Point position = contents_area.origin();
459 ui::Range display_name(ui::Range::InvalidRange()); 459 gfx::Range display_name(gfx::Range::InvalidRange());
460 for (std::vector<base::string16>::const_iterator it = lines.begin(); 460 for (std::vector<base::string16>::const_iterator it = lines.begin();
461 it != lines.end(); ++it) { 461 it != lines.end(); ++it) {
462 gfx::RenderText* line = gfx::RenderText::CreateInstance(); 462 gfx::RenderText* line = gfx::RenderText::CreateInstance();
463 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); 463 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI);
464 line->SetText(*it); 464 line->SetText(*it);
465 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); 465 const gfx::Size size(contents_area.width(), line->GetStringSize().height());
466 line->SetDisplayRect(gfx::Rect(position, size)); 466 line->SetDisplayRect(gfx::Rect(position, size));
467 position.set_y(position.y() + size.height()); 467 position.set_y(position.y() + size.height());
468 468
469 // Set the default text color for the line. 469 // Set the default text color for the line.
470 line->SetColor(kPublicAccountUserCardTextColor); 470 line->SetColor(kPublicAccountUserCardTextColor);
471 471
472 // If a range of the line contains the user's display name, apply a custom 472 // If a range of the line contains the user's display name, apply a custom
473 // text color to it. 473 // text color to it.
474 if (display_name.is_empty()) 474 if (display_name.is_empty())
475 display_name.set_start(it->find(kDisplayNameMark)); 475 display_name.set_start(it->find(kDisplayNameMark));
476 if (!display_name.is_empty()) { 476 if (!display_name.is_empty()) {
477 display_name.set_end( 477 display_name.set_end(
478 it->find(kDisplayNameMark, display_name.start() + 1)); 478 it->find(kDisplayNameMark, display_name.start() + 1));
479 ui::Range line_range(0, it->size()); 479 gfx::Range line_range(0, it->size());
480 line->ApplyColor(kPublicAccountUserCardNameColor, 480 line->ApplyColor(kPublicAccountUserCardNameColor,
481 display_name.Intersect(line_range)); 481 display_name.Intersect(line_range));
482 // Update the range for the next line. 482 // Update the range for the next line.
483 if (display_name.end() >= line_range.end()) 483 if (display_name.end() >= line_range.end())
484 display_name.set_start(0); 484 display_name.set_start(0);
485 else 485 else
486 display_name = ui::Range::InvalidRange(); 486 display_name = gfx::Range::InvalidRange();
487 } 487 }
488 488
489 lines_.push_back(line); 489 lines_.push_back(line);
490 } 490 }
491 491
492 // Position the link after the label text, separated by a space. If it does 492 // Position the link after the label text, separated by a space. If it does
493 // not fit onto the last line of the text, wrap the link onto its own line. 493 // not fit onto the last line of the text, wrap the link onto its own line.
494 const gfx::Size last_line_size = lines_.back()->GetStringSize(); 494 const gfx::Size last_line_size = lines_.back()->GetStringSize();
495 const int space_width = font.GetStringWidth(ASCIIToUTF16(" ")); 495 const int space_width = font.GetStringWidth(ASCIIToUTF16(" "));
496 const gfx::Size link_size = learn_more_->GetPreferredSize(); 496 const gfx::Size link_size = learn_more_->GetPreferredSize();
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 kUserIconLargeSize : kUserIconSize; 1282 kUserIconLargeSize : kUserIconSize;
1283 1283
1284 avatar_->SetImage( 1284 avatar_->SetImage(
1285 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( 1285 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage(
1286 multiprofile_index_), 1286 multiprofile_index_),
1287 gfx::Size(icon_size, icon_size)); 1287 gfx::Size(icon_size, icon_size));
1288 } 1288 }
1289 1289
1290 } // namespace internal 1290 } // namespace internal
1291 } // namespace ash 1291 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/textinput_surroundingtext_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698