Commit 1d9f0e28 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HTMLSelectElement::SaveLastSelection to SelectType

This CL has no behavior changes.

Bug: 1052232
Change-Id: I94e3e0fdab11cdb25ec5927c199d9bfcfe250d5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108249
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751255}
parent 717f6a62
......@@ -509,20 +509,6 @@ void HTMLSelectElement::SelectAll() {
select_type_->SelectAll();
}
void HTMLSelectElement::SaveLastSelection() {
if (UsesMenuList()) {
last_on_change_option_ = SelectedOption();
return;
}
last_on_change_selection_.clear();
for (auto& element : GetListItems()) {
auto* option_element = DynamicTo<HTMLOptionElement>(element.Get());
last_on_change_selection_.push_back(option_element &&
option_element->Selected());
}
}
void HTMLSelectElement::SetActiveSelectionAnchor(HTMLOptionElement* option) {
active_selection_anchor_ = option;
select_type_->SaveListboxActiveSelection();
......@@ -927,7 +913,7 @@ void HTMLSelectElement::DispatchFocusEvent(
// Save the selection so it can be compared to the new selection when
// dispatching change events during blur event dispatch.
if (UsesMenuList())
SaveLastSelection();
select_type_->SaveLastSelection();
HTMLFormControlElementWithState::DispatchFocusEvent(old_focused_element, type,
source_capabilities);
}
......
......@@ -231,7 +231,6 @@ class CORE_EXPORT HTMLSelectElement final
enum ResetReason { kResetReasonSelectedOptionRemoved, kResetReasonOthers };
void ResetToDefaultSelection(ResetReason = kResetReasonOthers);
void TypeAheadFind(const KeyboardEvent&);
void SaveLastSelection();
// Returns the first selected OPTION, or nullptr.
HTMLOptionElement* SelectedOption() const;
......
......@@ -80,6 +80,7 @@ class MenuListSelectType final : public SelectType {
void DidDetachLayoutTree() override;
void DidRecalcStyle(const StyleRecalcChange change) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void SaveLastSelection() override;
void UpdateTextStyle() override { UpdateTextStyleInternal(); }
void UpdateTextStyleAndContent() override;
......@@ -234,7 +235,7 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) {
// when we call onChange during selectOption, which gets called
// from selectOptionByPopup, which gets called after the user
// makes a selection from the menu.
select_->SaveLastSelection();
SaveLastSelection();
// TODO(lanwei): Will check if we need to add
// InputDeviceCapabilities here when select menu list gets
// focus, see https://crbug.com/476530.
......@@ -284,7 +285,7 @@ bool MenuListSelectType::HandlePopupOpenKeyboardEvent() {
// dispatching change events during SelectOption, which gets called from
// SelectOptionByPopup, which gets called after the user makes a selection
// from the menu.
select_->SaveLastSelection();
SaveLastSelection();
ShowPopup();
return true;
}
......@@ -403,6 +404,10 @@ void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) {
popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
}
void MenuListSelectType::SaveLastSelection() {
select_->last_on_change_option_ = select_->SelectedOption();
}
void MenuListSelectType::DidDetachLayoutTree() {
if (popup_)
popup_->DisconnectClient();
......@@ -609,6 +614,7 @@ class ListBoxSelectType final : public SelectType {
explicit ListBoxSelectType(HTMLSelectElement& select) : SelectType(select) {}
bool DefaultEventHandler(const Event& event) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void SaveLastSelection() override;
void SelectAll() override;
void SaveListboxActiveSelection() override;
void HandleMouseRelease() override;
......@@ -822,7 +828,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
// Save the selection so it can be compared to the new selection
// when dispatching change events immediately after making the new
// selection.
select_->SaveLastSelection();
SaveLastSelection();
select_->SetActiveSelectionEnd(end_option);
......@@ -893,6 +899,15 @@ void ListBoxSelectType::DidSetSuggestedOption(HTMLOptionElement* option) {
select_->ScrollToOption(option);
}
void ListBoxSelectType::SaveLastSelection() {
select_->last_on_change_selection_.clear();
for (auto& element : select_->GetListItems()) {
auto* option_element = DynamicTo<HTMLOptionElement>(element.Get());
select_->last_on_change_selection_.push_back(option_element &&
option_element->Selected());
}
}
void ListBoxSelectType::UpdateMultiSelectFocus() {
if (!select_->is_multiple_)
return;
......@@ -913,7 +928,7 @@ void ListBoxSelectType::SelectAll() {
// Save the selection so it can be compared to the new selectAll selection
// when dispatching change events.
select_->SaveLastSelection();
SaveLastSelection();
active_selection_state_ = true;
select_->SetActiveSelectionAnchor(NextSelectableOption(nullptr));
......@@ -956,7 +971,7 @@ void ListBoxSelectType::UpdateSelectedState(HTMLOptionElement* clicked_option,
DCHECK(clicked_option);
// Save the selection so it can be compared to the new selection when
// dispatching change events during mouseup, or after autoscroll finishes.
select_->SaveLastSelection();
SaveLastSelection();
active_selection_state_ = true;
......
......@@ -32,6 +32,7 @@ class SelectType : public GarbageCollected<SelectType> {
virtual void DidDetachLayoutTree();
virtual void DidRecalcStyle(const StyleRecalcChange change);
virtual void DidSetSuggestedOption(HTMLOptionElement* option) = 0;
virtual void SaveLastSelection() = 0;
// Update style of text in the CSS box on style or selected OPTION change.
virtual void UpdateTextStyle();
......
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