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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 PlatformStyle::kReturnClicksFocusedControl); | 163 PlatformStyle::kReturnClicksFocusedControl); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void Link::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 166 void Link::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 167 Label::GetAccessibleNodeData(node_data); | 167 Label::GetAccessibleNodeData(node_data); |
| 168 node_data->role = ui::AX_ROLE_LINK; | 168 node_data->role = ui::AX_ROLE_LINK; |
| 169 } | 169 } |
| 170 | 170 |
| 171 void Link::OnEnabledChanged() { | 171 void Link::OnEnabledChanged() { |
| 172 RecalculateFont(); | 172 RecalculateFont(); |
| 173 View::OnEnabledChanged(); | 173 View::OnEnabledChanged(); // Jump over Label. |
| 174 } | 174 } |
| 175 | 175 |
| 176 void Link::OnFocus() { | 176 void Link::OnFocus() { |
| 177 Label::OnFocus(); | 177 Label::OnFocus(); |
| 178 RecalculateFont(); | 178 RecalculateFont(); |
| 179 // We render differently focused. | 179 // We render differently focused. |
| 180 SchedulePaint(); | 180 SchedulePaint(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void Link::OnBlur() { | 183 void Link::OnBlur() { |
| 184 Label::OnBlur(); | 184 Label::OnBlur(); |
| 185 RecalculateFont(); | 185 RecalculateFont(); |
| 186 // We render differently focused. | 186 // We render differently focused. |
| 187 SchedulePaint(); | 187 SchedulePaint(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void Link::SetFontList(const gfx::FontList& font_list) { | 190 void Link::SetFontList(const gfx::FontList& font_list) { |
| 191 Label::SetFontList(font_list); | 191 Label::SetFontList(font_list); |
| 192 RecalculateFont(); | 192 RecalculateFont(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void Link::SetText(const base::string16& text) { | 195 void Link::SetText(const base::string16& text) { |
| 196 Label::SetText(text); | 196 Label::SetText(text); |
| 197 ConfigureFocus(); | 197 ConfigureFocus(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 200 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 201 Label::OnNativeThemeChanged(theme); | 201 Label::OnNativeThemeChanged(theme); |
| 202 Label::SetEnabledColor(GetEnabledColor()); | 202 Label::SetEnabledColor(GetColor()); |
| 203 SetDisabledColor( | |
| 204 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); | |
| 205 } | 203 } |
| 206 | 204 |
| 207 void Link::SetEnabledColor(SkColor color) { | 205 void Link::SetEnabledColor(SkColor color) { |
| 208 requested_enabled_color_set_ = true; | 206 requested_enabled_color_set_ = true; |
| 209 requested_enabled_color_ = color; | 207 requested_enabled_color_ = color; |
| 210 Label::SetEnabledColor(GetEnabledColor()); | 208 Label::SetEnabledColor(GetColor()); |
| 211 } | 209 } |
| 212 | 210 |
| 213 bool Link::IsSelectionSupported() const { | 211 bool Link::IsSelectionSupported() const { |
| 214 return false; | 212 return false; |
| 215 } | 213 } |
| 216 | 214 |
| 217 void Link::SetUnderline(bool underline) { | 215 void Link::SetUnderline(bool underline) { |
| 218 if (underline_ == underline) | 216 if (underline_ == underline) |
| 219 return; | 217 return; |
| 220 underline_ = underline; | 218 underline_ = underline; |
| 221 RecalculateFont(); | 219 RecalculateFont(); |
| 222 } | 220 } |
| 223 | 221 |
| 224 void Link::Init() { | 222 void Link::Init() { |
| 225 listener_ = NULL; | 223 listener_ = NULL; |
| 226 pressed_ = false; | 224 pressed_ = false; |
| 227 underline_ = GetDefaultFocusStyle() != FocusStyle::UNDERLINE; | 225 underline_ = GetDefaultFocusStyle() != FocusStyle::UNDERLINE; |
| 228 RecalculateFont(); | 226 RecalculateFont(); |
| 229 | 227 |
| 230 // Label::Init() calls SetText(), but if that's being called from Label(), our | 228 // Label::Init() calls SetText(), but if that's being called from Label(), our |
| 231 // SetText() override will not be reached (because the constructed class is | 229 // SetText() override will not be reached (because the constructed class is |
| 232 // only a Label at the moment, not yet a Link). So explicitly configure focus | 230 // only a Label at the moment, not yet a Link). So explicitly configure focus |
| 233 // here. | 231 // here. |
| 234 ConfigureFocus(); | 232 ConfigureFocus(); |
| 235 } | 233 } |
| 236 | 234 |
| 237 void Link::SetPressed(bool pressed) { | 235 void Link::SetPressed(bool pressed) { |
| 238 if (pressed_ != pressed) { | 236 if (pressed_ != pressed) { |
| 239 pressed_ = pressed; | 237 pressed_ = pressed; |
| 240 Label::SetEnabledColor(GetEnabledColor()); | 238 Label::SetEnabledColor(GetColor()); |
| 241 RecalculateFont(); | 239 RecalculateFont(); |
| 242 SchedulePaint(); | 240 SchedulePaint(); |
| 243 } | 241 } |
| 244 } | 242 } |
| 245 | 243 |
| 246 void Link::RecalculateFont() { | 244 void Link::RecalculateFont() { |
| 247 // Underline the link if it is enabled and |underline_| is true. Also | 245 // Underline the link if it is enabled and |underline_| is true. Also |
| 248 // underline to indicate focus when that's the style. | 246 // underline to indicate focus when that's the style. |
| 249 const int style = font_list().GetFontStyle(); | 247 const int style = font_list().GetFontStyle(); |
| 250 const bool underline = | 248 const bool underline = |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 262 SetFocusBehavior(FocusBehavior::NEVER); | 260 SetFocusBehavior(FocusBehavior::NEVER); |
| 263 } else { | 261 } else { |
| 264 #if defined(OS_MACOSX) | 262 #if defined(OS_MACOSX) |
| 265 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 263 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 266 #else | 264 #else |
| 267 SetFocusBehavior(FocusBehavior::ALWAYS); | 265 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 268 #endif | 266 #endif |
| 269 } | 267 } |
| 270 } | 268 } |
| 271 | 269 |
| 272 SkColor Link::GetEnabledColor() { | 270 SkColor Link::GetColor() { |
| 271 const ui::NativeTheme* theme = GetNativeTheme(); | |
| 272 DCHECK(theme); | |
|
Peter Kasting
2017/06/01 04:55:58
The old code conditionalized this. Is it guarante
tapted
2017/06/01 11:22:18
Yup.
View::GetNativeTheme() and Widget::GetNative
| |
| 273 if (!enabled()) | |
| 274 return theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled); | |
| 275 | |
| 273 if (requested_enabled_color_set_) | 276 if (requested_enabled_color_set_) |
| 274 return requested_enabled_color_; | 277 return requested_enabled_color_; |
| 275 | 278 |
| 276 if (GetNativeTheme()) { | 279 return GetNativeTheme()->GetSystemColor( |
| 277 return GetNativeTheme()->GetSystemColor( | 280 pressed_ ? ui::NativeTheme::kColorId_LinkPressed |
| 278 pressed_ ? ui::NativeTheme::kColorId_LinkPressed | 281 : ui::NativeTheme::kColorId_LinkEnabled); |
| 279 : ui::NativeTheme::kColorId_LinkEnabled); | |
| 280 } | |
| 281 | |
| 282 return gfx::kPlaceholderColor; | |
| 283 } | 282 } |
| 284 | 283 |
| 285 } // namespace views | 284 } // namespace views |
| OLD | NEW |