Commit 798e2dfe authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Improve performance of updating shadow text in menulist SELECTs

HTMLSelectElement::UpdateMenuListLabel() detached and created Text
nodes every time by Element's textContent setter, and it was
inefficient.  We should keep one Text node, and UpdateMenuListLabel()
should update the nodeValue of the Text node.

Bug: 1048572
Change-Id: Ifef39627b00cc5345a2b0d53ac652e45d064e941
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040853Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739284}
parent f18e2a87
......@@ -2019,6 +2019,8 @@ void HTMLSelectElement::UpdateUserAgentShadowTree(ShadowRoot& root) {
Element* inner_element =
MakeGarbageCollected<MenuListInnerElement>(GetDocument());
inner_element->setAttribute(html_names::kAriaHiddenAttr, "true");
// Make sure InnerElement() always has a Text node.
inner_element->appendChild(Text::Create(GetDocument(), g_empty_string));
root.insertBefore(inner_element, root.firstChild());
UpdateMenuListLabel(UpdateFromElement());
}
......@@ -2369,7 +2371,12 @@ String HTMLSelectElement::UpdateFromElement() {
void HTMLSelectElement::UpdateMenuListLabel(const String& label) {
if (!UsesMenuList())
return;
InnerElement().setTextContent(label);
// TODO(tkent): If this function is called between size_ / is_multiple_
// change and UpdateUserAgentShadowTree(), InnerElement() can be a <slot>
// instead of MenuListInnerElement, and InnerElement() doesn't have a Text.
// We must fix it!
if (InnerElement().firstChild())
InnerElement().firstChild()->setNodeValue(label);
// LayoutMenuList::ControlClipRect() depends on the content box size of
// inner_element.
if (auto* box = GetLayoutBox()) {
......
......@@ -66,6 +66,7 @@ Input before setting suggested values:
| <shadow:root>
| <div>
| aria-hidden="true"
| ""
| <slot>
| name="user-agent-custom-assign-slot"
| "input.value: initial value"
......@@ -247,6 +248,7 @@ After resetting suggestedValue value:
| <shadow:root>
| <div>
| aria-hidden="true"
| ""
| <slot>
| name="user-agent-custom-assign-slot"
| "input.value: initial value"
......
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