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