Commit 5abe7d18 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move the content of UpdateUserAgentShadowTree() and InnerElement()

... from HTMLSelectElement to MenuListSelectType.

This CL has no behavior changes.

Bug: 1052232
Change-Id: Id8d0725cfce3f3421681a62b180760ab48d430cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228280
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@{#774984}
parent 55d2025a
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
#include "third_party/blink/renderer/core/html/forms/html_form_element.h" #include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#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/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"
...@@ -1196,21 +1195,11 @@ void HTMLSelectElement::UpdateUserAgentShadowTree(ShadowRoot& root) { ...@@ -1196,21 +1195,11 @@ void HTMLSelectElement::UpdateUserAgentShadowTree(ShadowRoot& root) {
will_be_removed->remove(); will_be_removed->remove();
} }
} }
if (UsesMenuList()) { select_type_->CreateShadowSubtree(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());
}
} }
Element& HTMLSelectElement::InnerElement() const { Element& HTMLSelectElement::InnerElement() const {
DCHECK(UsesMenuList()); return select_type_->InnerElement();
auto* inner_element = DynamicTo<Element>(UserAgentShadowRoot()->firstChild());
DCHECK(inner_element);
return *inner_element;
} }
HTMLOptionElement* HTMLSelectElement::SpatialNavigationFocusedOption() { HTMLOptionElement* HTMLSelectElement::SpatialNavigationFocusedOption() {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "third_party/blink/renderer/core/dom/mutation_observer.h" #include "third_party/blink/renderer/core/dom/mutation_observer.h"
#include "third_party/blink/renderer/core/dom/mutation_record.h" #include "third_party/blink/renderer/core/dom/mutation_record.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h" #include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/events/gesture_event.h" #include "third_party/blink/renderer/core/events/gesture_event.h"
#include "third_party/blink/renderer/core/events/keyboard_event.h" #include "third_party/blink/renderer/core/events/keyboard_event.h"
#include "third_party/blink/renderer/core/events/mouse_event.h" #include "third_party/blink/renderer/core/events/mouse_event.h"
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h" #include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h" #include "third_party/blink/renderer/core/html/forms/html_select_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/popup_menu.h"
#include "third_party/blink/renderer/core/input/event_handler.h" #include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/input/input_device_capabilities.h" #include "third_party/blink/renderer/core/input/input_device_capabilities.h"
...@@ -92,6 +94,8 @@ class MenuListSelectType final : public SelectType { ...@@ -92,6 +94,8 @@ class MenuListSelectType final : public SelectType {
} }
void MaximumOptionWidthMightBeChanged() const override; void MaximumOptionWidthMightBeChanged() const override;
void CreateShadowSubtree(ShadowRoot& root) override;
Element& InnerElement() const override;
void ShowPopup() override; void ShowPopup() override;
void HidePopup() override; void HidePopup() override;
void PopupDidHide() override; void PopupDidHide() override;
...@@ -292,6 +296,22 @@ bool MenuListSelectType::HandlePopupOpenKeyboardEvent() { ...@@ -292,6 +296,22 @@ bool MenuListSelectType::HandlePopupOpenKeyboardEvent() {
return true; return true;
} }
void MenuListSelectType::CreateShadowSubtree(ShadowRoot& root) {
Document& doc = select_->GetDocument();
Element* inner_element = MakeGarbageCollected<MenuListInnerElement>(doc);
inner_element->setAttribute(html_names::kAriaHiddenAttr, "true");
// Make sure InnerElement() always has a Text node.
inner_element->appendChild(Text::Create(doc, g_empty_string));
root.insertBefore(inner_element, root.firstChild());
}
Element& MenuListSelectType::InnerElement() const {
auto* inner_element =
DynamicTo<Element>(select_->UserAgentShadowRoot()->firstChild());
DCHECK(inner_element);
return *inner_element;
}
void MenuListSelectType::ShowPopup() { void MenuListSelectType::ShowPopup() {
if (PopupIsVisible()) if (PopupIsVisible())
return; return;
...@@ -1308,6 +1328,15 @@ void SelectType::ListBoxOnChange() {} ...@@ -1308,6 +1328,15 @@ void SelectType::ListBoxOnChange() {}
void SelectType::ClearLastOnChangeSelection() {} void SelectType::ClearLastOnChangeSelection() {}
void SelectType::CreateShadowSubtree(ShadowRoot& root) {}
Element& SelectType::InnerElement() const {
NOTREACHED();
// Returning select_ doesn't make sense, but we need to return an element
// to compile this source. This function must not be called.
return *select_;
}
void SelectType::ShowPopup() { void SelectType::ShowPopup() {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -58,6 +58,8 @@ class SelectType : public GarbageCollected<SelectType> { ...@@ -58,6 +58,8 @@ class SelectType : public GarbageCollected<SelectType> {
// This is for ListBoxes. // This is for ListBoxes.
virtual void ClearLastOnChangeSelection(); virtual void ClearLastOnChangeSelection();
virtual void CreateShadowSubtree(ShadowRoot& root);
virtual Element& InnerElement() const;
virtual void ShowPopup(); virtual void ShowPopup();
virtual void HidePopup(); virtual void HidePopup();
virtual void PopupDidHide(); virtual void PopupDidHide();
......
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