root/trunk/WebCore/dom/Document.h

Revision 35545, 39.2 kB (checked in by dino@apple.com, 4 days ago)

2008-08-04 Dean Jackson <dino@apple.com>

Reviewed by Dave Hyatt.

Improve AnimationController
https://bugs.webkit.org/show_bug.cgi?id=19938

  • Transition class is now called Animation
  • new state-based AnimationController that can support CSS Animations
  • add support for -webkit-transition-delay
  • remove -webkit-transition-repeat-count (since it never existed officially)
  • updates the -webkit-transition shorthand to reflect removing repeat count
  • updates the Transition class so that properties can be shared with animations
  • adds a "now" keyword for -webkit-transition-delay
  • adds a new change type for style (changed by animation)
  • adds new event names (although they are not dispatched yet)
  • makes text stroke and text fill colors returned by RenderStyle const

Tests:

  • manual-tests/transition-left.html
  • manual-tests/transition-delay.html
  • manual-tests/transition-timing-functions.html
  • css/CSSComputedStyleDeclaration.cpp:
  • css/CSSParser.cpp:
  • css/CSSParser.h:
  • css/CSSPropertyNames.in:
  • css/CSSStyleSelector.cpp:
  • css/CSSStyleSelector.h:
  • css/CSSTimingFunctionValue.h:
  • css/CSSValue.h:
  • css/CSSValueKeywords.in:
  • css/WebKitCSSTransformValue.cpp:
  • dom/Document.cpp:
  • dom/Document.h:
  • dom/Element.cpp:
  • dom/EventNames.h:
  • dom/Node.cpp:
  • dom/Node.h:
  • history/CachedPage.cpp:
  • page/AnimationController.cpp:
  • page/AnimationController.h:
  • page/Frame.cpp:
  • rendering/RenderObject.cpp:
  • rendering/RenderWidget.cpp:
  • rendering/style/RenderStyle.cpp:
  • rendering/style/RenderStyle.h:
  • Property svn:eol-style set to native
Line 
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 <wtf/HashCountedSet.h>
38 #include <wtf/ListHashSet.h>
39
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.
43 #if PLATFORM(MAC)
44 #define FRAME_LOADS_USER_STYLESHEET 1
45 #else
46 #define FRAME_LOADS_USER_STYLESHEET 0
47 #endif
48
49 namespace WebCore {
50
51     class AXObjectCache;
52     class Attr;
53     class Attribute;
54     class CDATASection;
55     class CachedCSSStyleSheet;
56     class CanvasRenderingContext2D;
57     class CharacterData;
58     class CSSStyleDeclaration;
59     class CSSStyleSelector;
60     class CSSStyleSheet;
61     class Comment;
62     class Database;
63     class DOMImplementation;
64     class DOMSelection;
65     class DOMWindow;
66     class DatabaseThread;
67     class DocLoader;
68     class DocumentFragment;
69     class DocumentType;
70     class EditingText;
71     class Element;
72     class EntityReference;
73     class Event;
74     class EventListener;
75     class Frame;
76     class FrameView;
77     class HTMLCanvasElement;
78     class HTMLDocument;
79     class HTMLElement;
80     class HTMLFormControlElementWithState;
81     class HTMLFormElement;
82     class HTMLHeadElement;
83     class HTMLImageLoader;
84     class HTMLInputElement;
85     class HTMLMapElement;
86     class IntPoint;
87     class JSNode;
88     class MouseEventWithHitTestResults;
89     class NodeFilter;
90     class NodeIterator;
91     class Page;
92     class PlatformMouseEvent;
93     class ProcessingInstruction;
94     class Range;
95     class RegisteredEventListener;
96     class RenderArena;
97     class SecurityOrigin;
98     class Settings;
99     class StyleSheet;
100     class StyleSheetList;
101     class Text;
102     class TextResourceDecoder;
103     class Tokenizer;
104     class TreeWalker;
105
106 #if ENABLE(SVG)
107     class SVGDocumentExtensions;
108 #endif
109     
110 #if ENABLE(XBL)
111     class XBLBindingManager;
112 #endif
113
114 #if ENABLE(XPATH)
115     class XPathEvaluator;
116     class XPathExpression;
117     class XPathNSResolver;
118     class XPathResult;
119 #endif
120
121 #if ENABLE(DASHBOARD_SUPPORT)
122     struct DashboardRegionValue;
123 #endif
124     struct HitTestRequest;
125
126     typedef int ExceptionCode;
127
128 class FormElementKey {
129 public:
130     FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0);
131     ~FormElementKey();
132     FormElementKey(const FormElementKey&);
133     FormElementKey& operator=(const FormElementKey&);
134
135     AtomicStringImpl* name() const { return m_name; }
136     AtomicStringImpl* type() const { return m_type; }
137
138     // Hash table deleted values, which are only constructed and never copied or destroyed.
139     FormElementKey(WTF::HashTableDeletedValueType) : m_name(hashTableDeletedValue()) { }
140     bool isHashTableDeletedValue() const { return m_name == hashTableDeletedValue(); }
141
142 private:
143     void ref() const;
144     void deref() const;
145
146     static AtomicStringImpl* hashTableDeletedValue() { return reinterpret_cast<AtomicStringImpl*>(-1); }
147
148     AtomicStringImpl* m_name;
149     AtomicStringImpl* m_type;
150 };
151
152 inline bool operator==(const FormElementKey& a, const FormElementKey& b)
153 {
154     return a.name() == b.name() && a.type() == b.type();
155 }
156
157 struct FormElementKeyHash {
158     static unsigned hash(const FormElementKey&);
159     static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; }
160     static const bool safeToCompareToEmptyOrDeleted = true;
161 };
162
163 struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
164     static void constructDeletedValue(FormElementKey& slot) { new (&slot) FormElementKey(WTF::HashTableDeletedValue); }
165     static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); }
166 };
167
168 class Document : public ContainerNode {
169 public:
170     static PassRefPtr<Document> create(Frame* frame)
171     {
172         return new Document(frame, false);
173     }
174     static PassRefPtr<Document> createXHTML(Frame* frame)
175     {
176         return new Document(frame, true);
177     }
178     virtual ~Document();
179
180     virtual void removedLastRef();
181
182     // Nodes belonging to this document hold "self-only" references -
183     // these are enough to keep the document from being destroyed, but
184     // not enough to keep it from removing its children. This allows a
185     // node that outlives its document to still have a valid document
186     // pointer without introducing reference cycles
187
188     void selfOnlyRef()
189     {
190         ASSERT(!m_deletionHasBegun);
191         ++m_selfOnlyRefCount;
192     }
193     void selfOnlyDeref()
194     {
195         ASSERT(!m_deletionHasBegun);
196         --m_selfOnlyRefCount;
197         if (!m_selfOnlyRefCount && !refCount()) {
198 #ifndef NDEBUG
199             m_deletionHasBegun = true;
200 #endif
201             delete this;
202         }
203     }
204
205     // DOM methods & attributes for Document
206
207     DocumentType* doctype() const { return m_docType.get(); }
208
209     DOMImplementation* implementation() const;
210     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
211     Element* documentElement() const;
212     virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
213     PassRefPtr<DocumentFragment> createDocumentFragment ();
214     PassRefPtr<Text> createTextNode(const String& data);
215     PassRefPtr<Comment> createComment(const String& data);
216     PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&);
217     PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
218     PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode& ec) { return createAttributeNS(String(), name, ec, true); }
219     PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
220     PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
221     PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
222     virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
223     PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser, ExceptionCode& ec);
224     Element* getElementById(const AtomicString&) const;
225     bool hasElementWithId(AtomicStringImpl* id) const;
226     bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); }
227
228     Element* elementFromPoint(int x, int y) const;
229     String readyState() const;
230     String inputEncoding() const;
231     String defaultCharset() const;
232
233     String charset() const { return inputEncoding(); }
234     String characterSet() const { return inputEncoding(); }
235
236     void setCharset(const String&);
237
238     String contentLanguage() const { return m_contentLanguage; }
239     void setContentLanguage(const String& lang) { m_contentLanguage = lang; }
240
241     String xmlEncoding() const { return m_xmlEncoding; }
242     String xmlVersion() const { return m_xmlVersion; }
243     bool xmlStandalone() const { return m_xmlStandalone; }
244
245     void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLTokenizer
246     void setXMLVersion(const String&, ExceptionCode&);
247     void setXMLStandalone(bool, ExceptionCode&);
248
249     String documentURI() const { return m_documentURI; }
250     void setDocumentURI(const String&);
251
252     virtual KURL baseURI() const;
253
254     PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
255
256     PassRefPtr<HTMLCollection> images();
257     PassRefPtr<HTMLCollection> embeds();
258     PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
259     PassRefPtr<HTMLCollection> applets();
260     PassRefPtr<HTMLCollection> links();
261     PassRefPtr<HTMLCollection> forms();
262     PassRefPtr<HTMLCollection> anchors();
263     PassRefPtr<HTMLCollection> all();
264     PassRefPtr<HTMLCollection> objects();
265     PassRefPtr<HTMLCollection> scripts();
266     PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
267     PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
268
269     HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type)
270     {
271         ASSERT(type >= HTMLCollection::FirstUnnamedDocumentCachedType);
272         unsigned index = type - HTMLCollection::FirstUnnamedDocumentCachedType;
273         ASSERT(index < HTMLCollection::NumUnnamedDocumentCachedTypes);
274         return &m_collectionInfo[index];
275     }
276
277     HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type, const AtomicString& name);
278
279     // DOM methods overridden from  parent classes
280
281     virtual String nodeName() const;
282     virtual NodeType nodeType() const;
283
284     // Other methods (not part of DOM)
285     virtual bool isDocumentNode() const { return true; }
286     virtual bool isHTMLDocument() const { return false; }
287     virtual bool isImageDocument() const { return false; }
288 #if ENABLE(SVG)
289     virtual bool isSVGDocument() const { return false; }
290 #endif
291     virtual bool isPluginDocument() const { return false; }
292     virtual bool isMediaDocument() const { return false; }
293    
294     CSSStyleSelector* styleSelector() const { return m_styleSelector; }
295
296     Element* getElementByAccessKey(const String& key) const;
297    
298     /**
299      * Updates the pending sheet count and then calls updateStyleSelector.
300      */
301     void removePendingSheet();
302
303     /**
304      * This method returns true if all top-level stylesheets have loaded (including
305      * any @imports that they may be loading).
306      */
307     bool haveStylesheetsLoaded() const
308     {
309         return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets
310 #if USE(LOW_BANDWIDTH_DISPLAY)
311             || m_inLowBandwidthDisplay
312 #endif
313             ;
314     }
315
316     /**
317      * Increments the number of pending sheets.  The <link> elements
318      * invoke this to add themselves to the loading list.
319      */
320     void addPendingSheet() { m_pendingStylesheets++; }
321
322     void addStyleSheetCandidateNode(Node*, bool createdByParser);
323     void removeStyleSheetCandidateNode(Node*);
324
325     bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
326     void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
327
328     /**
329      * Called when one or more stylesheets in the document may have been added, removed or changed.
330      *
331      * Creates a new style selector and assign it to this document. This is done by iterating through all nodes in
332      * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in
333      * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is
334      * constructed from these which is used to create the a new style selector which collates all of the stylesheets
335      * found and is used to calculate the derived styles for all rendering objects.
336      */
337     void updateStyleSelector();
338
339     void recalcStyleSelector();
340
341     bool usesDescendantRules() const { return m_usesDescendantRules; }
342     void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; }
343     bool usesSiblingRules() const { return m_usesSiblingRules; }
344     void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; }
345     bool usesFirstLineRules() const { return m_usesFirstLineRules; }
346     void setUsesFirstLineRules(bool b) { m_usesFirstLineRules = b; }
347     bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
348     void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
349
350     // Machinery for saving and restoring state when you leave and then go back to a page.
351     void registerFormElementWithState(HTMLFormControlElementWithState* e) { m_formElementsWithState.add(e); }
352     void unregisterFormElementWithState(HTMLFormControlElementWithState* e) { m_formElementsWithState.remove(e); }
353     Vector<String> formElementsState() const;
354     void setStateForNewFormElements(const Vector<String>&);
355     bool hasStateForNewFormElements() const;
356     bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
357
358     FrameView* view() const; // can be NULL
359     Frame* frame() const { return m_frame; } // can be NULL
360     Page* page() const; // can be NULL
361     Settings* settings() const; // can be NULL
362
363     PassRefPtr<Range> createRange();
364
365     PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
366         PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
367
368     PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
369         PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
370
371     // Special support for editing
372     PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration();
373     PassRefPtr<EditingText> createEditingTextNode(const String&);
374
375     virtual void recalcStyle( StyleChange = NoChange );
376     virtual void updateRendering();
377     void updateLayout();
378     void updateLayoutIgnorePendingStylesheets();
379     static void updateDocumentsRendering();
380     DocLoader* docLoader() { return m_docLoader; }
381
382     virtual void attach();
383     virtual void detach();
384
385     void clearFramePointer();
386
387     RenderArena* renderArena() { return m_renderArena; }
388
389     void clearAXObjectCache();
390     AXObjectCache* axObjectCache() const;
391    
392     // to get visually ordered hebrew and arabic pages right
393     void setVisuallyOrdered();
394
395     void open(Document* ownerDocument = 0);
396     void implicitOpen();
397     void close();
398     void implicitClose();
399     void cancelParsing();
400
401     void write(const String& text, Document* ownerDocument = 0);
402     void writeln(const String& text, Document* ownerDocument = 0);
403     void finishParsing();
404     void clear();
405
406     bool wellFormed() const { return m_wellFormed; }
407
408     const KURL& url() const { return m_url; }
409     void setURL(const KURL&);
410
411     const KURL& baseURL() const { return m_baseURL; }
412     // Setting the BaseElementURL will change the baseURL.
413     void setBaseElementURL(const KURL&);
414
415     const String& baseTarget() const { return m_baseTarget; }
416     // Setting the BaseElementTarget will change the baseTarget.
417     void setBaseElementTarget(const String& baseTarget) { m_baseTarget = baseTarget; }
418
419     KURL completeURL(const String&) const;
420
421     unsigned visitedLinkHash(const AtomicString& attributeURL) const;
422
423     // from cachedObjectClient
424     virtual void setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet*);
425
426 #if FRAME_LOADS_USER_STYLESHEET
427     void setUserStyleSheet(const String& sheet);
428 #endif
429
430     String userStyleSheet() const;
431
432     CSSStyleSheet* elementSheet();
433     CSSStyleSheet* mappedElementSheet();
434     virtual Tokenizer* createTokenizer();
435     Tokenizer* tokenizer() { return m_tokenizer; }
436    
437     bool printing() const { return m_printing; }
438     void setPrinting(bool p) { m_printing = p; }
439
440     enum ParseMode { Compat, AlmostStrict, Strict };
441
442 private:
443     virtual void determineParseMode() {}
444    
445 public:
446     void setParseMode(ParseMode m) { m_parseMode = m; }
447     ParseMode parseMode() const { return m_parseMode; }
448
449     bool inCompatMode() const { return m_parseMode == Compat; }
450     bool inAlmostStrictMode() const { return m_parseMode == AlmostStrict; }
451     bool inStrictMode() const { return m_parseMode == Strict; }
452    
453     void setParsing(bool);
454     bool parsing() const { return m_bParsing; }
455     int minimumLayoutDelay();
456     bool shouldScheduleLayout();
457     int elapsedTime() const;
458    
459     void setTextColor(const Color& color) { m_textColor = color; }
460     Color textColor() const { return m_textColor; }
461
462     const Color& linkColor() const { return m_linkColor; }
463     const Color& visitedLinkColor() const { return m_visitedLinkColor; }
464     const Color& activeLinkColor() const { return m_activeLinkColor; }
465     void setLinkColor(const Color& c) { m_linkColor = c; }
466     void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
467     void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
468     void resetLinkColor();
469     void resetVisitedLinkColor();
470     void resetActiveLinkColor();
471    
472     MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const IntPoint&, const PlatformMouseEvent&);
473
474     virtual bool childTypeAllowed(NodeType);
475     virtual PassRefPtr<Node> cloneNode(bool deep);
476
477     virtual bool canReplaceChild(Node* newChild, Node* oldChild);
478    
479     StyleSheetList* styleSheets();
480
481     /* Newly proposed CSS3 mechanism for selecting alternate
482        stylesheets using the DOM. May be subject to change as
483        spec matures. - dwh
484     */
485     String preferredStylesheetSet() const;
486     String selectedStylesheetSet() const;
487     void setSelectedStylesheetSet(const String&);
488
489     bool setFocusedNode(PassRefPtr<Node>);
490     Node* focusedNode() const { return m_focusedNode.get(); }
491
492     // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough
493     // for WebCore to ignore the autofocus attribute on any form controls
494