@@ -2327,9 +2327,9 @@ ExplicitlySetAttrElementsMap* Element::explicitlySetAttrElementsMapIfExists() co
2327
2327
return hasRareData () ? &elementRareData ()->explicitlySetAttrElementsMap () : nullptr ;
2328
2328
}
2329
2329
2330
- static RefPtr<Element> getElementByIdIncludingDisconnected (const Element& startElement, const AtomString& id)
2330
+ static RefPtr<Element> getElementByIdInternalIncludingDisconnected (const Element& startElement, const AtomString& id)
2331
2331
{
2332
- if (id.isEmpty ())
2332
+ if (id.isNull () || id. isEmpty ())
2333
2333
return nullptr ;
2334
2334
2335
2335
if (LIKELY (startElement.isInTreeScope ()))
@@ -2349,26 +2349,34 @@ static RefPtr<Element> getElementByIdIncludingDisconnected(const Element& startE
2349
2349
return nullptr ;
2350
2350
}
2351
2351
2352
- RefPtr<Element> Element::getElementAttribute (const QualifiedName& attributeName) const
2352
+ RefPtr<Element> Element::getElementForAttributeInternal (const QualifiedName& attributeName) const
2353
2353
{
2354
- ASSERT (isElementReflectionAttribute (document ().settings (), attributeName));
2354
+ RefPtr<Element> element = nullptr ;
2355
+ bool hasExplicitlySetElement = false ;
2355
2356
2356
2357
if (auto * map = explicitlySetAttrElementsMapIfExists ()) {
2357
2358
auto it = map->find (attributeName);
2358
2359
if (it != map->end ()) {
2359
2360
ASSERT (it->value .size () == 1 );
2360
- RefPtr element = it-> value [ 0 ]. get () ;
2361
- if (element && isDescendantOrShadowDescendantOf (element-> rootNode ()))
2362
- return element;
2363
- return nullptr ;
2361
+ hasExplicitlySetElement = true ;
2362
+ RefPtr explicitlySetElement = it-> value [ 0 ]. get ();
2363
+ if (explicitlySetElement && isDescendantOrShadowDescendantOf (explicitlySetElement-> rootNode ()))
2364
+ element = explicitlySetElement ;
2364
2365
}
2365
2366
}
2367
+
2368
+ if (!hasExplicitlySetElement) {
2369
+ const AtomString& id = getAttribute (attributeName);
2370
+ element = getElementByIdInternalIncludingDisconnected (*this , id);
2371
+ }
2366
2372
2367
- auto id = getAttribute (attributeName);
2368
- if (id.isNull ())
2369
- return nullptr ;
2373
+ return element;
2374
+ }
2370
2375
2371
- return getElementByIdIncludingDisconnected (*this , id);
2376
+ RefPtr<Element> Element::getElementAttributeForBindings (const QualifiedName& attributeName) const
2377
+ {
2378
+ ASSERT (isElementReflectionAttribute (document ().settings (), attributeName));
2379
+ return getElementForAttributeInternal (attributeName);
2372
2380
}
2373
2381
2374
2382
void Element::setElementAttribute (const QualifiedName& attributeName, Element* element)
@@ -2390,13 +2398,16 @@ void Element::setElementAttribute(const QualifiedName& attributeName, Element* e
2390
2398
cache->updateRelations (*this , attributeName);
2391
2399
}
2392
2400
2393
- std::optional<Vector<Ref<Element>>> Element::getElementsArrayAttribute (const QualifiedName& attributeName) const
2401
+ std::optional<Vector<Ref<Element>>> Element::getElementsArrayForAttributeInternal (const QualifiedName& attributeName) const
2394
2402
{
2395
- ASSERT (isElementsArrayReflectionAttribute (attributeName));
2403
+ std::optional<Vector<Ref<Element>>> elements;
2404
+ bool hasExplicitlySetElements = false ;
2396
2405
2397
2406
if (auto * map = explicitlySetAttrElementsMapIfExists ()) {
2398
- if (auto it = map->find (attributeName); it != map->end ()) {
2399
- return compactMap (it->value , [&](auto & weakElement) -> std::optional<Ref<Element>> {
2407
+ auto it = map->find (attributeName);
2408
+ if (it != map->end ()) {
2409
+ hasExplicitlySetElements = true ;
2410
+ elements = compactMap (it->value , [&](auto & weakElement) -> std::optional<Ref<Element>> {
2400
2411
RefPtr element = weakElement.get ();
2401
2412
if (element && isDescendantOrShadowDescendantOf (element->rootNode ()))
2402
2413
return element.releaseNonNull ();
@@ -2405,17 +2416,24 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayAttribute(const Qua
2405
2416
}
2406
2417
}
2407
2418
2408
- auto attr = attributeName;
2409
- if (attr == HTMLNames::aria_labelledbyAttr && !hasAttribute (HTMLNames::aria_labelledbyAttr) && hasAttribute (HTMLNames::aria_labeledbyAttr))
2410
- attr = HTMLNames::aria_labeledbyAttr;
2419
+ if (!hasExplicitlySetElements) {
2420
+ auto attr = attributeName;
2421
+ if (attr == HTMLNames::aria_labelledbyAttr && !hasAttribute (HTMLNames::aria_labelledbyAttr) && hasAttribute (HTMLNames::aria_labeledbyAttr))
2422
+ attr = HTMLNames::aria_labeledbyAttr;
2411
2423
2412
- if (!hasAttribute (attr))
2413
- return std::nullopt;
2424
+ SpaceSplitString ids (getAttribute (attr), SpaceSplitString::ShouldFoldCase::No);
2425
+ elements = compactMap (ids, [&](auto & id) {
2426
+ return getElementByIdInternalIncludingDisconnected (*this , id);
2427
+ });
2428
+ }
2414
2429
2415
- SpaceSplitString ids (getAttribute (attr), SpaceSplitString::ShouldFoldCase::No);
2416
- return WTF::compactMap (ids, [&](auto & id) {
2417
- return getElementByIdIncludingDisconnected (*this , id);
2418
- });
2430
+ return elements;
2431
+ }
2432
+
2433
+ std::optional<Vector<Ref<Element>>> Element::getElementsArrayAttributeForBindings (const QualifiedName& attributeName) const
2434
+ {
2435
+ ASSERT (isElementsArrayReflectionAttribute (attributeName));
2436
+ return getElementsArrayForAttributeInternal (attributeName);
2419
2437
}
2420
2438
2421
2439
void Element::setElementsArrayAttribute (const QualifiedName& attributeName, std::optional<Vector<Ref<Element>>>&& elements)
0 commit comments