layout/svg/nsSVGOuterSVGFrame.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef __NS_SVGOUTERSVGFRAME_H__
     7 #define __NS_SVGOUTERSVGFRAME_H__
     9 #include "mozilla/Attributes.h"
    10 #include "nsISVGSVGFrame.h"
    11 #include "nsSVGContainerFrame.h"
    12 #include "nsRegion.h"
    14 class nsSVGForeignObjectFrame;
    16 ////////////////////////////////////////////////////////////////////////
    17 // nsSVGOuterSVGFrame class
    19 typedef nsSVGDisplayContainerFrame nsSVGOuterSVGFrameBase;
    21 class nsSVGOuterSVGFrame : public nsSVGOuterSVGFrameBase,
    22                            public nsISVGSVGFrame
    23 {
    24   friend nsIFrame*
    25   NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    26 protected:
    27   nsSVGOuterSVGFrame(nsStyleContext* aContext);
    29 public:
    30   NS_DECL_QUERYFRAME
    31   NS_DECL_FRAMEARENA_HELPERS
    33 #ifdef DEBUG
    34   ~nsSVGOuterSVGFrame() {
    35     NS_ASSERTION(!mForeignObjectHash || mForeignObjectHash->Count() == 0,
    36                  "foreignObject(s) still registered!");
    37   }
    38 #endif
    40   // nsIFrame:
    41   virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    42   virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    44   virtual mozilla::IntrinsicSize GetIntrinsicSize() MOZ_OVERRIDE;
    45   virtual nsSize  GetIntrinsicRatio() MOZ_OVERRIDE;
    47   virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext,
    48                              nsSize aCBSize, nscoord aAvailableWidth,
    49                              nsSize aMargin, nsSize aBorder, nsSize aPadding,
    50                              uint32_t aFlags) MOZ_OVERRIDE;
    52   virtual nsresult Reflow(nsPresContext*          aPresContext,
    53                           nsHTMLReflowMetrics&     aDesiredSize,
    54                           const nsHTMLReflowState& aReflowState,
    55                           nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    57   virtual nsresult  DidReflow(nsPresContext*   aPresContext,
    58                               const nsHTMLReflowState*  aReflowState,
    59                               nsDidReflowStatus aStatus) MOZ_OVERRIDE;
    61   virtual bool UpdateOverflow() MOZ_OVERRIDE;
    63   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    64                                 const nsRect&           aDirtyRect,
    65                                 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    67   virtual void Init(nsIContent*      aContent,
    68                     nsIFrame*        aParent,
    69                     nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
    71   virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
    73   /**
    74    * Get the "type" of the frame
    75    *
    76    * @see nsGkAtoms::svgOuterSVGFrame
    77    */
    78   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    80 #ifdef DEBUG_FRAME_DUMP
    81   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
    82   {
    83     return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVG"), aResult);
    84   }
    85 #endif
    87   virtual nsresult  AttributeChanged(int32_t         aNameSpaceID,
    88                                      nsIAtom*        aAttribute,
    89                                      int32_t         aModType) MOZ_OVERRIDE;
    91   virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
    92     // Any children must be added to our single anonymous inner frame kid.
    93     NS_ABORT_IF_FALSE(GetFirstPrincipalChild() &&
    94                       GetFirstPrincipalChild()->GetType() ==
    95                         nsGkAtoms::svgOuterSVGAnonChildFrame,
    96                       "Where is our anonymous child?");
    97     return GetFirstPrincipalChild()->GetContentInsertionFrame();
    98   }
   100   virtual bool IsSVGTransformed(Matrix *aOwnTransform,
   101                                 Matrix *aFromParentTransform) const MOZ_OVERRIDE {
   102     // Our anonymous wrapper performs the transforms. We simply
   103     // return whether we are transformed here but don't apply the transforms
   104     // themselves.
   105     return GetFirstPrincipalChild()->IsSVGTransformed();
   106   }
   108   // nsISVGSVGFrame interface:
   109   virtual void NotifyViewportOrTransformChanged(uint32_t aFlags) MOZ_OVERRIDE;
   111   // nsISVGChildFrame methods:
   112   virtual nsresult PaintSVG(nsRenderingContext* aContext,
   113                             const nsIntRect *aDirtyRect,
   114                             nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
   116   virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
   117                                       uint32_t aFlags) MOZ_OVERRIDE;
   119   // nsSVGContainerFrame methods:
   120   virtual gfxMatrix GetCanvasTM(uint32_t aFor,
   121                                 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
   123   /* Methods to allow descendant nsSVGForeignObjectFrame frames to register and
   124    * unregister themselves with their nearest nsSVGOuterSVGFrame ancestor. This
   125    * is temporary until display list based invalidation is impleented for SVG.
   126    * Maintaining a list of our foreignObject descendants allows us to search
   127    * them for areas that need to be invalidated, without having to also search
   128    * the SVG frame tree for foreignObjects. This is important so that bug 539356
   129    * does not slow down SVG in general (only foreignObjects, until bug 614732 is
   130    * fixed).
   131    */
   132   void RegisterForeignObject(nsSVGForeignObjectFrame* aFrame);
   133   void UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame);
   135   virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const MOZ_OVERRIDE {
   136     // Our anonymous wrapper child must claim our children-only transforms as
   137     // its own so that our real children (the frames it wraps) are transformed
   138     // by them, and we must pretend we don't have any children-only transforms
   139     // so that our anonymous child is _not_ transformed by them.
   140     return false;
   141   }
   143   /**
   144    * Return true only if the height is unspecified (defaulting to 100%) or else
   145    * the height is explicitly set to a percentage value no greater than 100%.
   146    */
   147   bool VerticalScrollbarNotNeeded() const;
   149   bool IsCallingReflowSVG() const {
   150     return mCallingReflowSVG;
   151   }
   153   void InvalidateSVG(const nsRegion& aRegion)
   154   {
   155     if (!aRegion.IsEmpty()) {
   156       mInvalidRegion.Or(mInvalidRegion, aRegion);
   157       InvalidateFrame();
   158     }
   159   }
   161   void ClearInvalidRegion() { mInvalidRegion.SetEmpty(); }
   163   const nsRegion& GetInvalidRegion() {
   164     nsRect rect;
   165     if (!IsInvalid(rect)) {
   166       mInvalidRegion.SetEmpty();
   167     }
   168     return mInvalidRegion;
   169   }
   171   nsRegion FindInvalidatedForeignObjectFrameChildren(nsIFrame* aFrame);
   173 protected:
   175   bool mCallingReflowSVG;
   177   /* Returns true if our content is the document element and our document is
   178    * embedded in an HTML 'object', 'embed' or 'applet' element. Set
   179    * aEmbeddingFrame to obtain the nsIFrame for the embedding HTML element.
   180    */
   181   bool IsRootOfReplacedElementSubDoc(nsIFrame **aEmbeddingFrame = nullptr);
   183   /* Returns true if our content is the document element and our document is
   184    * being used as an image.
   185    */
   186   bool IsRootOfImage();
   188   // This is temporary until display list based invalidation is implemented for
   189   // SVG.
   190   // A hash-set containing our nsSVGForeignObjectFrame descendants. Note we use
   191   // a hash-set to avoid the O(N^2) behavior we'd get tearing down an SVG frame
   192   // subtree if we were to use a list (see bug 381285 comment 20).
   193   nsAutoPtr<nsTHashtable<nsPtrHashKey<nsSVGForeignObjectFrame> > > mForeignObjectHash;
   195   nsAutoPtr<gfxMatrix> mCanvasTM;
   197   nsRegion mInvalidRegion; 
   199   float mFullZoom;
   201   bool mViewportInitialized;
   202   bool mIsRootContent;
   203 };
   205 ////////////////////////////////////////////////////////////////////////
   206 // nsSVGOuterSVGAnonChildFrame class
   208 typedef nsSVGDisplayContainerFrame nsSVGOuterSVGAnonChildFrameBase;
   210 /**
   211  * nsSVGOuterSVGFrames have a single direct child that is an instance of this
   212  * class, and which is used to wrap their real child frames. Such anonymous
   213  * wrapper frames created from this class exist because SVG frames need their
   214  * GetPosition() offset to be their offset relative to "user space" (in app
   215  * units) so that they can play nicely with nsDisplayTransform. This is fine
   216  * for all SVG frames except for direct children of an nsSVGOuterSVGFrame,
   217  * since an nsSVGOuterSVGFrame can have CSS border and padding (unlike other
   218  * SVG frames). The direct children can't include the offsets due to any such
   219  * border/padding in their mRects since that would break nsDisplayTransform,
   220  * but not including these offsets would break other parts of the Mozilla code
   221  * that assume a frame's mRect contains its border-box-to-parent-border-box
   222  * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on
   223  * it. Wrapping an nsSVGOuterSVGFrame's children in an instance of this class
   224  * with its GetPosition() set to its nsSVGOuterSVGFrame's border/padding offset
   225  * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy.
   226  *
   227  * The reason that this class inherit from nsSVGDisplayContainerFrame rather
   228  * than simply from nsContainerFrame is so that we can avoid having special
   229  * handling for these inner wrappers in multiple parts of the SVG code. For
   230  * example, the implementations of IsSVGTransformed and GetCanvasTM assume
   231  * nsSVGContainerFrame instances all the way up to the nsSVGOuterSVGFrame.
   232  */
   233 class nsSVGOuterSVGAnonChildFrame
   234   : public nsSVGOuterSVGAnonChildFrameBase
   235 {
   236   friend nsIFrame*
   237   NS_NewSVGOuterSVGAnonChildFrame(nsIPresShell* aPresShell,
   238                                   nsStyleContext* aContext);
   240   nsSVGOuterSVGAnonChildFrame(nsStyleContext* aContext)
   241     : nsSVGOuterSVGAnonChildFrameBase(aContext)
   242   {}
   244 public:
   245   NS_DECL_FRAMEARENA_HELPERS
   247 #ifdef DEBUG
   248   virtual void Init(nsIContent* aContent,
   249                     nsIFrame* aParent,
   250                     nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
   251 #endif
   253 #ifdef DEBUG_FRAME_DUMP
   254   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE {
   255     return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVGAnonChild"), aResult);
   256   }
   257 #endif
   259   /**
   260    * Get the "type" of the frame
   261    *
   262    * @see nsGkAtoms::svgOuterSVGAnonChildFrame
   263    */
   264   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   266   // nsSVGContainerFrame methods:
   267   virtual gfxMatrix GetCanvasTM(uint32_t aFor,
   268                                 nsIFrame* aTransformRoot) MOZ_OVERRIDE {
   269     // GetCanvasTM returns the transform from an SVG frame to the frame's
   270     // nsSVGOuterSVGFrame's content box, so we do not include any x/y offset
   271     // set on us for any CSS border or padding on our nsSVGOuterSVGFrame.
   272     return static_cast<nsSVGOuterSVGFrame*>(mParent)->GetCanvasTM(aFor, aTransformRoot);
   273   }
   275   virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const MOZ_OVERRIDE;
   276 };
   278 #endif

mercurial