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" |
11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
12 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
13 #include "ui/base/material_design/material_design_controller.h" | 13 #include "ui/base/material_design/material_design_controller.h" |
14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
15 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/color_palette.h" | 17 #include "ui/gfx/color_palette.h" |
18 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
19 #include "ui/gfx/font_list.h" | 19 #include "ui/gfx/font_list.h" |
20 #include "ui/native_theme/native_theme.h" | 20 #include "ui/native_theme/native_theme.h" |
21 #include "ui/views/controls/link_listener.h" | 21 #include "ui/views/controls/link_listener.h" |
22 #include "ui/views/native_cursor.h" | 22 #include "ui/views/native_cursor.h" |
23 #include "ui/views/style/platform_style.h" | |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 | 26 |
26 const char Link::kViewClassName[] = "Link"; | 27 const char Link::kViewClassName[] = "Link"; |
27 | 28 |
28 Link::Link() : Link(base::string16()) {} | 29 Link::Link() : Link(base::string16()) {} |
29 | 30 |
30 Link::Link(const base::string16& title) | 31 Link::Link(const base::string16& title) |
31 : Label(title), | 32 : Label(title), |
32 requested_enabled_color_(gfx::kPlaceholderColor), | 33 requested_enabled_color_(gfx::kPlaceholderColor), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 SchedulePaint(); | 153 SchedulePaint(); |
153 } | 154 } |
154 | 155 |
155 void Link::SetFontList(const gfx::FontList& font_list) { | 156 void Link::SetFontList(const gfx::FontList& font_list) { |
156 Label::SetFontList(font_list); | 157 Label::SetFontList(font_list); |
157 RecalculateFont(); | 158 RecalculateFont(); |
158 } | 159 } |
159 | 160 |
160 void Link::SetText(const base::string16& text) { | 161 void Link::SetText(const base::string16& text) { |
161 Label::SetText(text); | 162 Label::SetText(text); |
163 | |
162 // Disable focusability for empty links. Otherwise Label::GetInsets() will | 164 // Disable focusability for empty links. Otherwise Label::GetInsets() will |
tapted
2016/02/23 03:01:19
This comment about Label::GetInsets() concerns me.
karandeepb
2016/03/15 02:19:50
Yeah GetInsets() is currently using focusable() to
| |
163 // give them an unconditional 1-px. inset on every side to allow for a focus | 165 // 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. | 166 // border, when in this case we probably wanted zero width. |
165 SetFocusable(!text.empty()); | 167 if (!text.empty()) { |
168 PlatformStyle::SetControlStyleFocus(this); | |
169 } else { | |
170 SetFocusable(false); | |
171 SetAccessibilityFocusable(false); | |
172 } | |
166 } | 173 } |
167 | 174 |
168 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 175 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
169 Label::SetEnabledColor(GetEnabledColor()); | 176 Label::SetEnabledColor(GetEnabledColor()); |
170 SetDisabledColor( | 177 SetDisabledColor( |
171 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); | 178 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); |
172 } | 179 } |
173 | 180 |
174 void Link::SetEnabledColor(SkColor color) { | 181 void Link::SetEnabledColor(SkColor color) { |
175 requested_enabled_color_set_ = true; | 182 requested_enabled_color_set_ = true; |
(...skipping 15 matching lines...) Expand all Loading... | |
191 } | 198 } |
192 | 199 |
193 void Link::Init() { | 200 void Link::Init() { |
194 listener_ = NULL; | 201 listener_ = NULL; |
195 pressed_ = false; | 202 pressed_ = false; |
196 underline_ = true; | 203 underline_ = true; |
197 RecalculateFont(); | 204 RecalculateFont(); |
198 | 205 |
199 // Label::Init() calls SetText(), but if that's being called from Label(), our | 206 // 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 | 207 // 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() | 208 // only a Label at the moment, not yet a Link). So explicitly set |
202 // call explicitly here. | 209 // focusability here. |
203 SetFocusable(!text().empty()); | 210 if (!text().empty()) { |
tapted
2016/02/23 03:01:19
This could also just call SetText again, but we sh
karandeepb
2016/03/15 02:19:50
Done.
| |
211 PlatformStyle::SetControlStyleFocus(this); | |
212 } else { | |
213 SetFocusable(false); | |
214 SetAccessibilityFocusable(false); | |
215 } | |
204 } | 216 } |
205 | 217 |
206 void Link::SetPressed(bool pressed) { | 218 void Link::SetPressed(bool pressed) { |
207 if (pressed_ != pressed) { | 219 if (pressed_ != pressed) { |
208 pressed_ = pressed; | 220 pressed_ = pressed; |
209 Label::SetEnabledColor(GetEnabledColor()); | 221 Label::SetEnabledColor(GetEnabledColor()); |
210 RecalculateFont(); | 222 RecalculateFont(); |
211 SchedulePaint(); | 223 SchedulePaint(); |
212 } | 224 } |
213 } | 225 } |
(...skipping 19 matching lines...) Expand all Loading... | |
233 } | 245 } |
234 | 246 |
235 if (!requested_pressed_color_set_ && GetNativeTheme()) | 247 if (!requested_pressed_color_set_ && GetNativeTheme()) |
236 return GetNativeTheme()->GetSystemColor( | 248 return GetNativeTheme()->GetSystemColor( |
237 ui::NativeTheme::kColorId_LinkPressed); | 249 ui::NativeTheme::kColorId_LinkPressed); |
238 | 250 |
239 return requested_pressed_color_; | 251 return requested_pressed_color_; |
240 } | 252 } |
241 | 253 |
242 } // namespace views | 254 } // namespace views |
OLD | NEW |