OLD | NEW |
---|---|
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/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/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/native_theme/native_theme.h" | 18 #include "ui/base/native_theme/native_theme.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/base/text/text_elider.h" | 20 #include "ui/base/text/text_elider.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/color_utils.h" | 22 #include "ui/gfx/color_utils.h" |
23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
24 #include "ui/gfx/insets.h" | 24 #include "ui/gfx/insets.h" |
25 #include "ui/gfx/text_constants.h" | |
25 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
26 | 27 |
27 namespace views { | 28 namespace views { |
28 | 29 |
29 // static | 30 // static |
30 const char Label::kViewClassName[] = "views/Label"; | 31 const char Label::kViewClassName[] = "views/Label"; |
31 | 32 |
32 const int Label::kFocusBorderPadding = 1; | 33 const int Label::kFocusBorderPadding = 1; |
33 | 34 |
34 Label::Label() { | 35 Label::Label() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 void Label::SetShadowOffset(int x, int y) { | 96 void Label::SetShadowOffset(int x, int y) { |
96 shadow_offset_.SetPoint(x, y); | 97 shadow_offset_.SetPoint(x, y); |
97 } | 98 } |
98 | 99 |
99 void Label::ClearEmbellishing() { | 100 void Label::ClearEmbellishing() { |
100 has_shadow_ = false; | 101 has_shadow_ = false; |
101 } | 102 } |
102 | 103 |
103 void Label::SetHorizontalAlignment(Alignment alignment) { | 104 void Label::SetHorizontalAlignment(Alignment alignment) { |
104 // If the View's UI layout is right-to-left and directionality_mode_ is | 105 // If the View's UI layout is right-to-left and directionality_mode_ is |
105 // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment | 106 // gfx::DIRECTIONALITY_FROM_UI, we need to flip the alignment so that the |
106 // settings take into account the text directionality. | 107 // alignment settings take into account the text directionality. |
107 if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) && | 108 if (base::i18n::IsRTL() && (alignment != ALIGN_CENTER) && |
108 (alignment != ALIGN_CENTER)) | 109 (directionality_mode_ == gfx::DIRECTIONALITY_FROM_UI)) |
xji
2012/07/30 18:32:16
I can see that you are trying to re-use gfx::Direc
msw
2012/07/31 03:03:06
You're right; Label doesn't currently support gfx:
| |
109 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; | 110 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; |
110 if (horiz_alignment_ != alignment) { | 111 if (horiz_alignment_ != alignment) { |
111 horiz_alignment_ = alignment; | 112 horiz_alignment_ = alignment; |
112 SchedulePaint(); | 113 SchedulePaint(); |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 void Label::SetMultiLine(bool multi_line) { | 117 void Label::SetMultiLine(bool multi_line) { |
117 DCHECK(!multi_line || !elide_in_middle_); | 118 DCHECK(!multi_line || !elide_in_middle_); |
118 if (multi_line != is_multi_line_) { | 119 if (multi_line != is_multi_line_) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 background_color_ = ui::NativeTheme::instance()->GetSystemColor( | 356 background_color_ = ui::NativeTheme::instance()->GetSystemColor( |
356 ui::NativeTheme::kColorId_LabelBackgroundColor); | 357 ui::NativeTheme::kColorId_LabelBackgroundColor); |
357 auto_color_readability_ = true; | 358 auto_color_readability_ = true; |
358 RecalculateColors(); | 359 RecalculateColors(); |
359 horiz_alignment_ = ALIGN_CENTER; | 360 horiz_alignment_ = ALIGN_CENTER; |
360 is_multi_line_ = false; | 361 is_multi_line_ = false; |
361 allow_character_break_ = false; | 362 allow_character_break_ = false; |
362 elide_in_middle_ = false; | 363 elide_in_middle_ = false; |
363 is_email_ = false; | 364 is_email_ = false; |
364 collapse_when_hidden_ = false; | 365 collapse_when_hidden_ = false; |
365 directionality_mode_ = USE_UI_DIRECTIONALITY; | 366 directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI; |
366 paint_as_focused_ = false; | 367 paint_as_focused_ = false; |
367 has_focus_border_ = false; | 368 has_focus_border_ = false; |
368 enabled_shadow_color_ = 0; | 369 enabled_shadow_color_ = 0; |
369 disabled_shadow_color_ = 0; | 370 disabled_shadow_color_ = 0; |
370 shadow_offset_.SetPoint(1, 1); | 371 shadow_offset_.SetPoint(1, 1); |
371 has_shadow_ = false; | 372 has_shadow_ = false; |
372 | 373 |
373 SetText(text); | 374 SetText(text); |
374 } | 375 } |
375 | 376 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 return gfx::Rect(text_origin, text_size); | 427 return gfx::Rect(text_origin, text_size); |
427 } | 428 } |
428 | 429 |
429 int Label::ComputeDrawStringFlags() const { | 430 int Label::ComputeDrawStringFlags() const { |
430 int flags = 0; | 431 int flags = 0; |
431 | 432 |
432 // We can't use subpixel rendering if the background is non-opaque. | 433 // We can't use subpixel rendering if the background is non-opaque. |
433 if (SkColorGetA(background_color_) != 0xFF) | 434 if (SkColorGetA(background_color_) != 0xFF) |
434 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; | 435 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; |
435 | 436 |
436 if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) { | 437 if (directionality_mode_ == gfx::DIRECTIONALITY_FROM_TEXT) { |
437 base::i18n::TextDirection direction = | 438 const base::i18n::TextDirection direction = |
xji
2012/07/30 19:00:04
if we introduce gfx::Canvas::DIRECTIONALITY_FROM_T
msw
2012/07/31 03:03:06
I've reverted these changes in this CL and I'll fo
| |
438 base::i18n::GetFirstStrongCharacterDirection(text_); | 439 base::i18n::GetFirstStrongCharacterDirection(text_); |
439 if (direction == base::i18n::RIGHT_TO_LEFT) | 440 if (direction == base::i18n::RIGHT_TO_LEFT) |
440 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; | 441 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; |
441 else | 442 else |
442 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 443 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
443 } | 444 } |
444 | 445 |
445 if (!is_multi_line_) | 446 if (!is_multi_line_) |
446 return flags; | 447 return flags; |
447 | 448 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 ui::ELIDE_IN_MIDDLE); | 491 ui::ELIDE_IN_MIDDLE); |
491 } else { | 492 } else { |
492 *paint_text = text_; | 493 *paint_text = text_; |
493 } | 494 } |
494 | 495 |
495 *text_bounds = GetTextBounds(); | 496 *text_bounds = GetTextBounds(); |
496 *flags = ComputeDrawStringFlags(); | 497 *flags = ComputeDrawStringFlags(); |
497 } | 498 } |
498 | 499 |
499 } // namespace views | 500 } // namespace views |
OLD | NEW |