Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: webkit/pending/Document.h

Issue 6500: Cleaning up the unfork (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/pending/DOMWindow.cpp ('k') | webkit/pending/Document.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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.
7 *
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.
12 *
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.
17 *
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.
22 *
23 */
24
25 #ifndef Document_h
26 #define Document_h
27
28 #include "Attr.h"
29 #include "Color.h"
30 #include "DeprecatedPtrList.h"
31 #include "DocumentMarker.h"
32 #include "HTMLCollection.h"
33 #include "HTMLFormElement.h"
34 #include "KURL.h"
35 #include "StringHash.h"
36 #include "Timer.h"
37 #include "unicode/uscript.h"
38 #include <wtf/HashCountedSet.h>
39 #include <wtf/ListHashSet.h>
40
41 // FIXME: We should move Mac off of the old Frame-based user stylesheet loading
42 // code and onto the new code in Page. We can't do that until the code in Page
43 // supports non-file: URLs, however.
44 #if PLATFORM(MAC) || PLATFORM(QT)
45 #define FRAME_LOADS_USER_STYLESHEET 1
46 #else
47 #define FRAME_LOADS_USER_STYLESHEET 0
48 #endif
49
50 namespace WebCore {
51
52 class AXObjectCache;
53 class Attr;
54 class Attribute;
55 class CDATASection;
56 class CachedCSSStyleSheet;
57 class CanvasRenderingContext2D;
58 class CharacterData;
59 class CSSStyleDeclaration;
60 class CSSStyleSelector;
61 class CSSStyleSheet;
62 class Comment;
63 class Database;
64 class DOMImplementation;
65 class DOMSelection;
66 class DOMWindow;
67 class DatabaseThread;
68 class DocLoader;
69 class DocumentFragment;
70 class DocumentType;
71 class EditingText;
72 class Element;
73 class EntityReference;
74 class Event;
75 class EventListener;
76 class Frame;
77 class FrameView;
78 class HTMLCanvasElement;
79 class HTMLDocument;
80 class HTMLElement;
81 class HTMLFormControlElementWithState;
82 class HTMLFormElement;
83 class HTMLHeadElement;
84 class HTMLImageLoader;
85 class HTMLInputElement;
86 class HTMLMapElement;
87 class IntPoint;
88 class JSNode;
89 class MouseEventWithHitTestResults;
90 class NodeFilter;
91 class NodeIterator;
92 class Page;
93 class PlatformMouseEvent;
94 class ProcessingInstruction;
95 class Range;
96 class RegisteredEventListener;
97 class RenderArena;
98 class SecurityOrigin;
99 class Settings;
100 class StyleSheet;
101 class StyleSheetList;
102 class Text;
103 class TextResourceDecoder;
104 class Tokenizer;
105 class TreeWalker;
106
107 #if ENABLE(SVG)
108 class SVGDocumentExtensions;
109 #endif
110
111 #if ENABLE(XBL)
112 class XBLBindingManager;
113 #endif
114
115 #if ENABLE(XPATH)
116 class XPathEvaluator;
117 class XPathExpression;
118 class XPathNSResolver;
119 class XPathResult;
120 #endif
121
122 #if ENABLE(DASHBOARD_SUPPORT)
123 struct DashboardRegionValue;
124 #endif
125 struct HitTestRequest;
126
127 typedef int ExceptionCode;
128
129 class FormElementKey {
130 public:
131 FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0);
132 ~FormElementKey();
133 FormElementKey(const FormElementKey&);
134 FormElementKey& operator=(const FormElementKey&);
135
136 AtomicStringImpl* name() const { return m_name; }
137 AtomicStringImpl* type() const { return m_type; }
138
139 // Hash table deleted values, which are only constructed and never copied or destroyed.
140 FormElementKey(WTF::HashTableDeletedValueType) : m_name(hashTableDeletedValu e()) { }
141 bool isHashTableDeletedValue() const { return m_name == hashTableDeletedValu e(); }
142
143 private:
144 void ref() const;
145 void deref() const;
146
147 static AtomicStringImpl* hashTableDeletedValue() { return reinterpret_cast<A tomicStringImpl*>(-1); }
148
149 AtomicStringImpl* m_name;
150 AtomicStringImpl* m_type;
151 };
152
153 inline bool operator==(const FormElementKey& a, const FormElementKey& b)
154 {
155 return a.name() == b.name() && a.type() == b.type();
156 }
157
158 struct FormElementKeyHash {
159 static unsigned hash(const FormElementKey&);
160 static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; }
161 static const bool safeToCompareToEmptyOrDeleted = true;
162 };
163
164 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
165 static void constructDeletedValue(FormElementKey& slot) { new (&slot) FormEl ementKey(WTF::HashTableDeletedValue); }
166 static bool isDeletedValue(const FormElementKey& value) { return value.isHas hTableDeletedValue(); }
167 };
168
169 class Document : public ContainerNode {
170 public:
171 static PassRefPtr<Document> create(Frame* frame)
172 {
173 return new Document(frame, false);
174 }
175 static PassRefPtr<Document> createXHTML(Frame* frame)
176 {
177 return new Document(frame, true);
178 }
179 virtual ~Document();
180
181 virtual void removedLastRef();
182
183 // Nodes belonging to this document hold "self-only" references -
184 // these are enough to keep the document from being destroyed, but
185 // not enough to keep it from removing its children. This allows a
186 // node that outlives its document to still have a valid document
187 // pointer without introducing reference cycles
188
189 void selfOnlyRef()
190 {
191 ASSERT(!m_deletionHasBegun);
192 ++m_selfOnlyRefCount;
193 }
194 void selfOnlyDeref()
195 {
196 ASSERT(!m_deletionHasBegun);
197 --m_selfOnlyRefCount;
198 if (!m_selfOnlyRefCount && !refCount()) {
199 #ifndef NDEBUG
200 m_deletionHasBegun = true;
201 #endif
202 delete this;
203 }
204 }
205
206 // DOM methods & attributes for Document
207
208 DocumentType* doctype() const { return m_docType.get(); }
209
210 DOMImplementation* implementation() const;
211 virtual void childrenChanged(bool changedByParser = false, Node* beforeChang e = 0, Node* afterChange = 0, int childCountDelta = 0);
212 Element* documentElement() const;
213 virtual PassRefPtr<Element> createElement(const AtomicString& tagName, Excep tionCode&);
214 PassRefPtr<DocumentFragment> createDocumentFragment ();
215 PassRefPtr<Text> createTextNode(const String& data);
216 PassRefPtr<Comment> createComment(const String& data);
217 PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCod e&);
218 PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
219 PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode& ec) { re turn createAttributeNS(String(), name, ec, true); }
220 PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
221 PassRefPtr<EntityReference> createEntityReference(const String& name, Except ionCode&);
222 PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
223 virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, cons t String& qualifiedName, ExceptionCode&);
224 PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser , ExceptionCode& ec);
225 Element* getElementById(const AtomicString&) const;
226 bool hasElementWithId(AtomicStringImpl* id) const;
227 bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); }
228
229 Element* elementFromPoint(int x, int y) const;
230 String readyState() const;
231 String inputEncoding() const;
232 String defaultCharset() const;
233
234 String charset() const { return inputEncoding(); }
235 String characterSet() const { return inputEncoding(); }
236
237 void setCharset(const String&);
238 UScriptCode dominantScript() const;
239
240 String contentLanguage() const { return m_contentLanguage; }
241 void setContentLanguage(const String& lang) { m_contentLanguage = lang; }
242
243 String xmlEncoding() const { return m_xmlEncoding; }
244 String xmlVersion() const { return m_xmlVersion; }
245 bool xmlStandalone() const { return m_xmlStandalone; }
246
247 void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLTokenizer
248 void setXMLVersion(const String&, ExceptionCode&);
249 void setXMLStandalone(bool, ExceptionCode&);
250
251 String documentURI() const { return m_documentURI; }
252 void setDocumentURI(const String&);
253
254 virtual KURL baseURI() const;
255
256 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
257
258 PassRefPtr<HTMLCollection> images();
259 PassRefPtr<HTMLCollection> embeds();
260 PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
261 PassRefPtr<HTMLCollection> applets();
262 PassRefPtr<HTMLCollection> links();
263 PassRefPtr<HTMLCollection> forms();
264 PassRefPtr<HTMLCollection> anchors();
265 PassRefPtr<HTMLCollection> all();
266 PassRefPtr<HTMLCollection> objects();
267 PassRefPtr<HTMLCollection> scripts();
268 PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
269 PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
270
271 HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type)
272 {
273 ASSERT(type >= HTMLCollection::FirstUnnamedDocumentCachedType);
274 unsigned index = type - HTMLCollection::FirstUnnamedDocumentCachedType;
275 ASSERT(index < HTMLCollection::NumUnnamedDocumentCachedTypes);
276 return &m_collectionInfo[index];
277 }
278
279 HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type, con st AtomicString& name);
280
281 // DOM methods overridden from parent classes
282
283 virtual String nodeName() const;
284 virtual NodeType nodeType() const;
285
286 // Other methods (not part of DOM)
287 virtual bool isDocumentNode() const { return true; }
288 virtual bool isHTMLDocument() const { return false; }
289 virtual bool isImageDocument() const { return false; }
290 #if ENABLE(SVG)
291 virtual bool isSVGDocument() const { return false; }
292 #endif
293 virtual bool isPluginDocument() const { return false; }
294 virtual bool isMediaDocument() const { return false; }
295
296 CSSStyleSelector* styleSelector() const { return m_styleSelector; }
297
298 Element* getElementByAccessKey(const String& key) const;
299
300 /**
301 * Updates the pending sheet count and then calls updateStyleSelector.
302 */
303 void removePendingSheet();
304
305 /**
306 * This method returns true if all top-level stylesheets have loaded (includ ing
307 * any @imports that they may be loading).
308 */
309 bool haveStylesheetsLoaded() const
310 {
311 return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets
312 #if USE(LOW_BANDWIDTH_DISPLAY)
313 || m_inLowBandwidthDisplay
314 #endif
315 ;
316 }
317
318 /**
319 * Increments the number of pending sheets. The <link> elements
320 * invoke this to add themselves to the loading list.
321 */
322 void addPendingSheet() { m_pendingStylesheets++; }
323
324 void addStyleSheetCandidateNode(Node*, bool createdByParser);
325 void removeStyleSheetCandidateNode(Node*);
326
327 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfter StylesheetsLoad; }
328 void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAft erStylesheetsLoad = b; }
329
330 /**
331 * Called when one or more stylesheets in the document may have been added, removed or changed.
332 *
333 * Creates a new style selector and assign it to this document. This is done by iterating through all nodes in
334 * document (or those before <BODY> in a HTML document), searching for style sheets. Stylesheets can be contained in
335 * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (X ML documents only). A list is
336 * constructed from these which is used to create the a new style selector w hich collates all of the stylesheets
337 * found and is used to calculate the derived styles for all rendering objec ts.
338 */
339 void updateStyleSelector();
340
341 void recalcStyleSelector();
342
343 bool usesDescendantRules() const { return m_usesDescendantRules; }
344 void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; }
345 bool usesSiblingRules() const { return m_usesSiblingRules; }
346 void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; }
347 bool usesFirstLineRules() const { return m_usesFirstLineRules; }
348 void setUsesFirstLineRules(bool b) { m_usesFirstLineRules = b; }
349 bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
350 void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
351
352 // Machinery for saving and restoring state when you leave and then go back to a page.
353 void registerFormElementWithState(HTMLFormControlElementWithState* e) { m_fo rmElementsWithState.add(e); }
354 void unregisterFormElementWithState(HTMLFormControlElementWithState* e) { m_ formElementsWithState.remove(e); }
355 Vector<String> formElementsState() const;
356 void setStateForNewFormElements(const Vector<String>&);
357 bool hasStateForNewFormElements() const;
358 bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
359
360 FrameView* view() const; // can be NULL
361 Frame* frame() const { return m_frame; } // can be NULL
362 Page* page() const; // can be NULL
363 Settings* settings() const; // can be NULL
364
365 PassRefPtr<Range> createRange();
366
367 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
368 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
369
370 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
371 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
372
373 // Special support for editing
374 PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
375 PassRefPtr<EditingText> createEditingTextNode(const String&);
376
377 virtual void recalcStyle( StyleChange = NoChange );
378 virtual void updateRendering();
379 void updateLayout();
380 void updateLayoutIgnorePendingStylesheets();
381 static void updateDocumentsRendering();
382 DocLoader* docLoader() { return m_docLoader; }
383
384 virtual void attach();
385 virtual void detach();
386
387 void clearFramePointer();
388
389 RenderArena* renderArena() { return m_renderArena; }
390
391 void clearAXObjectCache();
392 AXObjectCache* axObjectCache() const;
393
394 // to get visually ordered hebrew and arabic pages right
395 void setVisuallyOrdered();
396
397 void open(Document* ownerDocument = 0);
398 void implicitOpen();
399 void close();
400 void implicitClose();
401 void cancelParsing();
402
403 void write(const String& text, Document* ownerDocument = 0);
404 void writeln(const String& text, Document* ownerDocument = 0);
405 void finishParsing();
406 void clear();
407
408 bool wellFormed() const { return m_wellFormed; }
409
410 const KURL& url() const { return m_url; }
411 void setURL(const KURL&);
412
413 const KURL& baseURL() const { return m_baseURL; }
414 // Setting the BaseElementURL will change the baseURL.
415 void setBaseElementURL(const KURL&);
416
417 const String& baseTarget() const { return m_baseTarget; }
418 // Setting the BaseElementTarget will change the baseTarget.
419 void setBaseElementTarget(const String& baseTarget) { m_baseTarget = baseTar get; }
420
421 KURL completeURL(const String&) const;
422
423 unsigned visitedLinkHash(const AtomicString& attributeURL) const;
424
425 // from cachedObjectClient
426 virtual void setCSSStyleSheet(const String& url, const String& charset, cons t CachedCSSStyleSheet*);
427
428 #if FRAME_LOADS_USER_STYLESHEET
429 void setUserStyleSheet(const String& sheet);
430 #endif
431
432 String userStyleSheet() const;
433
434 CSSStyleSheet* elementSheet();
435 CSSStyleSheet* mappedElementSheet();
436 virtual Tokenizer* createTokenizer();
437 Tokenizer* tokenizer() { return m_tokenizer; }
438
439 bool printing() const { return m_printing; }
440 void setPrinting(bool p) { m_printing = p; }
441
442 enum ParseMode { Compat, AlmostStrict, Strict };
443
444 // Used by Chromium to know if it can just SIGKILL a renderer when navigatin g
445 bool hasUnloadEventListener();
446
447 private:
448 virtual void determineParseMode() {}
449
450 public:
451 void setParseMode(ParseMode m) { m_parseMode = m; }
452 ParseMode parseMode() const { return m_parseMode; }
453
454 bool inCompatMode() const { return m_parseMode == Compat; }
455 bool inAlmostStrictMode() const { return m_parseMode == AlmostStrict; }
456 bool inStrictMode() const { return m_parseMode == Strict; }
457
458 void setParsing(bool);
459 bool parsing() const { return m_bParsing; }
460 int minimumLayoutDelay();
461 bool shouldScheduleLayout();
462 int elapsedTime() const;
463
464 void setTextColor(const Color& color) { m_textColor = color; }
465 Color textColor() const { return m_textColor; }
466
467 const Color& linkColor() const { return m_linkColor; }
468 const Color& visitedLinkColor() const { return m_visitedLinkColor; }
469 const Color& activeLinkColor() const { return m_activeLinkColor; }
470 void setLinkColor(const Color& c) { m_linkColor = c; }
471 void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
472 void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
473 void resetLinkColor();
474 void resetVisitedLinkColor();
475 void resetActiveLinkColor();
476
477 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const IntPoint&, const PlatformMouseEvent&);
478
479 virtual bool childTypeAllowed(NodeType);
480 virtual PassRefPtr<Node> cloneNode(bool deep);
481
482 virtual bool canReplaceChild(Node* newChild, Node* oldChild);
483
484 StyleSheetList* styleSheets();
485
486 /* Newly proposed CSS3 mechanism for selecting alternate
487 stylesheets using the DOM. May be subject to change as
488 spec matures. - dwh
489 */
490 String preferredStylesheetSet() const;
491 String selectedStylesheetSet() const;
492 void setSelectedStylesheetSet(const String&);
493
494 bool setFocusedNode(PassRefPtr<Node>);
495 Node* focusedNode() const { return m_focusedNode.get(); }
496
497 // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough
498 // for WebCore to ignore the autofocus attribute on any form controls
499 bool ignoreAutofocus() const { return m_ignoreAutofocus; };
500 void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shou ldIgnore; };
501
502 void setHoverNode(PassRefPtr<Node>);
503 Node* hoverNode() const { return m_hoverNode.get(); }
504
505 void setActiveNode(PassRefPtr<Node>);
506 Node* activeNode() const { return m_activeNode.get(); }
507
508 void focusedNodeRemoved();
509 void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false);
510 void hoveredNodeDetached(Node*);
511 void activeChainNodeDetached(Node*);
512
513 // Updates for :target (CSS3 selector).
514 void setCSSTarget(Node*);
515 Node* getCSSTarget() const;
516
517 void setDocumentChanged(bool);
518
519 void attachNodeIterator(NodeIterator*);
520 void detachNodeIterator(NodeIterator*);
521
522 void attachRange(Range*);
523 void detachRange(Range*);
524
525 void nodeChildrenChanged(ContainerNode*);
526 void nodeWillBeRemoved(Node*);
527
528 void textInserted(Node*, unsigned offset, unsigned length);
529 void textRemoved(Node*, unsigned offset, unsigned length);
530 void textNodesMerged(Text* oldNode, unsigned offset);
531 void textNodeSplit(Text* oldNode);
532
533 DOMWindow* defaultView() const { return domWindow(); }
534 DOMWindow* domWindow() const;
535
536 PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&);
537
538 // keep track of what types of event listeners are registered, so we don't
539 // dispatch events unnecessarily
540 enum ListenerType {
541 DOMSUBTREEMODIFIED_LISTENER = 0x01,
542 DOMNODEINSERTED_LISTENER = 0x02,
543 DOMNODEREMOVED_LISTENER = 0x04,
544 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 0x08,
545 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 0x10,
546 DOMATTRMODIFIED_LISTENER = 0x20,
547 DOMCHARACTERDATAMODIFIED_LISTENER = 0x40,
548 OVERFLOWCHANGED_LISTENER = 0x80,
549 ANIMATIONEND_LISTENER = 0x100,
550 ANIMATIONSTART_LISTENER = 0x200,
551 ANIMATIONITERATION_LISTENER = 0x400,
552 TRANSITIONEND_LISTENER = 0x800
553 };
554
555 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTy pes & listenerType); }
556 void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listen erTypes | listenerType; }
557
558 CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
559
560 void handleWindowEvent(Event*, bool useCapture);
561 void setHTMLWindowEventListener(const AtomicString &eventType, PassRefPtr<Ev entListener>);
562 EventListener* getHTMLWindowEventListener(const AtomicString &eventType);
563 void removeHTMLWindowEventListener(const AtomicString &eventType);
564
565 void setHTMLWindowEventListener(const AtomicString& eventType, Attribute*);
566
567 void addWindowEventListener(const AtomicString& eventType, PassRefPtr<EventL istener>, bool useCapture);
568 void removeWindowEventListener(const AtomicString& eventType, EventListener* , bool useCapture);
569 bool hasWindowEventListener(const AtomicString& eventType);
570
571 void addPendingFrameUnloadEventCount();
572 void removePendingFrameUnloadEventCount();
573 void addPendingFrameBeforeUnloadEventCount();
574 void removePendingFrameBeforeUnloadEventCount();
575
576 PassRefPtr<EventListener> createHTMLEventListener(const String& functionName , const String& code, Node*);
577
578 /**
579 * Searches through the document, starting from fromNode, for the next selec table element that comes after fromNode.
580 * The order followed is as specified in section 17.11.1 of the HTML4 spec, which is elements with tab indexes
581 * first (from lowest to highest), and then elements without tab indexes (in document order).
582 *
583 * @param fromNode The node from which to start searching. The node after th is will be focused. May be null.
584 *
585 * @return The focus node that comes after fromNode
586 *
587 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1
588 */
589 Node* nextFocusableNode(Node* start, KeyboardEvent*);
590
591 /**
592 * Searches through the document, starting from fromNode, for the previous s electable element (that comes _before_)
593 * fromNode. The order followed is as specified in section 17.11.1 of the HT ML4 spec, which is elements with tab
594 * indexes first (from lowest to highest), and then elements without tab ind exes (in document order).
595 *
596 * @param fromNode The node from which to start searching. The node before t his will be focused. May be null.
597 *
598 * @return The focus node that comes before fromNode
599 *
600 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1
601 */
602 Node* previousFocusableNode(Node* start, KeyboardEvent*);
603
604 int nodeAbsIndex(Node*);
605 Node* nodeWithAbsIndex(int absIndex);
606
607 /**
608 * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv ="..." content="...">. This is called
609 * when a meta tag is encountered during document parsing, and also when a s cript dynamically changes or adds a meta
610 * tag. This enables scripts to use meta tags to perform refreshes and set e xpiry dates in addition to them being
611 * specified in a HTML file.
612 *
613 * @param equiv The http header name (value of the meta tag's "equiv" attrib ute)
614 * @param content The header value (value of the meta tag's "content" attrib ute)
615 */
616 void processHttpEquiv(const String& equiv, const String& content);
617
618 void dispatchImageLoadEventSoon(HTMLImageLoader*);
619 void dispatchImageLoadEventsNow();
620 void removeImage(HTMLImageLoader*);
621
622 // Returns the owning element in the parent document.
623 // Returns 0 if this is the top level document.
624 Element* ownerElement() const;
625
626 String title() const { return m_title; }
627 void setTitle(const String&, Element* titleElement = 0);
628 void removeTitle(Element* titleElement);
629
630 String cookie() const;
631 void setCookie(const String&);
632
633 String referrer() const;
634
635 String domain() const;
636 void setDomain(const String& newDomain);
637
638 String lastModified() const;
639
640 const KURL& cookieURL() const { return m_cookieURL; }
641
642 const KURL& policyBaseURL() const { return m_policyBaseURL; }
643 void setPolicyBaseURL(const KURL& url) { m_policyBaseURL = url; }
644
645 // The following implements the rule from HTML 4 for what valid names are.
646 // To get this right for all the XML cases, we probably have to improve this or move it
647 // and make it sensitive to the type of document.
648 static bool isValidName(const String&);
649
650 // The following breaks a qualified name into a prefix and a local name.
651 // It also does a validity check, and returns false if the qualified name
652 // is invalid. It also sets ExceptionCode when name is invalid.
653 static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&);
654
655 // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
656 static bool hasPrefixNamespaceMismatch(const QualifiedName&);
657
658 void addElementById(const AtomicString& elementId, Element *element);
659 void removeElementById(const AtomicString& elementId, Element *element);
660
661 void addImageMap(HTMLMapElement*);
662 void removeImageMap(HTMLMapElement*);
663 HTMLMapElement* getImageMap(const String& url) const;
664
665 HTMLElement* body();
666 void setBody(PassRefPtr<HTMLElement>, ExceptionCode&);
667
668 HTMLHeadElement* head();
669
670 bool execCommand(const String& command, bool userInterface = false, const St ring& value = String());
671 bool queryCommandEnabled(const String& command);
672 bool queryCommandIndeterm(const String& command);
673 bool queryCommandState(const String& command);
674 bool queryCommandSupported(const String& command);
675 String queryCommandValue(const String& command);
676
677 void addMarker(Range*, DocumentMarker::MarkerType, String description = Stri ng());
678 void addMarker(Node*, DocumentMarker);
679 void copyMarkers(Node *srcNode, unsigned startOffset, int length, Node *dstN ode, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
680 void removeMarkers(Range*, DocumentMarker::MarkerType = DocumentMarker::AllM arkers);
681 void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker:: MarkerType = DocumentMarker::AllMarkers);
682 void removeMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
683 void removeMarkers(Node*);
684 void repaintMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers) ;
685 void setRenderedRectForMarker(Node*, DocumentMarker, const IntRect&);
686 void invalidateRenderedRectsForMarkersInRect(const IntRect&);
687 void shiftMarkers(Node*, unsigned startOffset, int delta, DocumentMarker::Ma rkerType = DocumentMarker::AllMarkers);
688
689 DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::Marke rType = DocumentMarker::AllMarkers);
690 Vector<DocumentMarker> markersForNode(Node*);
691 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType = Documen tMarker::AllMarkers);
692
693 // designMode support
694 enum InheritedBool { off = false, on = true, inherit };
695 void setDesignMode(InheritedBool value);
696 InheritedBool getDesignMode() const;
697 bool inDesignMode() const;
698
699 Document* parentDocument() const;
700 Document* topDocument() const;
701
702 int docID() const { return m_docID; }
703
704 #if ENABLE(XSLT)
705 void applyXSLTransform(ProcessingInstruction* pi);
706 void setTransformSource(void* doc);
707 const void* transformSource() { return m_transformSource; }
708 PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDoc ument; }
709 void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
710 #endif
711
712 #if ENABLE(XBL)
713 // XBL methods
714 XBLBindingManager* bindingManager() const { return m_bindingManager; }
715 #endif
716
717 void incDOMTreeVersion() { ++m_domtree_version; }
718 unsigned domTreeVersion() const { return m_domtree_version; }
719
720 void setDocType(PassRefPtr<DocumentType>);
721
722 void finishedParsing();
723
724 #if ENABLE(XPATH)
725 // XPathEvaluator methods
726 PassRefPtr<XPathExpression> createExpression(const String& expression,
727 XPathNSResolver* resolver,
728 ExceptionCode& ec);
729 PassRefPtr<XPathNSResolver> createNSResolver(Node *nodeResolver);
730 PassRefPtr<XPathResult> evaluate(const String& expression,
731 Node* contextNode,
732 XPathNSResolver* resolver,
733 unsigned short type,
734 XPathResult* result,
735 ExceptionCode& ec);
736 #endif // ENABLE(XPATH)
737
738 enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingShe ets, IgnoreLayoutWithPendingSheets };
739
740 bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout = = DidLayoutWithPendingSheets; }
741
742 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = tr ue; }
743
744 const String& iconURL() const { return m_iconURL; }
745 void setIconURL(const String& iconURL, const String& type);
746
747 void setUseSecureKeyboardEntryWhenActive(bool);
748 bool useSecureKeyboardEntryWhenActive() const;
749
750 #if USE(LOW_BANDWIDTH_DISPLAY)
751 void setDocLoader(DocLoader* loader) { m_docLoader = loader; }
752 bool inLowBandwidthDisplay() const { return m_inLowBandwidthDisplay; }
753 void setLowBandwidthDisplay(bool lowBandWidth) { m_inLowBandwidthDisplay = l owBandWidth; }
754 #endif
755
756 void addNodeListCache() { ++m_numNodeListCaches; }
757 void removeNodeListCache() { ASSERT(m_numNodeListCaches > 0); --m_numNodeLis tCaches; }
758 bool hasNodeListCaches() const { return m_numNodeListCaches; }
759
760 void updateFocusAppearanceSoon();
761 void cancelFocusAppearanceUpdate();
762
763 // FF method for accessing the selection added for compatability.
764 DOMSelection* getSelection() const;
765
766 // Extension for manipulating canvas drawing contexts for use in CSS
767 CanvasRenderingContext2D* getCSSCanvasContext(const String& type, const Stri ng& name, int width, int height);
768 HTMLCanvasElement* getCSSCanvasElement(const String& name);
769
770 bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
771 void initDNSPrefetchEnabled();
772 void setDNSPrefetchControl(const WebCore::String&);
773
774 protected:
775 Document(Frame*, bool isXHTML);
776
777 private:
778 CSSStyleSelector* m_styleSelector;
779 bool m_didCalculateStyleSelector;
780
781 Frame* m_frame;
782 DocLoader* m_docLoader;
783 Tokenizer* m_tokenizer;
784 bool m_wellFormed;
785
786 // Document URLs.
787 KURL m_url; // Document.URL: The URL from which this document was retrieved .
788 KURL m_baseURL; // Node.baseURI: The URL to use when resolving relative URL s.
789 KURL m_baseElementURL; // The URL set by the <base> element.
790 KURL m_cookieURL; // The URL to use for cookie access.
791 KURL m_policyBaseURL; // The policy URL for third-party cookie blocking.
792
793 // Document.documentURI:
794 // Although URL-like, Document.documentURI can actually be set to any
795 // string by content. Document.documentURI affects m_baseURL unless the
796 // document contains a <base> element, in which case the <base> element
797 // takes precedence.
798 String m_documentURI;
799
800 String m_baseTarget;
801
802 RefPtr<DocumentType> m_docType;
803 mutable RefPtr<DOMImplementation> m_implementation;
804
805 RefPtr<StyleSheet> m_sheet;
806 #if FRAME_LOADS_USER_STYLESHEET
807 String m_usersheet;
808 #endif
809
810 // Track the number of currently loading top-level stylesheets. Sheets
811 // loaded using the @import directive are not included in this count.
812 // We use this count of pending sheets to detect when we can begin attaching
813 // elements.
814 int m_pendingStylesheets;
815
816 // But sometimes you need to ignore pending stylesheet count to
817 // force an immediate layout when requested by JS.
818 bool m_ignorePendingStylesheets;
819
820 // If we do ignore the pending stylesheet count, then we need to add a boole an
821 // to track that this happened so that we can do a full repaint when the sty lesheets
822 // do eventually load.
823 PendingSheetLayout m_pendingSheetLayout;
824
825 bool m_hasNodesWithPlaceholderStyle;
826
827 RefPtr<CSSStyleSheet> m_elemSheet;
828 RefPtr<CSSStyleSheet> m_mappedElementSheet;
829
830 bool m_printing;
831
832 bool m_ignoreAutofocus;
833
834 ParseMode m_parseMode;
835
836 Color m_textColor;
837
838 RefPtr<Node> m_focusedNode;
839 RefPtr<Node> m_hoverNode;
840 RefPtr<Node> m_activeNode;
841 mutable RefPtr<Element> m_documentElement;
842
843 unsigned m_domtree_version;
844
845 HashSet<NodeIterator*> m_nodeIterators;
846 HashSet<Range*> m_ranges;
847
848 unsigned short m_listenerTypes;
849
850 RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are cur rently in effect for our media type and stylesheet set.
851 ListHashSet<Node*> m_styleSheetCandidateNodes; // All of the nodes that coul d potentially provide stylesheets to the document (<link>, <style>, <?xml-styles heet>)
852
853 RegisteredEventListenerList m_windowEventListeners;
854
855 typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElem entKeyHashTraits> FormElementStateMap;
856 ListHashSet<HTMLFormControlElementWithState*> m_formElementsWithState;
857 FormElementStateMap m_stateForNewFormElements;
858
859 Color m_linkColor;
860 Color m_visitedLinkColor;
861 Color m_activeLinkColor;
862
863 String m_preferredStylesheetSet;
864 String m_selectedStylesheetSet;
865
866 bool m_loadingSheet;
867 bool visuallyOrdered;
868 bool m_bParsing;
869 bool m_docChanged;
870 bool m_inStyleRecalc;
871 bool m_closeAfterStyleRecalc;
872 bool m_usesDescendantRules;
873 bool m_usesSiblingRules;
874 bool m_usesFirstLineRules;
875 bool m_usesFirstLetterRules;
876 bool m_gotoAnchorNeededAfterStylesheetsLoad;
877
878 bool m_isDNSPrefetchEnabled;
879 bool m_haveExplicitlyDisabledDNSPrefetch;
880
881 String m_title;
882 bool m_titleSetExplicitly;
883 RefPtr<Element> m_titleElement;
884
885 RenderArena* m_renderArena;
886
887 typedef std::pair<Vector<DocumentMarker>, Vector<IntRect> > MarkerMapVectorP air;
888 typedef HashMap<RefPtr<Node>, MarkerMapVectorPair*> MarkerMap;
889 MarkerMap m_markers;
890
891 mutable AXObjectCache* m_axObjectCache;
892
893 DeprecatedPtrList<HTMLImageLoader> m_imageLoadEventDispatchSoonList;
894 DeprecatedPtrList<HTMLImageLoader> m_imageLoadEventDispatchingList;
895 Timer<Document> m_imageLoadEventTimer;
896
897 Timer<Document> m_updateFocusAppearanceTimer;
898
899 Node* m_cssTarget;
900
901 bool m_processingLoadEvent;
902 double m_startTime;
903 bool m_overMinimumLayoutThreshold;
904
905 #if ENABLE(XSLT)
906 void* m_transformSource;
907 RefPtr<Document> m_transformSourceDocument;
908 #endif
909
910 #if ENABLE(XBL)
911 XBLBindingManager* m_bindingManager; // The access point through which docum ents and elements communicate with XBL.
912 #endif
913
914 typedef HashMap<AtomicStringImpl*, HTMLMapElement*> ImageMapsByName;
915 ImageMapsByName m_imageMapsByName;
916
917 HashSet<Node*> m_disconnectedNodesWithEventListeners;
918
919 int m_docID; // A unique document identifier used for things like document-s pecific mapped attributes.
920
921 String m_xmlEncoding;
922 String m_xmlVersion;
923 bool m_xmlStandalone;
924
925 String m_contentLanguage;
926
927 // UScriptCode can be derived from non-Unicode charsets and help us select a fallback
928 // font. Because it's derived from charset, it's a document-wide constant.
929 // For instance, it'll be Latin, SimplifiedHan, TraditionalHan, Hiragana,
930 // Hangul, Arabic and Hebrew for documents in ISO-8859-1, GBK, Big5, Shift_J IS,
931 // EUC-KR, Windows-1256 and Windows-1255, respectively. In case of Japanese encodings,
932 // either Hiragana or Katakana should work but Han does not because it does not
933 // uniquely identify Japanese and as a result does not help the font selecti on.
934 // Obviously, this does not work well for Unicode-encoded documents. In the meantime,
935 // we can resort to the 'dominant' script of the current UI language.
936 // In the future, we should refer to the value of xml:lang and lang to infer
937 // this value for invididual text nodes. CSSStyleSelector might be a good pl ace for that.
938 // Moreover, the value of m_contentLanguage should be utilized as well.
939 mutable UScriptCode m_dominantScript;
940
941 public:
942 bool inPageCache();
943 void setInPageCache(bool flag);
944
945 // Elements can register themselves for the "willSaveToCache()" and
946 // "didRestoreFromCache()" callbacks
947 void registerForCacheCallbacks(Element*);
948 void unregisterForCacheCallbacks(Element*);
949 void willSaveToCache();
950 void didRestoreFromCache();
951
952 void setShouldCreateRenderers(bool);
953 bool shouldCreateRenderers();
954
955 void setDecoder(PassRefPtr<TextResourceDecoder>);
956 TextResourceDecoder* decoder() const { return m_decoder.get(); }
957
958 UChar backslashAsCurrencySymbol() const;
959
960 #if ENABLE(DASHBOARD_SUPPORT)
961 void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
962 bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; }
963 bool hasDashboardRegions () const { return m_hasDashboardRegions; }
964 void setHasDashboardRegions (bool f) { m_hasDashboardRegions = f; }
965 const Vector<DashboardRegionValue>& dashboardRegions() const;
966 void setDashboardRegions(const Vector<DashboardRegionValue>&);
967 #endif
968
969 void removeAllEventListenersFromAllNodes();
970
971 void registerDisconnectedNodeWithEventListeners(Node*);
972 void unregisterDisconnectedNodeWithEventListeners(Node*);
973
974 HTMLFormElement::CheckedRadioButtons& checkedRadioButtons() { return m_check edRadioButtons; }
975
976 #if ENABLE(SVG)
977 const SVGDocumentExtensions* svgExtensions();
978 SVGDocumentExtensions* accessSVGExtensions();
979 #endif
980
981 void initSecurityContext();
982 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
983
984 // Explicitly override the security origin for this document.
985 // Note: It is dangerous to change the security origin of a document
986 // that already contains content.
987 void setSecurityOrigin(SecurityOrigin*);
988
989 bool processingLoadEvent() const { return m_processingLoadEvent; }
990
991 #if ENABLE(DATABASE)
992 void addOpenDatabase(Database*);
993 void removeOpenDatabase(Database*);
994 DatabaseThread* databaseThread(); // Creates the thread as needed, but not if it has been already terminated.
995 void setHasOpenDatabases() { m_hasOpenDatabases = true; }
996 bool hasOpenDatabases() { return m_hasOpenDatabases; }
997 void stopDatabases();
998 #endif
999 protected:
1000 void clearXMLVersion() { m_xmlVersion = String(); }
1001
1002 private:
1003 void updateTitle();
1004 void removeAllDisconnectedNodeEventListeners();
1005 void imageLoadEventTimerFired(Timer<Document>*);
1006 void updateFocusAppearanceTimerFired(Timer<Document>*);
1007 void updateBaseURL();
1008
1009 RefPtr<SecurityOrigin> m_securityOrigin;
1010
1011 RenderObject* m_savedRenderer;
1012 int m_secureForms;
1013
1014 RefPtr<TextResourceDecoder> m_decoder;
1015
1016 // We maintain the invariant that m_duplicateIds is the count of all element s with a given ID
1017 // excluding the one referenced in m_elementsById, if any. This means it one less than the total count
1018 // when the first node with a given ID is cached, otherwise the same as the total count.
1019 mutable HashMap<AtomicStringImpl*, Element*> m_elementsById;
1020 mutable HashCountedSet<AtomicStringImpl*> m_duplicateIds;
1021
1022 mutable HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKe y;
1023
1024 InheritedBool m_designMode;
1025
1026 int m_selfOnlyRefCount;
1027
1028 HTMLFormElement::CheckedRadioButtons m_checkedRadioButtons;
1029
1030 typedef HashMap<AtomicStringImpl*, HTMLCollection::CollectionInfo*> NamedCol lectionMap;
1031 HTMLCollection::CollectionInfo m_collectionInfo[HTMLCollection::NumUnnamedDo cumentCachedTypes];
1032 NamedCollectionMap m_nameCollectionInfo[HTMLCollection::NumNamedDocumentCach edTypes];
1033
1034 #if ENABLE(XPATH)
1035 RefPtr<XPathEvaluator> m_xpathEvaluator;
1036 #endif
1037
1038 #if ENABLE(SVG)
1039 SVGDocumentExtensions* m_svgExtensions;
1040 #endif
1041
1042 #if ENABLE(DASHBOARD_SUPPORT)
1043 Vector<DashboardRegionValue> m_dashboardRegions;
1044 bool m_hasDashboardRegions;
1045 bool m_dashboardRegionsDirty;
1046 #endif
1047
1048 HashMap<String, RefPtr<HTMLCanvasElement> > m_cssCanvasElements;
1049
1050 mutable bool m_accessKeyMapValid;
1051 bool m_createRenderers;
1052 bool m_inPageCache;
1053 String m_iconURL;
1054
1055 HashSet<Element*> m_pageCacheCallbackElements;
1056
1057 bool m_useSecureKeyboardEntryWhenActive;
1058
1059 bool m_isXHTML;
1060
1061 unsigned m_numNodeListCaches;
1062
1063 public:
1064 typedef HashMap<WebCore::Node*, JSNode*> JSWrapperCache;
1065 JSWrapperCache& wrapperCache() { return m_wrapperCache; }
1066 private:
1067 JSWrapperCache m_wrapperCache;
1068
1069 #if ENABLE(DATABASE)
1070 RefPtr<DatabaseThread> m_databaseThread;
1071 bool m_hasOpenDatabases; // This never changes back to false, even as the database thread is closed.
1072 typedef HashSet<Database*> DatabaseSet;
1073 OwnPtr<DatabaseSet> m_openDatabaseSet;
1074 #endif
1075
1076 #if USE(LOW_BANDWIDTH_DISPLAY)
1077 bool m_inLowBandwidthDisplay;
1078 #endif
1079
1080 };
1081
1082 inline bool Document::hasElementWithId(AtomicStringImpl* id) const
1083 {
1084 ASSERT(id);
1085 return m_elementsById.contains(id) || m_duplicateIds.contains(id);
1086 }
1087
1088 } // namespace WebCore
1089
1090 #endif // Document_h
OLDNEW
« no previous file with comments | « webkit/pending/DOMWindow.cpp ('k') | webkit/pending/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698