summaryrefslogtreecommitdiff
path: root/src/3rdparty/webkit/WebCore/wml/WMLElement.cpp
blob: e818f9d029d4a437b6f4091ebaa1dd8e3acf59c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#include "config.h"

#if ENABLE(WML)
#include "WMLElement.h"

#include "CSSPropertyNames.h"
#include "HTMLNames.h"
#include "MappedAttribute.h"
#include "RenderObject.h"
#include "WMLErrorHandling.h"
#include "WMLNames.h"
#include "WMLVariables.h"

using std::max;
using std::min;

namespace WebCore {

using namespace WMLNames;

WMLElement::WMLElement(const QualifiedName& tagName, Document* doc)
    : StyledElement(tagName, doc)
{
}

bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
{
    if (attrName == HTMLNames::alignAttr) {
        result = eUniversal;
        return false;
    }

    return StyledElement::mapToEntry(attrName, result);
}
    
void WMLElement::parseMappedAttribute(MappedAttribute* attr)
{
    if (attr->name() == HTMLNames::idAttr
        || attr->name() == HTMLNames::classAttr
        || attr->name() == HTMLNames::styleAttr)
        return StyledElement::parseMappedAttribute(attr);

    if (attr->name() == HTMLNames::alignAttr) {
        if (equalIgnoringCase(attr->value(), "middle"))
            addCSSProperty(attr, CSSPropertyTextAlign, "center");
        else
            addCSSProperty(attr, CSSPropertyTextAlign, attr->value());
    } else if (attr->name() == HTMLNames::tabindexAttr) {
        String indexstring = attr->value();
        if (indexstring.length()) {
            bool parsedOK;
            int tabindex = indexstring.toIntStrict(&parsedOK);
            if (parsedOK)
                // Clamp tabindex to the range of 'short' to match Firefox's behavior.
                setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
        }
    }
}

bool WMLElement::rendererIsNeeded(RenderStyle* style)
{
    return document()->documentElement() == this || style->display() != NONE;
}

RenderObject* WMLElement::createRenderer(RenderArena*, RenderStyle* style)
{
    return RenderObject::createObject(this, style);
}

String WMLElement::parseValueSubstitutingVariableReferences(const AtomicString& value, WMLErrorCode defaultErrorCode)
{
    bool isValid = false;
    if (!containsVariableReference(value, isValid))
        return value;

    if (!isValid) {
        reportWMLError(document(), defaultErrorCode);
        return String();
    }

    return substituteVariableReferences(value, document());
}

String WMLElement::parseValueForbiddingVariableReferences(const AtomicString& value)
{
    bool isValid = false;
    if (containsVariableReference(value, isValid)) {
        reportWMLError(document(), WMLErrorInvalidVariableReferenceLocation);
        return String();
    }

    return value;
}

}

#endif