layout/svg/nsSVGAFrame.cpp

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 // Keep in (case-insensitive) order:
     7 #include "gfxMatrix.h"
     8 #include "mozilla/dom/SVGAElement.h"
     9 #include "nsSVGContainerFrame.h"
    10 #include "nsSVGIntegrationUtils.h"
    11 #include "nsSVGUtils.h"
    12 #include "SVGLengthList.h"
    14 using namespace mozilla;
    16 typedef nsSVGDisplayContainerFrame nsSVGAFrameBase;
    18 class nsSVGAFrame : public nsSVGAFrameBase
    19 {
    20   friend nsIFrame*
    21   NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    22 protected:
    23   nsSVGAFrame(nsStyleContext* aContext) :
    24     nsSVGAFrameBase(aContext) {}
    26 public:
    27   NS_DECL_FRAMEARENA_HELPERS
    29 #ifdef DEBUG
    30   virtual void Init(nsIContent*      aContent,
    31                     nsIFrame*        aParent,
    32                     nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
    33 #endif
    35   // nsIFrame:
    36   virtual nsresult  AttributeChanged(int32_t         aNameSpaceID,
    37                                      nsIAtom*        aAttribute,
    38                                      int32_t         aModType) MOZ_OVERRIDE;
    40   /**
    41    * Get the "type" of the frame
    42    *
    43    * @see nsGkAtoms::svgAFrame
    44    */
    45   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    47 #ifdef DEBUG_FRAME_DUMP
    48   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
    49   {
    50     return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult);
    51   }
    52 #endif
    53   // nsISVGChildFrame interface:
    54   virtual void NotifySVGChanged(uint32_t aFlags) MOZ_OVERRIDE;
    56   // nsSVGContainerFrame methods:
    57   virtual gfxMatrix GetCanvasTM(uint32_t aFor,
    58                                 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
    60 private:
    61   nsAutoPtr<gfxMatrix> mCanvasTM;
    62 };
    64 //----------------------------------------------------------------------
    65 // Implementation
    67 nsIFrame*
    68 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    69 {
    70   return new (aPresShell) nsSVGAFrame(aContext);
    71 }
    73 NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame)
    75 //----------------------------------------------------------------------
    76 // nsIFrame methods
    77 #ifdef DEBUG
    78 void
    79 nsSVGAFrame::Init(nsIContent* aContent,
    80                   nsIFrame* aParent,
    81                   nsIFrame* aPrevInFlow)
    82 {
    83   NS_ASSERTION(aContent->IsSVG(nsGkAtoms::a),
    84                "Trying to construct an SVGAFrame for a "
    85                "content element that doesn't support the right interfaces");
    87   nsSVGAFrameBase::Init(aContent, aParent, aPrevInFlow);
    88 }
    89 #endif /* DEBUG */
    91 nsresult
    92 nsSVGAFrame::AttributeChanged(int32_t         aNameSpaceID,
    93                               nsIAtom*        aAttribute,
    94                               int32_t         aModType)
    95 {
    96   if (aNameSpaceID == kNameSpaceID_None &&
    97       aAttribute == nsGkAtoms::transform) {
    98     // We don't invalidate for transform changes (the layers code does that).
    99     // Also note that SVGTransformableElement::GetAttributeChangeHint will
   100     // return nsChangeHint_UpdateOverflow for "transform" attribute changes
   101     // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call.
   102     NotifySVGChanged(TRANSFORM_CHANGED);
   103   }
   105  return NS_OK;
   106 }
   108 nsIAtom *
   109 nsSVGAFrame::GetType() const
   110 {
   111   return nsGkAtoms::svgAFrame;
   112 }
   114 //----------------------------------------------------------------------
   115 // nsISVGChildFrame methods
   117 void
   118 nsSVGAFrame::NotifySVGChanged(uint32_t aFlags)
   119 {
   120   NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
   121                     "Invalidation logic may need adjusting");
   123   if (aFlags & TRANSFORM_CHANGED) {
   124     // make sure our cached transform matrix gets (lazily) updated
   125     mCanvasTM = nullptr;
   126   }
   128   nsSVGAFrameBase::NotifySVGChanged(aFlags);
   129 }
   131 //----------------------------------------------------------------------
   132 // nsSVGContainerFrame methods:
   134 gfxMatrix
   135 nsSVGAFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
   136 {
   137   if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
   138     if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
   139         (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
   140       return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
   141     }
   142   }
   143   if (!mCanvasTM) {
   144     NS_ASSERTION(mParent, "null parent");
   146     nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
   147     dom::SVGAElement *content = static_cast<dom::SVGAElement*>(mContent);
   149     gfxMatrix tm = content->PrependLocalTransformsTo(
   150         this == aTransformRoot ? gfxMatrix() :
   151                                  parent->GetCanvasTM(aFor, aTransformRoot));
   153     mCanvasTM = new gfxMatrix(tm);
   154   }
   156   return *mCanvasTM;
   157 }

mercurial