1/* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * Copyright (C) 2006, 2007, 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 "HTMLLIElement.h" 25 26#include "Attribute.h" 27#include "CSSPropertyNames.h" 28#include "CSSValueKeywords.h" 29#include "HTMLNames.h" 30#include "RenderListItem.h" 31 32namespace WebCore { 33 34using namespace HTMLNames; 35 36HTMLLIElement::HTMLLIElement(const QualifiedName& tagName, Document& document) 37 : HTMLElement(tagName, document) 38{ 39 ASSERT(hasTagName(liTag)); 40 setHasCustomStyleResolveCallbacks(); 41} 42 43PassRefPtr<HTMLLIElement> HTMLLIElement::create(Document& document) 44{ 45 return adoptRef(new HTMLLIElement(liTag, document)); 46} 47 48PassRefPtr<HTMLLIElement> HTMLLIElement::create(const QualifiedName& tagName, Document& document) 49{ 50 return adoptRef(new HTMLLIElement(tagName, document)); 51} 52 53bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const 54{ 55 if (name == typeAttr) 56 return true; 57 return HTMLElement::isPresentationAttribute(name); 58} 59 60void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) 61{ 62 if (name == typeAttr) { 63 if (value == "a") 64 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha); 65 else if (value == "A") 66 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha); 67 else if (value == "i") 68 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman); 69 else if (value == "I") 70 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman); 71 else if (value == "1") 72 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal); 73 else 74 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value); 75 } else 76 HTMLElement::collectStyleForPresentationAttribute(name, value, style); 77} 78 79void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 80{ 81 if (name == valueAttr) { 82 if (renderer() && renderer()->isListItem()) 83 parseValue(value); 84 } else 85 HTMLElement::parseAttribute(name, value); 86} 87 88void HTMLLIElement::didAttachRenderers() 89{ 90 if (!renderer() || !renderer()->isListItem()) 91 return; 92 RenderListItem* listItemRenderer = toRenderListItem(renderer()); 93 94 // Find the enclosing list node. 95 Element* listNode = 0; 96 Element* current = this; 97 while (!listNode) { 98 current = current->parentElement(); 99 if (!current) 100 break; 101 if (current->hasTagName(ulTag) || current->hasTagName(olTag)) 102 listNode = current; 103 } 104 105 // If we are not in a list, tell the renderer so it can position us inside. 106 // We don't want to change our style to say "inside" since that would affect nested nodes. 107 if (!listNode) 108 listItemRenderer->setNotInList(true); 109 110 parseValue(fastGetAttribute(valueAttr)); 111} 112 113inline void HTMLLIElement::parseValue(const AtomicString& value) 114{ 115 ASSERT(renderer() && renderer()->isListItem()); 116 117 bool valueOK; 118 int requestedValue = value.toInt(&valueOK); 119 if (valueOK) 120 toRenderListItem(renderer())->setExplicitValue(requestedValue); 121 else 122 toRenderListItem(renderer())->clearExplicitValue(); 123} 124 125} 126