Commit f3194828 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move the major part of LayoutMenuList::UpdateFromElement()

... to HTMLSelectElement

- Early-return for !UsesMenuList().  LayoutListBox doesn't have
  UpdateFromElement() implementation.

- Move LayoutMenuList::option_style_ to HTMLSelectElement.

This CL has no behavior changes.

Bug: 1040828
Change-Id: I5870e228f9ad473844d6a05e7611e59cbcfcd084
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2014205Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733893}
parent b3ebda54
...@@ -2238,12 +2238,52 @@ void HTMLSelectElement::ChangeRendering() { ...@@ -2238,12 +2238,52 @@ void HTMLSelectElement::ChangeRendering() {
} }
void HTMLSelectElement::UpdateFromElement() { void HTMLSelectElement::UpdateFromElement() {
if (!UsesMenuList())
return;
auto* layout_object = GetLayoutObject(); auto* layout_object = GetLayoutObject();
if (!layout_object) if (!layout_object)
return; return;
HTMLOptionElement* option = OptionToBeShown();
String text = g_empty_string;
option_style_ = nullptr;
if (IsMultiple()) {
unsigned selected_count = 0;
HTMLOptionElement* selected_option_element = nullptr;
for (auto* const option : GetOptionList()) {
if (option->Selected()) {
if (++selected_count == 1)
selected_option_element = option;
}
}
if (selected_count == 1) {
text = selected_option_element->TextIndentedToRespectGroupLabel();
option_style_ = selected_option_element->GetComputedStyle();
} else {
Locale& locale = GetLocale();
String localized_number_string =
locale.ConvertToLocalizedNumber(String::Number(selected_count));
text = locale.QueryString(IDS_FORM_SELECT_MENU_LIST_TEXT,
localized_number_string);
DCHECK(!option_style_);
}
} else {
if (option) {
text = option->TextIndentedToRespectGroupLabel();
option_style_ = option->GetComputedStyle();
}
}
ToLayoutMenuList(layout_object)->SetText(text.StripWhiteSpace());
layout_object->UpdateFromElement(); layout_object->UpdateFromElement();
if (UsesMenuList()) DidUpdateMenuListActiveOption(option);
DidUpdateMenuListActiveOption(OptionToBeShown()); }
const ComputedStyle* HTMLSelectElement::OptionStyle() const {
DCHECK(UsesMenuList());
return option_style_.get();
} }
} // namespace blink } // namespace blink
...@@ -161,6 +161,9 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -161,6 +161,9 @@ class CORE_EXPORT HTMLSelectElement final
void PopupDidHide(); void PopupDidHide();
bool PopupIsVisible() const { return popup_is_visible_; } bool PopupIsVisible() const { return popup_is_visible_; }
HTMLOptionElement* OptionToBeShown() const; HTMLOptionElement* OptionToBeShown() const;
// Style of the selected OPTION. This is nullable, and only for
// the menulist mode.
const ComputedStyle* OptionStyle() const;
void ShowPopup(); void ShowPopup();
void HidePopup(); void HidePopup();
PopupMenu* Popup() const { return popup_.Get(); } PopupMenu* Popup() const { return popup_.Get(); }
...@@ -305,6 +308,7 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -305,6 +308,7 @@ class CORE_EXPORT HTMLSelectElement final
Member<HTMLOptionElement> active_selection_end_; Member<HTMLOptionElement> active_selection_end_;
Member<HTMLOptionElement> option_to_scroll_to_; Member<HTMLOptionElement> option_to_scroll_to_;
Member<HTMLOptionElement> suggested_option_; Member<HTMLOptionElement> suggested_option_;
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 is_multiple_; bool is_multiple_;
......
...@@ -113,9 +113,10 @@ void LayoutMenuList::CreateInnerBlock() { ...@@ -113,9 +113,10 @@ void LayoutMenuList::CreateInnerBlock() {
bool LayoutMenuList::HasOptionStyleChanged( bool LayoutMenuList::HasOptionStyleChanged(
const ComputedStyle& inner_style) const { const ComputedStyle& inner_style) const {
return option_style_ && const ComputedStyle* option_style = SelectElement()->OptionStyle();
((option_style_->Direction() != inner_style.Direction() || return option_style &&
option_style_->GetUnicodeBidi() != inner_style.GetUnicodeBidi())); ((option_style->Direction() != inner_style.Direction() ||
option_style->GetUnicodeBidi() != inner_style.GetUnicodeBidi()));
} }
void LayoutMenuList::AdjustInnerStyle(ComputedStyle& inner_style) const { void LayoutMenuList::AdjustInnerStyle(ComputedStyle& inner_style) const {
...@@ -155,8 +156,9 @@ void LayoutMenuList::AdjustInnerStyle(ComputedStyle& inner_style) const { ...@@ -155,8 +156,9 @@ void LayoutMenuList::AdjustInnerStyle(ComputedStyle& inner_style) const {
if (HasOptionStyleChanged(inner_style)) { if (HasOptionStyleChanged(inner_style)) {
inner_block_->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation( inner_block_->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
layout_invalidation_reason::kStyleChange); layout_invalidation_reason::kStyleChange);
inner_style.SetDirection(option_style_->Direction()); const ComputedStyle* option_style = SelectElement()->OptionStyle();
inner_style.SetUnicodeBidi(option_style_->GetUnicodeBidi()); inner_style.SetDirection(option_style->Direction());
inner_style.SetUnicodeBidi(option_style->GetUnicodeBidi());
} }
} }
...@@ -229,41 +231,6 @@ void LayoutMenuList::UpdateOptionsWidth() const { ...@@ -229,41 +231,6 @@ void LayoutMenuList::UpdateOptionsWidth() const {
} }
void LayoutMenuList::UpdateFromElement() { void LayoutMenuList::UpdateFromElement() {
HTMLSelectElement* select = SelectElement();
HTMLOptionElement* option = select->OptionToBeShown();
String text = g_empty_string;
option_style_ = nullptr;
if (select->IsMultiple()) {
unsigned selected_count = 0;
HTMLOptionElement* selected_option_element = nullptr;
for (auto* const option : select->GetOptionList()) {
if (option->Selected()) {
if (++selected_count == 1)
selected_option_element = option;
}
}
if (selected_count == 1) {
text = selected_option_element->TextIndentedToRespectGroupLabel();
option_style_ = selected_option_element->GetComputedStyle();
} else {
Locale& locale = select->GetLocale();
String localized_number_string =
locale.ConvertToLocalizedNumber(String::Number(selected_count));
text = locale.QueryString(IDS_FORM_SELECT_MENU_LIST_TEXT,
localized_number_string);
DCHECK(!option_style_);
}
} else {
if (option) {
text = option->TextIndentedToRespectGroupLabel();
option_style_ = option->GetComputedStyle();
}
}
SetText(text.StripWhiteSpace());
DCHECK(inner_block_); DCHECK(inner_block_);
if (HasOptionStyleChanged(inner_block_->StyleRef())) if (HasOptionStyleChanged(inner_block_->StyleRef()))
UpdateInnerStyle(); UpdateInnerStyle();
......
...@@ -41,6 +41,7 @@ class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox { ...@@ -41,6 +41,7 @@ class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox {
HTMLSelectElement* SelectElement() const; HTMLSelectElement* SelectElement() const;
String GetText() const; String GetText() const;
void SetText(const String&);
const char* GetName() const override { return "LayoutMenuList"; } const char* GetName() const override { return "LayoutMenuList"; }
...@@ -96,7 +97,6 @@ class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox { ...@@ -96,7 +97,6 @@ class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox {
void UpdateInnerStyle(); void UpdateInnerStyle();
void AdjustInnerStyle(ComputedStyle&) const; void AdjustInnerStyle(ComputedStyle&) const;
bool HasOptionStyleChanged(const ComputedStyle& inner_style) const; bool HasOptionStyleChanged(const ComputedStyle& inner_style) const;
void SetText(const String&);
void UpdateInnerBlockHeight(); void UpdateInnerBlockHeight();
void UpdateOptionsWidth() const; void UpdateOptionsWidth() const;
void SetIndexToSelectOnCancel(int list_index); void SetIndexToSelectOnCancel(int list_index);
...@@ -109,8 +109,6 @@ class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox { ...@@ -109,8 +109,6 @@ class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox {
// m_optionsWidth is calculated and cached on demand. // m_optionsWidth is calculated and cached on demand.
// updateOptionsWidth() should be called before reading them. // updateOptionsWidth() should be called before reading them.
mutable int options_width_; mutable int options_width_;
scoped_refptr<const ComputedStyle> option_style_;
}; };
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutMenuList, IsMenuList()); DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutMenuList, IsMenuList());
......
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