HTMLTableCaptionElement.cpp (2604B)
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/HTMLTableCaptionElement.h" 8 9 #include "mozilla/MappedDeclarationsBuilder.h" 10 #include "mozilla/dom/HTMLTableCaptionElementBinding.h" 11 #include "nsAttrValueInlines.h" 12 #include "nsStyleConsts.h" 13 14 NS_IMPL_NS_NEW_HTML_ELEMENT(TableCaption) 15 16 namespace mozilla::dom { 17 18 HTMLTableCaptionElement::~HTMLTableCaptionElement() = default; 19 20 JSObject* HTMLTableCaptionElement::WrapNode(JSContext* aCx, 21 JS::Handle<JSObject*> aGivenProto) { 22 return HTMLTableCaptionElement_Binding::Wrap(aCx, this, aGivenProto); 23 } 24 25 NS_IMPL_ELEMENT_CLONE(HTMLTableCaptionElement) 26 27 static constexpr nsAttrValue::EnumTableEntry kCaptionAlignTable[] = { 28 {"top", StyleCaptionSide::Top}, 29 {"bottom", StyleCaptionSide::Bottom}, 30 }; 31 32 bool HTMLTableCaptionElement::ParseAttribute( 33 int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue, 34 nsIPrincipal* aMaybeScriptedPrincipal, nsAttrValue& aResult) { 35 if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) { 36 return aResult.ParseEnumValue(aValue, kCaptionAlignTable, false); 37 } 38 39 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, 40 aMaybeScriptedPrincipal, aResult); 41 } 42 43 void HTMLTableCaptionElement::MapAttributesIntoRule( 44 MappedDeclarationsBuilder& aBuilder) { 45 if (!aBuilder.PropertyIsSet(eCSSProperty_caption_side)) { 46 const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::align); 47 if (value && value->Type() == nsAttrValue::eEnum) { 48 aBuilder.SetKeywordValue(eCSSProperty_caption_side, 49 value->GetEnumValue()); 50 } 51 } 52 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder); 53 } 54 55 NS_IMETHODIMP_(bool) 56 HTMLTableCaptionElement::IsAttributeMapped(const nsAtom* aAttribute) const { 57 static const MappedAttributeEntry attributes[] = {{nsGkAtoms::align}, 58 {nullptr}}; 59 60 static const MappedAttributeEntry* const map[] = { 61 attributes, 62 sCommonAttributeMap, 63 }; 64 65 return FindAttributeDependence(aAttribute, map); 66 } 67 68 nsMapRuleToAttributesFunc HTMLTableCaptionElement::GetAttributeMappingFunction() 69 const { 70 return &MapAttributesIntoRule; 71 } 72 73 } // namespace mozilla::dom