Chromium Code Reviews| 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); | |
|
Evan Stade
2013/07/11 17:54:39
I dont' know if this is an expensive operation, bu
fdoray
2013/07/11 19:56:26
It makes a call to a Windows function (GetSysColor
| |
| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; | 175 static bool initialized = false; |
| 168 static SkColor kDefaultEnabledColor; | 176 static SkColor kDefaultEnabledColor = GetDefaultEnabledColor(); |
| 169 static SkColor kDefaultDisabledColor; | 177 static SkColor kDefaultDisabledColor; |
| 170 static SkColor kDefaultPressedColor; | 178 static SkColor kDefaultPressedColor; |
| 171 if (!initialized) { | 179 if (!initialized) { |
| 172 #if defined(OS_WIN) | 180 #if defined(OS_WIN) |
| 173 kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); | |
| 174 kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | 181 kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| 175 kDefaultPressedColor = SkColorSetRGB(200, 0, 0); | 182 kDefaultPressedColor = SkColorSetRGB(200, 0, 0); |
| 176 #else | 183 #else |
| 177 // TODO(beng): source from theme provider. | 184 // TODO(beng): source from theme provider. |
| 178 kDefaultEnabledColor = SkColorSetRGB(0, 51, 153); | |
| 179 kDefaultDisabledColor = SK_ColorBLACK; | 185 kDefaultDisabledColor = SK_ColorBLACK; |
| 180 kDefaultPressedColor = SK_ColorRED; | 186 kDefaultPressedColor = SK_ColorRED; |
| 181 #endif | 187 #endif |
| 182 | 188 |
| 183 initialized = true; | 189 initialized = true; |
| 184 } | 190 } |
| 185 | 191 |
| 186 listener_ = NULL; | 192 listener_ = NULL; |
| 187 pressed_ = false; | 193 pressed_ = false; |
| 188 underline_ = true; | 194 underline_ = true; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 206 void Link::RecalculateFont() { | 212 void Link::RecalculateFont() { |
| 207 // Underline the link iff it is enabled and |underline_| is true. | 213 // Underline the link iff it is enabled and |underline_| is true. |
| 208 const int style = font().GetStyle(); | 214 const int style = font().GetStyle(); |
| 209 const int intended_style = (enabled() && underline_) ? | 215 const int intended_style = (enabled() && underline_) ? |
| 210 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); | 216 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); |
| 211 if (style != intended_style) | 217 if (style != intended_style) |
| 212 Label::SetFont(font().DeriveFont(0, intended_style)); | 218 Label::SetFont(font().DeriveFont(0, intended_style)); |
| 213 } | 219 } |
| 214 | 220 |
| 215 } // namespace views | 221 } // namespace views |
| OLD | NEW |