| 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 "HTMLOListElement.h" |
| 25 | |
| 26 | #include "CSSPropertyNames.h" |
| 27 | #include "CSSValueKeywords.h" |
| 28 | #include "HTMLNames.h" |
| 29 | #include "HTMLParserIdioms.h" |
| 30 | #include "RenderListItem.h" |
| 31 | #include <wtf/IsoMallocInlines.h> |
| 32 | |
| 33 | // FIXME: There should be a standard way to turn a std::expected into a Optional. |
| 34 | // Maybe we should put this into the header file for Expected and give it a better name. |
| 35 | template<typename T, typename E> inline Optional<T> optionalValue(Expected<T, E>&& expected) |
| 36 | { |
| 37 | return expected ? Optional<T>(WTFMove(expected.value())) : WTF::nullopt; |
| 38 | } |
| 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLOListElement); |
| 43 | |
| 44 | using namespace HTMLNames; |
| 45 | |
| 46 | inline HTMLOListElement::HTMLOListElement(const QualifiedName& tagName, Document& document) |
| 47 | : HTMLElement(tagName, document) |
| 48 | { |
| 49 | ASSERT(hasTagName(olTag)); |
| 50 | } |
| 51 | |
| 52 | Ref<HTMLOListElement> HTMLOListElement::create(Document& document) |
| 53 | { |
| 54 | return adoptRef(*new HTMLOListElement(olTag, document)); |
| 55 | } |
| 56 | |
| 57 | Ref<HTMLOListElement> HTMLOListElement::create(const QualifiedName& tagName, Document& document) |
| 58 | { |
| 59 | return adoptRef(*new HTMLOListElement(tagName, document)); |
| 60 | } |
| 61 | |
| 62 | bool HTMLOListElement::isPresentationAttribute(const QualifiedName& name) const |
| 63 | { |
| 64 | if (name == typeAttr) |
| 65 | return true; |
| 66 | return HTMLElement::isPresentationAttribute(name); |
| 67 | } |
| 68 | |
| 69 | void HTMLOListElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) |
| 70 | { |
| 71 | if (name == typeAttr) { |
| 72 | if (value == "a" ) |
| 73 | addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha); |
| 74 | else if (value == "A" ) |
| 75 | addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha); |
| 76 | else if (value == "i" ) |
| 77 | addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman); |
| 78 | else if (value == "I" ) |
| 79 | addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman); |
| 80 | else if (value == "1" ) |
| 81 | addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal); |
| 82 | } else |
| 83 | HTMLElement::collectStyleForPresentationAttribute(name, value, style); |
| 84 | } |
| 85 | |
| 86 | void HTMLOListElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 87 | { |
| 88 | if (name == startAttr) { |
| 89 | int oldStart = start(); |
| 90 | m_start = optionalValue(parseHTMLInteger(value)); |
| 91 | if (oldStart == start()) |
| 92 | return; |
| 93 | RenderListItem::updateItemValuesForOrderedList(*this); |
| 94 | } else if (name == reversedAttr) { |
| 95 | bool reversed = !value.isNull(); |
| 96 | if (reversed == m_isReversed) |
| 97 | return; |
| 98 | m_isReversed = reversed; |
| 99 | RenderListItem::updateItemValuesForOrderedList(*this); |
| 100 | } else |
| 101 | HTMLElement::parseAttribute(name, value); |
| 102 | } |
| 103 | |
| 104 | void HTMLOListElement::setStartForBindings(int start) |
| 105 | { |
| 106 | setIntegralAttribute(startAttr, start); |
| 107 | } |
| 108 | |
| 109 | unsigned HTMLOListElement::itemCount() const |
| 110 | { |
| 111 | if (!m_itemCount) |
| 112 | m_itemCount = RenderListItem::itemCountForOrderedList(*this); |
| 113 | return m_itemCount.value(); |
| 114 | } |
| 115 | |
| 116 | } |
| 117 | |