• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 * doc)41 WMLElement::WMLElement(const QualifiedName& tagName, Document* doc)
42     : StyledElement(tagName, doc)
43 {
44 }
45 
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const46 bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
47 {
48     if (attrName == HTMLNames::alignAttr) {
49         result = eUniversal;
50         return false;
51     }
52 
53     return StyledElement::mapToEntry(attrName, result);
54 }
55 
parseMappedAttribute(MappedAttribute * attr)56 void WMLElement::parseMappedAttribute(MappedAttribute* attr)
57 {
58     if (attr->name() == HTMLNames::idAttr
59         || attr->name() == HTMLNames::classAttr
60         || attr->name() == HTMLNames::styleAttr)
61         return StyledElement::parseMappedAttribute(attr);
62 
63     if (attr->name() == HTMLNames::alignAttr) {
64         if (equalIgnoringCase(attr->value(), "middle"))
65             addCSSProperty(attr, CSSPropertyTextAlign, "center");
66         else
67             addCSSProperty(attr, CSSPropertyTextAlign, attr->value());
68     } else if (attr->name() == HTMLNames::tabindexAttr) {
69         String indexstring = attr->value();
70         if (indexstring.length()) {
71             bool parsedOK;
72             int tabindex = indexstring.toIntStrict(&parsedOK);
73             if (parsedOK)
74                 // Clamp tabindex to the range of 'short' to match Firefox's behavior.
75                 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
76         }
77     }
78 }
79 
title() const80 String WMLElement::title() const
81 {
82     return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::titleAttr));
83 }
84 
rendererIsNeeded(RenderStyle * style)85 bool WMLElement::rendererIsNeeded(RenderStyle* style)
86 {
87     return document()->documentElement() == this || style->display() != NONE;
88 }
89 
createRenderer(RenderArena *,RenderStyle * style)90 RenderObject* WMLElement::createRenderer(RenderArena*, RenderStyle* style)
91 {
92     return RenderObject::createObject(this, style);
93 }
94 
parseValueSubstitutingVariableReferences(const AtomicString & value,WMLErrorCode defaultErrorCode) const95 String WMLElement::parseValueSubstitutingVariableReferences(const AtomicString& value, WMLErrorCode defaultErrorCode) const
96 {
97     bool isValid = false;
98     if (!containsVariableReference(value, isValid))
99         return value;
100 
101     if (!isValid) {
102         reportWMLError(document(), defaultErrorCode);
103         return String();
104     }
105 
106     return substituteVariableReferences(value, document());
107 }
108 
parseValueForbiddingVariableReferences(const AtomicString & value) const109 String WMLElement::parseValueForbiddingVariableReferences(const AtomicString& value) const
110 {
111     bool isValid = false;
112     if (containsVariableReference(value, isValid)) {
113         reportWMLError(document(), WMLErrorInvalidVariableReferenceLocation);
114         return String();
115     }
116 
117     return value;
118 }
119 
120 }
121 
122 #endif
123