documentimpl.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,275 行 · 第 1/4 页

JAVA
1,275
字号
            if (enclosingAttr != null) {                dispatchEvent(enclosingAttr, me);                if (owner != null)                    dispatchEvent(owner, me);            }            else                dispatchEvent(node, me);        }    } // dispatchAggregateEvents(NodeImpl, AttrImpl,String) :void    /**     * NON-DOM INTERNAL: Pre-mutation context check, in     * preparation for later generating DOMAttrModified events.     * Determines whether this node is within an Attr     * @param node node to get enclosing attribute for     * @return either a description of that Attr, or null if none such.      */    protected void saveEnclosingAttr(NodeImpl node) {        savedEnclosingAttr = null;        // MUTATION PREPROCESSING AND PRE-EVENTS:        // If we're within the scope of an Attr and DOMAttrModified         // was requested, we need to preserve its previous value for        // that event.        LCount lc = LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);        if (lc.captures + lc.bubbles + lc.defaults > 0) {            NodeImpl eventAncestor = node;            while (true) {                if (eventAncestor == null)                    return;                int type = eventAncestor.getNodeType();                if (type == Node.ATTRIBUTE_NODE) {                    EnclosingAttr retval = new EnclosingAttr();                    retval.node = (AttrImpl) eventAncestor;                    retval.oldvalue = retval.node.getNodeValue();                    savedEnclosingAttr = retval;                    return;                }                else if (type == Node.ENTITY_REFERENCE_NODE)                    eventAncestor = eventAncestor.parentNode();                else                    return;                // Any other parent means we're not in an Attr            }        }    } // saveEnclosingAttr(NodeImpl) :void    /**     * A method to be called when a character data node has been modified     */    void modifyingCharacterData(NodeImpl node) {        if (mutationEvents) {            saveEnclosingAttr(node);        }    }    /**     * A method to be called when a character data node has been modified     */    void modifiedCharacterData(NodeImpl node, String oldvalue, String value) {        if (mutationEvents) {            // MUTATION POST-EVENTS:            LCount lc =                LCount.lookup(MutationEventImpl.DOM_CHARACTER_DATA_MODIFIED);            if (lc.captures + lc.bubbles + lc.defaults > 0) {                MutationEvent me = new MutationEventImpl();                me.initMutationEvent(                                 MutationEventImpl.DOM_CHARACTER_DATA_MODIFIED,                                     true, false, null,                                     oldvalue, value, null, (short) 0);                dispatchEvent(node, me);            }                        // Subroutine: Transmit DOMAttrModified and DOMSubtreeModified,            // if required. (Common to most kinds of mutation)            dispatchAggregateEvents(node, savedEnclosingAttr);        } // End mutation postprocessing    }    /**     * A method to be called when a node is about to be inserted in the tree.     */    void insertingNode(NodeImpl node, boolean replace) {        if (mutationEvents) {            if (!replace) {                saveEnclosingAttr(node);            }        }    }    /**     * A method to be called when a node has been inserted in the tree.     */    void insertedNode(NodeImpl node, NodeImpl newInternal, boolean replace) {        if (mutationEvents) {            // MUTATION POST-EVENTS:            // "Local" events (non-aggregated)            // New child is told it was inserted, and where            LCount lc = LCount.lookup(MutationEventImpl.DOM_NODE_INSERTED);            if (lc.captures + lc.bubbles + lc.defaults > 0) {                MutationEventImpl me = new MutationEventImpl();                me.initMutationEvent(MutationEventImpl.DOM_NODE_INSERTED,                                     true, false, node,                                     null, null, null, (short) 0);                dispatchEvent(newInternal, me);            }            // If within the Document, tell the subtree it's been added            // to the Doc.            lc = LCount.lookup(                            MutationEventImpl.DOM_NODE_INSERTED_INTO_DOCUMENT);            if (lc.captures + lc.bubbles + lc.defaults > 0) {                NodeImpl eventAncestor = node;                if (savedEnclosingAttr != null)                    eventAncestor = (NodeImpl)                        savedEnclosingAttr.node.getOwnerElement();                if (eventAncestor != null) { // Might have been orphan Attr                    NodeImpl p = eventAncestor;                    while (p != null) {                        eventAncestor = p; // Last non-null ancestor                        // In this context, ancestry includes                        // walking back from Attr to Element                        if (p.getNodeType() == ATTRIBUTE_NODE) {                            p = (NodeImpl) ((AttrImpl)p).getOwnerElement();                        }                        else {                            p = p.parentNode();                        }                    }                    if (eventAncestor.getNodeType() == Node.DOCUMENT_NODE){                        MutationEventImpl me = new MutationEventImpl();                        me.initMutationEvent(MutationEventImpl                                             .DOM_NODE_INSERTED_INTO_DOCUMENT,                                             false,false,null,null,                                             null,null,(short)0);                        dispatchEventToSubtree(node, newInternal, me);                    }                }            }            if (!replace) {                // Subroutine: Transmit DOMAttrModified and DOMSubtreeModified                // (Common to most kinds of mutation)                dispatchAggregateEvents(node, savedEnclosingAttr);            }        }    }    /**     * A method to be called when a node is about to be removed from the tree.     */    void removingNode(NodeImpl node, NodeImpl oldChild, boolean replace) {        // notify iterators        if (iterators != null) {            int size = iterators.size();            for (int i = 0; i != size; i++) {               ((NodeIteratorImpl)iterators.elementAt(i)).removeNode(oldChild);            }        }        // notify ranges        if (ranges != null) {            int size = ranges.size();            for (int i = 0; i != size; i++) {                ((RangeImpl)ranges.elementAt(i)).removeNode(oldChild);            }        }        // mutation events        if (mutationEvents) {            // MUTATION PREPROCESSING AND PRE-EVENTS:            // If we're within the scope of an Attr and DOMAttrModified             // was requested, we need to preserve its previous value for            // that event.            if (!replace) {                saveEnclosingAttr(node);            }            // Child is told that it is about to be removed            LCount lc = LCount.lookup(MutationEventImpl.DOM_NODE_REMOVED);            if (lc.captures + lc.bubbles + lc.defaults > 0) {                MutationEventImpl me= new MutationEventImpl();                me.initMutationEvent(MutationEventImpl.DOM_NODE_REMOVED,                                     true, false, node, null,                                     null, null, (short) 0);                dispatchEvent(oldChild, me);            }            // If within Document, child's subtree is informed that it's            // losing that status            lc = LCount.lookup(                             MutationEventImpl.DOM_NODE_REMOVED_FROM_DOCUMENT);            if (lc.captures + lc.bubbles + lc.defaults > 0) {                NodeImpl eventAncestor = this;                if(savedEnclosingAttr != null)                    eventAncestor = (NodeImpl)                        savedEnclosingAttr.node.getOwnerElement();                if (eventAncestor != null) { // Might have been orphan Attr                    for (NodeImpl p = eventAncestor.parentNode();                         p != null; p = p.parentNode()) {                        eventAncestor = p; // Last non-null ancestor                    }                    if (eventAncestor.getNodeType() == Node.DOCUMENT_NODE){                        MutationEventImpl me = new MutationEventImpl();                        me.initMutationEvent(                              MutationEventImpl.DOM_NODE_REMOVED_FROM_DOCUMENT,                                             false, false, null,                                             null, null, null, (short) 0);                        dispatchEventToSubtree(node, oldChild, me);                    }                }            }        } // End mutation preprocessing    }    /**     * A method to be called when a node has been removed from the tree.     */    void removedNode(NodeImpl node, boolean replace) {        if (mutationEvents) {            // MUTATION POST-EVENTS:            // Subroutine: Transmit DOMAttrModified and DOMSubtreeModified,            // if required. (Common to most kinds of mutation)            if (!replace) {                dispatchAggregateEvents(node, savedEnclosingAttr);            }        } // End mutation postprocessing    }    /**     * A method to be called when a node is about to be replaced in the tree.     */    void replacingNode(NodeImpl node) {        if (mutationEvents) {            saveEnclosingAttr(node);        }    }    /**     * A method to be called when a node has been replaced in the tree.     */    void replacedNode(NodeImpl node) {        if (mutationEvents) {            dispatchAggregateEvents(node, savedEnclosingAttr);        }    }    /**     * A method to be called when an attribute value has been modified     */    void modifiedAttrValue(AttrImpl attr, String oldvalue) {        if (mutationEvents) {            // MUTATION POST-EVENTS:            dispatchAggregateEvents(attr, attr, oldvalue,                                    MutationEvent.MODIFICATION);        }    }    /**     * A method to be called when an attribute node has been set     */    void setAttrNode(AttrImpl attr, AttrImpl previous) {        if (mutationEvents) {            // MUTATION POST-EVENTS:            if (previous == null) {                dispatchAggregateEvents(attr.ownerNode, attr, null,                                        MutationEvent.ADDITION);            }            else {                dispatchAggregateEvents(attr.ownerNode, attr,                                        previous.getNodeValue(),                                        MutationEvent.MODIFICATION);            }        }    }    /**     * A method to be called when an attribute node has been removed     */    void removedAttrNode(AttrImpl attr, NodeImpl oldOwner, String name) {        // We can't use the standard dispatchAggregate, since it assumes        // that the Attr is still attached to an owner. This code is        // similar but dispatches to the previous owner, "element".        if (mutationEvents) {    	    // If we have to send DOMAttrModified (determined earlier),            // do so.            LCount lc = LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);            if (lc.captures + lc.bubbles + lc.defaults > 0) {                MutationEventImpl me= new MutationEventImpl();                me.initMutationEvent(MutationEventImpl.DOM_ATTR_MODIFIED,                                     true, false, attr,                                     attr.getNodeValue(), null, name,                                     MutationEvent.REMOVAL);                dispatchEvent(oldOwner, me);            }            // We can hand off to process DOMSubtreeModified, though.            // Note that only the Element needs to be informed; the            // Attr's subtree has not been changed by this operation.            dispatchAggregateEvents(oldOwner, null, null, (short) 0);        }    }        /**     * A method to be called when an attribute node has been renamed     */    void renamedAttrNode(Attr oldAt, Attr newAt) {	// REVISIT: To be implemented!!!    }    /**     * A method to be called when an element has been renamed     */    void renamedElement(Element oldEl, Element newEl) {	// REVISIT: To be implemented!!!    }} // class DocumentImpl

⌨️ 快捷键说明

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