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 | 23 |
24 namespace views { | 24 namespace views { |
25 | 25 |
26 // static | |
26 const char Link::kViewClassName[] = "Link"; | 27 const char Link::kViewClassName[] = "Link"; |
28 const int Link::kFocusBorderPadding = 1; | |
27 | 29 |
28 Link::Link() : Link(base::string16()) {} | 30 Link::Link() : Link(base::string16()) {} |
29 | 31 |
30 Link::Link(const base::string16& title) | 32 Link::Link(const base::string16& title) |
31 : Label(title), | 33 : Label(title), |
32 requested_enabled_color_(gfx::kPlaceholderColor), | 34 requested_enabled_color_(gfx::kPlaceholderColor), |
33 requested_enabled_color_set_(false), | 35 requested_enabled_color_set_(false), |
34 requested_pressed_color_(gfx::kPlaceholderColor), | 36 requested_pressed_color_(gfx::kPlaceholderColor), |
35 requested_pressed_color_set_(false) { | 37 requested_pressed_color_set_(false) { |
36 Init(); | 38 Init(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { |
161 Label::SetText(text); | 163 Label::SetText(text); |
162 // Disable focusability for empty links. Otherwise Label::GetInsets() will | 164 // Disable focusability for empty links. |
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. | |
165 SetFocusBehavior(text.empty() ? FocusBehavior::NEVER : FocusBehavior::ALWAYS); | 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; |
176 requested_enabled_color_ = color; | 176 requested_enabled_color_ = color; |
177 Label::SetEnabledColor(GetEnabledColor()); | 177 Label::SetEnabledColor(GetEnabledColor()); |
178 } | 178 } |
179 | 179 |
180 gfx::Insets Link::GetInsets() const { | |
181 gfx::Insets insets = Label::GetInsets(); | |
182 // Non-empty links will have a focus border around them. | |
183 if (!text().empty()) { | |
karandeepb
2016/04/27 08:04:40
There are 1-2 instances where the focusability of
| |
184 insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, | |
185 kFocusBorderPadding, kFocusBorderPadding); | |
186 } | |
187 return insets; | |
188 } | |
189 | |
180 void Link::SetPressedColor(SkColor color) { | 190 void Link::SetPressedColor(SkColor color) { |
181 requested_pressed_color_set_ = true; | 191 requested_pressed_color_set_ = true; |
182 requested_pressed_color_ = color; | 192 requested_pressed_color_ = color; |
183 Label::SetEnabledColor(GetEnabledColor()); | 193 Label::SetEnabledColor(GetEnabledColor()); |
184 } | 194 } |
185 | 195 |
186 void Link::SetUnderline(bool underline) { | 196 void Link::SetUnderline(bool underline) { |
187 if (underline_ == underline) | 197 if (underline_ == underline) |
188 return; | 198 return; |
189 underline_ = underline; | 199 underline_ = underline; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 } | 244 } |
235 | 245 |
236 if (!requested_pressed_color_set_ && GetNativeTheme()) | 246 if (!requested_pressed_color_set_ && GetNativeTheme()) |
237 return GetNativeTheme()->GetSystemColor( | 247 return GetNativeTheme()->GetSystemColor( |
238 ui::NativeTheme::kColorId_LinkPressed); | 248 ui::NativeTheme::kColorId_LinkPressed); |
239 | 249 |
240 return requested_pressed_color_; | 250 return requested_pressed_color_; |
241 } | 251 } |
242 | 252 |
243 } // namespace views | 253 } // namespace views |
OLD | NEW |