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 "nsFrame.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsSVGOuterSVGFrame.h" michael@0: #include "mozilla/dom/SVGSVGElement.h" michael@0: #include "mozilla/dom/SVGViewElement.h" michael@0: michael@0: typedef nsFrame SVGViewFrameBase; michael@0: michael@0: using namespace mozilla::dom; michael@0: michael@0: /** michael@0: * While views are not directly rendered in SVG they can be linked to michael@0: * and thereby override attributes of an element via a fragment michael@0: * identifier. The SVGViewFrame class passes on any attribute changes michael@0: * the view receives to the overridden element (if there is one). michael@0: **/ michael@0: class SVGViewFrame : public SVGViewFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGViewFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: SVGViewFrame(nsStyleContext* aContext) michael@0: : SVGViewFrameBase(aContext) michael@0: { michael@0: AddStateBits(NS_FRAME_IS_NONDISPLAY); michael@0: } michael@0: michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: #ifdef DEBUG michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE michael@0: { michael@0: return SVGViewFrameBase::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("SVGView"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgFELeafFrame 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_NewSVGViewFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) SVGViewFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame) michael@0: michael@0: #ifdef DEBUG michael@0: void michael@0: SVGViewFrame::Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) michael@0: { michael@0: NS_ASSERTION(aContent->IsSVG(nsGkAtoms::view), michael@0: "Content is not an SVG view"); michael@0: michael@0: SVGViewFrameBase::Init(aContent, aParent, aPrevInFlow); michael@0: } michael@0: #endif /* DEBUG */ michael@0: michael@0: nsIAtom * michael@0: SVGViewFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::svgViewFrame; michael@0: } michael@0: michael@0: nsresult michael@0: SVGViewFrame::AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) michael@0: { michael@0: // Ignore zoomAndPan as it does not cause the element to re-render michael@0: michael@0: if (aNameSpaceID == kNameSpaceID_None && michael@0: (aAttribute == nsGkAtoms::preserveAspectRatio || michael@0: aAttribute == nsGkAtoms::viewBox || michael@0: aAttribute == nsGkAtoms::viewTarget)) { michael@0: michael@0: nsSVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this); michael@0: NS_ASSERTION(outerSVGFrame->GetContent()->IsSVG(nsGkAtoms::svg), michael@0: "Expecting an element"); michael@0: michael@0: SVGSVGElement* svgElement = michael@0: static_cast(outerSVGFrame->GetContent()); michael@0: michael@0: nsAutoString viewID; michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID); michael@0: michael@0: if (svgElement->IsOverriddenBy(viewID)) { michael@0: // We're the view that's providing overrides, so pretend that the frame michael@0: // we're overriding was updated. michael@0: outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType); michael@0: } michael@0: } michael@0: michael@0: return SVGViewFrameBase::AttributeChanged(aNameSpaceID, michael@0: aAttribute, aModType); michael@0: }