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