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

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

Issue 10695101: Remove code that forces text directionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove directionality forcing and modes; may be incorrect... Created 8 years, 5 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/controls/label_unittest.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>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 void Label::SetShadowOffset(int x, int y) { 106 void Label::SetShadowOffset(int x, int y) {
107 shadow_offset_.SetPoint(x, y); 107 shadow_offset_.SetPoint(x, y);
108 } 108 }
109 109
110 void Label::ClearEmbellishing() { 110 void Label::ClearEmbellishing() {
111 has_shadow_ = false; 111 has_shadow_ = false;
112 } 112 }
113 113
114 void Label::SetHorizontalAlignment(Alignment alignment) { 114 void Label::SetHorizontalAlignment(Alignment alignment) {
115 // If the View's UI layout is right-to-left and directionality_mode_ is 115 // TODO(msw): Change Alignment to LEADING/TRAILING?
116 // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment 116 // TODO(msw): Check (and potentially flip) the alignment when setting text?
117 // settings take into account the text directionality. 117 // TODO(msw): Check against multi-line label regressions (not RenderText)...
118 if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) && 118 // If the string's directionality is right-to-left, flip the alignment.
119 (alignment != ALIGN_CENTER)) 119 if (base::i18n::GetFirstStrongCharacterDirection(text()) ==
120 base::i18n::RIGHT_TO_LEFT &&
121 alignment != ALIGN_CENTER) {
120 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; 122 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT;
123 }
xji 2012/07/10 19:59:57 so the alignment is also based on text directional
121 if (horiz_alignment_ != alignment) { 124 if (horiz_alignment_ != alignment) {
122 horiz_alignment_ = alignment; 125 horiz_alignment_ = alignment;
123 SchedulePaint(); 126 SchedulePaint();
124 } 127 }
125 } 128 }
126 129
127 void Label::SetMultiLine(bool multi_line) { 130 void Label::SetMultiLine(bool multi_line) {
128 DCHECK(!multi_line || !elide_in_middle_); 131 DCHECK(!multi_line || !elide_in_middle_);
129 if (multi_line != is_multi_line_) { 132 if (multi_line != is_multi_line_) {
130 is_multi_line_ = multi_line; 133 is_multi_line_ = multi_line;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 background_color_ = ui::NativeTheme::instance()->GetSystemColor( 369 background_color_ = ui::NativeTheme::instance()->GetSystemColor(
367 ui::NativeTheme::kColorId_LabelBackgroundColor); 370 ui::NativeTheme::kColorId_LabelBackgroundColor);
368 auto_color_readability_ = true; 371 auto_color_readability_ = true;
369 RecalculateColors(); 372 RecalculateColors();
370 horiz_alignment_ = ALIGN_CENTER; 373 horiz_alignment_ = ALIGN_CENTER;
371 is_multi_line_ = false; 374 is_multi_line_ = false;
372 allow_character_break_ = false; 375 allow_character_break_ = false;
373 elide_in_middle_ = false; 376 elide_in_middle_ = false;
374 is_email_ = false; 377 is_email_ = false;
375 collapse_when_hidden_ = false; 378 collapse_when_hidden_ = false;
376 directionality_mode_ = USE_UI_DIRECTIONALITY;
377 paint_as_focused_ = false; 379 paint_as_focused_ = false;
378 has_focus_border_ = false; 380 has_focus_border_ = false;
379 enabled_shadow_color_ = 0; 381 enabled_shadow_color_ = 0;
380 disabled_shadow_color_ = 0; 382 disabled_shadow_color_ = 0;
381 shadow_offset_.SetPoint(1, 1); 383 shadow_offset_.SetPoint(1, 1);
382 has_shadow_ = false; 384 has_shadow_ = false;
383 385
384 SetText(text); 386 SetText(text);
385 } 387 }
386 388
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return gfx::Rect(text_origin, text_size); 439 return gfx::Rect(text_origin, text_size);
438 } 440 }
439 441
440 int Label::ComputeDrawStringFlags() const { 442 int Label::ComputeDrawStringFlags() const {
441 int flags = 0; 443 int flags = 0;
442 444
443 // We can't use subpixel rendering if the background is non-opaque. 445 // We can't use subpixel rendering if the background is non-opaque.
444 if (SkColorGetA(background_color_) != 0xFF) 446 if (SkColorGetA(background_color_) != 0xFF)
445 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; 447 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
446 448
447 if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
448 base::i18n::TextDirection direction =
449 base::i18n::GetFirstStrongCharacterDirection(text_);
450 if (direction == base::i18n::RIGHT_TO_LEFT)
451 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
452 else
453 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
454 }
455
456 if (!is_multi_line_) 449 if (!is_multi_line_)
457 return flags; 450 return flags;
458 451
459 flags |= gfx::Canvas::MULTI_LINE; 452 flags |= gfx::Canvas::MULTI_LINE;
460 #if !defined(OS_WIN) 453 #if !defined(OS_WIN)
461 // Don't elide multiline labels on Linux. 454 // Don't elide multiline labels on Linux.
462 // Todo(davemoore): Do we depend on eliding multiline text? 455 // Todo(davemoore): Do we depend on eliding multiline text?
463 // Pango insists on limiting the number of lines to one if text is 456 // Pango insists on limiting the number of lines to one if text is
464 // elided. You can get around this if you can pass a maximum height 457 // elided. You can get around this if you can pass a maximum height
465 // but we don't currently have that data when we call the pango code. 458 // but we don't currently have that data when we call the pango code.
(...skipping 26 matching lines...) Expand all
492 void Label::CalculateDrawStringParams(string16* paint_text, 485 void Label::CalculateDrawStringParams(string16* paint_text,
493 gfx::Rect* text_bounds, 486 gfx::Rect* text_bounds,
494 int* flags) const { 487 int* flags) const {
495 DCHECK(paint_text && text_bounds && flags); 488 DCHECK(paint_text && text_bounds && flags);
496 489
497 if (!url_.is_empty()) { 490 if (!url_.is_empty()) {
498 // TODO(jungshik) : Figure out how to get 'intl.accept_languages' 491 // TODO(jungshik) : Figure out how to get 'intl.accept_languages'
499 // preference and use it when calling ElideUrl. 492 // preference and use it when calling ElideUrl.
500 *paint_text = 493 *paint_text =
501 ui::ElideUrl(url_, font_, GetAvailableRect().width(), std::string()); 494 ui::ElideUrl(url_, font_, GetAvailableRect().width(), std::string());
502 495 // Ensure that URLs have LTR directionality.
503 // An URLs is always treated as an LTR text and therefore we should 496 // TODO(msw): Check cases like "/\x05d0", "://\x05d0".
504 // explicitly mark it as such if the locale is RTL so that URLs containing 497 DCHECK_EQ(base::i18n::GetFirstStrongCharacterDirection(*paint_text),
505 // Hebrew or Arabic characters are displayed correctly. 498 base::i18n::LEFT_TO_RIGHT);
506 //
507 // Note that we don't check the View's UI layout setting in order to
508 // determine whether or not to insert the special Unicode formatting
509 // characters. We use the locale settings because an URL is always treated
510 // as an LTR string, even if its containing view does not use an RTL UI
511 // layout.
512 *paint_text = base::i18n::GetDisplayStringInLTRDirectionality(
513 *paint_text);
514 } else if (is_email_) { 499 } else if (is_email_) {
515 *paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width()); 500 *paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width());
516 } else if (elide_in_middle_) { 501 } else if (elide_in_middle_) {
517 *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(), 502 *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(),
518 ui::ELIDE_IN_MIDDLE); 503 ui::ELIDE_IN_MIDDLE);
519 } else { 504 } else {
520 *paint_text = text_; 505 *paint_text = text_;
521 } 506 }
522 507
523 *text_bounds = GetTextBounds(); 508 *text_bounds = GetTextBounds();
524 *flags = ComputeDrawStringFlags(); 509 *flags = ComputeDrawStringFlags();
525 } 510 }
526 511
527 } // namespace views 512 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698