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 "EventPathWalker.h" 30#include "HTMLNames.h" 31#include "RenderListItem.h" 32 33namespace WebCore { 34 35using namespace HTMLNames; 36 37HTMLLIElement::HTMLLIElement(const QualifiedName& tagName, Document* document) 38 : HTMLElement(tagName, document) 39{ 40 ASSERT(hasTagName(liTag)); 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, MutableStylePropertySet* 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::attach(const AttachContext& context) 89{ 90 ASSERT(!attached()); 91 92 HTMLElement::attach(context); 93 94 if (renderer() && renderer()->isListItem()) { 95 RenderListItem* listItemRenderer = toRenderListItem(renderer()); 96 97 // Find the enclosing list node. 98 Element* listNode = 0; 99 Element* current = this; 100 while (!listNode) { 101 current = current->parentElement(); 102 if (!current) 103 break; 104 if (current->hasTagName(ulTag) || current->hasTagName(olTag)) 105 listNode = current; 106 } 107 108 // If we are not in a list, tell the renderer so it can position us inside. 109 // We don't want to change our style to say "inside" since that would affect nested nodes. 110 if (!listNode) 111 listItemRenderer->setNotInList(true); 112 113 parseValue(fastGetAttribute(valueAttr)); 114 } 115} 116 117inline void HTMLLIElement::parseValue(const AtomicString& value) 118{ 119 ASSERT(renderer() && renderer()->isListItem()); 120 121 bool valueOK; 122 int requestedValue = value.toInt(&valueOK); 123 if (valueOK) 124 toRenderListItem(renderer())->setExplicitValue(requestedValue); 125 else 126 toRenderListItem(renderer())->clearExplicitValue(); 127} 128 129} 130