Commit 19cbd51a authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HandlePopupOpenKeyboardEvent(), ShouldOpenPopupForKey*Event() of...

Move HandlePopupOpenKeyboardEvent(), ShouldOpenPopupForKey*Event() of HTMLSelectElement to MenuListSelectType

They are used only by MenuListSelectType.
This CL has no behavior changes.

Bug: 1052232
Change-Id: I0fe76842e2767c4f7a0d8ee6f1e1f3cf69cec4d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065693Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743020}
parent 76ee218c
...@@ -1266,48 +1266,6 @@ void HTMLSelectElement::ResetImpl() { ...@@ -1266,48 +1266,6 @@ void HTMLSelectElement::ResetImpl() {
SetNeedsValidityCheck(); SetNeedsValidityCheck();
} }
bool HTMLSelectElement::HandlePopupOpenKeyboardEvent(const Event& event) {
focus();
// Calling focus() may cause us to lose our layoutObject. Return true so
// that our caller doesn't process the event further, but don't set
// the event as handled.
if (!GetLayoutObject() || !UsesMenuList() || IsDisabledFormControl())
return false;
// Save the selection so it can be compared to the new selection when
// dispatching change events during selectOption, which gets called from
// selectOptionByPopup, which gets called after the user makes a selection
// from the menu.
SaveLastSelection();
ShowPopup();
return true;
}
bool HTMLSelectElement::ShouldOpenPopupForKeyDownEvent(
const KeyboardEvent& key_event) {
const String& key = key_event.key();
LayoutTheme& layout_theme = LayoutTheme::GetTheme();
if (IsSpatialNavigationEnabled(GetDocument().GetFrame()))
return false;
return ((layout_theme.PopsMenuByArrowKeys() &&
(key == "ArrowDown" || key == "ArrowUp")) ||
(layout_theme.PopsMenuByAltDownUpOrF4Key() &&
(key == "ArrowDown" || key == "ArrowUp") && key_event.altKey()) ||
(layout_theme.PopsMenuByAltDownUpOrF4Key() &&
(!key_event.altKey() && !key_event.ctrlKey() && key == "F4")));
}
bool HTMLSelectElement::ShouldOpenPopupForKeyPressEvent(
const KeyboardEvent& event) {
LayoutTheme& layout_theme = LayoutTheme::GetTheme();
int key_code = event.keyCode();
return ((layout_theme.PopsMenuBySpaceKey() && key_code == ' ' &&
!type_ahead_.HasActiveSession(event)) ||
(layout_theme.PopsMenuByReturnKey() && key_code == '\r'));
}
void HTMLSelectElement::SetPopupIsVisible(bool popup_is_visible) { void HTMLSelectElement::SetPopupIsVisible(bool popup_is_visible) {
popup_is_visible_ = popup_is_visible; popup_is_visible_ = popup_is_visible;
if (::features::IsFormControlsRefreshEnabled() && GetLayoutObject()) { if (::features::IsFormControlsRefreshEnabled() && GetLayoutObject()) {
......
...@@ -255,10 +255,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -255,10 +255,6 @@ class CORE_EXPORT HTMLSelectElement final
void ParseMultipleAttribute(const AtomicString&); void ParseMultipleAttribute(const AtomicString&);
HTMLOptionElement* LastSelectedOption() const; HTMLOptionElement* LastSelectedOption() const;
void UpdateSelectedState(HTMLOptionElement*, bool multi, bool shift); void UpdateSelectedState(HTMLOptionElement*, bool multi, bool shift);
// Returns true if this function handled the event.
bool HandlePopupOpenKeyboardEvent(const Event&);
bool ShouldOpenPopupForKeyDownEvent(const KeyboardEvent&);
bool ShouldOpenPopupForKeyPressEvent(const KeyboardEvent&);
void SetPopupIsVisible(bool); void SetPopupIsVisible(bool);
void SetOptionsChangedOnLayoutObject(); void SetOptionsChangedOnLayoutObject();
wtf_size_t SearchOptionsForValue(const String&, wtf_size_t SearchOptionsForValue(const String&,
......
...@@ -75,6 +75,11 @@ class MenuListSelectType final : public SelectType { ...@@ -75,6 +75,11 @@ class MenuListSelectType final : public SelectType {
} }
private: private:
bool ShouldOpenPopupForKeyDownEvent(const KeyboardEvent& event);
bool ShouldOpenPopupForKeyPressEvent(const KeyboardEvent& event);
// Returns true if this function handled the event.
bool HandlePopupOpenKeyboardEvent();
String UpdateTextStyleInternal(); String UpdateTextStyleInternal();
void DidUpdateActiveOption(HTMLOptionElement* option); void DidUpdateActiveOption(HTMLOptionElement* option);
...@@ -94,8 +99,8 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) { ...@@ -94,8 +99,8 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) {
if (!select_->GetLayoutObject() || !key_event) if (!select_->GetLayoutObject() || !key_event)
return false; return false;
if (select_->ShouldOpenPopupForKeyDownEvent(*key_event)) if (ShouldOpenPopupForKeyDownEvent(*key_event))
return select_->HandlePopupOpenKeyboardEvent(event); return HandlePopupOpenKeyboardEvent();
// When using spatial navigation, we want to be able to navigate away // When using spatial navigation, we want to be able to navigate away
// from the select element when the user hits any of the arrow keys, // from the select element when the user hits any of the arrow keys,
...@@ -167,8 +172,8 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) { ...@@ -167,8 +172,8 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) {
return true; return true;
} }
if (select_->ShouldOpenPopupForKeyPressEvent(*key_event)) if (ShouldOpenPopupForKeyPressEvent(*key_event))
return select_->HandlePopupOpenKeyboardEvent(event); return HandlePopupOpenKeyboardEvent();
if (!LayoutTheme::GetTheme().PopsMenuByReturnKey() && key_code == '\r') { if (!LayoutTheme::GetTheme().PopsMenuByReturnKey() && key_code == '\r') {
if (HTMLFormElement* form = select_->Form()) if (HTMLFormElement* form = select_->Form())
...@@ -212,6 +217,49 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) { ...@@ -212,6 +217,49 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) {
return false; return false;
} }
bool MenuListSelectType::ShouldOpenPopupForKeyDownEvent(
const KeyboardEvent& event) {
const String& key = event.key();
LayoutTheme& layout_theme = LayoutTheme::GetTheme();
if (IsSpatialNavigationEnabled(select_->GetDocument().GetFrame()))
return false;
return ((layout_theme.PopsMenuByArrowKeys() &&
(key == "ArrowDown" || key == "ArrowUp")) ||
(layout_theme.PopsMenuByAltDownUpOrF4Key() &&
(key == "ArrowDown" || key == "ArrowUp") && event.altKey()) ||
(layout_theme.PopsMenuByAltDownUpOrF4Key() &&
(!event.altKey() && !event.ctrlKey() && key == "F4")));
}
bool MenuListSelectType::ShouldOpenPopupForKeyPressEvent(
const KeyboardEvent& event) {
LayoutTheme& layout_theme = LayoutTheme::GetTheme();
int key_code = event.keyCode();
return ((layout_theme.PopsMenuBySpaceKey() && key_code == ' ' &&
!select_->type_ahead_.HasActiveSession(event)) ||
(layout_theme.PopsMenuByReturnKey() && key_code == '\r'));
}
bool MenuListSelectType::HandlePopupOpenKeyboardEvent() {
select_->focus();
// Calling focus() may cause us to lose our LayoutObject. Return true so
// that our caller doesn't process the event further, but don't set
// the event as handled.
if (!select_->GetLayoutObject() || will_be_destroyed_ ||
select_->IsDisabledFormControl())
return false;
// Save the selection so it can be compared to the new selection when
// dispatching change events during SelectOption, which gets called from
// SelectOptionByPopup, which gets called after the user makes a selection
// from the menu.
select_->SaveLastSelection();
select_->ShowPopup();
return true;
}
void MenuListSelectType::DidSelectOption( void MenuListSelectType::DidSelectOption(
HTMLOptionElement* element, HTMLOptionElement* element,
HTMLSelectElement::SelectOptionFlags flags, HTMLSelectElement::SelectOptionFlags flags,
......
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