Line data Source code
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 "HTMLFontElement.h"
8 : #include "mozilla/dom/HTMLFontElementBinding.h"
9 : #include "mozilla/GenericSpecifiedValuesInlines.h"
10 : #include "nsAttrValueInlines.h"
11 : #include "nsMappedAttributes.h"
12 : #include "nsContentUtils.h"
13 : #include "nsCSSParser.h"
14 :
15 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Font)
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 0 : HTMLFontElement::~HTMLFontElement()
21 : {
22 0 : }
23 :
24 : JSObject*
25 0 : HTMLFontElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
26 : {
27 0 : return HTMLFontElementBinding::Wrap(aCx, this, aGivenProto);
28 : }
29 :
30 0 : NS_IMPL_ELEMENT_CLONE(HTMLFontElement)
31 :
32 : bool
33 0 : HTMLFontElement::ParseAttribute(int32_t aNamespaceID,
34 : nsIAtom* aAttribute,
35 : const nsAString& aValue,
36 : nsAttrValue& aResult)
37 : {
38 0 : if (aNamespaceID == kNameSpaceID_None) {
39 0 : if (aAttribute == nsGkAtoms::size) {
40 0 : int32_t size = nsContentUtils::ParseLegacyFontSize(aValue);
41 0 : if (size) {
42 0 : aResult.SetTo(size, &aValue);
43 0 : return true;
44 : }
45 0 : return false;
46 : }
47 0 : if (aAttribute == nsGkAtoms::color) {
48 0 : return aResult.ParseColor(aValue);
49 : }
50 : }
51 :
52 0 : return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
53 0 : aResult);
54 : }
55 :
56 : void
57 0 : HTMLFontElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
58 : GenericSpecifiedValues* aData)
59 : {
60 0 : if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Font))) {
61 : // face: string list
62 0 : if (!aData->PropertyIsSet(eCSSProperty_font_family)) {
63 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::face);
64 0 : if (value && value->Type() == nsAttrValue::eString &&
65 0 : !value->IsEmptyString()) {
66 0 : aData->SetFontFamily(value->GetStringValue());
67 : }
68 : }
69 : // size: int
70 0 : if (!aData->PropertyIsSet(eCSSProperty_font_size)) {
71 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
72 0 : if (value && value->Type() == nsAttrValue::eInteger)
73 0 : aData->SetKeywordValue(eCSSProperty_font_size, value->GetIntegerValue());
74 : }
75 : }
76 0 : if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Color))) {
77 0 : if (!aData->PropertyIsSet(eCSSProperty_color) &&
78 0 : aData->PresContext()->UseDocumentColors()) {
79 : // color: color
80 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::color);
81 : nscolor color;
82 0 : if (value && value->GetColorValue(color)) {
83 0 : aData->SetColorValue(eCSSProperty_color, color);
84 : }
85 : }
86 : }
87 0 : if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(TextReset)) &&
88 0 : aData->PresContext()->CompatibilityMode() == eCompatibility_NavQuirks) {
89 : // Make <a><font color="red">text</font></a> give the text a red underline
90 : // in quirks mode. The NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL flag only
91 : // affects quirks mode rendering.
92 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::color);
93 : nscolor color;
94 0 : if (value && value->GetColorValue(color)) {
95 0 : aData->SetTextDecorationColorOverride();
96 : }
97 : }
98 :
99 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
100 0 : }
101 :
102 : NS_IMETHODIMP_(bool)
103 0 : HTMLFontElement::IsAttributeMapped(const nsIAtom* aAttribute) const
104 : {
105 : static const MappedAttributeEntry attributes[] = {
106 : { &nsGkAtoms::face },
107 : { &nsGkAtoms::size },
108 : { &nsGkAtoms::color },
109 : { nullptr }
110 : };
111 :
112 : static const MappedAttributeEntry* const map[] = {
113 : attributes,
114 : sCommonAttributeMap,
115 : };
116 :
117 0 : return FindAttributeDependence(aAttribute, map);
118 : }
119 :
120 :
121 : nsMapRuleToAttributesFunc
122 0 : HTMLFontElement::GetAttributeMappingFunction() const
123 : {
124 0 : return &MapAttributesIntoRule;
125 : }
126 :
127 : } // namespace dom
128 : } // namespace mozilla
|