Coverage Report

Created: 2018-09-25 14:53

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