Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLLIElement.cpp
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 "core/html/HTMLLIElement.h"
25
26 #include "CSSPropertyNames.h"
27 #include "CSSValueKeywords.h"
28 #include "HTMLNames.h"
29 #include "core/dom/NodeRenderingTraversal.h"
30 #include "core/rendering/RenderListItem.h"
31
32 namespace WebCore {
33
34 using namespace HTMLNames;
35
36 HTMLLIElement::HTMLLIElement(Document& document)
37     : HTMLElement(liTag, document)
38 {
39     ScriptWrappable::init(this);
40 }
41
42 PassRefPtrWillBeRawPtr<HTMLLIElement> HTMLLIElement::create(Document& document)
43 {
44     return adoptRefWillBeRefCountedGarbageCollected(new HTMLLIElement(document));
45 }
46
47 bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const
48 {
49     if (name == typeAttr)
50         return true;
51     return HTMLElement::isPresentationAttribute(name);
52 }
53
54 void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
55 {
56     if (name == typeAttr) {
57         if (value == "a")
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);
67         else
68             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value);
69     } else
70         HTMLElement::collectStyleForPresentationAttribute(name, value, style);
71 }
72
73 void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
74 {
75     if (name == valueAttr) {
76         if (renderer() && renderer()->isListItem())
77             parseValue(value);
78     } else
79         HTMLElement::parseAttribute(name, value);
80 }
81
82 void HTMLLIElement::attach(const AttachContext& context)
83 {
84     HTMLElement::attach(context);
85
86     if (renderer() && renderer()->isListItem()) {
87         RenderListItem* listItemRenderer = toRenderListItem(renderer());
88
89         ASSERT(!document().childNeedsDistributionRecalc());
90
91         // Find the enclosing list node.
92         Element* listNode = 0;
93         Element* current = this;
94         while (!listNode) {
95             current = NodeRenderingTraversal::parentElement(current);
96             if (!current)
97                 break;
98             if (isHTMLUListElement(*current) || isHTMLOListElement(*current))
99                 listNode = current;
100         }
101
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.
104         if (!listNode) {
105             listItemRenderer->setNotInList(true);
106             listItemRenderer->updateMarkerLocation();
107         }
108
109         parseValue(fastGetAttribute(valueAttr));
110     }
111 }
112
113 inline 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 }