layout/svg/nsSVGGradientFrame.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.

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_SVGGRADIENTFRAME_H__
michael@0 7 #define __NS_SVGGRADIENTFRAME_H__
michael@0 8
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "gfxMatrix.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12 #include "nsFrame.h"
michael@0 13 #include "nsLiteralString.h"
michael@0 14 #include "nsSVGPaintServerFrame.h"
michael@0 15
michael@0 16 class gfxPattern;
michael@0 17 class nsIAtom;
michael@0 18 class nsIContent;
michael@0 19 class nsIFrame;
michael@0 20 class nsIPresShell;
michael@0 21 class nsStyleContext;
michael@0 22
michael@0 23 struct gfxRect;
michael@0 24
michael@0 25 namespace mozilla {
michael@0 26 class nsSVGAnimatedTransformList;
michael@0 27
michael@0 28 namespace dom {
michael@0 29 class SVGLinearGradientElement;
michael@0 30 class SVGRadialGradientElement;
michael@0 31 } // namespace dom
michael@0 32 } // namespace mozilla
michael@0 33
michael@0 34 typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
michael@0 35
michael@0 36 /**
michael@0 37 * Gradients can refer to other gradients. We create an nsSVGPaintingProperty
michael@0 38 * with property type nsGkAtoms::href to track the referenced gradient.
michael@0 39 */
michael@0 40 class nsSVGGradientFrame : public nsSVGGradientFrameBase
michael@0 41 {
michael@0 42 protected:
michael@0 43 nsSVGGradientFrame(nsStyleContext* aContext);
michael@0 44
michael@0 45 public:
michael@0 46 NS_DECL_FRAMEARENA_HELPERS
michael@0 47
michael@0 48 // nsSVGPaintServerFrame methods:
michael@0 49 virtual already_AddRefed<gfxPattern>
michael@0 50 GetPaintServerPattern(nsIFrame *aSource,
michael@0 51 const gfxMatrix& aContextMatrix,
michael@0 52 nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
michael@0 53 float aGraphicOpacity,
michael@0 54 const gfxRect *aOverrideBounds) MOZ_OVERRIDE;
michael@0 55
michael@0 56 // nsIFrame interface:
michael@0 57 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
michael@0 58 nsIAtom* aAttribute,
michael@0 59 int32_t aModType) MOZ_OVERRIDE;
michael@0 60
michael@0 61 #ifdef DEBUG_FRAME_DUMP
michael@0 62 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
michael@0 63 {
michael@0 64 return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
michael@0 65 }
michael@0 66 #endif // DEBUG
michael@0 67
michael@0 68 private:
michael@0 69
michael@0 70 // Parse our xlink:href and set up our nsSVGPaintingProperty if we
michael@0 71 // reference another gradient and we don't have a property. Return
michael@0 72 // the referenced gradient's frame if available, null otherwise.
michael@0 73 nsSVGGradientFrame* GetReferencedGradient();
michael@0 74
michael@0 75 // Optionally get a stop frame (returns stop index/count)
michael@0 76 void GetStopFrames(nsTArray<nsIFrame*>* aStopFrames);
michael@0 77
michael@0 78 const mozilla::nsSVGAnimatedTransformList* GetGradientTransformList(
michael@0 79 nsIContent* aDefault);
michael@0 80 // Will be singular for gradientUnits="objectBoundingBox" with an empty bbox.
michael@0 81 gfxMatrix GetGradientTransform(nsIFrame *aSource,
michael@0 82 const gfxRect *aOverrideBounds);
michael@0 83
michael@0 84 protected:
michael@0 85 virtual bool GradientVectorLengthIsZero() = 0;
michael@0 86 virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
michael@0 87
michael@0 88 // Internal methods for handling referenced gradients
michael@0 89 class AutoGradientReferencer;
michael@0 90 nsSVGGradientFrame* GetReferencedGradientIfNotInUse();
michael@0 91
michael@0 92 // Accessors to lookup gradient attributes
michael@0 93 uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault);
michael@0 94 uint16_t GetEnumValue(uint32_t aIndex)
michael@0 95 {
michael@0 96 return GetEnumValue(aIndex, mContent);
michael@0 97 }
michael@0 98 uint16_t GetGradientUnits();
michael@0 99 uint16_t GetSpreadMethod();
michael@0 100
michael@0 101 // Gradient-type-specific lookups since the length values differ between
michael@0 102 // linear and radial gradients
michael@0 103 virtual mozilla::dom::SVGLinearGradientElement * GetLinearGradientWithLength(
michael@0 104 uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault);
michael@0 105 virtual mozilla::dom::SVGRadialGradientElement * GetRadialGradientWithLength(
michael@0 106 uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* aDefault);
michael@0 107
michael@0 108 // The frame our gradient is (currently) being applied to
michael@0 109 nsIFrame* mSource;
michael@0 110
michael@0 111 private:
michael@0 112 // Flag to mark this frame as "in use" during recursive calls along our
michael@0 113 // gradient's reference chain so we can detect reference loops. See:
michael@0 114 // http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
michael@0 115 bool mLoopFlag;
michael@0 116 // Gradients often don't reference other gradients, so here we cache
michael@0 117 // the fact that that isn't happening.
michael@0 118 bool mNoHRefURI;
michael@0 119 };
michael@0 120
michael@0 121
michael@0 122 // -------------------------------------------------------------------------
michael@0 123 // Linear Gradients
michael@0 124 // -------------------------------------------------------------------------
michael@0 125
michael@0 126 typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
michael@0 127
michael@0 128 class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
michael@0 129 {
michael@0 130 friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
michael@0 131 nsStyleContext* aContext);
michael@0 132 protected:
michael@0 133 nsSVGLinearGradientFrame(nsStyleContext* aContext) :
michael@0 134 nsSVGLinearGradientFrameBase(aContext) {}
michael@0 135
michael@0 136 public:
michael@0 137 NS_DECL_FRAMEARENA_HELPERS
michael@0 138
michael@0 139 // nsIFrame interface:
michael@0 140 #ifdef DEBUG
michael@0 141 virtual void Init(nsIContent* aContent,
michael@0 142 nsIFrame* aParent,
michael@0 143 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
michael@0 144 #endif
michael@0 145
michael@0 146 virtual nsIAtom* GetType() const MOZ_OVERRIDE; // frame type: nsGkAtoms::svgLinearGradientFrame
michael@0 147
michael@0 148 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
michael@0 149 nsIAtom* aAttribute,
michael@0 150 int32_t aModType) MOZ_OVERRIDE;
michael@0 151
michael@0 152 #ifdef DEBUG_FRAME_DUMP
michael@0 153 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
michael@0 154 {
michael@0 155 return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
michael@0 156 }
michael@0 157 #endif // DEBUG
michael@0 158
michael@0 159 protected:
michael@0 160 float GetLengthValue(uint32_t aIndex);
michael@0 161 virtual mozilla::dom::SVGLinearGradientElement* GetLinearGradientWithLength(
michael@0 162 uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault) MOZ_OVERRIDE;
michael@0 163 virtual bool GradientVectorLengthIsZero() MOZ_OVERRIDE;
michael@0 164 virtual already_AddRefed<gfxPattern> CreateGradient() MOZ_OVERRIDE;
michael@0 165 };
michael@0 166
michael@0 167 // -------------------------------------------------------------------------
michael@0 168 // Radial Gradients
michael@0 169 // -------------------------------------------------------------------------
michael@0 170
michael@0 171 typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
michael@0 172
michael@0 173 class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
michael@0 174 {
michael@0 175 friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
michael@0 176 nsStyleContext* aContext);
michael@0 177 protected:
michael@0 178 nsSVGRadialGradientFrame(nsStyleContext* aContext) :
michael@0 179 nsSVGRadialGradientFrameBase(aContext) {}
michael@0 180
michael@0 181 public:
michael@0 182 NS_DECL_FRAMEARENA_HELPERS
michael@0 183
michael@0 184 // nsIFrame interface:
michael@0 185 #ifdef DEBUG
michael@0 186 virtual void Init(nsIContent* aContent,
michael@0 187 nsIFrame* aParent,
michael@0 188 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
michael@0 189 #endif
michael@0 190
michael@0 191 virtual nsIAtom* GetType() const MOZ_OVERRIDE; // frame type: nsGkAtoms::svgRadialGradientFrame
michael@0 192
michael@0 193 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
michael@0 194 nsIAtom* aAttribute,
michael@0 195 int32_t aModType) MOZ_OVERRIDE;
michael@0 196
michael@0 197 #ifdef DEBUG_FRAME_DUMP
michael@0 198 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
michael@0 199 {
michael@0 200 return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
michael@0 201 }
michael@0 202 #endif // DEBUG
michael@0 203
michael@0 204 protected:
michael@0 205 float GetLengthValue(uint32_t aIndex);
michael@0 206 float GetLengthValue(uint32_t aIndex, float aDefaultValue);
michael@0 207 float GetLengthValueFromElement(uint32_t aIndex,
michael@0 208 mozilla::dom::SVGRadialGradientElement& aElement);
michael@0 209 virtual mozilla::dom::SVGRadialGradientElement* GetRadialGradientWithLength(
michael@0 210 uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* aDefault) MOZ_OVERRIDE;
michael@0 211 virtual bool GradientVectorLengthIsZero() MOZ_OVERRIDE;
michael@0 212 virtual already_AddRefed<gfxPattern> CreateGradient() MOZ_OVERRIDE;
michael@0 213 };
michael@0 214
michael@0 215 #endif // __NS_SVGGRADIENTFRAME_H__
michael@0 216

mercurial