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

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

Issue 323993002: Use labels to display views tab titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; update tests. 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 e9708a3e1d33c50bbd9486e5d92eb65d74f0aefe..e1e1bcfe1c2d2b5309c2e7daafe9dd9865b965b1 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -120,11 +120,9 @@ void Label::ClearEmbellishing() {
}
void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
- // 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)) {
+ // If the UI layout is right-to-left, flip the alignment direction.
+ if (base::i18n::IsRTL() &&
+ (alignment == gfx::ALIGN_LEFT || alignment == gfx::ALIGN_RIGHT)) {
alignment = (alignment == gfx::ALIGN_LEFT) ?
gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
}
@@ -134,6 +132,15 @@ void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
}
}
+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) {
if (height != line_height_) {
line_height_ = height;
@@ -405,7 +412,7 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
allow_character_break_ = false;
elide_behavior_ = gfx::ELIDE_TAIL;
collapse_when_hidden_ = false;
- directionality_mode_ = USE_UI_DIRECTIONALITY;
+ directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI;
enabled_shadow_color_ = 0;
disabled_shadow_color_ = 0;
shadow_offset_.SetPoint(1, 1);
@@ -430,33 +437,27 @@ void Label::RecalculateColors() {
}
gfx::Rect Label::GetTextBounds() const {
- gfx::Rect available_rect(GetAvailableRect());
+ gfx::Rect available(GetAvailableRect());
gfx::Size text_size(GetTextSize());
- 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_) {
+ text_size.set_width(std::min(available.width(), text_size.width()));
+ gfx::Point origin(GetInsets().left(), GetInsets().top());
+ switch (GetHorizontalAlignment()) {
case gfx::ALIGN_LEFT:
break;
case gfx::ALIGN_CENTER:
- // 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);
+ // 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);
break;
case gfx::ALIGN_RIGHT:
- text_origin.set_x(available_rect.right() - text_size.width());
+ origin.set_x(available.right() - text_size.width());
break;
default:
NOTREACHED();
break;
}
- text_origin.Offset(0,
- std::max(0, (available_rect.height() - text_size.height())) / 2);
- return gfx::Rect(text_origin, text_size);
+ origin.Offset(0, std::max(0, (available.height() - text_size.height())) / 2);
+ return gfx::Rect(origin, text_size);
}
int Label::ComputeDrawStringFlags() const {
@@ -466,7 +467,11 @@ int Label::ComputeDrawStringFlags() const {
if (SkColorGetA(background_color_) != 0xFF)
flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
- if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
+ 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) {
base::i18n::TextDirection direction =
base::i18n::GetFirstStrongCharacterDirection(layout_text());
if (direction == base::i18n::RIGHT_TO_LEFT)
@@ -475,7 +480,7 @@ int Label::ComputeDrawStringFlags() const {
flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
}
- switch (horizontal_alignment_) {
+ switch (GetHorizontalAlignment()) {
case gfx::ALIGN_LEFT:
flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
break;
@@ -485,6 +490,9 @@ int Label::ComputeDrawStringFlags() const {
case gfx::ALIGN_RIGHT:
flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
break;
+ default:
+ NOTREACHED();
+ break;
}
if (!is_multi_line_)
« 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