📄 dom_nodeimpl.h
字号:
* Notifies the node that no more children will be added. */ virtual void close(); void closeRenderer(); void createRendererIfNeeded(); virtual khtml::RenderStyle *styleForRenderer(khtml::RenderObject *parent); virtual bool rendererIsNeeded(khtml::RenderStyle *); virtual khtml::RenderObject *createRenderer(khtml::RenderArena *, khtml::RenderStyle *); // ----------------------------------------------------------------------------- // Methods for maintaining the state of the element between history navigation /** * Indicates whether or not this type of node maintains its state. If so, the state of the node will be stored when * the user goes to a different page using the state() method, and restored using the restoreState() method if the * user returns (e.g. using the back button). This is used to ensure that user-changeable elements such as form * controls maintain their contents when the user returns to a previous page in the history. */ virtual bool maintainsState(); /** * Returns the state of this node represented as a string. This string will be passed to restoreState() if the user * returns to the page. * * @return State information about the node represented as a string */ virtual QString state(); /** * Sets the state of the element based on a string previosuly returned by state(). This is used to initialize form * controls with their old values when the user returns to the page in their history. * * @param state A string representation of the node's previously-stored state */ virtual void restoreState(const QString &state); // ----------------------------------------------------------------------------- // Notification of document stucture changes /** * Notifies the node that it has been inserted into the document. This is called during document parsing, and also * when a node is added through the DOM methods insertBefore(), appendChild() or replaceChild(). Note that this only * happens when the node becomes part of the document tree, i.e. only when the document is actually an ancestor of * the node. The call happens _after_ the node has been added to the tree. * * This is similar to the DOMNodeInsertedIntoDocument DOM event, but does not require the overhead of event * dispatching. */ virtual void insertedIntoDocument(); /** * Notifies the node that it is no longer part of the document tree, i.e. when the document is no longer an ancestor * node. * * This is similar to the DOMNodeRemovedFromDocument DOM event, but does not require the overhead of event * dispatching, and is called _after_ the node is removed from the tree. */ virtual void removedFromDocument(); /** * Notifies the node that its list of children have changed (either by adding or removing child nodes), or a child * node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value. */ virtual void childrenChanged(); virtual DOMString toString() const = 0; /** * Sometimes we need to get the string between two points on the DOM graph. Use this function to do this. * For example, when the user copies some selected text to the clipboard as html. * @param selectionStart Where to start the selection. If selectionStart != this, it is assumed we are after the start point * @param selectionEnd Where to end the selection. If selectionEnd != this, it is assumed we are before the end point (unless found is true) * @param startOffset Number of characters into the text in selectionStart that the start of the selection is. * @param endOffset Number of characters into the text in selectionEnd that the end of the selection is. * @param found When this is set to true, don't print anymore but closing tags. * @return An html formatted string for this node and its children between the selectionStart and selectionEnd. */ virtual DOMString selectionToString(NodeImpl * /*selectionStart*/, NodeImpl * /*selectionEnd*/, int /*startOffset*/, int /*endOffset*/, bool &/*found*/) const { return toString(); }private: // members DocumentPtr *document; NodeImpl *m_previous; NodeImpl *m_next;protected: khtml::RenderObject *m_render; RegisteredListenerList m_regdListeners; unsigned short m_tabIndex : 15; bool m_hasTabIndex : 1; bool m_hasId : 1; bool m_hasStyle : 1; bool m_attached : 1; bool m_closed : 1; bool m_changed : 1; bool m_hasChangedChild : 1; bool m_inDocument : 1; bool m_hasAnchor : 1; bool m_specified : 1; // used in AttrImpl. Accessor functions there bool m_focused : 1; bool m_active : 1; bool m_styleElement : 1; // contains stylesheet text bool m_implicit : 1; // implicitely generated by the parser bool m_rendererNeedsClose : 1; bool m_htmlCompat : 1; // true if element was created in HTML compat mode bool m_unused : 1;};// this is the full Node Implementation with parents and children.class NodeBaseImpl : public NodeImpl{public: NodeBaseImpl(DocumentPtr *doc) : NodeImpl(doc), _first(0), _last(0) {} virtual ~NodeBaseImpl(); // DOM methods overridden from parent classes virtual NodeImpl *firstChild() const; virtual NodeImpl *lastChild() const; virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode ); virtual NodeImpl *replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ); virtual NodeImpl *removeChild ( NodeImpl *oldChild, int &exceptioncode ); virtual NodeImpl *appendChild ( NodeImpl *newChild, int &exceptioncode ); virtual bool hasChildNodes ( ) const; // Other methods (not part of DOM) void removeChildren(); void cloneChildNodes(NodeImpl *clone); virtual void setFirstChild(NodeImpl *child); virtual void setLastChild(NodeImpl *child); virtual NodeImpl *addChild(NodeImpl *newChild); virtual void attach(); virtual void detach(); bool getUpperLeftCorner(int &xPos, int &yPos) const; bool getLowerRightCorner(int &xPos, int &yPos) const; virtual void setFocus(bool=true); virtual void setActive(bool=true); virtual unsigned long childNodeCount(); virtual NodeImpl *childNode(unsigned long index);protected: NodeImpl *_first; NodeImpl *_last; // helper functions for inserting children: // ### this should vanish. do it in dom/ ! // check for same source document: bool checkSameDocument( NodeImpl *newchild, int &exceptioncode ); // check for being child: bool checkIsChild( NodeImpl *oldchild, int &exceptioncode ); // ### // find out if a node is allowed to be our child void dispatchChildInsertedEvents( NodeImpl *child, int &exceptioncode ); void dispatchChildRemovalEvents( NodeImpl *child, int &exceptioncode );};// --------------------------------------------------------------------------class Node;class NodeImpl;class NodeListImpl : public khtml::Shared<NodeListImpl>{public: //Type of the item stored in the cache. enum Type { UNCACHEABLE, //Too complex to be cached like this CHILD_NODES, LAST_NODE_LIST = CHILD_NODES }; struct CacheKey { NodeImpl* baseNode; int type; CacheKey(): type(UNCACHEABLE) {} CacheKey(NodeImpl* _baseNode, int _type): baseNode(_baseNode), type(_type) {} int hash() const { return int(reinterpret_cast<unsigned long>(baseNode) >> 2) ^ (unsigned(type) << 26); } bool operator==(const CacheKey& other) const { return baseNode == other.baseNode && type == other.type; } }; struct Cache: public khtml::Shared<Cache> { static Cache* make() { return new Cache; } CacheKey key;//### We must store this in here due to QCache in Qt3 sucking unsigned int version; union { NodeImpl* node; unsigned int index; } current; unsigned int position; unsigned int length; bool hasLength; void updateNodeListInfo(DocumentImpl* doc); virtual void clear(DocumentImpl* doc); virtual ~Cache(); }; typedef Cache* CacheFactory(); NodeListImpl(NodeImpl* node, int type, CacheFactory* factory = 0); virtual ~NodeListImpl(); // DOM methods & attributes for NodeList virtual unsigned long length() const; virtual NodeImpl *item ( unsigned long index ) const; // Other methods (not part of DOM)protected: // helper functions for searching all ElementImpls in a tree unsigned long recursiveLength(NodeImpl *start) const; NodeImpl *recursiveItem ( NodeImpl* absStart, NodeImpl *start, unsigned long &offset ) const; NodeImpl *recursiveItemBack( NodeImpl* absStart, NodeImpl *start, unsigned long &offset ) const; // Override this to determine what nodes to return. Set doRecurse to // false if the children of this node do not need to be entered. virtual bool nodeMatches( NodeImpl *testNode, bool& doRecurse ) const = 0; NodeImpl* m_refNode; mutable Cache* m_cache;};class ChildNodeListImpl : public NodeListImpl{public: ChildNodeListImpl( NodeImpl *n); protected: virtual bool nodeMatches( NodeImpl *testNode, bool& doRecurse ) const;};/** * NodeList which lists all Nodes in a document with a given tag name */class TagNodeListImpl : public NodeListImpl{public: TagNodeListImpl( NodeImpl *n, NodeImpl::Id id ); TagNodeListImpl( NodeImpl *n, const DOMString &namespaceURI, const DOMString &localName ); // Other methods (not part of DOM)protected: virtual bool nodeMatches( NodeImpl *testNode, bool& doRecurse ) const; NodeImpl::Id m_id; DOMString m_namespaceURI; DOMString m_localName; bool m_matchAllNames; bool m_matchAllNamespaces; bool m_namespaceAware;};/** * NodeList which lists all Nodes in a Element with a given "name=" tag */class NameNodeListImpl : public NodeListImpl{public: NameNodeListImpl( NodeImpl *doc, const DOMString &t ); // Other methods (not part of DOM)protected: virtual bool nodeMatches( NodeImpl *testNode, bool& doRecurse ) const; DOMString nodeName;};// Generic NamedNodeMap interface// Other classes implement this for more specific situations e.g. attributes// of an elementclass NamedNodeMapImpl : public khtml::Shared<NamedNodeMapImpl>{public: NamedNodeMapImpl(); virtual ~NamedNodeMapImpl(); // DOM methods & attributes for NamedNodeMap virtual NodeImpl *getNamedItem ( NodeImpl::Id id, bool nsAware = false, DOMStringImpl* qName = 0 ) const = 0; virtual Node removeNamedItem ( NodeImpl::Id id, bool nsAware, DOMStringImpl* qName, int &exceptioncode ) = 0; virtual Node setNamedItem ( NodeImpl* arg, bool nsAware, DOMStringImpl* qName, int &exceptioncode ) = 0; virtual NodeImpl *item ( unsigned long index ) const = 0; virtual unsigned long length( ) const = 0; // Other methods (not part of DOM) virtual NodeImpl::Id mapId(DOMStringImpl* namespaceURI, DOMStringImpl* localName, bool readonly) = 0; virtual bool isReadOnly() { return false; }};// Generic read-only NamedNodeMap implementation// Used for e.g. entities and notations in DocumentType.// You can add nodes using addNodeclass GenericRONamedNodeMapImpl : public NamedNodeMapImpl{public: GenericRONamedNodeMapImpl(DocumentPtr* doc); virtual ~GenericRONamedNodeMapImpl(); // DOM methods & attributes for NamedNodeMap virtual NodeImpl *getNamedItem ( NodeImpl::Id id, bool nsAware = false, DOMStringImpl* qName = 0 ) const; virtual Node removeNamedItem ( NodeImpl::Id id, bool nsAware, DOMStringImpl* qName, int &exceptioncode ); virtual Node setNamedItem ( NodeImpl* arg, bool nsAware, DOMStringImpl* qName, int &exceptioncode ); virtual NodeImpl *item ( unsigned long index ) const; virtual unsigned long length( ) const; // Other methods (not part of DOM) virtual NodeImpl::Id mapId(DOMStringImpl* namespaceURI, DOMStringImpl* localName, bool readonly); virtual bool isReadOnly() { return true; } void addNode(NodeImpl *n);protected: DocumentImpl* m_doc; QPtrList<NodeImpl> *m_contents;};} //namespace#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -