⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dom2_rangeimpl.cpp

📁 将konqueror浏览器移植到ARM9 2410中
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    switch (n->nodeType()) {	case Node::ENTITY_NODE:	case Node::NOTATION_NODE:	case Node::DOCUMENT_TYPE_NODE:            exceptioncode = RangeException::INVALID_NODE_TYPE_ERR + RangeException::_EXCEPTION_OFFSET;	    break;        case Node::TEXT_NODE:        case Node::COMMENT_NODE:        case Node::CDATA_SECTION_NODE:            if ( (unsigned long)offset > static_cast<CharacterDataImpl*>(n)->length() )                exceptioncode = DOMException::INDEX_SIZE_ERR;            break;        case Node::PROCESSING_INSTRUCTION_NODE:            // ### are we supposed to check with just data or the whole contents?            if ( (unsigned long)offset > static_cast<ProcessingInstructionImpl*>(n)->data().length() )                exceptioncode = DOMException::INDEX_SIZE_ERR;            break;        default:            if ( (unsigned long)offset > n->childNodeCount() )                exceptioncode = DOMException::INDEX_SIZE_ERR;            break;    }}void RangeImpl::checkNodeBA( NodeImpl *n, int &exceptioncode ) const{    // INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an    // Attr, Document or DocumentFragment node or if refNode is a Document,    // DocumentFragment, Attr, Entity, or Notation node.    NodeImpl *root = n;    while (root->parentNode())	root = root->parentNode();    if (!(root->nodeType() == Node::ATTRIBUTE_NODE ||          root->nodeType() == Node::DOCUMENT_NODE ||          root->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)) {        exceptioncode = RangeException::INVALID_NODE_TYPE_ERR + RangeException::_EXCEPTION_OFFSET;        return;    }    if( n->nodeType() == Node::DOCUMENT_NODE ||        n->nodeType() == Node::DOCUMENT_FRAGMENT_NODE ||        n->nodeType() == Node::ATTRIBUTE_NODE ||        n->nodeType() == Node::ENTITY_NODE ||        n->nodeType() == Node::NOTATION_NODE )        exceptioncode = RangeException::INVALID_NODE_TYPE_ERR  + RangeException::_EXCEPTION_OFFSET;}RangeImpl *RangeImpl::cloneRange(int &exceptioncode){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return 0;    }    return new RangeImpl(m_ownerDocument,m_startContainer,m_startOffset,m_endContainer,m_endOffset);}void RangeImpl::setStartAfter( NodeImpl *refNode, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if (!refNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    if (refNode->getDocument() != m_ownerDocument->document()) {        exceptioncode = DOMException::WRONG_DOCUMENT_ERR;        return;    }    checkNodeBA( refNode, exceptioncode );    if (exceptioncode)        return;    setStart( refNode->parentNode(), refNode->nodeIndex()+1, exceptioncode );}void RangeImpl::setEndBefore( NodeImpl *refNode, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if (!refNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    if (refNode->getDocument() != m_ownerDocument->document()) {        exceptioncode = DOMException::WRONG_DOCUMENT_ERR;        return;    }    checkNodeBA( refNode, exceptioncode );    if (exceptioncode)        return;    setEnd( refNode->parentNode(), refNode->nodeIndex(), exceptioncode );}void RangeImpl::setEndAfter( NodeImpl *refNode, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if (!refNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    if (refNode->getDocument() != m_ownerDocument->document()) {        exceptioncode = DOMException::WRONG_DOCUMENT_ERR;        return;    }    checkNodeBA( refNode, exceptioncode );    if (exceptioncode)        return;    setEnd( refNode->parentNode(), refNode->nodeIndex()+1, exceptioncode );}void RangeImpl::selectNode( NodeImpl *refNode, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if (!refNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    // INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Entity, Notation or    // DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation    // node.    NodeImpl *anc;    for (anc = refNode->parentNode(); anc; anc = anc->parentNode()) {        if (anc->nodeType() == Node::ENTITY_NODE ||            anc->nodeType() == Node::NOTATION_NODE ||            anc->nodeType() == Node::DOCUMENT_TYPE_NODE) {            exceptioncode = RangeException::INVALID_NODE_TYPE_ERR + RangeException::_EXCEPTION_OFFSET;            return;        }    }    if (refNode->nodeType() == Node::DOCUMENT_NODE ||        refNode->nodeType() == Node::DOCUMENT_FRAGMENT_NODE ||        refNode->nodeType() == Node::ATTRIBUTE_NODE ||        refNode->nodeType() == Node::ENTITY_NODE ||        refNode->nodeType() == Node::NOTATION_NODE) {        exceptioncode = RangeException::INVALID_NODE_TYPE_ERR + RangeException::_EXCEPTION_OFFSET;        return;    }    setStartBefore( refNode, exceptioncode );    if (exceptioncode)        return;    setEndAfter( refNode, exceptioncode );}void RangeImpl::selectNodeContents( NodeImpl *refNode, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if (!refNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    // INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Entity, Notation    // or DocumentType node.    NodeImpl *n;    for (n = refNode; n; n = n->parentNode()) {        if (n->nodeType() == Node::ENTITY_NODE ||            n->nodeType() == Node::NOTATION_NODE ||            n->nodeType() == Node::DOCUMENT_TYPE_NODE) {            exceptioncode = RangeException::INVALID_NODE_TYPE_ERR + RangeException::_EXCEPTION_OFFSET;            return;        }    }    setStartContainer(refNode);    m_startOffset = 0;    setEndContainer(refNode);    m_endOffset = refNode->childNodeCount();}void RangeImpl::surroundContents( NodeImpl *newParent, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if( !newParent ) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    // INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, Notation,    // Document, or DocumentFragment node.    if( newParent->nodeType() == Node::ATTRIBUTE_NODE ||        newParent->nodeType() == Node::ENTITY_NODE ||        newParent->nodeType() == Node::NOTATION_NODE ||        newParent->nodeType() == Node::DOCUMENT_TYPE_NODE ||        newParent->nodeType() == Node::DOCUMENT_NODE ||        newParent->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) {        exceptioncode = RangeException::INVALID_NODE_TYPE_ERR + RangeException::_EXCEPTION_OFFSET;        return;    }    // NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of either boundary-point of    // the Range is read-only.    if (readOnly()) {        exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;        return;    }    NodeImpl *n = m_startContainer;    while (n && !n->isReadOnly())        n = n->parentNode();    if (n) {        exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;        return;    }    n = m_endContainer;    while (n && !n->isReadOnly())        n = n->parentNode();    if (n) {        exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;        return;    }    // WRONG_DOCUMENT_ERR: Raised if newParent and the container of the start of the Range were    // not created from the same document.    if (newParent->getDocument() != m_startContainer->getDocument()) {        exceptioncode = DOMException::WRONG_DOCUMENT_ERR;        return;    }    // HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that    // does not allow children of the type of newParent or if newParent is an ancestor of the container    // or if node would end up with a child node of a type not allowed by the type of node.    if (!m_startContainer->childTypeAllowed(newParent->nodeType())) {        exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;        return;    }    for (n = m_startContainer; n; n = n->parentNode()) {        if (n == newParent) {            exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;            return;        }    }    // ### check if node would end up with a child node of a type not allowed by the type of node    // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-text node.    if (m_startContainer->nodeType() != Node::TEXT_NODE &&        m_startContainer->nodeType() != Node::COMMENT_NODE &&        m_startContainer->nodeType() != Node::CDATA_SECTION_NODE &&        m_startContainer->nodeType() != Node::PROCESSING_INSTRUCTION_NODE) {        if (m_startOffset > 0 && m_startOffset < m_startContainer->childNodeCount()) {            exceptioncode = RangeException::BAD_BOUNDARYPOINTS_ERR + RangeException::_EXCEPTION_OFFSET;            return;        }    }    if (m_endContainer->nodeType() != Node::TEXT_NODE &&        m_endContainer->nodeType() != Node::COMMENT_NODE &&        m_endContainer->nodeType() != Node::CDATA_SECTION_NODE &&        m_endContainer->nodeType() != Node::PROCESSING_INSTRUCTION_NODE) {        if (m_endOffset > 0 && m_endOffset < m_endContainer->childNodeCount()) {            exceptioncode = RangeException::BAD_BOUNDARYPOINTS_ERR + RangeException::_EXCEPTION_OFFSET;            return;        }    }    while (newParent->firstChild()) {    	newParent->removeChild(newParent->firstChild(),exceptioncode);	if (exceptioncode)	    return;    }    DocumentFragmentImpl *fragment = extractContents(exceptioncode);    if (exceptioncode)        return;    insertNode( newParent, exceptioncode );    if (exceptioncode)        return;    newParent->appendChild( fragment, exceptioncode );    if (exceptioncode)        return;    selectNode( newParent, exceptioncode );}void RangeImpl::setStartBefore( NodeImpl *refNode, int &exceptioncode ){    if (m_detached) {        exceptioncode = DOMException::INVALID_STATE_ERR;        return;    }    if (!refNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return;    }    if (refNode->getDocument() != m_ownerDocument->document()) {        exceptioncode = DOMException::WRONG_DOCUMENT_ERR;        return;    }    checkNodeBA( refNode, exceptioncode );    if (exceptioncode)        return;    setStart( refNode->parentNode(), refNode->nodeIndex(), exceptioncode );}void RangeImpl::setStartContainer(NodeImpl *_startContainer){    if (m_startContainer == _startContainer)        return;    if (m_startContainer)        m_startContainer->deref();    m_startContainer = _startContainer;    if (m_startContainer)        m_startContainer->ref();}void RangeImpl::setEndContainer(NodeImpl *_endContainer){    if (m_endContainer == _endContainer)        return;    if (m_endContainer)        m_endContainer->deref();    m_endContainer = _endContainer;    if (m_endContainer)        m_endContainer->ref();}void RangeImpl::checkDeleteExtract(int &exceptioncode) {    NodeImpl *start;    if (m_startContainer->nodeType() != Node::TEXT_NODE &&	m_startContainer->nodeType() != Node::CDATA_SECTION_NODE &&	m_startContainer->nodeType() != Node::COMMENT_NODE &&	m_startContainer->nodeType() != Node::PROCESSING_INSTRUCTION_NODE) {	start = m_startContainer->childNode(m_startOffset);	if (!start) {	    if (m_startContainer->lastChild())		start = m_startContainer->lastChild()->traverseNextNode();	    else		start = m_startContainer->traverseNextNode();	}    }    else	start = m_startContainer;    NodeImpl *end;    if (m_endContainer->nodeType() != Node::TEXT_NODE &&	m_endContainer->nodeType() != Node::CDATA_SECTION_NODE &&	m_endContainer->nodeType() != Node::COMMENT_NODE &&	m_endContainer->nodeType() != Node::PROCESSING_INSTRUCTION_NODE) {	end = m_endContainer->childNode(m_endOffset);	if (!end) {	    if (m_endContainer->lastChild())		end = m_endContainer->lastChild()->traverseNextNode();	    else		end = m_endContainer->traverseNextNode();	}    }    else	end = m_endContainer;    NodeImpl *n;    for (n = start; n != end; n = n->traverseNextNode()) {	if (n->isReadOnly()) {	    exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;	    return;	}	if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) { // ### is this for only directly under the DF, or anywhere?	    exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;	    return;	}    }    if (containedByReadOnly()) {	exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;	return;    }}bool RangeImpl::containedByReadOnly() {    NodeImpl *n;    for (n = m_startContainer; n; n = n->parentNode()) {	if (n->isReadOnly())	    return true;    }    for (n = m_endContainer; n; n = n->parentNode()) {	if (n->isReadOnly())	    return true;    }    return false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -