1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved.
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 "Attribute.h"
27#include "CSSPropertyNames.h"
28#include "CSSValueKeywords.h"
29#include "CSSValuePool.h"
30#include "HTMLNames.h"
31#include "StylePropertySet.h"
32
33namespace WebCore {
34
35using namespace HTMLNames;
36
37HTMLHRElement::HTMLHRElement(const QualifiedName& tagName, Document* document)
38    : HTMLElement(tagName, document)
39{
40    ASSERT(hasTagName(hrTag));
41}
42
43PassRefPtr<HTMLHRElement> HTMLHRElement::create(Document* document)
44{
45    return adoptRef(new HTMLHRElement(hrTag, document));
46}
47
48PassRefPtr<HTMLHRElement> HTMLHRElement::create(const QualifiedName& tagName, Document* document)
49{
50    return adoptRef(new HTMLHRElement(tagName, document));
51}
52
53bool HTMLHRElement::isPresentationAttribute(const QualifiedName& name) const
54{
55    if (name == alignAttr || name == widthAttr || name == colorAttr || name == noshadeAttr || name == sizeAttr)
56        return true;
57    return HTMLElement::isPresentationAttribute(name);
58}
59
60void HTMLHRElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
61{
62    if (name == alignAttr) {
63        if (equalIgnoringCase(value, "left")) {
64            addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, 0, CSSPrimitiveValue::CSS_PX);
65            addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto);
66        } else if (equalIgnoringCase(value, "right")) {
67            addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, CSSValueAuto);
68            addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, 0, CSSPrimitiveValue::CSS_PX);
69        } else {
70            addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, CSSValueAuto);
71            addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto);
72        }
73    } else if (name == widthAttr) {
74        bool ok;
75        int v = value.toInt(&ok);
76        if (ok && !v)
77            addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 1, CSSPrimitiveValue::CSS_PX);
78        else
79            addHTMLLengthToStyle(style, CSSPropertyWidth, value);
80    } else if (name == colorAttr) {
81        addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid);
82        addHTMLColorToStyle(style, CSSPropertyBorderColor, value);
83        addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value);
84    } else if (name == noshadeAttr) {
85        addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid);
86
87        RefPtr<CSSPrimitiveValue> darkGrayValue = cssValuePool().createColorValue(Color::darkGray);
88        style->setProperty(CSSPropertyBorderColor, darkGrayValue);
89        style->setProperty(CSSPropertyBackgroundColor, darkGrayValue);
90    } else if (name == sizeAttr) {
91        StringImpl* si = value.impl();
92        int size = si->toInt();
93        if (size <= 1)
94            addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomWidth, 0, CSSPrimitiveValue::CSS_PX);
95        else
96            addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, size - 2, CSSPrimitiveValue::CSS_PX);
97    } else
98        HTMLElement::collectStyleForPresentationAttribute(name, value, style);
99}
100
101}
102