现在的位置: 首页 > 综合 > 正文

DOM level 2

2014年01月17日 ⁄ 综合 ⁄ 共 9035字 ⁄ 字号 评论关闭

DOM level 2 core
Node object hierarchy:
Document
DocumentFragment
DocumentType
EntityReference
Element
Attr
ProcessingInstruction
Comment
Text
CDATASection
Entity
Notation

Changes between DOM Level 1 Core and DOM Level 2 Core
Interface Attr
The Attr interface has one new attribute: ownerElement.
Interface Document
The Document interface has five new methods: importNode, createElementNS, createAttributeNS, getElementsByTagNameNS and getElementById.
Interface NamedNodeMap
The NamedNodeMap interface has three new methods: getNamedItemNS, setNamedItemNS, removeNamedItemNS.
Interface Node
The Node interface has two new methods: isSupported and hasAttributes.
normalize, previously in the Element interface, has been moved in the Node interface.
The Node interface has three new attributes: namespaceURI, prefix and localName.
The ownerDocument attribute was specified to be null when the node is a Document. It now is also null when the node is a DocumentType which is not used with any Document yet.
Interface DocumentType
The DocumentType interface has three attributes: publicId, systemId and internalSubset.
Interface DOMImplementation
The DOMImplementation interface has two new methods: createDocumentType and createDocument.
Interface Element
The Element interface has eight new methods: getAttributeNS, setAttributeNS, removeAttributeNS, getAttributeNodeNS, setAttributeNodeNS, getElementsByTagNameNS, hasAttribute and hasAttributeNS.
The method normalize is now inherited from the Node interface where it was moved.
Exception DOMException
The DOMException has five new exception codes: INVALID_STATE_ERR, SYNTAX_ERR, INVALID_MODIFICATION_ERR, NAMESPACE_ERR and INVALID_ACCESS_ERR.
A.1.2.1: New types
DOMTimeStamp
The DOMTimeStamp type was added to the Core module.

(DOM) Level 2 Views Specification
1.builds on the "Document Object Model Level 2 Core"
2.AbstractView
create an association between a view and its target document.
3.Interfaces
AbstractView A base interface that all views shall derive from.
DocumentView 

(DOM) Level 2 Events Specification
1.builds on the Document Object Model Level 2 Core [DOM Level 2 Core] and on Document Object Model Level 2 Views [DOM Level 2 
Views].
2.OverView
The first goal is the design of a generic event system.
The specification will provide standard modules of events for user interface control and document mutation notifications.
3.Terminology
UI events
User interface events. These events are generated by user interaction through an external device (mouse, keyboard, etc.)
UI Logical events
Device independent user interface events such as focus change messages or element triggering notifications.
Mutation events
Events caused by any action which modifies the structure of the document.
Capturing
The process by which an event can be handled by one of the event's target's ancestors before being handled by the event's target
Bubbling
The process by which an event propagates upward through its ancestors after being handled by the event's target.
Cancelable

A designation for events which indicates that upon handling the event the client may choose to prevent the DOM implementation from processing any default action associated with the event.

(Capture or Bubble depends on who registered the event.If it's parent, the process will be capture; if it's son, the process will be bubbling.Capture is used from Model to View, Bubble is used from View to Model)
4.basic event flow
All the event listeners of the EventTarget will be triggered. No Event capture or Bubbling will happen.
5.Event capture
The event listener register on the ancestor will would intercept the event, before the event is received by the target. Capture begins from the top of the tree, that is the Document.
Capture just happen downward not upon.
Event's stopProgagation will stop the event.
capture or bubbling is the attribute of the event.
6.Event bubbling
Events is the same as non-bubbling. All the event listener found upward will be triggerd.

in DOM leve2 's event model 

Event Capture and Event Bubbling coexist in the Model, it's event flow including the fellowing 3 phrases:

a. Event capture; b. Event handle; c. Event bubbling

take 

<html>
<head>
</head>
<body>
<div>click me</div>
</body>
</html>

for example , it will be

Capture: Document ->Element.html->Element.body->Element.div

Handle:div

Bubbling: Element.div->Element.body->Element.html->Document

7.Event cancelation
The interface of the event, which will cancle the event.

8.Event registration interfaces
// Introduced in DOM Level 2:
interface EventTarget {
  void               addEventListener(in DOMString type,
                                      in EventListener listener,
                                      in boolean useCapture);
  void               removeEventListener(in DOMString type,
                                         in EventListener listener,
                                         in boolean useCapture);
  boolean            dispatchEvent(in Event evt)
                                        raises(EventException);
};

9.Interface EventListener
interface EventListener {
  void               handleEvent(in Event evt);
};
10.Event interface
interface Event {
  // PhaseType
  const unsigned short      CAPTURING_PHASE                = 1;
  const unsigned short      AT_TARGET                      = 2;
  const unsigned short      BUBBLING_PHASE                 = 3;
  readonly attribute DOMString        type;
  readonly attribute EventTarget      target;
  readonly attribute EventTarget      currentTarget;
  readonly attribute unsigned short   eventPhase;
  readonly attribute boolean          bubbles;
  readonly attribute boolean          cancelable;
  readonly attribute DOMTimeStamp     timeStamp;
  void               stopPropagation();
  void               preventDefault();
  void               initEvent(in DOMString eventTypeArg,
                               in boolean canBubbleArg,
                               in boolean cancelableArg);
};
DocumentEvent interface
interface DocumentEvent {
  Event              createEvent(in DOMString eventType)
                                        raises(DOMException);
};

Event module definitions
the DOM will define a module of user interface events including lower level device dependent events, a module of UI logical events, and a module of document mutation events.

a.UIEvent
interface UIEvent : Event {
  readonly attribute views::AbstractView  view;
  readonly attribute long             detail;
  void               initUIEvent(in DOMString typeArg,
                                 in boolean canBubbleArg,
                                 in boolean cancelableArg,
                                 in views::AbstractView viewArg,
                                 in long detailArg);
};

b.interface MouseEvent : UIEvent {
  readonly attribute long             screenX;
  readonly attribute long             screenY;
  readonly attribute long             clientX;
  readonly attribute long             clientY;
  readonly attribute boolean          ctrlKey;
  readonly attribute boolean          shiftKey;
  readonly attribute boolean          altKey;
  readonly attribute boolean          metaKey;
  readonly attribute unsigned short   button;
  readonly attribute EventTarget      relatedTarget;
  void               initMouseEvent(in DOMString typeArg,
                                    in boolean canBubbleArg,
                                    in boolean cancelableArg,
                                    in views::AbstractView viewArg,
                                    in long detailArg,
                                    in long screenXArg,
                                    in long screenYArg,
                                    in long clientXArg,
                                    in long clientYArg,
                                    in boolean ctrlKeyArg,
                                    in boolean altKeyArg,
                                    in boolean shiftKeyArg,
                                    in boolean metaKeyArg,
                                    in unsigned short buttonArg,
                                    in EventTarget relatedTargetArg);
};

c.Key events, no
d.interface MutationEvent : Event {

  // attrChangeType
  const unsigned short      MODIFICATION                   = 1;
  const unsigned short      ADDITION                       = 2;
  const unsigned short      REMOVAL                        = 3;

  readonly attribute Node             relatedNode;
  readonly attribute DOMString        prevValue;
  readonly attribute DOMString        newValue;
  readonly attribute DOMString        attrName;
  readonly attribute unsigned short   attrChange;
  void               initMutationEvent(in DOMString typeArg,
                                       in boolean canBubbleArg,
                                       in boolean cancelableArg,
                                       in Node relatedNodeArg,
                                       in DOMString prevValueArg,
                                       in DOMString newValueArg,
                                       in DOMString attrNameArg,
                                       in unsigned short attrChangeArg);
};

Document Object Model (DOM) Level 2 Traversal and Range Specification
1.Introduction
TreeWalker and NodeIterator is the interfaces to provider traversal of a document's contents.
NodeIterator presents a flattened view, TreeWalker maintains the hierarchical relationship.
NodeIterator and TreeWalker present a view of a document subtree. Iterator or TreeWalker is created with a NodeFilter to examine each node to be included.
2.NodeIterators
a.create a NodeIterator
    NodeIterator iter=
     ((DocumentTraversal)document).createNodeIterator(
          root, NodeFilter.SHOW_ELEMENT, null);

    while (Node n = iter.nextNode())
        printMe(n);

Javascript
1.ScriptController is a class execute the script. It has the member "Frame m_frame" which is the Document's Frame to manipulate.
"m_frame" is valued in ScriptController's construction parameter list.
2.Frame has member "ScriptController m_script" and "<DOMWindow> m_domWindow"
?DOMWindow is the "Window" in the javascript

抱歉!评论已关闭.