Upstream version 9.38.198.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 "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"
31
32 namespace blink {
33
34 using namespace HTMLNames;
35
36 inline HTMLLIElement::HTMLLIElement(Document& document)
37     : HTMLElement(liTag, document)
38 {
39     ScriptWrappable::init(this);
40 }
41
42 DEFINE_NODE_FACTORY(HTMLLIElement)
43
44 bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const
45 {
46     if (name == typeAttr)
47         return true;
48     return HTMLElement::isPresentationAttribute(name);
49 }
50
51 void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
52 {
53     if (name == typeAttr) {
54         if (value == "a")
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);
64         else
65             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value);
66     } else
67         HTMLElement::collectStyleForPresentationAttribute(name, value, style);
68 }
69
70 void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
71 {
72     if (name == valueAttr) {
73         if (renderer() && renderer()->isListItem())
74             parseValue(value);
75     } else
76         HTMLElement::parseAttribute(name, value);
77 }
78
79 void HTMLLIElement::attach(const AttachContext& context)
80 {
81     HTMLElement::attach(context);
82
83     if (renderer() && renderer()->isListItem()) {
84         RenderListItem* listItemRenderer = toRenderListItem(renderer());
85
86         ASSERT(!document().childNeedsDistributionRecalc());
87
88         // Find the enclosing list node.
89         Element* listNode = 0;
90         Element* current = this;
91         while (!listNode) {
92             current = NodeRenderingTraversal::parentElement(current);
93             if (!current)
94                 break;
95             if (isHTMLUListElement(*current) || isHTMLOListElement(*current))
96                 listNode = current;
97         }
98
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.
101         if (!listNode)
102             listItemRenderer->setNotInList(true);
103
104         parseValue(fastGetAttribute(valueAttr));
105     }
106 }
107
108 inline void HTMLLIElement::parseValue(const AtomicString& value)
109 {
110     ASSERT(renderer() && renderer()->isListItem());
111
112     bool valueOK;
113     int requestedValue = value.toInt(&valueOK);
114     if (valueOK)
115         toRenderListItem(renderer())->setExplicitValue(requestedValue);
116     else
117         toRenderListItem(renderer())->clearExplicitValue();
118 }
119
120 }