Commit 99405d96 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move HTMLSelectElement::popup_ to MenuListSelectType

Rename HTMLSelectElement::Popup() to PopupForTesting() because it is
used only by testing code.

This CL has no behavior changes.

Bug: 1052232
Change-Id: I0c84297de59937b496c52dc974dabd9cd5508229
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087325
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@{#747133}
parent f9c00776
...@@ -178,7 +178,7 @@ TEST_F(ExternalPopupMenuTest, DidAcceptIndex) { ...@@ -178,7 +178,7 @@ TEST_F(ExternalPopupMenuTest, DidAcceptIndex) {
ASSERT_TRUE(select->PopupIsVisible()); ASSERT_TRUE(select->PopupIsVisible());
WebExternalPopupMenuClient* client = WebExternalPopupMenuClient* client =
static_cast<ExternalPopupMenu*>(select->Popup()); static_cast<ExternalPopupMenu*>(select->PopupForTesting());
client->DidAcceptIndex(2); client->DidAcceptIndex(2);
EXPECT_FALSE(select->PopupIsVisible()); EXPECT_FALSE(select->PopupIsVisible());
ASSERT_EQ("2", select->InnerElement().innerText().Utf8()); ASSERT_EQ("2", select->InnerElement().innerText().Utf8());
...@@ -198,7 +198,7 @@ TEST_F(ExternalPopupMenuTest, DidAcceptIndices) { ...@@ -198,7 +198,7 @@ TEST_F(ExternalPopupMenuTest, DidAcceptIndices) {
ASSERT_TRUE(select->PopupIsVisible()); ASSERT_TRUE(select->PopupIsVisible());
WebExternalPopupMenuClient* client = WebExternalPopupMenuClient* client =
static_cast<ExternalPopupMenu*>(select->Popup()); static_cast<ExternalPopupMenu*>(select->PopupForTesting());
int indices[] = {2}; int indices[] = {2};
WebVector<int> indices_vector(indices, 1); WebVector<int> indices_vector(indices, 1);
client->DidAcceptIndices(indices_vector); client->DidAcceptIndices(indices_vector);
...@@ -220,7 +220,7 @@ TEST_F(ExternalPopupMenuTest, DidAcceptIndicesClearSelect) { ...@@ -220,7 +220,7 @@ TEST_F(ExternalPopupMenuTest, DidAcceptIndicesClearSelect) {
ASSERT_TRUE(select->PopupIsVisible()); ASSERT_TRUE(select->PopupIsVisible());
WebExternalPopupMenuClient* client = WebExternalPopupMenuClient* client =
static_cast<ExternalPopupMenu*>(select->Popup()); static_cast<ExternalPopupMenu*>(select->PopupForTesting());
WebVector<int> indices; WebVector<int> indices;
client->DidAcceptIndices(indices); client->DidAcceptIndices(indices);
EXPECT_FALSE(select->PopupIsVisible()); EXPECT_FALSE(select->PopupIsVisible());
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
#include "third_party/blink/renderer/core/html/forms/html_opt_group_element.h" #include "third_party/blink/renderer/core/html/forms/html_opt_group_element.h"
#include "third_party/blink/renderer/core/html/forms/html_option_element.h" #include "third_party/blink/renderer/core/html/forms/html_option_element.h"
#include "third_party/blink/renderer/core/html/forms/menu_list_inner_element.h" #include "third_party/blink/renderer/core/html/forms/menu_list_inner_element.h"
#include "third_party/blink/renderer/core/html/forms/popup_menu.h"
#include "third_party/blink/renderer/core/html/forms/select_type.h" #include "third_party/blink/renderer/core/html/forms/select_type.h"
#include "third_party/blink/renderer/core/html/html_hr_element.h" #include "third_party/blink/renderer/core/html/html_hr_element.h"
#include "third_party/blink/renderer/core/html/html_slot_element.h" #include "third_party/blink/renderer/core/html/html_slot_element.h"
...@@ -1416,7 +1415,6 @@ void HTMLSelectElement::Trace(Visitor* visitor) { ...@@ -1416,7 +1415,6 @@ void HTMLSelectElement::Trace(Visitor* visitor) {
visitor->Trace(option_to_scroll_to_); visitor->Trace(option_to_scroll_to_);
visitor->Trace(suggested_option_); visitor->Trace(suggested_option_);
visitor->Trace(select_type_); visitor->Trace(select_type_);
visitor->Trace(popup_);
HTMLFormControlElementWithState::Trace(visitor); HTMLFormControlElementWithState::Trace(visitor);
} }
...@@ -1582,6 +1580,10 @@ void HTMLSelectElement::HidePopup() { ...@@ -1582,6 +1580,10 @@ void HTMLSelectElement::HidePopup() {
select_type_->HidePopup(); select_type_->HidePopup();
} }
PopupMenu* HTMLSelectElement::PopupForTesting() const {
return select_type_->PopupForTesting();
}
void HTMLSelectElement::DidRecalcStyle(const StyleRecalcChange change) { void HTMLSelectElement::DidRecalcStyle(const StyleRecalcChange change) {
HTMLFormControlElementWithState::DidRecalcStyle(change); HTMLFormControlElementWithState::DidRecalcStyle(change);
select_type_->DidRecalcStyle(change); select_type_->DidRecalcStyle(change);
......
...@@ -171,7 +171,7 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -171,7 +171,7 @@ class CORE_EXPORT HTMLSelectElement final
const ComputedStyle* OptionStyle() const; const ComputedStyle* OptionStyle() const;
void ShowPopup(); void ShowPopup();
void HidePopup(); void HidePopup();
PopupMenu* Popup() const { return popup_.Get(); } PopupMenu* PopupForTesting() const;
void ResetTypeAheadSessionForTesting(); void ResetTypeAheadSessionForTesting();
...@@ -307,7 +307,6 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -307,7 +307,6 @@ class CORE_EXPORT HTMLSelectElement final
bool is_autofilled_by_preview_; bool is_autofilled_by_preview_;
Member<SelectType> select_type_; Member<SelectType> select_type_;
Member<PopupMenu> popup_;
int index_to_select_on_cancel_; int index_to_select_on_cancel_;
bool popup_is_visible_; bool popup_is_visible_;
......
...@@ -89,6 +89,7 @@ class MenuListSelectType final : public SelectType { ...@@ -89,6 +89,7 @@ class MenuListSelectType final : public SelectType {
void ShowPopup() override; void ShowPopup() override;
void HidePopup() override; void HidePopup() override;
void PopupDidHide() override; void PopupDidHide() override;
PopupMenu* PopupForTesting() const override;
void DidMutateSubtree(); void DidMutateSubtree();
...@@ -103,6 +104,7 @@ class MenuListSelectType final : public SelectType { ...@@ -103,6 +104,7 @@ class MenuListSelectType final : public SelectType {
void ObserveTreeMutation(); void ObserveTreeMutation();
void UnobserveTreeMutation(); void UnobserveTreeMutation();
Member<PopupMenu> popup_;
Member<PopupUpdater> popup_updater_; Member<PopupUpdater> popup_updater_;
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;
...@@ -110,6 +112,7 @@ class MenuListSelectType final : public SelectType { ...@@ -110,6 +112,7 @@ class MenuListSelectType final : public SelectType {
}; };
void MenuListSelectType::Trace(Visitor* visitor) { void MenuListSelectType::Trace(Visitor* visitor) {
visitor->Trace(popup_);
visitor->Trace(popup_updater_); visitor->Trace(popup_updater_);
SelectType::Trace(visitor); SelectType::Trace(visitor);
} }
...@@ -290,24 +293,24 @@ void MenuListSelectType::ShowPopup() { ...@@ -290,24 +293,24 @@ void MenuListSelectType::ShowPopup() {
if (select_->VisibleBoundsInVisualViewport().IsEmpty()) if (select_->VisibleBoundsInVisualViewport().IsEmpty())
return; return;
if (!select_->popup_) { if (!popup_) {
select_->popup_ = document.GetPage()->GetChromeClient().OpenPopupMenu( popup_ = document.GetPage()->GetChromeClient().OpenPopupMenu(
*document.GetFrame(), *select_); *document.GetFrame(), *select_);
} }
if (!select_->popup_) if (!popup_)
return; return;
select_->SetPopupIsVisible(true); select_->SetPopupIsVisible(true);
ObserveTreeMutation(); ObserveTreeMutation();
select_->popup_->Show(); popup_->Show();
if (AXObjectCache* cache = document.ExistingAXObjectCache()) if (AXObjectCache* cache = document.ExistingAXObjectCache())
cache->DidShowMenuListPopup(select_->GetLayoutObject()); cache->DidShowMenuListPopup(select_->GetLayoutObject());
} }
void MenuListSelectType::HidePopup() { void MenuListSelectType::HidePopup() {
if (select_->popup_) if (popup_)
select_->popup_->Hide(); popup_->Hide();
} }
void MenuListSelectType::PopupDidHide() { void MenuListSelectType::PopupDidHide() {
...@@ -319,6 +322,10 @@ void MenuListSelectType::PopupDidHide() { ...@@ -319,6 +322,10 @@ void MenuListSelectType::PopupDidHide() {
} }
} }
PopupMenu* MenuListSelectType::PopupForTesting() const {
return popup_.Get();
}
void MenuListSelectType::DidSelectOption( void MenuListSelectType::DidSelectOption(
HTMLOptionElement* element, HTMLOptionElement* element,
HTMLSelectElement::SelectOptionFlags flags, HTMLSelectElement::SelectOptionFlags flags,
...@@ -332,7 +339,7 @@ void MenuListSelectType::DidSelectOption( ...@@ -332,7 +339,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 (select_->PopupIsVisible() && should_update_popup)
select_->popup_->UpdateFromElement(PopupMenu::kBySelectionChange); popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
SelectType::DidSelectOption(element, flags, should_update_popup); SelectType::DidSelectOption(element, flags, should_update_popup);
...@@ -372,14 +379,14 @@ void MenuListSelectType::DidBlur() { ...@@ -372,14 +379,14 @@ void MenuListSelectType::DidBlur() {
void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) { void MenuListSelectType::DidSetSuggestedOption(HTMLOptionElement*) {
UpdateTextStyleAndContent(); UpdateTextStyleAndContent();
if (select_->PopupIsVisible()) if (select_->PopupIsVisible())
select_->popup_->UpdateFromElement(PopupMenu::kBySelectionChange); popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
} }
void MenuListSelectType::DidDetachLayoutTree() { void MenuListSelectType::DidDetachLayoutTree() {
if (select_->popup_) if (popup_)
select_->popup_->DisconnectClient(); popup_->DisconnectClient();
select_->SetPopupIsVisible(false); select_->SetPopupIsVisible(false);
select_->popup_ = nullptr; popup_ = nullptr;
UnobserveTreeMutation(); UnobserveTreeMutation();
} }
...@@ -388,7 +395,7 @@ void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) { ...@@ -388,7 +395,7 @@ void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) {
return; return;
UpdateTextStyle(); UpdateTextStyle();
if (select_->PopupIsVisible()) if (select_->PopupIsVisible())
select_->popup_->UpdateFromElement(PopupMenu::kByStyleChange); popup_->UpdateFromElement(PopupMenu::kByStyleChange);
} }
String MenuListSelectType::UpdateTextStyleInternal() { String MenuListSelectType::UpdateTextStyleInternal() {
...@@ -550,8 +557,8 @@ void MenuListSelectType::UnobserveTreeMutation() { ...@@ -550,8 +557,8 @@ void MenuListSelectType::UnobserveTreeMutation() {
void MenuListSelectType::DidMutateSubtree() { void MenuListSelectType::DidMutateSubtree() {
DCHECK(select_->PopupIsVisible()); DCHECK(select_->PopupIsVisible());
DCHECK(select_->popup_); DCHECK(popup_);
select_->popup_->UpdateFromElement(PopupMenu::kByDOMChange); popup_->UpdateFromElement(PopupMenu::kByDOMChange);
} }
// ============================================================================ // ============================================================================
...@@ -938,6 +945,11 @@ void SelectType::PopupDidHide() { ...@@ -938,6 +945,11 @@ void SelectType::PopupDidHide() {
NOTREACHED(); NOTREACHED();
} }
PopupMenu* SelectType::PopupForTesting() const {
NOTREACHED();
return nullptr;
}
// 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
......
...@@ -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 PopupMenu* PopupForTesting() const;
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