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 "HTMLFontElement.h"
8 #include "mozilla/dom/Document.h"
9 #include "mozilla/dom/HTMLFontElementBinding.h"
10 #include "mozilla/MappedDeclarationsBuilder.h"
11 #include "nsAttrValueInlines.h"
12 #include "nsContentUtils.h"
14 NS_IMPL_NS_NEW_HTML_ELEMENT(Font
)
16 namespace mozilla::dom
{
18 HTMLFontElement::~HTMLFontElement() = default;
20 JSObject
* HTMLFontElement::WrapNode(JSContext
* aCx
,
21 JS::Handle
<JSObject
*> aGivenProto
) {
22 return HTMLFontElement_Binding::Wrap(aCx
, this, aGivenProto
);
25 NS_IMPL_ELEMENT_CLONE(HTMLFontElement
)
27 bool HTMLFontElement::ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
28 const nsAString
& aValue
,
29 nsIPrincipal
* aMaybeScriptedPrincipal
,
30 nsAttrValue
& aResult
) {
31 if (aNamespaceID
== kNameSpaceID_None
) {
32 if (aAttribute
== nsGkAtoms::size
) {
33 int32_t size
= nsContentUtils::ParseLegacyFontSize(aValue
);
35 aResult
.SetTo(size
, &aValue
);
40 if (aAttribute
== nsGkAtoms::color
) {
41 return aResult
.ParseColor(aValue
);
45 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
46 aMaybeScriptedPrincipal
, aResult
);
49 void HTMLFontElement::MapAttributesIntoRule(
50 MappedDeclarationsBuilder
& aBuilder
) {
52 if (!aBuilder
.PropertyIsSet(eCSSProperty_font_family
)) {
53 const nsAttrValue
* value
= aBuilder
.GetAttr(nsGkAtoms::face
);
54 if (value
&& value
->Type() == nsAttrValue::eString
&&
55 !value
->IsEmptyString()) {
56 aBuilder
.SetFontFamily(NS_ConvertUTF16toUTF8(value
->GetStringValue()));
60 if (!aBuilder
.PropertyIsSet(eCSSProperty_font_size
)) {
61 const nsAttrValue
* value
= aBuilder
.GetAttr(nsGkAtoms::size
);
62 if (value
&& value
->Type() == nsAttrValue::eInteger
) {
63 aBuilder
.SetKeywordValue(eCSSProperty_font_size
,
64 value
->GetIntegerValue());
67 if (!aBuilder
.PropertyIsSet(eCSSProperty_color
)) {
69 const nsAttrValue
* value
= aBuilder
.GetAttr(nsGkAtoms::color
);
71 if (value
&& value
->GetColorValue(color
)) {
72 aBuilder
.SetColorValue(eCSSProperty_color
, color
);
75 if (aBuilder
.Document().GetCompatibilityMode() == eCompatibility_NavQuirks
) {
76 // Make <a><font color="red">text</font></a> give the text a red underline
77 // in quirks mode. The StyleTextDecorationLine_COLOR_OVERRIDE flag only
78 // affects quirks mode rendering.
79 const nsAttrValue
* value
= aBuilder
.GetAttr(nsGkAtoms::color
);
81 if (value
&& value
->GetColorValue(color
)) {
82 aBuilder
.SetTextDecorationColorOverride();
86 nsGenericHTMLElement::MapCommonAttributesInto(aBuilder
);
90 HTMLFontElement::IsAttributeMapped(const nsAtom
* aAttribute
) const {
91 static const MappedAttributeEntry attributes
[] = {
92 {nsGkAtoms::face
}, {nsGkAtoms::size
}, {nsGkAtoms::color
}, {nullptr}};
94 static const MappedAttributeEntry
* const map
[] = {
99 return FindAttributeDependence(aAttribute
, map
);
102 nsMapRuleToAttributesFunc
HTMLFontElement::GetAttributeMappingFunction() const {
103 return &MapAttributesIntoRule
;
106 } // namespace mozilla::dom