Commit 434e5db5 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

MenuList SELECT: Update text in the shadow element

When UpdateFromElement() is called, textContent of the shadow element
should be updated as well as the text in the anonymous block.
Exceptions:
 * In DidStyleRecalc() and AttachLayoutTree(), we must not update DOM
   at all.
 * Instead, we should update the textContent
  - when the UA shadow tree is created, or
  - even if the SELECT has no LayoutObject

This CL has no user-visible behavior changes because the shadow element
has display:none.

Bug: 1040828
Change-Id: I55f0bfd0399ca50a8aa99c64a8fdf89ef5c42e68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032656Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737652}
parent 42d1f5e9
...@@ -368,9 +368,9 @@ void HTMLSelectElement::OptionElementChildrenChanged( ...@@ -368,9 +368,9 @@ void HTMLSelectElement::OptionElementChildrenChanged(
const HTMLOptionElement& option) { const HTMLOptionElement& option) {
SetNeedsValidityCheck(); SetNeedsValidityCheck();
if (option.Selected() && UsesMenuList())
UpdateMenuListLabel(UpdateFromElement());
if (GetLayoutObject()) { if (GetLayoutObject()) {
if (option.Selected() && UsesMenuList())
UpdateFromElement();
if (AXObjectCache* cache = if (AXObjectCache* cache =
GetLayoutObject()->GetDocument().ExistingAXObjectCache()) GetLayoutObject()->GetDocument().ExistingAXObjectCache())
cache->ChildrenChanged(this); cache->ChildrenChanged(this);
...@@ -916,10 +916,9 @@ void HTMLSelectElement::SetSuggestedOption(HTMLOptionElement* option) { ...@@ -916,10 +916,9 @@ void HTMLSelectElement::SetSuggestedOption(HTMLOptionElement* option) {
return; return;
suggested_option_ = option; suggested_option_ = option;
if (GetLayoutObject()) { UpdateMenuListLabel(UpdateFromElement());
UpdateFromElement(); if (GetLayoutObject())
ScrollToOption(option); ScrollToOption(option);
}
if (PopupIsVisible()) if (PopupIsVisible())
popup_->UpdateFromElement(PopupMenu::kBySelectionChange); popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
} }
...@@ -1093,7 +1092,7 @@ void HTMLSelectElement::SelectOption(HTMLOptionElement* element, ...@@ -1093,7 +1092,7 @@ void HTMLSelectElement::SelectOption(HTMLOptionElement* element,
} }
// For the menu list case, this is what makes the selected element appear. // For the menu list case, this is what makes the selected element appear.
UpdateFromElement(); UpdateMenuListLabel(UpdateFromElement());
// PopupMenu::UpdateFromElement() posts an O(N) task. // PopupMenu::UpdateFromElement() posts an O(N) task.
if (PopupIsVisible() && should_update_popup) if (PopupIsVisible() && should_update_popup)
popup_->UpdateFromElement(PopupMenu::kBySelectionChange); popup_->UpdateFromElement(PopupMenu::kBySelectionChange);
...@@ -2010,6 +2009,7 @@ void HTMLSelectElement::UpdateUserAgentShadowTree(ShadowRoot& root) { ...@@ -2010,6 +2009,7 @@ void HTMLSelectElement::UpdateUserAgentShadowTree(ShadowRoot& root) {
if (UsesMenuList()) { if (UsesMenuList()) {
root.insertBefore(MakeGarbageCollected<MenuListInnerElement>(GetDocument()), root.insertBefore(MakeGarbageCollected<MenuListInnerElement>(GetDocument()),
root.firstChild()); root.firstChild());
UpdateMenuListLabel(UpdateFromElement());
} }
} }
...@@ -2077,7 +2077,7 @@ void HTMLSelectElement::PopupDidHide() { ...@@ -2077,7 +2077,7 @@ void HTMLSelectElement::PopupDidHide() {
void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) { void HTMLSelectElement::SetIndexToSelectOnCancel(int list_index) {
index_to_select_on_cancel_ = list_index; index_to_select_on_cancel_ = list_index;
UpdateFromElement(); UpdateMenuListLabel(UpdateFromElement());
} }
HTMLOptionElement* HTMLSelectElement::OptionToBeShown() const { HTMLOptionElement* HTMLSelectElement::OptionToBeShown() const {
...@@ -2291,12 +2291,9 @@ void HTMLSelectElement::ChangeRendering() { ...@@ -2291,12 +2291,9 @@ void HTMLSelectElement::ChangeRendering() {
} }
} }
void HTMLSelectElement::UpdateFromElement() { String HTMLSelectElement::UpdateFromElement() {
if (!UsesMenuList()) if (!UsesMenuList())
return; return String();
auto* layout_object = GetLayoutObject();
if (!layout_object)
return;
HTMLOptionElement* option = OptionToBeShown(); HTMLOptionElement* option = OptionToBeShown();
String text = g_empty_string; String text = g_empty_string;
...@@ -2330,9 +2327,18 @@ void HTMLSelectElement::UpdateFromElement() { ...@@ -2330,9 +2327,18 @@ void HTMLSelectElement::UpdateFromElement() {
} }
} }
ToLayoutMenuList(layout_object)->SetText(text.StripWhiteSpace()); String stripped = text.StripWhiteSpace();
layout_object->UpdateFromElement(); if (auto* layout_object = GetLayoutObject()) {
DidUpdateMenuListActiveOption(option); ToLayoutMenuList(layout_object)->SetText(stripped);
layout_object->UpdateFromElement();
DidUpdateMenuListActiveOption(option);
}
return stripped;
}
void HTMLSelectElement::UpdateMenuListLabel(const String& label) {
if (UsesMenuList())
InnerElement().setTextContent(label);
} }
const ComputedStyle* HTMLSelectElement::OptionStyle() const { const ComputedStyle* HTMLSelectElement::OptionStyle() const {
......
...@@ -186,7 +186,10 @@ class CORE_EXPORT HTMLSelectElement final ...@@ -186,7 +186,10 @@ class CORE_EXPORT HTMLSelectElement final
private: private:
const AtomicString& FormControlType() const override; const AtomicString& FormControlType() const override;
void UpdateFromElement(); // Update style on style or selected OPTION change, and return text to be
// shown.
String UpdateFromElement();
void UpdateMenuListLabel(const String& label);
bool MayTriggerVirtualKeyboard() const override; bool MayTriggerVirtualKeyboard() const override;
......
...@@ -155,6 +155,7 @@ Input after setting suggestedValue: ...@@ -155,6 +155,7 @@ Input after setting suggestedValue:
| "TX" | "TX"
| <shadow:root> | <shadow:root>
| <div> | <div>
| "TX"
| <slot> | <slot>
| name="user-agent-custom-assign-slot" | name="user-agent-custom-assign-slot"
| "input.value: initial value" | "input.value: initial value"
......
...@@ -91,6 +91,7 @@ instead of "initial value". ...@@ -91,6 +91,7 @@ instead of "initial value".
| "inserted value" | "inserted value"
| <shadow:root> | <shadow:root>
| <div> | <div>
| "initial value"
| <slot> | <slot>
| name="user-agent-custom-assign-slot" | name="user-agent-custom-assign-slot"
| "input.value: initial value" | "input.value: initial value"
......
...@@ -43,7 +43,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -43,7 +43,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"childNodeIndexes": [ "childNodeIndexes": [
4, 4,
5, 5,
34 35
], ],
"attributes": [ "attributes": [
{ {
...@@ -67,11 +67,10 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -67,11 +67,10 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"childNodeIndexes": [ "childNodeIndexes": [
6, 6,
7, 7,
14,
15, 15,
18, 16,
19, 19,
21, 20,
22, 22,
23, 23,
24, 24,
...@@ -81,7 +80,8 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -81,7 +80,8 @@ Tests DOMSnapshot.getSnapshot method returning input values.
28, 28,
29, 29,
30, 30,
33 31,
34
], ],
"attributes": [ "attributes": [
{ {
...@@ -104,7 +104,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -104,7 +104,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
8, 8,
9 10
], ],
"layoutNodeIndex": 4 "layoutNodeIndex": 4
}, },
...@@ -113,6 +113,16 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -113,6 +113,16 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"nodeName": "DIV", "nodeName": "DIV",
"nodeValue": "", "nodeValue": "",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [
9
],
"shadowRootType": "user-agent"
},
{
"nodeType": 3,
"nodeName": "#text",
"nodeValue": "Option 1",
"backendNodeId": "<number>",
"shadowRootType": "user-agent" "shadowRootType": "user-agent"
}, },
{ {
...@@ -121,8 +131,8 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -121,8 +131,8 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"nodeValue": "", "nodeValue": "",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
10, 11,
12 13
], ],
"attributes": [ "attributes": [
{ {
...@@ -139,7 +149,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -139,7 +149,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"optionSelected": true, "optionSelected": true,
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
11 12
], ],
"attributes": [ "attributes": [
{ {
...@@ -162,7 +172,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -162,7 +172,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"optionSelected": false, "optionSelected": false,
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
13 14
], ],
"attributes": [ "attributes": [
{ {
...@@ -192,7 +202,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -192,7 +202,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"inputValue": "InputValue", "inputValue": "InputValue",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
16 17
], ],
"attributes": [ "attributes": [
{ {
...@@ -213,7 +223,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -213,7 +223,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"nodeValue": "", "nodeValue": "",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
17 18
], ],
"layoutNodeIndex": 7, "layoutNodeIndex": 7,
"shadowRootType": "user-agent", "shadowRootType": "user-agent",
...@@ -242,7 +252,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -242,7 +252,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"inputValue": "ButtonValue", "inputValue": "ButtonValue",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
20 21
], ],
"attributes": [ "attributes": [
{ {
...@@ -411,7 +421,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -411,7 +421,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"textValue": "TextAreaValue", "textValue": "TextAreaValue",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
31 32
], ],
"attributes": [ "attributes": [
{ {
...@@ -427,7 +437,7 @@ Tests DOMSnapshot.getSnapshot method returning input values. ...@@ -427,7 +437,7 @@ Tests DOMSnapshot.getSnapshot method returning input values.
"nodeValue": "", "nodeValue": "",
"backendNodeId": "<number>", "backendNodeId": "<number>",
"childNodeIndexes": [ "childNodeIndexes": [
32 33
], ],
"layoutNodeIndex": 22, "layoutNodeIndex": 22,
"shadowRootType": "user-agent", "shadowRootType": "user-agent",
......
...@@ -82,6 +82,7 @@ instead of "initial value". ...@@ -82,6 +82,7 @@ instead of "initial value".
| "inserted value" | "inserted value"
| <shadow:root> | <shadow:root>
| <div> | <div>
| "initial value"
| <slot> | <slot>
| name="user-agent-custom-assign-slot" | name="user-agent-custom-assign-slot"
| "input.value: initial value" | "input.value: initial value"
......
...@@ -91,6 +91,7 @@ instead of "initial value". ...@@ -91,6 +91,7 @@ instead of "initial value".
| "inserted value" | "inserted value"
| <shadow:root> | <shadow:root>
| <div> | <div>
| "initial value"
| <slot> | <slot>
| name="user-agent-custom-assign-slot" | name="user-agent-custom-assign-slot"
| "input.value: initial value" | "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