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, 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/HTMLLIElement.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 HTMLLIElement::HTMLLIElement(const QualifiedName& tagName, Document* document)
     36     : HTMLElement(tagName, document)
     37 {
     38     ASSERT(hasTagName(liTag));
     39     ScriptWrappable::init(this);
     40 }
     41 
     42 PassRefPtr<HTMLLIElement> HTMLLIElement::create(Document* document)
     43 {
     44     return adoptRef(new HTMLLIElement(liTag, document));
     45 }
     46 
     47 PassRefPtr<HTMLLIElement> HTMLLIElement::create(const QualifiedName& tagName, Document* document)
     48 {
     49     return adoptRef(new HTMLLIElement(tagName, document));
     50 }
     51 
     52 bool HTMLLIElement::isPresentationAttribute(const QualifiedName& name) const
     53 {
     54     if (name == typeAttr)
     55         return true;
     56     return HTMLElement::isPresentationAttribute(name);
     57 }
     58 
     59 void HTMLLIElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
     60 {
     61     if (name == typeAttr) {
     62         if (value == "a")
     63             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerAlpha);
     64         else if (value == "A")
     65             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperAlpha);
     66         else if (value == "i")
     67             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueLowerRoman);
     68         else if (value == "I")
     69             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueUpperRoman);
     70         else if (value == "1")
     71             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, CSSValueDecimal);
     72         else
     73             addPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType, value);
     74     } else
     75         HTMLElement::collectStyleForPresentationAttribute(name, value, style);
     76 }
     77 
     78 void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
     79 {
     80     if (name == valueAttr) {
     81         if (renderer() && renderer()->isListItem())
     82             parseValue(value);
     83     } else
     84         HTMLElement::parseAttribute(name, value);
     85 }
     86 
     87 void HTMLLIElement::attach(const AttachContext& context)
     88 {
     89     ASSERT(!attached());
     90 
     91     HTMLElement::attach(context);
     92 
     93     if (renderer() && renderer()->isListItem()) {
     94         RenderListItem* listItemRenderer = toRenderListItem(renderer());
     95 
     96         // Find the enclosing list node.
     97         Element* listNode = 0;
     98         Element* current = this;
     99         while (!listNode) {
    100             current = current->parentElement();
    101             if (!current)
    102                 break;
    103             if (current->hasTagName(ulTag) || current->hasTagName(olTag))
    104                 listNode = current;
    105         }
    106 
    107         // If we are not in a list, tell the renderer so it can position us inside.
    108         // We don't want to change our style to say "inside" since that would affect nested nodes.
    109         if (!listNode)
    110             listItemRenderer->setNotInList(true);
    111 
    112         parseValue(fastGetAttribute(valueAttr));
    113     }
    114 }
    115 
    116 inline void HTMLLIElement::parseValue(const AtomicString& value)
    117 {
    118     ASSERT(renderer() && renderer()->isListItem());
    119 
    120     bool valueOK;
    121     int requestedValue = value.toInt(&valueOK);
    122     if (valueOK)
    123         toRenderListItem(renderer())->setExplicitValue(requestedValue);
    124     else
    125         toRenderListItem(renderer())->clearExplicitValue();
    126 }
    127 
    128 }
    129