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

Unified Diff: ui/views/controls/label.cc

Issue 327273005: Revert of Use labels to display views tab titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label.cc
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc
index e1e1bcfe1c2d2b5309c2e7daafe9dd9865b965b1..e9708a3e1d33c50bbd9486e5d92eb65d74f0aefe 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -120,9 +120,11 @@
}
void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
- // If the UI layout is right-to-left, flip the alignment direction.
- if (base::i18n::IsRTL() &&
- (alignment == gfx::ALIGN_LEFT || alignment == gfx::ALIGN_RIGHT)) {
+ // If the View's UI layout is right-to-left and directionality_mode_ is
+ // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment
+ // settings take into account the text directionality.
+ if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) &&
+ (alignment != gfx::ALIGN_CENTER)) {
alignment = (alignment == gfx::ALIGN_LEFT) ?
gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
}
@@ -130,15 +132,6 @@
horizontal_alignment_ = alignment;
SchedulePaint();
}
-}
-
-gfx::HorizontalAlignment Label::GetHorizontalAlignment() const {
- if (horizontal_alignment_ != gfx::ALIGN_TO_HEAD)
- return horizontal_alignment_;
-
- const base::i18n::TextDirection dir =
- base::i18n::GetFirstStrongCharacterDirection(layout_text());
- return dir == base::i18n::RIGHT_TO_LEFT ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
}
void Label::SetLineHeight(int height) {
@@ -412,7 +405,7 @@
allow_character_break_ = false;
elide_behavior_ = gfx::ELIDE_TAIL;
collapse_when_hidden_ = false;
- directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI;
+ directionality_mode_ = USE_UI_DIRECTIONALITY;
enabled_shadow_color_ = 0;
disabled_shadow_color_ = 0;
shadow_offset_.SetPoint(1, 1);
@@ -437,27 +430,33 @@
}
gfx::Rect Label::GetTextBounds() const {
- gfx::Rect available(GetAvailableRect());
+ gfx::Rect available_rect(GetAvailableRect());
gfx::Size text_size(GetTextSize());
- text_size.set_width(std::min(available.width(), text_size.width()));
- gfx::Point origin(GetInsets().left(), GetInsets().top());
- switch (GetHorizontalAlignment()) {
+ text_size.set_width(std::min(available_rect.width(), text_size.width()));
+
+ gfx::Insets insets = GetInsets();
+ gfx::Point text_origin(insets.left(), insets.top());
+ switch (horizontal_alignment_) {
case gfx::ALIGN_LEFT:
break;
case gfx::ALIGN_CENTER:
- // Put any extra margin pixel on the left to match the legacy behavior
- // from the use of GetTextExtentPoint32() on Windows.
- origin.Offset((available.width() + 1 - text_size.width()) / 2, 0);
+ // We put any extra margin pixel on the left rather than the right. We
+ // used to do this because measurement on Windows used
+ // GetTextExtentPoint32(), which could report a value one too large on the
+ // right; we now use DrawText(), and who knows if it can also do this.
+ text_origin.Offset((available_rect.width() + 1 - text_size.width()) / 2,
+ 0);
break;
case gfx::ALIGN_RIGHT:
- origin.set_x(available.right() - text_size.width());
+ text_origin.set_x(available_rect.right() - text_size.width());
break;
default:
NOTREACHED();
break;
}
- origin.Offset(0, std::max(0, (available.height() - text_size.height())) / 2);
- return gfx::Rect(origin, text_size);
+ text_origin.Offset(0,
+ std::max(0, (available_rect.height() - text_size.height())) / 2);
+ return gfx::Rect(text_origin, text_size);
}
int Label::ComputeDrawStringFlags() const {
@@ -467,11 +466,7 @@
if (SkColorGetA(background_color_) != 0xFF)
flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
- if (directionality_mode_ == gfx::DIRECTIONALITY_FORCE_LTR) {
- flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
- } else if (directionality_mode_ == gfx::DIRECTIONALITY_FORCE_RTL) {
- flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
- } else if (directionality_mode_ == gfx::DIRECTIONALITY_FROM_TEXT) {
+ if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
base::i18n::TextDirection direction =
base::i18n::GetFirstStrongCharacterDirection(layout_text());
if (direction == base::i18n::RIGHT_TO_LEFT)
@@ -480,7 +475,7 @@
flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
}
- switch (GetHorizontalAlignment()) {
+ switch (horizontal_alignment_) {
case gfx::ALIGN_LEFT:
flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
break;
@@ -489,9 +484,6 @@
break;
case gfx::ALIGN_RIGHT:
flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
- break;
- default:
- NOTREACHED();
break;
}
« 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