LCOV - code coverage report
Current view: top level - dom/svg - SVGForeignObjectElement.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 29 43 67.4 %
Date: 2017-07-14 16:53:18 Functions: 7 13 53.8 %
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             : #include "mozilla/ArrayUtils.h"
       8             : 
       9             : #include "nsCOMPtr.h"
      10             : #include "mozilla/dom/SVGDocument.h"
      11             : #include "mozilla/dom/SVGForeignObjectElement.h"
      12             : #include "mozilla/dom/SVGForeignObjectElementBinding.h"
      13             : 
      14           4 : NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(ForeignObject)
      15             : 
      16             : namespace mozilla {
      17             : namespace dom {
      18             : 
      19             : JSObject*
      20           0 : SVGForeignObjectElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
      21             : {
      22           0 :   return SVGForeignObjectElementBinding::Wrap(aCx, this, aGivenProto);
      23             : }
      24             : 
      25             : nsSVGElement::LengthInfo SVGForeignObjectElement::sLengthInfo[4] =
      26             : {
      27             :   { &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
      28             :   { &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
      29             :   { &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
      30             :   { &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
      31             : };
      32             : 
      33             : //----------------------------------------------------------------------
      34             : // Implementation
      35             : 
      36           2 : SVGForeignObjectElement::SVGForeignObjectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
      37           2 :   : SVGGraphicsElement(aNodeInfo)
      38             : {
      39           2 : }
      40             : 
      41             : //----------------------------------------------------------------------
      42             : // nsIDOMNode methods
      43             : 
      44           0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGForeignObjectElement)
      45             : 
      46             : //----------------------------------------------------------------------
      47             : 
      48             : already_AddRefed<SVGAnimatedLength>
      49           0 : SVGForeignObjectElement::X()
      50             : {
      51           0 :   return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
      52             : }
      53             : 
      54             : already_AddRefed<SVGAnimatedLength>
      55           0 : SVGForeignObjectElement::Y()
      56             : {
      57           0 :   return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
      58             : }
      59             : 
      60             : already_AddRefed<SVGAnimatedLength>
      61           0 : SVGForeignObjectElement::Width()
      62             : {
      63           0 :   return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
      64             : }
      65             : 
      66             : already_AddRefed<SVGAnimatedLength>
      67           0 : SVGForeignObjectElement::Height()
      68             : {
      69           0 :   return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
      70             : }
      71             : 
      72             : //----------------------------------------------------------------------
      73             : // nsSVGElement methods
      74             : 
      75             : /* virtual */ gfxMatrix
      76           4 : SVGForeignObjectElement::PrependLocalTransformsTo(
      77             :   const gfxMatrix &aMatrix, SVGTransformTypes aWhich) const
      78             : {
      79             :   // 'transform' attribute:
      80             :   gfxMatrix fromUserSpace =
      81           4 :     SVGGraphicsElement::PrependLocalTransformsTo(aMatrix, aWhich);
      82           4 :   if (aWhich == eUserSpaceToParent) {
      83           0 :     return fromUserSpace;
      84             :   }
      85             :   // our 'x' and 'y' attributes:
      86             :   float x, y;
      87             :   const_cast<SVGForeignObjectElement*>(this)->
      88           4 :     GetAnimatedLengthValues(&x, &y, nullptr);
      89           4 :   gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
      90           4 :   if (aWhich == eChildToUserSpace) {
      91           4 :     return toUserSpace * aMatrix;
      92             :   }
      93           0 :   MOZ_ASSERT(aWhich == eAllTransforms, "Unknown TransformTypes");
      94           0 :   return toUserSpace * fromUserSpace;
      95             : }
      96             : 
      97             : /* virtual */ bool
      98           8 : SVGForeignObjectElement::HasValidDimensions() const
      99             : {
     100          16 :   return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() &&
     101          16 :          mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
     102          24 :          mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() &&
     103          16 :          mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0;
     104             : }
     105             : 
     106             : //----------------------------------------------------------------------
     107             : // nsIContent methods
     108             : 
     109             : nsresult
     110           2 : SVGForeignObjectElement::BindToTree(nsIDocument* aDocument,
     111             :                                     nsIContent* aParent,
     112             :                                     nsIContent* aBindingParent,
     113             :                                     bool aCompileEventHandlers)
     114             : {
     115           2 :   nsresult rv = SVGGraphicsElement::BindToTree(aDocument, aParent,
     116             :                                                aBindingParent,
     117           2 :                                                aCompileEventHandlers);
     118           2 :   NS_ENSURE_SUCCESS(rv, rv);
     119             : 
     120           2 :   nsIDocument* doc = GetComposedDoc();
     121           2 :   if (doc && doc->IsSVGDocument()) {
     122             :     // We assume that we're going to have HTML content, so we ensure that the
     123             :     // UA style sheets that nsDocumentViewer::CreateStyleSet skipped when
     124             :     // it saw the document was an SVG document are loaded.
     125             :     //
     126             :     // We setup these style sheets during binding, not element construction,
     127             :     // because elements can be moved from the document that creates them to
     128             :     // another document.
     129           2 :     doc->AsSVGDocument()->EnsureNonSVGUserAgentStyleSheetsLoaded();
     130             :   }
     131             : 
     132           2 :   return rv;
     133             : }
     134             : 
     135             : NS_IMETHODIMP_(bool)
     136          18 : SVGForeignObjectElement::IsAttributeMapped(const nsIAtom* name) const
     137             : {
     138             :   static const MappedAttributeEntry* const map[] = {
     139             :     sFEFloodMap,
     140             :     sFiltersMap,
     141             :     sFontSpecificationMap,
     142             :     sGradientStopMap,
     143             :     sLightingEffectsMap,
     144             :     sMarkersMap,
     145             :     sTextContentElementsMap,
     146             :     sViewportsMap
     147             :   };
     148             : 
     149          36 :   return FindAttributeDependence(name, map) ||
     150          36 :     SVGGraphicsElement::IsAttributeMapped(name);
     151             : }
     152             : 
     153             : //----------------------------------------------------------------------
     154             : // nsSVGElement methods
     155             : 
     156             : nsSVGElement::LengthAttributesInfo
     157          18 : SVGForeignObjectElement::GetLengthInfo()
     158             : {
     159             :   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
     160          18 :                               ArrayLength(sLengthInfo));
     161             : }
     162             : 
     163             : } // namespace dom
     164             : } // namespace mozilla
     165             : 

Generated by: LCOV version 1.13