1 /*
2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21 #include "config.h"
22
23 #if ENABLE(WML)
24 #include "WMLElement.h"
25
26 #include "Attribute.h"
27 #include "CSSPropertyNames.h"
28 #include "HTMLNames.h"
29 #include "HTMLParserIdioms.h"
30 #include "RenderObject.h"
31 #include "WMLErrorHandling.h"
32 #include "WMLNames.h"
33 #include "WMLVariables.h"
34
35 using std::max;
36 using std::min;
37
38 namespace WebCore {
39
40 using namespace WMLNames;
41
WMLElement(const QualifiedName & tagName,Document * document)42 WMLElement::WMLElement(const QualifiedName& tagName, Document* document)
43 : StyledElement(tagName, document, CreateStyledElement)
44 {
45 }
46
create(const QualifiedName & tagName,Document * document)47 PassRefPtr<WMLElement> WMLElement::create(const QualifiedName& tagName, Document* document)
48 {
49 return adoptRef(new WMLElement(tagName, document));
50 }
51
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const52 bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
53 {
54 if (attrName == HTMLNames::alignAttr) {
55 result = eUniversal;
56 return false;
57 }
58
59 return StyledElement::mapToEntry(attrName, result);
60 }
61
parseMappedAttribute(Attribute * attr)62 void WMLElement::parseMappedAttribute(Attribute* attr)
63 {
64 if (isIdAttributeName(attr->name())
65 || attr->name() == HTMLNames::classAttr
66 || attr->name() == HTMLNames::styleAttr)
67 return StyledElement::parseMappedAttribute(attr);
68
69 if (attr->name() == HTMLNames::alignAttr) {
70 if (equalIgnoringCase(attr->value(), "middle"))
71 addCSSProperty(attr, CSSPropertyTextAlign, "center");
72 else
73 addCSSProperty(attr, CSSPropertyTextAlign, attr->value());
74 } else if (attr->name() == HTMLNames::tabindexAttr) {
75 String indexstring = attr->value();
76 int tabindex = 0;
77 if (parseHTMLInteger(indexstring, tabindex)) {
78 // Clamp tabindex to the range of 'short' to match Firefox's behavior.
79 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
80 }
81 }
82 }
83
title() const84 String WMLElement::title() const
85 {
86 return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::titleAttr));
87 }
88
rendererIsNeeded(RenderStyle * style)89 bool WMLElement::rendererIsNeeded(RenderStyle* style)
90 {
91 return document()->documentElement() == this || style->display() != NONE;
92 }
93
createRenderer(RenderArena *,RenderStyle * style)94 RenderObject* WMLElement::createRenderer(RenderArena*, RenderStyle* style)
95 {
96 return RenderObject::createObject(this, style);
97 }
98
parseValueSubstitutingVariableReferences(const AtomicString & value,WMLErrorCode defaultErrorCode) const99 String WMLElement::parseValueSubstitutingVariableReferences(const AtomicString& value, WMLErrorCode defaultErrorCode) const
100 {
101 bool isValid = false;
102 if (!containsVariableReference(value, isValid))
103 return value;
104
105 if (!isValid) {
106 reportWMLError(document(), defaultErrorCode);
107 return String();
108 }
109
110 return substituteVariableReferences(value, document());
111 }
112
parseValueForbiddingVariableReferences(const AtomicString & value) const113 String WMLElement::parseValueForbiddingVariableReferences(const AtomicString& value) const
114 {
115 bool isValid = false;
116 if (containsVariableReference(value, isValid)) {
117 reportWMLError(document(), WMLErrorInvalidVariableReferenceLocation);
118 return String();
119 }
120
121 return value;
122 }
123
124 }
125
126 #endif
127