Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLTableColElement.cpp
blobae8e619a0f122f078eeff986763e1a9445e0092e
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/. */
7 #include "mozilla/dom/HTMLTableColElement.h"
8 #include "mozilla/dom/HTMLTableColElementBinding.h"
9 #include "nsAttrValueInlines.h"
10 #include "mozilla/MappedDeclarationsBuilder.h"
12 NS_IMPL_NS_NEW_HTML_ELEMENT(TableCol)
14 namespace mozilla::dom {
16 // use the same protection as ancient code did
17 // http://lxr.mozilla.org/classic/source/lib/layout/laytable.c#46
18 #define MAX_COLSPAN 1000
20 HTMLTableColElement::~HTMLTableColElement() = default;
22 JSObject* HTMLTableColElement::WrapNode(JSContext* aCx,
23 JS::Handle<JSObject*> aGivenProto) {
24 return HTMLTableColElement_Binding::Wrap(aCx, this, aGivenProto);
27 NS_IMPL_ELEMENT_CLONE(HTMLTableColElement)
29 bool HTMLTableColElement::ParseAttribute(int32_t aNamespaceID,
30 nsAtom* aAttribute,
31 const nsAString& aValue,
32 nsIPrincipal* aMaybeScriptedPrincipal,
33 nsAttrValue& aResult) {
34 if (aNamespaceID == kNameSpaceID_None) {
35 /* ignore these attributes, stored simply as strings ch */
36 if (aAttribute == nsGkAtoms::span) {
37 /* protection from unrealistic large colspan values */
38 aResult.ParseClampedNonNegativeInt(aValue, 1, 1, MAX_COLSPAN);
39 return true;
41 if (aAttribute == nsGkAtoms::width) {
42 // Spec says to use ParseNonzeroHTMLDimension, but Chrome and Safari both
43 // allow 0, and we did all along too, so keep that behavior. See
44 // https://github.com/whatwg/html/issues/4717
45 return aResult.ParseHTMLDimension(aValue);
47 if (aAttribute == nsGkAtoms::align) {
48 return ParseTableCellHAlignValue(aValue, aResult);
50 if (aAttribute == nsGkAtoms::valign) {
51 return ParseTableVAlignValue(aValue, aResult);
55 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
56 aMaybeScriptedPrincipal, aResult);
59 void HTMLTableColElement::MapAttributesIntoRule(
60 MappedDeclarationsBuilder& aBuilder) {
61 if (!aBuilder.PropertyIsSet(eCSSProperty__x_span)) {
62 // span: int
63 const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::span);
64 if (value && value->Type() == nsAttrValue::eInteger) {
65 int32_t val = value->GetIntegerValue();
66 // Note: Do NOT use this code for table cells! The value "0"
67 // means something special for colspan and rowspan, but for <col
68 // span> and <colgroup span> it's just disallowed.
69 if (val > 0) {
70 aBuilder.SetIntValue(eCSSProperty__x_span, value->GetIntegerValue());
75 nsGenericHTMLElement::MapWidthAttributeInto(aBuilder);
76 nsGenericHTMLElement::MapDivAlignAttributeInto(aBuilder);
77 nsGenericHTMLElement::MapVAlignAttributeInto(aBuilder);
78 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder);
81 NS_IMETHODIMP_(bool)
82 HTMLTableColElement::IsAttributeMapped(const nsAtom* aAttribute) const {
83 static const MappedAttributeEntry attributes[] = {{nsGkAtoms::width},
84 {nsGkAtoms::align},
85 {nsGkAtoms::valign},
86 {nsGkAtoms::span},
87 {nullptr}};
89 static const MappedAttributeEntry* const map[] = {
90 attributes,
91 sCommonAttributeMap,
94 return FindAttributeDependence(aAttribute, map);
97 nsMapRuleToAttributesFunc HTMLTableColElement::GetAttributeMappingFunction()
98 const {
99 return &MapAttributesIntoRule;
102 } // namespace mozilla::dom