layout/svg/nsSVGOuterSVGFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/svg/nsSVGOuterSVGFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,278 @@
     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 +#ifndef __NS_SVGOUTERSVGFRAME_H__
    1.10 +#define __NS_SVGOUTERSVGFRAME_H__
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsISVGSVGFrame.h"
    1.14 +#include "nsSVGContainerFrame.h"
    1.15 +#include "nsRegion.h"
    1.16 +
    1.17 +class nsSVGForeignObjectFrame;
    1.18 +
    1.19 +////////////////////////////////////////////////////////////////////////
    1.20 +// nsSVGOuterSVGFrame class
    1.21 +
    1.22 +typedef nsSVGDisplayContainerFrame nsSVGOuterSVGFrameBase;
    1.23 +
    1.24 +class nsSVGOuterSVGFrame : public nsSVGOuterSVGFrameBase,
    1.25 +                           public nsISVGSVGFrame
    1.26 +{
    1.27 +  friend nsIFrame*
    1.28 +  NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.29 +protected:
    1.30 +  nsSVGOuterSVGFrame(nsStyleContext* aContext);
    1.31 +
    1.32 +public:
    1.33 +  NS_DECL_QUERYFRAME
    1.34 +  NS_DECL_FRAMEARENA_HELPERS
    1.35 +
    1.36 +#ifdef DEBUG
    1.37 +  ~nsSVGOuterSVGFrame() {
    1.38 +    NS_ASSERTION(!mForeignObjectHash || mForeignObjectHash->Count() == 0,
    1.39 +                 "foreignObject(s) still registered!");
    1.40 +  }
    1.41 +#endif
    1.42 +
    1.43 +  // nsIFrame:
    1.44 +  virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    1.45 +  virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    1.46 +
    1.47 +  virtual mozilla::IntrinsicSize GetIntrinsicSize() MOZ_OVERRIDE;
    1.48 +  virtual nsSize  GetIntrinsicRatio() MOZ_OVERRIDE;
    1.49 +
    1.50 +  virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext,
    1.51 +                             nsSize aCBSize, nscoord aAvailableWidth,
    1.52 +                             nsSize aMargin, nsSize aBorder, nsSize aPadding,
    1.53 +                             uint32_t aFlags) MOZ_OVERRIDE;
    1.54 +
    1.55 +  virtual nsresult Reflow(nsPresContext*          aPresContext,
    1.56 +                          nsHTMLReflowMetrics&     aDesiredSize,
    1.57 +                          const nsHTMLReflowState& aReflowState,
    1.58 +                          nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    1.59 +
    1.60 +  virtual nsresult  DidReflow(nsPresContext*   aPresContext,
    1.61 +                              const nsHTMLReflowState*  aReflowState,
    1.62 +                              nsDidReflowStatus aStatus) MOZ_OVERRIDE;
    1.63 +
    1.64 +  virtual bool UpdateOverflow() MOZ_OVERRIDE;
    1.65 +
    1.66 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.67 +                                const nsRect&           aDirtyRect,
    1.68 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    1.69 +
    1.70 +  virtual void Init(nsIContent*      aContent,
    1.71 +                    nsIFrame*        aParent,
    1.72 +                    nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
    1.73 +
    1.74 +  virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
    1.75 +
    1.76 +  /**
    1.77 +   * Get the "type" of the frame
    1.78 +   *
    1.79 +   * @see nsGkAtoms::svgOuterSVGFrame
    1.80 +   */
    1.81 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    1.82 +
    1.83 +#ifdef DEBUG_FRAME_DUMP
    1.84 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
    1.85 +  {
    1.86 +    return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVG"), aResult);
    1.87 +  }
    1.88 +#endif
    1.89 +
    1.90 +  virtual nsresult  AttributeChanged(int32_t         aNameSpaceID,
    1.91 +                                     nsIAtom*        aAttribute,
    1.92 +                                     int32_t         aModType) MOZ_OVERRIDE;
    1.93 +
    1.94 +  virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
    1.95 +    // Any children must be added to our single anonymous inner frame kid.
    1.96 +    NS_ABORT_IF_FALSE(GetFirstPrincipalChild() &&
    1.97 +                      GetFirstPrincipalChild()->GetType() ==
    1.98 +                        nsGkAtoms::svgOuterSVGAnonChildFrame,
    1.99 +                      "Where is our anonymous child?");
   1.100 +    return GetFirstPrincipalChild()->GetContentInsertionFrame();
   1.101 +  }
   1.102 +
   1.103 +  virtual bool IsSVGTransformed(Matrix *aOwnTransform,
   1.104 +                                Matrix *aFromParentTransform) const MOZ_OVERRIDE {
   1.105 +    // Our anonymous wrapper performs the transforms. We simply
   1.106 +    // return whether we are transformed here but don't apply the transforms
   1.107 +    // themselves.
   1.108 +    return GetFirstPrincipalChild()->IsSVGTransformed();
   1.109 +  }
   1.110 +
   1.111 +  // nsISVGSVGFrame interface:
   1.112 +  virtual void NotifyViewportOrTransformChanged(uint32_t aFlags) MOZ_OVERRIDE;
   1.113 +
   1.114 +  // nsISVGChildFrame methods:
   1.115 +  virtual nsresult PaintSVG(nsRenderingContext* aContext,
   1.116 +                            const nsIntRect *aDirtyRect,
   1.117 +                            nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
   1.118 +
   1.119 +  virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
   1.120 +                                      uint32_t aFlags) MOZ_OVERRIDE;
   1.121 +
   1.122 +  // nsSVGContainerFrame methods:
   1.123 +  virtual gfxMatrix GetCanvasTM(uint32_t aFor,
   1.124 +                                nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
   1.125 +
   1.126 +  /* Methods to allow descendant nsSVGForeignObjectFrame frames to register and
   1.127 +   * unregister themselves with their nearest nsSVGOuterSVGFrame ancestor. This
   1.128 +   * is temporary until display list based invalidation is impleented for SVG.
   1.129 +   * Maintaining a list of our foreignObject descendants allows us to search
   1.130 +   * them for areas that need to be invalidated, without having to also search
   1.131 +   * the SVG frame tree for foreignObjects. This is important so that bug 539356
   1.132 +   * does not slow down SVG in general (only foreignObjects, until bug 614732 is
   1.133 +   * fixed).
   1.134 +   */
   1.135 +  void RegisterForeignObject(nsSVGForeignObjectFrame* aFrame);
   1.136 +  void UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame);
   1.137 +
   1.138 +  virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const MOZ_OVERRIDE {
   1.139 +    // Our anonymous wrapper child must claim our children-only transforms as
   1.140 +    // its own so that our real children (the frames it wraps) are transformed
   1.141 +    // by them, and we must pretend we don't have any children-only transforms
   1.142 +    // so that our anonymous child is _not_ transformed by them.
   1.143 +    return false;
   1.144 +  }
   1.145 +
   1.146 +  /**
   1.147 +   * Return true only if the height is unspecified (defaulting to 100%) or else
   1.148 +   * the height is explicitly set to a percentage value no greater than 100%.
   1.149 +   */
   1.150 +  bool VerticalScrollbarNotNeeded() const;
   1.151 +
   1.152 +  bool IsCallingReflowSVG() const {
   1.153 +    return mCallingReflowSVG;
   1.154 +  }
   1.155 +
   1.156 +  void InvalidateSVG(const nsRegion& aRegion)
   1.157 +  {
   1.158 +    if (!aRegion.IsEmpty()) {
   1.159 +      mInvalidRegion.Or(mInvalidRegion, aRegion);
   1.160 +      InvalidateFrame();
   1.161 +    }
   1.162 +  }
   1.163 +  
   1.164 +  void ClearInvalidRegion() { mInvalidRegion.SetEmpty(); }
   1.165 +
   1.166 +  const nsRegion& GetInvalidRegion() {
   1.167 +    nsRect rect;
   1.168 +    if (!IsInvalid(rect)) {
   1.169 +      mInvalidRegion.SetEmpty();
   1.170 +    }
   1.171 +    return mInvalidRegion;
   1.172 +  }
   1.173 +
   1.174 +  nsRegion FindInvalidatedForeignObjectFrameChildren(nsIFrame* aFrame);
   1.175 +
   1.176 +protected:
   1.177 +
   1.178 +  bool mCallingReflowSVG;
   1.179 +
   1.180 +  /* Returns true if our content is the document element and our document is
   1.181 +   * embedded in an HTML 'object', 'embed' or 'applet' element. Set
   1.182 +   * aEmbeddingFrame to obtain the nsIFrame for the embedding HTML element.
   1.183 +   */
   1.184 +  bool IsRootOfReplacedElementSubDoc(nsIFrame **aEmbeddingFrame = nullptr);
   1.185 +
   1.186 +  /* Returns true if our content is the document element and our document is
   1.187 +   * being used as an image.
   1.188 +   */
   1.189 +  bool IsRootOfImage();
   1.190 +
   1.191 +  // This is temporary until display list based invalidation is implemented for
   1.192 +  // SVG.
   1.193 +  // A hash-set containing our nsSVGForeignObjectFrame descendants. Note we use
   1.194 +  // a hash-set to avoid the O(N^2) behavior we'd get tearing down an SVG frame
   1.195 +  // subtree if we were to use a list (see bug 381285 comment 20).
   1.196 +  nsAutoPtr<nsTHashtable<nsPtrHashKey<nsSVGForeignObjectFrame> > > mForeignObjectHash;
   1.197 +
   1.198 +  nsAutoPtr<gfxMatrix> mCanvasTM;
   1.199 +
   1.200 +  nsRegion mInvalidRegion; 
   1.201 +
   1.202 +  float mFullZoom;
   1.203 +
   1.204 +  bool mViewportInitialized;
   1.205 +  bool mIsRootContent;
   1.206 +};
   1.207 +
   1.208 +////////////////////////////////////////////////////////////////////////
   1.209 +// nsSVGOuterSVGAnonChildFrame class
   1.210 +
   1.211 +typedef nsSVGDisplayContainerFrame nsSVGOuterSVGAnonChildFrameBase;
   1.212 +
   1.213 +/**
   1.214 + * nsSVGOuterSVGFrames have a single direct child that is an instance of this
   1.215 + * class, and which is used to wrap their real child frames. Such anonymous
   1.216 + * wrapper frames created from this class exist because SVG frames need their
   1.217 + * GetPosition() offset to be their offset relative to "user space" (in app
   1.218 + * units) so that they can play nicely with nsDisplayTransform. This is fine
   1.219 + * for all SVG frames except for direct children of an nsSVGOuterSVGFrame,
   1.220 + * since an nsSVGOuterSVGFrame can have CSS border and padding (unlike other
   1.221 + * SVG frames). The direct children can't include the offsets due to any such
   1.222 + * border/padding in their mRects since that would break nsDisplayTransform,
   1.223 + * but not including these offsets would break other parts of the Mozilla code
   1.224 + * that assume a frame's mRect contains its border-box-to-parent-border-box
   1.225 + * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on
   1.226 + * it. Wrapping an nsSVGOuterSVGFrame's children in an instance of this class
   1.227 + * with its GetPosition() set to its nsSVGOuterSVGFrame's border/padding offset
   1.228 + * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy.
   1.229 + *
   1.230 + * The reason that this class inherit from nsSVGDisplayContainerFrame rather
   1.231 + * than simply from nsContainerFrame is so that we can avoid having special
   1.232 + * handling for these inner wrappers in multiple parts of the SVG code. For
   1.233 + * example, the implementations of IsSVGTransformed and GetCanvasTM assume
   1.234 + * nsSVGContainerFrame instances all the way up to the nsSVGOuterSVGFrame.
   1.235 + */
   1.236 +class nsSVGOuterSVGAnonChildFrame
   1.237 +  : public nsSVGOuterSVGAnonChildFrameBase
   1.238 +{
   1.239 +  friend nsIFrame*
   1.240 +  NS_NewSVGOuterSVGAnonChildFrame(nsIPresShell* aPresShell,
   1.241 +                                  nsStyleContext* aContext);
   1.242 +
   1.243 +  nsSVGOuterSVGAnonChildFrame(nsStyleContext* aContext)
   1.244 +    : nsSVGOuterSVGAnonChildFrameBase(aContext)
   1.245 +  {}
   1.246 +
   1.247 +public:
   1.248 +  NS_DECL_FRAMEARENA_HELPERS
   1.249 +
   1.250 +#ifdef DEBUG
   1.251 +  virtual void Init(nsIContent* aContent,
   1.252 +                    nsIFrame* aParent,
   1.253 +                    nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
   1.254 +#endif
   1.255 +
   1.256 +#ifdef DEBUG_FRAME_DUMP
   1.257 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE {
   1.258 +    return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVGAnonChild"), aResult);
   1.259 +  }
   1.260 +#endif
   1.261 +
   1.262 +  /**
   1.263 +   * Get the "type" of the frame
   1.264 +   *
   1.265 +   * @see nsGkAtoms::svgOuterSVGAnonChildFrame
   1.266 +   */
   1.267 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.268 +
   1.269 +  // nsSVGContainerFrame methods:
   1.270 +  virtual gfxMatrix GetCanvasTM(uint32_t aFor,
   1.271 +                                nsIFrame* aTransformRoot) MOZ_OVERRIDE {
   1.272 +    // GetCanvasTM returns the transform from an SVG frame to the frame's
   1.273 +    // nsSVGOuterSVGFrame's content box, so we do not include any x/y offset
   1.274 +    // set on us for any CSS border or padding on our nsSVGOuterSVGFrame.
   1.275 +    return static_cast<nsSVGOuterSVGFrame*>(mParent)->GetCanvasTM(aFor, aTransformRoot);
   1.276 +  }
   1.277 +
   1.278 +  virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const MOZ_OVERRIDE;
   1.279 +};
   1.280 +
   1.281 +#endif

mercurial