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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 SchedulePaint(); | 152 SchedulePaint(); |
153 } | 153 } |
154 | 154 |
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 |
162 // Disable focusability for empty links. Otherwise Label::GetInsets() will | 163 // 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 | 164 // 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. | 165 // border, when in this case we probably wanted zero width. |
165 SetFocusable(!text.empty()); | 166 SetFocusBehavior(text.empty() ? NEVER : CONTROL); |
166 } | 167 } |
167 | 168 |
168 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 169 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
169 Label::SetEnabledColor(GetEnabledColor()); | 170 Label::SetEnabledColor(GetEnabledColor()); |
170 SetDisabledColor( | 171 SetDisabledColor( |
171 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); | 172 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); |
172 } | 173 } |
173 | 174 |
174 void Link::SetEnabledColor(SkColor color) { | 175 void Link::SetEnabledColor(SkColor color) { |
175 requested_enabled_color_set_ = true; | 176 requested_enabled_color_set_ = true; |
(...skipping 15 matching lines...) Expand all Loading... |
191 } | 192 } |
192 | 193 |
193 void Link::Init() { | 194 void Link::Init() { |
194 listener_ = NULL; | 195 listener_ = NULL; |
195 pressed_ = false; | 196 pressed_ = false; |
196 underline_ = true; | 197 underline_ = true; |
197 RecalculateFont(); | 198 RecalculateFont(); |
198 | 199 |
199 // Label::Init() calls SetText(), but if that's being called from Label(), our | 200 // 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 | 201 // 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() | 202 // only a Label at the moment, not yet a Link). So explicitly set |
202 // call explicitly here. | 203 // focusability here. |
203 SetFocusable(!text().empty()); | 204 SetFocusBehavior(text().empty() ? NEVER : CONTROL); |
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 |