Commit 7cad75f5 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move popup_is_visible_ from HTMLSelectElement to MenuListSelectType

Bug: 1052232
Change-Id: Ib5d57aaabaf78d97007d31b8b9a3e3c123f0dea5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089437
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@{#747586}
parent 77d5626f
...@@ -93,8 +93,7 @@ HTMLSelectElement::HTMLSelectElement(Document& document) ...@@ -93,8 +93,7 @@ HTMLSelectElement::HTMLSelectElement(Document& document)
active_selection_state_(false), active_selection_state_(false),
should_recalc_list_items_(false), should_recalc_list_items_(false),
is_autofilled_by_preview_(false), is_autofilled_by_preview_(false),
index_to_select_on_cancel_(-1), index_to_select_on_cancel_(-1) {
popup_is_visible_(false) {
// Make sure SelectType is created after initializing |uses_menu_list_|. // Make sure SelectType is created after initializing |uses_menu_list_|.
select_type_ = SelectType::Create(*this); select_type_ = SelectType::Create(*this);
SetHasCustomStyleCallbacks(); SetHasCustomStyleCallbacks();
...@@ -1180,12 +1179,8 @@ void HTMLSelectElement::ResetImpl() { ...@@ -1180,12 +1179,8 @@ void HTMLSelectElement::ResetImpl() {
SetNeedsValidityCheck(); SetNeedsValidityCheck();
} }
void HTMLSelectElement::SetPopupIsVisible(bool popup_is_visible) { bool HTMLSelectElement::PopupIsVisible() const {
popup_is_visible_ = popup_is_visible; return select_type_->PopupIsVisible();
if (::features::IsFormControlsRefreshEnabled() && GetLayoutObject()) {
// Invalidate paint to ensure that the focus ring is updated.
GetLayoutObject()->SetShouldDoFullPaintInvalidation();
}
} }
void HTMLSelectElement::UpdateSelectedState(HTMLOptionElement* clicked_option, void HTMLSelectElement::UpdateSelectedState(HTMLOptionElement* clicked_option,
......
...@@ -164,7 +164,7 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -164,7 +164,7 @@ class CORE_EXPORT HTMLSelectElement final
// Provisional selection is a selection made using arrow keys or type ahead. // Provisional selection is a selection made using arrow keys or type ahead.
void ProvisionalSelectionChanged(unsigned); void ProvisionalSelectionChanged(unsigned);
void PopupDidHide(); void PopupDidHide();
bool PopupIsVisible() const { return popup_is_visible_; } bool PopupIsVisible() const;
HTMLOptionElement* OptionToBeShown() const; HTMLOptionElement* OptionToBeShown() const;
// Style of the selected OPTION. This is nullable, and only for // Style of the selected OPTION. This is nullable, and only for
// the menulist mode. // the menulist mode.
...@@ -255,7 +255,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -255,7 +255,6 @@ class CORE_EXPORT HTMLSelectElement final
void ParseMultipleAttribute(const AtomicString&); void ParseMultipleAttribute(const AtomicString&);
HTMLOptionElement* LastSelectedOption() const; HTMLOptionElement* LastSelectedOption() const;
void UpdateSelectedState(HTMLOptionElement*, bool multi, bool shift); void UpdateSelectedState(HTMLOptionElement*, bool multi, bool shift);
void SetPopupIsVisible(bool);
void SetOptionsChangedOnLayoutObject(); void SetOptionsChangedOnLayoutObject();
wtf_size_t SearchOptionsForValue(const String&, wtf_size_t SearchOptionsForValue(const String&,
wtf_size_t list_index_start, wtf_size_t list_index_start,
...@@ -308,7 +307,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -308,7 +307,6 @@ class CORE_EXPORT HTMLSelectElement final
Member<SelectType> select_type_; Member<SelectType> select_type_;
int index_to_select_on_cancel_; int index_to_select_on_cancel_;
bool popup_is_visible_;
friend class ListBoxSelectType; friend class ListBoxSelectType;
friend class MenuListSelectType; friend class MenuListSelectType;
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "third_party/blink/renderer/core/page/spatial_navigation.h" #include "third_party/blink/renderer/core/page/spatial_navigation.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h" #include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/text/platform_locale.h" #include "third_party/blink/renderer/platform/text/platform_locale.h"
#include "ui/base/ui_base_features.h"
namespace blink { namespace blink {
...@@ -89,6 +90,7 @@ class MenuListSelectType final : public SelectType { ...@@ -89,6 +90,7 @@ class MenuListSelectType final : public SelectType {
void ShowPopup() override; void ShowPopup() override;
void HidePopup() override; void HidePopup() override;
void PopupDidHide() override; void PopupDidHide() override;
bool PopupIsVisible() const override;
PopupMenu* PopupForTesting() const override; PopupMenu* PopupForTesting() const override;
void DidMutateSubtree(); void DidMutateSubtree();
...@@ -98,6 +100,7 @@ class MenuListSelectType final : public SelectType { ...@@ -98,6 +100,7 @@ class MenuListSelectType final : public SelectType {
bool ShouldOpenPopupForKeyPressEvent(const KeyboardEvent& event); bool ShouldOpenPopupForKeyPressEvent(const KeyboardEvent& event);
// Returns true if this function handled the event. // Returns true if this function handled the event.
bool HandlePopupOpenKeyboardEvent(); bool HandlePopupOpenKeyboardEvent();
void SetPopupIsVisible(bool popup_is_visible);
void DispatchEventsIfSelectedOptionChanged(); void DispatchEventsIfSelectedOptionChanged();
String UpdateTextStyleInternal(); String UpdateTextStyleInternal();
void DidUpdateActiveOption(HTMLOptionElement* option); void DidUpdateActiveOption(HTMLOptionElement* option);
...@@ -109,6 +112,7 @@ class MenuListSelectType final : public SelectType { ...@@ -109,6 +112,7 @@ class MenuListSelectType final : public SelectType {
scoped_refptr<const ComputedStyle> option_style_; scoped_refptr<const ComputedStyle> option_style_;
int ax_menulist_last_active_index_ = -1; int ax_menulist_last_active_index_ = -1;
bool has_updated_menulist_active_option_ = false; bool has_updated_menulist_active_option_ = false;
bool popup_is_visible_ = false;
}; };
void MenuListSelectType::Trace(Visitor* visitor) { void MenuListSelectType::Trace(Visitor* visitor) {
...@@ -220,7 +224,7 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) { ...@@ -220,7 +224,7 @@ bool MenuListSelectType::DefaultEventHandler(const Event& event) {
source_capabilities)); source_capabilities));
if (select_->GetLayoutObject() && !will_be_destroyed_ && if (select_->GetLayoutObject() && !will_be_destroyed_ &&
!select_->IsDisabledFormControl()) { !select_->IsDisabledFormControl()) {
if (select_->PopupIsVisible()) { if (PopupIsVisible()) {
HidePopup(); HidePopup();
} else { } else {
// Save the selection so it can be compared to the new selection // Save the selection so it can be compared to the new selection
...@@ -283,7 +287,7 @@ bool MenuListSelectType::HandlePopupOpenKeyboardEvent() { ...@@ -283,7 +287,7 @@ bool MenuListSelectType::HandlePopupOpenKeyboardEvent() {
} }
void MenuListSelectType::ShowPopup() { void MenuListSelectType::ShowPopup() {
if (select_->PopupIsVisible()) if (PopupIsVisible())
return; return;
Document& document = select_->GetDocument(); Document& document = select_->GetDocument();
if (document.GetPage()->GetChromeClient().HasOpenedPopup()) if (document.GetPage()->GetChromeClient().HasOpenedPopup())
...@@ -300,7 +304,7 @@ void MenuListSelectType::ShowPopup() { ...@@ -300,7 +304,7 @@ void MenuListSelectType::ShowPopup() {
if (!popup_) if (!popup_)
return; return;
select_->SetPopupIsVisible(true); SetPopupIsVisible(true);
ObserveTreeMutation(); ObserveTreeMutation();
popup_->Show(); popup_->Show();
...@@ -314,7 +318,7 @@ void MenuListSelectType::HidePopup() { ...@@ -314,7 +318,7 @@ void MenuListSelectType::HidePopup() {
} }
void MenuListSelectType::PopupDidHide() { void MenuListSelectType::PopupDidHide() {
select_->SetPopupIsVisible(false); SetPopupIsVisible(false);
UnobserveTreeMutation(); UnobserveTreeMutation();
if (AXObjectCache* cache = select_->GetDocument().ExistingAXObjectCache()) { if (AXObjectCache* cache = select_->GetDocument().ExistingAXObjectCache()) {
if (auto* layout_object = select_->GetLayoutObject()) if (auto* layout_object = select_->GetLayoutObject())
...@@ -322,6 +326,20 @@ void MenuListSelectType::PopupDidHide() { ...@@ -322,6 +326,20 @@ void MenuListSelectType::PopupDidHide() {
} }
} }
bool MenuListSelectType::PopupIsVisible() const {
return popup_is_visible_;
}
void MenuListSelectType::SetPopupIsVisible(bool popup_is_visible) {
popup_is_visible_ = popup_is_visible;
if (!::features::IsFormControlsRefreshEnabled())
return;
if (auto* layout_object = select_->GetLayoutObject()) {
// Invalidate paint to ensure that the focus ring is updated.
layout_object->SetShouldDoFullPaintInvalidation();
}
}
PopupMenu* MenuListSelectType::PopupForTesting() const { PopupMenu* MenuListSelectType::PopupForTesting() const {
return popup_.Get(); return popup_.Get();
} }
...@@ -338,7 +356,7 @@ void MenuListSelectType::DidSelectOption( ...@@ -338,7 +356,7 @@ void MenuListSelectType::DidSelectOption(
UpdateTextStyleAndContent(); UpdateTextStyleAndContent();
// PopupMenu::UpdateFromElement() posts an O(N) task. // PopupMenu::UpdateFromElement() posts an O(N) task.
if (select_->PopupIsVisible() && should_update_popup) if (PopupIsVisible() && should_update_popup)
popup_->UpdateFromElement(PopupMenu::kBySelectionChange); popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
SelectType::DidSelectOption(element, flags, should_update_popup); SelectType::DidSelectOption(element, flags, should_update_popup);
...@@ -371,21 +389,21 @@ void MenuListSelectType::DidBlur() { ...@@ -371,21 +389,21 @@ void MenuListSelectType::DidBlur() {
// change events for list boxes whenever the selection change is actually // change events for list boxes whenever the selection change is actually
// made. This matches other browsers' behavior. // made. This matches other browsers' behavior.
DispatchEventsIfSelectedOptionChanged(); DispatchEventsIfSelectedOptionChanged();
if (select_->PopupIsVisible()) if (PopupIsVisible())
HidePopup(); HidePopup();
SelectType::DidBlur(); SelectType::DidBlur();
} }
void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) { void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) {
UpdateTextStyleAndContent(); UpdateTextStyleAndContent();
if (select_->PopupIsVisible()) if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kBySelectionChange); popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
} }
void MenuListSelectType::DidDetachLayoutTree() { void MenuListSelectType::DidDetachLayoutTree() {
if (popup_) if (popup_)
popup_->DisconnectClient(); popup_->DisconnectClient();
select_->SetPopupIsVisible(false); SetPopupIsVisible(false);
popup_ = nullptr; popup_ = nullptr;
UnobserveTreeMutation(); UnobserveTreeMutation();
} }
...@@ -394,7 +412,7 @@ void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) { ...@@ -394,7 +412,7 @@ void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) {
if (change.ReattachLayoutTree()) if (change.ReattachLayoutTree())
return; return;
UpdateTextStyle(); UpdateTextStyle();
if (select_->PopupIsVisible()) if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kByStyleChange); popup_->UpdateFromElement(PopupMenu::kByStyleChange);
} }
...@@ -512,7 +530,7 @@ class PopupUpdater : public MutationObserver::Delegate { ...@@ -512,7 +530,7 @@ class PopupUpdater : public MutationObserver::Delegate {
MutationObserver&) override { MutationObserver&) override {
// We disconnect the MutationObserver when a popup is closed. However // We disconnect the MutationObserver when a popup is closed. However
// MutationObserver can call back after disconnection. // MutationObserver can call back after disconnection.
if (!select_->PopupIsVisible()) if (!select_type_->PopupIsVisible())
return; return;
for (const auto& record : records) { for (const auto& record : records) {
if (record->type() == "attributes") { if (record->type() == "attributes") {
...@@ -556,7 +574,7 @@ void MenuListSelectType::UnobserveTreeMutation() { ...@@ -556,7 +574,7 @@ void MenuListSelectType::UnobserveTreeMutation() {
} }
void MenuListSelectType::DidMutateSubtree() { void MenuListSelectType::DidMutateSubtree() {
DCHECK(select_->PopupIsVisible()); DCHECK(PopupIsVisible());
DCHECK(popup_); DCHECK(popup_);
popup_->UpdateFromElement(PopupMenu::kByDOMChange); popup_->UpdateFromElement(PopupMenu::kByDOMChange);
} }
...@@ -945,6 +963,10 @@ void SelectType::PopupDidHide() { ...@@ -945,6 +963,10 @@ void SelectType::PopupDidHide() {
NOTREACHED(); NOTREACHED();
} }
bool SelectType::PopupIsVisible() const {
return false;
}
PopupMenu* SelectType::PopupForTesting() const { PopupMenu* SelectType::PopupForTesting() const {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
......
...@@ -50,6 +50,7 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -50,6 +50,7 @@ class SelectType : public GarbageCollected<SelectType> {
virtual void ShowPopup(); virtual void ShowPopup();
virtual void HidePopup(); virtual void HidePopup();
virtual void PopupDidHide(); virtual void PopupDidHide();
virtual bool PopupIsVisible() const;
virtual PopupMenu* PopupForTesting() const; virtual PopupMenu* PopupForTesting() const;
enum SkipDirection { kSkipBackwards = -1, kSkipForwards = 1 }; enum SkipDirection { kSkipBackwards = -1, kSkipForwards = 1 };
......
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