Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: ui/views/controls/link.cc

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Rebased Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Disable focusability for empty links. Otherwise Label::GetInsets() will 162 ConfigureFocus();
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);
166 } 163 }
167 164
168 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) { 165 void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) {
169 Label::SetEnabledColor(GetEnabledColor()); 166 Label::SetEnabledColor(GetEnabledColor());
170 SetDisabledColor( 167 SetDisabledColor(
171 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled)); 168 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled));
172 } 169 }
173 170
174 void Link::SetEnabledColor(SkColor color) { 171 void Link::SetEnabledColor(SkColor color) {
175 requested_enabled_color_set_ = true; 172 requested_enabled_color_set_ = true;
(...skipping 15 matching lines...) Expand all
191 } 188 }
192 189
193 void Link::Init() { 190 void Link::Init() {
194 listener_ = NULL; 191 listener_ = NULL;
195 pressed_ = false; 192 pressed_ = false;
196 underline_ = true; 193 underline_ = true;
197 RecalculateFont(); 194 RecalculateFont();
198 195
199 // Label::Init() calls SetText(), but if that's being called from Label(), our 196 // 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 197 // SetText() override will not be reached (because the constructed class is
201 // only a Label at the moment, not yet a Link). So set the focus behavior 198 // only a Label at the moment, not yet a Link). So explicitly configure focus
202 // here as well 199 // here.
203 SetFocusBehavior(text().empty() ? FocusBehavior::NEVER 200 ConfigureFocus();
204 : FocusBehavior::ALWAYS);
205 } 201 }
206 202
207 void Link::SetPressed(bool pressed) { 203 void Link::SetPressed(bool pressed) {
208 if (pressed_ != pressed) { 204 if (pressed_ != pressed) {
209 pressed_ = pressed; 205 pressed_ = pressed;
210 Label::SetEnabledColor(GetEnabledColor()); 206 Label::SetEnabledColor(GetEnabledColor());
211 RecalculateFont(); 207 RecalculateFont();
212 SchedulePaint(); 208 SchedulePaint();
213 } 209 }
214 } 210 }
215 211
216 void Link::RecalculateFont() { 212 void Link::RecalculateFont() {
217 // Underline the link iff it is enabled and |underline_| is true. 213 // Underline the link iff it is enabled and |underline_| is true.
218 const int style = font_list().GetFontStyle(); 214 const int style = font_list().GetFontStyle();
219 const int intended_style = (enabled() && underline_) ? 215 const int intended_style = (enabled() && underline_) ?
220 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE); 216 (style | gfx::Font::UNDERLINE) : (style & ~gfx::Font::UNDERLINE);
221 if (style != intended_style) 217 if (style != intended_style)
222 Label::SetFontList(font_list().DeriveWithStyle(intended_style)); 218 Label::SetFontList(font_list().DeriveWithStyle(intended_style));
223 } 219 }
224 220
221 void Link::ConfigureFocus() {
222 // 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
224 // border, when in this case we probably wanted zero width.
225 if (text().empty()) {
226 SetFocusBehavior(FocusBehavior::NEVER);
227 } else {
228 #if defined(OS_MACOSX)
229 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
230 #else
231 SetFocusBehavior(FocusBehavior::ALWAYS);
232 #endif
233 }
234 }
235
225 SkColor Link::GetEnabledColor() { 236 SkColor Link::GetEnabledColor() {
226 // In material mode, there is no pressed effect, so always use the unpressed 237 // In material mode, there is no pressed effect, so always use the unpressed
227 // color. 238 // color.
228 if (!pressed_ || ui::MaterialDesignController::IsModeMaterial()) { 239 if (!pressed_ || ui::MaterialDesignController::IsModeMaterial()) {
229 if (!requested_enabled_color_set_ && GetNativeTheme()) 240 if (!requested_enabled_color_set_ && GetNativeTheme())
230 return GetNativeTheme()->GetSystemColor( 241 return GetNativeTheme()->GetSystemColor(
231 ui::NativeTheme::kColorId_LinkEnabled); 242 ui::NativeTheme::kColorId_LinkEnabled);
232 243
233 return requested_enabled_color_; 244 return requested_enabled_color_;
234 } 245 }
235 246
236 if (!requested_pressed_color_set_ && GetNativeTheme()) 247 if (!requested_pressed_color_set_ && GetNativeTheme())
237 return GetNativeTheme()->GetSystemColor( 248 return GetNativeTheme()->GetSystemColor(
238 ui::NativeTheme::kColorId_LinkPressed); 249 ui::NativeTheme::kColorId_LinkPressed);
239 250
240 return requested_pressed_color_; 251 return requested_pressed_color_;
241 } 252 }
242 253
243 } // namespace views 254 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698