michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Keep in (case-insensitive) order: michael@0: #include "nsContentUtils.h" michael@0: #include "nsFrame.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsLiteralString.h" michael@0: #include "nsSVGEffects.h" michael@0: #include "nsSVGFilters.h" michael@0: #include "mozilla/dom/SVGFEImageElement.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: michael@0: typedef nsFrame SVGFEImageFrameBase; michael@0: michael@0: class SVGFEImageFrame : public SVGFEImageFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: SVGFEImageFrame(nsStyleContext* aContext) michael@0: : SVGFEImageFrameBase(aContext) michael@0: { michael@0: AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY); michael@0: } michael@0: michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE michael@0: { michael@0: return SVGFEImageFrameBase::IsFrameOfType(aFlags & ~(nsIFrame::eSVG)); michael@0: } michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("SVGFEImage"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgFEImageFrame michael@0: */ michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) MOZ_OVERRIDE; michael@0: michael@0: virtual bool UpdateOverflow() MOZ_OVERRIDE { michael@0: // We don't maintain a visual overflow rect michael@0: return false; michael@0: } michael@0: }; michael@0: michael@0: nsIFrame* michael@0: NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) SVGFEImageFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(SVGFEImageFrame) michael@0: michael@0: /* virtual */ void michael@0: SVGFEImageFrame::DestroyFrom(nsIFrame* aDestructRoot) michael@0: { michael@0: nsCOMPtr imageLoader = michael@0: do_QueryInterface(SVGFEImageFrameBase::mContent); michael@0: michael@0: if (imageLoader) { michael@0: imageLoader->FrameDestroyed(this); michael@0: imageLoader->DecrementVisibleCount(); michael@0: } michael@0: michael@0: SVGFEImageFrameBase::DestroyFrom(aDestructRoot); michael@0: } michael@0: michael@0: void michael@0: SVGFEImageFrame::Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) michael@0: { michael@0: NS_ASSERTION(aContent->IsSVG(nsGkAtoms::feImage), michael@0: "Trying to construct an SVGFEImageFrame for a " michael@0: "content element that doesn't support the right interfaces"); michael@0: michael@0: SVGFEImageFrameBase::Init(aContent, aParent, aPrevInFlow); michael@0: nsCOMPtr imageLoader = michael@0: do_QueryInterface(SVGFEImageFrameBase::mContent); michael@0: michael@0: if (imageLoader) { michael@0: // We assume that feImage's are always visible. michael@0: // Increment the visible count before calling FrameCreated so that michael@0: // FrameCreated will actually track the image correctly. michael@0: imageLoader->IncrementVisibleCount(); michael@0: imageLoader->FrameCreated(this); michael@0: } michael@0: } michael@0: michael@0: nsIAtom * michael@0: SVGFEImageFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::svgFEImageFrame; michael@0: } michael@0: michael@0: nsresult michael@0: SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) michael@0: { michael@0: SVGFEImageElement *element = static_cast(mContent); michael@0: if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) { michael@0: nsSVGEffects::InvalidateRenderingObservers(this); michael@0: } michael@0: if (aNameSpaceID == kNameSpaceID_XLink && michael@0: aAttribute == nsGkAtoms::href) { michael@0: michael@0: // Prevent setting image.src by exiting early michael@0: if (nsContentUtils::IsImageSrcSetDisabled()) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: if (element->mStringAttributes[SVGFEImageElement::HREF].IsExplicitlySet()) { michael@0: element->LoadSVGImage(true, true); michael@0: } else { michael@0: element->CancelImageRequests(true); michael@0: } michael@0: } michael@0: michael@0: return SVGFEImageFrameBase::AttributeChanged(aNameSpaceID, michael@0: aAttribute, aModType); michael@0: }