Commit 8a9364a9 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HTMLSelectElement::last_on_change_selection_ to ListBoxSelectType

It is referred only by ListBoxSelectType.
SelectType::DidBlur(), which modifies last_on_change_selection_, is
also moved to ListBoxSelectType.

This CL has no behavior changes.

Bug: 1052232
Change-Id: I6ccb206f3432f7c7dbc0685133ca7ae3a1abeca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105832
Commit-Queue: Kent Tamura <tkent@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751580}
parent 7bbd52bb
......@@ -803,7 +803,7 @@ void HTMLSelectElement::OptionInserted(HTMLOptionElement& option,
ResetToDefaultSelection();
}
SetNeedsValidityCheck();
last_on_change_selection_.clear();
select_type_->ClearLastOnChangeSelection();
if (!GetDocument().IsActive())
return;
......@@ -834,7 +834,7 @@ void HTMLSelectElement::OptionRemoved(HTMLOptionElement& option) {
if (option.Selected())
SetAutofillState(WebAutofillState::kNotFilled);
SetNeedsValidityCheck();
last_on_change_selection_.clear();
select_type_->ClearLastOnChangeSelection();
if (!GetDocument().IsActive())
return;
......@@ -850,12 +850,12 @@ void HTMLSelectElement::OptGroupInsertedOrRemoved(
HTMLOptGroupElement& optgroup) {
SetRecalcListItems();
SetNeedsValidityCheck();
last_on_change_selection_.clear();
select_type_->ClearLastOnChangeSelection();
}
void HTMLSelectElement::HrInsertedOrRemoved(HTMLHRElement& hr) {
SetRecalcListItems();
last_on_change_selection_.clear();
select_type_->ClearLastOnChangeSelection();
}
// TODO(tkent): This function is not efficient. It contains multiple O(N)
......
......@@ -284,7 +284,6 @@ class CORE_EXPORT HTMLSelectElement final
// list_items_ contains HTMLOptionElement, HTMLOptGroupElement, and
// HTMLHRElement objects.
mutable ListItems list_items_;
Vector<bool> last_on_change_selection_;
TypeAhead type_ahead_;
unsigned size_;
Member<HTMLOptionElement> last_on_change_option_;
......
......@@ -395,7 +395,6 @@ void MenuListSelectType::DidBlur() {
DispatchEventsIfSelectedOptionChanged();
if (PopupIsVisible())
HidePopup();
SelectType::DidBlur();
}
void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) {
......@@ -613,12 +612,14 @@ class ListBoxSelectType final : public SelectType {
public:
explicit ListBoxSelectType(HTMLSelectElement& select) : SelectType(select) {}
bool DefaultEventHandler(const Event& event) override;
void DidBlur() override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void SaveLastSelection() override;
void SelectAll() override;
void SaveListboxActiveSelection() override;
void HandleMouseRelease() override;
void ListBoxOnChange() override;
void ClearLastOnChangeSelection() override;
private:
HTMLOptionElement* NextSelectableOptionPageAway(HTMLOptionElement*,
......@@ -636,6 +637,7 @@ class ListBoxSelectType final : public SelectType {
void UpdateListBoxSelection(bool deselect_other_options, bool scroll = true);
Vector<bool> cached_state_for_active_selection_;
Vector<bool> last_on_change_selection_;
bool is_in_non_contiguous_selection_ = false;
bool active_selection_state_ = false;
};
......@@ -711,7 +713,7 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
}
}
// Mousedown didn't happen in this element.
if (select_->last_on_change_selection_.IsEmpty())
if (last_on_change_selection_.IsEmpty())
return false;
if (HTMLOptionElement* option = EventTargetOption(*mouse_event)) {
......@@ -894,17 +896,21 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return false;
}
void ListBoxSelectType::DidBlur() {
ClearLastOnChangeSelection();
}
void ListBoxSelectType::DidSetSuggestedOption(HTMLOptionElement* option) {
if (select_->GetLayoutObject())
select_->ScrollToOption(option);
}
void ListBoxSelectType::SaveLastSelection() {
select_->last_on_change_selection_.clear();
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());
last_on_change_selection_.push_back(option_element &&
option_element->Selected());
}
}
......@@ -1072,7 +1078,7 @@ void ListBoxSelectType::SaveListboxActiveSelection() {
void ListBoxSelectType::HandleMouseRelease() {
// We didn't start this click/drag on any options.
if (select_->last_on_change_selection_.IsEmpty())
if (last_on_change_selection_.IsEmpty())
return;
ListBoxOnChange();
}
......@@ -1083,8 +1089,8 @@ void ListBoxSelectType::ListBoxOnChange() {
// If the cached selection list is empty, or the size has changed, then fire
// 'change' event, and return early.
// FIXME: Why? This looks unreasonable.
if (select_->last_on_change_selection_.IsEmpty() ||
select_->last_on_change_selection_.size() != items.size()) {
if (last_on_change_selection_.IsEmpty() ||
last_on_change_selection_.size() != items.size()) {
select_->DispatchChangeEvent();
return;
}
......@@ -1095,9 +1101,9 @@ void ListBoxSelectType::ListBoxOnChange() {
HTMLElement* element = items[i];
auto* option_element = DynamicTo<HTMLOptionElement>(element);
bool selected = option_element && option_element->Selected();
if (selected != select_->last_on_change_selection_[i])
if (selected != last_on_change_selection_[i])
fire_on_change = true;
select_->last_on_change_selection_[i] = selected;
last_on_change_selection_[i] = selected;
}
if (fire_on_change) {
......@@ -1106,6 +1112,10 @@ void ListBoxSelectType::ListBoxOnChange() {
}
}
void ListBoxSelectType::ClearLastOnChangeSelection() {
last_on_change_selection_.clear();
}
// ============================================================================
SelectType::SelectType(HTMLSelectElement& select) : select_(select) {}
......@@ -1132,10 +1142,6 @@ void SelectType::DidSelectOption(HTMLOptionElement*,
select_->SetNeedsValidityCheck();
}
void SelectType::DidBlur() {
select_->last_on_change_selection_.clear();
}
void SelectType::DidDetachLayoutTree() {}
void SelectType::DidRecalcStyle(const StyleRecalcChange) {}
......@@ -1166,6 +1172,8 @@ void SelectType::HandleMouseRelease() {}
void SelectType::ListBoxOnChange() {}
void SelectType::ClearLastOnChangeSelection() {}
void SelectType::ShowPopup() {
NOTREACHED();
}
......
......@@ -28,7 +28,7 @@ class SelectType : public GarbageCollected<SelectType> {
HTMLSelectElement::SelectOptionFlags flags,
bool should_update_popup);
virtual void DidBlur();
virtual void DidBlur() = 0;
virtual void DidDetachLayoutTree();
virtual void DidRecalcStyle(const StyleRecalcChange change);
virtual void DidSetSuggestedOption(HTMLOptionElement* option) = 0;
......@@ -49,6 +49,9 @@ class SelectType : public GarbageCollected<SelectType> {
virtual void SaveListboxActiveSelection();
virtual void HandleMouseRelease();
virtual void ListBoxOnChange();
// Clear OPTION selection information saved by SaveLastSelection().
// This is for ListBoxes.
virtual void ClearLastOnChangeSelection();
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