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

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

Issue 11044020: Make Web Intents picker in Views conform to latest mocks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Include changes from CL 11077006 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
Index: ui/views/controls/link.cc
diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc
index d116aa35db5f74e8039bae56162a6b42fe34ee0a..c5d2bcd7e55101b7d3237c89ea8473197dd3f75a 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) {
+ mouseIsInside_ = true;
+ RecalculateFont();
+}
+
+void Link::OnMouseExited(const ui::MouseEvent& event) {
+ mouseIsInside_ = 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 underlineOnHover) {
+ underlineOnHover_ = underlineOnHover;
+ RecalculateFont();
+}
+
void Link::Init() {
static bool initialized = false;
static SkColor kDefaultEnabledColor;
@@ -178,6 +193,8 @@ void Link::Init() {
listener_ = NULL;
pressed_ = false;
+ underlineOnHover_ = false;
+ mouseIsInside_ = 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 (underlineOnHover_) {
+ // 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() && mouseIsInside_ ?
+ (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)));

Powered by Google App Engine
This is Rietveld 408576698