1/**
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003 Apple Computer, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "HTMLHRElement.h"
25
26#include "CSSPropertyNames.h"
27#include "CSSValueKeywords.h"
28#include "HTMLNames.h"
29#include "MappedAttribute.h"
30
31namespace WebCore {
32
33using namespace HTMLNames;
34
35HTMLHRElement::HTMLHRElement(const QualifiedName& tagName, Document* doc)
36    : HTMLElement(tagName, doc)
37{
38    ASSERT(hasTagName(hrTag));
39}
40
41HTMLHRElement::~HTMLHRElement()
42{
43}
44
45bool HTMLHRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
46{
47    if (attrName == alignAttr ||
48        attrName == widthAttr ||
49        attrName == colorAttr ||
50        attrName == sizeAttr ||
51        attrName == noshadeAttr) {
52        result = eHR;
53        return false;
54    }
55    return HTMLElement::mapToEntry(attrName, result);
56}
57
58void HTMLHRElement::parseMappedAttribute(MappedAttribute *attr)
59{
60    if (attr->name() == alignAttr) {
61        if (equalIgnoringCase(attr->value(), "left")) {
62            addCSSProperty(attr, CSSPropertyMarginLeft, "0");
63            addCSSProperty(attr, CSSPropertyMarginRight, CSSValueAuto);
64        } else if (equalIgnoringCase(attr->value(), "right")) {
65            addCSSProperty(attr, CSSPropertyMarginLeft, CSSValueAuto);
66            addCSSProperty(attr, CSSPropertyMarginRight, "0");
67        } else {
68            addCSSProperty(attr, CSSPropertyMarginLeft, CSSValueAuto);
69            addCSSProperty(attr, CSSPropertyMarginRight, CSSValueAuto);
70        }
71    } else if (attr->name() == widthAttr) {
72        bool ok;
73        int v = attr->value().toInt(&ok);
74        if (ok && !v)
75            addCSSLength(attr, CSSPropertyWidth, "1");
76        else
77            addCSSLength(attr, CSSPropertyWidth, attr->value());
78    } else if (attr->name() == colorAttr) {
79        addCSSProperty(attr, CSSPropertyBorderTopStyle, CSSValueSolid);
80        addCSSProperty(attr, CSSPropertyBorderRightStyle, CSSValueSolid);
81        addCSSProperty(attr, CSSPropertyBorderBottomStyle, CSSValueSolid);
82        addCSSProperty(attr, CSSPropertyBorderLeftStyle, CSSValueSolid);
83        addCSSColor(attr, CSSPropertyBorderColor, attr->value());
84        addCSSColor(attr, CSSPropertyBackgroundColor, attr->value());
85    } else if (attr->name() == noshadeAttr) {
86        addCSSProperty(attr, CSSPropertyBorderTopStyle, CSSValueSolid);
87        addCSSProperty(attr, CSSPropertyBorderRightStyle, CSSValueSolid);
88        addCSSProperty(attr, CSSPropertyBorderBottomStyle, CSSValueSolid);
89        addCSSProperty(attr, CSSPropertyBorderLeftStyle, CSSValueSolid);
90        addCSSColor(attr, CSSPropertyBorderColor, String("grey"));
91        addCSSColor(attr, CSSPropertyBackgroundColor, String("grey"));
92    } else if (attr->name() == sizeAttr) {
93        StringImpl* si = attr->value().impl();
94        int size = si->toInt();
95        if (size <= 1)
96            addCSSProperty(attr, CSSPropertyBorderBottomWidth, String("0"));
97        else
98            addCSSLength(attr, CSSPropertyHeight, String::number(size-2));
99    } else
100        HTMLElement::parseMappedAttribute(attr);
101}
102
103String HTMLHRElement::align() const
104{
105    return getAttribute(alignAttr);
106}
107
108void HTMLHRElement::setAlign(const String &value)
109{
110    setAttribute(alignAttr, value);
111}
112
113bool HTMLHRElement::noShade() const
114{
115    return !getAttribute(noshadeAttr).isNull();
116}
117
118void HTMLHRElement::setNoShade(bool noShade)
119{
120    setAttribute(noshadeAttr, noShade ? "" : 0);
121}
122
123String HTMLHRElement::size() const
124{
125    return getAttribute(sizeAttr);
126}
127
128void HTMLHRElement::setSize(const String &value)
129{
130    setAttribute(sizeAttr, value);
131}
132
133String HTMLHRElement::width() const
134{
135    return getAttribute(widthAttr);
136}
137
138void HTMLHRElement::setWidth(const String &value)
139{
140    setAttribute(widthAttr, value);
141}
142
143}
144