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

📄 node.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    return new NodeRareData;}    short Node::tabIndex() const{    return hasRareData() ? rareData()->tabIndex() : 0;}    void Node::setTabIndexExplicitly(short i){    ensureRareData()->setTabIndexExplicitly(i);}String Node::nodeValue() const{  return String();}void Node::setNodeValue(const String& /*nodeValue*/, ExceptionCode& ec){    // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly    if (isReadOnlyNode()) {        ec = NO_MODIFICATION_ALLOWED_ERR;        return;    }    // By default, setting nodeValue has no effect.}PassRefPtr<NodeList> Node::childNodes(){    NodeRareData* data = ensureRareData();    if (!data->nodeLists()) {        data->setNodeLists(auto_ptr<NodeListsNodeData>(new NodeListsNodeData));        document()->addNodeListCache();    }    return ChildNodeList::create(this, &data->nodeLists()->m_childNodeListCaches);}Node *Node::lastDescendant() const{    Node *n = const_cast<Node *>(this);    while (n && n->lastChild())        n = n->lastChild();    return n;}Node* Node::firstDescendant() const{    Node *n = const_cast<Node *>(this);    while (n && n->firstChild())        n = n->firstChild();    return n;}bool Node::insertBefore(PassRefPtr<Node>, Node*, ExceptionCode& ec, bool){    ec = HIERARCHY_REQUEST_ERR;    return false;}bool Node::replaceChild(PassRefPtr<Node>, Node*, ExceptionCode& ec, bool){    ec = HIERARCHY_REQUEST_ERR;    return false;}bool Node::removeChild(Node*, ExceptionCode& ec){    ec = NOT_FOUND_ERR;    return false;}bool Node::appendChild(PassRefPtr<Node>, ExceptionCode& ec, bool){    ec = HIERARCHY_REQUEST_ERR;    return false;}void Node::remove(ExceptionCode& ec){    ref();    if (Node *p = parentNode())        p->removeChild(this, ec);    else        ec = HIERARCHY_REQUEST_ERR;    deref();}void Node::normalize(){    // Go through the subtree beneath us, normalizing all nodes. This means that    // any two adjacent text nodes are merged together.    RefPtr<Node> node = this;    while (Node* firstChild = node->firstChild())        node = firstChild;    for (; node; node = node->traverseNextNodePostOrder()) {        NodeType type = node->nodeType();        if (type == ELEMENT_NODE)            static_cast<Element*>(node.get())->normalizeAttributes();        Node* firstChild = node->firstChild();        if (firstChild && !firstChild->nextSibling() && firstChild->isTextNode()) {            Text* text = static_cast<Text*>(firstChild);            if (!text->length()) {                ExceptionCode ec;                text->remove(ec);            }        }        if (node == this)            break;        if (type == TEXT_NODE) {            while (1) {                Node* nextSibling = node->nextSibling();                if (!nextSibling || !nextSibling->isTextNode())                    break;                // Current child and the next one are both text nodes. Merge them.                Text* text = static_cast<Text*>(node.get());                RefPtr<Text> nextText = static_cast<Text*>(nextSibling);                unsigned offset = text->length();                ExceptionCode ec;                text->appendData(nextText->data(), ec);                document()->textNodesMerged(nextText.get(), offset);                nextText->remove(ec);            }        }    }}const AtomicString& Node::virtualPrefix() const{    // For nodes other than elements and attributes, the prefix is always null    return nullAtom;}void Node::setPrefix(const AtomicString& /*prefix*/, ExceptionCode& ec){    // The spec says that for nodes other than elements and attributes, prefix is always null.    // It does not say what to do when the user tries to set the prefix on another type of    // node, however Mozilla throws a NAMESPACE_ERR exception.    ec = NAMESPACE_ERR;}const AtomicString& Node::virtualLocalName() const{    return nullAtom;}const AtomicString& Node::virtualNamespaceURI() const{    return nullAtom;}ContainerNode* Node::addChild(PassRefPtr<Node>){    return 0;}bool Node::isContentEditable() const{    return parent() && parent()->isContentEditable();}bool Node::isContentRichlyEditable() const{    return parent() && parent()->isContentRichlyEditable();}bool Node::shouldUseInputMethod() const{    return isContentEditable();}RenderBox* Node::renderBox() const{    return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0;}RenderBoxModelObject* Node::renderBoxModelObject() const{    return m_renderer && m_renderer->isBoxModelObject() ? toRenderBoxModelObject(m_renderer) : 0;}IntRect Node::getRect() const{    // FIXME: broken with transforms    if (renderer())        return renderer()->absoluteBoundingBoxRect();    return IntRect();}void Node::setChanged(StyleChangeType changeType){    if ((changeType != NoStyleChange) && !attached()) // changed compared to what?        return;    if (!(changeType == InlineStyleChange && (m_styleChange == FullStyleChange || m_styleChange == AnimationStyleChange)))        m_styleChange = changeType;    if (m_styleChange != NoStyleChange) {        for (Node* p = parentNode(); p && !p->hasChangedChild(); p = p->parentNode())            p->setHasChangedChild(true);        document()->setDocumentChanged(true);    }}static Node* outermostLazyAttachedAncestor(Node* start){    Node* p = start;    for (Node* next = p->parentNode(); !next->renderer(); p = next, next = next->parentNode()) {}    return p;}void Node::lazyAttach(){    bool mustDoFullAttach = false;    for (Node* n = this; n; n = n->traverseNextNode(this)) {        if (!n->canLazyAttach()) {            mustDoFullAttach = true;            break;        }        if (n->firstChild())            n->setHasChangedChild(true);        n->m_styleChange = FullStyleChange;        n->m_attached = true;    }    if (mustDoFullAttach) {        Node* lazyAttachedAncestor = outermostLazyAttachedAncestor(this);        if (lazyAttachedAncestor->attached())            lazyAttachedAncestor->detach();        lazyAttachedAncestor->attach();    } else {        for (Node* p = parentNode(); p && !p->hasChangedChild(); p = p->parentNode())            p->setHasChangedChild(true);        document()->setDocumentChanged(true);    }}bool Node::canLazyAttach(){    return shadowAncestorNode() == this;}    void Node::setFocus(bool b){     if (b || hasRareData())        ensureRareData()->setFocused(b);}bool Node::rareDataFocused() const{    ASSERT(hasRareData());    return rareData()->isFocused();}    bool Node::isFocusable() const{    return hasRareData() && rareData()->tabIndexSetExplicitly();}bool Node::isKeyboardFocusable(KeyboardEvent*) const{    return isFocusable() && tabIndex() >= 0;}bool Node::isMouseFocusable() const{    return isFocusable();}unsigned Node::nodeIndex() const{    Node *_tempNode = previousSibling();    unsigned count=0;    for( count=0; _tempNode; count++ )        _tempNode = _tempNode->previousSibling();    return count;}void Node::registerDynamicNodeList(DynamicNodeList* list){    NodeRareData* data = ensureRareData();    if (!data->nodeLists()) {        data->setNodeLists(auto_ptr<NodeListsNodeData>(new NodeListsNodeData));        document()->addNodeListCache();    } else if (!m_document->hasNodeListCaches()) {        // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now.        data->nodeLists()->invalidateCaches();    }    if (list->hasOwnCaches())        data->nodeLists()->m_listsWithCaches.add(list);}void Node::unregisterDynamicNodeList(DynamicNodeList* list){    ASSERT(rareData());    ASSERT(rareData()->nodeLists());    if (list->hasOwnCaches()) {        NodeRareData* data = rareData();        data->nodeLists()->m_listsWithCaches.remove(list);        if (data->nodeLists()->isEmpty()) {            data->clearNodeLists();            document()->removeNodeListCache();        }    }}void Node::notifyLocalNodeListsAttributeChanged(){    if (!hasRareData())        return;    NodeRareData* data = rareData();    if (!data->nodeLists())        return;    data->nodeLists()->invalidateCachesThatDependOnAttributes();    if (data->nodeLists()->isEmpty()) {        data->clearNodeLists();        document()->removeNodeListCache();    }}void Node::notifyNodeListsAttributeChanged(){    for (Node *n = this; n; n = n->parentNode())        n->notifyLocalNodeListsAttributeChanged();}void Node::notifyLocalNodeListsChildrenChanged(){    if (!hasRareData())        return;    NodeRareData* data = rareData();    if (!data->nodeLists())        return;    data->nodeLists()->invalidateCaches();    NodeListsNodeData::NodeListSet::iterator end = data->nodeLists()->m_listsWithCaches.end();    for (NodeListsNodeData::NodeListSet::iterator i = data->nodeLists()->m_listsWithCaches.begin(); i != end; ++i)        (*i)->invalidateCache();    if (data->nodeLists()->isEmpty()) {        data->clearNodeLists();        document()->removeNodeListCache();    }}void Node::notifyNodeListsChildrenChanged(){    for (Node* n = this; n; n = n->parentNode())        n->notifyLocalNodeListsChildrenChanged();}Node *Node::traverseNextNode(const Node *stayWithin) const{    if (firstChild())        return firstChild();    if (this == stayWithin)        return 0;    if (nextSibling())        return nextSibling();    const Node *n = this;    while (n && !n->nextSibling() && (!stayWithin || n->parentNode() != stayWithin))        n = n->parentNode();    if (n)        return n->nextSibling();    return 0;}Node *Node::traverseNextSibling(const Node *stayWithin) const{    if (this == stayWithin)        return 0;    if (nextSibling())        return nextSibling();    const Node *n = this;    while (n && !n->nextSibling() && (!stayWithin || n->parentNode() != stayWithin))        n = n->parentNode();    if (n)        return n->nextSibling();    return 0;}Node* Node::traverseNextNodePostOrder() const{    Node* next = nextSibling();    if (!next)        return parentNode();    while (Node* firstChild = next->firstChild())        next = firstChild;    return next;}Node *Node::traversePreviousNode(const Node *stayWithin) const{    if (this == stayWithin)        return 0;    if (previousSibling()) {        Node *n = previousSibling();        while (n->lastChild())            n = n->lastChild();        return n;    }    return parentNode();}Node *Node::traversePreviousNodePostOrder(const Node *stayWithin) const{    if (lastChild())        return lastChild();    if (this == stayWithin)        return 0;    if (previousSibling())        return previousSibling();    const Node *n = this;    while (n && !n->previousSibling() && (!stayWithin || n->parentNode() != stayWithin))        n = n->parentNode();    if (n)        return n->previousSibling();    return 0;}Node* Node::traversePreviousSiblingPostOrder(const Node* stayWithin) const{

⌨️ 快捷键说明

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