Index: ui/views/controls/link.cc |
diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc |
index d116aa35db5f74e8039bae56162a6b42fe34ee0a..5909629fc7898ca841e0e1fe3748e9419199b0bd 100644 |
--- a/ui/views/controls/link.cc |
+++ b/ui/views/controls/link.cc |
@@ -94,6 +94,16 @@ void Link::OnMouseCaptureLost() { |
SetPressed(false); |
} |
+void Link::OnMouseEntered(const ui::MouseEvent& event) { |
+ mouse_inside_ = true; |
+ RecalculateFont(); |
+} |
+ |
+void Link::OnMouseExited(const ui::MouseEvent& event) { |
+ mouse_inside_ = false; |
+ RecalculateFont(); |
+} |
+ |
bool Link::OnKeyPressed(const ui::KeyEvent& event) { |
bool activate = ((event.key_code() == ui::VKEY_SPACE) || |
(event.key_code() == ui::VKEY_RETURN)); |
@@ -156,6 +166,11 @@ void Link::SetPressedColor(SkColor color) { |
Label::SetEnabledColor(requested_pressed_color_); |
} |
+void Link::SetUnderlineOnHover(bool underline_on_hover) { |
+ underline_on_hover_ = underline_on_hover; |
+ RecalculateFont(); |
+} |
+ |
void Link::Init() { |
static bool initialized = false; |
static SkColor kDefaultEnabledColor; |
@@ -178,6 +193,8 @@ void Link::Init() { |
listener_ = NULL; |
pressed_ = false; |
+ underline_on_hover_ = false; |
+ mouse_inside_ = false; |
SetEnabledColor(kDefaultEnabledColor); |
SetDisabledColor(kDefaultDisabledColor); |
SetPressedColor(kDefaultPressedColor); |
@@ -196,8 +213,15 @@ void Link::SetPressed(bool pressed) { |
} |
void Link::RecalculateFont() { |
- // The font should be underlined iff the link is enabled. |
- if (enabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { |
+ if (underline_on_hover_) { |
+ // For underline on hover, the font should be underlined iff the link is |
+ // enabled and the mouse is hovering over it. |
+ Label::SetFont(font().DeriveFont(0, enabled() && mouse_inside_ ? |
+ (font().GetStyle() | gfx::Font::UNDERLINED) : |
+ (font().GetStyle() & ~gfx::Font::UNDERLINED))); |
+ } else if (enabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { |
+ // For constant underlining, the font should be underlined iff the link is |
+ // enabled. |
Label::SetFont(font().DeriveFont(0, enabled() ? |
(font().GetStyle() | gfx::Font::UNDERLINED) : |
(font().GetStyle() & ~gfx::Font::UNDERLINED))); |