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.
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.
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.
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.
24 #include "core/html/HTMLLIElement.h"
26 #include "CSSPropertyNames.h"
27 #include "CSSValueKeywords.h"
28 #include "HTMLNames.h"
29 #include "core/dom/NodeRenderingTraversal.h"
30 #include "core/rendering/RenderListItem.h"
34 using namespace HTMLNames;
36 HTMLLIElement::HTMLLIElement(Document& document)
37 : HTMLElement(liTag, document)
39 ScriptWrappable::init(this);
42 PassRefPtrWillBeRawPtr<HTMLLIElement> HTMLLIElement::create(Document& document)
44 return adoptRefWillBeRefCountedGarbageCollected(new HTMLLIElement(document));
47 bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const
51 return HTMLElement::isPresentationAttribute(name);
54 void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
56 if (name == typeAttr) {
58 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha);
59 else if (value == "A")
60 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha);
61 else if (value == "i")
62 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman);
63 else if (value == "I")
64 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman);
65 else if (value == "1")
66 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal);
68 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value);
70 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
73 void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
75 if (name == valueAttr) {
76 if (renderer() && renderer()->isListItem())
79 HTMLElement::parseAttribute(name, value);
82 void HTMLLIElement::attach(const AttachContext& context)
84 HTMLElement::attach(context);
86 if (renderer() && renderer()->isListItem()) {
87 RenderListItem* listItemRenderer = toRenderListItem(renderer());
89 ASSERT(!document().childNeedsDistributionRecalc());
91 // Find the enclosing list node.
92 Element* listNode = 0;
93 Element* current = this;
95 current = NodeRenderingTraversal::parentElement(current);
98 if (isHTMLUListElement(*current) || isHTMLOListElement(*current))
102 // If we are not in a list, tell the renderer so it can position us inside.
103 // We don't want to change our style to say "inside" since that would affect nested nodes.
105 listItemRenderer->setNotInList(true);
106 listItemRenderer->updateMarkerLocation();
109 parseValue(fastGetAttribute(valueAttr));
113 inline void HTMLLIElement::parseValue(const AtomicString& value)
115 ASSERT(renderer() && renderer()->isListItem());
118 int requestedValue = value.toInt(&valueOK);
120 toRenderListItem(renderer())->setExplicitValue(requestedValue);
122 toRenderListItem(renderer())->clearExplicitValue();