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 "CSSPropertyNames.h" |
27 | #include "CSSValueKeywords.h" |
28 | #include "CSSValuePool.h" |
29 | #include "HTMLNames.h" |
30 | #include "StyleProperties.h" |
31 | #include <wtf/IsoMallocInlines.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLHRElement); |
36 | |
37 | using namespace HTMLNames; |
38 | |
39 | HTMLHRElement::HTMLHRElement(const QualifiedName& tagName, Document& document) |
40 | : HTMLElement(tagName, document) |
41 | { |
42 | ASSERT(hasTagName(hrTag)); |
43 | } |
44 | |
45 | Ref<HTMLHRElement> HTMLHRElement::create(Document& document) |
46 | { |
47 | return adoptRef(*new HTMLHRElement(hrTag, document)); |
48 | } |
49 | |
50 | Ref<HTMLHRElement> HTMLHRElement::create(const QualifiedName& tagName, Document& document) |
51 | { |
52 | return adoptRef(*new HTMLHRElement(tagName, document)); |
53 | } |
54 | |
55 | bool HTMLHRElement::isPresentationAttribute(const QualifiedName& name) const |
56 | { |
57 | if (name == widthAttr || name == colorAttr || name == noshadeAttr || name == sizeAttr) |
58 | return true; |
59 | return HTMLElement::isPresentationAttribute(name); |
60 | } |
61 | |
62 | void HTMLHRElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) |
63 | { |
64 | if (name == alignAttr) { |
65 | if (equalLettersIgnoringASCIICase(value, "left" )) { |
66 | addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, 0, CSSPrimitiveValue::CSS_PX); |
67 | addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto); |
68 | } else if (equalLettersIgnoringASCIICase(value, "right" )) { |
69 | addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, CSSValueAuto); |
70 | addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, 0, CSSPrimitiveValue::CSS_PX); |
71 | } else { |
72 | addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, CSSValueAuto); |
73 | addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto); |
74 | } |
75 | } else if (name == widthAttr) { |
76 | bool ok; |
77 | int v = value.toInt(&ok); |
78 | if (ok && !v) |
79 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 1, CSSPrimitiveValue::CSS_PX); |
80 | else |
81 | addHTMLLengthToStyle(style, CSSPropertyWidth, value); |
82 | } else if (name == colorAttr) { |
83 | addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid); |
84 | addHTMLColorToStyle(style, CSSPropertyBorderColor, value); |
85 | addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value); |
86 | } else if (name == noshadeAttr) { |
87 | if (!hasAttributeWithoutSynchronization(colorAttr)) { |
88 | addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid); |
89 | |
90 | RefPtr<CSSPrimitiveValue> darkGrayValue = CSSValuePool::singleton().createColorValue(Color::darkGray); |
91 | style.setProperty(CSSPropertyBorderColor, darkGrayValue); |
92 | style.setProperty(CSSPropertyBackgroundColor, darkGrayValue); |
93 | } |
94 | } else if (name == sizeAttr) { |
95 | StringImpl* si = value.impl(); |
96 | int size = si->toInt(); |
97 | if (size <= 1) |
98 | addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomWidth, 0, CSSPrimitiveValue::CSS_PX); |
99 | else |
100 | addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, size - 2, CSSPrimitiveValue::CSS_PX); |
101 | } else |
102 | HTMLElement::collectStyleForPresentationAttribute(name, value, style); |
103 | } |
104 | |
105 | bool HTMLHRElement::canContainRangeEndPoint() const |
106 | { |
107 | return hasChildNodes() && HTMLElement::canContainRangeEndPoint(); |
108 | } |
109 | |
110 | } |
111 | |