Commit 4c2f2aa2 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Add 4 new virtual methods to SelectType

- DidDetachLayoutTree()
- DidRecalcStyle()
- DidSetSuggestedOption()
- PopupDidHide()

Move parts of the contents of DetchLayoutTree(), DidRecalcStyle(),
SetSuggestedOption(), and PopupDidHide() of HTMLSelectElement to them.

We need to call SelectType::DidDetachLayoutTree() in |HTMLSelectElement
::ChangeRendering()| before replacing select_type_. When a SELECT
changed its type from MenuList to ListBox, DetachLayoutTree() in this
function triggered the popup-disconnecting code after switching to
ListBox. After this CL, select_type_->DidDetachLayoutTree() in
DetachLayoutTree() doesn't trigger the popup-disconnecting code because
select_type_ is a ListBoxSelectType.

This CL has no behavior changes.

Bug: 1052232
Change-Id: Iaff5691a670bd7570c7c47334f548cc84c4dc0bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084332Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746699}
parent be0abf51
...@@ -804,11 +804,7 @@ void HTMLSelectElement::SetSuggestedOption(HTMLOptionElement* option) { ...@@ -804,11 +804,7 @@ void HTMLSelectElement::SetSuggestedOption(HTMLOptionElement* option) {
return; return;
suggested_option_ = option; suggested_option_ = option;
select_type_->UpdateTextStyleAndContent(); select_type_->DidSetSuggestedOption(option);
if (GetLayoutObject())
ScrollToOption(option);
if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
} }
void HTMLSelectElement::ScrollToOption(HTMLOptionElement* option) { void HTMLSelectElement::ScrollToOption(HTMLOptionElement* option) {
...@@ -1530,12 +1526,7 @@ LayoutUnit HTMLSelectElement::ClientPaddingRight() const { ...@@ -1530,12 +1526,7 @@ LayoutUnit HTMLSelectElement::ClientPaddingRight() const {
} }
void HTMLSelectElement::PopupDidHide() { void HTMLSelectElement::PopupDidHide() {
SetPopupIsVisible(false); select_type_->PopupDidHide();
UnobserveTreeMutation();
if (AXObjectCache* cache = GetDocument().ExistingAXObjectCache()) {
if (GetLayoutObject() && UsesMenuList())
cache->DidHideMenuListPopup(GetLayoutObject());
}
} }
void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) { void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) {
...@@ -1597,11 +1588,7 @@ void HTMLSelectElement::HidePopup() { ...@@ -1597,11 +1588,7 @@ void HTMLSelectElement::HidePopup() {
void HTMLSelectElement::DidRecalcStyle(const StyleRecalcChange change) { void HTMLSelectElement::DidRecalcStyle(const StyleRecalcChange change) {
HTMLFormControlElementWithState::DidRecalcStyle(change); HTMLFormControlElementWithState::DidRecalcStyle(change);
if (change.ReattachLayoutTree()) select_type_->DidRecalcStyle(change);
return;
select_type_->UpdateTextStyle();
if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kByStyleChange);
} }
void HTMLSelectElement::AttachLayoutTree(AttachContext& context) { void HTMLSelectElement::AttachLayoutTree(AttachContext& context) {
...@@ -1623,11 +1610,7 @@ void HTMLSelectElement::AttachLayoutTree(AttachContext& context) { ...@@ -1623,11 +1610,7 @@ void HTMLSelectElement::AttachLayoutTree(AttachContext& context) {
void HTMLSelectElement::DetachLayoutTree(bool performing_reattach) { void HTMLSelectElement::DetachLayoutTree(bool performing_reattach) {
HTMLFormControlElementWithState::DetachLayoutTree(performing_reattach); HTMLFormControlElementWithState::DetachLayoutTree(performing_reattach);
if (popup_) select_type_->DidDetachLayoutTree();
popup_->DisconnectClient();
SetPopupIsVisible(false);
popup_ = nullptr;
UnobserveTreeMutation();
} }
void HTMLSelectElement::ResetTypeAheadSessionForTesting() { void HTMLSelectElement::ResetTypeAheadSessionForTesting() {
...@@ -1716,6 +1699,7 @@ void HTMLSelectElement::CloneNonAttributePropertiesFrom( ...@@ -1716,6 +1699,7 @@ void HTMLSelectElement::CloneNonAttributePropertiesFrom(
} }
void HTMLSelectElement::ChangeRendering() { void HTMLSelectElement::ChangeRendering() {
select_type_->DidDetachLayoutTree();
UpdateUsesMenuList(); UpdateUsesMenuList();
select_type_->WillBeDestroyed(); select_type_->WillBeDestroyed();
select_type_ = SelectType::Create(*this); select_type_ = SelectType::Create(*this);
......
...@@ -70,6 +70,9 @@ class MenuListSelectType final : public SelectType { ...@@ -70,6 +70,9 @@ class MenuListSelectType final : public SelectType {
HTMLSelectElement::SelectOptionFlags flags, HTMLSelectElement::SelectOptionFlags flags,
bool should_update_popup) override; bool should_update_popup) override;
void DidBlur() override; void DidBlur() override;
void DidDetachLayoutTree() override;
void DidRecalcStyle(const StyleRecalcChange change) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void UpdateTextStyle() override { UpdateTextStyleInternal(); } void UpdateTextStyle() override { UpdateTextStyleInternal(); }
void UpdateTextStyleAndContent() override; void UpdateTextStyleAndContent() override;
...@@ -79,6 +82,7 @@ class MenuListSelectType final : public SelectType { ...@@ -79,6 +82,7 @@ class MenuListSelectType final : public SelectType {
void ShowPopup() override; void ShowPopup() override;
void HidePopup() override; void HidePopup() override;
void PopupDidHide() override;
private: private:
bool ShouldOpenPopupForKeyDownEvent(const KeyboardEvent& event); bool ShouldOpenPopupForKeyDownEvent(const KeyboardEvent& event);
...@@ -290,6 +294,15 @@ void MenuListSelectType::HidePopup() { ...@@ -290,6 +294,15 @@ void MenuListSelectType::HidePopup() {
select_->popup_->Hide(); select_->popup_->Hide();
} }
void MenuListSelectType::PopupDidHide() {
select_->SetPopupIsVisible(false);
select_->UnobserveTreeMutation();
if (AXObjectCache* cache = select_->GetDocument().ExistingAXObjectCache()) {
if (auto* layout_object = select_->GetLayoutObject())
cache->DidHideMenuListPopup(layout_object);
}
}
void MenuListSelectType::DidSelectOption( void MenuListSelectType::DidSelectOption(
HTMLOptionElement* element, HTMLOptionElement* element,
HTMLSelectElement::SelectOptionFlags flags, HTMLSelectElement::SelectOptionFlags flags,
...@@ -340,6 +353,28 @@ void MenuListSelectType::DidBlur() { ...@@ -340,6 +353,28 @@ void MenuListSelectType::DidBlur() {
SelectType::DidBlur(); SelectType::DidBlur();
} }
void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) {
UpdateTextStyleAndContent();
if (select_->PopupIsVisible())
select_->popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
}
void MenuListSelectType::DidDetachLayoutTree() {
if (select_->popup_)
select_->popup_->DisconnectClient();
select_->SetPopupIsVisible(false);
select_->popup_ = nullptr;
select_->UnobserveTreeMutation();
}
void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) {
if (change.ReattachLayoutTree())
return;
UpdateTextStyle();
if (select_->PopupIsVisible())
select_->popup_->UpdateFromElement(PopupMenu::kByStyleChange);
}
String MenuListSelectType::UpdateTextStyleInternal() { String MenuListSelectType::UpdateTextStyleInternal() {
HTMLOptionElement* option = select_->OptionToBeShown(); HTMLOptionElement* option = select_->OptionToBeShown();
String text = g_empty_string; String text = g_empty_string;
...@@ -431,6 +466,7 @@ class ListBoxSelectType final : public SelectType { ...@@ -431,6 +466,7 @@ 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 DidSetSuggestedOption(HTMLOptionElement* option) override;
void UpdateMultiSelectFocus() override; void UpdateMultiSelectFocus() override;
void SelectAll() override; void SelectAll() override;
...@@ -690,6 +726,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) { ...@@ -690,6 +726,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return false; return false;
} }
void ListBoxSelectType::DidSetSuggestedOption(HTMLOptionElement* option) {
if (select_->GetLayoutObject())
select_->ScrollToOption(option);
}
void ListBoxSelectType::UpdateMultiSelectFocus() { void ListBoxSelectType::UpdateMultiSelectFocus() {
if (!select_->is_multiple_) if (!select_->is_multiple_)
return; return;
...@@ -772,6 +813,10 @@ void SelectType::DidBlur() { ...@@ -772,6 +813,10 @@ void SelectType::DidBlur() {
select_->last_on_change_selection_.clear(); select_->last_on_change_selection_.clear();
} }
void SelectType::DidDetachLayoutTree() {}
void SelectType::DidRecalcStyle(const StyleRecalcChange) {}
void SelectType::UpdateTextStyle() {} void SelectType::UpdateTextStyle() {}
void SelectType::UpdateTextStyleAndContent() {} void SelectType::UpdateTextStyleAndContent() {}
...@@ -795,6 +840,10 @@ void SelectType::HidePopup() { ...@@ -795,6 +840,10 @@ void SelectType::HidePopup() {
NOTREACHED(); NOTREACHED();
} }
void SelectType::PopupDidHide() {
NOTREACHED();
}
// Returns the 1st valid OPTION |skip| items from |list_index| in direction // Returns the 1st valid OPTION |skip| items from |list_index| in direction
// |direction| if there is one. // |direction| if there is one.
// Otherwise, it returns the valid OPTION closest to that boundary which is past // Otherwise, it returns the valid OPTION closest to that boundary which is past
......
...@@ -29,6 +29,9 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -29,6 +29,9 @@ class SelectType : public GarbageCollected<SelectType> {
bool should_update_popup); bool should_update_popup);
virtual void DidBlur(); virtual void DidBlur();
virtual void DidDetachLayoutTree();
virtual void DidRecalcStyle(const StyleRecalcChange change);
virtual void DidSetSuggestedOption(HTMLOptionElement* option) = 0;
// Update style of text in the CSS box on style or selected OPTION change. // Update style of text in the CSS box on style or selected OPTION change.
virtual void UpdateTextStyle(); virtual void UpdateTextStyle();
...@@ -46,6 +49,7 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -46,6 +49,7 @@ class SelectType : public GarbageCollected<SelectType> {
virtual void ShowPopup(); virtual void ShowPopup();
virtual void HidePopup(); virtual void HidePopup();
virtual void PopupDidHide();
enum SkipDirection { kSkipBackwards = -1, kSkipForwards = 1 }; enum SkipDirection { kSkipBackwards = -1, kSkipForwards = 1 };
CORE_EXPORT HTMLOptionElement* NextSelectableOption(HTMLOptionElement*) const; CORE_EXPORT HTMLOptionElement* NextSelectableOption(HTMLOptionElement*) const;
......
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