Home | History | Annotate | Download | only in html
      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 blink {
     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 }
     44 
     45 DEFINE_NODE_FACTORY(HTMLOListElement)
     46 
     47 bool HTMLOListElement::isPresentationAttribute(const QualifiedName& name) const
     48 {
     49     if (name == typeAttr)
     50         return true;
     51     return HTMLElement::isPresentationAttribute(name);
     52 }
     53 
     54 void HTMLOListElement::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         HTMLElement::collectStyleForPresentationAttribute(name, value, style);
     69 }
     70 
     71 void HTMLOListElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
     72 {
     73     if (name == startAttr) {
     74         int oldStart = start();
     75         bool canParse;
     76         int parsedStart = value.toInt(&canParse);
     77         m_hasExplicitStart = canParse;
     78         m_start = canParse ? parsedStart : 0xBADBEEF;
     79         if (oldStart == start())
     80             return;
     81         updateItemValues();
     82     } else if (name == reversedAttr) {
     83         bool reversed = !value.isNull();
     84         if (reversed == m_isReversed)
     85             return;
     86         m_isReversed = reversed;
     87         updateItemValues();
     88     } else
     89         HTMLElement::parseAttribute(name, value);
     90 }
     91 
     92 void HTMLOListElement::setStart(int start)
     93 {
     94     setIntegralAttribute(startAttr, start);
     95 }
     96 
     97 void HTMLOListElement::updateItemValues()
     98 {
     99     if (!renderer())
    100         return;
    101     document().updateDistributionForNodeIfNeeded(this);
    102     RenderListItem::updateItemValuesForOrderedList(this);
    103 }
    104 
    105 void HTMLOListElement::recalculateItemCount()
    106 {
    107     m_itemCount = RenderListItem::itemCountForOrderedList(this);
    108     m_shouldRecalculateItemCount = false;
    109 }
    110 
    111 }
    112