зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1823757 - use parsed atoms for popovertarget attribute, r=emilio
Use parsed atoms to store popovertarget attributes as more effective mechanism to search for ID match in attr associated elements implementation. Followup from D173337. Differential Revision: https://phabricator.services.mozilla.com/D174786
This commit is contained in:
Родитель
1bc387d5f5
Коммит
7dfe52adaf
|
@ -225,16 +225,28 @@ void DocumentOrShadowRoot::CloneAdoptedSheetsFrom(
|
|||
}
|
||||
}
|
||||
|
||||
Element* DocumentOrShadowRoot::GetElementById(const nsAString& aElementId) {
|
||||
Element* DocumentOrShadowRoot::GetElementById(
|
||||
const nsAString& aElementId) const {
|
||||
if (MOZ_UNLIKELY(aElementId.IsEmpty())) {
|
||||
nsContentUtils::ReportEmptyGetElementByIdArg(AsNode().OwnerDoc());
|
||||
ReportEmptyGetElementByIdArg();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (IdentifierMapEntry* entry = mIdentifierMap.GetEntry(aElementId)) {
|
||||
if (Element* el = entry->GetIdElement()) {
|
||||
return el;
|
||||
}
|
||||
return entry->GetIdElement();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Element* DocumentOrShadowRoot::GetElementById(nsAtom* aElementId) const {
|
||||
if (MOZ_UNLIKELY(aElementId == nsGkAtoms::_empty)) {
|
||||
ReportEmptyGetElementByIdArg();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (IdentifierMapEntry* entry = mIdentifierMap.GetEntry(aElementId)) {
|
||||
return entry->GetIdElement();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -578,7 +590,7 @@ Element* DocumentOrShadowRoot::LookupImageElement(const nsAString& aId) {
|
|||
return entry ? entry->GetImageIdElement() : nullptr;
|
||||
}
|
||||
|
||||
void DocumentOrShadowRoot::ReportEmptyGetElementByIdArg() {
|
||||
void DocumentOrShadowRoot::ReportEmptyGetElementByIdArg() const {
|
||||
nsContentUtils::ReportEmptyGetElementByIdArg(AsNode().OwnerDoc());
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,8 @@ class DocumentOrShadowRoot : public RadioGroupManager {
|
|||
|
||||
void RemoveStyleSheet(StyleSheet&);
|
||||
|
||||
Element* GetElementById(const nsAString& aElementId);
|
||||
Element* GetElementById(const nsAString& aElementId) const;
|
||||
Element* GetElementById(nsAtom* aElementId) const;
|
||||
|
||||
/**
|
||||
* This method returns _all_ the elements in this scope which have id
|
||||
|
@ -201,7 +202,7 @@ class DocumentOrShadowRoot : public RadioGroupManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ReportEmptyGetElementByIdArg();
|
||||
void ReportEmptyGetElementByIdArg() const;
|
||||
|
||||
// Web Animations
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
|
|
|
@ -1727,18 +1727,22 @@ Element* Element::GetAttrAssociatedElement(nsAtom* aAttr) const {
|
|||
}
|
||||
}
|
||||
|
||||
nsAutoString value;
|
||||
if (!GetAttr(aAttr, value)) {
|
||||
const nsAttrValue* value = GetParsedAttr(aAttr);
|
||||
if (!value) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(value->Type() == nsAttrValue::eAtom,
|
||||
"Attribute used for attr associated element must be parsed");
|
||||
|
||||
nsAtom* valueAtom = value->GetAtomValue();
|
||||
if (auto* docOrShadowRoot = GetContainingDocumentOrShadowRoot()) {
|
||||
return docOrShadowRoot->GetElementById(value);
|
||||
return docOrShadowRoot->GetElementById(valueAtom);
|
||||
}
|
||||
|
||||
nsINode* root = SubtreeRoot();
|
||||
for (auto* node = root; node; node = node->GetNextNode(root)) {
|
||||
if (node->HasID() && node->AsContent()->GetID()->Equals(value)) {
|
||||
if (node->HasID() && node->AsContent()->GetID() == valueAtom) {
|
||||
return node->AsElement();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,8 +148,8 @@ bool HTMLButtonElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
aMaybeScriptedPrincipal, aResult);
|
||||
return nsGenericHTMLFormControlElementWithState::ParseAttribute(
|
||||
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
|
||||
}
|
||||
|
||||
bool HTMLButtonElement::IsDisabledForEvents(WidgetEvent* aEvent) {
|
||||
|
|
|
@ -5318,8 +5318,8 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
aMaybeScriptedPrincipal, aResult);
|
||||
return TextControlElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
aMaybeScriptedPrincipal, aResult);
|
||||
}
|
||||
|
||||
void HTMLInputElement::ImageInputMapAttributesIntoRule(
|
||||
|
|
|
@ -1162,8 +1162,8 @@ bool HTMLSelectElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|||
return true;
|
||||
}
|
||||
}
|
||||
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
aMaybeScriptedPrincipal, aResult);
|
||||
return nsGenericHTMLFormControlElementWithState::ParseAttribute(
|
||||
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
|
||||
}
|
||||
|
||||
void HTMLSelectElement::MapAttributesIntoRule(
|
||||
|
|
|
@ -389,8 +389,8 @@ bool HTMLTextAreaElement::ParseAttribute(int32_t aNamespaceID,
|
|||
return true;
|
||||
}
|
||||
}
|
||||
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
aMaybeScriptedPrincipal, aResult);
|
||||
return TextControlElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
aMaybeScriptedPrincipal, aResult);
|
||||
}
|
||||
|
||||
void HTMLTextAreaElement::MapAttributesIntoRule(
|
||||
|
|
|
@ -2785,10 +2785,15 @@ bool nsGenericHTMLFormControlElementWithState::ParseAttribute(
|
|||
int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal, nsAttrValue& aResult) {
|
||||
if (aNamespaceID == kNameSpaceID_None &&
|
||||
aAttribute == nsGkAtoms::popovertargetaction &&
|
||||
StaticPrefs::dom_element_popover_enabled()) {
|
||||
return aResult.ParseEnumValue(aValue, kPopoverTargetActionTable, false,
|
||||
kPopoverTargetActionDefault);
|
||||
if (aAttribute == nsGkAtoms::popovertargetaction) {
|
||||
return aResult.ParseEnumValue(aValue, kPopoverTargetActionTable, false,
|
||||
kPopoverTargetActionDefault);
|
||||
}
|
||||
if (aAttribute == nsGkAtoms::popovertarget) {
|
||||
aResult.ParseAtom(aValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLFormControlElement::ParseAttribute(
|
||||
|
|
|
@ -1233,7 +1233,7 @@ class nsGenericHTMLFormControlElementWithState
|
|||
NS_IMPL_FROMNODE_HELPER(nsGenericHTMLFormControlElementWithState,
|
||||
IsGenericHTMLFormControlElementWithState())
|
||||
|
||||
// nsIContent
|
||||
// Element
|
||||
bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче