Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGElementFactory.cpp
Line
Count
Source (jump to first uncovered line)
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 "SVGElementFactory.h"
8
#include "nsGkAtoms.h"
9
#include "nsIContent.h"
10
#include "mozilla/dom/NodeInfo.h"
11
#include "mozilla/dom/Element.h"
12
#include "mozilla/dom/FromParser.h"
13
#include "mozilla/StaticPtr.h"
14
#include "nsDataHashtable.h"
15
#include "nsHashKeys.h"
16
17
using namespace mozilla;
18
using namespace mozilla::dom;
19
20
// Hash table that maps nsAtom* SVG tags to a SVGContentCreatorFunction.
21
using TagAtomTable = nsDataHashtable<nsPtrHashKey<nsAtom>, SVGContentCreatorFunction>;
22
StaticAutoPtr<TagAtomTable> sTagAtomTable;
23
24
#define SVG_TAG(_tag, _classname)                                              \
25
  nsresult NS_NewSVG##_classname##Element(                                     \
26
    nsIContent** aResult,                                                      \
27
    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);                     \
28
                                                                               \
29
  nsresult NS_NewSVG##_classname##Element(                                     \
30
    nsIContent** aResult,                                                      \
31
    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,                      \
32
    FromParser aFromParser)                                                    \
33
0
  {                                                                            \
34
0
    return NS_NewSVG##_classname##Element(aResult, std::move(aNodeInfo));  \
35
0
  }
Unexecuted instantiation: NS_NewSVGAElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGAnimateElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGAnimateMotionElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGAnimateTransformElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGCircleElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGClipPathElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGDefsElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGDescElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGEllipseElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEBlendElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEColorMatrixElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEComponentTransferElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFECompositeElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEConvolveMatrixElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEDiffuseLightingElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEDisplacementMapElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEDistantLightElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEDropShadowElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEFloodElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEFuncAElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEFuncBElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEFuncGElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEFuncRElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEGaussianBlurElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEImageElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEMergeElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEMergeNodeElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEMorphologyElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEOffsetElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFEPointLightElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFESpecularLightingElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFESpotLightElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFETileElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFETurbulenceElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGFilterElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGForeignObjectElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGGElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGImageElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGLineElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGLinearGradientElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGMarkerElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGMaskElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGMetadataElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGMPathElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGPathElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGPatternElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGPolygonElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGPolylineElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGRadialGradientElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGRectElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGSetElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGStopElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGStyleElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGSwitchElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGSymbolElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGTextElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGTextPathElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGTitleElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGTSpanElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGUseElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
Unexecuted instantiation: NS_NewSVGViewElement(nsIContent**, already_AddRefed<mozilla::dom::NodeInfo>&&, mozilla::dom::FromParser)
36
37
#define SVG_FROM_PARSER_TAG(_tag, _classname)
38
39
#include "SVGTagList.h"
40
#undef SVG_TAG
41
#undef SVG_FROM_PARSER_TAG
42
43
nsresult
44
NS_NewSVGElement(Element** aResult,
45
                 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
46
47
enum SVGTag {
48
#define SVG_TAG(_tag, _classname) eSVGTag_##_tag,
49
#define SVG_FROM_PARSER_TAG(_tag, _classname) eSVGTag_##_tag,
50
#include "SVGTagList.h"
51
#undef SVG_TAG
52
#undef SVG_FROM_PARSER_TAG
53
  eSVGTag_Count
54
};
55
56
void
57
SVGElementFactory::Init()
58
3
{
59
3
  sTagAtomTable = new TagAtomTable(64);
60
3
61
3
#define SVG_TAG(_tag, _classname) \
62
183
  sTagAtomTable->Put(nsGkAtoms::_tag, NS_NewSVG##_classname##Element);
63
3
#define SVG_FROM_PARSER_TAG(_tag, _classname) \
64
6
  sTagAtomTable->Put(nsGkAtoms::_tag, NS_NewSVG##_classname##Element);
65
3
#include "SVGTagList.h"
66
3
#undef SVG_TAG
67
3
#undef SVG_FROM_PARSER_TAG
68
3
}
69
70
void
71
SVGElementFactory::Shutdown()
72
0
{
73
0
  sTagAtomTable = nullptr;
74
0
}
75
76
nsresult
77
NS_NewSVGElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
78
                 FromParser aFromParser)
79
0
{
80
0
  NS_ASSERTION(sTagAtomTable, "no lookup table, needs SVGElementFactory::Init");
81
0
82
0
  RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
83
0
  nsAtom* name = ni->NameAtom();
84
0
85
0
  NS_ASSERTION(ni->NamespaceEquals(kNameSpaceID_SVG),
86
0
               "Trying to create SVG elements that aren't in the SVG namespace");
87
0
88
0
  SVGContentCreatorFunction cb = sTagAtomTable->Get(name);
89
0
  if (cb) {
90
0
    nsCOMPtr<nsIContent> content;
91
0
    nsresult rv = cb(getter_AddRefs(content), ni.forget(), aFromParser);
92
0
    *aResult = content.forget().take()->AsElement();
93
0
    return rv;
94
0
  }
95
0
96
0
  // if we don't know what to create, just create a standard svg element:
97
0
  return NS_NewSVGElement(aResult, ni.forget());
98
0
}
99
100
nsresult
101
NS_NewSVGUnknownElement(nsIContent** aResult,
102
                        already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
103
                        FromParser aFromParser)
104
0
{
105
0
  RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
106
0
  nsCOMPtr<Element> element;
107
0
  nsresult rv = NS_NewSVGElement(getter_AddRefs(element), ni.forget());
108
0
  element.forget(aResult);
109
0
  return rv;
110
0
}