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 | // Main header first: |
michael@0 | 7 | #include "nsSVGInnerSVGFrame.h" |
michael@0 | 8 | |
michael@0 | 9 | // Keep others in (case-insensitive) order: |
michael@0 | 10 | #include "gfxContext.h" |
michael@0 | 11 | #include "nsIFrame.h" |
michael@0 | 12 | #include "nsISVGChildFrame.h" |
michael@0 | 13 | #include "nsRenderingContext.h" |
michael@0 | 14 | #include "nsSVGContainerFrame.h" |
michael@0 | 15 | #include "nsSVGEffects.h" |
michael@0 | 16 | #include "nsSVGIntegrationUtils.h" |
michael@0 | 17 | #include "mozilla/dom/SVGSVGElement.h" |
michael@0 | 18 | |
michael@0 | 19 | using namespace mozilla; |
michael@0 | 20 | using namespace mozilla::dom; |
michael@0 | 21 | |
michael@0 | 22 | nsIFrame* |
michael@0 | 23 | NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 24 | { |
michael@0 | 25 | return new (aPresShell) nsSVGInnerSVGFrame(aContext); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | NS_IMPL_FRAMEARENA_HELPERS(nsSVGInnerSVGFrame) |
michael@0 | 29 | |
michael@0 | 30 | //---------------------------------------------------------------------- |
michael@0 | 31 | // nsIFrame methods |
michael@0 | 32 | |
michael@0 | 33 | NS_QUERYFRAME_HEAD(nsSVGInnerSVGFrame) |
michael@0 | 34 | NS_QUERYFRAME_ENTRY(nsSVGInnerSVGFrame) |
michael@0 | 35 | NS_QUERYFRAME_ENTRY(nsISVGSVGFrame) |
michael@0 | 36 | NS_QUERYFRAME_TAIL_INHERITING(nsSVGInnerSVGFrameBase) |
michael@0 | 37 | |
michael@0 | 38 | #ifdef DEBUG |
michael@0 | 39 | void |
michael@0 | 40 | nsSVGInnerSVGFrame::Init(nsIContent* aContent, |
michael@0 | 41 | nsIFrame* aParent, |
michael@0 | 42 | nsIFrame* aPrevInFlow) |
michael@0 | 43 | { |
michael@0 | 44 | NS_ASSERTION(aContent->IsSVG(nsGkAtoms::svg), |
michael@0 | 45 | "Content is not an SVG 'svg' element!"); |
michael@0 | 46 | |
michael@0 | 47 | nsSVGInnerSVGFrameBase::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 48 | } |
michael@0 | 49 | #endif /* DEBUG */ |
michael@0 | 50 | |
michael@0 | 51 | nsIAtom * |
michael@0 | 52 | nsSVGInnerSVGFrame::GetType() const |
michael@0 | 53 | { |
michael@0 | 54 | return nsGkAtoms::svgInnerSVGFrame; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | //---------------------------------------------------------------------- |
michael@0 | 58 | // nsISVGChildFrame methods |
michael@0 | 59 | |
michael@0 | 60 | nsresult |
michael@0 | 61 | nsSVGInnerSVGFrame::PaintSVG(nsRenderingContext *aContext, |
michael@0 | 62 | const nsIntRect *aDirtyRect, |
michael@0 | 63 | nsIFrame* aTransformRoot) |
michael@0 | 64 | { |
michael@0 | 65 | NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() || |
michael@0 | 66 | (mState & NS_FRAME_IS_NONDISPLAY), |
michael@0 | 67 | "If display lists are enabled, only painting of non-display " |
michael@0 | 68 | "SVG should take this code path"); |
michael@0 | 69 | |
michael@0 | 70 | gfxContextAutoSaveRestore autoSR; |
michael@0 | 71 | |
michael@0 | 72 | if (StyleDisplay()->IsScrollableOverflow()) { |
michael@0 | 73 | float x, y, width, height; |
michael@0 | 74 | static_cast<SVGSVGElement*>(mContent)-> |
michael@0 | 75 | GetAnimatedLengthValues(&x, &y, &width, &height, nullptr); |
michael@0 | 76 | |
michael@0 | 77 | if (width <= 0 || height <= 0) { |
michael@0 | 78 | return NS_OK; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent); |
michael@0 | 82 | gfxMatrix clipTransform = parent->GetCanvasTM(FOR_PAINTING, aTransformRoot); |
michael@0 | 83 | |
michael@0 | 84 | gfxContext *gfx = aContext->ThebesContext(); |
michael@0 | 85 | autoSR.SetContext(gfx); |
michael@0 | 86 | gfxRect clipRect = |
michael@0 | 87 | nsSVGUtils::GetClipRectForFrame(this, x, y, width, height); |
michael@0 | 88 | nsSVGUtils::SetClipRect(gfx, clipTransform, clipRect); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | return nsSVGInnerSVGFrameBase::PaintSVG(aContext, aDirtyRect); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void |
michael@0 | 95 | nsSVGInnerSVGFrame::ReflowSVG() |
michael@0 | 96 | { |
michael@0 | 97 | // mRect must be set before FinishAndStoreOverflow is called in order |
michael@0 | 98 | // for our overflow areas to be clipped correctly. |
michael@0 | 99 | float x, y, width, height; |
michael@0 | 100 | static_cast<SVGSVGElement*>(mContent)-> |
michael@0 | 101 | GetAnimatedLengthValues(&x, &y, &width, &height, nullptr); |
michael@0 | 102 | mRect = nsLayoutUtils::RoundGfxRectToAppRect( |
michael@0 | 103 | gfxRect(x, y, width, height), |
michael@0 | 104 | PresContext()->AppUnitsPerCSSPixel()); |
michael@0 | 105 | |
michael@0 | 106 | // If we have a filter, we need to invalidate ourselves because filter |
michael@0 | 107 | // output can change even if none of our descendants need repainting. |
michael@0 | 108 | if (StyleSVGReset()->HasFilters()) { |
michael@0 | 109 | InvalidateFrame(); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | nsSVGInnerSVGFrameBase::ReflowSVG(); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | void |
michael@0 | 116 | nsSVGInnerSVGFrame::NotifySVGChanged(uint32_t aFlags) |
michael@0 | 117 | { |
michael@0 | 118 | NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED), |
michael@0 | 119 | "Invalidation logic may need adjusting"); |
michael@0 | 120 | |
michael@0 | 121 | if (aFlags & COORD_CONTEXT_CHANGED) { |
michael@0 | 122 | |
michael@0 | 123 | SVGSVGElement *svg = static_cast<SVGSVGElement*>(mContent); |
michael@0 | 124 | |
michael@0 | 125 | bool xOrYIsPercentage = |
michael@0 | 126 | svg->mLengthAttributes[SVGSVGElement::ATTR_X].IsPercentage() || |
michael@0 | 127 | svg->mLengthAttributes[SVGSVGElement::ATTR_Y].IsPercentage(); |
michael@0 | 128 | bool widthOrHeightIsPercentage = |
michael@0 | 129 | svg->mLengthAttributes[SVGSVGElement::ATTR_WIDTH].IsPercentage() || |
michael@0 | 130 | svg->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT].IsPercentage(); |
michael@0 | 131 | |
michael@0 | 132 | if (xOrYIsPercentage || widthOrHeightIsPercentage) { |
michael@0 | 133 | // Ancestor changes can't affect how we render from the perspective of |
michael@0 | 134 | // any rendering observers that we may have, so we don't need to |
michael@0 | 135 | // invalidate them. We also don't need to invalidate ourself, since our |
michael@0 | 136 | // changed ancestor will have invalidated its entire area, which includes |
michael@0 | 137 | // our area. |
michael@0 | 138 | // For perf reasons we call this before calling NotifySVGChanged() below. |
michael@0 | 139 | nsSVGUtils::ScheduleReflowSVG(this); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | // Coordinate context changes affect mCanvasTM if we have a |
michael@0 | 143 | // percentage 'x' or 'y', or if we have a percentage 'width' or 'height' AND |
michael@0 | 144 | // a 'viewBox'. |
michael@0 | 145 | |
michael@0 | 146 | if (!(aFlags & TRANSFORM_CHANGED) && |
michael@0 | 147 | (xOrYIsPercentage || |
michael@0 | 148 | (widthOrHeightIsPercentage && svg->HasViewBoxRect()))) { |
michael@0 | 149 | aFlags |= TRANSFORM_CHANGED; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | if (svg->HasViewBoxRect() || !widthOrHeightIsPercentage) { |
michael@0 | 153 | // Remove COORD_CONTEXT_CHANGED, since we establish the coordinate |
michael@0 | 154 | // context for our descendants and this notification won't change its |
michael@0 | 155 | // dimensions: |
michael@0 | 156 | aFlags &= ~COORD_CONTEXT_CHANGED; |
michael@0 | 157 | |
michael@0 | 158 | if (!aFlags) { |
michael@0 | 159 | return; // No notification flags left |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | if (aFlags & TRANSFORM_CHANGED) { |
michael@0 | 165 | // make sure our cached transform matrix gets (lazily) updated |
michael@0 | 166 | mCanvasTM = nullptr; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | nsSVGInnerSVGFrameBase::NotifySVGChanged(aFlags); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | nsresult |
michael@0 | 173 | nsSVGInnerSVGFrame::AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 174 | nsIAtom* aAttribute, |
michael@0 | 175 | int32_t aModType) |
michael@0 | 176 | { |
michael@0 | 177 | if (aNameSpaceID == kNameSpaceID_None && |
michael@0 | 178 | !(GetStateBits() & NS_FRAME_IS_NONDISPLAY)) { |
michael@0 | 179 | |
michael@0 | 180 | SVGSVGElement* content = static_cast<SVGSVGElement*>(mContent); |
michael@0 | 181 | |
michael@0 | 182 | if (aAttribute == nsGkAtoms::width || |
michael@0 | 183 | aAttribute == nsGkAtoms::height) { |
michael@0 | 184 | nsSVGEffects::InvalidateRenderingObservers(this); |
michael@0 | 185 | nsSVGUtils::ScheduleReflowSVG(this); |
michael@0 | 186 | |
michael@0 | 187 | if (content->HasViewBoxOrSyntheticViewBox()) { |
michael@0 | 188 | // make sure our cached transform matrix gets (lazily) updated |
michael@0 | 189 | mCanvasTM = nullptr; |
michael@0 | 190 | content->ChildrenOnlyTransformChanged(); |
michael@0 | 191 | nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED); |
michael@0 | 192 | } else { |
michael@0 | 193 | uint32_t flags = COORD_CONTEXT_CHANGED; |
michael@0 | 194 | if (mCanvasTM && mCanvasTM->IsSingular()) { |
michael@0 | 195 | mCanvasTM = nullptr; |
michael@0 | 196 | flags |= TRANSFORM_CHANGED; |
michael@0 | 197 | } |
michael@0 | 198 | nsSVGUtils::NotifyChildrenOfSVGChange(this, flags); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | } else if (aAttribute == nsGkAtoms::transform || |
michael@0 | 202 | aAttribute == nsGkAtoms::preserveAspectRatio || |
michael@0 | 203 | aAttribute == nsGkAtoms::viewBox || |
michael@0 | 204 | aAttribute == nsGkAtoms::x || |
michael@0 | 205 | aAttribute == nsGkAtoms::y) { |
michael@0 | 206 | // make sure our cached transform matrix gets (lazily) updated |
michael@0 | 207 | mCanvasTM = nullptr; |
michael@0 | 208 | |
michael@0 | 209 | nsSVGUtils::NotifyChildrenOfSVGChange( |
michael@0 | 210 | this, aAttribute == nsGkAtoms::viewBox ? |
michael@0 | 211 | TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED : TRANSFORM_CHANGED); |
michael@0 | 212 | |
michael@0 | 213 | // We don't invalidate for transform changes (the layers code does that). |
michael@0 | 214 | // Also note that SVGTransformableElement::GetAttributeChangeHint will |
michael@0 | 215 | // return nsChangeHint_UpdateOverflow for "transform" attribute changes |
michael@0 | 216 | // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call. |
michael@0 | 217 | |
michael@0 | 218 | if (aAttribute == nsGkAtoms::x || aAttribute == nsGkAtoms::y) { |
michael@0 | 219 | nsSVGEffects::InvalidateRenderingObservers(this); |
michael@0 | 220 | nsSVGUtils::ScheduleReflowSVG(this); |
michael@0 | 221 | } else if (aAttribute == nsGkAtoms::viewBox || |
michael@0 | 222 | (aAttribute == nsGkAtoms::preserveAspectRatio && |
michael@0 | 223 | content->HasViewBoxOrSyntheticViewBox())) { |
michael@0 | 224 | content->ChildrenOnlyTransformChanged(); |
michael@0 | 225 | // SchedulePaint sets a global state flag so we only need to call it once |
michael@0 | 226 | // (on ourself is fine), not once on each child (despite bug 828240). |
michael@0 | 227 | SchedulePaint(); |
michael@0 | 228 | } |
michael@0 | 229 | } |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | return NS_OK; |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | nsIFrame* |
michael@0 | 236 | nsSVGInnerSVGFrame::GetFrameForPoint(const nsPoint &aPoint) |
michael@0 | 237 | { |
michael@0 | 238 | NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() || |
michael@0 | 239 | (mState & NS_FRAME_IS_NONDISPLAY), |
michael@0 | 240 | "If display lists are enabled, only hit-testing of non-display " |
michael@0 | 241 | "SVG should take this code path"); |
michael@0 | 242 | |
michael@0 | 243 | if (StyleDisplay()->IsScrollableOverflow()) { |
michael@0 | 244 | nsSVGElement *content = static_cast<nsSVGElement*>(mContent); |
michael@0 | 245 | nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent); |
michael@0 | 246 | |
michael@0 | 247 | float clipX, clipY, clipWidth, clipHeight; |
michael@0 | 248 | content->GetAnimatedLengthValues(&clipX, &clipY, &clipWidth, &clipHeight, nullptr); |
michael@0 | 249 | |
michael@0 | 250 | if (!nsSVGUtils::HitTestRect(gfx::ToMatrix(parent->GetCanvasTM(FOR_HIT_TESTING)), |
michael@0 | 251 | clipX, clipY, clipWidth, clipHeight, |
michael@0 | 252 | PresContext()->AppUnitsToDevPixels(aPoint.x), |
michael@0 | 253 | PresContext()->AppUnitsToDevPixels(aPoint.y))) { |
michael@0 | 254 | return nullptr; |
michael@0 | 255 | } |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | return nsSVGInnerSVGFrameBase::GetFrameForPoint(aPoint); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | //---------------------------------------------------------------------- |
michael@0 | 262 | // nsISVGSVGFrame methods: |
michael@0 | 263 | |
michael@0 | 264 | void |
michael@0 | 265 | nsSVGInnerSVGFrame::NotifyViewportOrTransformChanged(uint32_t aFlags) |
michael@0 | 266 | { |
michael@0 | 267 | // The dimensions of inner-<svg> frames are purely defined by their "width" |
michael@0 | 268 | // and "height" attributes, and transform changes can only occur as a result |
michael@0 | 269 | // of changes to their "width", "height", "viewBox" or "preserveAspectRatio" |
michael@0 | 270 | // attributes. Changes to all of these attributes are handled in |
michael@0 | 271 | // AttributeChanged(), so we should never be called. |
michael@0 | 272 | NS_ERROR("Not called for nsSVGInnerSVGFrame"); |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | //---------------------------------------------------------------------- |
michael@0 | 276 | // nsSVGContainerFrame methods: |
michael@0 | 277 | |
michael@0 | 278 | gfxMatrix |
michael@0 | 279 | nsSVGInnerSVGFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot) |
michael@0 | 280 | { |
michael@0 | 281 | if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) { |
michael@0 | 282 | if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) || |
michael@0 | 283 | (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) { |
michael@0 | 284 | return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this); |
michael@0 | 285 | } |
michael@0 | 286 | } |
michael@0 | 287 | if (!mCanvasTM) { |
michael@0 | 288 | NS_ASSERTION(mParent, "null parent"); |
michael@0 | 289 | |
michael@0 | 290 | nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent); |
michael@0 | 291 | SVGSVGElement *content = static_cast<SVGSVGElement*>(mContent); |
michael@0 | 292 | |
michael@0 | 293 | gfxMatrix tm = content->PrependLocalTransformsTo( |
michael@0 | 294 | this == aTransformRoot ? gfxMatrix() : |
michael@0 | 295 | parent->GetCanvasTM(aFor, aTransformRoot)); |
michael@0 | 296 | |
michael@0 | 297 | mCanvasTM = new gfxMatrix(tm); |
michael@0 | 298 | } |
michael@0 | 299 | return *mCanvasTM; |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | bool |
michael@0 | 303 | nsSVGInnerSVGFrame::HasChildrenOnlyTransform(gfx::Matrix *aTransform) const |
michael@0 | 304 | { |
michael@0 | 305 | SVGSVGElement *content = static_cast<SVGSVGElement*>(mContent); |
michael@0 | 306 | |
michael@0 | 307 | if (content->HasViewBoxOrSyntheticViewBox()) { |
michael@0 | 308 | // XXX Maybe return false if the transform is the identity transform? |
michael@0 | 309 | if (aTransform) { |
michael@0 | 310 | *aTransform = content->GetViewBoxTransform(); |
michael@0 | 311 | } |
michael@0 | 312 | return true; |
michael@0 | 313 | } |
michael@0 | 314 | return false; |
michael@0 | 315 | } |