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

Side by Side Diff: ui/views/controls/label.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 | « ui/ui_unittests.gypi ('k') | ui/views/controls/styled_label.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 "ui/views/controls/label.h" 5 #include "ui/views/controls/label.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "ui/base/accessibility/accessible_view_state.h" 17 #include "ui/base/accessibility/accessible_view_state.h"
18 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/base/text/text_elider.h"
20 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
22 #include "ui/gfx/insets.h" 21 #include "ui/gfx/insets.h"
23 #include "ui/gfx/shadow_value.h" 22 #include "ui/gfx/shadow_value.h"
23 #include "ui/gfx/text_elider.h"
24 #include "ui/gfx/text_utils.h" 24 #include "ui/gfx/text_utils.h"
25 #include "ui/native_theme/native_theme.h" 25 #include "ui/native_theme/native_theme.h"
26 #include "ui/views/background.h" 26 #include "ui/views/background.h"
27 27
28 namespace { 28 namespace {
29 29
30 // The padding for the focus border when rendering focused text. 30 // The padding for the focus border when rendering focused text.
31 const int kFocusBorderPadding = 1; 31 const int kFocusBorderPadding = 1;
32 const int kCachedSizeLimit = 10; 32 const int kCachedSizeLimit = 10;
33 33
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 void Label::CalculateDrawStringParams(string16* paint_text, 488 void Label::CalculateDrawStringParams(string16* paint_text,
489 gfx::Rect* text_bounds, 489 gfx::Rect* text_bounds,
490 int* flags) const { 490 int* flags) const {
491 DCHECK(paint_text && text_bounds && flags); 491 DCHECK(paint_text && text_bounds && flags);
492 492
493 // TODO(msw): Use ElideRectangleText to support eliding multi-line text. Once 493 // TODO(msw): Use ElideRectangleText to support eliding multi-line text. Once
494 // this is done, we can set NO_ELLIPSIS unconditionally at the bottom. 494 // this is done, we can set NO_ELLIPSIS unconditionally at the bottom.
495 if (is_multi_line_ || (elide_behavior_ == NO_ELIDE)) { 495 if (is_multi_line_ || (elide_behavior_ == NO_ELIDE)) {
496 *paint_text = text_; 496 *paint_text = text_;
497 } else if (elide_behavior_ == ELIDE_IN_MIDDLE) { 497 } else if (elide_behavior_ == ELIDE_IN_MIDDLE) {
498 *paint_text = ui::ElideText(text_, font_list_, GetAvailableRect().width(), 498 *paint_text = gfx::ElideText(text_, font_list_, GetAvailableRect().width(),
499 ui::ELIDE_IN_MIDDLE); 499 gfx::ELIDE_IN_MIDDLE);
500 } else if (elide_behavior_ == ELIDE_AT_END) { 500 } else if (elide_behavior_ == ELIDE_AT_END) {
501 *paint_text = ui::ElideText(text_, font_list_, GetAvailableRect().width(), 501 *paint_text = gfx::ElideText(text_, font_list_, GetAvailableRect().width(),
502 ui::ELIDE_AT_END); 502 gfx::ELIDE_AT_END);
503 } else { 503 } else {
504 DCHECK_EQ(ELIDE_AS_EMAIL, elide_behavior_); 504 DCHECK_EQ(ELIDE_AS_EMAIL, elide_behavior_);
505 *paint_text = ui::ElideEmail(text_, font_list_, GetAvailableRect().width()); 505 *paint_text = gfx::ElideEmail(text_, font_list_,
506 GetAvailableRect().width());
506 } 507 }
507 508
508 *text_bounds = GetTextBounds(); 509 *text_bounds = GetTextBounds();
509 *flags = ComputeDrawStringFlags(); 510 *flags = ComputeDrawStringFlags();
510 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) 511 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE))
511 *flags |= gfx::Canvas::NO_ELLIPSIS; 512 *flags |= gfx::Canvas::NO_ELLIPSIS;
512 } 513 }
513 514
514 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 515 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
515 if (!enabled_color_set_) { 516 if (!enabled_color_set_) {
(...skipping 17 matching lines...) Expand all
533 for (int i = 0; i < kCachedSizeLimit; ++i) 534 for (int i = 0; i < kCachedSizeLimit; ++i)
534 cached_heights_[i] = gfx::Size(); 535 cached_heights_[i] = gfx::Size();
535 } 536 }
536 537
537 bool Label::ShouldShowDefaultTooltip() const { 538 bool Label::ShouldShowDefaultTooltip() const {
538 return !is_multi_line_ && 539 return !is_multi_line_ &&
539 gfx::GetStringWidth(text_, font_list_) > GetAvailableRect().width(); 540 gfx::GetStringWidth(text_, font_list_) > GetAvailableRect().width();
540 } 541 }
541 542
542 } // namespace views 543 } // namespace views
OLDNEW
« no previous file with comments | « ui/ui_unittests.gypi ('k') | ui/views/controls/styled_label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698