2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
30 #include "DeprecatedPtrList.h"
31 #include "DeprecatedValueList.h"
32 #include "DocumentMarker.h"
33 #include "HTMLCollection.h"
34 #include "HTMLFormElement.h"
35 #include "StringHash.h"
37 #include <wtf/HashCountedSet.h>
38 #include <wtf/ListHashSet.h>
40 // FIXME: We should move Mac off of the old Frame-based user stylesheet loading
41 // code and onto the new code in Page. We can't do that until the code in Page
42 // supports non-file: URLs, however.
44 #define FRAME_LOADS_USER_STYLESHEET 1
46 #define FRAME_LOADS_USER_STYLESHEET 0
55 class CachedCSSStyleSheet;
56 class CSSStyleDeclaration;
57 class CSSStyleSelector;
60 class DOMImplementation;
64 class DocumentFragment;
68 class EntityReference;
75 class HTMLFormControlElementWithState;
76 class HTMLFormElement;
77 class HTMLHeadElement;
78 class HTMLImageLoader;
79 class HTMLInputElement;
82 class MouseEventWithHitTestResults;
88 class PlatformMouseEvent;
89 class ProcessingInstruction;
91 class RegisteredEventListener;
98 class TextResourceDecoder;
102 class XBLBindingManager;
105 class XPathEvaluator;
106 class XPathExpression;
107 class XPathNSResolver;
111 struct DashboardRegionValue;
112 struct HitTestRequest;
115 class SVGDocumentExtensions;
118 typedef int ExceptionCode;
120 class FormElementKey {
122 FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0);
124 FormElementKey(const FormElementKey&);
125 FormElementKey& operator=(const FormElementKey&);
126 AtomicStringImpl* name() const { return m_name; }
127 AtomicStringImpl* type() const { return m_type; }
131 AtomicStringImpl* m_name;
132 AtomicStringImpl* m_type;
135 inline bool operator==(const FormElementKey& a, const FormElementKey& b)
136 { return a.name() == b.name() && a.type() == b.type(); }
138 struct FormElementKeyHash {
139 static unsigned hash(const FormElementKey&);
140 static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; }
141 static const bool safeToCompareToEmptyOrDeleted = true;
144 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
145 static FormElementKey deletedValue();
148 class Document : public ContainerNode {
150 Document(DOMImplementation*, Frame*, bool isXHTML = false);
153 virtual void removedLastRef();
155 // Nodes belonging to this document hold "self-only" references -
156 // these are enough to keep the document from being destroyed, but
157 // not enough to keep it from removing its children. This allows a
158 // node that outlives its document to still have a valid document
159 // pointer without introducing reference cycles
163 ASSERT(!m_deletionHasBegun);
164 ++m_selfOnlyRefCount;
168 ASSERT(!m_deletionHasBegun);
169 --m_selfOnlyRefCount;
170 if (!m_selfOnlyRefCount && !refCount()) {
172 m_deletionHasBegun = true;
178 // DOM methods & attributes for Document
180 virtual DocumentType* doctype() const; // May return 0 for HTML documents
181 DocumentType* realDocType() const { return m_docType.get(); }
183 DOMImplementation* implementation() const;
184 virtual void childrenChanged(bool changedByParser = false);
185 Element* documentElement() const;
186 virtual PassRefPtr<Element> createElement(const String& tagName, ExceptionCode&);
187 PassRefPtr<DocumentFragment> createDocumentFragment ();
188 PassRefPtr<Text> createTextNode(const String& data);
189 PassRefPtr<Comment> createComment(const String& data);
190 PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
191 PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
192 PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode& ec) { return createAttributeNS(String(), name, ec); }
193 PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
194 PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
195 PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
196 virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
197 PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser, ExceptionCode& ec);
198 Element* getElementById(const AtomicString&) const;
200 Element* elementFromPoint(int x, int y) const;
201 String readyState() const;
202 String inputEncoding() const;
203 String defaultCharset() const;
205 String charset() const { return inputEncoding(); }
206 String characterSet() const { return inputEncoding(); }
208 void setCharset(const String&);
210 String contentLanguage() const { return m_contentLanguage; }
211 void setContentLanguage(const String& lang) { m_contentLanguage = lang; }
213 String xmlEncoding() const { return m_xmlEncoding; }
214 String xmlVersion() const { return m_xmlVersion; }
215 bool xmlStandalone() const { return m_xmlStandalone; }
217 void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLTokenizer
218 void setXMLVersion(const String&, ExceptionCode&);
219 void setXMLStandalone(bool, ExceptionCode&);
221 String documentURI() const;
222 void setDocumentURI(const String&);
224 virtual String baseURI() const;
226 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
228 PassRefPtr<HTMLCollection> images();
229 PassRefPtr<HTMLCollection> embeds();
230 PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
231 PassRefPtr<HTMLCollection> applets();
232 PassRefPtr<HTMLCollection> links();
233 PassRefPtr<HTMLCollection> forms();
234 PassRefPtr<HTMLCollection> anchors();
235 PassRefPtr<HTMLCollection> all();
236 PassRefPtr<HTMLCollection> objects();
237 PassRefPtr<HTMLCollection> scripts();
238 PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
239 PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
241 HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type)
243 ASSERT(type >= HTMLCollection::FirstUnnamedDocumentCachedType);
244 unsigned index = type - HTMLCollection::FirstUnnamedDocumentCachedType;
245 ASSERT(index < HTMLCollection::NumUnnamedDocumentCachedTypes);
246 return &m_collectionInfo[index];
249 HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type, const AtomicString& name);
251 // DOM methods overridden from parent classes
253 virtual String nodeName() const;
254 virtual NodeType nodeType() const;
256 // Other methods (not part of DOM)
257 virtual bool isDocumentNode() const { return true; }
258 virtual bool isHTMLDocument() const { return false; }
259 virtual bool isImageDocument() const { return false; }
261 virtual bool isSVGDocument() const { return false; }
263 virtual bool isPluginDocument() const { return false; }
265 CSSStyleSelector* styleSelector() const { return m_styleSelector; }
267 Element* getElementByAccessKey(const String& key) const;
270 * Updates the pending sheet count and then calls updateStyleSelector.
272 void removePendingSheet();
275 * This method returns true if all top-level stylesheets have loaded (including
276 * any @imports that they may be loading).
278 bool haveStylesheetsLoaded() const
280 return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets
281 #if USE(LOW_BANDWIDTH_DISPLAY)
282 || m_inLowBandwidthDisplay
288 * Increments the number of pending sheets. The <link> elements
289 * invoke this to add themselves to the loading list.
291 void addPendingSheet() { m_pendingStylesheets++; }
293 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
294 void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
297 * Called when one or more stylesheets in the document may have been added, removed or changed.
299 * Creates a new style selector and assign it to this document. This is done by iterating through all nodes in
300 * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in
301 * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is
302 * constructed from these which is used to create the a new style selector which collates all of the stylesheets
303 * found and is used to calculate the derived styles for all rendering objects.
305 void updateStyleSelector();
307 void recalcStyleSelector();
309 bool usesDescendantRules() const { return m_usesDescendantRules; }
310 void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; }
311 bool usesSiblingRules() const { return m_usesSiblingRules; }
312 void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; }
313 bool usesFirstLineRules() const { return m_usesFirstLineRules; }
314 void setUsesFirstLineRules(bool b) { m_usesFirstLineRules = b; }
315 bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
316 void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
318 // Machinery for saving and restoring state when you leave and then go back to a page.
319 void registerFormElementWithState(HTMLFormControlElementWithState* e) { m_formElementsWithState.add(e); }
320 void unregisterFormElementWithState(HTMLFormControlElementWithState* e) { m_formElementsWithState.remove(e); }
321 Vector<String> formElementsState() const;
322 void setStateForNewFormElements(const Vector<String>&);
323 bool hasStateForNewFormElements() const;
324 bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
326 FrameView* view() const; // can be NULL
327 Frame* frame() const { return m_frame; } // can be NULL
328 Page* page() const; // can be NULL
329 Settings* settings() const; // can be NULL
331 PassRefPtr<Range> createRange();
333 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
334 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
336 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
337 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
339 // Special support for editing
340 PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
341 PassRefPtr<EditingText> createEditingTextNode(const String&);
343 virtual void recalcStyle( StyleChange = NoChange );
344 static DeprecatedPtrList<Document>* changedDocuments;
345 virtual void updateRendering();
347 void updateLayoutIgnorePendingStylesheets();
348 static void updateDocumentsRendering();
349 DocLoader* docLoader() { return m_docLoader; }
351 virtual void attach();
352 virtual void detach();
354 RenderArena* renderArena() { return m_renderArena; }
356 AXObjectCache* axObjectCache() const;
358 // to get visually ordered hebrew and arabic pages right
359 void setVisuallyOrdered();
364 void implicitClose();
365 void cancelParsing();
367 void write(const String& text);
368 void writeln(const String& text);
369 void finishParsing();
372 bool wellFormed() const { return m_wellFormed; }
374 DeprecatedString url() const { return m_url.isEmpty() ? "about:blank" : m_url; }
375 void setURL(const DeprecatedString& url);
377 DeprecatedString baseURL() const { return m_baseURL.isEmpty() ? url() : m_baseURL; }
378 void setBaseURL(const DeprecatedString& baseURL);
380 String baseTarget() const { return m_baseTarget; }
381 void setBaseTarget(const String& baseTarget) { m_baseTarget = baseTarget; }
383 DeprecatedString completeURL(const DeprecatedString &);
384 String completeURL(const String&);
386 // from cachedObjectClient
387 virtual void setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet*);
389 #if FRAME_LOADS_USER_STYLESHEET
390 void setUserStyleSheet(const String& sheet);
393 String userStyleSheet() const;
395 CSSStyleSheet* elementSheet();
396 CSSStyleSheet* mappedElementSheet();
397 virtual Tokenizer* createTokenizer();
398 Tokenizer* tokenizer() { return m_tokenizer; }
400 bool printing() const { return m_printing; }
401 void setPrinting(bool p) { m_printing = p; }
403 enum ParseMode { Compat, AlmostStrict, Strict };
405 virtual void determineParseMode(const String&);
406 void setParseMode(ParseMode m) { pMode = m; }
407 ParseMode parseMode() const { return pMode; }
409 bool inCompatMode() const { return pMode == Compat; }
410 bool inAlmostStrictMode() const { return pMode == AlmostStrict; }
411 bool inStrictMode() const { return pMode == Strict; }
413 enum HTMLMode { Html3, Html4, XHtml };
415 void setHTMLMode(HTMLMode m) { hMode = m; }
416 HTMLMode htmlMode() const { return hMode; }
418 void setParsing(bool);
419 bool parsing() const { return m_bParsing; }
420 int minimumLayoutDelay();
421 bool shouldScheduleLayout();
422 int elapsedTime() const;
424 void setTextColor(const Color& color) { m_textColor = color; }
425 Color textColor() const { return m_textColor; }
427 const Color& linkColor() const { return m_linkColor; }
428 const Color& visitedLinkColor() const { return m_visitedLinkColor; }
429 const Color& activeLinkColor() const { return m_activeLinkColor; }
430 void setLinkColor(const Color& c) { m_linkColor = c; }
431 void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
432 void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
433 void resetLinkColor();
434 void resetVisitedLinkColor();
435 void resetActiveLinkColor();
437 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const IntPoint&, const PlatformMouseEvent&);
439 virtual bool childTypeAllowed(NodeType);
440 virtual PassRefPtr<Node> cloneNode(bool deep);
442 virtual bool canReplaceChild(Node* newChild, Node* oldChild);
444 StyleSheetList* styleSheets();
446 /* Newly proposed CSS3 mechanism for selecting alternate
447 stylesheets using the DOM. May be subject to change as
450 String preferredStylesheetSet() const;
451 String selectedStylesheetSet() const;
452 void setSelectedStylesheetSet(const String&);
454 bool setFocusedNode(PassRefPtr<Node>);
455 Node* focusedNode() const { return m_focusedNode.get(); }
457 void setHoverNode(PassRefPtr<Node>);
458 Node* hoverNode() const { return m_hoverNode.get(); }
460 void setActiveNode(PassRefPtr<Node>);
461 Node* activeNode() const { return m_activeNode.get(); }
463 void focusedNodeRemoved();
464 void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
465 void hoveredNodeDetached(Node*);
466 void activeChainNodeDetached(Node*);
468 // Updates for :target (CSS3 selector).
469 void setCSSTarget(Node*);
470 Node* getCSSTarget() const;
472 void setDocumentChanged(bool);
474 void attachNodeIterator(NodeIterator*);
475 void detachNodeIterator(NodeIterator*);
476 void notifyBeforeNodeRemoval(Node*);
477 DOMWindow* defaultView() const;
478 PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
480 // keep track of what types of event listeners are registered, so we don't
481 // dispatch events unnecessarily
483 DOMSUBTREEMODIFIED_LISTENER = 0x01,
484 DOMNODEINSERTED_LISTENER = 0x02,
485 DOMNODEREMOVED_LISTENER = 0x04,
486 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 0x08,
487 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
488 DOMATTRMODIFIED_LISTENER = 0x20,
489 DOMCHARACTERDATAMODIFIED_LISTENER = 0x40,
490 OVERFLOWCHANGED_LISTENER = 0x80
493 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
494 void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
496 CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
498 void handleWindowEvent(Event*, bool useCapture);
499 void setHTMLWindowEventListener(const AtomicString &eventType, PassRefPtr<EventListener>);
500 EventListener* getHTMLWindowEventListener(const AtomicString &eventType);
501 void removeHTMLWindowEventListener(const AtomicString &eventType);
503 void setHTMLWindowEventListener(const AtomicString& eventType, Attribute*);
505 void addWindowEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
506 void removeWindowEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
507 bool hasWindowEventListener(const AtomicString& eventType);
509 PassRefPtr<EventListener> createHTMLEventListener(const String& functionName, const String& code, Node*);
512 * Searches through the document, starting from fromNode, for the next selectable element that comes after fromNode.
513 * The order followed is as specified in section 17.11.1 of the HTML4 spec, which is elements with tab indexes
514 * first (from lowest to highest), and then elements without tab indexes (in document order).
516 * @param fromNode The node from which to start searching. The node after this will be focused. May be null.
518 * @return The focus node that comes after fromNode
520 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1
522 Node* nextFocusableNode(Node* start, KeyboardEvent*);
525 * Searches through the document, starting from fromNode, for the previous selectable element (that comes _before_)
526 * fromNode. The order followed is as specified in section 17.11.1 of the HTML4 spec, which is elements with tab
527 * indexes first (from lowest to highest), and then elements without tab indexes (in document order).
529 * @param fromNode The node from which to start searching. The node before this will be focused. May be null.
531 * @return The focus node that comes before fromNode
533 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1
535 Node* previousFocusableNode(Node* start, KeyboardEvent*);
537 int nodeAbsIndex(Node*);
538 Node* nodeWithAbsIndex(int absIndex);
541 * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
542 * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
543 * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
544 * specified in a HTML file.
546 * @param equiv The http header name (value of the meta tag's "equiv" attribute)
547 * @param content The header value (value of the meta tag's "content" attribute)
549 void processHttpEquiv(const String& equiv, const String& content);
551 void dispatchImageLoadEventSoon(HTMLImageLoader*);
552 void dispatchImageLoadEventsNow();
553 void removeImage(HTMLImageLoader*);
555 // Returns the owning element in the parent document.
556 // Returns 0 if this is the top level document.
557 Element* ownerElement() const;
559 String title() const { return m_title; }
560 void setTitle(const String&, Element* titleElement = 0);
561 void removeTitle(Element* titleElement);
563 String cookie() const;
564 void setCookie(const String&);
566 String referrer() const;
568 String domain() const;
569 void setDomain(const String& newDomain);
571 String lastModified() const;
573 String policyBaseURL() const { return m_policyBaseURL; }
574 void setPolicyBaseURL(const String& s) { m_policyBaseURL = s; }
576 // The following implements the rule from HTML 4 for what valid names are.
577 // To get this right for all the XML cases, we probably have to improve this or move it
578 // and make it sensitive to the type of document.
579 static bool isValidName(const String&);
581 // The following breaks a qualified name into a prefix and a local name.
582 // It also does a validity check, and returns false if the qualified name is invalid
583 // (empty string or invalid characters).
584 static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName);
586 void addElementById(const AtomicString& elementId, Element *element);
587 void removeElementById(const AtomicString& elementId, Element *element);
589 void addImageMap(HTMLMapElement*);
590 void removeImageMap(HTMLMapElement*);
591 HTMLMapElement* getImageMap(const String& url) const;
594 void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
596 HTMLHeadElement* head();
598 String toString() const;
600 bool execCommand(const String& command, bool userInterface = false, const String& value = String());
601 bool queryCommandEnabled(const String& command);
602 bool queryCommandIndeterm(const String& command);
603 bool queryCommandState(const String& command);
604 bool queryCommandSupported(const String& command);
605 String queryCommandValue(const String& command);
607 void addMarker(Range*, DocumentMarker::MarkerType, String description = String());
608 void addMarker(Node*, DocumentMarker);
609 void copyMarkers(Node *srcNode, unsigned startOffset, int length, Node *dstNode, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
610 void removeMarkers(Range*, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
611 void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
612 void removeMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
613 void removeMarkers(Node*);
614 void repaintMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
615 void setRenderedRectForMarker(Node*, DocumentMarker, const IntRect&);
616 void invalidateRenderedRectsForMarkersInRect(const IntRect&);
617 void shiftMarkers(Node*, unsigned startOffset, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
619 DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
620 Vector<DocumentMarker> markersForNode(Node*);
621 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
623 // designMode support
624 enum InheritedBool { off = false, on = true, inherit };
625 void setDesignMode(InheritedBool value);
626 InheritedBool getDesignMode() const;
627 bool inDesignMode() const;
629 Document* parentDocument() const;
630 Document* topDocument() const;
632 int docID() const { return m_docID; }
635 void applyXSLTransform(ProcessingInstruction* pi);
636 void setTransformSource(void* doc);
637 const void* transformSource() { return m_transformSource; }
638 PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
639 void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
644 XBLBindingManager* bindingManager() const { return m_bindingManager; }
647 void incDOMTreeVersion() { ++m_domtree_version; }
648 unsigned domTreeVersion() const { return m_domtree_version; }
650 void setDocType(PassRefPtr<DocumentType>);
652 void finishedParsing();
655 // XPathEvaluator methods
656 PassRefPtr<XPathExpression> createExpression(const String& expression,
657 XPathNSResolver* resolver,
659 PassRefPtr<XPathNSResolver> createNSResolver(Node *nodeResolver);
660 PassRefPtr<XPathResult> evaluate(const String& expression,
662 XPathNSResolver* resolver,
666 #endif // ENABLE(XPATH)
668 enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets };
670 bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; }
672 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
675 void setIconURL(const String& iconURL, const String& type);
677 bool isAllowedToLoadLocalResources() const { return m_isAllowedToLoadLocalResources; }
679 void setUseSecureKeyboardEntryWhenActive(bool);
680 bool useSecureKeyboardEntryWhenActive() const;
682 #if USE(LOW_BANDWIDTH_DISPLAY)
683 void setDocLoader(DocLoader* loader) { m_docLoader = loader; }
684 bool inLowBandwidthDisplay() const { return m_inLowBandwidthDisplay; }
685 void setLowBandwidthDisplay(bool lowBandWidth) { m_inLowBandwidthDisplay = lowBandWidth; }
688 void addNodeList() { m_numNodeLists++; }
689 void removeNodeList() { m_numNodeLists--; }
690 bool hasNodeLists() const { return m_numNodeLists != 0; }
692 void updateFocusAppearanceSoon();
693 void cancelFocusAppearanceUpdate();
696 CSSStyleSelector* m_styleSelector;
697 bool m_didCalculateStyleSelector;
700 DocLoader* m_docLoader;
701 Tokenizer* m_tokenizer;
703 DeprecatedString m_url;
704 DeprecatedString m_baseURL;
707 RefPtr<DocumentType> m_docType;
708 RefPtr<DOMImplementation> m_implementation;
710 RefPtr<StyleSheet> m_sheet;
711 #if FRAME_LOADS_USER_STYLESHEET
715 // Track the number of currently loading top-level stylesheets. Sheets
716 // loaded using the @import directive are not included in this count.
717 // We use this count of pending sheets to detect when we can begin attaching
719 int m_pendingStylesheets;
721 // But sometimes you need to ignore pending stylesheet count to
722 // force an immediate layout when requested by JS.
723 bool m_ignorePendingStylesheets;
725 // If we do ignore the pending stylesheet count, then we need to add a boolean
726 // to track that this happened so that we can do a full repaint when the stylesheets
727 // do eventually load.
728 PendingSheetLayout m_pendingSheetLayout;
730 bool m_hasNodesWithPlaceholderStyle;
732 RefPtr<CSSStyleSheet> m_elemSheet;
733 RefPtr<CSSStyleSheet> m_mappedElementSheet;
742 RefPtr<Node> m_focusedNode;
743 RefPtr<Node> m_hoverNode;
744 RefPtr<Node> m_activeNode;
745 mutable RefPtr<Element> m_documentElement;
747 unsigned m_domtree_version;
749 HashSet<NodeIterator*> m_nodeIterators;
751 unsigned short m_listenerTypes;
752 RefPtr<StyleSheetList> m_styleSheets;
754 typedef DeprecatedValueList<RefPtr<RegisteredEventListener> > RegisteredEventListenerList;
755 RegisteredEventListenerList m_windowEventListeners;
757 typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
758 ListHashSet<HTMLFormControlElementWithState*> m_formElementsWithState;
759 FormElementStateMap m_stateForNewFormElements;
762 Color m_visitedLinkColor;
763 Color m_activeLinkColor;
765 String m_preferredStylesheetSet;
766 String m_selectedStylesheetSet;
769 bool visuallyOrdered;
772 bool m_inStyleRecalc;
773 bool m_closeAfterStyleRecalc;
774 bool m_usesDescendantRules;
775 bool m_usesSiblingRules;
776 bool m_usesFirstLineRules;
777 bool m_usesFirstLetterRules;
778 bool m_gotoAnchorNeededAfterStylesheetsLoad;
781 bool m_titleSetExplicitly;
782 RefPtr<Element> m_titleElement;
784 RenderArena* m_renderArena;
786 typedef std::pair<Vector<DocumentMarker>, Vector<IntRect> > MarkerMapVectorPair;
787 typedef HashMap<RefPtr<Node>, MarkerMapVectorPair*> MarkerMap;
790 mutable AXObjectCache* m_axObjectCache;
792 DeprecatedPtrList<HTMLImageLoader> m_imageLoadEventDispatchSoonList;
793 DeprecatedPtrList<HTMLImageLoader> m_imageLoadEventDispatchingList;
794 Timer<Document> m_imageLoadEventTimer;
796 Timer<Document> m_updateFocusAppearanceTimer;
800 bool m_processingLoadEvent;
802 bool m_overMinimumLayoutThreshold;
805 void* m_transformSource;
806 RefPtr<Document> m_transformSourceDocument;
810 XBLBindingManager* m_bindingManager; // The access point through which documents and elements communicate with XBL.
813 typedef HashMap<AtomicStringImpl*, HTMLMapElement*> ImageMapsByName;
814 ImageMapsByName m_imageMapsByName;
816 String m_policyBaseURL;
818 HashSet<Node*> m_disconnectedNodesWithEventListeners;
820 int m_docID; // A unique document identifier used for things like document-specific mapped attributes.
822 String m_xmlEncoding;
824 bool m_xmlStandalone;
826 String m_contentLanguage;
830 void setInPageCache(bool flag);
832 // Elements can register themselves for the "willSaveToCache()" and
833 // "didRestoreFromCache()" callbacks
834 void registerForCacheCallbacks(Element*);
835 void unregisterForCacheCallbacks(Element*);
836 void willSaveToCache();
837 void didRestoreFromCache();
839 void setShouldCreateRenderers(bool);
840 bool shouldCreateRenderers();
842 void setDecoder(TextResourceDecoder*);
843 TextResourceDecoder* decoder() const { return m_decoder.get(); }
845 UChar backslashAsCurrencySymbol() const;
847 void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
848 bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
849 bool hasDashboardRegions () const { return m_hasDashboardRegions; }
850 void setHasDashboardRegions (bool f) { m_hasDashboardRegions = f; }
851 const Vector<DashboardRegionValue>& dashboardRegions() const;
852 void setDashboardRegions(const Vector<DashboardRegionValue>&);
854 void removeAllEventListenersFromAllNodes();
856 void registerDisconnectedNodeWithEventListeners(Node*);
857 void unregisterDisconnectedNodeWithEventListeners(Node*);
859 HTMLFormElement::CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
862 const SVGDocumentExtensions* svgExtensions();
863 SVGDocumentExtensions* accessSVGExtensions();
866 void initSecurityOrigin();
867 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
869 // Explicitly override the security origin for this document.
870 // Note: It is dangerous to change the security origin of a document
871 // that already contains content.
872 void setSecurityOrigin(SecurityOrigin*);
874 bool processingLoadEvent() const { return m_processingLoadEvent; }
877 DatabaseThread* databaseThread(); // Creates the thread as needed, but not if it has been already terminated.
878 void setHasOpenDatabases() { m_hasOpenDatabases = true; }
879 bool hasOpenDatabases() { return m_hasOpenDatabases; }
882 void clearXMLVersion() { m_xmlVersion = String(); }
885 bool shouldBeAllowedToLoadLocalResources() const;
888 void removeAllDisconnectedNodeEventListeners();
889 void imageLoadEventTimerFired(Timer<Document>*);
890 void updateFocusAppearanceTimerFired(Timer<Document>*);
892 RefPtr<SecurityOrigin> m_securityOrigin;
894 RenderObject* m_savedRenderer;
897 RefPtr<TextResourceDecoder> m_decoder;
899 // We maintain the invariant that m_duplicateIds is the count of all elements with a given ID
900 // excluding the one referenced in m_elementsById, if any. This means it one less than the total count
901 // when the first node with a given ID is cached, otherwise the same as the total count.
902 mutable HashMap<AtomicStringImpl*, Element*> m_elementsById;
903 mutable HashCountedSet<AtomicStringImpl*> m_duplicateIds;
905 mutable HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKey;
907 InheritedBool m_designMode;
909 int m_selfOnlyRefCount;
911 HTMLFormElement::CheckedRadioButtons m_checkedRadioButtons;
913 typedef HashMap<AtomicStringImpl*, HTMLCollection::CollectionInfo*> NamedCollectionMap;
914 HTMLCollection::CollectionInfo m_collectionInfo[HTMLCollection::NumUnnamedDocumentCachedTypes];
915 NamedCollectionMap m_nameCollectionInfo[HTMLCollection::NumNamedDocumentCachedTypes];
918 RefPtr<XPathEvaluator> m_xpathEvaluator;
922 SVGDocumentExtensions* m_svgExtensions;
925 Vector<DashboardRegionValue> m_dashboardRegions;
926 bool m_hasDashboardRegions;
927 bool m_dashboardRegionsDirty;
929 mutable bool m_accessKeyMapValid;
930 bool m_createRenderers;
934 HashSet<Element*> m_pageCacheCallbackElements;
936 bool m_isAllowedToLoadLocalResources;
938 bool m_useSecureKeyboardEntryWhenActive;
942 unsigned m_numNodeLists;
945 RefPtr<DatabaseThread> m_databaseThread;
946 bool m_hasOpenDatabases; // This never changes back to false, even as the database thread is closed.
948 #if USE(LOW_BANDWIDTH_DISPLAY)
949 bool m_inLowBandwidthDisplay;
953 } // namespace WebCore