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

📄 dom_nodeimpl.h

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) *           (C) 1999 Antti Koivisto (koivisto@kde.org) *           (C) 2001 Dirk Mueller (mueller@kde.org) *           (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#ifndef _DOM_NodeImpl_h_#define _DOM_NodeImpl_h_#include "dom/dom_misc.h"#include "dom/dom_string.h"#include "dom/dom_node.h"#include "misc/helper.h"#include "misc/shared.h"// The namespace used for XHTML elements#define XHTML_NAMESPACE "http://www.w3.org/1999/xhtml"class QPainter;template <class type> class QPtrList;template <class type> class QValueList;class KHTMLView;class QRect;class QMouseEvent;class QKeyEvent;class QTextStream;namespace khtml {    class RenderStyle;    class RenderObject;    class RenderArena;}namespace DOM {class NodeListImpl;class NamedNodeMapImpl;class DocumentImpl;class CSSStyleDeclarationImpl;class RegisteredEventListener;class EventImpl;class DocumentPtr : public khtml::Shared<DocumentPtr>{public:    DocumentImpl *document() const { return doc; }private:    DocumentPtr() { doc = 0; }    friend class DocumentImpl;    friend class DOMImplementationImpl;    DocumentImpl *doc;};struct RegisteredListenerList {    RegisteredListenerList() : listeners(0)    {}    ~RegisteredListenerList();    void addEventListener(int id, EventListener *listener, const bool useCapture);    void removeEventListener(int id, EventListener *listener, bool useCapture);    void setHTMLEventListener(int id, EventListener *listener);    EventListener *getHTMLEventListener(int id);    bool hasEventListener(int id);    void clear();    //### KDE4: should disappear    bool stillContainsListener(const RegisteredEventListener& listener);    QValueList<RegisteredEventListener>* listeners;//The actual listener list - may be 0private:    bool isHTMLEventListener(EventListener* listener);};// this class implements nodes, which can have a parent but no children:#define NodeImpl_IdNSMask    0xffff0000#define NodeImpl_IdLocalMask 0x0000ffffconst Q_UINT16 noNamespace = 0;const Q_UINT16 anyNamespace = 0xffff;const Q_UINT16 xhtmlNamespace = 1;const Q_UINT16 anyLocalName = 0xffff;inline Q_UINT16 localNamePart(Q_UINT32 id) { return id & NodeImpl_IdLocalMask; }inline Q_UINT16 namespacePart(Q_UINT32 id) { return (((unsigned int)id) & NodeImpl_IdNSMask) >> 16; }inline Q_UINT32 makeId(Q_UINT16 n, Q_UINT16 l) { return (n << 16) | l; }const Q_UINT32 anyQName = makeId(anyNamespace, anyLocalName);class NodeImpl : public khtml::TreeShared<NodeImpl>{    friend class DocumentImpl;public:    NodeImpl(DocumentPtr *doc);    virtual ~NodeImpl();    // DOM methods & attributes for Node    virtual DOMString nodeName() const;    virtual DOMString nodeValue() const;    virtual void setNodeValue( const DOMString &_nodeValue, int &exceptioncode );    virtual unsigned short nodeType() const;    NodeImpl *parentNode() const { return m_parent; }    NodeImpl *previousSibling() const { return m_previous; }    NodeImpl *nextSibling() const { return m_next; }    virtual NodeListImpl *childNodes();    virtual NodeImpl *firstChild() const;    virtual NodeImpl *lastChild() const;    // insertBefore, replaceChild and appendChild also close newChild    // unlike the speed optimized addChild (which is used by the parser)    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;    virtual NodeImpl *cloneNode ( bool deep ) = 0;    virtual DOMString localName() const;    virtual DOMString prefix() const;    virtual DOMString namespaceURI() const;    virtual void setPrefix(const DOMString &_prefix, int &exceptioncode );    void normalize ();    // Other methods (not part of DOM)    virtual bool isElementNode() const { return false; }    virtual bool isHTMLElement() const { return false; }    virtual bool isAttributeNode() const { return false; }    virtual bool isTextNode() const { return false; }    virtual bool isDocumentNode() const { return false; }    virtual bool isXMLElementNode() const { return false; }    virtual bool isGenericFormElement() const { return false; }    virtual bool containsOnlyWhitespace() const { return false; }    virtual bool contentEditable() const;    // helper functions not being part of the DOM    // Attention: they assume that the caller did the consistency checking!    void setPreviousSibling(NodeImpl *previous) { m_previous = previous; }    void setNextSibling(NodeImpl *next) { m_next = next; }    virtual void setFirstChild(NodeImpl *child);    virtual void setLastChild(NodeImpl *child);    // used by the parser. Doesn't do as many error checkings as    // appendChild(), and returns the node into which will be parsed next.    virtual NodeImpl *addChild(NodeImpl *newChild);    typedef Q_UINT32 Id;    // id() is used to easily and exactly identify a node. It    // is optimized for quick comparison and low memory consumption.    // its value depends on the owner document of the node and is    // categorized in the following way:    // 1..ID_LAST_TAG: the node inherits HTMLElementImpl and is    //                 part of the HTML namespace.    //                 The HTML namespace is either the global    //                 one (no namespace) or the XHTML namespace    //                 depending on the owner document's doctype    // ID_LAST_TAG+1..0xffff: non-HTML elements in the global namespace    // others       non-HTML elements in a namespace.    //                 the upper 16 bit identify the namespace    //                 the lower 16 bit identify the local part of the    //                 qualified element name.    virtual Id id() const { return 0; }    enum IdType {        AttributeId,        ElementId,        NamespaceId    };    enum MouseEventType {        MousePress,        MouseRelease,        MouseClick,        MouseDblClick,        MouseMove    };    struct MouseEvent    {        MouseEvent( int _button, MouseEventType _type,                    const DOMString &_url = DOMString(), const DOMString& _target = DOMString(),                    NodeImpl *_innerNode = 0, NodeImpl *_innerNonSharedNode = 0)            {                button = _button; type = _type;                url = _url; target = _target;                innerNode = _innerNode;		innerNonSharedNode = _innerNonSharedNode;            }        int button;        MouseEventType type;        DOMString url; // url under mouse or empty        DOMString target;        Node innerNode;	Node innerNonSharedNode;    };    // for LINK and STYLE    virtual void sheetLoaded() {}    bool hasID() const      { return m_hasId; }    bool hasStyle() const   { return m_hasStyle; }    bool active() const     { return m_active; }    bool focused() const { return m_focused; }    bool attached() const   { return m_attached; }    bool closed() const     { return m_closed; }    bool changed() const    { return m_changed; }    bool hasChangedChild() const { return m_hasChangedChild; }    bool hasAnchor() const { return m_hasAnchor; }    bool inDocument() const { return m_inDocument; }    bool styleElement() const { return m_styleElement; }    bool implicitNode() const { return m_implicit; }    bool htmlCompat() const { return m_htmlCompat; }    void setHasID(bool b=true) { m_hasId = b; }    void setHasStyle(bool b=true) { m_hasStyle = b; }    void setHasChangedChild( bool b = true ) { m_hasChangedChild = b; }    void setInDocument(bool b=true) { m_inDocument = b; }    void setHTMLCompat(bool b) { m_htmlCompat = b; }    virtual void setFocus(bool b=true) { m_focused = b; }    virtual void setActive(bool b=true) { m_active = b; }    virtual void setChanged(bool b=true);    unsigned short tabIndex() const { return m_tabIndex; }    void setTabIndex(unsigned short _tabIndex) { m_tabIndex = _tabIndex; }    virtual bool isFocusable() const { return false; }    virtual bool isMouseFocusable() const { return isFocusable(); }    virtual bool isTabFocusable() const { return isFocusable(); }    virtual bool isInline() const;    virtual void getCaret(int offset, bool override, int &_x, int &_y, int &width, int &height);    virtual QRect getRect() const;    enum StyleChange { NoChange, NoInherit, Inherit, Force };    virtual void recalcStyle( StyleChange = NoChange ) {}    StyleChange diff( khtml::RenderStyle *s1, khtml::RenderStyle *s2 ) const;    unsigned long nodeIndex() const;    // Returns the document that this node is associated with. This is guaranteed to always be non-null, as opposed to    // DOM's ownerDocument() which is null for Document nodes (and sometimes DocumentType nodes).    DocumentImpl* getDocument() const { return document->document(); }    void addEventListener(int id, EventListener *listener, const bool useCapture);    void removeEventListener(int id, EventListener *listener, bool useCapture);    void setHTMLEventListener(int id, EventListener *listener);    EventListener *getHTMLEventListener(int id);    void dispatchEvent(EventImpl *evt, int &exceptioncode, bool tempEvent = false);    void dispatchGenericEvent( EventImpl *evt, int &exceptioncode);    // return true if event not prevented    bool dispatchHTMLEvent(int _id, bool canBubbleArg, bool cancelableArg);    void dispatchWindowEvent(int _id, bool canBubbleArg, bool cancelableArg);    void dispatchMouseEvent(QMouseEvent *e, int overrideId = 0, int overrideDetail = 0);    void dispatchUIEvent(int _id, int detail = 0);    void dispatchSubtreeModifiedEvent();    // return true if defaultPrevented (i.e. event should be swallowed)    // this matches the logic in KHTMLView.    bool dispatchKeyEvent(QKeyEvent *key, bool keypress);    void handleLocalEvents(EventImpl *evt, bool useCapture);    /**     * Perform the default action for an event e.g. submitting a form     */    virtual void defaultEventHandler(EventImpl *evt);    virtual bool isReadOnly();    virtual bool childTypeAllowed( unsigned short /*type*/ ) { return false; }    virtual unsigned long childNodeCount();    virtual NodeImpl *childNode(unsigned long index);    /**     * Does a pre-order traversal of the tree to find the node next node after this one. This uses the same order that     * the tags appear in the source file.     *     * @param stayWithin If not null, the traversal will stop once the specified node is reached. This can be used to     * restrict traversal to a particular sub-tree.     *     * @return The next node, in document order     *     * see traversePreviousNode()     */    NodeImpl *traverseNextNode(NodeImpl *stayWithin = 0) const;    /**     * Does a reverse pre-order traversal to find the node that comes before the current one in document order     *     * see traverseNextNode()     */    NodeImpl *traversePreviousNode() const;    DocumentPtr *docPtr() const { return document; }    khtml::RenderObject *renderer() const { return m_render; }    khtml::RenderObject *nextRenderer();    khtml::RenderObject *previousRenderer();    void setRenderer(khtml::RenderObject* renderer) { m_render = renderer; }    void checkSetPrefix(const DOMString &_prefix, int &exceptioncode);    void checkAddChild(NodeImpl *newChild, int &exceptioncode);    bool isAncestor( NodeImpl *other );    virtual bool childAllowed( NodeImpl *newChild );    /**     * Returns the minimum caret offset that is allowed for this node.     *     * This default implementation always returns 0. Textual child nodes     * may return other values.     */    virtual long minOffset() const;    /**     * Returns the maximum caret offset that is allowed for this node.     *     * This default implementation always returns the node count.     * Textual child nodes return the character count instead.     */    virtual long maxOffset() const;    // -----------------------------------------------------------------------------    // Integration with rendering tree    /**     * Attaches this node to the rendering tree. This calculates the style to be applied to the node and creates an     * appropriate RenderObject which will be inserted into the tree (except when the style has display: none). This     * makes the node visible in the KHTMLView.     */    virtual void attach();    /**     * Detaches the node from the rendering tree, making it invisible in the rendered view. This method will remove     * the node's rendering object from the rendering tree and delete it.     */    virtual void detach();    /**

⌨️ 快捷键说明

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