📄 dom_elementimpl.cpp
字号:
for (unsigned long i = 0; i < len; i++) parseAttribute(&namedAttrMap->m_attrs[i]); }}NodeImpl *ElementImpl::cloneNode(bool deep){ ElementImpl *clone; if ( !localName().isNull() ) clone = getDocument()->createElementNS( namespaceURI(), nodeName() ); else clone = getDocument()->createElement( nodeName() ); if (!clone) return 0; finishCloneNode( clone, deep ); return clone;}void ElementImpl::finishCloneNode( ElementImpl* clone, bool deep ){ // clone attributes if (namedAttrMap) clone->attributes()->copyAttributes(namedAttrMap); // clone individual style rules if (m_styleDecls) *(clone->styleRules()) = *m_styleDecls; if (deep) cloneChildNodes(clone);}DOMString ElementImpl::nodeName() const{ return tagName();}DOMString ElementImpl::namespaceURI() const{ if (m_htmlCompat) return DOMString(); return getDocument()->getName(NamespaceId, id() >> 16);}DOMString ElementImpl::prefix() const{ return m_prefix;}void ElementImpl::setPrefix( const DOMString &_prefix, int &exceptioncode ){ checkSetPrefix(_prefix, exceptioncode); if (exceptioncode) return; if (m_prefix == _prefix.implementation()) return; if (m_prefix) m_prefix->deref(); m_prefix = _prefix.implementation(); if (m_prefix) m_prefix->ref();}void ElementImpl::createAttributeMap() const{ namedAttrMap = new NamedAttrMapImpl(const_cast<ElementImpl*>(this)); namedAttrMap->ref();}NamedAttrMapImpl* ElementImpl::defaultMap() const{ return 0;}RenderStyle *ElementImpl::styleForRenderer(RenderObject * /*parentRenderer*/){ return getDocument()->styleSelector()->styleForElement(this);}RenderObject *ElementImpl::createRenderer(RenderArena *arena, RenderStyle *style){ if (getDocument()->documentElement() == this && style->display() == NONE) { // Ignore display: none on root elements. Force a display of block in that case. RenderBlock* result = new (arena) RenderBlock(this); if (result) result->setStyle(style); return result; } return RenderObject::createObject(this, style);}void ElementImpl::attach(){ assert(!attached()); assert(!m_render); assert(parentNode());#if SPEED_DEBUG < 1 createRendererIfNeeded();#endif NodeBaseImpl::attach();}void ElementImpl::close(){ NodeImpl::close(); if (!getDocument()->renderer()) return; // the document is about to be destroyed if (m_restyleChildrenLate) { NodeImpl *e = firstChild(); while(e) { if (e->isElementNode()) { if (static_cast<ElementImpl*>(e)->restyleLate()) { static_cast<ElementImpl*>(e)->recalcStyle(Force); static_cast<ElementImpl*>(e)->setRestyleLate(false); } } e = e->nextSibling(); } m_restyleChildrenLate = false; } if (m_restyleSelfLate) { recalcStyle(Force); m_restyleSelfLate = false; }}void ElementImpl::recalcStyle( StyleChange change ){ // ### should go away and be done in renderobject RenderStyle* _style = m_render ? m_render->style() : 0; bool hasParentRenderer = parent() ? parent()->attached() : false;#if 0 const char* debug; switch(change) { case NoChange: debug = "NoChange"; break; case NoInherit: debug= "NoInherit"; break; case Inherit: debug = "Inherit"; break; case Force: debug = "Force"; break; } qDebug("recalcStyle(%d: %s, changed: %d)[%p: %s]", change, debug, changed(), this, tagName().string().latin1());#endif if ( hasParentRenderer && (change >= Inherit || changed()) ) { EDisplay oldDisplay = _style ? _style->display() : NONE; EPosition oldPosition = _style ? _style->position() : STATIC; RenderStyle *newStyle = getDocument()->styleSelector()->styleForElement(this); newStyle->ref(); StyleChange ch = diff( _style, newStyle ); if ( ch != NoChange ) { if (oldDisplay != newStyle->display() || oldPosition != newStyle->position()) { if (attached()) detach(); // ### uuhm, suboptimal. style gets calculated again attach(); // attach recalulates the style for all children. No need to do it twice. setChanged( false ); setHasChangedChild( false ); newStyle->deref(); return; } if( m_render && newStyle ) { //qDebug("--> setting style on render element bgcolor=%s", newStyle->backgroundColor().name().latin1()); m_render->setStyle(newStyle); } } newStyle->deref(); if ( change != Force) { if (getDocument()->usesDescendantRules()) change = Force; else change = ch; } } NodeImpl *n; for (n = _first; n; n = n->nextSibling()) { if ( change >= Inherit || n->isTextNode() || n->hasChangedChild() || n->changed() ) { //qDebug(" (%p) calling recalcStyle on child %p/%s, change=%d", this, n, n->isElementNode() ? ((ElementImpl *)n)->tagName().string().latin1() : n->isTextNode() ? "text" : "unknown", change ); n->recalcStyle( change ); } } setChanged( false ); setHasChangedChild( false );}bool ElementImpl::isFocusable() const{ // Only make editable elements selectable if its parent element // is not editable. FIXME: this is not 100% right as non-editable elements // within editable elements are focusable too. return contentEditable() && (!parentNode() || !parentNode()->contentEditable());}// DOM Section 1.1.1bool ElementImpl::childAllowed( NodeImpl *newChild ){ if (!childTypeAllowed(newChild->nodeType())) return false; // ### check xml element allowedness according to DTD // If either this node or the other node is an XML element node, allow regardless (we don't do DTD checks for XML // yet) if (isXMLElementNode() || newChild->isXMLElementNode()) return true; else return checkChild(id(), newChild->id(), !getDocument()->inCompatMode());}bool ElementImpl::childTypeAllowed( unsigned short type ){ switch (type) { case Node::ELEMENT_NODE: case Node::TEXT_NODE: case Node::COMMENT_NODE: case Node::PROCESSING_INSTRUCTION_NODE: case Node::CDATA_SECTION_NODE: case Node::ENTITY_REFERENCE_NODE: return true; break; default: return false; }}void ElementImpl::createDecl( ){ m_styleDecls = new CSSStyleDeclarationImpl(0); m_styleDecls->ref(); m_styleDecls->setParent(getDocument()->elementSheet()); m_styleDecls->setNode(this); m_styleDecls->setStrictParsing( !getDocument()->inCompatMode() );}void ElementImpl::dispatchAttrRemovalEvent(NodeImpl::Id /*id*/, DOMStringImpl * /*value*/){ // ### enable this stuff again if (!getDocument()->hasListenerType(DocumentImpl::DOMATTRMODIFIED_LISTENER)) return; //int exceptioncode = 0; //dispatchEvent(new MutationEventImpl(EventImpl::DOMATTRMODIFIED_EVENT,true,false,attr,attr->value(), //attr->value(), getDocument()->attrName(attr->id()),MutationEvent::REMOVAL),exceptioncode);}void ElementImpl::dispatchAttrAdditionEvent(NodeImpl::Id /*id*/, DOMStringImpl * /*value*/){ // ### enable this stuff again if (!getDocument()->hasListenerType(DocumentImpl::DOMATTRMODIFIED_LISTENER)) return; //int exceptioncode = 0; //dispatchEvent(new MutationEventImpl(EventImpl::DOMATTRMODIFIED_EVENT,true,false,attr,attr->value(), //attr->value(),getDocument()->attrName(attr->id()),MutationEvent::ADDITION),exceptioncode);}void ElementImpl::updateId(DOMStringImpl* oldId, DOMStringImpl* newId){ if (!inDocument()) return; DocumentImpl* doc = getDocument(); if (oldId && oldId->l) removeId(DOMString(oldId).string()); if (newId && newId->l) addId(DOMString(newId).string());}void ElementImpl::removeId(const QString& id){ getDocument()->getElementByIdCache().remove(id, this);}void ElementImpl::addId(const QString& id){ getDocument()->getElementByIdCache().add(id, this);}void ElementImpl::insertedIntoDocument(){ // need to do superclass processing first so inDocument() is true // by the time we reach updateId NodeBaseImpl::insertedIntoDocument(); if (hasID()) { DOMString id = getAttribute(ATTR_ID); updateId(0, id.implementation()); }}void ElementImpl::removedFromDocument(){ if (hasID()) { DOMString id = getAttribute(ATTR_ID); updateId(id.implementation(), 0); } NodeBaseImpl::removedFromDocument();}DOMString ElementImpl::openTagStartToString(bool expandurls) const{ DOMString result = DOMString("<") + tagName(); NamedAttrMapImpl *attrMap = attributes(true); if (attrMap) { unsigned long numAttrs = attrMap->length(); for (unsigned long i = 0; i < numAttrs; i++) { result += " "; AttributeImpl *attribute = attrMap->attrAt(i); AttrImpl *attr = attribute->attr(); if (attr) { result += attr->toString(); } else { result += getDocument()->getName( NodeImpl::AttributeId, attribute->id()); if (!attribute->value().isNull()) { result += "=\""; // FIXME: substitute entities for any instances of " or ' // Expand out all urls, i.e. the src and href attributes if(expandurls && ( attribute->id() == ATTR_SRC || attribute->id() == ATTR_HREF)) if(getDocument()) { //We need to sanitize the urls - strip out the passwords. //FIXME: are src= and href= the only places that might have a password and need to be sanitized? KURL safeURL(getDocument()->completeURL(attribute->value().string())); safeURL.setPass(QString::null); result += safeURL.htmlURL(); } else { kdWarning() << "getDocument() returned false"; result += attribute->value(); } else result += attribute->value(); result += "\""; } } } } return result;}DOMString ElementImpl::selectionToString(NodeImpl *selectionStart, NodeImpl *selectionEnd, int startOffset, int endOffset, bool &found) const{ DOMString result = openTagStartToString(); if (hasChildNodes()) { result += ">"; for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) { result += child->selectionToString(selectionStart, selectionEnd, startOffset, endOffset, found); // this might set found to true if(child == selectionEnd) found = true; if(found) break; } result += "</"; result += tagName(); result += ">"; } else { result += " />"; } return result;}DOMString ElementImpl::toString() const{ DOMString result = openTagStartToString(); if (hasChildNodes()) { result += ">"; for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) { result += child->toString(); } result += "</"; result += tagName(); result += ">"; } else { result += " />"; } return result;}bool ElementImpl::contentEditable() const {#if 0 DOM::CSSPrimitiveValueImpl *val = static_cast<DOM::CSSPrimitiveValueImpl *> (const_cast<ElementImpl *>(this)->styleRules() ->getPropertyCSSValue(CSS_PROP__KONQ_USER_INPUT));// kdDebug() << "val" << val << endl; return val ? val->getIdent() == CSS_VAL_ENABLED : false;#endif return NodeImpl::contentEditable();}void ElementImpl::setContentEditable(bool enabled) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -