summaryrefslogtreecommitdiffstats
path: root/ui/views/controls
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 22:09:32 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 22:09:32 +0000
commit0b401e850256683e4ba15824a64a710e9c02183c (patch)
tree573d4e1f5622a690af1a7b72bd7d8534a799fae8 /ui/views/controls
parentc0aa875b9923b3faf641ac6f6cb7ccce9dcbb569 (diff)
downloadchromium_src-0b401e850256683e4ba15824a64a710e9c02183c.zip
chromium_src-0b401e850256683e4ba15824a64a710e9c02183c.tar.gz
chromium_src-0b401e850256683e4ba15824a64a710e9c02183c.tar.bz2
Cleanup Views Label unused code and eliding.
Nix Label::SetEmail, which only influenced eliding. Add ELIDE_AS_EMAIL flag instead; use in ProfileItemView. Remove unused MouseOverBackground code and related: (OnMouse*, OnPaintBackground, *ContainsMouse, etc.) Remove unused paint_as_focused* and invalidate_text_size(). Make kViewClassName and kFocusBorderPadding cc file locals. Group a couple related accessors and their comments; etc. BUG=155363 TEST=No behavior changes, no complaints. R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/11369085 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/controls')
-rw-r--r--ui/views/controls/label.cc73
-rw-r--r--ui/views/controls/label.h72
2 files changed, 23 insertions, 122 deletions
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc
index f4af0a2..4de151b 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -25,12 +25,16 @@
#include "ui/gfx/shadow_value.h"
#include "ui/views/background.h"
-namespace views {
+namespace {
-// static
-const char Label::kViewClassName[] = "views/Label";
+const char kViewClassName[] = "views/Label";
-const int Label::kFocusBorderPadding = 1;
+// The padding for the focus border when rendering focused text.
+const int kFocusBorderPadding = 1;
+
+} // namespace
+
+namespace views {
Label::Label() {
Init(string16(), GetDefaultFont());
@@ -59,16 +63,10 @@ void Label::SetText(const string16& text) {
return;
text_ = text;
text_size_valid_ = false;
- is_email_ = false;
PreferredSizeChanged();
SchedulePaint();
}
-void Label::SetEmail(const string16& email) {
- SetText(email);
- is_email_ = true;
-}
-
void Label::SetAutoColorReadabilityEnabled(bool enabled) {
auto_color_readability_ = enabled;
RecalculateColors();
@@ -140,7 +138,6 @@ void Label::SetElideBehavior(ElideBehavior elide_behavior) {
if (elide_behavior != elide_behavior_) {
elide_behavior_ = elide_behavior;
text_size_valid_ = false;
- is_email_ = false;
PreferredSizeChanged();
SchedulePaint();
}
@@ -150,14 +147,6 @@ void Label::SetTooltipText(const string16& tooltip_text) {
tooltip_text_ = tooltip_text;
}
-void Label::SetMouseOverBackground(Background* background) {
- mouse_over_background_.reset(background);
-}
-
-const Background* Label::GetMouseOverBackground() const {
- return mouse_over_background_.get();
-}
-
void Label::SizeToFit(int max_width) {
DCHECK(is_multi_line_);
@@ -189,7 +178,7 @@ void Label::SetHasFocusBorder(bool has_focus_border) {
gfx::Insets Label::GetInsets() const {
gfx::Insets insets = View::GetInsets();
- if (focusable() || has_focus_border_) {
+ if (focusable() || has_focus_border_) {
insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding,
kFocusBorderPadding, kFocusBorderPadding);
}
@@ -233,18 +222,6 @@ bool Label::HitTestRect(const gfx::Rect& rect) const {
return false;
}
-void Label::OnMouseMoved(const ui::MouseEvent& event) {
- UpdateContainsMouse(event);
-}
-
-void Label::OnMouseEntered(const ui::MouseEvent& event) {
- UpdateContainsMouse(event);
-}
-
-void Label::OnMouseExited(const ui::MouseEvent& event) {
- SetContainsMouse(false);
-}
-
bool Label::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
DCHECK(tooltip);
@@ -281,7 +258,7 @@ void Label::PaintText(gfx::Canvas* canvas,
enabled() ? actual_enabled_color_ : actual_disabled_color_,
text_bounds, flags, shadows);
- if (HasFocus() || paint_as_focused_) {
+ if (HasFocus()) {
gfx::Rect focus_bounds = text_bounds;
focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding);
canvas->DrawFocusRect(focus_bounds);
@@ -328,21 +305,12 @@ void Label::OnPaint(gfx::Canvas* canvas) {
PaintText(canvas, paint_text, text_bounds, flags);
}
-void Label::OnPaintBackground(gfx::Canvas* canvas) {
- const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL;
- if (!bg)
- bg = background();
- if (bg)
- bg->Paint(canvas, this);
-}
-
// static
gfx::Font Label::GetDefaultFont() {
return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
}
void Label::Init(const string16& text, const gfx::Font& font) {
- contains_mouse_ = false;
font_ = font;
text_size_valid_ = false;
requested_enabled_color_ = ui::NativeTheme::instance()->GetSystemColor(
@@ -357,10 +325,8 @@ void Label::Init(const string16& text, const gfx::Font& font) {
is_multi_line_ = false;
allow_character_break_ = false;
elide_behavior_ = NO_ELIDE;
- is_email_ = false;
collapse_when_hidden_ = false;
directionality_mode_ = USE_UI_DIRECTIONALITY;
- paint_as_focused_ = false;
has_focus_border_ = false;
enabled_shadow_color_ = 0;
disabled_shadow_color_ = 0;
@@ -381,18 +347,6 @@ void Label::RecalculateColors() {
requested_disabled_color_;
}
-void Label::UpdateContainsMouse(const ui::MouseEvent& event) {
- SetContainsMouse(GetTextBounds().Contains(event.x(), event.y()));
-}
-
-void Label::SetContainsMouse(bool contains_mouse) {
- if (contains_mouse_ == contains_mouse)
- return;
- contains_mouse_ = contains_mouse;
- if (GetMouseOverBackground())
- SchedulePaint();
-}
-
gfx::Rect Label::GetTextBounds() const {
gfx::Rect available_rect(GetAvailableRect());
gfx::Size text_size(GetTextSize());
@@ -469,9 +423,8 @@ int Label::ComputeDrawStringFlags() const {
}
gfx::Rect Label::GetAvailableRect() const {
- gfx::Rect bounds(gfx::Point(), size());
- gfx::Insets insets(GetInsets());
- bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom());
+ gfx::Rect bounds(size());
+ bounds.Inset(GetInsets());
return bounds;
}
@@ -481,7 +434,7 @@ void Label::CalculateDrawStringParams(string16* paint_text,
DCHECK(paint_text && text_bounds && flags);
// TODO(msw): Use ElideRectangleText to support eliding multi-line text.
- if (is_email_) {
+ if (elide_behavior_ == ELIDE_AS_EMAIL) {
*paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width());
} else if (elide_behavior_ == ELIDE_IN_MIDDLE) {
*paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(),
diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h
index 7e5340e..bd21766 100644
--- a/ui/views/controls/label.h
+++ b/ui/views/controls/label.h
@@ -45,37 +45,25 @@ class VIEWS_EXPORT Label : public View {
};
enum ElideBehavior {
- NO_ELIDE,
- ELIDE_IN_MIDDLE,
- ELIDE_AT_END,
+ NO_ELIDE, // Do not elide the label text; truncate as needed.
+ ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed.
+ ELIDE_AT_END, // Add ellipsis at the end of the string as needed.
+ ELIDE_AS_EMAIL, // Elide while retaining username/domain chars as needed.
};
- // The view class name.
- static const char kViewClassName[];
-
- // The padding for the focus border when rendering focused text.
- static const int kFocusBorderPadding;
-
Label();
explicit Label(const string16& text);
Label(const string16& text, const gfx::Font& font);
virtual ~Label();
- // Sets the font.
+ // Get or set the font used by this label.
+ const gfx::Font& font() const { return font_; }
virtual void SetFont(const gfx::Font& font);
- // Sets the label text.
+ // Get or set the label text.
+ const string16& text() const { return text_; }
void SetText(const string16& text);
- // Sets the label text to |email|. Emails have a custom eliding algorithm.
- void SetEmail(const string16& email);
-
- // Returns the font used by this label.
- const gfx::Font& font() const { return font_; }
-
- // Returns the label text.
- const string16& text() const { return text_; };
-
// Enables or disables auto-color-readability (enabled by default). If this
// is enabled, then calls to set any foreground or background color will
// trigger an automatic mapper that uses color_utils::GetReadableColor() to
@@ -125,12 +113,9 @@ class VIEWS_EXPORT Label : public View {
return directionality_mode_;
}
- // Sets whether the label text can wrap on multiple lines.
- // Default is false.
- void SetMultiLine(bool multi_line);
-
- // Returns whether the label text can wrap on multiple lines.
+ // Get or set if the label text can wrap on multiple lines; default is false.
bool is_multi_line() const { return is_multi_line_; }
+ void SetMultiLine(bool multi_line);
// Sets whether the label text can be split on words.
// Default is false. This only works when is_multi_line is true.
@@ -147,11 +132,6 @@ class VIEWS_EXPORT Label : public View {
// default behavior, call this with an empty string.
void SetTooltipText(const string16& tooltip_text);
- // The background color to use when the mouse is over the label. Label
- // takes ownership of the Background.
- void SetMouseOverBackground(Background* background);
- const Background* GetMouseOverBackground() const;
-
// Resizes the label so its width is set to the width of the longest line and
// its height deduced accordingly.
// This is only intended for multi-line labels and is useful when the label's
@@ -166,12 +146,6 @@ class VIEWS_EXPORT Label : public View {
void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; }
bool collapse_when_hidden() const { return collapse_when_hidden_; }
- // Gets/set whether or not this label is to be painted as a focused element.
- void set_paint_as_focused(bool paint_as_focused) {
- paint_as_focused_ = paint_as_focused;
- }
- bool paint_as_focused() const { return paint_as_focused_; }
-
void SetHasFocusBorder(bool has_focus_border);
// Overridden from View:
@@ -185,11 +159,6 @@ class VIEWS_EXPORT Label : public View {
virtual int GetHeightForWidth(int w) OVERRIDE;
virtual std::string GetClassName() const OVERRIDE;
virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
- // Mouse enter/exit are overridden to render mouse over background color.
- // These invoke SetContainsMouse as necessary.
- virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
- virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
- virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
// Gets the tooltip text for labels that are wider than their bounds, except
// when the label is multiline, in which case it just returns false (no
@@ -206,8 +175,6 @@ class VIEWS_EXPORT Label : public View {
const gfx::Rect& text_bounds,
int flags);
- void invalidate_text_size() { text_size_valid_ = false; }
-
virtual gfx::Size GetTextSize() const;
SkColor disabled_color() const { return actual_disabled_color_; }
@@ -216,9 +183,6 @@ class VIEWS_EXPORT Label : public View {
// Overridden to dirty our text bounds if we're multi-line.
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
- // If the mouse is over the label, and a mouse over background has been
- // specified, its used. Otherwise super's implementation is invoked.
- virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
private:
// These tests call CalculateDrawStringParams in order to verify the
@@ -238,15 +202,6 @@ class VIEWS_EXPORT Label : public View {
void RecalculateColors();
- // If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise
- // SetContainsMouse(false) is invoked.
- void UpdateContainsMouse(const ui::MouseEvent& event);
-
- // Updates whether the mouse is contained in the Label. If the new value
- // differs from the current value, and a mouse over background is specified,
- // SchedulePaint is invoked.
- void SetContainsMouse(bool contains_mouse);
-
// Returns where the text is drawn, in the receivers coordinate system.
gfx::Rect GetTextBounds() const;
@@ -272,12 +227,8 @@ class VIEWS_EXPORT Label : public View {
bool is_multi_line_;
bool allow_character_break_;
ElideBehavior elide_behavior_;
- bool is_email_;
Alignment horiz_alignment_;
string16 tooltip_text_;
- // Whether the mouse is over this label.
- bool contains_mouse_;
- scoped_ptr<Background> mouse_over_background_;
// Whether to collapse the label when it's not visible.
bool collapse_when_hidden_;
// The following member variable is used to control whether the
@@ -285,9 +236,6 @@ class VIEWS_EXPORT Label : public View {
// character or is determined by chrome UI's locale.
DirectionalityMode directionality_mode_;
// When embedded in a larger control that is focusable, setting this flag
- // allows this view to be painted as focused even when it is itself not.
- bool paint_as_focused_;
- // When embedded in a larger control that is focusable, setting this flag
// allows this view to reserve space for a focus border that it otherwise
// might not have because it is not itself focusable.
bool has_focus_border_;