Commit e20a1040 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HTMLSelectElement::UpdateMultiSelectListBoxFocus() to SelectType

This CL has no behavior changes.

Bug: 1052232
Change-Id: I9417bbe69cc2de2a171b537d50a487923165bafe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065569Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742953}
parent f770fa48
...@@ -95,7 +95,6 @@ HTMLSelectElement::HTMLSelectElement(Document& document) ...@@ -95,7 +95,6 @@ HTMLSelectElement::HTMLSelectElement(Document& document)
size_(0), size_(0),
last_on_change_option_(nullptr), last_on_change_option_(nullptr),
is_multiple_(false), is_multiple_(false),
is_in_non_contiguous_selection_(false),
active_selection_state_(false), active_selection_state_(false),
should_recalc_list_items_(false), should_recalc_list_items_(false),
is_autofilled_by_preview_(false), is_autofilled_by_preview_(false),
...@@ -665,7 +664,7 @@ void HTMLSelectElement::UpdateListBoxSelection(bool deselect_other_options, ...@@ -665,7 +664,7 @@ void HTMLSelectElement::UpdateListBoxSelection(bool deselect_other_options,
++i; ++i;
} }
UpdateMultiSelectListBoxFocus(); select_type_->UpdateMultiSelectFocus();
SetNeedsValidityCheck(); SetNeedsValidityCheck();
if (scroll) if (scroll)
ScrollToSelection(); ScrollToSelection();
...@@ -703,20 +702,6 @@ void HTMLSelectElement::ListBoxOnChange() { ...@@ -703,20 +702,6 @@ void HTMLSelectElement::ListBoxOnChange() {
} }
} }
void HTMLSelectElement::UpdateMultiSelectListBoxFocus() {
if (!is_multiple_)
return;
for (auto* const option : GetOptionList()) {
if (option->IsDisabledFormControl() || !option->GetLayoutObject())
continue;
bool is_focused =
(option == active_selection_end_) && is_in_non_contiguous_selection_;
option->SetMultiSelectFocusedState(is_focused);
}
ScrollToSelection();
}
void HTMLSelectElement::DispatchInputAndChangeEventForMenuList() { void HTMLSelectElement::DispatchInputAndChangeEventForMenuList() {
DCHECK(UsesMenuList()); DCHECK(UsesMenuList());
......
...@@ -265,7 +265,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -265,7 +265,6 @@ class CORE_EXPORT HTMLSelectElement final
wtf_size_t list_index_start, wtf_size_t list_index_start,
wtf_size_t list_index_end) const; wtf_size_t list_index_end) const;
void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true); void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true);
void UpdateMultiSelectListBoxFocus();
void SetIndexToSelectOnCancel(int list_index); void SetIndexToSelectOnCancel(int list_index);
void SetSuggestedOption(HTMLOptionElement*); void SetSuggestedOption(HTMLOptionElement*);
void ToggleSelection(HTMLOptionElement&); void ToggleSelection(HTMLOptionElement&);
...@@ -319,7 +318,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -319,7 +318,6 @@ class CORE_EXPORT HTMLSelectElement final
Member<HTMLOptionElement> suggested_option_; Member<HTMLOptionElement> suggested_option_;
bool uses_menu_list_ = true; bool uses_menu_list_ = true;
bool is_multiple_; bool is_multiple_;
bool is_in_non_contiguous_selection_;
bool active_selection_state_; bool active_selection_state_;
mutable bool should_recalc_list_items_; mutable bool should_recalc_list_items_;
bool is_autofilled_by_preview_; bool is_autofilled_by_preview_;
......
...@@ -335,6 +335,10 @@ class ListBoxSelectType final : public SelectType { ...@@ -335,6 +335,10 @@ class ListBoxSelectType final : public SelectType {
public: public:
explicit ListBoxSelectType(HTMLSelectElement& select) : SelectType(select) {} explicit ListBoxSelectType(HTMLSelectElement& select) : SelectType(select) {}
bool DefaultEventHandler(const Event& event) override; bool DefaultEventHandler(const Event& event) override;
void UpdateMultiSelectFocus() override;
private:
bool is_in_non_contiguous_selection_ = false;
}; };
bool ListBoxSelectType::DefaultEventHandler(const Event& event) { bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
...@@ -527,12 +531,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -527,12 +531,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
select_->SetActiveSelectionEnd(end_option); select_->SetActiveSelectionEnd(end_option);
select_->is_in_non_contiguous_selection_ = is_in_non_contiguous_selection_ = select_->is_multiple_ && is_control_key;
select_->is_multiple_ && is_control_key;
bool select_new_item = bool select_new_item =
!select_->is_multiple_ || keyboard_event->shiftKey() || !select_->is_multiple_ || keyboard_event->shiftKey() ||
(!IsSpatialNavigationEnabled(select_->GetDocument().GetFrame()) && (!IsSpatialNavigationEnabled(select_->GetDocument().GetFrame()) &&
!select_->is_in_non_contiguous_selection_); !is_in_non_contiguous_selection_);
if (select_new_item) if (select_new_item)
select_->active_selection_state_ = true; select_->active_selection_state_ = true;
// If the anchor is uninitialized, or if we're going to deselect all // If the anchor is uninitialized, or if we're going to deselect all
...@@ -546,12 +549,12 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -546,12 +549,12 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
} }
select_->ScrollToOption(end_option); select_->ScrollToOption(end_option);
if (select_new_item || select_->is_in_non_contiguous_selection_) { if (select_new_item || is_in_non_contiguous_selection_) {
if (select_new_item) { if (select_new_item) {
select_->UpdateListBoxSelection(deselect_others); select_->UpdateListBoxSelection(deselect_others);
select_->ListBoxOnChange(); select_->ListBoxOnChange();
} }
select_->UpdateMultiSelectListBoxFocus(); UpdateMultiSelectFocus();
} else { } else {
select_->ScrollToSelection(); select_->ScrollToSelection();
} }
...@@ -572,7 +575,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -572,7 +575,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return true; return true;
} else if (select_->is_multiple_ && key_code == ' ' && } else if (select_->is_multiple_ && key_code == ' ' &&
(IsSpatialNavigationEnabled(select_->GetDocument().GetFrame()) || (IsSpatialNavigationEnabled(select_->GetDocument().GetFrame()) ||
select_->is_in_non_contiguous_selection_)) { is_in_non_contiguous_selection_)) {
HTMLOptionElement* option = select_->active_selection_end_; HTMLOptionElement* option = select_->active_selection_end_;
// If there's no active selection, // If there's no active selection,
// act as if "ArrowDown" had been pressed. // act as if "ArrowDown" had been pressed.
...@@ -589,6 +592,20 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -589,6 +592,20 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return false; return false;
} }
void ListBoxSelectType::UpdateMultiSelectFocus() {
if (!select_->is_multiple_)
return;
for (auto* const option : select_->GetOptionList()) {
if (option->IsDisabledFormControl() || !option->GetLayoutObject())
continue;
bool is_focused = (option == select_->active_selection_end_) &&
is_in_non_contiguous_selection_;
option->SetMultiSelectFocusedState(is_focused);
}
select_->ScrollToSelection();
}
// ============================================================================ // ============================================================================
SelectType::SelectType(HTMLSelectElement& select) : select_(select) {} SelectType::SelectType(HTMLSelectElement& select) : select_(select) {}
...@@ -624,4 +641,6 @@ const ComputedStyle* SelectType::OptionStyle() const { ...@@ -624,4 +641,6 @@ const ComputedStyle* SelectType::OptionStyle() const {
return nullptr; return nullptr;
} }
void SelectType::UpdateMultiSelectFocus() {}
} // namespace blink } // namespace blink
...@@ -36,6 +36,9 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -36,6 +36,9 @@ class SelectType : public GarbageCollected<SelectType> {
virtual const ComputedStyle* OptionStyle() const; virtual const ComputedStyle* OptionStyle() const;
// Update :-internal-multi-select-focus state of selected OPTIONs.
virtual void UpdateMultiSelectFocus();
// TODO(crbug.com/1052232): Add more virtual functions. // TODO(crbug.com/1052232): Add more virtual functions.
protected: protected:
......
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