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) 2006, 2007 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 "HTMLLIElement.h"
     25 
     26 #include "CSSPropertyNames.h"
     27 #include "CSSValueKeywords.h"
     28 #include "HTMLNames.h"
     29 #include "MappedAttribute.h"
     30 #include "RenderListItem.h"
     31 
     32 namespace WebCore {
     33 
     34 using namespace HTMLNames;
     35 
     36 HTMLLIElement::HTMLLIElement(const QualifiedName& tagName, Document* doc)
     37     : HTMLElement(tagName, doc)
     38     , m_requestedValue(0)
     39 {
     40     ASSERT(hasTagName(liTag));
     41 }
     42 
     43 bool HTMLLIElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
     44 {
     45     if (attrName == typeAttr) {
     46         result = eListItem; // Share with <ol> since all the values are the same
     47         return false;
     48     }
     49 
     50     return HTMLElement::mapToEntry(attrName, result);
     51 }
     52 
     53 void HTMLLIElement::parseMappedAttribute(MappedAttribute* attr)
     54 {
     55     if (attr->name() == valueAttr) {
     56         m_requestedValue = attr->value().toInt();
     57         if (renderer() && renderer()->isListItem()) {
     58             if (m_requestedValue > 0)
     59                 toRenderListItem(renderer())->setExplicitValue(m_requestedValue);
     60             else
     61                 toRenderListItem(renderer())->clearExplicitValue();
     62         }
     63     } else if (attr->name() == typeAttr) {
     64         if (attr->value() == "a")
     65             addCSSProperty(attr, CSSPropertyListStyleType, CSSValueLowerAlpha);
     66         else if (attr->value() == "A")
     67             addCSSProperty(attr, CSSPropertyListStyleType, CSSValueUpperAlpha);
     68         else if (attr->value() == "i")
     69             addCSSProperty(attr, CSSPropertyListStyleType, CSSValueLowerRoman);
     70         else if (attr->value() == "I")
     71             addCSSProperty(attr, CSSPropertyListStyleType, CSSValueUpperRoman);
     72         else if (attr->value() == "1")
     73             addCSSProperty(attr, CSSPropertyListStyleType, CSSValueDecimal);
     74         else
     75             addCSSProperty(attr, CSSPropertyListStyleType, attr->value());
     76     } else
     77         HTMLElement::parseMappedAttribute(attr);
     78 }
     79 
     80 void HTMLLIElement::attach()
     81 {
     82     ASSERT(!attached());
     83 
     84     HTMLElement::attach();
     85 
     86     if (renderer() && renderer()->isListItem()) {
     87         RenderListItem* render = toRenderListItem(renderer());
     88 
     89         // Find the enclosing list node.
     90         Node* listNode = 0;
     91         Node* n = this;
     92         while (!listNode && (n = n->parentNode())) {
     93             if (n->hasTagName(ulTag) || n->hasTagName(olTag))
     94                 listNode = n;
     95         }
     96 
     97         // If we are not in a list, tell the renderer so it can position us inside.
     98         // We don't want to change our style to say "inside" since that would affect nested nodes.
     99         if (!listNode)
    100             render->setNotInList(true);
    101 
    102         if (m_requestedValue > 0)
    103             render->setExplicitValue(m_requestedValue);
    104         else
    105             render->clearExplicitValue();
    106     }
    107 }
    108 
    109 String HTMLLIElement::type() const
    110 {
    111     return getAttribute(typeAttr);
    112 }
    113 
    114 void HTMLLIElement::setType(const String& value)
    115 {
    116     setAttribute(typeAttr, value);
    117 }
    118 
    119 int HTMLLIElement::value() const
    120 {
    121     return getAttribute(valueAttr).toInt();
    122 }
    123 
    124 void HTMLLIElement::setValue(int value)
    125 {
    126     setAttribute(valueAttr, String::number(value));
    127 }
    128 
    129 }
    130