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 "core/CSSPropertyNames.h"
27 #include "core/CSSValueKeywords.h"
28 #include "core/HTMLNames.h"
29 #include "core/dom/NodeRenderingTraversal.h"
30 #include "core/rendering/RenderListItem.h"
34 using namespace HTMLNames;
36 inline HTMLLIElement::HTMLLIElement(Document& document)
37 : HTMLElement(liTag, document)
39 ScriptWrappable::init(this);
42 DEFINE_NODE_FACTORY(HTMLLIElement)
44 bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const
48 return HTMLElement::isPresentationAttribute(name);
51 void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
53 if (name == typeAttr) {
55 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha);
56 else if (value == "A")
57 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha);
58 else if (value == "i")
59 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman);
60 else if (value == "I")
61 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman);
62 else if (value == "1")
63 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal);
65 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value);
67 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
70 void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
72 if (name == valueAttr) {
73 if (renderer() && renderer()->isListItem())
76 HTMLElement::parseAttribute(name, value);
79 void HTMLLIElement::attach(const AttachContext& context)
81 HTMLElement::attach(context);
83 if (renderer() && renderer()->isListItem()) {
84 RenderListItem* listItemRenderer = toRenderListItem(renderer());
86 ASSERT(!document().childNeedsDistributionRecalc());
88 // Find the enclosing list node.
89 Element* listNode = 0;
90 Element* current = this;
92 current = NodeRenderingTraversal::parentElement(current);
95 if (isHTMLUListElement(*current) || isHTMLOListElement(*current))
99 // If we are not in a list, tell the renderer so it can position us inside.
100 // We don't want to change our style to say "inside" since that would affect nested nodes.
102 listItemRenderer->setNotInList(true);
104 parseValue(fastGetAttribute(valueAttr));
108 inline void HTMLLIElement::parseValue(const AtomicString& value)
110 ASSERT(renderer() && renderer()->isListItem());
113 int requestedValue = value.toInt(&valueOK);
115 toRenderListItem(renderer())->setExplicitValue(requestedValue);
117 toRenderListItem(renderer())->clearExplicitValue();