1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/SVGViewFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// Keep in (case-insensitive) order: 1.10 +#include "nsFrame.h" 1.11 +#include "nsGkAtoms.h" 1.12 +#include "nsSVGOuterSVGFrame.h" 1.13 +#include "mozilla/dom/SVGSVGElement.h" 1.14 +#include "mozilla/dom/SVGViewElement.h" 1.15 + 1.16 +typedef nsFrame SVGViewFrameBase; 1.17 + 1.18 +using namespace mozilla::dom; 1.19 + 1.20 +/** 1.21 + * While views are not directly rendered in SVG they can be linked to 1.22 + * and thereby override attributes of an <svg> element via a fragment 1.23 + * identifier. The SVGViewFrame class passes on any attribute changes 1.24 + * the view receives to the overridden <svg> element (if there is one). 1.25 + **/ 1.26 +class SVGViewFrame : public SVGViewFrameBase 1.27 +{ 1.28 + friend nsIFrame* 1.29 + NS_NewSVGViewFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.30 +protected: 1.31 + SVGViewFrame(nsStyleContext* aContext) 1.32 + : SVGViewFrameBase(aContext) 1.33 + { 1.34 + AddStateBits(NS_FRAME_IS_NONDISPLAY); 1.35 + } 1.36 + 1.37 +public: 1.38 + NS_DECL_FRAMEARENA_HELPERS 1.39 + 1.40 +#ifdef DEBUG 1.41 + virtual void Init(nsIContent* aContent, 1.42 + nsIFrame* aParent, 1.43 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.44 +#endif 1.45 + 1.46 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.47 + { 1.48 + return SVGViewFrameBase::IsFrameOfType(aFlags & ~(nsIFrame::eSVG)); 1.49 + } 1.50 + 1.51 +#ifdef DEBUG_FRAME_DUMP 1.52 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE 1.53 + { 1.54 + return MakeFrameName(NS_LITERAL_STRING("SVGView"), aResult); 1.55 + } 1.56 +#endif 1.57 + 1.58 + /** 1.59 + * Get the "type" of the frame 1.60 + * 1.61 + * @see nsGkAtoms::svgFELeafFrame 1.62 + */ 1.63 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.64 + 1.65 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.66 + nsIAtom* aAttribute, 1.67 + int32_t aModType) MOZ_OVERRIDE; 1.68 + 1.69 + virtual bool UpdateOverflow() MOZ_OVERRIDE { 1.70 + // We don't maintain a visual overflow rect 1.71 + return false; 1.72 + } 1.73 +}; 1.74 + 1.75 +nsIFrame* 1.76 +NS_NewSVGViewFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.77 +{ 1.78 + return new (aPresShell) SVGViewFrame(aContext); 1.79 +} 1.80 + 1.81 +NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame) 1.82 + 1.83 +#ifdef DEBUG 1.84 +void 1.85 +SVGViewFrame::Init(nsIContent* aContent, 1.86 + nsIFrame* aParent, 1.87 + nsIFrame* aPrevInFlow) 1.88 +{ 1.89 + NS_ASSERTION(aContent->IsSVG(nsGkAtoms::view), 1.90 + "Content is not an SVG view"); 1.91 + 1.92 + SVGViewFrameBase::Init(aContent, aParent, aPrevInFlow); 1.93 +} 1.94 +#endif /* DEBUG */ 1.95 + 1.96 +nsIAtom * 1.97 +SVGViewFrame::GetType() const 1.98 +{ 1.99 + return nsGkAtoms::svgViewFrame; 1.100 +} 1.101 + 1.102 +nsresult 1.103 +SVGViewFrame::AttributeChanged(int32_t aNameSpaceID, 1.104 + nsIAtom* aAttribute, 1.105 + int32_t aModType) 1.106 +{ 1.107 + // Ignore zoomAndPan as it does not cause the <svg> element to re-render 1.108 + 1.109 + if (aNameSpaceID == kNameSpaceID_None && 1.110 + (aAttribute == nsGkAtoms::preserveAspectRatio || 1.111 + aAttribute == nsGkAtoms::viewBox || 1.112 + aAttribute == nsGkAtoms::viewTarget)) { 1.113 + 1.114 + nsSVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this); 1.115 + NS_ASSERTION(outerSVGFrame->GetContent()->IsSVG(nsGkAtoms::svg), 1.116 + "Expecting an <svg> element"); 1.117 + 1.118 + SVGSVGElement* svgElement = 1.119 + static_cast<SVGSVGElement*>(outerSVGFrame->GetContent()); 1.120 + 1.121 + nsAutoString viewID; 1.122 + mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID); 1.123 + 1.124 + if (svgElement->IsOverriddenBy(viewID)) { 1.125 + // We're the view that's providing overrides, so pretend that the frame 1.126 + // we're overriding was updated. 1.127 + outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType); 1.128 + } 1.129 + } 1.130 + 1.131 + return SVGViewFrameBase::AttributeChanged(aNameSpaceID, 1.132 + aAttribute, aModType); 1.133 +}