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)
41 DEFINE_NODE_FACTORY(HTMLLIElement)
43 bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const
47 return HTMLElement::isPresentationAttribute(name);
50 void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
52 if (name == typeAttr) {
54 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha);
55 else if (value == "A")
56 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha);
57 else if (value == "i")
58 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman);
59 else if (value == "I")
60 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman);
61 else if (value == "1")
62 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal);
64 addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value);
66 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
69 void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
71 if (name == valueAttr) {
72 if (renderer() && renderer()->isListItem())
75 HTMLElement::parseAttribute(name, value);
78 void HTMLLIElement::attach(const AttachContext& context)
80 HTMLElement::attach(context);
82 if (renderer() && renderer()->isListItem()) {
83 RenderListItem* listItemRenderer = toRenderListItem(renderer());
85 ASSERT(!document().childNeedsDistributionRecalc());
87 // Find the enclosing list node.
88 Element* listNode = 0;
89 Element* current = this;
91 current = NodeRenderingTraversal::parentElement(current);
94 if (isHTMLUListElement(*current) || isHTMLOListElement(*current))
98 // If we are not in a list, tell the renderer so it can position us inside.
99 // We don't want to change our style to say "inside" since that would affect nested nodes.
101 listItemRenderer->setNotInList(true);
103 parseValue(fastGetAttribute(valueAttr));
107 inline void HTMLLIElement::parseValue(const AtomicString& value)
109 ASSERT(renderer() && renderer()->isListItem());
112 int requestedValue = value.toInt(&valueOK);
114 toRenderListItem(renderer())->setExplicitValue(requestedValue);
116 toRenderListItem(renderer())->clearExplicitValue();