1 /**
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
6  *
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.
11  *
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.
16  *
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.
21  *
22  */
23 #include "html_listimpl.h"
24 
25 using namespace DOM;
26 
27 #include "css/cssproperties.h"
28 #include "css/cssvalues.h"
29 #include "rendering/render_list.h"
30 #include "xml/dom_docimpl.h"
31 
32 using namespace khtml;
33 
id() const34 NodeImpl::Id HTMLUListElementImpl::id() const
35 {
36     return ID_UL;
37 }
38 
parseAttribute(AttributeImpl * attr)39 void HTMLUListElementImpl::parseAttribute(AttributeImpl *attr)
40 {
41     switch (attr->id()) {
42     case ATTR_TYPE:
43         addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, attr->value());
44         break;
45     default:
46         HTMLElementImpl::parseAttribute(attr);
47     }
48 }
49 
50 // -------------------------------------------------------------------------
51 
id() const52 NodeImpl::Id HTMLDirectoryElementImpl::id() const
53 {
54     return ID_DIR;
55 }
56 
57 // -------------------------------------------------------------------------
58 
id() const59 NodeImpl::Id HTMLMenuElementImpl::id() const
60 {
61     return ID_MENU;
62 }
63 
64 // -------------------------------------------------------------------------
65 
id() const66 NodeImpl::Id HTMLOListElementImpl::id() const
67 {
68     return ID_OL;
69 }
70 
parseAttribute(AttributeImpl * attr)71 void HTMLOListElementImpl::parseAttribute(AttributeImpl *attr)
72 {
73     switch (attr->id()) {
74     case ATTR_TYPE:
75         if (strcmp(attr->value(), "a") == 0) {
76             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA);
77         } else if (strcmp(attr->value(), "A") == 0) {
78             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA);
79         } else if (strcmp(attr->value(), "i") == 0) {
80             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN);
81         } else if (strcmp(attr->value(), "I") == 0) {
82             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN);
83         } else if (strcmp(attr->value(), "1") == 0) {
84             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL);
85         }
86         break;
87     case ATTR_START:
88         _start = attr->val() ? attr->val()->toInt() : 1;
89         break;
90     default:
91         HTMLUListElementImpl::parseAttribute(attr);
92     }
93 }
94 
95 // -------------------------------------------------------------------------
96 
id() const97 NodeImpl::Id HTMLLIElementImpl::id() const
98 {
99     return ID_LI;
100 }
101 
parseAttribute(AttributeImpl * attr)102 void HTMLLIElementImpl::parseAttribute(AttributeImpl *attr)
103 {
104     switch (attr->id()) {
105     case ATTR_VALUE:
106         if (m_render && m_render->isListItem() && m_render->style()->display() == LIST_ITEM) {
107             static_cast<RenderListItem *>(m_render)->setValue(attr->value().toInt());
108         }
109         break;
110     case ATTR_TYPE:
111         if (strcmp(attr->value(), "a") == 0) {
112             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA);
113         } else if (strcmp(attr->value(), "A") == 0) {
114             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA);
115         } else if (strcmp(attr->value(), "i") == 0) {
116             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN);
117         } else if (strcmp(attr->value(), "I") == 0) {
118             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN);
119         } else if (strcmp(attr->value(), "1") == 0) {
120             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL);
121         } else {
122             addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, attr->value());
123         }
124         break;
125     default:
126         HTMLElementImpl::parseAttribute(attr);
127     }
128 }
129 
attach()130 void HTMLLIElementImpl::attach()
131 {
132     assert(!attached());
133 
134     HTMLElementImpl::attach();
135 
136     if (m_render && m_render->style()->display() == LIST_ITEM) {
137         RenderListItem *render = static_cast<RenderListItem *>(renderer());
138         NodeImpl *listNode = nullptr;
139         NodeImpl *n = parentNode();
140         while (!listNode && n) {
141             switch (n->id()) {
142             case ID_UL:
143             case ID_OL:
144                 listNode = n;
145                 break;
146             }
147             n = n->parentNode();
148         }
149 
150         // if we are not in a list, then position us inside
151         // can't use addCSSProperty cause its inherited attribute
152         render->setInsideList(listNode);
153 
154         DOMString v = getAttribute(ATTR_VALUE);
155         if (!v.isEmpty()) {
156             render->setValue(v.implementation()->toInt());
157         }
158     }
159 }
160 
161 // -------------------------------------------------------------------------
162 
id() const163 NodeImpl::Id HTMLDListElementImpl::id() const
164 {
165     return ID_DL;
166 }
167 
168