Bug 1839223 - Remove nsMappedAttributes. r=smaug

Instead, lazily schedule evaluation of them before styling, much like we
were doing for SVG.

A subtle tweak is that we only remain scheduled while in the document.
This allows us to use the "in document" bit plus the "mapped attributes
dirty" bit to know our scheduled status. It also prevents doing silly
work for disconnected elements, and having to do hashmap lookups on
adoption and node destruction.

Differential Revision: https://phabricator.services.mozilla.com/D181549
This commit is contained in:
Emilio Cobos Álvarez
2023-06-22 17:22:03 +00:00
parent a086a6d3f2
commit a1007b18c6
97 changed files with 1132 additions and 2193 deletions

View File

@@ -53,7 +53,6 @@
#include "nsGkAtoms.h"
#include "nsStyleConsts.h"
#include "nsPresContext.h"
#include "nsMappedAttributes.h"
#include "nsIFormControl.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/HTMLDataListElement.h"
@@ -75,7 +74,7 @@
#include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/MappedDeclarations.h"
#include "mozilla/MappedDeclarationsBuilder.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/TextControlState.h"
#include "mozilla/TextEditor.h"
@@ -4469,30 +4468,32 @@ void HTMLInputElement::HandleTypeChange(FormControlType aNewType,
RecomputeDirectionality(this, aNotify);
}
if (oldType == FormControlType::InputImage) {
// We're no longer an image input. Cancel our image requests, if we have
// any.
CancelImageRequests(aNotify);
// And we should update our mapped attribute mapping function.
mAttrs.UpdateMappedAttrRuleMapper(*this);
} else if (mType == FormControlType::InputImage) {
if (aNotify) {
// We just got switched to be an image input; we should see
// whether we have an image to load;
if (oldType == FormControlType::InputImage ||
mType == FormControlType::InputImage) {
if (oldType == FormControlType::InputImage) {
// We're no longer an image input. Cancel our image requests, if we have
// any.
CancelImageRequests(aNotify);
} else if (aNotify) {
// We just got switched to be an image input; we should see whether we
// have an image to load;
nsAutoString src;
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
if (GetAttr(nsGkAtoms::src, src)) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
// initiated by a user interaction.
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
LoadImage(src, false, aNotify, eImageLoadType_Normal,
mSrcTriggeringPrincipal);
}
}
// And we should update our mapped attribute mapping function.
mAttrs.UpdateMappedAttrRuleMapper(*this);
// We should update our mapped attribute mapping function.
if (mAttrs.HasAttrs() && !mAttrs.IsPendingMappedAttributeEvaluation()) {
mAttrs.InfallibleMarkAsPendingPresAttributeEvaluation();
if (auto* doc = GetComposedDoc()) {
doc->ScheduleForPresAttrEvaluation(this);
}
}
}
if (mType == FormControlType::InputPassword && IsInComposedDoc()) {
@@ -5248,19 +5249,17 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
}
void HTMLInputElement::ImageInputMapAttributesIntoRule(
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
MappedDeclarationsBuilder& aBuilder) {
nsGenericHTMLFormControlElementWithState::MapImageBorderAttributeInto(
aAttributes, aDecls);
aBuilder);
nsGenericHTMLFormControlElementWithState::MapImageMarginAttributeInto(
aAttributes, aDecls);
aBuilder);
nsGenericHTMLFormControlElementWithState::MapImageSizeAttributesInto(
aAttributes, aDecls, MapAspectRatio::Yes);
aBuilder, MapAspectRatio::Yes);
// Images treat align as "float"
nsGenericHTMLFormControlElementWithState::MapImageAlignAttributeInto(
aAttributes, aDecls);
nsGenericHTMLFormControlElementWithState::MapCommonAttributesInto(aAttributes,
aDecls);
aBuilder);
nsGenericHTMLFormControlElementWithState::MapCommonAttributesInto(aBuilder);
}
nsChangeHint HTMLInputElement::GetAttributeChangeHint(const nsAtom* aAttribute,