2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Simon Hausmann <hausmann@kde.org>
5 * Copyright (C) 2003, 2006, 2008, 2010 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include "HTMLFontElement.h"
26 #include "Attribute.h"
27 #include "CSSPropertyNames.h"
28 #include "CSSValueKeywords.h"
29 #include "HTMLNames.h"
30 #include "HTMLParserIdioms.h"
31 #include <wtf/text/StringBuilder.h>
37 using namespace HTMLNames;
39 HTMLFontElement::HTMLFontElement(const QualifiedName& tagName, Document* document)
40 : HTMLElement(tagName, document)
42 ASSERT(hasTagName(fontTag));
45 PassRefPtr<HTMLFontElement> HTMLFontElement::create(const QualifiedName& tagName, Document* document)
47 return adoptRef(new HTMLFontElement(tagName, document));
50 // http://www.whatwg.org/specs/web-apps/current-work/multipage/rendering.html#fonts-and-colors
51 static bool parseFontSize(const String& input, int& size)
56 const UChar* position = input.characters();
57 const UChar* end = position + input.length();
60 while (position < end) {
61 if (!isHTMLSpace(*position))
69 ASSERT(position < end);
94 digits.reserveCapacity(16);
95 while (position < end) {
96 if (!isASCIIDigit(*position))
98 digits.append(*position++);
102 if (digits.isEmpty())
106 int value = charactersToIntStrict(digits.characters(), digits.length());
109 if (mode == RelativePlus)
111 else if (mode == RelativeMinus)
126 bool HTMLFontElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
128 if (attrName == sizeAttr ||
129 attrName == colorAttr ||
130 attrName == faceAttr) {
135 return HTMLElement::mapToEntry(attrName, result);
138 bool HTMLFontElement::cssValueFromFontSizeNumber(const String& s, int& size)
141 if (!parseFontSize(s, num))
146 // FIXME: The spec says that we're supposed to use CSSValueXxSmall here.
147 size = CSSValueXSmall;
150 size = CSSValueSmall;
153 size = CSSValueMedium;
156 size = CSSValueLarge;
159 size = CSSValueXLarge;
162 size = CSSValueXxLarge;
165 size = CSSValueWebkitXxxLarge;
168 ASSERT_NOT_REACHED();
173 void HTMLFontElement::parseMappedAttribute(Attribute* attr)
175 if (attr->name() == sizeAttr) {
177 if (cssValueFromFontSizeNumber(attr->value(), size))
178 addCSSProperty(attr, CSSPropertyFontSize, size);
179 } else if (attr->name() == colorAttr) {
180 addCSSColor(attr, CSSPropertyColor, attr->value());
181 } else if (attr->name() == faceAttr) {
182 addCSSProperty(attr, CSSPropertyFontFamily, attr->value());
184 HTMLElement::parseMappedAttribute(attr);