Skip to content

Commit a8ba5eb

Browse files
committed
Add hasDataList() method to HTMLInputElement.
Need the bug URL (OOPS!). Reviewed by NOBODY (OOPS!). This reserves list() for use in bindings, and dataList() for internal use. Once referenceTarget is implemented, dataList() will be used to retrieve the list-associated element, which may be inside a shadow root, while list() may return null (see WICG/webcomponents#1072 for discussion). hasDataList() checks whether a list-associated element is present, without risking leaking shadow root internals inappropriately. * Source/WebCore/html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::list const): (WebCore::HTMLInputElement::hasDataList const): * Source/WebCore/html/HTMLInputElement.h: * Source/WebCore/html/TextFieldInputType.cpp: (WebCore::TextFieldInputType::handleClickEvent): (WebCore::TextFieldInputType::showPicker): (WebCore::TextFieldInputType::createShadowSubtree): (WebCore::TextFieldInputType::didSetValueByUserEdit): (WebCore::TextFieldInputType::dataListMayHaveChanged): (WebCore::TextFieldInputType::dataListButtonElementWasClicked): * Source/WebCore/html/shadow/SliderThumbElement.cpp: (WebCore::RenderSliderContainer::computeLogicalHeight const): * Source/WebCore/rendering/RenderTheme.cpp: (WebCore::RenderTheme::hasListButton const):
1 parent 22f9653 commit a8ba5eb

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

Source/WebCore/accessibility/AccessibilityObject.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -3279,16 +3279,8 @@ String AccessibilityObject::popupValue() const
32793279

32803280
bool AccessibilityObject::hasDatalist() const
32813281
{
3282-
auto datalistId = getAttribute(listAttr);
3283-
if (datalistId.isEmpty())
3284-
return false;
3285-
3286-
auto element = this->element();
3287-
if (!element)
3288-
return false;
3289-
3290-
auto datalist = element->treeScope().getElementById(datalistId);
3291-
return is<HTMLDataListElement>(datalist);
3282+
RefPtr input = dynamicDowncast<HTMLInputElement>(element());
3283+
return input && input->hasDataList();
32923284
}
32933285

32943286
bool AccessibilityObject::supportsSetSize() const

Source/WebCore/html/HTMLInputElement.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,11 @@ RefPtr<HTMLElement> HTMLInputElement::list() const
18881888
return dataList();
18891889
}
18901890

1891+
bool HTMLInputElement::hasDataList() const
1892+
{
1893+
return dataList();
1894+
}
1895+
18911896
RefPtr<HTMLDataListElement> HTMLInputElement::dataList() const
18921897
{
18931898
if (!m_hasNonEmptyList || !m_inputType->shouldRespectListAttribute())

Source/WebCore/html/HTMLInputElement.h

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class HTMLInputElement final : public HTMLTextFormControlElement {
288288
bool willRespondToMouseClickEventsWithEditability(Editability) const final;
289289

290290
WEBCORE_EXPORT bool isFocusingWithDataListDropdown() const;
291+
bool hasDataList() const;
291292
RefPtr<HTMLDataListElement> dataList() const;
292293
void dataListMayHaveChanged();
293294

Source/WebCore/html/TextFieldInputType.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChange
182182

183183
void TextFieldInputType::handleClickEvent(MouseEvent&)
184184
{
185-
if (element()->focused() && element()->list())
185+
if (element()->focused() && element()->hasDataList())
186186
displaySuggestions(DataListSuggestionActivationType::ControlClicked);
187187
}
188188

189189
void TextFieldInputType::showPicker()
190190
{
191191
#if !PLATFORM(IOS_FAMILY)
192-
if (element()->list())
192+
if (element()->hasDataList())
193193
displaySuggestions(DataListSuggestionActivationType::ControlClicked);
194194
#endif
195195
}
@@ -327,7 +327,7 @@ void TextFieldInputType::createShadowSubtree()
327327
bool shouldHaveSpinButton = this->shouldHaveSpinButton();
328328
bool shouldHaveCapsLockIndicator = this->shouldHaveCapsLockIndicator();
329329
bool shouldDrawAutoFillButton = this->shouldDrawAutoFillButton();
330-
bool hasDataList = element()->list();
330+
bool hasDataList = element()->hasDataList();
331331
bool createsContainer = shouldHaveSpinButton || shouldHaveCapsLockIndicator || shouldDrawAutoFillButton || hasDataList || needsContainer();
332332

333333
Ref innerText = TextControlInnerTextElement::create(document, element()->isInnerTextElementEditable());
@@ -691,7 +691,7 @@ void TextFieldInputType::didSetValueByUserEdit()
691691
return;
692692
if (RefPtr frame = element()->document().frame())
693693
frame->editor().textDidChangeInTextField(*element());
694-
if (element()->list())
694+
if (element()->hasDataList())
695695
displaySuggestions(DataListSuggestionActivationType::TextChanged);
696696
}
697697

@@ -884,7 +884,7 @@ void TextFieldInputType::dataListMayHaveChanged()
884884
if (!element())
885885
return;
886886
m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, element()->list() ? CSSValueBlock : CSSValueNone, IsImportant::Yes);
887-
if (element()->list() && element()->focused())
887+
if (element()->hasDataList() && element()->focused())
888888
displaySuggestions(DataListSuggestionActivationType::DataListMayHaveChanged);
889889
}
890890

@@ -896,7 +896,7 @@ HTMLElement* TextFieldInputType::dataListButtonElement() const
896896
void TextFieldInputType::dataListButtonElementWasClicked()
897897
{
898898
Ref<HTMLInputElement> input(*element());
899-
if (input->list()) {
899+
if (input->hasDataList()) {
900900
m_isFocusingWithDataListDropdown = true;
901901
unsigned max = visibleValue().length();
902902
input->setSelectionRange(max, max);

Source/WebCore/html/shadow/SliderThumbElement.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ RenderBox::LogicalExtentComputedValues RenderSliderContainer::computeLogicalHeig
111111
auto& input = downcast<HTMLInputElement>(*element()->shadowHost());
112112
bool isVertical = hasVerticalAppearance(input);
113113

114-
if (input.renderer()->isRenderSlider() && !isVertical && input.list()) {
114+
if (input.renderer()->isRenderSlider() && !isVertical && input.hasDataList()) {
115115
int offsetFromCenter = theme().sliderTickOffsetFromTrackCenter();
116116
LayoutUnit trackHeight;
117117
if (offsetFromCenter < 0)

Source/WebCore/rendering/RenderTheme.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ bool RenderTheme::isDefault(const RenderObject& o) const
12241224
bool RenderTheme::hasListButton(const RenderObject& renderer) const
12251225
{
12261226
RefPtr input = dynamicDowncast<HTMLInputElement>(renderer.generatingNode());
1227-
return input && input->list();
1227+
return input && input->hasDataList();
12281228
}
12291229

12301230
bool RenderTheme::hasListButtonPressed(const RenderObject& renderer) const

0 commit comments

Comments
 (0)