Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / html / HTMLFontElement.cpp
blobfc6036a33fe19c6372793834c01ba4a68d547600
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/HTMLFontElementBinding.h"
9 #include "mozilla/MappedDeclarations.h"
10 #include "nsAttrValueInlines.h"
11 #include "nsMappedAttributes.h"
12 #include "nsContentUtils.h"
14 NS_IMPL_NS_NEW_HTML_ELEMENT(Font)
16 namespace mozilla {
17 namespace 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);
35 if (size) {
36 aResult.SetTo(size, &aValue);
37 return true;
39 return false;
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) {
52 // face: string list
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(value->GetStringValue());
60 // size: int
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)) {
67 // color: color
68 const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::color);
69 nscolor 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);
79 nscolor color;
80 if (value && value->GetColorValue(color)) {
81 aDecls.SetTextDecorationColorOverride();
85 nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
88 NS_IMETHODIMP_(bool)
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[] = {
94 attributes,
95 sCommonAttributeMap,
98 return FindAttributeDependence(aAttribute, map);
101 nsMapRuleToAttributesFunc HTMLFontElement::GetAttributeMappingFunction() const {
102 return &MapAttributesIntoRule;
105 } // namespace dom
106 } // namespace mozilla