Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/html/HTMLTableColElement.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 "mozilla/dom/HTMLTableColElement.h"
8
#include "mozilla/dom/HTMLTableColElementBinding.h"
9
#include "nsMappedAttributes.h"
10
#include "nsAttrValueInlines.h"
11
#include "mozilla/MappedDeclarations.h"
12
13
NS_IMPL_NS_NEW_HTML_ELEMENT(TableCol)
14
15
namespace mozilla {
16
namespace dom {
17
18
// use the same protection as ancient code did
19
// http://lxr.mozilla.org/classic/source/lib/layout/laytable.c#46
20
0
#define MAX_COLSPAN 1000
21
22
HTMLTableColElement::~HTMLTableColElement()
23
0
{
24
0
}
25
26
JSObject*
27
HTMLTableColElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
28
0
{
29
0
  return HTMLTableColElement_Binding::Wrap(aCx, this, aGivenProto);
30
0
}
31
32
NS_IMPL_ELEMENT_CLONE(HTMLTableColElement)
33
34
bool
35
HTMLTableColElement::ParseAttribute(int32_t aNamespaceID,
36
                                    nsAtom* aAttribute,
37
                                    const nsAString& aValue,
38
                                    nsIPrincipal* aMaybeScriptedPrincipal,
39
                                    nsAttrValue& aResult)
40
0
{
41
0
  if (aNamespaceID == kNameSpaceID_None) {
42
0
    /* ignore these attributes, stored simply as strings ch */
43
0
    if (aAttribute == nsGkAtoms::charoff) {
44
0
      return aResult.ParseSpecialIntValue(aValue);
45
0
    }
46
0
    if (aAttribute == nsGkAtoms::span) {
47
0
      /* protection from unrealistic large colspan values */
48
0
      aResult.ParseClampedNonNegativeInt(aValue, 1, 1, MAX_COLSPAN);
49
0
      return true;
50
0
    }
51
0
    if (aAttribute == nsGkAtoms::width) {
52
0
      return aResult.ParseSpecialIntValue(aValue);
53
0
    }
54
0
    if (aAttribute == nsGkAtoms::align) {
55
0
      return ParseTableCellHAlignValue(aValue, aResult);
56
0
    }
57
0
    if (aAttribute == nsGkAtoms::valign) {
58
0
      return ParseTableVAlignValue(aValue, aResult);
59
0
    }
60
0
  }
61
0
62
0
  return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
63
0
                                              aMaybeScriptedPrincipal, aResult);
64
0
}
65
66
void
67
HTMLTableColElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
68
                                           MappedDeclarations& aDecls)
69
0
{
70
0
  if (!aDecls.PropertyIsSet(eCSSProperty__x_span)) {
71
0
    // span: int
72
0
    const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::span);
73
0
    if (value && value->Type() == nsAttrValue::eInteger) {
74
0
      int32_t val = value->GetIntegerValue();
75
0
      // Note: Do NOT use this code for table cells!  The value "0"
76
0
      // means something special for colspan and rowspan, but for <col
77
0
      // span> and <colgroup span> it's just disallowed.
78
0
      if (val > 0) {
79
0
        aDecls.SetIntValue(eCSSProperty__x_span, value->GetIntegerValue());
80
0
      }
81
0
    }
82
0
  }
83
0
84
0
  nsGenericHTMLElement::MapWidthAttributeInto(aAttributes, aDecls);
85
0
  nsGenericHTMLElement::MapDivAlignAttributeInto(aAttributes, aDecls);
86
0
  nsGenericHTMLElement::MapVAlignAttributeInto(aAttributes, aDecls);
87
0
  nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
88
0
}
89
90
NS_IMETHODIMP_(bool)
91
HTMLTableColElement::IsAttributeMapped(const nsAtom* aAttribute) const
92
0
{
93
0
  static const MappedAttributeEntry attributes[] = {
94
0
    { &nsGkAtoms::width },
95
0
    { &nsGkAtoms::align },
96
0
    { &nsGkAtoms::valign },
97
0
    { &nsGkAtoms::span },
98
0
    { nullptr }
99
0
  };
100
0
101
0
  static const MappedAttributeEntry* const map[] = {
102
0
    attributes,
103
0
    sCommonAttributeMap,
104
0
  };
105
0
106
0
  return FindAttributeDependence(aAttribute, map);
107
0
}
108
109
110
nsMapRuleToAttributesFunc
111
HTMLTableColElement::GetAttributeMappingFunction() const
112
0
{
113
0
  return &MapAttributesIntoRule;
114
0
}
115
116
} // namespace dom
117
} // namespace mozilla