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