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