2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
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.
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.
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.
24 #include "WMLElement.h"
26 #include "Attribute.h"
27 #include "CSSPropertyNames.h"
28 #include "HTMLNames.h"
29 #include "RenderObject.h"
30 #include "WMLErrorHandling.h"
32 #include "WMLVariables.h"
39 using namespace WMLNames;
41 WMLElement::WMLElement(const QualifiedName& tagName, Document* document)
42 : StyledElement(tagName, document, CreateStyledElementZeroRefCount)
46 PassRefPtr<WMLElement> WMLElement::create(const QualifiedName& tagName, Document* document)
48 return new WMLElement(tagName, document);
51 bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
53 if (attrName == HTMLNames::alignAttr) {
58 return StyledElement::mapToEntry(attrName, result);
61 void WMLElement::parseMappedAttribute(Attribute* attr)
63 if (isIdAttributeName(attr->name())
64 || attr->name() == HTMLNames::classAttr
65 || attr->name() == HTMLNames::styleAttr)
66 return StyledElement::parseMappedAttribute(attr);
68 if (attr->name() == HTMLNames::alignAttr) {
69 if (equalIgnoringCase(attr->value(), "middle"))
70 addCSSProperty(attr, CSSPropertyTextAlign, "center");
72 addCSSProperty(attr, CSSPropertyTextAlign, attr->value());
73 } else if (attr->name() == HTMLNames::tabindexAttr) {
74 String indexstring = attr->value();
75 if (indexstring.length()) {
77 int tabindex = indexstring.toIntStrict(&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()))));
85 String WMLElement::title() const
87 return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::titleAttr));
90 bool WMLElement::rendererIsNeeded(RenderStyle* style)
92 return document()->documentElement() == this || style->display() != NONE;
95 RenderObject* WMLElement::createRenderer(RenderArena*, RenderStyle* style)
97 return RenderObject::createObject(this, style);
100 String WMLElement::parseValueSubstitutingVariableReferences(const AtomicString& value, WMLErrorCode defaultErrorCode) const
102 bool isValid = false;
103 if (!containsVariableReference(value, isValid))
107 reportWMLError(document(), defaultErrorCode);
111 return substituteVariableReferences(value, document());
114 String WMLElement::parseValueForbiddingVariableReferences(const AtomicString& value) const
116 bool isValid = false;
117 if (containsVariableReference(value, isValid)) {
118 reportWMLError(document(), WMLErrorInvalidVariableReferenceLocation);