Commit 83fcb35a authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move the content of HTMLSelectElement::OptionToBeShown() to SelectType.

This CL renames HTMLSelectElement::OptionToBeShown() to
OptionToBeShownForTesting() because it is used only by testing code.

This CL has no behavior changes.

Bug: 1052232
Change-Id: I8522a59be99958be526fd59f4494860755666254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094520Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748131}
parent b4488011
...@@ -1514,16 +1514,8 @@ void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) { ...@@ -1514,16 +1514,8 @@ void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) {
select_type_->UpdateTextStyleAndContent(); select_type_->UpdateTextStyleAndContent();
} }
HTMLOptionElement* HTMLSelectElement::OptionToBeShown() const { HTMLOptionElement* HTMLSelectElement::OptionToBeShownForTesting() const {
if (HTMLOptionElement* option = OptionAtListIndex(index_to_select_on_cancel_)) return select_type_->OptionToBeShown();
return option;
if (suggested_option_)
return suggested_option_;
// TODO(tkent): We should not call optionToBeShown() in isMultiple() case.
if (IsMultiple())
return SelectedOption();
DCHECK_EQ(SelectedOption(), last_on_change_option_);
return last_on_change_option_;
} }
void HTMLSelectElement::SelectOptionByPopup(int list_index) { void HTMLSelectElement::SelectOptionByPopup(int list_index) {
......
...@@ -165,7 +165,7 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -165,7 +165,7 @@ class CORE_EXPORT HTMLSelectElement final
void ProvisionalSelectionChanged(unsigned); void ProvisionalSelectionChanged(unsigned);
void PopupDidHide(); void PopupDidHide();
bool PopupIsVisible() const; bool PopupIsVisible() const;
HTMLOptionElement* OptionToBeShown() const; HTMLOptionElement* OptionToBeShownForTesting() 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.
const ComputedStyle* OptionStyle() const; const ComputedStyle* OptionStyle() const;
......
...@@ -143,7 +143,8 @@ TEST_F(HTMLSelectElementTest, RestoreUnmatchedFormControlState) { ...@@ -143,7 +143,8 @@ TEST_F(HTMLSelectElementTest, RestoreUnmatchedFormControlState) {
// Restore // Restore
select->RestoreFormControlState(select_state); select->RestoreFormControlState(select_state);
EXPECT_EQ(-1, To<HTMLSelectElement>(element)->selectedIndex()); EXPECT_EQ(-1, To<HTMLSelectElement>(element)->selectedIndex());
EXPECT_EQ(nullptr, To<HTMLSelectElement>(element)->OptionToBeShown()); EXPECT_EQ(nullptr,
To<HTMLSelectElement>(element)->OptionToBeShownForTesting());
} }
TEST_F(HTMLSelectElementTest, VisibleBoundsInVisualViewport) { TEST_F(HTMLSelectElementTest, VisibleBoundsInVisualViewport) {
......
...@@ -83,6 +83,7 @@ class MenuListSelectType final : public SelectType { ...@@ -83,6 +83,7 @@ class MenuListSelectType final : public SelectType {
void UpdateTextStyle() override { UpdateTextStyleInternal(); } void UpdateTextStyle() override { UpdateTextStyleInternal(); }
void UpdateTextStyleAndContent() override; void UpdateTextStyleAndContent() override;
HTMLOptionElement* OptionToBeShown() const override;
const ComputedStyle* OptionStyle() const override { const ComputedStyle* OptionStyle() const override {
return option_style_.get(); return option_style_.get();
} }
...@@ -418,7 +419,7 @@ void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) { ...@@ -418,7 +419,7 @@ void MenuListSelectType::DidRecalcStyle(const StyleRecalcChange change) {
} }
String MenuListSelectType::UpdateTextStyleInternal() { String MenuListSelectType::UpdateTextStyleInternal() {
HTMLOptionElement* option = select_->OptionToBeShown(); HTMLOptionElement* option = OptionToBeShown();
String text = g_empty_string; String text = g_empty_string;
const ComputedStyle* option_style = nullptr; const ComputedStyle* option_style = nullptr;
...@@ -502,6 +503,19 @@ void MenuListSelectType::DidUpdateActiveOption(HTMLOptionElement* option) { ...@@ -502,6 +503,19 @@ void MenuListSelectType::DidUpdateActiveOption(HTMLOptionElement* option) {
select_->GetLayoutObject(), option_index); select_->GetLayoutObject(), option_index);
} }
HTMLOptionElement* MenuListSelectType::OptionToBeShown() const {
if (auto* option =
select_->OptionAtListIndex(select_->index_to_select_on_cancel_))
return option;
if (select_->suggested_option_)
return select_->suggested_option_;
// TODO(tkent): We should not call OptionToBeShown() in IsMultiple() case.
if (select_->IsMultiple())
return select_->SelectedOption();
DCHECK_EQ(select_->SelectedOption(), select_->last_on_change_option_);
return select_->last_on_change_option_;
}
void MenuListSelectType::MaximumOptionWidthMightBeChanged() const { void MenuListSelectType::MaximumOptionWidthMightBeChanged() const {
if (LayoutObject* layout_object = select_->GetLayoutObject()) { if (LayoutObject* layout_object = select_->GetLayoutObject()) {
layout_object->SetNeedsLayoutAndPrefWidthsRecalc( layout_object->SetNeedsLayoutAndPrefWidthsRecalc(
...@@ -948,6 +962,11 @@ void SelectType::UpdateTextStyle() {} ...@@ -948,6 +962,11 @@ void SelectType::UpdateTextStyle() {}
void SelectType::UpdateTextStyleAndContent() {} void SelectType::UpdateTextStyleAndContent() {}
HTMLOptionElement* SelectType::OptionToBeShown() const {
NOTREACHED();
return nullptr;
}
const ComputedStyle* SelectType::OptionStyle() const { const ComputedStyle* SelectType::OptionStyle() const {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
......
...@@ -40,6 +40,7 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -40,6 +40,7 @@ class SelectType : public GarbageCollected<SelectType> {
// and update the text. // and update the text.
virtual void UpdateTextStyleAndContent(); virtual void UpdateTextStyleAndContent();
virtual HTMLOptionElement* OptionToBeShown() const;
virtual const ComputedStyle* OptionStyle() const; virtual const ComputedStyle* OptionStyle() const;
virtual void MaximumOptionWidthMightBeChanged() const; virtual void MaximumOptionWidthMightBeChanged() 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