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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/link.cc
diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc
index 30e50a997607094468ddf8f0d3dc49bb9ea10602..0bd5f0ecaca83f4a11caac8493e2aa4a39b17ea8 100644
--- a/ui/views/controls/link.cc
+++ b/ui/views/controls/link.cc
@@ -159,10 +159,7 @@ void Link::SetFontList(const gfx::FontList& font_list) {
void Link::SetText(const base::string16& text) {
Label::SetText(text);
- // Disable focusability for empty links. Otherwise Label::GetInsets() will
- // give them an unconditional 1-px. inset on every side to allow for a focus
- // border, when in this case we probably wanted zero width.
- SetFocusBehavior(text.empty() ? FocusBehavior::NEVER : FocusBehavior::ALWAYS);
+ ConfigureFocus();
}
void Link::OnNativeThemeChanged(const ui::NativeTheme* theme) {
@@ -198,10 +195,9 @@ void Link::Init() {
// Label::Init() calls SetText(), but if that's being called from Label(), our
// SetText() override will not be reached (because the constructed class is
- // only a Label at the moment, not yet a Link). So set the focus behavior
- // here as well
- SetFocusBehavior(text().empty() ? FocusBehavior::NEVER
- : FocusBehavior::ALWAYS);
+ // only a Label at the moment, not yet a Link). So explicitly configure focus
+ // here.
+ ConfigureFocus();
}
void Link::SetPressed(bool pressed) {
@@ -222,6 +218,21 @@ void Link::RecalculateFont() {
Label::SetFontList(font_list().DeriveWithStyle(intended_style));
}
+void Link::ConfigureFocus() {
+ // Disable focusability for empty links. Otherwise Label::GetInsets() will
+ // give them an unconditional 1-px. inset on every side to allow for a focus
+ // border, when in this case we probably wanted zero width.
+ if (text().empty()) {
+ SetFocusBehavior(FocusBehavior::NEVER);
+ } else {
+#if defined(OS_MACOSX)
+ SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
+#else
+ SetFocusBehavior(FocusBehavior::ALWAYS);
+#endif
+ }
+}
+
SkColor Link::GetEnabledColor() {
// In material mode, there is no pressed effect, so always use the unpressed
// color.

Powered by Google App Engine
This is Rietveld 408576698