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 "HTMLNames.h" 30 31namespace WebCore { 32 33using namespace HTMLNames; 34 35HTMLHRElement::HTMLHRElement(const QualifiedName& tagName, Document* document) 36 : HTMLElement(tagName, document) 37{ 38 ASSERT(hasTagName(hrTag)); 39} 40 41PassRefPtr<HTMLHRElement> HTMLHRElement::create(Document* document) 42{ 43 return adoptRef(new HTMLHRElement(hrTag, document)); 44} 45 46PassRefPtr<HTMLHRElement> HTMLHRElement::create(const QualifiedName& tagName, Document* document) 47{ 48 return adoptRef(new HTMLHRElement(tagName, document)); 49} 50 51bool HTMLHRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const 52{ 53 if (attrName == alignAttr || 54 attrName == widthAttr || 55 attrName == colorAttr || 56 attrName == sizeAttr || 57 attrName == noshadeAttr) { 58 result = eHR; 59 return false; 60 } 61 return HTMLElement::mapToEntry(attrName, result); 62} 63 64void HTMLHRElement::parseMappedAttribute(Attribute* attr) 65{ 66 if (attr->name() == alignAttr) { 67 if (equalIgnoringCase(attr->value(), "left")) { 68 addCSSProperty(attr, CSSPropertyMarginLeft, "0"); 69 addCSSProperty(attr, CSSPropertyMarginRight, CSSValueAuto); 70 } else if (equalIgnoringCase(attr->value(), "right")) { 71 addCSSProperty(attr, CSSPropertyMarginLeft, CSSValueAuto); 72 addCSSProperty(attr, CSSPropertyMarginRight, "0"); 73 } else { 74 addCSSProperty(attr, CSSPropertyMarginLeft, CSSValueAuto); 75 addCSSProperty(attr, CSSPropertyMarginRight, CSSValueAuto); 76 } 77 } else if (attr->name() == widthAttr) { 78 bool ok; 79 int v = attr->value().toInt(&ok); 80 if (ok && !v) 81 addCSSLength(attr, CSSPropertyWidth, "1"); 82 else 83 addCSSLength(attr, CSSPropertyWidth, attr->value()); 84 } else if (attr->name() == colorAttr) { 85 addCSSProperty(attr, CSSPropertyBorderTopStyle, CSSValueSolid); 86 addCSSProperty(attr, CSSPropertyBorderRightStyle, CSSValueSolid); 87 addCSSProperty(attr, CSSPropertyBorderBottomStyle, CSSValueSolid); 88 addCSSProperty(attr, CSSPropertyBorderLeftStyle, CSSValueSolid); 89 addCSSColor(attr, CSSPropertyBorderColor, attr->value()); 90 addCSSColor(attr, CSSPropertyBackgroundColor, attr->value()); 91 } else if (attr->name() == noshadeAttr) { 92 addCSSProperty(attr, CSSPropertyBorderTopStyle, CSSValueSolid); 93 addCSSProperty(attr, CSSPropertyBorderRightStyle, CSSValueSolid); 94 addCSSProperty(attr, CSSPropertyBorderBottomStyle, CSSValueSolid); 95 addCSSProperty(attr, CSSPropertyBorderLeftStyle, CSSValueSolid); 96 addCSSColor(attr, CSSPropertyBorderColor, String("grey")); 97 addCSSColor(attr, CSSPropertyBackgroundColor, String("grey")); 98 } else if (attr->name() == sizeAttr) { 99 StringImpl* si = attr->value().impl(); 100 int size = si->toInt(); 101 if (size <= 1) 102 addCSSProperty(attr, CSSPropertyBorderBottomWidth, String("0")); 103 else 104 addCSSLength(attr, CSSPropertyHeight, String::number(size-2)); 105 } else 106 HTMLElement::parseMappedAttribute(attr); 107} 108 109} 110