#include "html_listimpl.h"
using namespace DOM;
#include "css/cssproperties.h"
#include "css/cssvalues.h"
#include "rendering/render_list.h"
#include "misc/htmlhashes.h"
#include "xml/dom_docimpl.h"
using namespace khtml;
NodeImpl::Id HTMLUListElementImpl::id() const
{
return ID_UL;
}
bool HTMLUListElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
{
switch (attr) {
case ATTR_TYPE:
result = eUnorderedList;
return false;
default:
break;
}
return HTMLElementImpl::mapToEntry(attr, result);
}
void HTMLUListElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
switch(attr->id())
{
case ATTR_TYPE:
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, attr->value());
break;
default:
HTMLElementImpl::parseHTMLAttribute(attr);
}
}
NodeImpl::Id HTMLDirectoryElementImpl::id() const
{
return ID_DIR;
}
NodeImpl::Id HTMLMenuElementImpl::id() const
{
return ID_MENU;
}
NodeImpl::Id HTMLOListElementImpl::id() const
{
return ID_OL;
}
bool HTMLOListElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
{
switch (attr) {
case ATTR_TYPE:
result = eListItem; return false;
default:
break;
}
return HTMLElementImpl::mapToEntry(attr, result);
}
void HTMLOListElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
switch(attr->id())
{
case ATTR_TYPE:
if ( strcmp( attr->value(), "a" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA);
else if ( strcmp( attr->value(), "A" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA);
else if ( strcmp( attr->value(), "i" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN);
else if ( strcmp( attr->value(), "I" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN);
else if ( strcmp( attr->value(), "1" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL);
break;
case ATTR_START:
_start = !attr->isNull() ? attr->value().toInt() : 1;
default:
HTMLUListElementImpl::parseHTMLAttribute(attr);
}
}
NodeImpl::Id HTMLLIElementImpl::id() const
{
return ID_LI;
}
bool HTMLLIElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
{
switch (attr) {
case ATTR_TYPE:
result = eListItem; return false;
default:
break;
}
return HTMLElementImpl::mapToEntry(attr, result);
}
void HTMLLIElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
switch(attr->id())
{
case ATTR_VALUE:
isValued = true;
requestedValue = !attr->isNull() ? attr->value().toInt() : 0;
if(m_render && m_render->isListItem())
{
RenderListItem *list = static_cast<RenderListItem *>(m_render);
list->setValue(requestedValue);
}
break;
case ATTR_TYPE:
if ( strcmp( attr->value(), "a" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ALPHA);
else if ( strcmp( attr->value(), "A" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ALPHA);
else if ( strcmp( attr->value(), "i" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_LOWER_ROMAN);
else if ( strcmp( attr->value(), "I" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_UPPER_ROMAN);
else if ( strcmp( attr->value(), "1" ) == 0 )
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_DECIMAL);
else
addCSSProperty(attr, CSS_PROP_LIST_STYLE_TYPE, attr->value());
break;
default:
HTMLElementImpl::parseHTMLAttribute(attr);
}
}
void HTMLLIElementImpl::attach()
{
assert(!attached());
HTMLElementImpl::attach();
if ( m_render && m_render->style()->display() == LIST_ITEM ) {
RenderListItem *render = static_cast<RenderListItem *>(m_render);
NodeImpl *listNode = 0;
NodeImpl *n = this;
while (!listNode && (n = n->parentNode())) {
switch (n->id()) {
case ID_UL:
case ID_OL:
listNode = n;
}
}
if (!listNode)
render->setNotInList(true);
if (listNode && listNode->id() == ID_OL && !m_render->previousSibling()) {
HTMLOListElementImpl *ol = static_cast<HTMLOListElementImpl *>(listNode);
render->setValue(ol->start());
}
if (isValued)
render->setValue(requestedValue);
}
}
NodeImpl::Id HTMLDListElementImpl::id() const
{
return ID_DL;
}