Commit ae4abbb5 authored by Wei Li's avatar Wei Li Committed by Chromium LUCI CQ

Simplify default focus behavior definition

Use a variable instead of a static function to represent the default
focus behavior in platform style files.

Bug: 1001103
Change-Id: Icf92ea6b83037ba3b285ba0c5eccb7bc16f1f460
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2579653Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835278}
parent 7947c660
......@@ -377,7 +377,7 @@ in system settings needs to be enabled to have navigation of all controls on the
screen.
To comply with Mac’s behavior, Chrome sets
[DefaultFocusBehavior() ](https://source.chromium.org/chromium/chromium/src/+/master:ui/views/style/platform_style_mac.mm;l=86)in
[kDefaultFocusBehavior](https://source.chromium.org/chromium/chromium/src/+/master:ui/views/style/platform_style.h?q=kDefaultFocusBehavior) in
the platform style to ACCESSIBLE_ONLY on Mac as opposed to ALWAYS on other
platforms. Controls that are
[marked](https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/ui/views/toolbar/toolbar_button.cc;drc=93819857a690b79b1524052513747846c068ca90;l=104)
......
......@@ -591,7 +591,7 @@ Button::Button(PressedCallback callback)
: AnimationDelegateViews(this),
callback_(std::move(callback)),
ink_drop_base_color_(gfx::kPlaceholderColor) {
SetFocusBehavior(PlatformStyle::DefaultFocusBehavior());
SetFocusBehavior(PlatformStyle::kDefaultFocusBehavior);
SetProperty(kIsButtonProperty, true);
hover_animation_.SetSlideDuration(base::TimeDelta::FromMilliseconds(150));
SetInstallFocusRingOnFocus(true);
......
......@@ -43,7 +43,7 @@ using ImageButtonTest = ViewsTestBase;
TEST_F(ImageButtonTest, FocusBehavior) {
ImageButton button;
EXPECT_EQ(PlatformStyle::DefaultFocusBehavior(), button.GetFocusBehavior());
EXPECT_EQ(PlatformStyle::kDefaultFocusBehavior, button.GetFocusBehavior());
}
TEST_F(ImageButtonTest, Basics) {
......
......@@ -143,7 +143,7 @@ class LabelButtonTest : public test::WidgetTest {
};
TEST_F(LabelButtonTest, FocusBehavior) {
EXPECT_EQ(PlatformStyle::DefaultFocusBehavior(), button_->GetFocusBehavior());
EXPECT_EQ(PlatformStyle::kDefaultFocusBehavior, button_->GetFocusBehavior());
}
TEST_F(LabelButtonTest, Init) {
......
......@@ -127,7 +127,7 @@ void ButtonExample::LabelButtonPressed(LabelButton* label_button,
label_button->IsAccessibilityFocusable()
? label_button->SetFocusBehavior(View::FocusBehavior::NEVER)
: label_button->SetFocusBehavior(
PlatformStyle::DefaultFocusBehavior());
PlatformStyle::kDefaultFocusBehavior);
}
} else if (event.IsAltDown()) {
label_button->SetIsDefault(!label_button->GetIsDefault());
......
......@@ -50,6 +50,8 @@ const bool PlatformStyle::kUseRipples = true;
const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = false;
const bool PlatformStyle::kTextfieldUsesDragCursorWhenDraggable = true;
const bool PlatformStyle::kInactiveWidgetControlsAppearDisabled = false;
const View::FocusBehavior PlatformStyle::kDefaultFocusBehavior =
View::FocusBehavior::ALWAYS;
// Linux clips bubble windows that extend outside their parent window
// bounds.
......@@ -83,11 +85,6 @@ gfx::Range PlatformStyle::RangeToDeleteBackwards(const base::string16& text,
return gfx::Range(cursor_position, previous_grapheme_index);
}
// static
View::FocusBehavior PlatformStyle::DefaultFocusBehavior() {
return View::FocusBehavior::ALWAYS;
}
#endif // OS_APPLE
#if !BUILDFLAG(ENABLE_DESKTOP_AURA) || \
......
......@@ -80,6 +80,9 @@ class VIEWS_EXPORT PlatformStyle {
// for bubbles going off-screen to bring more bubble area into view.
static const bool kAdjustBubbleIfOffscreen;
// Default focus behavior on the platform.
static const View::FocusBehavior kDefaultFocusBehavior;
// Creates the default scrollbar for the given orientation.
static std::unique_ptr<ScrollBar> CreateScrollBar(bool is_horizontal);
......@@ -99,9 +102,6 @@ class VIEWS_EXPORT PlatformStyle {
static gfx::Range RangeToDeleteBackwards(const base::string16& text,
size_t cursor_position);
// Returns the default focus behavior based on the platform.
static View::FocusBehavior DefaultFocusBehavior();
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformStyle);
};
......
......@@ -44,6 +44,8 @@ const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = true;
const bool PlatformStyle::kUseRipples = false;
const bool PlatformStyle::kInactiveWidgetControlsAppearDisabled = true;
const bool PlatformStyle::kAdjustBubbleIfOffscreen = false;
const View::FocusBehavior PlatformStyle::kDefaultFocusBehavior =
View::FocusBehavior::ACCESSIBLE_ONLY;
const Button::KeyClickAction PlatformStyle::kKeyClickActionOnSpace =
Button::KeyClickAction::kOnKeyPress;
......@@ -82,9 +84,4 @@ gfx::Range PlatformStyle::RangeToDeleteBackwards(const base::string16& text,
range_to_delete.location);
}
// static
View::FocusBehavior PlatformStyle::DefaultFocusBehavior() {
return View::FocusBehavior::ACCESSIBLE_ONLY;
}
} // namespace views
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment