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