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

Side by Side Diff: ui/views/controls/label.cc

Issue 343513002: Refactor views::Label and gfx::RenderText shadow functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove forbidden static FontList. Created 6 years, 6 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/views/controls/label.h ('k') | ui/views/examples/label_example.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/accessibility/ax_view_state.h" 17 #include "ui/accessibility/ax_view_state.h"
18 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
21 #include "ui/gfx/insets.h" 21 #include "ui/gfx/insets.h"
22 #include "ui/gfx/shadow_value.h"
23 #include "ui/gfx/text_elider.h" 22 #include "ui/gfx/text_elider.h"
24 #include "ui/gfx/text_utils.h" 23 #include "ui/gfx/text_utils.h"
25 #include "ui/gfx/utf16_indexing.h" 24 #include "ui/gfx/utf16_indexing.h"
26 #include "ui/native_theme/native_theme.h" 25 #include "ui/native_theme/native_theme.h"
27 #include "ui/views/background.h" 26 #include "ui/views/background.h"
28 27
29 namespace { 28 namespace {
30 29
31 const int kCachedSizeLimit = 10; 30 const int kCachedSizeLimit = 10;
32 const base::char16 kPasswordReplacementChar = '*'; 31 const base::char16 kPasswordReplacementChar = '*';
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 disabled_color_set_ = true; 97 disabled_color_set_ = true;
99 RecalculateColors(); 98 RecalculateColors();
100 } 99 }
101 100
102 void Label::SetBackgroundColor(SkColor color) { 101 void Label::SetBackgroundColor(SkColor color) {
103 background_color_ = color; 102 background_color_ = color;
104 background_color_set_ = true; 103 background_color_set_ = true;
105 RecalculateColors(); 104 RecalculateColors();
106 } 105 }
107 106
108 void Label::SetShadowColors(SkColor enabled_color, SkColor disabled_color) {
109 enabled_shadow_color_ = enabled_color;
110 disabled_shadow_color_ = disabled_color;
111 has_shadow_ = true;
112 }
113
114 void Label::SetShadowOffset(int x, int y) {
115 shadow_offset_.SetPoint(x, y);
116 }
117
118 void Label::ClearEmbellishing() {
119 has_shadow_ = false;
120 }
121
122 void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { 107 void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
123 // If the UI layout is right-to-left, flip the alignment direction. 108 // If the UI layout is right-to-left, flip the alignment direction.
124 if (base::i18n::IsRTL() && 109 if (base::i18n::IsRTL() &&
125 (alignment == gfx::ALIGN_LEFT || alignment == gfx::ALIGN_RIGHT)) { 110 (alignment == gfx::ALIGN_LEFT || alignment == gfx::ALIGN_RIGHT)) {
126 alignment = (alignment == gfx::ALIGN_LEFT) ? 111 alignment = (alignment == gfx::ALIGN_LEFT) ?
127 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; 112 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
128 } 113 }
129 if (horizontal_alignment_ != alignment) { 114 if (horizontal_alignment_ != alignment) {
130 horizontal_alignment_ = alignment; 115 horizontal_alignment_ = alignment;
131 SchedulePaint(); 116 SchedulePaint();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 312 }
328 313
329 void Label::PaintText(gfx::Canvas* canvas, 314 void Label::PaintText(gfx::Canvas* canvas,
330 const base::string16& text, 315 const base::string16& text,
331 const gfx::Rect& text_bounds, 316 const gfx::Rect& text_bounds,
332 int flags) { 317 int flags) {
333 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; 318 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
334 if (elide_behavior_ == gfx::FADE_TAIL) { 319 if (elide_behavior_ == gfx::FADE_TAIL) {
335 canvas->DrawFadedString(text, font_list_, color, text_bounds, flags); 320 canvas->DrawFadedString(text, font_list_, color, text_bounds, flags);
336 } else { 321 } else {
337 gfx::ShadowValues shadows;
338 if (has_shadow_) {
339 shadows.push_back(gfx::ShadowValue(shadow_offset_, shadow_blur_,
340 enabled() ? enabled_shadow_color_ : disabled_shadow_color_));
341 }
342 canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds, 322 canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds,
343 line_height_, flags, shadows); 323 line_height_, flags, shadows_);
344 324
345 if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) { 325 if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) {
346 canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_, 326 canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_,
347 text_bounds, flags); 327 text_bounds, flags);
348 } 328 }
349 } 329 }
350 330
351 if (HasFocus()) { 331 if (HasFocus()) {
352 gfx::Rect focus_bounds = text_bounds; 332 gfx::Rect focus_bounds = text_bounds;
353 focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); 333 focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 auto_color_readability_ = true; 386 auto_color_readability_ = true;
407 UpdateColorsFromTheme(ui::NativeTheme::instance()); 387 UpdateColorsFromTheme(ui::NativeTheme::instance());
408 horizontal_alignment_ = gfx::ALIGN_CENTER; 388 horizontal_alignment_ = gfx::ALIGN_CENTER;
409 line_height_ = 0; 389 line_height_ = 0;
410 is_multi_line_ = false; 390 is_multi_line_ = false;
411 is_obscured_ = false; 391 is_obscured_ = false;
412 allow_character_break_ = false; 392 allow_character_break_ = false;
413 elide_behavior_ = gfx::ELIDE_TAIL; 393 elide_behavior_ = gfx::ELIDE_TAIL;
414 collapse_when_hidden_ = false; 394 collapse_when_hidden_ = false;
415 directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI; 395 directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI;
416 enabled_shadow_color_ = 0;
417 disabled_shadow_color_ = 0;
418 shadow_offset_.SetPoint(1, 1);
419 has_shadow_ = false;
420 shadow_blur_ = 0;
421 halo_color_ = SK_ColorTRANSPARENT; 396 halo_color_ = SK_ColorTRANSPARENT;
422 cached_heights_.resize(kCachedSizeLimit); 397 cached_heights_.resize(kCachedSizeLimit);
423 ResetCachedSize(); 398 ResetCachedSize();
424 399
425 SetText(text); 400 SetText(text);
426 } 401 }
427 402
428 void Label::RecalculateColors() { 403 void Label::RecalculateColors() {
429 actual_enabled_color_ = auto_color_readability_ ? 404 actual_enabled_color_ = auto_color_readability_ ?
430 color_utils::GetReadableColor(requested_enabled_color_, 405 color_utils::GetReadableColor(requested_enabled_color_,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 cached_heights_[i] = gfx::Size(); 538 cached_heights_[i] = gfx::Size();
564 } 539 }
565 540
566 bool Label::ShouldShowDefaultTooltip() const { 541 bool Label::ShouldShowDefaultTooltip() const {
567 return !is_multi_line_ && !is_obscured_ && 542 return !is_multi_line_ && !is_obscured_ &&
568 gfx::GetStringWidth(layout_text(), font_list_) > 543 gfx::GetStringWidth(layout_text(), font_list_) >
569 GetAvailableRect().width(); 544 GetAvailableRect().width();
570 } 545 }
571 546
572 } // namespace views 547 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/examples/label_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698