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/MappedDeclarations.h"
11 #include "nsAttrValueInlines.h"
12 #include "nsMappedAttributes.h"
13 #include "nsContentUtils.h"
15 NS_IMPL_NS_NEW_HTML_ELEMENT(Font
)
17 namespace mozilla::dom
{
19 HTMLFontElement::~HTMLFontElement() = default;
21 JSObject
* HTMLFontElement::WrapNode(JSContext
* aCx
,
22 JS::Handle
<JSObject
*> aGivenProto
) {
23 return HTMLFontElement_Binding::Wrap(aCx
, this, aGivenProto
);
26 NS_IMPL_ELEMENT_CLONE(HTMLFontElement
)
28 bool HTMLFontElement::ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
29 const nsAString
& aValue
,
30 nsIPrincipal
* aMaybeScriptedPrincipal
,
31 nsAttrValue
& aResult
) {
32 if (aNamespaceID
== kNameSpaceID_None
) {
33 if (aAttribute
== nsGkAtoms::size
) {
34 int32_t size
= nsContentUtils::ParseLegacyFontSize(aValue
);
36 aResult
.SetTo(size
, &aValue
);
41 if (aAttribute
== nsGkAtoms::color
) {
42 return aResult
.ParseColor(aValue
);
46 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
47 aMaybeScriptedPrincipal
, aResult
);
50 void HTMLFontElement::MapAttributesIntoRule(
51 const nsMappedAttributes
* aAttributes
, MappedDeclarations
& aDecls
) {
53 if (!aDecls
.PropertyIsSet(eCSSProperty_font_family
)) {
54 const nsAttrValue
* value
= aAttributes
->GetAttr(nsGkAtoms::face
);
55 if (value
&& value
->Type() == nsAttrValue::eString
&&
56 !value
->IsEmptyString()) {
57 aDecls
.SetFontFamily(NS_ConvertUTF16toUTF8(value
->GetStringValue()));
61 if (!aDecls
.PropertyIsSet(eCSSProperty_font_size
)) {
62 const nsAttrValue
* value
= aAttributes
->GetAttr(nsGkAtoms::size
);
63 if (value
&& value
->Type() == nsAttrValue::eInteger
)
64 aDecls
.SetKeywordValue(eCSSProperty_font_size
, value
->GetIntegerValue());
66 if (!aDecls
.PropertyIsSet(eCSSProperty_color
)) {
68 const nsAttrValue
* value
= aAttributes
->GetAttr(nsGkAtoms::color
);
70 if (value
&& value
->GetColorValue(color
)) {
71 aDecls
.SetColorValue(eCSSProperty_color
, color
);
74 if (aDecls
.Document()->GetCompatibilityMode() == eCompatibility_NavQuirks
) {
75 // Make <a><font color="red">text</font></a> give the text a red underline
76 // in quirks mode. The StyleTextDecorationLine_COLOR_OVERRIDE flag only
77 // affects quirks mode rendering.
78 const nsAttrValue
* value
= aAttributes
->GetAttr(nsGkAtoms::color
);
80 if (value
&& value
->GetColorValue(color
)) {
81 aDecls
.SetTextDecorationColorOverride();
85 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes
, aDecls
);
89 HTMLFontElement::IsAttributeMapped(const nsAtom
* aAttribute
) const {
90 static const MappedAttributeEntry attributes
[] = {
91 {nsGkAtoms::face
}, {nsGkAtoms::size
}, {nsGkAtoms::color
}, {nullptr}};
93 static const MappedAttributeEntry
* const map
[] = {
98 return FindAttributeDependence(aAttribute
, map
);
101 nsMapRuleToAttributesFunc
HTMLFontElement::GetAttributeMappingFunction() const {
102 return &MapAttributesIntoRule
;
105 } // namespace mozilla::dom