Commit ff60fb54 authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Convert enum to enum class for Button::KeyClickAction

Use enum class instead of enum for ButtonKey::ClickAction
enum class is more type safety.

Bug: 940736
Change-Id: Iaf2caca28d4fc72efb933761030f365454325e80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844913
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703590}
parent 49cd7de8
......@@ -282,11 +282,10 @@ void HoverButton::SetTitleTextWithHintRange(const base::string16& title_text,
views::Button::KeyClickAction HoverButton::GetKeyClickActionForEvent(
const ui::KeyEvent& event) {
if (event.key_code() == ui::VKEY_RETURN) {
// As the hover button is presented in the user menu, it triggers an
// |CLICK_ON_KEY_PRESS| action every time the user clicks on enter on all
// platforms (it ignores the value of
// |PlatformStyle::kReturnClicksFocusedControl|.
return CLICK_ON_KEY_PRESS;
// As the hover button is presented in the user menu, it triggers a
// kOnKeyPress action every time the user clicks on enter on all platforms.
// (it ignores the value of PlatformStyle::kReturnClicksFocusedControl)
return KeyClickAction::kOnKeyPress;
}
return LabelButton::GetKeyClickActionForEvent(event);
}
......
......@@ -146,7 +146,7 @@ bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
bool ContentSettingImageView::OnKeyPressed(const ui::KeyEvent& event) {
// Pause animation so that the icon does not shrink and deselect while the
// user is attempting to press it using key commands.
if (GetKeyClickActionForEvent(event) == KeyClickAction::CLICK_ON_KEY_RELEASE)
if (GetKeyClickActionForEvent(event) == KeyClickAction::kOnKeyRelease)
PauseAnimation();
return Button::OnKeyPressed(event);
}
......
......@@ -280,8 +280,8 @@ Button::KeyClickAction Button::GetKeyClickActionForEvent(
return PlatformStyle::kKeyClickActionOnSpace;
if (event.key_code() == ui::VKEY_RETURN &&
PlatformStyle::kReturnClicksFocusedControl)
return CLICK_ON_KEY_PRESS;
return CLICK_NONE;
return KeyClickAction::kOnKeyPress;
return KeyClickAction::kNone;
}
void Button::SetButtonController(
......@@ -370,7 +370,7 @@ bool Button::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) {
// If this button is focused and the user presses space or enter, don't let
// that be treated as an accelerator if there is a key click action
// corresponding to it.
return GetKeyClickActionForEvent(event) != KeyClickAction::CLICK_NONE;
return GetKeyClickActionForEvent(event) != KeyClickAction::kNone;
}
base::string16 Button::GetTooltipText(const gfx::Point& p) const {
......
......@@ -62,10 +62,10 @@ class VIEWS_EXPORT Button : public InkDropHostView,
// An enum describing the events on which a button should be clicked for a
// given key event.
enum KeyClickAction {
CLICK_ON_KEY_PRESS,
CLICK_ON_KEY_RELEASE,
CLICK_NONE,
enum class KeyClickAction {
kOnKeyPress,
kOnKeyRelease,
kNone,
};
// TODO(cyan): Consider having Button implement ButtonControllerDelegate.
......
......@@ -80,7 +80,7 @@ bool ButtonController::OnKeyPressed(const ui::KeyEvent& event) {
return false;
switch (button_->GetKeyClickActionForEvent(event)) {
case Button::KeyClickAction::CLICK_ON_KEY_RELEASE:
case Button::KeyClickAction::kOnKeyRelease:
button_->SetState(Button::STATE_PRESSED);
if (button_controller_delegate_->GetInkDrop()->GetTargetInkDropState() !=
InkDropState::ACTION_PENDING) {
......@@ -88,11 +88,11 @@ bool ButtonController::OnKeyPressed(const ui::KeyEvent& event) {
nullptr /* event */);
}
return true;
case Button::KeyClickAction::CLICK_ON_KEY_PRESS:
case Button::KeyClickAction::kOnKeyPress:
button_->SetState(Button::STATE_NORMAL);
button_controller_delegate_->NotifyClick(event);
return true;
case Button::KeyClickAction::CLICK_NONE:
case Button::KeyClickAction::kNone:
return false;
}
......@@ -103,7 +103,7 @@ bool ButtonController::OnKeyPressed(const ui::KeyEvent& event) {
bool ButtonController::OnKeyReleased(const ui::KeyEvent& event) {
const bool click_button = button_->state() == Button::STATE_PRESSED &&
button_->GetKeyClickActionForEvent(event) ==
Button::KeyClickAction::CLICK_ON_KEY_RELEASE;
Button::KeyClickAction::kOnKeyRelease;
if (!click_button)
return false;
......
......@@ -72,7 +72,7 @@ class TestButton : public Button, public ButtonListener {
~TestButton() override = default;
KeyClickAction GetKeyClickActionForEvent(const ui::KeyEvent& event) override {
if (custom_key_click_action_ == KeyClickAction::CLICK_NONE)
if (custom_key_click_action_ == KeyClickAction::kNone)
return Button::GetKeyClickActionForEvent(event);
return custom_key_click_action_;
}
......@@ -117,7 +117,7 @@ class TestButton : public Button, public ButtonListener {
int ink_drop_layer_add_count_ = 0;
int ink_drop_layer_remove_count_ = 0;
KeyClickAction custom_key_click_action_ = KeyClickAction::CLICK_NONE;
KeyClickAction custom_key_click_action_ = KeyClickAction::kNone;
DISALLOW_COPY_AND_ASSIGN(TestButton);
};
......@@ -831,9 +831,8 @@ TEST_F(ButtonTest, CustomActionOnKeyPressedEvent) {
button()->RequestFocus();
EXPECT_TRUE(button()->HasFocus());
// Set the button to handle any key pressed event as |CLICK_ON_KEY_PRESS|.
button()->set_custom_key_click_action(
Button::KeyClickAction::CLICK_ON_KEY_PRESS);
// Set the button to handle any key pressed event as kOnKeyPress.
button()->set_custom_key_click_action(Button::KeyClickAction::kOnKeyPress);
ui::KeyEvent control_press(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, ui::EF_NONE);
EXPECT_TRUE(button()->OnKeyPressed(control_press));
......
......@@ -42,7 +42,7 @@ const bool PlatformStyle::kDialogDefaultButtonCanBeCancel = true;
const bool PlatformStyle::kSelectWordOnRightClick = false;
const bool PlatformStyle::kSelectAllOnRightClickWhenUnfocused = false;
const Button::KeyClickAction PlatformStyle::kKeyClickActionOnSpace =
Button::CLICK_ON_KEY_RELEASE;
Button::KeyClickAction::kOnKeyRelease;
const bool PlatformStyle::kReturnClicksFocusedControl = true;
const bool PlatformStyle::kTableViewSupportsKeyboardNavigationByCell = true;
const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = false;
......
......@@ -46,7 +46,7 @@ const bool PlatformStyle::kPreferFocusRings = true;
const bool PlatformStyle::kInactiveWidgetControlsAppearDisabled = true;
const Button::KeyClickAction PlatformStyle::kKeyClickActionOnSpace =
Button::CLICK_ON_KEY_PRESS;
Button::KeyClickAction::kOnKeyPress;
// On Mac, the Return key is used to perform the default action even when a
// control is focused.
......
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