| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void Link::SetFontList(const gfx::FontList& font_list) { | 155 void Link::SetFontList(const gfx::FontList& font_list) { |
| 156 Label::SetFontList(font_list); | 156 Label::SetFontList(font_list); |
| 157 RecalculateFont(); | 157 RecalculateFont(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void Link::SetText(const base::string16& text) { | 160 void Link::SetText(const base::string16& text) { |
| 161 Label::SetText(text); | 161 Label::SetText(text); |
| 162 // Disable focusability for empty links. Otherwise Label::GetInsets() will | 162 // Disable focusability for empty links. Otherwise Label::GetInsets() will |
| 163 // give them an unconditional 1-px. inset on every side to allow for a focus | 163 // give them an unconditional 1-px. inset on every side to allow for a focus |
| 164 // border, when in this case we probably wanted zero width. | 164 // border, when in this case we probably wanted zero width. |
| 165 SetFocusable(!text.empty()); | 165 SetFocusBehavior(text.empty() ? FocusBehavior::NEVER : FocusBehavior::ALWAYS); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 168 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 169 Label::SetEnabledColor(GetEnabledColor()); | 169 Label::SetEnabledColor(GetEnabledColor()); |
| 170 SetDisabledColor( | 170 SetDisabledColor( |
| 171 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); | 171 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void Link::SetEnabledColor(SkColor color) { | 174 void Link::SetEnabledColor(SkColor color) { |
| 175 requested_enabled_color_set_ = true; | 175 requested_enabled_color_set_ = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 191 } | 191 } |
| 192 | 192 |
| 193 void Link::Init() { | 193 void Link::Init() { |
| 194 listener_ = NULL; | 194 listener_ = NULL; |
| 195 pressed_ = false; | 195 pressed_ = false; |
| 196 underline_ = true; | 196 underline_ = true; |
| 197 RecalculateFont(); | 197 RecalculateFont(); |
| 198 | 198 |
| 199 // Label::Init() calls SetText(), but if that's being called from Label(), our | 199 // Label::Init() calls SetText(), but if that's being called from Label(), our |
| 200 // SetText() override will not be reached (because the constructed class is | 200 // SetText() override will not be reached (because the constructed class is |
| 201 // only a Label at the moment, not yet a Link). So so the set_focusable() | 201 // only a Label at the moment, not yet a Link). So set the focus behavior |
| 202 // call explicitly here. | 202 // here as well |
| 203 SetFocusable(!text().empty()); | 203 SetFocusBehavior(text().empty() ? FocusBehavior::NEVER |
| 204 : FocusBehavior::ALWAYS); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void Link::SetPressed(bool pressed) { | 207 void Link::SetPressed(bool pressed) { |
| 207 if (pressed_ != pressed) { | 208 if (pressed_ != pressed) { |
| 208 pressed_ = pressed; | 209 pressed_ = pressed; |
| 209 Label::SetEnabledColor(GetEnabledColor()); | 210 Label::SetEnabledColor(GetEnabledColor()); |
| 210 RecalculateFont(); | 211 RecalculateFont(); |
| 211 SchedulePaint(); | 212 SchedulePaint(); |
| 212 } | 213 } |
| 213 } | 214 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 233 } | 234 } |
| 234 | 235 |
| 235 if (!requested_pressed_color_set_ && GetNativeTheme()) | 236 if (!requested_pressed_color_set_ && GetNativeTheme()) |
| 236 return GetNativeTheme()->GetSystemColor( | 237 return GetNativeTheme()->GetSystemColor( |
| 237 ui::NativeTheme::kColorId_LinkPressed); | 238 ui::NativeTheme::kColorId_LinkPressed); |
| 238 | 239 |
| 239 return requested_pressed_color_; | 240 return requested_pressed_color_; |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace views | 243 } // namespace views |
| OLD | NEW |