summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/controls/label.cc35
-rw-r--r--views/controls/label.h12
-rw-r--r--views/widget/tooltip_manager.cc4
3 files changed, 35 insertions, 16 deletions
diff --git a/views/controls/label.cc b/views/controls/label.cc
index 9ab4e36..88a755d 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -131,30 +131,40 @@ const GURL Label::GetURL() const {
return url_set_ ? url_ : GURL(WideToUTF8(text_));
}
-void Label::SetHorizontalAlignment(Alignment a) {
+void Label::SetHorizontalAlignment(Alignment alignment) {
// If the View's UI layout is right-to-left and rtl_alignment_mode_ is
// USE_UI_ALIGNMENT, we need to flip the alignment so that the alignment
// settings take into account the text directionality.
if (base::i18n::IsRTL() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) &&
- (a != ALIGN_CENTER))
- a = (a == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT;
- if (horiz_alignment_ != a) {
- horiz_alignment_ = a;
+ (alignment != ALIGN_CENTER))
+ alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT;
+ if (horiz_alignment_ != alignment) {
+ horiz_alignment_ = alignment;
SchedulePaint();
}
}
-void Label::SetMultiLine(bool f) {
- if (f != is_multi_line_) {
- is_multi_line_ = f;
+void Label::SetMultiLine(bool multi_line) {
+ DCHECK(!multi_line || !elide_in_middle_);
+ if (multi_line != is_multi_line_) {
+ is_multi_line_ = multi_line;
text_size_valid_ = false;
SchedulePaint();
}
}
-void Label::SetAllowCharacterBreak(bool f) {
- if (f != allow_character_break_) {
- allow_character_break_ = f;
+void Label::SetAllowCharacterBreak(bool allow_character_break) {
+ if (allow_character_break != allow_character_break_) {
+ allow_character_break_ = allow_character_break;
+ text_size_valid_ = false;
+ SchedulePaint();
+ }
+}
+
+void Label::SetElideInMiddle(bool elide_in_middle) {
+ DCHECK(!elide_in_middle || !is_multi_line_);
+ if (elide_in_middle != elide_in_middle_) {
+ elide_in_middle_ = elide_in_middle;
text_size_valid_ = false;
SchedulePaint();
}
@@ -285,6 +295,7 @@ void Label::Init(const std::wstring& text, const gfx::Font& font) {
horiz_alignment_ = ALIGN_CENTER;
is_multi_line_ = false;
allow_character_break_ = false;
+ elide_in_middle_ = false;
collapse_when_hidden_ = false;
rtl_alignment_mode_ = USE_UI_ALIGNMENT;
paint_as_focused_ = false;
@@ -311,6 +322,8 @@ void Label::CalculateDrawStringParams(std::wstring* paint_text,
// as an LTR string, even if its containing view does not use an RTL UI
// layout.
base::i18n::GetDisplayStringInLTRDirectionality(paint_text);
+ } else if (elide_in_middle_) {
+ *paint_text = gfx::ElideText(text_, font_, width(), true);
} else {
*paint_text = text_;
}
diff --git a/views/controls/label.h b/views/controls/label.h
index 60ccb69..2b00912 100644
--- a/views/controls/label.h
+++ b/views/controls/label.h
@@ -107,7 +107,7 @@ class Label : public View {
// is set. Otherwise, the label's alignment specified as a parameter will be
// flipped in RTL locales. Please see the comments in SetRTLAlignmentMode for
// more information.
- void SetHorizontalAlignment(Alignment a);
+ void SetHorizontalAlignment(Alignment alignment);
Alignment horizontal_alignment() const { return horiz_alignment_; }
@@ -125,14 +125,19 @@ class Label : public View {
// Set whether the label text can wrap on multiple lines.
// Default is false.
- void SetMultiLine(bool f);
+ void SetMultiLine(bool multi_line);
// Return whether the label text can wrap on multiple lines.
bool is_multi_line() const { return is_multi_line_; }
// Set whether the label text can be split on words.
// Default is false. This only works when is_multi_line is true.
- void SetAllowCharacterBreak(bool f);
+ void SetAllowCharacterBreak(bool allow_character_break);
+
+ // Set whether the label text should be elided in the middle (if necessary).
+ // The default is to elide at the end.
+ // NOTE: This is not supported for multi-line strings.
+ void SetElideInMiddle(bool elide_in_middle);
// Sets the tooltip text. Default behavior for a label (single-line) is to
// show the full text if it is wider than its bounds. Calling this overrides
@@ -233,6 +238,7 @@ class Label : public View {
mutable bool text_size_valid_;
bool is_multi_line_;
bool allow_character_break_;
+ bool elide_in_middle_;
bool url_set_;
Alignment horiz_alignment_;
std::wstring tooltip_text_;
diff --git a/views/widget/tooltip_manager.cc b/views/widget/tooltip_manager.cc
index 2a088b1..39ccab8 100644
--- a/views/widget/tooltip_manager.cc
+++ b/views/widget/tooltip_manager.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -57,7 +57,7 @@ void TooltipManager::TrimTooltipToFit(std::wstring* text,
std::wstring result;
for (std::vector<std::wstring>::iterator i = lines.begin(); i != lines.end();
++i) {
- std::wstring elided_text = gfx::ElideText(*i, font, available_width);
+ std::wstring elided_text = gfx::ElideText(*i, font, available_width, false);
*max_width = std::max(*max_width, font.GetStringWidth(elided_text));
if (i == lines.begin() && i + 1 == lines.end()) {
*text = elided_text;