Bug 1821913 part 1 - Simplify IsAttributeMapped for SVG text r=emilio

Merge sFontSpecificationMap into sTextContentElementsMap since they always exist together

Move IsAttributeMapped for text elements to SVGTextContentElement so all text (text, tspan, textPath) share a single common implementation.

Differential Revision: https://phabricator.services.mozilla.com/D172377
This commit is contained in:
Robert Longson 2023-03-13 16:58:47 +00:00
Родитель 60ec046ced
Коммит 34d680d9dc
21 изменённых файлов: 84 добавлений и 157 удалений

Просмотреть файл

@ -164,14 +164,10 @@ void SVGAElement::UnbindFromTree(bool aNullParent) {
NS_IMETHODIMP_(bool)
SVGAElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sFEFloodMap, sFiltersMap, sGradientStopMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGAElementBase::IsAttributeMapped(name);

Просмотреть файл

@ -33,14 +33,10 @@ NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGDefsElement)
NS_IMETHODIMP_(bool)
SVGDefsElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sFEFloodMap, sFiltersMap, sGradientStopMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGGraphicsElement::IsAttributeMapped(name);

Просмотреть файл

@ -989,19 +989,23 @@ const Element::MappedAttributeEntry SVGElement::sTextContentElementsMap[] = {
// Properties that we don't support are commented out.
// { nsGkAtoms::alignment_baseline },
// { nsGkAtoms::baseline_shift },
{nsGkAtoms::direction}, {nsGkAtoms::dominant_baseline},
{nsGkAtoms::letter_spacing}, {nsGkAtoms::text_anchor},
{nsGkAtoms::text_decoration}, {nsGkAtoms::unicode_bidi},
{nsGkAtoms::white_space}, {nsGkAtoms::word_spacing},
{nsGkAtoms::writing_mode}, {nullptr}};
// PresentationAttributes-FontSpecification
/* static */
const Element::MappedAttributeEntry SVGElement::sFontSpecificationMap[] = {
{nsGkAtoms::font_family}, {nsGkAtoms::font_size},
{nsGkAtoms::font_size_adjust}, {nsGkAtoms::font_stretch},
{nsGkAtoms::font_style}, {nsGkAtoms::font_variant},
{nsGkAtoms::fontWeight}, {nullptr}};
{nsGkAtoms::direction},
{nsGkAtoms::dominant_baseline},
{nsGkAtoms::font_family},
{nsGkAtoms::font_size},
{nsGkAtoms::font_size_adjust},
{nsGkAtoms::font_stretch},
{nsGkAtoms::font_style},
{nsGkAtoms::font_variant},
{nsGkAtoms::fontWeight},
{nsGkAtoms::letter_spacing},
{nsGkAtoms::text_anchor},
{nsGkAtoms::text_decoration},
{nsGkAtoms::unicode_bidi},
{nsGkAtoms::white_space},
{nsGkAtoms::word_spacing},
{nsGkAtoms::writing_mode},
{nullptr}};
// PresentationAttributes-GradientStop
/* static */
@ -1013,7 +1017,7 @@ const Element::MappedAttributeEntry SVGElement::sGradientStopMap[] = {
const Element::MappedAttributeEntry SVGElement::sViewportsMap[] = {
{nsGkAtoms::overflow}, {nsGkAtoms::clip}, {nullptr}};
// PresentationAttributes-Makers
// PresentationAttributes-Markers
/* static */
const Element::MappedAttributeEntry SVGElement::sMarkersMap[] = {
{nsGkAtoms::marker_end},

Просмотреть файл

@ -130,7 +130,6 @@ class SVGElement : public SVGElementBase // nsIContent
static const MappedAttributeEntry sFillStrokeMap[];
static const MappedAttributeEntry sGraphicsMap[];
static const MappedAttributeEntry sTextContentElementsMap[];
static const MappedAttributeEntry sFontSpecificationMap[];
static const MappedAttributeEntry sGradientStopMap[];
static const MappedAttributeEntry sViewportsMap[];
static const MappedAttributeEntry sMarkersMap[];

Просмотреть файл

@ -94,12 +94,14 @@ already_AddRefed<DOMSVGAnimatedString> SVGFilterElement::Href() {
NS_IMETHODIMP_(bool)
SVGFilterElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {
sColorMap, sFEFloodMap,
sFiltersMap, sFontSpecificationMap,
sGradientStopMap, sLightingEffectsMap,
sMarkersMap, sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {sColorMap,
sFEFloodMap,
sFiltersMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGFilterElementBase::IsAttributeMapped(name);
}

Просмотреть файл

@ -111,14 +111,10 @@ bool SVGForeignObjectElement::HasValidDimensions() const {
NS_IMETHODIMP_(bool)
SVGForeignObjectElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sFEFloodMap, sFiltersMap, sGradientStopMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return IsInLengthInfo(name, sLengthInfo) ||
FindAttributeDependence(name, map) ||

Просмотреть файл

@ -32,14 +32,10 @@ NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGGElement)
NS_IMETHODIMP_(bool)
SVGGElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sFEFloodMap, sFiltersMap, sGradientStopMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGGraphicsElement::IsAttributeMapped(name);

Просмотреть файл

@ -123,17 +123,11 @@ void SVGMarkerElement::SetOrientToAngle(DOMSVGAngle& angle, ErrorResult& rv) {
NS_IMETHODIMP_(bool)
SVGMarkerElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap,
sColorMap,
sFillStrokeMap,
sGraphicsMap};
static const MappedAttributeEntry* const map[] = {
sColorMap, sFEFloodMap, sFillStrokeMap,
sFiltersMap, sGradientStopMap, sGraphicsMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGMarkerElementBase::IsAttributeMapped(name);

Просмотреть файл

@ -105,17 +105,11 @@ SVGElement::EnumAttributesInfo SVGMaskElement::GetEnumInfo() {
NS_IMETHODIMP_(bool)
SVGMaskElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sColorMap,
sFEFloodMap,
sFillStrokeMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sGraphicsMap,
sMarkersMap,
sMaskMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sColorMap, sFEFloodMap, sFillStrokeMap,
sFiltersMap, sGradientStopMap, sGraphicsMap,
sMarkersMap, sMaskMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGMaskElementBase::IsAttributeMapped(name);

Просмотреть файл

@ -117,17 +117,11 @@ already_AddRefed<DOMSVGAnimatedString> SVGPatternElement::Href() {
NS_IMETHODIMP_(bool)
SVGPatternElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sColorMap,
sFEFloodMap,
sFillStrokeMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sGraphicsMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sColorMap, sFEFloodMap, sFillStrokeMap,
sFiltersMap, sGradientStopMap, sGraphicsMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGPatternElementBase::IsAttributeMapped(name);

Просмотреть файл

@ -91,14 +91,10 @@ void SVGSwitchElement::RemoveChildNode(nsIContent* aKid, bool aNotify) {
NS_IMETHODIMP_(bool)
SVGSwitchElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sFEFloodMap, sFiltersMap, sGradientStopMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGSwitchElementBase::IsAttributeMapped(name);

Просмотреть файл

@ -37,17 +37,4 @@ SVGElement::LengthAttributesInfo SVGTSpanElement::GetLengthInfo() {
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTSpanElement)
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGTSpanElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {
sColorMap, sFillStrokeMap, sFontSpecificationMap, sGraphicsMap,
sTextContentElementsMap};
return FindAttributeDependence(name, map) ||
SVGTSpanElementBase::IsAttributeMapped(name);
}
} // namespace mozilla::dom

Просмотреть файл

@ -27,8 +27,6 @@ class SVGTSpanElement final : public SVGTSpanElementBase {
public:
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
protected:

Просмотреть файл

@ -187,4 +187,15 @@ int32_t SVGTextContentElement::GetCharNumAtPosition(
return textFrame ? textFrame->GetCharNumAtPosition(this, aPoint) : -1;
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGTextContentElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sTextContentElementsMap};
return FindAttributeDependence(name, map) ||
SVGTextContentElementBase::IsAttributeMapped(name);
}
} // namespace mozilla::dom

Просмотреть файл

@ -50,6 +50,9 @@ class SVGTextContentElement : public SVGTextContentElementBase {
MOZ_CAN_RUN_SCRIPT float GetRotationOfChar(uint32_t charnum, ErrorResult& rv);
MOZ_CAN_RUN_SCRIPT int32_t GetCharNumAtPosition(const DOMPointInit& aPoint);
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
protected:
explicit SVGTextContentElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)

Просмотреть файл

@ -37,16 +37,4 @@ SVGElement::LengthAttributesInfo SVGTextElement::GetLengthInfo() {
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextElement)
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGTextElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sTextContentElementsMap,
sFontSpecificationMap};
return FindAttributeDependence(name, map) ||
SVGTextElementBase::IsAttributeMapped(name);
}
} // namespace mozilla::dom

Просмотреть файл

@ -27,8 +27,6 @@ class SVGTextElement final : public SVGTextElementBase {
public:
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
protected:

Просмотреть файл

@ -105,19 +105,6 @@ already_AddRefed<DOMSVGAnimatedEnumeration> SVGTextPathElement::Side() {
return mEnumAttributes[SIDE].ToDOMAnimatedEnum(this);
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGTextPathElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {
sColorMap, sFillStrokeMap, sFontSpecificationMap, sGraphicsMap,
sTextContentElementsMap};
return FindAttributeDependence(name, map) ||
SVGTextPathElementBase::IsAttributeMapped(name);
}
//----------------------------------------------------------------------
// SVGElement overrides

Просмотреть файл

@ -40,8 +40,6 @@ class SVGTextPathElement final : public SVGTextPathElementBase {
public:
// nsIContent interface
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
SVGAnimatedPathSegList* GetAnimPathSegList() override { return &mPath; }

Просмотреть файл

@ -610,14 +610,10 @@ SVGUseFrame* SVGUseElement::GetFrame() const {
NS_IMETHODIMP_(bool)
SVGUseElement::IsAttributeMapped(const nsAtom* name) const {
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sFEFloodMap, sFiltersMap, sGradientStopMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return name == nsGkAtoms::x || name == nsGkAtoms::y ||
FindAttributeDependence(name, map) ||

Просмотреть файл

@ -87,17 +87,11 @@ SVGViewportElement::IsAttributeMapped(const nsAtom* name) const {
return true;
}
static const MappedAttributeEntry* const map[] = {sColorMap,
sFEFloodMap,
sFillStrokeMap,
sFiltersMap,
sFontSpecificationMap,
sGradientStopMap,
sGraphicsMap,
sLightingEffectsMap,
sMarkersMap,
sTextContentElementsMap,
sViewportsMap};
static const MappedAttributeEntry* const map[] = {
sColorMap, sFEFloodMap, sFillStrokeMap,
sFiltersMap, sGradientStopMap, sGraphicsMap,
sLightingEffectsMap, sMarkersMap, sTextContentElementsMap,
sViewportsMap};
return FindAttributeDependence(name, map) ||
SVGGraphicsElement::IsAttributeMapped(name);