27 #ifndef _DOM_DocumentImpl_h_ 28 #define _DOM_DocumentImpl_h_ 30 #include "xml/dom_elementimpl.h" 31 #include "xml/dom_nodelistimpl.h" 32 #include "xml/dom_textimpl.h" 33 #include "xml/dom2_traversalimpl.h" 34 #include "xml/security_origin.h" 35 #include "misc/shared.h" 36 #include "misc/loader.h" 37 #include "misc/seed.h" 39 #include <QStringList> 47 #include <QTimerEvent> 58 class CSSStyleSelector;
65 class CachedCSSStyleSheet;
66 class DynamicDomRestyler;
68 class XPathResultImpl;
69 class XPathExpressionImpl;
70 class XPathNSResolverImpl;
80 class SVGDocumentExtensions;
87 class AbstractViewImpl;
89 class CDATASectionImpl;
90 class CSSStyleSheetImpl;
92 class DocumentFragmentImpl;
94 class XMLDocumentImpl;
96 class DocumentTypeImpl;
97 class EditingTextImpl;
99 class EntityReferenceImpl;
102 class HTMLDocumentImpl;
103 class HTMLElementImpl;
104 class HTMLPartContainerElementImpl;
105 class HTMLImageElementImpl;
108 class NodeFilterImpl;
109 class NodeIteratorImpl;
111 class ProcessingInstructionImpl;
113 class StyleSheetImpl;
114 class StyleSheetListImpl;
116 class TreeWalkerImpl;
117 class WindowEventTargetImpl;
119 class DOMImplementationImpl :
public khtml::Shared<DOMImplementationImpl>
122 DOMImplementationImpl();
123 ~DOMImplementationImpl();
127 DocumentTypeImpl *createDocumentType(
const DOMString &qualifiedName,
const DOMString &publicId,
128 const DOMString &systemId,
int &exceptioncode);
129 static DocumentImpl *createDocument(
const DOMString &namespaceURI,
const DOMString &qualifiedName,
130 DocumentTypeImpl *dtype,
134 static CSSStyleSheetImpl *createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media,
int &exceptioncode);
137 static HTMLDocumentImpl *createHTMLDocument(
const DOMString &title);
140 static DocumentImpl *createDocument(
KHTMLView *v =
nullptr);
141 static XMLDocumentImpl *createXMLDocument(
KHTMLView *v =
nullptr);
142 static HTMLDocumentImpl *createHTMLDocument(
KHTMLView *v =
nullptr);
143 static WebCore::SVGDocument *createSVGDocument(
KHTMLView *v =
nullptr);
171 void add(
const DOMString &
id, ElementImpl *nd);
176 void set(
const DOMString &id, ElementImpl *nd);
181 void remove(
const DOMString &id, ElementImpl *nd);
208 DocumentTypeImpl *doctype()
const;
210 DOMImplementationImpl *implementation()
const;
211 ElementImpl *documentElement()
const;
212 void childrenChanged()
override;
213 virtual ElementImpl *createElement(
const DOMString &tagName,
int *pExceptioncode =
nullptr);
214 virtual AttrImpl *createAttribute(
const DOMString &tagName,
int *pExceptioncode =
nullptr);
215 DocumentFragmentImpl *createDocumentFragment();
216 TextImpl *createTextNode(DOMStringImpl *data)
218 return new TextImpl(docPtr(), data);
220 TextImpl *createTextNode(
const QString &data)
222 return createTextNode(
new DOMStringImpl(data.
unicode(), data.
length()));
224 TextImpl *createTextNode(
const DOMString &data)
228 TextImpl *createTextNode(
const char *latin1)
230 return createTextNode(
DOMString(latin1));
232 CommentImpl *createComment(DOMStringImpl *data);
233 CDATASectionImpl *createCDATASection(DOMStringImpl *data,
int &exceptioncode);
234 ProcessingInstructionImpl *createProcessingInstruction(
const DOMString &target, DOMStringImpl *data);
235 EntityReferenceImpl *createEntityReference(
const DOMString &name,
int &exceptioncode);
236 NodeImpl *importNode(NodeImpl *importedNode,
bool deep,
int &exceptioncode);
237 virtual ElementImpl *createElementNS(
const DOMString &_namespaceURI,
const DOMString &_qualifiedName,
238 int *pExceptioncode =
nullptr);
239 virtual AttrImpl *createAttributeNS(
const DOMString &_namespaceURI,
const DOMString &_qualifiedName,
240 int *pExceptioncode =
nullptr);
241 ElementImpl *getElementById(
const DOMString &elementId)
const;
244 khtml::XPathExpressionImpl *createExpression(
DOM::DOMString &expression,
245 khtml::XPathNSResolverImpl *resolver,
247 khtml::XPathNSResolverImpl *createNSResolver(NodeImpl *nodeResolver);
249 NodeImpl *contextNode,
250 khtml::XPathNSResolverImpl *resolver,
252 khtml::XPathResultImpl *result,
265 unsigned short nodeType()
const override;
268 bool isDocumentNode()
const override 272 virtual bool isHTMLDocument()
const 276 virtual bool isSVGDocument()
const;
278 virtual ElementImpl *createHTMLElement(
const DOMString &tagName,
bool caseInsensitive =
true);
280 virtual ElementImpl *createSVGElement(
const QualifiedName &name);
284 return m_styleSelector;
290 void styleSheetLoaded();
298 return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets;
305 void addPendingSheet();
313 return m_pendingStylesheets;
328 void updateStyleSelector(
bool shallow =
false);
330 void ensureStyleSheetListUpToDate()
332 if (m_styleSheetListDirty) {
333 rebuildStyleSheetList(
true);
337 bool readyForLayout()
const;
340 WindowEventTargetImpl *windowEventTarget()
const 342 return m_windowEventTarget;
345 void rebuildStyleSheetList(
bool force =
false);
346 void rebuildStyleSelector();
347 bool m_styleSheetListDirty;
352 void attemptRestoreState(NodeImpl *e);
356 bool unsubmittedFormChanges();
357 void registerMaintainsState(NodeImpl *e)
359 m_maintainsState.append(e);
361 void deregisterMaintainsState(NodeImpl *e)
364 if ((i = m_maintainsState.indexOf(e)) != -1) {
365 m_maintainsState.removeAt(i);
375 RangeImpl *createRange();
377 NodeIteratorImpl *createNodeIterator(NodeImpl *root,
unsigned long whatToShow,
378 NodeFilterImpl *filter,
bool entityReferenceExpansion,
int &exceptioncode);
380 TreeWalkerImpl *createTreeWalker(NodeImpl *root,
unsigned long whatToShow, NodeFilterImpl *filter,
381 bool entityReferenceExpansion,
int &exceptioncode);
383 EditingTextImpl *createEditingTextNode(
const DOMString &text);
385 void recalcStyle(StyleChange = NoChange)
override;
386 virtual void updateRendering();
388 static void updateDocumentsRendering();
394 void attach()
override;
395 void detach()
override;
397 khtml::RenderArena *renderArena()
399 return m_renderArena.get();
403 void setVisuallyOrdered();
408 void setSelection(NodeImpl *s,
int sp, NodeImpl *e,
int ep);
409 void clearSelection();
410 void updateSelection();
412 void open(
bool clearEventListeners =
true);
413 void close()
override;
414 virtual void contentLoaded() {}
416 void write(
const QString &text);
418 void finishParsing();
424 void setURL(
const QString &url)
431 return m_baseURL.
isEmpty() ? m_url : m_baseURL;
433 void setBaseURL(
const QUrl &baseURL);
439 void setBaseTarget(
const QString &baseTarget)
441 m_baseTarget = baseTarget;
447 return url.isEmpty() ? url : completeURL(url.string());
450 void setUserStyleSheet(
const QString &sheet);
455 void setPrintStyleSheet(
const QString &sheet)
457 m_printSheet = sheet;
459 QString printStyleSheet()
const 464 CSSStyleSheetImpl *elementSheet();
465 virtual khtml::Tokenizer *createTokenizer();
466 khtml::Tokenizer *tokenizer()
485 return m_paintDevice;
501 virtual void determineParseMode();
502 void setParseMode(ParseMode m)
506 ParseMode parseMode()
const 511 bool inCompatMode()
const 513 return pMode == Compat;
515 bool inTransitionalMode()
const 517 return pMode == Transitional;
519 bool inStrictMode()
const 521 return pMode == Strict;
525 HTMLMode htmlMode()
const 530 void setParsing(
bool b)
539 void setHasVariableLength(
bool b =
true)
541 m_bVariableLength = b;
543 bool hasVariableLength()
const 545 return m_bVariableLength;
548 void setTextColor(
QColor color)
557 void setDesignMode(
bool b);
558 bool designMode()
const;
561 bool prepareMouseEvent(
bool readonly,
int x,
int y, MouseEvent *ev);
563 bool childTypeAllowed(
unsigned short nodeType)
override;
564 WTF::PassRefPtr<NodeImpl> cloneNode(
bool deep)
override;
566 StyleSheetListImpl *styleSheets()
568 return m_styleSheets;
573 return m_preferredStylesheetSet;
576 void setSelectedStylesheetSet(
const DOMString &);
577 void setPreferredStylesheetSet(
const DOMString &s)
579 m_preferredStylesheetSet = s;
582 void addStyleSheet(StyleSheetImpl *,
int *exceptioncode =
nullptr);
583 void removeStyleSheet(StyleSheetImpl *,
int *exceptioncode =
nullptr);
587 return m_availableSheets;
590 NodeImpl *hoverNode()
const 594 void setHoverNode(NodeImpl *newHoverNode);
595 NodeImpl *focusNode()
const 599 void quietResetFocus();
600 void setFocusNode(NodeImpl *newFocusNode);
601 NodeImpl *activeNode()
const 605 void setActiveNode(NodeImpl *newActiveNode);
608 void setCSSTarget(NodeImpl *n);
609 NodeImpl *getCSSTarget()
614 bool isDocumentChanged()
618 virtual void setDocumentChanged(
bool =
true);
619 void attachNodeIterator(NodeIteratorImpl *ni);
620 void detachNodeIterator(NodeIteratorImpl *ni);
621 void notifyBeforeNodeRemoval(NodeImpl *n);
622 AbstractViewImpl *defaultView()
const 624 return m_defaultView;
626 EventImpl *createEvent(
const DOMString &eventType,
int &exceptioncode);
631 DOMSUBTREEMODIFIED_LISTENER = 0x01,
632 DOMNODEINSERTED_LISTENER = 0x02,
633 DOMNODEREMOVED_LISTENER = 0x04,
634 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 0x08,
635 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
636 DOMATTRMODIFIED_LISTENER = 0x20,
637 DOMCHARACTERDATAMODIFIED_LISTENER = 0x40
640 bool hasListenerType(ListenerType listenerType)
const 642 return (m_listenerTypes & listenerType);
644 void addListenerType(ListenerType listenerType)
646 m_listenerTypes = m_listenerTypes | listenerType;
649 CSSStyleDeclarationImpl *getOverrideStyle(ElementImpl *elt, DOMStringImpl *pseudoElt);
655 void setAsync(
bool b)
664 void error(
int err,
const QString &text)
override;
667 LocalStyleRefs *localStyleRefs()
669 return &m_localStyleRefs;
672 void defaultEventHandler(EventImpl *evt)
override;
675 void setHTMLWindowEventListener(
unsigned id,
EventListener *listener);
684 bool hasWindowEventListener(
EventName id);
699 NodeImpl *nextFocusNode(NodeImpl *fromNode);
712 NodeImpl *previousFocusNode(NodeImpl *fromNode);
714 ElementImpl *findAccessKeyElement(
QChar c);
716 int nodeAbsIndex(NodeImpl *node);
717 NodeImpl *nodeWithAbsIndex(
int absIndex);
730 void dispatchImageLoadEventSoon(HTMLImageElementImpl *);
731 void dispatchImageLoadEventsNow();
732 void removeImage(HTMLImageElementImpl *);
737 HTMLPartContainerElementImpl *ownerElement()
const;
739 khtml::SecurityOrigin *origin()
const;
740 void setOrigin(khtml::SecurityOrigin *);
744 void setDomain(
const DOMString &newDomain);
747 bool isURLAllowed(
const QString &url)
const;
749 HTMLElementImpl *body()
const;
753 bool execCommand(
const DOMString &command,
bool userInterface,
const DOMString &value);
754 bool queryCommandEnabled(
const DOMString &command);
755 bool queryCommandIndeterm(
const DOMString &command);
756 bool queryCommandState(
const DOMString &command);
757 bool queryCommandSupported(
const DOMString &command);
770 void incDOMTreeVersion(
unsigned ver)
772 ++m_domTreeVersions[ver];
774 unsigned int domTreeVersion(
unsigned ver)
const 776 return m_domTreeVersions[ver];
782 DynamicNodeListImpl::Cache *acquireCachedNodeListInfo(DynamicNodeListImpl::CacheFactory *fact,
783 NodeImpl *base,
int type);
784 void releaseCachedNodeListInfo(DynamicNodeListImpl::Cache *cache);
786 JSEditor *jsEditor();
790 return m_counterDict.
value(o);
794 m_counterDict.insert(o, dict);
798 delete m_counterDict.take(o);
803 return m_underDocNamedCache;
808 return m_getElementByIdCache;
813 return m_contentLanguage;
815 void setContentLanguage(
const QString &cl)
817 m_contentLanguage = cl;
822 return *m_dynamicDomRestyler;
826 return *m_dynamicDomRestyler;
830 const WebCore::SVGDocumentExtensions *svgExtensions();
831 WebCore::SVGDocumentExtensions *accessSVGExtensions();
834 void finishedParsing();
840 int m_stateRestorePos;
843 khtml::Tokenizer *m_tokenizer;
849 mutable DocumentTypeImpl *m_doctype;
851 mutable DOMImplementationImpl *m_implementation;
863 int m_pendingStylesheets;
864 bool m_ignorePendingStylesheets;
866 CSSStyleSheetImpl *m_elemSheet;
873 NodeImpl *m_hoverNode;
874 NodeImpl *m_focusNode;
875 NodeImpl *m_activeNode;
876 NodeImpl *m_cssTarget;
878 unsigned int m_domTreeVersions[NumTreeVersions];
880 WebCore::SVGDocumentExtensions *m_svgExtensions;
883 AbstractViewImpl *m_defaultView;
885 unsigned short m_listenerTypes;
886 StyleSheetListImpl *m_styleSheets;
887 StyleSheetListImpl *m_addedStyleSheets;
888 LocalStyleRefs m_localStyleRefs;
889 WindowEventTargetImpl *m_windowEventTarget;
890 RegisteredListenerList m_windowEventListeners;
898 bool visuallyOrdered;
901 bool m_styleSelectorDirty;
902 bool m_inStyleRecalc;
906 bool m_bVariableLength;
914 mutable ElementImpl *m_documentElement;
926 int m_imageLoadEventTimer;
931 SharedPtr<khtml::RenderArena> m_renderArena;
933 JSEditor *m_jsEditor;
934 mutable RefPtr<khtml::SecurityOrigin> m_origin;
936 int m_selfOnlyRefCount;
946 ++m_selfOnlyRefCount;
950 --m_selfOnlyRefCount;
951 if (!m_selfOnlyRefCount && !refCount()) {
957 void removedLastRef()
override;
965 class WindowEventTargetImpl :
public EventTargetImpl
970 Type eventTargetType()
const override;
972 KJS::Window *window();
977 class DocumentFragmentImpl :
public NodeBaseImpl
984 unsigned short nodeType()
const override;
985 WTF::PassRefPtr<NodeImpl> cloneNode(
bool deep)
override;
988 bool childTypeAllowed(
unsigned short type)
override;
993 class DocumentTypeImpl :
public NodeImpl
996 DocumentTypeImpl(DOMImplementationImpl *_implementation,
DocumentImpl *doc,
1002 NamedNodeMapImpl *entities()
const;
1003 NamedNodeMapImpl *notations()
const;
1007 return m_qualifiedName;
1024 unsigned short nodeType()
const override;
1025 bool childTypeAllowed(
unsigned short type)
override;
1026 WTF::PassRefPtr<NodeImpl> cloneNode(
bool deep)
override;
1031 m_qualifiedName = n;
1033 void setPublicId(
const DOMString &publicId)
1035 m_publicId = publicId;
1037 void setSystemId(
const DOMString &systemId)
1039 m_systemId = systemId;
1041 void setInternalSubset(
const DOMString &subset)
1045 DOMImplementationImpl *implementation()
const 1047 return m_implementation;
1053 DOMImplementationImpl *m_implementation;
1054 mutable NamedNodeMapImpl *m_entities;
1055 mutable NamedNodeMapImpl *m_notations;
1068 void close()
override;
Provides encoding detection capabilities.
bool hasPendingSheets() const
Returns true if the document has pending stylesheets loading.
This file is part of the HTML rendering engine for KDE.
This class is khtml's main class.
Renders and displays HTML in a QScrollArea.
bool isEmpty() const const
For each name, we hold a reference count, and a pointer.
This class implements the basic string we use in the DOM.
the StyleSelector implementation for CSS.
const T value(const Key &key) const const
Introduced in DOM Level 2.
const QChar * unicode() const const
This library provides a full-featured HTML parser and widget.
bool haveStylesheetsLoaded() const
This method returns true if all top-level stylesheets have loaded (including any @imports that they m...
Base Class for all rendering tree objects.
DOMStringImpl * implementation() const