LCOV - code coverage report
Current view: top level - dom/svg - SVGViewportElement.h (source / functions) Hit Total Coverage
Test: output.info Lines: 19 28 67.9 %
Date: 2017-07-14 16:53:18 Functions: 7 12 58.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef mozilla_dom_SVGViewportElement_h
       8             : #define mozilla_dom_SVGViewportElement_h
       9             : 
      10             : #include "mozilla/dom/FromParser.h"
      11             : #include "nsAutoPtr.h"
      12             : #include "nsIContentInlines.h"
      13             : #include "nsISVGPoint.h"
      14             : #include "nsSVGEnum.h"
      15             : #include "nsSVGLength2.h"
      16             : #include "SVGGraphicsElement.h"
      17             : #include "SVGImageContext.h"
      18             : #include "nsSVGViewBox.h"
      19             : #include "SVGPreserveAspectRatio.h"
      20             : #include "SVGAnimatedPreserveAspectRatio.h"
      21             : #include "mozilla/Attributes.h"
      22             : 
      23             : class nsSVGOuterSVGFrame;
      24             : class nsSVGViewportFrame;
      25             : 
      26             : namespace mozilla {
      27             : class AutoPreserveAspectRatioOverride;
      28             : class DOMSVGAnimatedPreserveAspectRatio;
      29             : 
      30             : namespace dom {
      31             : class SVGAnimatedRect;
      32             : class SVGTransform;
      33             : class SVGViewElement;
      34             : class SVGViewportElement;
      35             : 
      36             : class svgFloatSize {
      37             : public:
      38          86 :   svgFloatSize(float aWidth, float aHeight)
      39          86 :     : width(aWidth)
      40          86 :     , height(aHeight)
      41          86 :   {}
      42          43 :   bool operator!=(const svgFloatSize& rhs) {
      43          43 :     return width != rhs.width || height != rhs.height;
      44             :   }
      45             :   float width;
      46             :   float height;
      47             : };
      48             : 
      49             : class SVGViewportElement : public SVGGraphicsElement
      50             : {
      51             :   friend class ::nsSVGOuterSVGFrame;
      52             :   friend class ::nsSVGViewportFrame;
      53             : 
      54             : protected:
      55             : 
      56             :   SVGViewportElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
      57             :   ~SVGViewportElement();
      58             : 
      59             : public:
      60             : 
      61             :   // nsIContent interface
      62             :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
      63             : 
      64             :   // nsSVGElement specializations:
      65             :   virtual gfxMatrix PrependLocalTransformsTo(
      66             :     const gfxMatrix &aMatrix,
      67             :     SVGTransformTypes aWhich = eAllTransforms) const override;
      68             : 
      69             :   virtual bool HasValidDimensions() const override;
      70             : 
      71             :   // SVGViewportElement methods:
      72             : 
      73             :   float GetLength(uint8_t mCtxType);
      74             : 
      75             :   // public helpers:
      76             : 
      77             :   /**
      78             :    * Returns true if this element has a base/anim value for its "viewBox"
      79             :    * attribute that defines a viewBox rectangle with finite values, or
      80             :    * if there is a view element overriding this element's viewBox and it
      81             :    * has a valid viewBox.
      82             :    *
      83             :    * Note that this does not check whether we need to synthesize a viewBox,
      84             :    * so you must call ShouldSynthesizeViewBox() if you need to chck that too.
      85             :    *
      86             :    * Note also that this method does not pay attention to whether the width or
      87             :    * height values of the viewBox rect are positive!
      88             :    */
      89         347 :   bool HasViewBoxRect() const {
      90         347 :     return GetViewBoxInternal().HasRect();
      91             :   }
      92             : 
      93             :   /**
      94             :    * Returns true if we should synthesize a viewBox for ourselves (that is, if
      95             :    * we're the root element in an image document, and we're not currently being
      96             :    * painted for an <svg:image> element).
      97             :    *
      98             :    * Only call this method if HasViewBoxRect() returns false.
      99             :    */
     100             :   bool ShouldSynthesizeViewBox() const;
     101             : 
     102          62 :   bool HasViewBoxOrSyntheticViewBox() const {
     103          62 :     return HasViewBoxRect() || ShouldSynthesizeViewBox();
     104             :   }
     105             : 
     106         772 :   bool HasChildrenOnlyTransform() const {
     107         772 :     return mHasChildrenOnlyTransform;
     108             :   }
     109             : 
     110             :   void UpdateHasChildrenOnlyTransform();
     111             : 
     112             :   enum ChildrenOnlyTransformChangedFlags {
     113             :     eDuringReflow = 1
     114             :   };
     115             : 
     116             :   /**
     117             :    * This method notifies the style system that the overflow rects of our
     118             :    * immediate childrens' frames need to be updated. It is called by our own
     119             :    * frame when changes (e.g. to currentScale) cause our children-only
     120             :    * transform to change.
     121             :    *
     122             :    * The reason we have this method instead of overriding
     123             :    * GetAttributeChangeHint is because we need to act on non-attribute (e.g.
     124             :    * currentScale) changes in addition to attribute (e.g. viewBox) changes.
     125             :    */
     126             :   void ChildrenOnlyTransformChanged(uint32_t aFlags = 0);
     127             : 
     128             :   gfx::Matrix GetViewBoxTransform() const;
     129             : 
     130             :   // WebIDL
     131             :   already_AddRefed<SVGAnimatedRect> ViewBox();
     132             :   already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
     133             :   virtual nsSVGViewBox* GetViewBox() override;
     134             : 
     135             : protected:
     136             : 
     137             :   // implementation helpers:
     138             : 
     139        1035 :   bool IsRoot() const {
     140        1035 :     NS_ASSERTION((IsInUncomposedDoc() && !GetParent()) ==
     141             :                  (OwnerDoc() && (OwnerDoc()->GetRootElement() == this)),
     142             :                  "Can't determine if we're root");
     143        1035 :     return IsInUncomposedDoc() && !GetParent();
     144             :   }
     145             : 
     146             :   /**
     147             :    * Returns true if either this is an SVG <svg> element that is the child of
     148             :    * another non-foreignObject SVG element, or this is a SVG <symbol> element
     149             :    * this is the root of a use-element shadow tree.
     150             :    */
     151        1747 :   bool IsInner() const {
     152        1747 :     const nsIContent *parent = GetFlattenedTreeParent();
     153        1747 :     return parent && parent->IsSVGElement() &&
     154        1747 :            !parent->IsSVGElement(nsGkAtoms::foreignObject);
     155             :   }
     156             : 
     157             :   /**
     158             :    * Returns the explicit or default preserveAspectRatio, unless we're
     159             :    * synthesizing a viewBox, in which case it returns the "none" value.
     160             :    */
     161           0 :   virtual SVGPreserveAspectRatio GetPreserveAspectRatioWithOverride() const {
     162           0 :     return mPreserveAspectRatio.GetAnimValue();
     163             :   }
     164             : 
     165             :   /**
     166             :    * Returns the explicit viewBox rect, if specified, or else a synthesized
     167             :    * viewBox, if appropriate, or else a viewBox matching the dimensions of the
     168             :    * SVG viewport.
     169             :    */
     170             :   nsSVGViewBoxRect GetViewBoxWithSynthesis(
     171             :       float aViewportWidth, float aViewportHeight) const;
     172             : 
     173             :   /**
     174             :    * Retrieve the value of currentScale and currentTranslate.
     175             :    */
     176           0 :   virtual SVGPoint GetCurrentTranslate() const
     177           0 :   { return SVGPoint(0.0f, 0.0f); }
     178           0 :   virtual float GetCurrentScale() const
     179           0 :   { return 1.0f; }
     180             : 
     181             :   enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
     182             :   nsSVGLength2 mLengthAttributes[4];
     183             :   static LengthInfo sLengthInfo[4];
     184             :   virtual LengthAttributesInfo GetLengthInfo() override;
     185             : 
     186             :   virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio() override;
     187             : 
     188           0 :   virtual const nsSVGViewBox& GetViewBoxInternal() const { return mViewBox; }
     189           0 :   virtual nsSVGAnimatedTransformList* GetTransformInternal() const {
     190           0 :     return mTransforms;
     191             :   }
     192             :   nsSVGViewBox                   mViewBox;
     193             :   SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
     194             : 
     195             :   // The size of the rectangular SVG viewport into which we render. This is
     196             :   // not (necessarily) the same as the content area. See:
     197             :   //
     198             :   //   http://www.w3.org/TR/SVG11/coords.html#ViewportSpace
     199             :   //
     200             :   // XXXjwatt Currently only used for outer <svg>, but maybe we could use -1 to
     201             :   // flag this as an inner <svg> to save the overhead of GetCtx calls?
     202             :   // XXXjwatt our frame should probably reset these when it's destroyed.
     203             :   float mViewportWidth, mViewportHeight;
     204             : 
     205             :   bool     mHasChildrenOnlyTransform;
     206             : };
     207             : 
     208             : } // namespace dom
     209             : 
     210             : } // namespace mozilla
     211             : 
     212             : #endif // SVGViewportElement_h

Generated by: LCOV version 1.13