📄 dom_docimpl.cpp
字号:
write(text.string());}void DocumentImpl::write( const QString &text ){ if (!m_tokenizer) { open(); if (m_view) m_view->part()->resetFromScript(); m_tokenizer->setAutoClose(); write(QString::fromLatin1("<html>")); } m_tokenizer->write(text, false);}void DocumentImpl::writeln( const DOMString &text ){ write(text); write(DOMString("\n"));}void DocumentImpl::finishParsing ( ){ if(m_tokenizer) m_tokenizer->finish();}void DocumentImpl::setUserStyleSheet( const QString& sheet ){ if ( m_usersheet != sheet ) { m_usersheet = sheet; updateStyleSelector(); }}CSSStyleSheetImpl* DocumentImpl::elementSheet(){ if (!m_elemSheet) { m_elemSheet = new CSSStyleSheetImpl(this, baseURL().url() ); m_elemSheet->ref(); } return m_elemSheet;}void DocumentImpl::determineParseMode( const QString &/*str*/ ){ // For XML documents, use strict parse mode pMode = Strict; hMode = XHtml; kdDebug(6020) << " using strict parseMode" << endl;}NodeImpl *DocumentImpl::nextFocusNode(NodeImpl *fromNode){ unsigned short fromTabIndex; if (!fromNode) { // No starting node supplied; begin with the top of the document NodeImpl *n; int lowestTabIndex = 65535; for (n = this; n != 0; n = n->traverseNextNode()) { if (n->isTabFocusable()) { if ((n->tabIndex() > 0) && (n->tabIndex() < lowestTabIndex)) lowestTabIndex = n->tabIndex(); } } if (lowestTabIndex == 65535) lowestTabIndex = 0; // Go to the first node in the document that has the desired tab index for (n = this; n != 0; n = n->traverseNextNode()) { if (n->isTabFocusable() && (n->tabIndex() == lowestTabIndex)) return n; } return 0; } else { fromTabIndex = fromNode->tabIndex(); } if (fromTabIndex == 0) { // Just need to find the next selectable node after fromNode (in document order) that doesn't have a tab index NodeImpl *n = fromNode->traverseNextNode(); while (n && !(n->isTabFocusable() && n->tabIndex() == 0)) n = n->traverseNextNode(); return n; } else { // Find the lowest tab index out of all the nodes except fromNode, that is greater than or equal to fromNode's // tab index. For nodes with the same tab index as fromNode, we are only interested in those that come after // fromNode in document order. // If we don't find a suitable tab index, the next focus node will be one with a tab index of 0. unsigned short lowestSuitableTabIndex = 65535; NodeImpl *n; bool reachedFromNode = false; for (n = this; n != 0; n = n->traverseNextNode()) { if (n->isTabFocusable() && ((reachedFromNode && (n->tabIndex() >= fromTabIndex)) || (!reachedFromNode && (n->tabIndex() > fromTabIndex))) && (n->tabIndex() < lowestSuitableTabIndex) && (n != fromNode)) { // We found a selectable node with a tab index at least as high as fromNode's. Keep searching though, // as there may be another node which has a lower tab index but is still suitable for use. lowestSuitableTabIndex = n->tabIndex(); } if (n == fromNode) reachedFromNode = true; } if (lowestSuitableTabIndex == 65535) { // No next node with a tab index -> just take first node with tab index of 0 NodeImpl *n = this; while (n && !(n->isTabFocusable() && n->tabIndex() == 0)) n = n->traverseNextNode(); return n; } // Search forwards from fromNode for (n = fromNode->traverseNextNode(); n != 0; n = n->traverseNextNode()) { if (n->isTabFocusable() && (n->tabIndex() == lowestSuitableTabIndex)) return n; } // The next node isn't after fromNode, start from the beginning of the document for (n = this; n != fromNode; n = n->traverseNextNode()) { if (n->isTabFocusable() && (n->tabIndex() == lowestSuitableTabIndex)) return n; } assert(false); // should never get here return 0; }}NodeImpl *DocumentImpl::previousFocusNode(NodeImpl *fromNode){ NodeImpl *lastNode = this; while (lastNode->lastChild()) lastNode = lastNode->lastChild(); if (!fromNode) { // No starting node supplied; begin with the very last node in the document NodeImpl *n; int highestTabIndex = 0; for (n = lastNode; n != 0; n = n->traversePreviousNode()) { if (n->isTabFocusable()) { if (n->tabIndex() == 0) return n; else if (n->tabIndex() > highestTabIndex) highestTabIndex = n->tabIndex(); } } // No node with a tab index of 0; just go to the last node with the highest tab index for (n = lastNode; n != 0; n = n->traversePreviousNode()) { if (n->isTabFocusable() && (n->tabIndex() == highestTabIndex)) return n; } return 0; } else { unsigned short fromTabIndex = fromNode->tabIndex(); if (fromTabIndex == 0) { // Find the previous selectable node before fromNode (in document order) that doesn't have a tab index NodeImpl *n = fromNode->traversePreviousNode(); while (n && !(n->isTabFocusable() && n->tabIndex() == 0)) n = n->traversePreviousNode(); if (n) return n; // No previous nodes with a 0 tab index, go to the last node in the document that has the highest tab index int highestTabIndex = 0; for (n = this; n != 0; n = n->traverseNextNode()) { if (n->isTabFocusable() && (n->tabIndex() > highestTabIndex)) highestTabIndex = n->tabIndex(); } if (highestTabIndex == 0) return 0; for (n = lastNode; n != 0; n = n->traversePreviousNode()) { if (n->isTabFocusable() && (n->tabIndex() == highestTabIndex)) return n; } assert(false); // should never get here return 0; } else { // Find the lowest tab index out of all the nodes except fromNode, that is less than or equal to fromNode's // tab index. For nodes with the same tab index as fromNode, we are only interested in those before // fromNode. // If we don't find a suitable tab index, then there will be no previous focus node. unsigned short highestSuitableTabIndex = 0; NodeImpl *n; bool reachedFromNode = false; for (n = this; n != 0; n = n->traverseNextNode()) { if (n->isTabFocusable() && ((!reachedFromNode && (n->tabIndex() <= fromTabIndex)) || (reachedFromNode && (n->tabIndex() < fromTabIndex))) && (n->tabIndex() > highestSuitableTabIndex) && (n != fromNode)) { // We found a selectable node with a tab index no higher than fromNode's. Keep searching though, as // there may be another node which has a higher tab index but is still suitable for use. highestSuitableTabIndex = n->tabIndex(); } if (n == fromNode) reachedFromNode = true; } if (highestSuitableTabIndex == 0) { // No previous node with a tab index. Since the order specified by HTML is nodes with tab index > 0 // first, this means that there is no previous node. return 0; } // Search backwards from fromNode for (n = fromNode->traversePreviousNode(); n != 0; n = n->traversePreviousNode()) { if (n->isTabFocusable() && (n->tabIndex() == highestSuitableTabIndex)) return n; } // The previous node isn't before fromNode, start from the end of the document for (n = lastNode; n != fromNode; n = n->traversePreviousNode()) { if (n->isTabFocusable() && (n->tabIndex() == highestSuitableTabIndex)) return n; } assert(false); // should never get here return 0; } }}ElementImpl* DocumentImpl::findAccessKeyElement(QChar c){ c = c.upper(); for( NodeImpl* n = this; n != NULL; n = n->traverseNextNode()) { if( n->isElementNode()) { ElementImpl* en = static_cast< ElementImpl* >( n ); DOMString s = en->getAttribute( ATTR_ACCESSKEY ); if( s.length() == 1 && s[ 0 ].upper() == c ) return en; } } return NULL;}int DocumentImpl::nodeAbsIndex(NodeImpl *node){ assert(node->getDocument() == this); int absIndex = 0; for (NodeImpl *n = node; n && n != this; n = n->traversePreviousNode()) absIndex++; return absIndex;}NodeImpl *DocumentImpl::nodeWithAbsIndex(int absIndex){ NodeImpl *n = this; for (int i = 0; n && (i < absIndex); i++) { n = n->traverseNextNode(); } return n;}void DocumentImpl::processHttpEquiv(const DOMString &equiv, const DOMString &content){ assert(!equiv.isNull() && !content.isNull()); KHTMLView *v = getDocument()->view(); if(strcasecmp(equiv, "refresh") == 0 && v && v->part()->metaRefreshEnabled()) { // get delay and url QString str = content.string().stripWhiteSpace(); int pos = str.find(QRegExp("[;,]")); if ( pos == -1 ) pos = str.find(QRegExp("[ \t]")); bool ok = false; int delay = kMax( 0, content.implementation()->toInt(&ok) ); if ( !ok && str.length() && str[0] == '.' ) ok = true; if (pos == -1) // There can be no url (David) { if(ok) v->part()->scheduleRedirection(delay, v->part()->url().url() ); } else { pos++; while(pos < (int)str.length() && str[pos].isSpace()) pos++; str = str.mid(pos); if(str.find("url", 0, false ) == 0) str = str.mid(3); str = str.stripWhiteSpace(); if ( str.length() && str[0] == '=' ) str = str.mid( 1 ).stripWhiteSpace(); while(str.length() && (str[str.length()-1] == ';' || str[str.length()-1] == ',')) str.setLength(str.length()-1); str = parseURL( DOMString(str) ).string(); QString newURL = getDocument()->completeURL( str ); if ( ok ) v->part()->scheduleRedirection(delay, getDocument()->completeURL( str ), delay < 2 || newURL == URL().url()); } } else if(strcasecmp(equiv, "expires") == 0) { bool relative = false; QString str = content.string().stripWhiteSpace(); time_t expire_date = KRFCDate::parseDate(str); if (!expire_date) { expire_date = str.toULong(); relative = true; } if (!expire_date) expire_date = 1; // expire now if (m_docLoader) m_docLoader->setExpireDate(expire_date, relative); } else if(v && (strcasecmp(equiv, "pragma") == 0 || strcasecmp(equiv, "cache-control") == 0)) { QString str = content.string().lower().stripWhiteSpace(); KURL url = v->part()->url(); if ((str == "no-cache") && url.protocol().startsWith("http")) { KIO::http_update_cache(url, true, 0); } } else if( (strcasecmp(equiv, "set-cookie") == 0)) { // ### make setCookie work on XML documents too; e.g. in case of <html:meta .....> HTMLDocumentImpl *d = static_cast<HTMLDocumentImpl *>(this); d->setCookie(content); } else if (strcasecmp(equiv, "default-style") == 0) { // HTML 4.0 14.3.2 // http://www.hixie.ch/tests/evil/css/import/main/preferred.html m_preferredStylesheetSet = content; updateStyleSelector(); }}bool DocumentImpl::prepareMouseEvent( bool readonly, int _x, int _y, MouseEvent *ev ){ if ( m_render ) { assert(m_render->isCanvas()); RenderObject::NodeInfo renderInfo(readonly, ev->type == MousePress); bool isInside = m_render->layer()->nodeAtPoint(renderInfo, _x, _y); ev->innerNode = renderInfo.innerNode(); ev->innerNonSharedNode = renderInfo.innerNonSharedNode(); if (renderInfo.URLElement()) { assert(renderInfo.URLElement()->isElementNode()); //qDebug("urlnode: %s (%d)", getTagName(renderInfo.URLElement()->id()).string().latin1(), renderInfo.URLElement()->id()); ElementImpl* e = static_cast<ElementImpl*>(renderInfo.URLElement()); DOMString href = khtml::parseURL(e->getAttribute(ATTR_HREF)); DOMString target = e->getAttribute(ATTR_TARGET); if (!target.isNull() && !href.isNull()) { ev->target = target; ev->url = href; } else ev->url = href; } if (!readonly) updateRendering(); return isInside; } return false;}// DOM Section 1.1.1bool DocumentImpl::childAllowed( NodeImpl *newChild ){ // Documents may contain a maximum of one Element child if (newChild->nodeType() == Node::ELEMENT_NODE) { NodeImpl *c; for (c = firstChild(); c; c = c->nextSibling()) { if (c->nodeType() == Node::ELEMENT_NODE) return false; } } // Documents may contain a maximum of one DocumentType child if (newChild->nodeType() == Node::DOCUMENT_TYPE_NODE) { NodeImpl *c; for (c = firstChild(); c; c = c->nextSibling()) { if (c->nodeType() == Node::DOCUMENT_TYPE_NODE) return false; } } return childTypeAllowed(newChild->nodeType());}bool DocumentImpl::childTypeAllowed( unsigned short type ){ switch (type) { case Node::ELEMENT_NODE: case Node::PROCESSING_INSTRUCTION_NODE: case Node::COMMENT_NODE: case Node::DOCUMENT_TYPE_NODE: return true; break; default: return false; }}NodeImpl *DocumentImpl::cloneNode ( bool /*deep*/ ){ // Spec says cloning Document nodes is "implementation dependent" // so we do not support it... return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -