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

Move HTMLSelectElement::SaveListboxActiveSelection() to SelectType

Also moves cached_state_for_active_selection_ to ListBoxSelectType.
This CL has no behavior changes.

Bug: 1052232
Change-Id: Ie32cdf5eb9cba2daf7031b20dc71a9ca907d92e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098191
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749564}
parent 27868204
......@@ -339,8 +339,7 @@ void HTMLSelectElement::ParseAttribute(
UpdateUserAgentShadowTree(*UserAgentShadowRoot());
ResetToDefaultSelection();
select_type_->UpdateTextStyleAndContent();
if (!UsesMenuList())
SaveListboxActiveSelection();
select_type_->SaveListboxActiveSelection();
}
} else if (params.name == html_names::kMultipleAttr) {
ParseMultipleAttribute(params.new_value);
......@@ -527,27 +526,7 @@ void HTMLSelectElement::SaveLastSelection() {
void HTMLSelectElement::SetActiveSelectionAnchor(HTMLOptionElement* option) {
active_selection_anchor_ = option;
if (!UsesMenuList())
SaveListboxActiveSelection();
}
void HTMLSelectElement::SaveListboxActiveSelection() {
// Cache the selection state so we can restore the old selection as the new
// selection pivots around this anchor index.
// Example:
// 1. Press the mouse button on the second OPTION
// active_selection_anchor_ points the second OPTION.
// 2. Drag the mouse pointer onto the fifth OPTION
// active_selection_end_ points the fifth OPTION, OPTIONs at 1-4 indices
// are selected.
// 3. Drag the mouse pointer onto the fourth OPTION
// active_selection_end_ points the fourth OPTION, OPTIONs at 1-3 indices
// are selected.
// UpdateListBoxSelection needs to clear selection of the fifth OPTION.
cached_state_for_active_selection_.resize(0);
for (auto* const option : GetOptionList()) {
cached_state_for_active_selection_.push_back(option->Selected());
}
select_type_->SaveListboxActiveSelection();
}
void HTMLSelectElement::SetActiveSelectionEnd(HTMLOptionElement* option) {
......
......@@ -232,7 +232,6 @@ class CORE_EXPORT HTMLSelectElement final
void ResetToDefaultSelection(ResetReason = kResetReasonOthers);
void TypeAheadFind(const KeyboardEvent&);
void SaveLastSelection();
void SaveListboxActiveSelection();
// Returns the first selected OPTION, or nullptr.
HTMLOptionElement* SelectedOption() const;
......@@ -287,7 +286,6 @@ class CORE_EXPORT HTMLSelectElement final
// HTMLHRElement objects.
mutable ListItems list_items_;
Vector<bool> last_on_change_selection_;
Vector<bool> cached_state_for_active_selection_;
TypeAhead type_ahead_;
unsigned size_;
Member<HTMLOptionElement> last_on_change_option_;
......
......@@ -609,6 +609,7 @@ class ListBoxSelectType final : public SelectType {
bool DefaultEventHandler(const Event& event) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void SelectAll() override;
void SaveListboxActiveSelection() override;
private:
HTMLOptionElement* NextSelectableOptionPageAway(HTMLOptionElement*,
......@@ -625,6 +626,7 @@ class ListBoxSelectType final : public SelectType {
SelectionMode mode);
void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true);
Vector<bool> cached_state_for_active_selection_;
bool is_in_non_contiguous_selection_ = false;
};
......@@ -1014,11 +1016,11 @@ void ListBoxSelectType::UpdateListBoxSelection(bool deselect_other_options,
option->SetDirty(true);
} else if (deselect_other_options ||
i >= static_cast<int>(
select_->cached_state_for_active_selection_.size())) {
cached_state_for_active_selection_.size())) {
option->SetSelectedState(false);
option->SetDirty(true);
} else {
option->SetSelectedState(select_->cached_state_for_active_selection_[i]);
option->SetSelectedState(cached_state_for_active_selection_[i]);
}
++i;
}
......@@ -1030,6 +1032,25 @@ void ListBoxSelectType::UpdateListBoxSelection(bool deselect_other_options,
select_->NotifyFormStateChanged();
}
void ListBoxSelectType::SaveListboxActiveSelection() {
// Cache the selection state so we can restore the old selection as the new
// selection pivots around this anchor index.
// Example:
// 1. Press the mouse button on the second OPTION
// active_selection_anchor_ points the second OPTION.
// 2. Drag the mouse pointer onto the fifth OPTION
// active_selection_end_ points the fifth OPTION, OPTIONs at 1-4 indices
// are selected.
// 3. Drag the mouse pointer onto the fourth OPTION
// active_selection_end_ points the fourth OPTION, OPTIONs at 1-3 indices
// are selected.
// UpdateListBoxSelection needs to clear selection of the fifth OPTION.
cached_state_for_active_selection_.resize(0);
for (auto* const option : select_->GetOptionList()) {
cached_state_for_active_selection_.push_back(option->Selected());
}
}
// ============================================================================
SelectType::SelectType(HTMLSelectElement& select) : select_(select) {}
......@@ -1084,6 +1105,8 @@ void SelectType::SelectAll() {
NOTREACHED();
}
void SelectType::SaveListboxActiveSelection() {}
void SelectType::ShowPopup() {
NOTREACHED();
}
......
......@@ -45,6 +45,7 @@ class SelectType : public GarbageCollected<SelectType> {
virtual void MaximumOptionWidthMightBeChanged() const;
virtual void SelectAll();
virtual void SaveListboxActiveSelection();
virtual void ShowPopup();
virtual void HidePopup();
......
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