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

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

Issue 11143024: Add ability to underline links on hover in Views (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge master Created 8 years, 2 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/link.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)));
« no previous file with comments | « ui/views/controls/link.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698