File indexing completed on 2024-05-05 16:10:13
0001 /** 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 0005 * (C) 1999 Antti Koivisto (koivisto@kde.org) 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Library General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Library General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Library General Public License 0018 * along with this library; see the file COPYING.LIB. If not, write to 0019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 * 0022 */ 0023 #include "html_listimpl.h" 0024 0025 using namespace DOM; 0026 0027 #include "css/cssproperties.h" 0028 #include "css/cssvalues.h" 0029 #include "rendering/render_list.h" 0030 #include "xml/dom_docimpl.h" 0031 0032 using namespace khtml; 0033 0034 NodeImpl::Id HTMLUListElementImpl::id() const 0035 { 0036 return ID_UL; 0037 } 0038 0039 void HTMLUListElementImpl::parseAttribute(AttributeImpl *attr) 0040 { 0041 switch (attr->id()) { 0042 case ATTR_TYPE: 0043 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, attr->value()); 0044 break; 0045 default: 0046 HTMLElementImpl::parseAttribute(attr); 0047 } 0048 } 0049 0050 // ------------------------------------------------------------------------- 0051 0052 NodeImpl::Id HTMLDirectoryElementImpl::id() const 0053 { 0054 return ID_DIR; 0055 } 0056 0057 // ------------------------------------------------------------------------- 0058 0059 NodeImpl::Id HTMLMenuElementImpl::id() const 0060 { 0061 return ID_MENU; 0062 } 0063 0064 // ------------------------------------------------------------------------- 0065 0066 NodeImpl::Id HTMLOListElementImpl::id() const 0067 { 0068 return ID_OL; 0069 } 0070 0071 void HTMLOListElementImpl::parseAttribute(AttributeImpl *attr) 0072 { 0073 switch (attr->id()) { 0074 case ATTR_TYPE: 0075 if (strcmp(attr->value(), "a") == 0) { 0076 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA); 0077 } else if (strcmp(attr->value(), "A") == 0) { 0078 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA); 0079 } else if (strcmp(attr->value(), "i") == 0) { 0080 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN); 0081 } else if (strcmp(attr->value(), "I") == 0) { 0082 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN); 0083 } else if (strcmp(attr->value(), "1") == 0) { 0084 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL); 0085 } 0086 break; 0087 case ATTR_START: 0088 _start = attr->val() ? attr->val()->toInt() : 1; 0089 break; 0090 default: 0091 HTMLUListElementImpl::parseAttribute(attr); 0092 } 0093 } 0094 0095 // ------------------------------------------------------------------------- 0096 0097 NodeImpl::Id HTMLLIElementImpl::id() const 0098 { 0099 return ID_LI; 0100 } 0101 0102 void HTMLLIElementImpl::parseAttribute(AttributeImpl *attr) 0103 { 0104 switch (attr->id()) { 0105 case ATTR_VALUE: 0106 if (m_render && m_render->isListItem() && m_render->style()->display() == LIST_ITEM) { 0107 static_cast<RenderListItem *>(m_render)->setValue(attr->value().toInt()); 0108 } 0109 break; 0110 case ATTR_TYPE: 0111 if (strcmp(attr->value(), "a") == 0) { 0112 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA); 0113 } else if (strcmp(attr->value(), "A") == 0) { 0114 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA); 0115 } else if (strcmp(attr->value(), "i") == 0) { 0116 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN); 0117 } else if (strcmp(attr->value(), "I") == 0) { 0118 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN); 0119 } else if (strcmp(attr->value(), "1") == 0) { 0120 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL); 0121 } else { 0122 addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, attr->value()); 0123 } 0124 break; 0125 default: 0126 HTMLElementImpl::parseAttribute(attr); 0127 } 0128 } 0129 0130 void HTMLLIElementImpl::attach() 0131 { 0132 assert(!attached()); 0133 0134 HTMLElementImpl::attach(); 0135 0136 if (m_render && m_render->style()->display() == LIST_ITEM) { 0137 RenderListItem *render = static_cast<RenderListItem *>(renderer()); 0138 NodeImpl *listNode = nullptr; 0139 NodeImpl *n = parentNode(); 0140 while (!listNode && n) { 0141 switch (n->id()) { 0142 case ID_UL: 0143 case ID_OL: 0144 listNode = n; 0145 break; 0146 } 0147 n = n->parentNode(); 0148 } 0149 0150 // if we are not in a list, then position us inside 0151 // can't use addCSSProperty cause its inherited attribute 0152 render->setInsideList(listNode); 0153 0154 DOMString v = getAttribute(ATTR_VALUE); 0155 if (!v.isEmpty()) { 0156 render->setValue(v.implementation()->toInt()); 0157 } 0158 } 0159 } 0160 0161 // ------------------------------------------------------------------------- 0162 0163 NodeImpl::Id HTMLDListElementImpl::id() const 0164 { 0165 return ID_DL; 0166 } 0167