📄 dom_elementimpl.cpp
字号:
child = nextChild; if(child->isElementNode()) { (static_cast<ElementImpl *>(child))->normalize(); } } }}AttributeList *ElementImpl::defaultMap() const{ return 0;}void ElementImpl::attach(MGHTMLView *w){ /* FIXME: */ m_style = document->styleSelector()->styleForElement(this, w->part()); if(_parent && _parent->renderer()) { m_render = khtml::RenderObject::createObject(this); if(m_render) { _parent->renderer()->addChild(m_render, _next ? _next->renderer() : 0); } } NodeBaseImpl::attach(w);}void ElementImpl::detach(){ NodeBaseImpl::detach();}void ElementImpl::applyChanges(bool top, bool force){ // ### find a better way to handle non-css attributes if(!m_render) return; if (top) recalcStyle(); // a style change can influence the children, so we just go // through them and trigger an appplyChanges there too NodeImpl *n = _first; while(n) { n->applyChanges(false,force || changed()); n = n->nextSibling(); } // calc min and max widths starting from leafs // might belong to renderer, but this is simple to do here if (force || changed()) m_render->calcMinMaxWidth(); if(top) { // force a relayout of this part of the document m_render->updateSize(); // force a repaint of this part. // ### if updateSize() changes any size, it will already force a // repaint, so we might do double work here... m_render->repaint(); } setChanged(false);}void ElementImpl::recalcStyle(){ if(!m_render) return; bool faf = m_style->flowAroundFloats(); delete m_style; /* FIXME: */ m_style = document->styleSelector()->styleForElement(this, NULL); m_style->setFlowAroundFloats(faf); m_render->setStyle(m_style); NodeImpl *n; for (n = _first; n; n = n->nextSibling()) n->recalcStyle();}void ElementImpl::setOwnerDocument(DocumentImpl *_document){ // also set for all our attributes uint i; for (i = 0; i < namedAttrMap->length(); i++) namedAttrMap->item(i)->setOwnerDocument(_document); NodeBaseImpl::setOwnerDocument(_document);}// -------------------------------------------------------------------------NamedAttrMapImpl::NamedAttrMapImpl(ElementImpl *e) : element(e){ attrs = 0; len = 0;}NamedAttrMapImpl::~NamedAttrMapImpl(){ clearAttrs();}void NamedAttrMapImpl::fromAttributeList(const AttributeList list){ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); element->checkReadOnly(); uint i; clearAttrs(); // should be empty, but just in case... // now import the list len = list.length(); attrs = new AttrImpl* [len]; for (i = 0; i < len; i++) { attrs[i] = new AttrImpl(list[i],element->ownerDocument(),element); element->parseAttribute(attrs[i]); } // used only during parsing - we don't call applyChanges() here}void NamedAttrMapImpl::fromNamedAttrMapImpl(const NamedAttrMapImpl *other){ // clone all attributes in the other map, but attach to our element if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); clearAttrs(); len = other->len; attrs = new AttrImpl* [len]; uint i; for (i = 0; i < len; i++) { attrs[i] = static_cast<AttrImpl*>(other->attrs[i]->cloneNode(false)); attrs[i]->_element = element; element->parseAttribute(attrs[i]); } element->setChanged(true);}unsigned long NamedAttrMapImpl::length() const { if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); return len;}NodeImpl *NamedAttrMapImpl::getNamedItem ( const DOMString &name ) const{ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); uint i; for (i = 0; i < len; i++) { if (!strcasecmp(attrs[i]->name(),name)) return attrs[i]; } return 0;}AttrImpl *NamedAttrMapImpl::getIdItem ( int id ) const{ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); uint i; for (i = 0; i < len; i++) { if (attrs[i]->attrId == id) return attrs[i]; } return 0;}NodeImpl *NamedAttrMapImpl::setNamedItem ( const Node &arg ){ // ### check for invalid chars in name ? // ### check same document if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); element->checkReadOnly(); if (arg.nodeType() != Node::ATTRIBUTE_NODE) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); AttrImpl *attr = static_cast<AttrImpl*>(arg.handle()); if (attr->_element) throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); uint i; for (i = 0; i < len; i++) { if (!strcasecmp(attrs[i]->name(),attr->name())) { // attribute with this id already in list AttrImpl *oldAttr = attrs[i]; attrs[i] = attr; attr->_element = element; oldAttr->_element = 0; element->parseAttribute(attr); element->setChanged(true); return oldAttr; // ### check this gets deleted if ref = 0 and it's not assigned to anything } } // attribute with this name not yet in list AttrImpl **newAttrs = new AttrImpl* [len+1]; if (attrs) { for (i = 0; i < len; i++) newAttrs[i] = attrs[i]; delete attrs; } attrs = newAttrs; attrs[len] = attr; len++; attr->_element = element; element->parseAttribute(attr); element->setChanged(true); return 0;}AttrImpl *NamedAttrMapImpl::setIdItem ( AttrImpl *attr ){ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); element->checkReadOnly(); if (attr->_element) throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); uint i; for (i = 0; i < len; i++) { if (attrs[i]->attrId == attr->attrId) { // attribute with this id already in list AttrImpl *oldAttr = attrs[i]; attrs[i] = attr; attr->_element = element; oldAttr->_element = 0; element->parseAttribute(attr); element->setChanged(true); return oldAttr; // ### check this gets deleted if ref = 0 and it's not assigned to anything } } // attribute with this id not yet in list AttrImpl **newAttrs = new AttrImpl* [len+1]; if (attrs) { for (i = 0; i < len; i++) newAttrs[i] = attrs[i]; delete attrs; } attrs = newAttrs; attrs[len] = attr; len++; attr->_element = element; element->parseAttribute(attr); element->setChanged(true); return 0;}NodeImpl *NamedAttrMapImpl::removeNamedItem ( const DOMString &name ){ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); element->checkReadOnly(); if (!attrs) return 0; uint i; int found = -1; for (i = 0; i < len && found < 0; i++) { if (!strcasecmp(attrs[i]->name(),name)) found = i; } if (found < 0) return 0; AttrImpl *ret = attrs[found]; ret->_element = 0; if (len == 1) { delete attrs; attrs = 0; len = 0; AttrImpl a(name,"",element->ownerDocument()); element->parseAttribute(&a); element->setChanged(true); return ret; } AttrImpl **newAttrs = new AttrImpl* [len-1]; for (i = 0; i < uint(found); i++) newAttrs[i] = attrs[i]; len--; for (; i < len; i++) newAttrs[i] = attrs[i+1]; delete attrs; attrs = newAttrs; DOMString nullStr; AttrImpl a(name,nullStr,element->ownerDocument()); element->parseAttribute(&a); element->setChanged(true); return ret;}AttrImpl *NamedAttrMapImpl::removeIdItem ( int id ){ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); element->checkReadOnly(); if (!attrs) return 0; uint i; int found = -1; for (i = 0; i < len && found < 0; i++) { if (attrs[i]->attrId == id) found = i; } if (found < 0) return 0; AttrImpl *ret = attrs[found]; ret->_element = 0; if (len == 1) { delete attrs; attrs = 0; len = 0; AttrImpl a(id,"",element->ownerDocument()); element->parseAttribute(&a); element->setChanged(true); return ret; } AttrImpl **newAttrs = new AttrImpl* [len-1]; for (i = 0; i < uint(found); i++) newAttrs[i] = attrs[i]; len--; for (; i < len; i++) newAttrs[i] = attrs[i+1]; delete attrs; attrs = newAttrs; DOMString nullStr; AttrImpl a(id,nullStr,element->ownerDocument()); element->parseAttribute(&a); element->setChanged(true); return ret;}NodeImpl *NamedAttrMapImpl::item ( unsigned long index ) const{ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); if (index >= len) return 0; else return attrs[index];}void NamedAttrMapImpl::clearAttrs(){ if (attrs) { uint i; for (i = 0; i < len; i++) { attrs[i]->_element = 0; if (attrs[i]->deleteMe()) delete attrs[i]; } delete [] attrs; attrs = 0; } len = 0;}AttrImpl *NamedAttrMapImpl::removeAttr( AttrImpl *oldAttr ){ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); uint i; for (i = 0; i < len; i++) { if (attrs[i] == oldAttr) { AttrImpl *ret = attrs[i]; if (len == 1) { delete attrs; attrs = 0; len = 0; } else { AttrImpl **newAttrs = new AttrImpl* [len-1]; uint ni; for (ni = 0; ni < i; ni++) newAttrs[ni] = attrs[ni]; len--; for (; ni < len; ni++) newAttrs[ni] = attrs[ni+1]; delete attrs; attrs = newAttrs; } ret->_element = 0; AttrImpl a = oldAttr->attrId ? AttrImpl(oldAttr->attrId,"",element->ownerDocument()) : AttrImpl(oldAttr->name(),"",element->ownerDocument()); element->parseAttribute(&a); element->setChanged(true); return ret; } } throw DOMException(DOMException::NOT_FOUND_ERR); return 0;}void NamedAttrMapImpl::detachFromElement(){ if (!element) throw DOMException(DOMException::NOT_FOUND_ERR); // we allow a NamedAttrMapImpl w/o an element in case someone still has a reference // to if after the element gets deleted - but the map is now invalid element = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -