| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/link.h" | 5 #include "ui/views/controls/link.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 Init(); | 27 Init(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 Link::Link(const string16& title) : Label(title) { | 30 Link::Link(const string16& title) : Label(title) { |
| 31 Init(); | 31 Init(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 Link::~Link() { | 34 Link::~Link() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 SkColor Link::GetDefaultEnabledColor() { |
| 38 #if defined(OS_WIN) |
| 39 return color_utils::GetSysSkColor(COLOR_HOTLIGHT); |
| 40 #else |
| 41 return SkColorSetRGB(0, 51, 153); |
| 42 #endif |
| 43 } |
| 44 |
| 37 void Link::OnEnabledChanged() { | 45 void Link::OnEnabledChanged() { |
| 38 RecalculateFont(); | 46 RecalculateFont(); |
| 39 View::OnEnabledChanged(); | 47 View::OnEnabledChanged(); |
| 40 } | 48 } |
| 41 | 49 |
| 42 const char* Link::GetClassName() const { | 50 const char* Link::GetClassName() const { |
| 43 return kViewClassName; | 51 return kViewClassName; |
| 44 } | 52 } |
| 45 | 53 |
| 46 gfx::NativeCursor Link::GetCursor(const ui::MouseEvent& event) { | 54 gfx::NativeCursor Link::GetCursor(const ui::MouseEvent& event) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 165 } |
| 158 | 166 |
| 159 void Link::SetUnderline(bool underline) { | 167 void Link::SetUnderline(bool underline) { |
| 160 if (underline_ == underline) | 168 if (underline_ == underline) |
| 161 return; | 169 return; |
| 162 underline_ = underline; | 170 underline_ = underline; |
| 163 RecalculateFont(); | 171 RecalculateFont(); |
| 164 } | 172 } |
| 165 | 173 |
| 166 void Link::Init() { | 174 void Link::Init() { |
| 167 static bool initialized = false; | |
| 168 static SkColor kDefaultEnabledColor; | |
| 169 static SkColor kDefaultDisabledColor; | |
| 170 static SkColor kDefaultPressedColor; | |
| 171 if (!initialized) { | |
| 172 #if defined(OS_WIN) | |
| 173 kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); | |
| 174 kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | |
| 175 kDefaultPressedColor = SkColorSetRGB(200, 0, 0); | |
| 176 #else | |
| 177 // TODO(beng): source from theme provider. | |
| 178 kDefaultEnabledColor = SkColorSetRGB(0, 51, 153); | |
| 179 kDefaultDisabledColor = SK_ColorBLACK; | |
| 180 kDefaultPressedColor = SK_ColorRED; | |
| 181 #endif | |
| 182 | |
| 183 initialized = true; | |
| 184 } | |
| 185 | |
| 186 listener_ = NULL; | 175 listener_ = NULL; |
| 187 pressed_ = false; | 176 pressed_ = false; |
| 188 underline_ = true; | 177 underline_ = true; |
| 189 SetEnabledColor(kDefaultEnabledColor); | 178 SetEnabledColor(GetDefaultEnabledColor()); |
| 190 SetDisabledColor(kDefaultDisabledColor); | 179 #if defined(OS_WIN) |
| 191 SetPressedColor(kDefaultPressedColor); | 180 SetDisabledColor(color_utils::GetSysSkColor(COLOR_WINDOWTEXT)); |
| 181 SetPressedColor(SkColorSetRGB(200, 0, 0)); |
| 182 #else |
| 183 // TODO(beng): source from theme provider. |
| 184 SetDisabledColor(SK_ColorBLACK); |
| 185 SetPressedColor(SK_ColorRED); |
| 186 #endif |
| 192 RecalculateFont(); | 187 RecalculateFont(); |
| 193 set_focusable(true); | 188 set_focusable(true); |
| 194 } | 189 } |
| 195 | 190 |
| 196 void Link::SetPressed(bool pressed) { | 191 void Link::SetPressed(bool pressed) { |
| 197 if (pressed_ != pressed) { | 192 if (pressed_ != pressed) { |
| 198 pressed_ = pressed; | 193 pressed_ = pressed; |
| 199 Label::SetEnabledColor(pressed_ ? | 194 Label::SetEnabledColor(pressed_ ? |
| 200 requested_pressed_color_ : requested_enabled_color_); | 195 requested_pressed_color_ : requested_enabled_color_); |
| 201 RecalculateFont(); | 196 RecalculateFont(); |
| 202 SchedulePaint(); | 197 SchedulePaint(); |
| 203 } | 198 } |
| 204 } | 199 } |
| 205 | 200 |
| 206 void Link::RecalculateFont() { | 201 void Link::RecalculateFont() { |
| 207 // Underline the link iff it is enabled and |underline_| is true. | 202 // Underline the link iff it is enabled and |underline_| is true. |
| 208 const int style = font().GetStyle(); | 203 const int style = font().GetStyle(); |
| 209 const int intended_style = (enabled() && underline_) ? | 204 const int intended_style = (enabled() && underline_) ? |
| 210 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); | 205 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); |
| 211 if (style != intended_style) | 206 if (style != intended_style) |
| 212 Label::SetFont(font().DeriveFont(0, intended_style)); | 207 Label::SetFont(font().DeriveFont(0, intended_style)); |
| 213 } | 208 } |
| 214 | 209 |
| 215 } // namespace views | 210 } // namespace views |
| OLD | NEW |