Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLOListElement.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  * Copyright (C) 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/HTMLOListElement.h"
25
26 #include "CSSPropertyNames.h"
27 #include "CSSValueKeywords.h"
28 #include "HTMLNames.h"
29 #include "core/rendering/RenderListItem.h"
30
31 namespace WebCore {
32
33 using namespace HTMLNames;
34
35 HTMLOListElement::HTMLOListElement(Document& document)
36     : HTMLElement(olTag, document)
37     , m_start(0xBADBEEF)
38     , m_itemCount(0)
39     , m_hasExplicitStart(false)
40     , m_isReversed(false)
41     , m_shouldRecalculateItemCount(false)
42 {
43     ScriptWrappable::init(this);
44 }
45
46 PassRefPtrWillBeRawPtr<HTMLOListElement> HTMLOListElement::create(Document& document)
47 {
48     return adoptRefWillBeRefCountedGarbageCollected(new HTMLOListElement(document));
49 }
50
51 bool HTMLOListElement::isPresentationAttribute(const QualifiedName& name) const
52 {
53     if (name == typeAttr)
54         return true;
55     return HTMLElement::isPresentationAttribute(name);
56 }
57
58 void HTMLOListElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
59 {
60     if (name == typeAttr) {
61         if (value == "a")
62             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha);
63         else if (value == "A")
64             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha);
65         else if (value == "i")
66             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman);
67         else if (value == "I")
68             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman);
69         else if (value == "1")
70             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal);
71     } else
72         HTMLElement::collectStyleForPresentationAttribute(name, value, style);
73 }
74
75 void HTMLOListElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
76 {
77     if (name == startAttr) {
78         int oldStart = start();
79         bool canParse;
80         int parsedStart = value.toInt(&canParse);
81         m_hasExplicitStart = canParse;
82         m_start = canParse ? parsedStart : 0xBADBEEF;
83         if (oldStart == start())
84             return;
85         updateItemValues();
86     } else if (name == reversedAttr) {
87         bool reversed = !value.isNull();
88         if (reversed == m_isReversed)
89             return;
90         m_isReversed = reversed;
91         updateItemValues();
92     } else
93         HTMLElement::parseAttribute(name, value);
94 }
95
96 void HTMLOListElement::setStart(int start)
97 {
98     setIntegralAttribute(startAttr, start);
99 }
100
101 void HTMLOListElement::updateItemValues()
102 {
103     if (!renderer())
104         return;
105     document().updateDistributionForNodeIfNeeded(this);
106     RenderListItem::updateItemValuesForOrderedList(this);
107 }
108
109 void HTMLOListElement::recalculateItemCount()
110 {
111     m_itemCount = RenderListItem::itemCountForOrderedList(this);
112     m_shouldRecalculateItemCount = false;
113 }
114
115 }