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/HTMLTableCaptionElement.h"
9 #include "mozilla/MappedDeclarationsBuilder.h"
10 #include "nsAttrValueInlines.h"
11 #include "nsStyleConsts.h"
12 #include "mozilla/dom/HTMLTableCaptionElementBinding.h"
14 NS_IMPL_NS_NEW_HTML_ELEMENT(TableCaption
)
16 namespace mozilla::dom
{
18 HTMLTableCaptionElement::~HTMLTableCaptionElement() = default;
20 JSObject
* HTMLTableCaptionElement::WrapNode(JSContext
* aCx
,
21 JS::Handle
<JSObject
*> aGivenProto
) {
22 return HTMLTableCaptionElement_Binding::Wrap(aCx
, this, aGivenProto
);
25 NS_IMPL_ELEMENT_CLONE(HTMLTableCaptionElement
)
27 static const nsAttrValue::EnumTable kCaptionAlignTable
[] = {
28 {"top", StyleCaptionSide::Top
},
29 {"bottom", StyleCaptionSide::Bottom
},
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);
39 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
40 aMaybeScriptedPrincipal
, aResult
);
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());
52 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder
);
56 HTMLTableCaptionElement::IsAttributeMapped(const nsAtom
* aAttribute
) const {
57 static const MappedAttributeEntry attributes
[] = {{nsGkAtoms::align
},
60 static const MappedAttributeEntry
* const map
[] = {
65 return FindAttributeDependence(aAttribute
, map
);
68 nsMapRuleToAttributesFunc
HTMLTableCaptionElement::GetAttributeMappingFunction()
70 return &MapAttributesIntoRule
;
73 } // namespace mozilla::dom