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 "CSSPropertyNames.h"
27 #include "HTMLNames.h"
28 #include "MappedAttribute.h"
29 #include "RenderObject.h"
30 #include "WMLErrorHandling.h"
31 #include "WMLNames.h"
32 #include "WMLVariables.h"
33
34 using std::max;
35 using std::min;
36
37 namespace WebCore {
38
39 using namespace WMLNames;
40
WMLElement(const QualifiedName & tagName,Document * document)41 WMLElement::WMLElement(const QualifiedName& tagName, Document* document)
42 : StyledElement(tagName, document, CreateElementZeroRefCount)
43 {
44 }
45
create(const QualifiedName & tagName,Document * document)46 PassRefPtr<WMLElement> WMLElement::create(const QualifiedName& tagName, Document* document)
47 {
48 return new WMLElement(tagName, document);
49 }
50
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const51 bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
52 {
53 if (attrName == HTMLNames::alignAttr) {
54 result = eUniversal;
55 return false;
56 }
57
58 return StyledElement::mapToEntry(attrName, result);
59 }
60
parseMappedAttribute(MappedAttribute * attr)61 void WMLElement::parseMappedAttribute(MappedAttribute* attr)
62 {
63 if (attr->name() == idAttributeName()
64 || attr->name() == HTMLNames::classAttr
65 || attr->name() == HTMLNames::styleAttr)
66 return StyledElement::parseMappedAttribute(attr);
67
68 if (attr->name() == HTMLNames::alignAttr) {
69 if (equalIgnoringCase(attr->value(), "middle"))
70 addCSSProperty(attr, CSSPropertyTextAlign, "center");
71 else
72 addCSSProperty(attr, CSSPropertyTextAlign, attr->value());
73 } else if (attr->name() == HTMLNames::tabindexAttr) {
74 String indexstring = attr->value();
75 if (indexstring.length()) {
76 bool parsedOK;
77 int tabindex = indexstring.toIntStrict(&parsedOK);
78 if (parsedOK)
79 // Clamp tabindex to the range of 'short' to match Firefox's behavior.
80 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
81 }
82 }
83 }
84
title() const85 String WMLElement::title() const
86 {
87 return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::titleAttr));
88 }
89
rendererIsNeeded(RenderStyle * style)90 bool WMLElement::rendererIsNeeded(RenderStyle* style)
91 {
92 return document()->documentElement() == this || style->display() != NONE;
93 }
94
createRenderer(RenderArena *,RenderStyle * style)95 RenderObject* WMLElement::createRenderer(RenderArena*, RenderStyle* style)
96 {
97 return RenderObject::createObject(this, style);
98 }
99
parseValueSubstitutingVariableReferences(const AtomicString & value,WMLErrorCode defaultErrorCode) const100 String WMLElement::parseValueSubstitutingVariableReferences(const AtomicString& value, WMLErrorCode defaultErrorCode) const
101 {
102 bool isValid = false;
103 if (!containsVariableReference(value, isValid))
104 return value;
105
106 if (!isValid) {
107 reportWMLError(document(), defaultErrorCode);
108 return String();
109 }
110
111 return substituteVariableReferences(value, document());
112 }
113
parseValueForbiddingVariableReferences(const AtomicString & value) const114 String WMLElement::parseValueForbiddingVariableReferences(const AtomicString& value) const
115 {
116 bool isValid = false;
117 if (containsVariableReference(value, isValid)) {
118 reportWMLError(document(), WMLErrorInvalidVariableReferenceLocation);
119 return String();
120 }
121
122 return value;
123 }
124
125 }
126
127 #endif
128