Commit 31b4286a authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HTMLSelectElement::UpdateListBoxSelection() to ListBoxSelectType

Also, this CL makes SelectType::UpdateMultiSelectFocus() a private
function of ListBoxSelectType. Only ListBoxSelectType needs it.

This CL has no behavior changes.

Bug: 1052232
Change-Id: Idc6a86adc0ad9cd4c8d51caa51a2d58251f9e254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098138
Auto-Submit: Kent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749457}
parent 30750caa
...@@ -554,46 +554,6 @@ void HTMLSelectElement::SetActiveSelectionEnd(HTMLOptionElement* option) { ...@@ -554,46 +554,6 @@ void HTMLSelectElement::SetActiveSelectionEnd(HTMLOptionElement* option) {
active_selection_end_ = option; active_selection_end_ = option;
} }
void HTMLSelectElement::UpdateListBoxSelection(bool deselect_other_options,
bool scroll) {
DCHECK(GetLayoutObject());
DCHECK(!UsesMenuList() || is_multiple_);
int active_selection_anchor_index =
active_selection_anchor_ ? active_selection_anchor_->index() : -1;
int active_selection_end_index =
active_selection_end_ ? active_selection_end_->index() : -1;
int start =
std::min(active_selection_anchor_index, active_selection_end_index);
int end = std::max(active_selection_anchor_index, active_selection_end_index);
int i = 0;
for (auto* const option : GetOptionList()) {
if (option->IsDisabledFormControl() || !option->GetLayoutObject()) {
++i;
continue;
}
if (i >= start && i <= end) {
option->SetSelectedState(active_selection_state_);
option->SetDirty(true);
} else if (deselect_other_options ||
i >= static_cast<int>(
cached_state_for_active_selection_.size())) {
option->SetSelectedState(false);
option->SetDirty(true);
} else {
option->SetSelectedState(cached_state_for_active_selection_[i]);
}
++i;
}
select_type_->UpdateMultiSelectFocus();
SetNeedsValidityCheck();
if (scroll)
ScrollToSelection();
NotifyFormStateChanged();
}
void HTMLSelectElement::ListBoxOnChange() { void HTMLSelectElement::ListBoxOnChange() {
DCHECK(!UsesMenuList()); DCHECK(!UsesMenuList());
......
...@@ -257,7 +257,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -257,7 +257,6 @@ class CORE_EXPORT HTMLSelectElement final
wtf_size_t SearchOptionsForValue(const String&, wtf_size_t SearchOptionsForValue(const String&,
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 SetIndexToSelectOnCancel(int list_index); void SetIndexToSelectOnCancel(int list_index);
void SetSuggestedOption(HTMLOptionElement*); void SetSuggestedOption(HTMLOptionElement*);
......
...@@ -608,12 +608,13 @@ class ListBoxSelectType final : public SelectType { ...@@ -608,12 +608,13 @@ class ListBoxSelectType final : public SelectType {
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 DidSetSuggestedOption(HTMLOptionElement* option) override; void DidSetSuggestedOption(HTMLOptionElement* option) override;
void UpdateMultiSelectFocus() override;
void SelectAll() override; void SelectAll() override;
private: private:
HTMLOptionElement* NextSelectableOptionPageAway(HTMLOptionElement*, HTMLOptionElement* NextSelectableOptionPageAway(HTMLOptionElement*,
SkipDirection) const; SkipDirection) const;
// Update :-internal-multi-select-focus state of selected OPTIONs.
void UpdateMultiSelectFocus();
void ToggleSelection(HTMLOptionElement& option); void ToggleSelection(HTMLOptionElement& option);
enum class SelectionMode { enum class SelectionMode {
kDeselectOthers, kDeselectOthers,
...@@ -622,6 +623,7 @@ class ListBoxSelectType final : public SelectType { ...@@ -622,6 +623,7 @@ class ListBoxSelectType final : public SelectType {
}; };
void UpdateSelectedState(HTMLOptionElement* clicked_option, void UpdateSelectedState(HTMLOptionElement* clicked_option,
SelectionMode mode); SelectionMode mode);
void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true);
bool is_in_non_contiguous_selection_ = false; bool is_in_non_contiguous_selection_ = false;
}; };
...@@ -708,11 +710,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -708,11 +710,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return false; return false;
select_->SetActiveSelectionEnd(option); select_->SetActiveSelectionEnd(option);
select_->UpdateListBoxSelection(false); UpdateListBoxSelection(false);
} else { } else {
select_->SetActiveSelectionAnchor(option); select_->SetActiveSelectionAnchor(option);
select_->SetActiveSelectionEnd(option); select_->SetActiveSelectionEnd(option);
select_->UpdateListBoxSelection(true); UpdateListBoxSelection(true);
} }
} }
} }
...@@ -838,7 +840,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -838,7 +840,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
select_->ScrollToOption(end_option); select_->ScrollToOption(end_option);
if (select_new_item || 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); UpdateListBoxSelection(deselect_others);
select_->ListBoxOnChange(); select_->ListBoxOnChange();
} }
UpdateMultiSelectFocus(); UpdateMultiSelectFocus();
...@@ -911,7 +913,7 @@ void ListBoxSelectType::SelectAll() { ...@@ -911,7 +913,7 @@ void ListBoxSelectType::SelectAll() {
select_->SetActiveSelectionAnchor(NextSelectableOption(nullptr)); select_->SetActiveSelectionAnchor(NextSelectableOption(nullptr));
select_->SetActiveSelectionEnd(PreviousSelectableOption(nullptr)); select_->SetActiveSelectionEnd(PreviousSelectableOption(nullptr));
select_->UpdateListBoxSelection(false, false); UpdateListBoxSelection(false, false);
select_->ListBoxOnChange(); select_->ListBoxOnChange();
select_->SetNeedsValidityCheck(); select_->SetNeedsValidityCheck();
} }
...@@ -988,7 +990,44 @@ void ListBoxSelectType::UpdateSelectedState(HTMLOptionElement* clicked_option, ...@@ -988,7 +990,44 @@ void ListBoxSelectType::UpdateSelectedState(HTMLOptionElement* clicked_option,
select_->SetActiveSelectionAnchor(clicked_option); select_->SetActiveSelectionAnchor(clicked_option);
select_->SetActiveSelectionEnd(clicked_option); select_->SetActiveSelectionEnd(clicked_option);
select_->UpdateListBoxSelection(mode != SelectionMode::kNotChangeOthers); UpdateListBoxSelection(mode != SelectionMode::kNotChangeOthers);
}
void ListBoxSelectType::UpdateListBoxSelection(bool deselect_other_options,
bool scroll) {
DCHECK(select_->GetLayoutObject());
HTMLOptionElement* const anchor_option = select_->active_selection_anchor_;
HTMLOptionElement* const end_option = select_->active_selection_end_;
const int anchor_index = anchor_option ? anchor_option->index() : -1;
const int end_index = end_option ? end_option->index() : -1;
const int start = std::min(anchor_index, end_index);
const int end = std::max(anchor_index, end_index);
int i = 0;
for (auto* const option : select_->GetOptionList()) {
if (option->IsDisabledFormControl() || !option->GetLayoutObject()) {
++i;
continue;
}
if (i >= start && i <= end) {
option->SetSelectedState(select_->active_selection_state_);
option->SetDirty(true);
} else if (deselect_other_options ||
i >= static_cast<int>(
select_->cached_state_for_active_selection_.size())) {
option->SetSelectedState(false);
option->SetDirty(true);
} else {
option->SetSelectedState(select_->cached_state_for_active_selection_[i]);
}
++i;
}
UpdateMultiSelectFocus();
select_->SetNeedsValidityCheck();
if (scroll)
select_->ScrollToSelection();
select_->NotifyFormStateChanged();
} }
// ============================================================================ // ============================================================================
...@@ -1041,8 +1080,6 @@ const ComputedStyle* SelectType::OptionStyle() const { ...@@ -1041,8 +1080,6 @@ const ComputedStyle* SelectType::OptionStyle() const {
void SelectType::MaximumOptionWidthMightBeChanged() const {} void SelectType::MaximumOptionWidthMightBeChanged() const {}
void SelectType::UpdateMultiSelectFocus() {}
void SelectType::SelectAll() { void SelectType::SelectAll() {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -44,9 +44,6 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -44,9 +44,6 @@ class SelectType : public GarbageCollected<SelectType> {
virtual const ComputedStyle* OptionStyle() const; virtual const ComputedStyle* OptionStyle() const;
virtual void MaximumOptionWidthMightBeChanged() const; virtual void MaximumOptionWidthMightBeChanged() const;
// Update :-internal-multi-select-focus state of selected OPTIONs.
virtual void UpdateMultiSelectFocus();
virtual void SelectAll(); virtual void SelectAll();
virtual void ShowPopup(); virtual void ShowPopup();
......
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