From 085b8e6d1d176560dd43e57a2c26318556eb163b Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Mon, 11 Feb 2013 17:22:17 +1100 Subject: [PATCH] Bug 655877 - Part 35: Ensure SVG text is updated when attributes on text content children change. r=jwatt --- layout/svg/nsSVGTextFrame2.cpp | 60 ++++++++++++++++++++++++++++------ layout/svg/nsSVGTextFrame2.h | 4 +-- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/layout/svg/nsSVGTextFrame2.cpp b/layout/svg/nsSVGTextFrame2.cpp index 50b645f9676..0bf1cb26769 100644 --- a/layout/svg/nsSVGTextFrame2.cpp +++ b/layout/svg/nsSVGTextFrame2.cpp @@ -2824,33 +2824,73 @@ nsSVGTextFrame2::GetType() const NS_IMPL_ISUPPORTS1(nsSVGTextFrame2::MutationObserver, nsIMutationObserver) void -nsSVGTextFrame2::MutationObserver::ContentAppended(nsIDocument *aDocument, - nsIContent *aContainer, - nsIContent *aFirstNewContent, +nsSVGTextFrame2::MutationObserver::ContentAppended(nsIDocument* aDocument, + nsIContent* aContainer, + nsIContent* aFirstNewContent, int32_t aNewIndexInContainer) { mFrame->NotifyGlyphMetricsChange(); } void -nsSVGTextFrame2::MutationObserver::ContentInserted(nsIDocument *aDocument, - nsIContent *aContainer, - nsIContent *aChild, +nsSVGTextFrame2::MutationObserver::ContentInserted( + nsIDocument* aDocument, + nsIContent* aContainer, + nsIContent* aChild, int32_t aIndexInContainer) { mFrame->NotifyGlyphMetricsChange(); } void -nsSVGTextFrame2::MutationObserver::ContentRemoved(nsIDocument *aDocument, - nsIContent *aContainer, - nsIContent *aChild, +nsSVGTextFrame2::MutationObserver::ContentRemoved( + nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, int32_t aIndexInContainer, - nsIContent *aPreviousSibling) + nsIContent* aPreviousSibling) { mFrame->NotifyGlyphMetricsChange(); } +void +nsSVGTextFrame2::MutationObserver::AttributeChanged( + nsIDocument* aDocument, + mozilla::dom::Element* aElement, + int32_t aNameSpaceID, + nsIAtom* aAttribute, + int32_t aModType) +{ + if (!aElement->IsSVG()) { + return; + } + + // Attribute changes on this element are handled in + // nsSVGTextFrame2::AttributeChanged. + if (aElement == mFrame->GetContent()) { + return; + } + + // Attributes changes on descendent elements. + if (aElement->Tag() == nsGkAtoms::textPath) { + if (aNameSpaceID == kNameSpaceID_None && + aAttribute == nsGkAtoms::startOffset) { + mFrame->NotifyGlyphMetricsChange(); + } else if (aNameSpaceID == kNameSpaceID_XLink && + aAttribute == nsGkAtoms::href) { + // Blow away our reference, if any + nsIFrame* childElementFrame = aElement->GetPrimaryFrame(); + childElementFrame->Properties().Delete(nsSVGEffects::HrefProperty()); + mFrame->NotifyGlyphMetricsChange(); + } + } else { + if (aNameSpaceID == kNameSpaceID_None && + IsGlyphPositioningAttribute(aAttribute)) { + mFrame->NotifyGlyphMetricsChange(); + } + } +} + NS_IMETHODIMP nsSVGTextFrame2::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, diff --git a/layout/svg/nsSVGTextFrame2.h b/layout/svg/nsSVGTextFrame2.h index e62e2cf32fe..3c6a8850f54 100644 --- a/layout/svg/nsSVGTextFrame2.h +++ b/layout/svg/nsSVGTextFrame2.h @@ -178,9 +178,6 @@ public: NS_IMETHOD Init(nsIContent* aContent, nsIFrame* aParent, nsIFrame* aPrevInFlow); - NS_IMETHOD AttributeChanged(int32_t aNameSpaceID, - nsIAtom* aAttribute, - int32_t aModType); NS_IMETHOD AttributeChanged(int32_t aNamespaceID, nsIAtom* aAttribute, @@ -317,6 +314,7 @@ private: NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED + NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED private: nsSVGTextFrame2* mFrame;