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) {
return;
suggested_option_ = option;
select_type_->UpdateTextStyleAndContent();
if (GetLayoutObject())
ScrollToOption(option);
if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
select_type_->DidSetSuggestedOption(option);
}
void HTMLSelectElement::ScrollToOption(HTMLOptionElement* option) {
......@@ -1530,12 +1526,7 @@ LayoutUnit HTMLSelectElement::ClientPaddingRight() const {
}
void HTMLSelectElement::PopupDidHide() {
SetPopupIsVisible(false);
UnobserveTreeMutation();
if (AXObjectCache* cache = GetDocument().ExistingAXObjectCache()) {
if (GetLayoutObject() && UsesMenuList())
cache->DidHideMenuListPopup(GetLayoutObject());
}
select_type_->PopupDidHide();
}
void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) {
......@@ -1597,11 +1588,7 @@ void HTMLSelectElement::HidePopup() {
void HTMLSelectElement::DidRecalcStyle(const StyleRecalcChange change) {
HTMLFormControlElementWithState::DidRecalcStyle(change);
if (change.ReattachLayoutTree())
return;
select_type_->UpdateTextStyle();
if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kByStyleChange);
select_type_->DidRecalcStyle(change);
}
void HTMLSelectElement::AttachLayoutTree(AttachContext& context) {
......@@ -1623,11 +1610,7 @@ void HTMLSelectElement::AttachLayoutTree(AttachContext& context) {
void HTMLSelectElement::DetachLayoutTree(bool performing_reattach) {
HTMLFormControlElementWithState::DetachLayoutTree(performing_reattach);
if (popup_)
popup_->DisconnectClient();
SetPopupIsVisible(false);
popup_ = nullptr;
UnobserveTreeMutation();
select_type_->DidDetachLayoutTree();
}
void HTMLSelectElement::ResetTypeAheadSessionForTesting() {
......@@ -1716,6 +1699,7 @@ void HTMLSelectElement::CloneNonAttributePropertiesFrom(
}
void HTMLSelectElement::ChangeRendering() {
select_type_->DidDetachLayoutTree();
UpdateUsesMenuList();
select_type_->WillBeDestroyed();
select_type_ = SelectType::Create(*this);
......
......@@ -70,6 +70,9 @@ class MenuListSelectType final : public SelectType {
HTMLSelectElement::SelectOptionFlags flags,
bool should_update_popup) override;
void DidBlur() override;
void DidDetachLayoutTree() override;
void DidRecalcStyle(const StyleRecalcChange change) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void UpdateTextStyle() override { UpdateTextStyleInternal(); }
void UpdateTextStyleAndContent() override;
......@@ -79,6 +82,7 @@ class MenuListSelectType final : public SelectType {
void ShowPopup() override;
void HidePopup() override;
void PopupDidHide() override;
private:
bool ShouldOpenPopupForKeyDownEvent(const KeyboardEvent& event);
......@@ -290,6 +294,15 @@ void MenuListSelectType::HidePopup() {
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(
HTMLOptionElement* element,
HTMLSelectElement::SelectOptionFlags flags,
......@@ -340,6 +353,28 @@ void MenuListSelectType::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() {
HTMLOptionElement* option = select_->OptionToBeShown();
String text = g_empty_string;
......@@ -431,6 +466,7 @@ class ListBoxSelectType final : public SelectType {
public:
explicit ListBoxSelectType(HTMLSelectElement& select) : SelectType(select) {}
bool DefaultEventHandler(const Event& event) override;
void DidSetSuggestedOption(HTMLOptionElement* option) override;
void UpdateMultiSelectFocus() override;
void SelectAll() override;
......@@ -690,6 +726,11 @@ bool ListBoxSelectType::DefaultEventHandler(const Event& event) {
return false;
}
void ListBoxSelectType::DidSetSuggestedOption(HTMLOptionElement* option) {
if (select_->GetLayoutObject())
select_->ScrollToOption(option);
}
void ListBoxSelectType::UpdateMultiSelectFocus() {
if (!select_->is_multiple_)
return;
......@@ -772,6 +813,10 @@ void SelectType::DidBlur() {
select_->last_on_change_selection_.clear();
}
void SelectType::DidDetachLayoutTree() {}
void SelectType::DidRecalcStyle(const StyleRecalcChange) {}
void SelectType::UpdateTextStyle() {}
void SelectType::UpdateTextStyleAndContent() {}
......@@ -795,6 +840,10 @@ void SelectType::HidePopup() {
NOTREACHED();
}
void SelectType::PopupDidHide() {
NOTREACHED();
}
// Returns the 1st valid OPTION |skip| items from |list_index| in direction
// |direction| if there is one.
// Otherwise, it returns the valid OPTION closest to that boundary which is past
......
......@@ -29,6 +29,9 @@ class SelectType : public GarbageCollected<SelectType> {
bool should_update_popup);
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.
virtual void UpdateTextStyle();
......@@ -46,6 +49,7 @@ class SelectType : public GarbageCollected<SelectType> {
virtual void ShowPopup();
virtual void HidePopup();
virtual void PopupDidHide();
enum SkipDirection { kSkipBackwards = -1, kSkipForwards = 1 };
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