fix logic
[personal-kdelibs.git] / khtml / html / html_listimpl.cpp
blobe1650af4652d1f8c21d4f5e3b968e68c6f8031ce
1 /**
2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #include "html_listimpl.h"
25 using namespace DOM;
27 #include "css/cssproperties.h"
28 #include "css/cssvalues.h"
29 #include "rendering/render_list.h"
30 #include "misc/htmlhashes.h"
31 #include "xml/dom_docimpl.h"
33 using namespace khtml;
35 NodeImpl::Id HTMLUListElementImpl::id() const
37 return ID_UL;
40 void HTMLUListElementImpl::parseAttribute(AttributeImpl *attr)
42 switch(attr->id())
44 case ATTR_TYPE:
45 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, attr->value());
46 break;
47 default:
48 HTMLElementImpl::parseAttribute(attr);
52 // -------------------------------------------------------------------------
54 NodeImpl::Id HTMLDirectoryElementImpl::id() const
56 return ID_DIR;
59 // -------------------------------------------------------------------------
61 NodeImpl::Id HTMLMenuElementImpl::id() const
63 return ID_MENU;
66 // -------------------------------------------------------------------------
68 NodeImpl::Id HTMLOListElementImpl::id() const
70 return ID_OL;
73 void HTMLOListElementImpl::parseAttribute(AttributeImpl *attr)
75 switch(attr->id())
77 case ATTR_TYPE:
78 if ( strcmp( attr->value(), "a" ) == 0 )
79 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA);
80 else if ( strcmp( attr->value(), "A" ) == 0 )
81 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA);
82 else if ( strcmp( attr->value(), "i" ) == 0 )
83 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN);
84 else if ( strcmp( attr->value(), "I" ) == 0 )
85 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN);
86 else if ( strcmp( attr->value(), "1" ) == 0 )
87 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL);
88 break;
89 case ATTR_START:
90 _start = attr->val() ? attr->val()->toInt() : 1;
91 break;
92 default:
93 HTMLUListElementImpl::parseAttribute(attr);
97 // -------------------------------------------------------------------------
99 NodeImpl::Id HTMLLIElementImpl::id() const
101 return ID_LI;
104 void HTMLLIElementImpl::parseAttribute(AttributeImpl *attr)
106 switch(attr->id())
108 case ATTR_VALUE:
109 if(m_render && m_render->isListItem() && m_render->style()->display() == LIST_ITEM)
110 static_cast<RenderListItem*>(m_render)->setValue(attr->value().toInt());
111 break;
112 case ATTR_TYPE:
113 if ( strcmp( attr->value(), "a" ) == 0 )
114 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA);
115 else if ( strcmp( attr->value(), "A" ) == 0 )
116 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA);
117 else if ( strcmp( attr->value(), "i" ) == 0 )
118 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN);
119 else if ( strcmp( attr->value(), "I" ) == 0 )
120 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN);
121 else if ( strcmp( attr->value(), "1" ) == 0 )
122 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL);
123 else
124 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, attr->value());
125 break;
126 default:
127 HTMLElementImpl::parseAttribute(attr);
131 void HTMLLIElementImpl::attach()
133 assert(!attached());
135 HTMLElementImpl::attach();
137 if ( m_render && m_render->style()->display() == LIST_ITEM ) {
138 RenderListItem* render = static_cast<RenderListItem*>( renderer() );
139 NodeImpl* listNode = 0;
140 NodeImpl* n = parentNode();
141 while ( !listNode && n ) {
142 switch( n->id() ) {
143 case ID_UL:
144 case ID_OL:
145 listNode = n;
146 break;
148 n = n->parentNode();
151 // if we are not in a list, then position us inside
152 // can't use addCSSProperty cause its inherited attribute
153 render->setInsideList( listNode );
155 DOMString v = getAttribute(ATTR_VALUE);
156 if ( !v.isEmpty() )
157 render->setValue( v.implementation()->toInt() );
162 // -------------------------------------------------------------------------
165 NodeImpl::Id HTMLDListElementImpl::id() const
167 return ID_DL;