| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 state->role = ui::AX_ROLE_LINK; | 135 state->role = ui::AX_ROLE_LINK; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void Link::OnEnabledChanged() { | 138 void Link::OnEnabledChanged() { |
| 139 RecalculateFont(); | 139 RecalculateFont(); |
| 140 View::OnEnabledChanged(); | 140 View::OnEnabledChanged(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void Link::OnFocus() { | 143 void Link::OnFocus() { |
| 144 Label::OnFocus(); | 144 Label::OnFocus(); |
| 145 RecalculateFont(); |
| 145 // We render differently focused. | 146 // We render differently focused. |
| 146 SchedulePaint(); | 147 SchedulePaint(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void Link::OnBlur() { | 150 void Link::OnBlur() { |
| 150 Label::OnBlur(); | 151 Label::OnBlur(); |
| 152 RecalculateFont(); |
| 151 // We render differently focused. | 153 // We render differently focused. |
| 152 SchedulePaint(); | 154 SchedulePaint(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void Link::SetFontList(const gfx::FontList& font_list) { | 157 void Link::SetFontList(const gfx::FontList& font_list) { |
| 156 Label::SetFontList(font_list); | 158 Label::SetFontList(font_list); |
| 157 RecalculateFont(); | 159 RecalculateFont(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void Link::SetText(const base::string16& text) { | 162 void Link::SetText(const base::string16& text) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 void Link::SetPressed(bool pressed) { | 205 void Link::SetPressed(bool pressed) { |
| 204 if (pressed_ != pressed) { | 206 if (pressed_ != pressed) { |
| 205 pressed_ = pressed; | 207 pressed_ = pressed; |
| 206 Label::SetEnabledColor(GetEnabledColor()); | 208 Label::SetEnabledColor(GetEnabledColor()); |
| 207 RecalculateFont(); | 209 RecalculateFont(); |
| 208 SchedulePaint(); | 210 SchedulePaint(); |
| 209 } | 211 } |
| 210 } | 212 } |
| 211 | 213 |
| 212 void Link::RecalculateFont() { | 214 void Link::RecalculateFont() { |
| 213 // Underline the link iff it is enabled and |underline_| is true. | 215 // Underline the link if it is enabled and |underline_| is true. Also |
| 216 // underline to indicate focus in MD. |
| 214 const int style = font_list().GetFontStyle(); | 217 const int style = font_list().GetFontStyle(); |
| 215 const int intended_style = (enabled() && underline_) ? | 218 const bool underline = |
| 219 underline_ || |
| 220 (HasFocus() && ui::MaterialDesignController::IsSecondaryUiMaterial()); |
| 221 const int intended_style = (enabled() && underline) ? |
| 216 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); | 222 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); |
| 223 |
| 217 if (style != intended_style) | 224 if (style != intended_style) |
| 218 Label::SetFontList(font_list().DeriveWithStyle(intended_style)); | 225 Label::SetFontList(font_list().DeriveWithStyle(intended_style)); |
| 219 } | 226 } |
| 220 | 227 |
| 221 void Link::ConfigureFocus() { | 228 void Link::ConfigureFocus() { |
| 222 // Disable focusability for empty links. Otherwise Label::GetInsets() will | 229 // Disable focusability for empty links. Otherwise Label::GetInsets() will |
| 223 // give them an unconditional 1-px. inset on every side to allow for a focus | 230 // give them an unconditional 1-px. inset on every side to allow for a focus |
| 224 // border, when in this case we probably wanted zero width. | 231 // border, when in this case we probably wanted zero width. |
| 225 if (text().empty()) { | 232 if (text().empty()) { |
| 226 SetFocusBehavior(FocusBehavior::NEVER); | 233 SetFocusBehavior(FocusBehavior::NEVER); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 245 } | 252 } |
| 246 | 253 |
| 247 if (!requested_pressed_color_set_ && GetNativeTheme()) | 254 if (!requested_pressed_color_set_ && GetNativeTheme()) |
| 248 return GetNativeTheme()->GetSystemColor( | 255 return GetNativeTheme()->GetSystemColor( |
| 249 ui::NativeTheme::kColorId_LinkPressed); | 256 ui::NativeTheme::kColorId_LinkPressed); |
| 250 | 257 |
| 251 return requested_pressed_color_; | 258 return requested_pressed_color_; |
| 252 } | 259 } |
| 253 | 260 |
| 254 } // namespace views | 261 } // namespace views |
| OLD | NEW |