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

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

Issue 10807082: Add RenderText DirectionalityMode enum and support; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore Label::SetURL; derive the direction from display text. Created 8 years, 4 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
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/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/render_text.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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void Label::SetShadowOffset(int x, int y) { 107 void Label::SetShadowOffset(int x, int y) {
107 shadow_offset_.SetPoint(x, y); 108 shadow_offset_.SetPoint(x, y);
108 } 109 }
109 110
110 void Label::ClearEmbellishing() { 111 void Label::ClearEmbellishing() {
111 has_shadow_ = false; 112 has_shadow_ = false;
112 } 113 }
113 114
114 void Label::SetHorizontalAlignment(Alignment alignment) { 115 void Label::SetHorizontalAlignment(Alignment alignment) {
115 // If the View's UI layout is right-to-left and directionality_mode_ is 116 // If the View's UI layout is right-to-left and directionality_mode_ is
116 // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment 117 // gfx::DERIVE_FROM_UI, we need to flip the alignment so that the alignment
117 // settings take into account the text directionality. 118 // settings take into account the text directionality.
118 if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) && 119 if (base::i18n::IsRTL() && (directionality_mode_ == gfx::DERIVE_FROM_UI) &&
119 (alignment != ALIGN_CENTER)) 120 (alignment != ALIGN_CENTER))
120 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; 121 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT;
121 if (horiz_alignment_ != alignment) { 122 if (horiz_alignment_ != alignment) {
122 horiz_alignment_ = alignment; 123 horiz_alignment_ = alignment;
123 SchedulePaint(); 124 SchedulePaint();
124 } 125 }
125 } 126 }
126 127
127 void Label::SetMultiLine(bool multi_line) { 128 void Label::SetMultiLine(bool multi_line) {
128 DCHECK(!multi_line || !elide_in_middle_); 129 DCHECK(!multi_line || !elide_in_middle_);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 background_color_ = ui::NativeTheme::instance()->GetSystemColor( 367 background_color_ = ui::NativeTheme::instance()->GetSystemColor(
367 ui::NativeTheme::kColorId_LabelBackgroundColor); 368 ui::NativeTheme::kColorId_LabelBackgroundColor);
368 auto_color_readability_ = true; 369 auto_color_readability_ = true;
369 RecalculateColors(); 370 RecalculateColors();
370 horiz_alignment_ = ALIGN_CENTER; 371 horiz_alignment_ = ALIGN_CENTER;
371 is_multi_line_ = false; 372 is_multi_line_ = false;
372 allow_character_break_ = false; 373 allow_character_break_ = false;
373 elide_in_middle_ = false; 374 elide_in_middle_ = false;
374 is_email_ = false; 375 is_email_ = false;
375 collapse_when_hidden_ = false; 376 collapse_when_hidden_ = false;
376 directionality_mode_ = USE_UI_DIRECTIONALITY; 377 directionality_mode_ = gfx::DERIVE_FROM_UI;
377 paint_as_focused_ = false; 378 paint_as_focused_ = false;
378 has_focus_border_ = false; 379 has_focus_border_ = false;
379 enabled_shadow_color_ = 0; 380 enabled_shadow_color_ = 0;
380 disabled_shadow_color_ = 0; 381 disabled_shadow_color_ = 0;
381 shadow_offset_.SetPoint(1, 1); 382 shadow_offset_.SetPoint(1, 1);
382 has_shadow_ = false; 383 has_shadow_ = false;
383 384
384 SetText(text); 385 SetText(text);
385 } 386 }
386 387
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return gfx::Rect(text_origin, text_size); 438 return gfx::Rect(text_origin, text_size);
438 } 439 }
439 440
440 int Label::ComputeDrawStringFlags() const { 441 int Label::ComputeDrawStringFlags() const {
441 int flags = 0; 442 int flags = 0;
442 443
443 // We can't use subpixel rendering if the background is non-opaque. 444 // We can't use subpixel rendering if the background is non-opaque.
444 if (SkColorGetA(background_color_) != 0xFF) 445 if (SkColorGetA(background_color_) != 0xFF)
445 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; 446 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
446 447
447 if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) { 448 if (directionality_mode_ == gfx::DERIVE_FROM_TEXT) {
448 base::i18n::TextDirection direction = 449 const base::i18n::TextDirection direction =
449 base::i18n::GetFirstStrongCharacterDirection(text_); 450 base::i18n::GetFirstStrongCharacterDirection(text_);
450 if (direction == base::i18n::RIGHT_TO_LEFT) 451 if (direction == base::i18n::RIGHT_TO_LEFT)
451 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; 452 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
452 else 453 else
453 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; 454 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
454 } 455 }
455 456
456 if (!is_multi_line_) 457 if (!is_multi_line_)
457 return flags; 458 return flags;
458 459
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 ui::ELIDE_IN_MIDDLE); 519 ui::ELIDE_IN_MIDDLE);
519 } else { 520 } else {
520 *paint_text = text_; 521 *paint_text = text_;
521 } 522 }
522 523
523 *text_bounds = GetTextBounds(); 524 *text_bounds = GetTextBounds();
524 *flags = ComputeDrawStringFlags(); 525 *flags = ComputeDrawStringFlags();
525 } 526 }
526 527
527 } // namespace views 528 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698