diff options
author | Andrei Popescu <andreip@google.com> | 2009-08-19 14:09:30 +0100 |
---|---|---|
committer | Andrei Popescu <andreip@google.com> | 2009-08-19 14:09:30 +0100 |
commit | 058ccc7ba0a4d59b9f6e92808332aa9895425fc7 (patch) | |
tree | 276aad5a2bbc2fd7d65d21bfca42c9de88b3dd20 /WebCore/dom | |
parent | 2796dd1bf3b4b01e7e1d96ea91bd3a212f647579 (diff) | |
download | external_webkit-058ccc7ba0a4d59b9f6e92808332aa9895425fc7.zip external_webkit-058ccc7ba0a4d59b9f6e92808332aa9895425fc7.tar.gz external_webkit-058ccc7ba0a4d59b9f6e92808332aa9895425fc7.tar.bz2 |
Revert "Merge WebKit r47420"
This reverts commit d227fc870c7a697500a3c900c31baf05fb9a8524.
Diffstat (limited to 'WebCore/dom')
42 files changed, 824 insertions, 737 deletions
diff --git a/WebCore/dom/Attr.cpp b/WebCore/dom/Attr.cpp index aa5916b..435c1af 100644 --- a/WebCore/dom/Attr.cpp +++ b/WebCore/dom/Attr.cpp @@ -3,7 +3,7 @@ * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Peter Kelly (pmk@post.com) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,10 +30,10 @@ namespace WebCore { -inline Attr::Attr(Element* element, Document* document, PassRefPtr<Attribute> attribute) - : ContainerNode(document) +Attr::Attr(Element* element, Document* docPtr, PassRefPtr<Attribute> a) + : ContainerNode(docPtr) , m_element(element) - , m_attribute(attribute) + , m_attribute(a) , m_ignoreChildrenChanged(0) , m_specified(true) { @@ -41,13 +41,6 @@ inline Attr::Attr(Element* element, Document* document, PassRefPtr<Attribute> at m_attribute->m_impl = this; } -PassRefPtr<Attr> Attr::create(Element* element, Document* document, PassRefPtr<Attribute> attribute) -{ - RefPtr<Attr> attr = adoptRef(new Attr(element, document, attribute)); - attr->createTextChild(); - return attr.release(); -} - Attr::~Attr() { ASSERT(m_attribute->attr() == this); @@ -93,14 +86,14 @@ const AtomicString& Attr::prefix() const return m_attribute->prefix(); } -void Attr::setPrefix(const AtomicString& prefix, ExceptionCode& ec) +void Attr::setPrefix(const AtomicString &_prefix, ExceptionCode& ec) { ec = 0; - checkSetPrefix(prefix, ec); + checkSetPrefix(_prefix, ec); if (ec) return; - m_attribute->setPrefix(prefix); + m_attribute->setPrefix(_prefix); } String Attr::nodeValue() const @@ -108,11 +101,11 @@ String Attr::nodeValue() const return value(); } -void Attr::setValue(const AtomicString& value, ExceptionCode&) +void Attr::setValue(const String& v, ExceptionCode&) { m_ignoreChildrenChanged++; removeChildren(); - m_attribute->setValue(value); + m_attribute->setValue(v.impl()); createTextChild(); m_ignoreChildrenChanged--; @@ -127,7 +120,7 @@ void Attr::setNodeValue(const String& v, ExceptionCode& ec) PassRefPtr<Node> Attr::cloneNode(bool /*deep*/) { - RefPtr<Attr> clone = adoptRef(new Attr(0, document(), m_attribute->clone())); + RefPtr<Attr> clone = new Attr(0, document(), m_attribute->clone()); cloneChildNodes(clone.get()); return clone.release(); } diff --git a/WebCore/dom/Attr.h b/WebCore/dom/Attr.h index e927a6e..ed4dc07 100644 --- a/WebCore/dom/Attr.h +++ b/WebCore/dom/Attr.h @@ -3,7 +3,7 @@ * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Peter Kelly (pmk@post.com) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -39,47 +39,48 @@ namespace WebCore { class Attr : public ContainerNode { friend class NamedNodeMap; public: - static PassRefPtr<Attr> create(Element*, Document*, PassRefPtr<Attribute>); - virtual ~Attr(); + Attr(Element*, Document*, PassRefPtr<Attribute>); + ~Attr(); + // Call this after calling the constructor so the + // Attr node isn't floating when we append the text node. + void createTextChild(); + + // DOM methods & attributes for Attr String name() const { return qualifiedName().toString(); } bool specified() const { return m_specified; } Element* ownerElement() const { return m_element; } - const AtomicString& value() const { return m_attribute->value(); } - void setValue(const AtomicString&, ExceptionCode&); - - Attribute* attr() const { return m_attribute.get(); } - const QualifiedName& qualifiedName() const { return m_attribute->name(); } - - // An extension to get presentational information for attributes. - CSSStyleDeclaration* style() { return m_attribute->style(); } - - void setSpecified(bool specified) { m_specified = specified; } - -private: - Attr(Element*, Document*, PassRefPtr<Attribute>); - - void createTextChild(); + String value() const { return m_attribute->value(); } + void setValue(const String&, ExceptionCode&); + // DOM methods overridden from parent classes virtual String nodeName() const; virtual NodeType nodeType() const; - const AtomicString& localName() const; const AtomicString& namespaceURI() const; const AtomicString& prefix() const; - virtual void setPrefix(const AtomicString&, ExceptionCode&); virtual String nodeValue() const; virtual void setNodeValue(const String&, ExceptionCode&); virtual PassRefPtr<Node> cloneNode(bool deep); + // Other methods (not part of DOM) virtual bool isAttributeNode() const { return true; } virtual bool childTypeAllowed(NodeType); virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + Attribute* attr() const { return m_attribute.get(); } + const QualifiedName& qualifiedName() const { return m_attribute->name(); } + + // An extension to get presentational information for attributes. + CSSStyleDeclaration* style() { return m_attribute->style(); } + + void setSpecified(bool specified) { m_specified = specified; } + +private: virtual const AtomicString& virtualPrefix() const { return prefix(); } virtual const AtomicString& virtualLocalName() const { return localName(); } virtual const AtomicString& virtualNamespaceURI() const { return namespaceURI(); } diff --git a/WebCore/dom/Attribute.cpp b/WebCore/dom/Attribute.cpp index 0ab0bb6..048ac6a 100644 --- a/WebCore/dom/Attribute.cpp +++ b/WebCore/dom/Attribute.cpp @@ -37,8 +37,10 @@ PassRefPtr<Attribute> Attribute::clone() const PassRefPtr<Attr> Attribute::createAttrIfNeeded(Element* e) { RefPtr<Attr> r = m_impl; - if (!r) - r = Attr::create(e, e->document(), this); + if (!r) { + r = new Attr(e, e->document(), this); + r->createTextChild(); + } return r.release(); } diff --git a/WebCore/dom/CDATASection.cpp b/WebCore/dom/CDATASection.cpp index d73054e..72faa70 100644 --- a/WebCore/dom/CDATASection.cpp +++ b/WebCore/dom/CDATASection.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -26,14 +26,13 @@ namespace WebCore { -inline CDATASection::CDATASection(Document* document, const String& data) - : Text(document, data) +CDATASection::CDATASection(Document* document, const String& text) + : Text(document, text) { } -PassRefPtr<CDATASection> CDATASection::create(Document* document, const String& data) +CDATASection::~CDATASection() { - return adoptRef(new CDATASection(document, data)); } String CDATASection::nodeName() const @@ -48,17 +47,19 @@ Node::NodeType CDATASection::nodeType() const PassRefPtr<Node> CDATASection::cloneNode(bool /*deep*/) { - return create(document(), data()); + return new CDATASection(document(), m_data); } +// DOM Section 1.1.1 bool CDATASection::childTypeAllowed(NodeType) { return false; } -PassRefPtr<Text> CDATASection::virtualCreate(const String& data) +PassRefPtr<Text> CDATASection::createNew(PassRefPtr<StringImpl> string) { - return create(document(), data); + return new CDATASection(document(), string); } + } // namespace WebCore diff --git a/WebCore/dom/CDATASection.h b/WebCore/dom/CDATASection.h index 5cf07e1..8b7df9d 100644 --- a/WebCore/dom/CDATASection.h +++ b/WebCore/dom/CDATASection.h @@ -1,7 +1,9 @@ /* + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,16 +31,16 @@ namespace WebCore { class CDATASection : public Text { public: - static PassRefPtr<CDATASection> create(Document*, const String&); - -private: CDATASection(Document*, const String&); + virtual ~CDATASection(); virtual String nodeName() const; virtual NodeType nodeType() const; virtual PassRefPtr<Node> cloneNode(bool deep); virtual bool childTypeAllowed(NodeType); - virtual PassRefPtr<Text> virtualCreate(const String&); + +protected: + virtual PassRefPtr<Text> createNew(PassRefPtr<StringImpl>); }; } // namespace WebCore diff --git a/WebCore/dom/CharacterData.cpp b/WebCore/dom/CharacterData.cpp index 902b7ff..9a72de9 100644 --- a/WebCore/dom/CharacterData.cpp +++ b/WebCore/dom/CharacterData.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,11 +30,20 @@ namespace WebCore { -CharacterData::CharacterData(Document* document, const String& text, ConstructionType type) - : Node(document, type) - , m_data(text.impl() ? text.impl() : StringImpl::empty()) +CharacterData::CharacterData(Document *doc, bool isText) + : Node(doc, false, false, isText) + , m_data(StringImpl::empty()) +{ +} + +CharacterData::CharacterData(Document* document, const String& text, bool isText) + : Node(document, false, false, isText) +{ + m_data = text.impl() ? text.impl() : StringImpl::empty(); +} + +CharacterData::~CharacterData() { - ASSERT(type == CreateOther || type == CreateText); } void CharacterData::setData(const String& data, ExceptionCode&) diff --git a/WebCore/dom/CharacterData.h b/WebCore/dom/CharacterData.h index 6c31933..d9e55c0 100644 --- a/WebCore/dom/CharacterData.h +++ b/WebCore/dom/CharacterData.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,6 +29,12 @@ namespace WebCore { class CharacterData : public Node { public: + CharacterData(Document*, const String& text, bool isText = false); + CharacterData(Document*, bool isText = false); + virtual ~CharacterData(); + + // DOM methods & attributes for CharacterData + String data() const { return m_data; } void setData(const String&, ExceptionCode&); unsigned length() const { return m_data->length(); } @@ -36,30 +42,31 @@ public: void appendData(const String&, ExceptionCode&); void insertData(unsigned offset, const String&, ExceptionCode&); void deleteData(unsigned offset, unsigned count, ExceptionCode&); - void replaceData(unsigned offset, unsigned count, const String&, ExceptionCode&); + void replaceData(unsigned offset, unsigned count, const String &arg, ExceptionCode&); bool containsOnlyWhitespace() const; - StringImpl* dataImpl() { return m_data.get(); } - -protected: - CharacterData(Document*, const String&, ConstructionType); - - virtual bool rendererIsNeeded(RenderStyle*); - - void setDataImpl(PassRefPtr<StringImpl> impl) { m_data = impl; } - void dispatchModifiedEvent(StringImpl* oldValue); + // DOM methods overridden from parent classes -private: virtual String nodeValue() const; virtual void setNodeValue(const String&, ExceptionCode&); + + // Other methods (not part of DOM) + virtual bool isCharacterDataNode() const { return true; } virtual int maxCharacterOffset() const; - virtual bool offsetInCharacters() const; + StringImpl* string() { return m_data.get(); } - void checkCharDataOperation(unsigned offset, ExceptionCode&); + virtual bool offsetInCharacters() const; + virtual bool rendererIsNeeded(RenderStyle*); +protected: RefPtr<StringImpl> m_data; + + void dispatchModifiedEvent(StringImpl* oldValue); + +private: + void checkCharDataOperation(unsigned offset, ExceptionCode&); }; } // namespace WebCore diff --git a/WebCore/dom/Comment.cpp b/WebCore/dom/Comment.cpp index 3dcde38..a36a491 100644 --- a/WebCore/dom/Comment.cpp +++ b/WebCore/dom/Comment.cpp @@ -1,7 +1,9 @@ -/* +/** + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,16 +24,22 @@ #include "config.h" #include "Comment.h" +#include "Document.h" + namespace WebCore { -inline Comment::Comment(Document* document, const String& text) - : CharacterData(document, text, CreateOther) +Comment::Comment(Document* doc, const String& text) + : CharacterData(doc, text) +{ +} + +Comment::Comment(Document* doc) + : CharacterData(doc) { } -PassRefPtr<Comment> Comment::create(Document* document, const String& text) +Comment::~Comment() { - return adoptRef(new Comment(document, text)); } String Comment::nodeName() const @@ -46,9 +54,10 @@ Node::NodeType Comment::nodeType() const PassRefPtr<Node> Comment::cloneNode(bool /*deep*/) { - return create(document(), data()); + return document()->createComment(m_data); } +// DOM Section 1.1.1 bool Comment::childTypeAllowed(NodeType) { return false; diff --git a/WebCore/dom/Comment.h b/WebCore/dom/Comment.h index 680ffae..d00ba62 100644 --- a/WebCore/dom/Comment.h +++ b/WebCore/dom/Comment.h @@ -1,7 +1,9 @@ /* + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,14 +31,16 @@ namespace WebCore { class Comment : public CharacterData { public: - static PassRefPtr<Comment> create(Document*, const String&); - -private: - Comment(Document*, const String&); + Comment(Document*, const String &_text); + Comment(Document*); + virtual ~Comment(); + // DOM methods overridden from parent classes virtual String nodeName() const; virtual NodeType nodeType() const; virtual PassRefPtr<Node> cloneNode(bool deep); + + // Other methods (not part of DOM) virtual bool isCommentNode() const { return true; } virtual bool childTypeAllowed(NodeType); }; diff --git a/WebCore/dom/ContainerNode.cpp b/WebCore/dom/ContainerNode.cpp index 569756c..2d79156 100644 --- a/WebCore/dom/ContainerNode.cpp +++ b/WebCore/dom/ContainerNode.cpp @@ -869,16 +869,16 @@ static void dispatchChildInsertionEvents(Node* child, ExceptionCode& ec) ASSERT(!eventDispatchForbidden()); RefPtr<Node> c = child; - RefPtr<Document> document = child->document(); + DocPtr<Document> doc = child->document(); if (c->parentNode() && c->parentNode()->inDocument()) c->insertedIntoDocument(); else c->insertedIntoTree(true); - document->incDOMTreeVersion(); + doc->incDOMTreeVersion(); - if (c->parentNode() && document->hasListenerType(Document::DOMNODEINSERTED_LISTENER)) { + if (c->parentNode() && doc->hasListenerType(Document::DOMNODEINSERTED_LISTENER)) { ec = 0; c->dispatchMutationEvent(eventNames().DOMNodeInsertedEvent, true, c->parentNode(), String(), String(), ec); if (ec) @@ -886,28 +886,27 @@ static void dispatchChildInsertionEvents(Node* child, ExceptionCode& ec) } // dispatch the DOMNodeInsertedIntoDocument event to all descendants - if (c->inDocument() && document->hasListenerType(Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) { + if (c->inDocument() && doc->hasListenerType(Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) for (; c; c = c->traverseNextNode(child)) { ec = 0; c->dispatchMutationEvent(eventNames().DOMNodeInsertedIntoDocumentEvent, false, 0, String(), String(), ec); if (ec) return; } - } } static void dispatchChildRemovalEvents(Node* child, ExceptionCode& ec) { RefPtr<Node> c = child; - RefPtr<Document> document = child->document(); + DocPtr<Document> doc = child->document(); // update auxiliary doc info (e.g. iterators) to note that node is being removed - document->nodeWillBeRemoved(child); + doc->nodeWillBeRemoved(child); - document->incDOMTreeVersion(); + doc->incDOMTreeVersion(); // dispatch pre-removal mutation events - if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LISTENER)) { + if (c->parentNode() && doc->hasListenerType(Document::DOMNODEREMOVED_LISTENER)) { ec = 0; c->dispatchMutationEvent(eventNames().DOMNodeRemovedEvent, true, c->parentNode(), String(), String(), ec); if (ec) @@ -915,7 +914,7 @@ static void dispatchChildRemovalEvents(Node* child, ExceptionCode& ec) } // dispatch the DOMNodeRemovedFromDocument event to all descendants - if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) + if (c->inDocument() && doc->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) for (; c; c = c->traverseNextNode(child)) { ec = 0; c->dispatchMutationEvent(eventNames().DOMNodeRemovedFromDocumentEvent, false, 0, String(), String(), ec); diff --git a/WebCore/dom/ContainerNode.h b/WebCore/dom/ContainerNode.h index aa480a7..3ad932c 100644 --- a/WebCore/dom/ContainerNode.h +++ b/WebCore/dom/ContainerNode.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -38,6 +38,7 @@ namespace Private { class ContainerNode : public Node { public: + ContainerNode(Document*, bool isElement = false); virtual ~ContainerNode(); Node* firstChild() const { return m_firstChild; } @@ -73,8 +74,6 @@ public: void cloneChildNodes(ContainerNode* clone); protected: - ContainerNode(Document*, ConstructionType = CreateContainer); - static void queuePostAttachCallback(NodeCallback, Node*); void suspendPostAttachCallbacks(); void resumePostAttachCallbacks(); @@ -98,8 +97,8 @@ private: Node* m_lastChild; }; -inline ContainerNode::ContainerNode(Document* document, ConstructionType type) - : Node(document, type) +inline ContainerNode::ContainerNode(Document* document, bool isElement) + : Node(document, isElement, true) , m_firstChild(0) , m_lastChild(0) { diff --git a/WebCore/dom/DocPtr.h b/WebCore/dom/DocPtr.h new file mode 100644 index 0000000..8b50e8d --- /dev/null +++ b/WebCore/dom/DocPtr.h @@ -0,0 +1,114 @@ +/* + * This file is part of the DOM implementation for KDE. + * Copyright (C) 2005, 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef DocPtr_h +#define DocPtr_h + +namespace WebCore { + +template <class T> class DocPtr { +public: + DocPtr() : m_ptr(0) {} + DocPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->selfOnlyRef(); } + DocPtr(const DocPtr &o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->selfOnlyRef(); } + ~DocPtr() { if (T *ptr = m_ptr) ptr->selfOnlyDeref(); } + + template <class U> DocPtr(const DocPtr<U> &o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->selfOnlyRef(); } + + void resetSkippingRef(T *o) { m_ptr = o; } + + T *get() const { return m_ptr; } + + T &operator*() const { return *m_ptr; } + T *operator->() const { return m_ptr; } + + bool operator!() const { return !m_ptr; } + + // this type conversion operator allows implicit conversion to + // bool but not to other integer types + + typedef T * (DocPtr::*UnspecifiedBoolType)() const; + operator UnspecifiedBoolType() const + { + return m_ptr ? &DocPtr::get : 0; + } + + DocPtr &operator=(const DocPtr &); + DocPtr &operator=(T *); + + private: + T *m_ptr; +}; + +template <class T> DocPtr<T> &DocPtr<T>::operator=(const DocPtr<T> &o) +{ + T *optr = o.m_ptr; + if (optr) + optr->selfOnlyRef(); + if (T *ptr = m_ptr) + ptr->selfOnlyDeref(); + m_ptr = optr; + return *this; +} + +template <class T> inline DocPtr<T> &DocPtr<T>::operator=(T *optr) +{ + if (optr) + optr->selfOnlyRef(); + if (T *ptr = m_ptr) + ptr->selfOnlyDeref(); + m_ptr = optr; + return *this; +} + +template <class T> inline bool operator==(const DocPtr<T> &a, const DocPtr<T> &b) +{ + return a.get() == b.get(); +} + +template <class T> inline bool operator==(const DocPtr<T> &a, const T *b) +{ + return a.get() == b; +} + +template <class T> inline bool operator==(const T *a, const DocPtr<T> &b) +{ + return a == b.get(); +} + +template <class T> inline bool operator!=(const DocPtr<T> &a, const DocPtr<T> &b) +{ + return a.get() != b.get(); +} + +template <class T> inline bool operator!=(const DocPtr<T> &a, const T *b) +{ + return a.get() != b; +} + +template <class T> inline bool operator!=(const T *a, const DocPtr<T> &b) +{ + return a != b.get(); +} + +} // namespace WebCore + +#endif // DocPtr_h diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp index 644eb61..066cf46 100644 --- a/WebCore/dom/Document.cpp +++ b/WebCore/dom/Document.cpp @@ -107,7 +107,6 @@ #include "SegmentedString.h" #include "SelectionController.h" #include "Settings.h" -#include "SharedWorkerRepository.h" #include "StyleSheetList.h" #include "TextEvent.h" #include "TextIterator.h" @@ -362,7 +361,7 @@ Document::Document(Frame* frame, bool isXHTML) , m_containsWMLContent(false) #endif { - m_document = this; + m_document.resetSkippingRef(this); m_printing = false; @@ -432,7 +431,8 @@ void Document::removedLastRef() // want the document to be destructed until after // removeAllChildren returns, so we guard ourselves with an // extra self-only ref. - selfOnlyRef(); + + DocPtr<Document> guard(this); // We must make sure not to be retaining any of our children through // these extra pointers or we will create a reference cycle. @@ -456,8 +456,6 @@ void Document::removedLastRef() #ifndef NDEBUG m_inRemovedLastRefFunction = false; #endif - - selfOnlyDeref(); } else { #ifndef NDEBUG m_deletionHasBegun = true; @@ -484,7 +482,7 @@ Document::~Document() #endif delete m_tokenizer; - m_document = 0; + m_document.resetSkippingRef(0); delete m_styleSelector; delete m_docLoader; @@ -520,6 +518,8 @@ Document::~Document() if (m_styleSheets) m_styleSheets->documentDestroyed(); + + m_document = 0; } void Document::resetLinkColor() @@ -589,17 +589,17 @@ PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionC PassRefPtr<DocumentFragment> Document::createDocumentFragment() { - return DocumentFragment::create(document()); + return new DocumentFragment(document()); } PassRefPtr<Text> Document::createTextNode(const String& data) { - return Text::create(this, data); + return new Text(this, data); } PassRefPtr<Comment> Document::createComment(const String& data) { - return Comment::create(this, data); + return new Comment(this, data); } PassRefPtr<CDATASection> Document::createCDATASection(const String& data, ExceptionCode& ec) @@ -608,7 +608,7 @@ PassRefPtr<CDATASection> Document::createCDATASection(const String& data, Except ec = NOT_SUPPORTED_ERR; return 0; } - return CDATASection::create(this, data); + return new CDATASection(this, data); } PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const String& target, const String& data, ExceptionCode& ec) @@ -621,7 +621,7 @@ PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const St ec = NOT_SUPPORTED_ERR; return 0; } - return ProcessingInstruction::create(this, target, data); + return new ProcessingInstruction(this, target, data); } PassRefPtr<EntityReference> Document::createEntityReference(const String& name, ExceptionCode& ec) @@ -634,12 +634,12 @@ PassRefPtr<EntityReference> Document::createEntityReference(const String& name, ec = NOT_SUPPORTED_ERR; return 0; } - return EntityReference::create(this, name); + return new EntityReference(this, name); } PassRefPtr<EditingText> Document::createEditingTextNode(const String& text) { - return EditingText::create(this, text); + return new EditingText(this, text); } PassRefPtr<CSSStyleDeclaration> Document::createCSSStyleDeclaration() @@ -704,8 +704,11 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo return newElement.release(); } - case ATTRIBUTE_NODE: - return Attr::create(0, this, static_cast<Attr*>(importedNode)->attr()->clone()); + case ATTRIBUTE_NODE: { + RefPtr<Attr> newAttr = new Attr(0, this, static_cast<Attr*>(importedNode)->attr()->clone()); + newAttr->createTextChild(); + return newAttr.release(); + } case DOCUMENT_FRAGMENT_NODE: { DocumentFragment* oldFragment = static_cast<DocumentFragment*>(importedNode); RefPtr<DocumentFragment> newFragment = createDocumentFragment(); @@ -1376,11 +1379,7 @@ void Document::detach() // Send out documentWillBecomeInactive() notifications to registered elements, // in order to stop media elements documentWillBecomeInactive(); - -#if ENABLE(SHARED_WORKERS) - SharedWorkerRepository::documentDetached(this); -#endif - + if (m_frame) { FrameView* view = m_frame->view(); if (view) @@ -1501,7 +1500,7 @@ AXObjectCache* Document::axObjectCache() const return doc->axObjectCache(); // this is the top-level document, so install a new cache - m_axObjectCache = new AXObjectCache(this); + m_axObjectCache = new AXObjectCache; return m_axObjectCache; #endif // ANDROID } @@ -2661,10 +2660,10 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode) focusChangeBlocked = true; newFocusedNode = 0; } - if (oldFocusedNode == this && oldFocusedNode->hasOneRef()) + if ((oldFocusedNode.get() == this) && oldFocusedNode->hasOneRef()) return true; - if (oldFocusedNode == oldFocusedNode->rootEditableElement()) + if (oldFocusedNode.get() == oldFocusedNode->rootEditableElement()) frame()->editor()->didEndEditing(); } @@ -2693,7 +2692,7 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode) } m_focusedNode->setFocus(); - if (m_focusedNode == m_focusedNode->rootEditableElement()) + if (m_focusedNode.get() == m_focusedNode->rootEditableElement()) frame()->editor()->didBeginEditing(); // eww, I suck. set the qt focus correctly @@ -2715,7 +2714,7 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode) } } -#if (PLATFORM(MAC) || PLATFORM(WIN)) && !PLATFORM(CHROMIUM) +#if PLATFORM(MAC) && !PLATFORM(CHROMIUM) if (!focusChangeBlocked && m_focusedNode && AXObjectCache::accessibilityEnabled()) axObjectCache()->handleFocusedUIElementChanged(); #elif PLATFORM(GTK) @@ -2724,9 +2723,9 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode) RenderObject* newFocusedRenderer = 0; if (oldFocusedNode) - oldFocusedRenderer = oldFocusedNode->renderer(); + oldFocusedRenderer = oldFocusedNode.get()->renderer(); if (newFocusedNode) - newFocusedRenderer = newFocusedNode->renderer(); + newFocusedRenderer = newFocusedNode.get()->renderer(); axObjectCache()->handleFocusedUIElementChangedWithRenderers(oldFocusedRenderer, newFocusedRenderer); } @@ -3926,7 +3925,7 @@ PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S // FIXME: Assume this is a mapped attribute, since createAttribute isn't namespace-aware. There's no harm to XML // documents if we're wrong. - return Attr::create(0, this, MappedAttribute::create(qName, StringImpl::empty())); + return new Attr(0, this, MappedAttribute::create(qName, StringImpl::empty())); } #if ENABLE(SVG) diff --git a/WebCore/dom/Document.h b/WebCore/dom/Document.h index c18a864..fc4dc7e 100644 --- a/WebCore/dom/Document.h +++ b/WebCore/dom/Document.h @@ -172,16 +172,19 @@ class Document : public ContainerNode, public ScriptExecutionContext { public: static PassRefPtr<Document> create(Frame* frame) { - return adoptRef(new Document(frame, false)); + return new Document(frame, false); } static PassRefPtr<Document> createXHTML(Frame* frame) { - return adoptRef(new Document(frame, true)); + return new Document(frame, true); } virtual ~Document(); + virtual bool isDocument() const { return true; } + using ContainerNode::ref; using ContainerNode::deref; + virtual void removedLastRef(); // Nodes belonging to this document hold "self-only" references - // these are enough to keep the document from being destroyed, but @@ -211,6 +214,7 @@ public: DocumentType* doctype() const { return m_docType.get(); } DOMImplementation* implementation() const; + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); Element* documentElement() const { @@ -295,6 +299,11 @@ public: CollectionCache* nameCollectionInfo(CollectionType, const AtomicString& name); + // DOM methods overridden from parent classes + + virtual String nodeName() const; + virtual NodeType nodeType() const; + // Other methods (not part of DOM) virtual bool isHTMLDocument() const { return false; } virtual bool isImageDocument() const { return false; } @@ -446,6 +455,9 @@ public: virtual String userAgent(const KURL&) const; + // from cachedObjectClient + virtual void setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet*); + #if FRAME_LOADS_USER_STYLESHEET void setUserStyleSheet(const String& sheet); #endif @@ -462,6 +474,10 @@ public: enum ParseMode { Compat, AlmostStrict, Strict }; +private: + virtual void determineParseMode() {} + +public: void setParseMode(ParseMode m) { m_parseMode = m; } ParseMode parseMode() const { return m_parseMode; } @@ -490,6 +506,11 @@ public: MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const IntPoint&, const PlatformMouseEvent&); + virtual bool childTypeAllowed(NodeType); + virtual PassRefPtr<Node> cloneNode(bool deep); + + virtual bool canReplaceChild(Node* newChild, Node* oldChild); + StyleSheetList* styleSheets(); /* Newly proposed CSS3 mechanism for selecting alternate @@ -730,6 +751,8 @@ public: void setDocType(PassRefPtr<DocumentType>); + virtual void finishedParsing(); + #if ENABLE(XPATH) // XPathEvaluator methods PassRefPtr<XPathExpression> createExpression(const String& expression, @@ -776,6 +799,7 @@ public: HTMLCanvasElement* getCSSCanvasElement(const String& name); bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; } + void initDNSPrefetch(); void parseDNSPrefetchControlHeader(const String&); virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL); @@ -784,95 +808,10 @@ public: virtual void scriptImported(unsigned long, const String&); virtual void postTask(PassRefPtr<Task>); // Executes the task on context's thread asynchronously. - typedef HashMap<WebCore::Node*, JSNode*> JSWrapperCache; - JSWrapperCache& wrapperCache() { return m_wrapperCache; } - - virtual void finishedParsing(); - - bool inPageCache() const { return m_inPageCache; } - void setInPageCache(bool flag); - - // Elements can register themselves for the "documentWillBecomeInactive()" and - // "documentDidBecomeActive()" callbacks - void registerForDocumentActivationCallbacks(Element*); - void unregisterForDocumentActivationCallbacks(Element*); - void documentWillBecomeInactive(); - void documentDidBecomeActive(); - - void registerForMediaVolumeCallbacks(Element*); - void unregisterForMediaVolumeCallbacks(Element*); - void mediaVolumeDidChange(); - - void setShouldCreateRenderers(bool); - bool shouldCreateRenderers(); - - void setDecoder(PassRefPtr<TextResourceDecoder>); - TextResourceDecoder* decoder() const { return m_decoder.get(); } - - String displayStringModifiedByEncoding(const String&) const; - PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const; - void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const; - - // Quirk for the benefit of Apple's Dictionary application. - void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; } - bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; } - -#if ENABLE(DASHBOARD_SUPPORT) - void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; } - bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; } - bool hasDashboardRegions () const { return m_hasDashboardRegions; } - void setHasDashboardRegions(bool f) { m_hasDashboardRegions = f; } - const Vector<DashboardRegionValue>& dashboardRegions() const; - void setDashboardRegions(const Vector<DashboardRegionValue>&); -#endif - - void removeAllEventListeners(); - - void registerDisconnectedNodeWithEventListeners(Node*); - void unregisterDisconnectedNodeWithEventListeners(Node*); - - CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } - -#if ENABLE(SVG) - const SVGDocumentExtensions* svgExtensions(); - SVGDocumentExtensions* accessSVGExtensions(); -#endif - - void initSecurityContext(); - - // Explicitly override the security origin for this document. - // Note: It is dangerous to change the security origin of a document - // that already contains content. - void setSecurityOrigin(SecurityOrigin*); - - bool processingLoadEvent() const { return m_processingLoadEvent; } - -#if ENABLE(DATABASE) - void addOpenDatabase(Database*); - void removeOpenDatabase(Database*); - DatabaseThread* databaseThread(); // Creates the thread as needed, but not if it has been already terminated. - void setHasOpenDatabases() { m_hasOpenDatabases = true; } - bool hasOpenDatabases() { return m_hasOpenDatabases; } - void stopDatabases(); -#endif - - void setUsingGeolocation(bool f) { m_usingGeolocation = f; } - bool usingGeolocation() const { return m_usingGeolocation; }; - -#if ENABLE(WML) - void setContainsWMLContent(bool value) { m_containsWMLContent = value; } - bool containsWMLContent() const { return m_containsWMLContent; } - - void resetWMLPageState(); - void initializeWMLPageState(); -#endif - protected: Document(Frame*, bool isXHTML); - void setStyleSelector(CSSStyleSelector* styleSelector) { m_styleSelector = styleSelector; } - - void clearXMLVersion() { m_xmlVersion = String(); } + void setStyleSelector(CSSStyleSelector* styleSelector) { m_styleSelector = styleSelector; } #if ENABLE(TOUCH_EVENTS) // Android public: @@ -887,38 +826,16 @@ private: #endif // ENABLE(TOUCH_EVENTS) private: - virtual bool isDocument() const { return true; } - virtual void removedLastRef(); - virtual void determineParseMode() { } - - virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); - - virtual String nodeName() const; - virtual NodeType nodeType() const; - virtual void setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet*); - virtual bool childTypeAllowed(NodeType); - virtual PassRefPtr<Node> cloneNode(bool deep); - virtual bool canReplaceChild(Node* newChild, Node* oldChild); - virtual void refScriptExecutionContext() { ref(); } virtual void derefScriptExecutionContext() { deref(); } virtual const KURL& virtualURL() const; // Same as url(), but needed for ScriptExecutionContext to implement it without a performance loss for direct calls. virtual KURL virtualCompleteURL(const String&) const; // Same as completeURL() for the same reason as above. - void initDNSPrefetch(); - String encoding() const; void executeScriptSoonTimerFired(Timer<Document>*); - void updateTitle(); - void removeAllDisconnectedNodeEventListeners(); - void updateFocusAppearanceTimerFired(Timer<Document>*); - void updateBaseURL(); - - void cacheDocumentElement() const; - CSSStyleSelector* m_styleSelector; bool m_didCalculateStyleSelector; @@ -1071,6 +988,96 @@ private: bool m_shouldProcessNoScriptElement; #endif +public: + bool inPageCache() const { return m_inPageCache; } + void setInPageCache(bool flag); + + // Elements can register themselves for the "documentWillBecomeInactive()" and + // "documentDidBecomeActive()" callbacks + void registerForDocumentActivationCallbacks(Element*); + void unregisterForDocumentActivationCallbacks(Element*); + void documentWillBecomeInactive(); + void documentDidBecomeActive(); + + void registerForMediaVolumeCallbacks(Element*); + void unregisterForMediaVolumeCallbacks(Element*); + void mediaVolumeDidChange(); + + void setShouldCreateRenderers(bool); + bool shouldCreateRenderers(); + + void setDecoder(PassRefPtr<TextResourceDecoder>); + TextResourceDecoder* decoder() const { return m_decoder.get(); } + + String displayStringModifiedByEncoding(const String&) const; + PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const; + void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const; + + // Quirk for the benefit of Apple's Dictionary application. + void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; } + bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; } + +#if ENABLE(DASHBOARD_SUPPORT) + void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; } + bool dashboardRegionsDirty() const { return m_dashboardRegionsDirty; } + bool hasDashboardRegions () const { return m_hasDashboardRegions; } + void setHasDashboardRegions(bool f) { m_hasDashboardRegions = f; } + const Vector<DashboardRegionValue>& dashboardRegions() const; + void setDashboardRegions(const Vector<DashboardRegionValue>&); +#endif + + void removeAllEventListeners(); + + void registerDisconnectedNodeWithEventListeners(Node*); + void unregisterDisconnectedNodeWithEventListeners(Node*); + + CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } + +#if ENABLE(SVG) + const SVGDocumentExtensions* svgExtensions(); + SVGDocumentExtensions* accessSVGExtensions(); +#endif + + void initSecurityContext(); + + // Explicitly override the security origin for this document. + // Note: It is dangerous to change the security origin of a document + // that already contains content. + void setSecurityOrigin(SecurityOrigin*); + + bool processingLoadEvent() const { return m_processingLoadEvent; } + +#if ENABLE(DATABASE) + void addOpenDatabase(Database*); + void removeOpenDatabase(Database*); + DatabaseThread* databaseThread(); // Creates the thread as needed, but not if it has been already terminated. + void setHasOpenDatabases() { m_hasOpenDatabases = true; } + bool hasOpenDatabases() { return m_hasOpenDatabases; } + void stopDatabases(); +#endif + + void setUsingGeolocation(bool f) { m_usingGeolocation = f; } + bool usingGeolocation() const { return m_usingGeolocation; }; + +#if ENABLE(WML) + void setContainsWMLContent(bool value) { m_containsWMLContent = value; } + bool containsWMLContent() const { return m_containsWMLContent; } + + void resetWMLPageState(); + void initializeWMLPageState(); +#endif + +protected: + void clearXMLVersion() { m_xmlVersion = String(); } + +private: + void updateTitle(); + void removeAllDisconnectedNodeEventListeners(); + void updateFocusAppearanceTimerFired(Timer<Document>*); + void updateBaseURL(); + + void cacheDocumentElement() const; + RenderObject* m_savedRenderer; int m_secureForms; @@ -1124,6 +1131,10 @@ private: unsigned m_numNodeListCaches; +public: + typedef HashMap<WebCore::Node*, JSNode*> JSWrapperCache; + JSWrapperCache& wrapperCache() { return m_wrapperCache; } +private: JSWrapperCache m_wrapperCache; #if ENABLE(DATABASE) @@ -1152,7 +1163,7 @@ inline bool Document::hasElementWithId(AtomicStringImpl* id) const inline bool Node::isDocumentNode() const { - return this == m_document; + return this == m_document.get(); } } // namespace WebCore diff --git a/WebCore/dom/DocumentFragment.cpp b/WebCore/dom/DocumentFragment.cpp index 3663e99..7a6174f 100644 --- a/WebCore/dom/DocumentFragment.cpp +++ b/WebCore/dom/DocumentFragment.cpp @@ -1,8 +1,10 @@ -/* +/** + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,18 +23,13 @@ */ #include "config.h" + #include "DocumentFragment.h" namespace WebCore { -inline DocumentFragment::DocumentFragment(Document* document) - : ContainerNode(document) -{ -} - -PassRefPtr<DocumentFragment> DocumentFragment::create(Document* document) +DocumentFragment::DocumentFragment(Document *doc) : ContainerNode(doc) { - return adoptRef(new DocumentFragment(document)); } String DocumentFragment::nodeName() const @@ -45,6 +42,7 @@ Node::NodeType DocumentFragment::nodeType() const return DOCUMENT_FRAGMENT_NODE; } +// DOM Section 1.1.1 bool DocumentFragment::childTypeAllowed(NodeType type) { switch (type) { @@ -62,7 +60,7 @@ bool DocumentFragment::childTypeAllowed(NodeType type) PassRefPtr<Node> DocumentFragment::cloneNode(bool deep) { - RefPtr<DocumentFragment> clone = create(document()); + RefPtr<DocumentFragment> clone = new DocumentFragment(document()); if (deep) cloneChildNodes(clone.get()); return clone.release(); diff --git a/WebCore/dom/DocumentFragment.h b/WebCore/dom/DocumentFragment.h index e624ee4..46d8ecd 100644 --- a/WebCore/dom/DocumentFragment.h +++ b/WebCore/dom/DocumentFragment.h @@ -1,8 +1,10 @@ /* + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,9 +32,6 @@ namespace WebCore { class DocumentFragment : public ContainerNode { public: - static PassRefPtr<DocumentFragment> create(Document*); - -private: DocumentFragment(Document*); virtual String nodeName() const; diff --git a/WebCore/dom/DocumentType.cpp b/WebCore/dom/DocumentType.cpp index b8185e7..885a65b 100644 --- a/WebCore/dom/DocumentType.cpp +++ b/WebCore/dom/DocumentType.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,11 +29,11 @@ namespace WebCore { -DocumentType::DocumentType(Document* document, const String& name, const String& publicId, const String& systemId) - : Node(document, CreateOther) - , m_name(name) - , m_publicId(publicId) - , m_systemId(systemId) +DocumentType::DocumentType(Document* document, const String& n, const String& p, const String& s) + : Node(document) + , m_name(n) + , m_publicId(p) + , m_systemId(s) { } @@ -54,7 +54,7 @@ Node::NodeType DocumentType::nodeType() const PassRefPtr<Node> DocumentType::cloneNode(bool /*deep*/) { - return create(document(), m_name, m_publicId, m_systemId); + return new DocumentType(document(), m_name, m_publicId, m_systemId); } void DocumentType::insertedIntoDocument() diff --git a/WebCore/dom/DocumentType.h b/WebCore/dom/DocumentType.h index 4f89d01..9fd3c6e 100644 --- a/WebCore/dom/DocumentType.h +++ b/WebCore/dom/DocumentType.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -34,7 +34,7 @@ class DocumentType : public Node { public: static PassRefPtr<DocumentType> create(Document* document, const String& name, const String& publicId, const String& systemId) { - return adoptRef(new DocumentType(document, name, publicId, systemId)); + return new DocumentType(document, name, publicId, systemId); } NamedNodeMap* entities() const { return m_entities.get(); } diff --git a/WebCore/dom/EditingText.cpp b/WebCore/dom/EditingText.cpp index b36931a..40cf97d 100644 --- a/WebCore/dom/EditingText.cpp +++ b/WebCore/dom/EditingText.cpp @@ -1,5 +1,9 @@ -/* - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. +/** + * This file is part of the DOM implementation for KDE. + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,19 +24,24 @@ #include "config.h" #include "EditingText.h" -// FIXME: Does this really require a class? Perhaps instead any text node -// inside an editable element could have the "always create a renderer" behavior. +// FIXME: does this really require a class? Perhaps any Text node +// inside an editable element should have the "always create a renderer" +// behavior. namespace WebCore { -inline EditingText::EditingText(Document* document, const String& data) - : Text(document, data) +EditingText::EditingText(Document *impl, const String &text) + : Text(impl, text) +{ +} + +EditingText::EditingText(Document *impl) + : Text(impl) { } -PassRefPtr<EditingText> EditingText::create(Document* document, const String& data) +EditingText::~EditingText() { - return adoptRef(new EditingText(document, data)); } bool EditingText::rendererIsNeeded(RenderStyle*) diff --git a/WebCore/dom/EditingText.h b/WebCore/dom/EditingText.h index 08223c2..e114786 100644 --- a/WebCore/dom/EditingText.h +++ b/WebCore/dom/EditingText.h @@ -1,5 +1,9 @@ /* - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. + * This file is part of the DOM implementation for KDE. + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,12 +31,11 @@ namespace WebCore { class EditingText : public Text { public: - static PassRefPtr<EditingText> create(Document*, const String&); + EditingText(Document *impl, const String &text); + EditingText(Document *impl); + virtual ~EditingText(); -private: virtual bool rendererIsNeeded(RenderStyle *); - - EditingText(Document*, const String&); }; } // namespace WebCore diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp index 7aee10c..1956be4 100644 --- a/WebCore/dom/Element.cpp +++ b/WebCore/dom/Element.cpp @@ -57,8 +57,8 @@ namespace WebCore { using namespace HTMLNames; using namespace XMLNames; -Element::Element(const QualifiedName& tagName, Document* document) - : ContainerNode(document, CreateElementZeroRefCount) +Element::Element(const QualifiedName& tagName, Document* doc) + : ContainerNode(doc, true) , m_tagName(tagName) { } diff --git a/WebCore/dom/Element.h b/WebCore/dom/Element.h index 6aa6312..223c26a 100644 --- a/WebCore/dom/Element.h +++ b/WebCore/dom/Element.h @@ -3,7 +3,7 @@ * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Peter Kelly (pmk@post.com) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -42,7 +42,7 @@ class IntSize; class Element : public ContainerNode { public: Element(const QualifiedName&, Document*); - virtual ~Element(); + ~Element(); const AtomicString& getIDAttribute() const; bool hasAttribute(const QualifiedName&) const; @@ -64,6 +64,7 @@ public: void scrollIntoView(bool alignToTop = true); void scrollIntoViewIfNeeded(bool centerIfNeeded = true); + void scrollByUnits(int units, ScrollGranularity); void scrollByLines(int lines); void scrollByPages(int pages); @@ -107,11 +108,17 @@ public: const AtomicString& localName() const { return m_tagName.localName(); } const AtomicString& prefix() const { return m_tagName.prefix(); } + virtual void setPrefix(const AtomicString&, ExceptionCode&); const AtomicString& namespaceURI() const { return m_tagName.namespaceURI(); } virtual KURL baseURI() const; + // DOM methods overridden from parent classes + virtual NodeType nodeType() const; virtual String nodeName() const; + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); PassRefPtr<Element> cloneElementWithChildren(); PassRefPtr<Element> cloneElementWithoutChildren(); @@ -129,9 +136,13 @@ public: // This method is called whenever an attribute is added, changed or removed. virtual void attributeChanged(Attribute*, bool preserveDecls = false); + // The implementation of Element::attributeChanged() calls the following two functions. + // They are separated to allow a different flow of control in StyledElement::attributeChanged(). + void recalcStyleIfNeededAfterAttributeChanged(Attribute*); + void updateAfterAttributeChanged(Attribute*); + // not part of the DOM void setAttributeMap(PassRefPtr<NamedNodeMap>); - NamedNodeMap* attributeMap() const { return namedAttrMap.get(); } virtual void copyNonAttributeProperties(const Element* /*source*/) { } @@ -142,6 +153,10 @@ public: virtual RenderStyle* computedStyle(); + virtual bool childTypeAllowed(NodeType); + + virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value); + void dispatchAttrRemovalEvent(Attribute*); void dispatchAttrAdditionEvent(Attribute*); @@ -155,6 +170,12 @@ public: virtual void updateFocusAppearance(bool restorePreviousSelection); void blur(); +#ifndef NDEBUG + virtual void formatForDebugger(char* buffer, unsigned length) const; +#endif + + bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle); + String innerText() const; String outerText() const; @@ -185,13 +206,13 @@ public: Element* nextElementSibling() const; unsigned childElementCount() const; + // FormControlElement API virtual bool isFormControlElement() const { return false; } virtual bool isEnabledFormControl() const { return true; } virtual bool isReadOnlyFormControl() const { return false; } virtual bool isTextFormControl() const { return false; } virtual bool isOptionalFormControl() const { return false; } virtual bool isRequiredFormControl() const { return false; } - virtual bool isDefaultButtonForForm() const { return false; } virtual bool formControlValueMatchesRenderer() const { return false; } virtual void setFormControlValueMatchesRenderer(bool) { } @@ -204,37 +225,13 @@ public: virtual void dispatchFormControlChangeEvent() { } -protected: - virtual void insertedIntoDocument(); - virtual void removedFromDocument(); - virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); - - // The implementation of Element::attributeChanged() calls the following two functions. - // They are separated to allow a different flow of control in StyledElement::attributeChanged(). - void recalcStyleIfNeededAfterAttributeChanged(Attribute*); - void updateAfterAttributeChanged(Attribute*); - private: - void scrollByUnits(int units, ScrollGranularity); - - virtual void setPrefix(const AtomicString&, ExceptionCode&); - virtual NodeType nodeType() const; - virtual bool childTypeAllowed(NodeType); - - virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value); - -#ifndef NDEBUG - virtual void formatForDebugger(char* buffer, unsigned length) const; -#endif - - bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle); - virtual void createAttributeMap() const; - virtual void updateStyleAttribute() const { } + virtual void updateStyleAttribute() const {} #if ENABLE(SVG) - virtual void updateAnimatedSVGAttribute(const String&) const { } + virtual void updateAnimatedSVGAttribute(const String&) const {} #endif void updateFocusAppearanceSoonAfterAttach(); @@ -251,10 +248,10 @@ private: QualifiedName m_tagName; virtual NodeRareData* createRareData(); +protected: ElementRareData* rareData() const; ElementRareData* ensureRareData(); -protected: mutable RefPtr<NamedNodeMap> namedAttrMap; }; diff --git a/WebCore/dom/Element.idl b/WebCore/dom/Element.idl index 16aac84..53711e9 100644 --- a/WebCore/dom/Element.idl +++ b/WebCore/dom/Element.idl @@ -21,7 +21,6 @@ module core { interface [ - CustomMarkFunction, GenerateConstructor, GenerateNativeConverter, InlineGetOwnPropertySlot, diff --git a/WebCore/dom/EntityReference.cpp b/WebCore/dom/EntityReference.cpp index c4c292a..012605c 100644 --- a/WebCore/dom/EntityReference.cpp +++ b/WebCore/dom/EntityReference.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2000 Peter Kelly (pmk@post.com) - * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,17 +23,12 @@ namespace WebCore { -inline EntityReference::EntityReference(Document* document, const String& entityName) +EntityReference::EntityReference(Document* document, const String& entityName) : ContainerNode(document) , m_entityName(entityName) { } -PassRefPtr<EntityReference> EntityReference::create(Document* document, const String& entityName) -{ - return adoptRef(new EntityReference(document, entityName)); -} - String EntityReference::nodeName() const { return m_entityName; @@ -46,7 +41,7 @@ Node::NodeType EntityReference::nodeType() const PassRefPtr<Node> EntityReference::cloneNode(bool) { - return create(document(), m_entityName); + return new EntityReference(document(), m_entityName); } } // namespace diff --git a/WebCore/dom/EntityReference.h b/WebCore/dom/EntityReference.h index 7a6f6c3..4767a5e 100644 --- a/WebCore/dom/EntityReference.h +++ b/WebCore/dom/EntityReference.h @@ -28,15 +28,13 @@ namespace WebCore { class EntityReference : public ContainerNode { public: - static PassRefPtr<EntityReference> create(Document*, const String& entityName); - -private: EntityReference(Document*, const String& entityName); virtual String nodeName() const; virtual NodeType nodeType() const; virtual PassRefPtr<Node> cloneNode(bool deep); +private: String m_entityName; }; diff --git a/WebCore/dom/EventNames.h b/WebCore/dom/EventNames.h index 18c4240..d28b154 100644 --- a/WebCore/dom/EventNames.h +++ b/WebCore/dom/EventNames.h @@ -73,7 +73,6 @@ namespace WebCore { macro(obsolete) \ macro(offline) \ macro(online) \ - macro(open) \ macro(overflowchanged) \ macro(paste) \ macro(readystatechange) \ diff --git a/WebCore/dom/EventTarget.cpp b/WebCore/dom/EventTarget.cpp index 2f13da8..7ba0584 100644 --- a/WebCore/dom/EventTarget.cpp +++ b/WebCore/dom/EventTarget.cpp @@ -44,11 +44,6 @@ EventTarget::~EventTarget() { } -EventSource* EventTarget::toEventSource() -{ - return 0; -} - Node* EventTarget::toNode() { return 0; @@ -111,13 +106,6 @@ SharedWorkerContext* EventTarget::toSharedWorkerContext() } #endif -#if ENABLE(NOTIFICATIONS) -Notification* EventTarget::toNotification() -{ - return 0; -} -#endif - #ifndef NDEBUG void forbidEventDispatch() { diff --git a/WebCore/dom/EventTarget.h b/WebCore/dom/EventTarget.h index 6d3cb7c..2ededda 100644 --- a/WebCore/dom/EventTarget.h +++ b/WebCore/dom/EventTarget.h @@ -43,10 +43,8 @@ namespace WebCore { class DOMWindow; class Event; class EventListener; - class EventSource; class MessagePort; class Node; - class Notification; class SVGElementInstance; class ScriptExecutionContext; class SharedWorker; @@ -59,7 +57,6 @@ namespace WebCore { class EventTarget { public: - virtual EventSource* toEventSource(); virtual MessagePort* toMessagePort(); virtual Node* toNode(); virtual DOMWindow* toDOMWindow(); @@ -81,10 +78,6 @@ namespace WebCore { virtual SharedWorkerContext* toSharedWorkerContext(); #endif -#if ENABLE(NOTIFICATIONS) - virtual Notification* toNotification(); -#endif - virtual ScriptExecutionContext* scriptExecutionContext() const = 0; virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) = 0; diff --git a/WebCore/dom/Node.cpp b/WebCore/dom/Node.cpp index 819f908..18655c6 100644 --- a/WebCore/dom/Node.cpp +++ b/WebCore/dom/Node.cpp @@ -337,69 +337,8 @@ Node::StyleChange Node::diff(const RenderStyle* s1, const RenderStyle* s2) return ch; } -inline bool Node::initialRefCount(ConstructionType type) -{ - switch (type) { - case CreateContainer: - case CreateElement: - case CreateOther: - case CreateText: - return 1; - case CreateElementZeroRefCount: - return 0; - } - ASSERT_NOT_REACHED(); - return 1; -} - -inline bool Node::isContainer(ConstructionType type) -{ - switch (type) { - case CreateContainer: - case CreateElement: - case CreateElementZeroRefCount: - return true; - case CreateOther: - case CreateText: - return false; - } - ASSERT_NOT_REACHED(); - return false; -} - -inline bool Node::isElement(ConstructionType type) -{ - switch (type) { - case CreateContainer: - case CreateOther: - case CreateText: - return false; - case CreateElement: - case CreateElementZeroRefCount: - return true; - } - ASSERT_NOT_REACHED(); - return false; -} - -inline bool Node::isText(ConstructionType type) -{ - switch (type) { - case CreateContainer: - case CreateElement: - case CreateElementZeroRefCount: - case CreateOther: - return false; - case CreateText: - return true; - } - ASSERT_NOT_REACHED(); - return false; -} - -Node::Node(Document* document, ConstructionType type) - : TreeShared<Node>(initialRefCount(type)) - , m_document(document) +Node::Node(Document* doc, bool isElement, bool isContainer, bool isText) + : m_document(doc) , m_previous(0) , m_next(0) , m_renderer(0) @@ -416,27 +355,25 @@ Node::Node(Document* document, ConstructionType type) , m_inDetach(false) , m_inSubtreeMark(false) , m_hasRareData(false) - , m_isElement(isElement(type)) - , m_isContainer(isContainer(type)) - , m_isText(isText(type)) + , m_isElement(isElement) + , m_isContainer(isContainer) + , m_isText(isText) , m_parsingChildrenFinished(true) +#if ENABLE(SVG) + , m_areSVGAttributesValid(true) +#endif , m_isStyleAttributeValid(true) , m_synchronizingStyleAttribute(false) #if ENABLE(SVG) - , m_areSVGAttributesValid(true) , m_synchronizingSVGAttributes(false) #endif { - if (m_document) - m_document->selfOnlyRef(); - #ifndef NDEBUG if (shouldIgnoreLeaks) ignoreSet.add(this); else nodeCounter.increment(); #endif - #if DUMP_NODE_STATISTICS liveNodeSet.add(this); #endif @@ -479,9 +416,6 @@ Node::~Node() m_previous->setNextSibling(0); if (m_next) m_next->setPreviousSibling(0); - - if (m_document) - m_document->selfOnlyDeref(); } #ifdef NDEBUG @@ -516,19 +450,14 @@ void Node::setDocument(Document* document) if (inDocument() || m_document == document) return; - document->selfOnlyRef(); - setWillMoveToNewOwnerDocumentWasCalled(false); willMoveToNewOwnerDocument(); ASSERT(willMoveToNewOwnerDocumentWasCalled); #if USE(JSC) - updateDOMNodeDocument(this, m_document, document); + updateDOMNodeDocument(this, m_document.get(), document); #endif - if (m_document) - m_document->selfOnlyDeref(); - m_document = document; setDidMoveToNewOwnerDocumentWasCalled(false); @@ -1971,11 +1900,11 @@ void Node::appendTextContent(bool convertBRsToNewlines, StringBuilder& content) case TEXT_NODE: case CDATA_SECTION_NODE: case COMMENT_NODE: - content.append(static_cast<const CharacterData*>(this)->data()); + content.append(static_cast<const CharacterData*>(this)->CharacterData::nodeValue()); break; case PROCESSING_INSTRUCTION_NODE: - content.append(static_cast<const ProcessingInstruction*>(this)->data()); + content.append(static_cast<const ProcessingInstruction*>(this)->ProcessingInstruction::nodeValue()); break; case ELEMENT_NODE: diff --git a/WebCore/dom/Node.h b/WebCore/dom/Node.h index d1f58dc..f10e830 100644 --- a/WebCore/dom/Node.h +++ b/WebCore/dom/Node.h @@ -25,6 +25,7 @@ #ifndef Node_h #define Node_h +#include "DocPtr.h" #include "EventTarget.h" #include "KURLHash.h" #include "PlatformString.h" @@ -107,6 +108,7 @@ public: enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force }; static StyleChange diff(const RenderStyle*, const RenderStyle*); + Node(Document*, bool isElement = false, bool isContainer = false, bool isText = false); virtual ~Node(); // DOM methods & attributes for Node @@ -314,7 +316,7 @@ public: { ASSERT(this); ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument())); - return m_document; + return m_document.get(); } void setDocument(Document*); @@ -671,35 +673,14 @@ public: using TreeShared<Node>::ref; using TreeShared<Node>::deref; - -protected: - // CreateElementZeroRefCount is deprecated and can be removed once we convert all element - // classes to start with a reference count of 1. - enum ConstructionType { CreateContainer, CreateElement, CreateOther, CreateText, CreateElementZeroRefCount }; - Node(Document*, ConstructionType); - - virtual void willMoveToNewOwnerDocument(); - virtual void didMoveToNewOwnerDocument(); - - virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { } - void setTabIndexExplicitly(short); - - bool hasRareData() const { return m_hasRareData; } - - NodeRareData* rareData() const; - NodeRareData* ensureRareData(); - + private: - static bool initialRefCount(ConstructionType); - static bool isContainer(ConstructionType); - static bool isElement(ConstructionType); - static bool isText(ConstructionType); - virtual void refEventTarget() { ref(); } virtual void derefEventTarget() { deref(); } void removeAllEventListenersSlowCase(); +private: virtual NodeRareData* createRareData(); Node* containerChildNode(unsigned index) const; unsigned containerChildNodeCount() const; @@ -717,7 +698,7 @@ private: void appendTextContent(bool convertBRsToNewlines, StringBuilder&) const; - Document* m_document; + DocPtr<Document> m_document; Node* m_previous; Node* m_next; RenderObject* m_renderer; @@ -740,16 +721,22 @@ private: const bool m_isText : 1; protected: - // These bits are used by derived classes, pulled up here so they can + // These bits are used by the Element derived class, pulled up here so they can // be stored in the same memory word as the Node bits above. + bool m_parsingChildrenFinished : 1; +#if ENABLE(SVG) + mutable bool m_areSVGAttributesValid : 1; +#endif - bool m_parsingChildrenFinished : 1; // Element - mutable bool m_isStyleAttributeValid : 1; // StyledElement - mutable bool m_synchronizingStyleAttribute : 1; // StyledElement + // These bits are used by the StyledElement derived class, and live here for the + // same reason as above. + mutable bool m_isStyleAttributeValid : 1; + mutable bool m_synchronizingStyleAttribute : 1; #if ENABLE(SVG) - mutable bool m_areSVGAttributesValid : 1; // Element - mutable bool m_synchronizingSVGAttributes : 1; // SVGElement + // This bit is used by the SVGElement derived class, and lives here for the same + // reason as above. + mutable bool m_synchronizingSVGAttributes : 1; #endif // 11 bits remaining diff --git a/WebCore/dom/Notation.cpp b/WebCore/dom/Notation.cpp index cade384..7081d98 100644 --- a/WebCore/dom/Notation.cpp +++ b/WebCore/dom/Notation.cpp @@ -1,6 +1,8 @@ -/* +/** + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 2000 Peter Kelly (pmk@post.com) - * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -17,14 +19,17 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - #include "config.h" #include "Notation.h" namespace WebCore { -Notation::Notation(Document* document, const String& name, const String& publicId, const String& systemId) - : ContainerNode(document) +Notation::Notation(Document* doc) : ContainerNode(doc) +{ +} + +Notation::Notation(Document* doc, const String& name, const String& publicId, const String& systemId) + : ContainerNode(doc) , m_name(name) , m_publicId(publicId) , m_systemId(systemId) @@ -47,6 +52,7 @@ PassRefPtr<Node> Notation::cloneNode(bool /*deep*/) return 0; } +// DOM Section 1.1.1 bool Notation::childTypeAllowed(NodeType) { return false; diff --git a/WebCore/dom/Notation.h b/WebCore/dom/Notation.h index 547c9e7..2bd5363 100644 --- a/WebCore/dom/Notation.h +++ b/WebCore/dom/Notation.h @@ -1,6 +1,8 @@ /* + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 2000 Peter Kelly (pmk@post.com) - * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,25 +24,26 @@ #ifndef Notation_h #define Notation_h +#include "CachedResourceClient.h" #include "ContainerNode.h" namespace WebCore { -// FIXME: This class is never instantiated. Maybe it should be removed. - class Notation : public ContainerNode { public: - const String& publicId() const { return m_publicId; } - const String& systemId() const { return m_systemId; } - -private: + Notation(Document*); Notation(Document*, const String& name, const String& publicId, const String& systemId); + // DOM methods & attributes for Notation + String publicId() const { return m_publicId; } + String systemId() const { return m_systemId; } + virtual String nodeName() const; virtual NodeType nodeType() const; virtual PassRefPtr<Node> cloneNode(bool deep); virtual bool childTypeAllowed(NodeType); +private: String m_name; String m_publicId; String m_systemId; diff --git a/WebCore/dom/ProcessingInstruction.cpp b/WebCore/dom/ProcessingInstruction.cpp index 8404481..806bf92 100644 --- a/WebCore/dom/ProcessingInstruction.cpp +++ b/WebCore/dom/ProcessingInstruction.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2000 Peter Kelly (pmk@post.com) - * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -35,10 +35,8 @@ namespace WebCore { -inline ProcessingInstruction::ProcessingInstruction(Document* document, const String& target, const String& data) - : ContainerNode(document) - , m_target(target) - , m_data(data) +ProcessingInstruction::ProcessingInstruction(Document* doc) + : ContainerNode(doc) , m_cachedSheet(0) , m_loading(false) , m_alternate(false) @@ -48,9 +46,17 @@ inline ProcessingInstruction::ProcessingInstruction(Document* document, const St { } -PassRefPtr<ProcessingInstruction> ProcessingInstruction::create(Document* document, const String& target, const String& data) +ProcessingInstruction::ProcessingInstruction(Document* doc, const String& target, const String& data) + : ContainerNode(doc) + , m_target(target) + , m_data(data) + , m_cachedSheet(0) + , m_loading(false) + , m_alternate(false) +#if ENABLE(XSLT) + , m_isXSL(false) +#endif { - return adoptRef(new ProcessingInstruction(document, target, data)); } ProcessingInstruction::~ProcessingInstruction() @@ -89,9 +95,8 @@ void ProcessingInstruction::setNodeValue(const String& nodeValue, ExceptionCode& PassRefPtr<Node> ProcessingInstruction::cloneNode(bool /*deep*/) { - // FIXME: Is it a problem that this does not copy m_localHref? - // What about other data members? - return create(document(), m_target, m_data); + // ### copy m_localHref + return new ProcessingInstruction(document(), m_target, m_data); } // DOM Section 1.1.1 diff --git a/WebCore/dom/ProcessingInstruction.h b/WebCore/dom/ProcessingInstruction.h index 4b7dc86..d133019 100644 --- a/WebCore/dom/ProcessingInstruction.h +++ b/WebCore/dom/ProcessingInstruction.h @@ -1,6 +1,8 @@ /* + * This file is part of the DOM implementation for KDE. + * * Copyright (C) 2000 Peter Kelly (pmk@post.com) - * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,28 +35,15 @@ class CSSStyleSheet; class ProcessingInstruction : public ContainerNode, private CachedResourceClient { public: - static PassRefPtr<ProcessingInstruction> create(Document*, const String& target, const String& data); + ProcessingInstruction(Document*); + ProcessingInstruction(Document*, const String& target, const String& data); virtual ~ProcessingInstruction(); - const String& target() const { return m_target; } - const String& data() const { return m_data; } + // DOM methods & attributes for Notation + String target() const { return m_target; } + String data() const { return m_data; } void setData(const String&, ExceptionCode&); - void setCreatedByParser(bool createdByParser) { m_createdByParser = createdByParser; } - - virtual void finishParsingChildren(); - - const String& localHref() const { return m_localHref; } - StyleSheet* sheet() const { return m_sheet.get(); } - void setCSSStyleSheet(PassRefPtr<CSSStyleSheet>); - -#if ENABLE(XSLT) - bool isXSL() const { return m_isXSL; } -#endif - -private: - ProcessingInstruction(Document*, const String& target, const String& data); - virtual String nodeName() const; virtual NodeType nodeType() const; virtual String nodeValue() const; @@ -66,18 +55,28 @@ private: virtual void insertedIntoDocument(); virtual void removedFromDocument(); + void setCreatedByParser(bool createdByParser) { m_createdByParser = createdByParser; } + virtual void finishParsingChildren(); + // Other methods (not part of DOM) + String localHref() const { return m_localHref; } + StyleSheet* sheet() const { return m_sheet.get(); } void checkStyleSheet(); virtual void setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet*); #if ENABLE(XSLT) virtual void setXSLStyleSheet(const String& url, const String& sheet); #endif - + void setCSSStyleSheet(PassRefPtr<CSSStyleSheet>); bool isLoading() const; virtual bool sheetLoaded(); +#if ENABLE(XSLT) + bool isXSL() const { return m_isXSL; } +#endif + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; +private: void parseStyleSheet(const String& sheet); String m_target; diff --git a/WebCore/dom/Range.cpp b/WebCore/dom/Range.cpp index b9a531c..edee305 100644 --- a/WebCore/dom/Range.cpp +++ b/WebCore/dom/Range.cpp @@ -586,7 +586,7 @@ PassRefPtr<DocumentFragment> Range::processContents(ActionType action, Exception RefPtr<DocumentFragment> fragment; if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) - fragment = DocumentFragment::create(m_ownerDocument.get()); + fragment = new DocumentFragment(m_ownerDocument.get()); ec = 0; if (collapsed(ec)) diff --git a/WebCore/dom/StyledElement.cpp b/WebCore/dom/StyledElement.cpp index 13c23fb..456cc52 100644 --- a/WebCore/dom/StyledElement.cpp +++ b/WebCore/dom/StyledElement.cpp @@ -280,6 +280,14 @@ CSSStyleDeclaration* StyledElement::style() return getInlineStyleDecl(); } +static inline int toHex(UChar c) +{ + return ((c >= '0' && c <= '9') ? (c - '0') + : ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) + : ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) + : -1))); +} + void StyledElement::addCSSProperty(MappedAttribute* attr, int id, const String &value) { if (!attr->decl()) createMappedDecl(attr); @@ -385,9 +393,10 @@ void StyledElement::addCSSColor(MappedAttribute* attr, int id, const String& c) // search forward for digits in the string int numDigits = 0; while (pos < (int)color.length() && numDigits < basicLength) { - colors[component] <<= 4; - if (isASCIIHexDigit(color[pos])) { - colors[component] += toASCIIHexValue(color[pos]); + int hex = toHex(color[pos]); + colors[component] = (colors[component] << 4); + if (hex > 0) { + colors[component] += hex; maxDigit = min(maxDigit, numDigits); } numDigits++; @@ -401,9 +410,10 @@ void StyledElement::addCSSColor(MappedAttribute* attr, int id, const String& c) // normalize to 00-ff. The highest filled digit counts, minimum is 2 digits maxDigit -= 2; - colors[0] >>= 4 * maxDigit; - colors[1] >>= 4 * maxDigit; - colors[2] >>= 4 * maxDigit; + colors[0] >>= 4*maxDigit; + colors[1] >>= 4*maxDigit; + colors[2] >>= 4*maxDigit; + // ASSERT(colors[0] < 0x100 && colors[1] < 0x100 && colors[2] < 0x100); color = String::format("#%02x%02x%02x", colors[0], colors[1], colors[2]); if (attr->decl()->setProperty(id, color, false)) diff --git a/WebCore/dom/Text.cpp b/WebCore/dom/Text.cpp index 00db1c1..bbd926b 100644 --- a/WebCore/dom/Text.cpp +++ b/WebCore/dom/Text.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -37,18 +37,22 @@ #include "WMLVariables.h" #endif -using namespace std; - namespace WebCore { -Text::Text(Document* document, const String& data) - : CharacterData(document, data, CreateText) +// DOM Section 1.1.1 + +Text::Text(Document* document, const String& text) + : CharacterData(document, text, true) +{ +} + +Text::Text(Document* document) + : CharacterData(document, true) { } -PassRefPtr<Text> Text::create(Document* document, const String& data) +Text::~Text() { - return adoptRef(new Text(document, data)); } PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec) @@ -57,14 +61,14 @@ PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec) // INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than // the number of 16-bit units in data. - if (offset > length()) { + if (offset > m_data->length()) { ec = INDEX_SIZE_ERR; return 0; } - RefPtr<StringImpl> oldStr = dataImpl(); - RefPtr<Text> newText = virtualCreate(oldStr->substring(offset)); - setDataImpl(oldStr->substring(0, offset)); + RefPtr<StringImpl> oldStr = m_data; + RefPtr<Text> newText = createNew(oldStr->substring(offset)); + m_data = oldStr->substring(0, offset); dispatchModifiedEvent(oldStr.get()); @@ -77,7 +81,7 @@ PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec) document()->textNodeSplit(this); if (renderer()) - toRenderText(renderer())->setText(dataImpl()); + toRenderText(renderer())->setText(m_data); return newText.release(); } @@ -195,7 +199,7 @@ Node::NodeType Text::nodeType() const PassRefPtr<Node> Text::cloneNode(bool /*deep*/) { - return create(document(), data()); + return document()->createTextNode(m_data); } bool Text::rendererIsNeeded(RenderStyle *style) @@ -240,7 +244,7 @@ bool Text::rendererIsNeeded(RenderStyle *style) return true; } -RenderObject* Text::createRenderer(RenderArena* arena, RenderStyle*) +RenderObject *Text::createRenderer(RenderArena* arena, RenderStyle*) { #if ENABLE(SVG) if (parentNode()->isSVGElement() @@ -248,17 +252,17 @@ RenderObject* Text::createRenderer(RenderArena* arena, RenderStyle*) && !parentNode()->hasTagName(SVGNames::foreignObjectTag) #endif ) - return new (arena) RenderSVGInlineText(this, dataImpl()); + return new (arena) RenderSVGInlineText(this, m_data); #endif - return new (arena) RenderText(this, dataImpl()); + return new (arena) RenderText(this, m_data); } void Text::attach() { #if ENABLE(WML) if (document()->isWMLDocument() && !containsOnlyWhitespace()) { - String text = data(); + String text = m_data; ASSERT(!text.isEmpty()); text = substituteVariableReferences(text, document()); @@ -282,7 +286,7 @@ void Text::recalcStyle(StyleChange change) if (needsStyleRecalc()) { if (renderer()) { if (renderer()->isText()) - toRenderText(renderer())->setText(dataImpl()); + toRenderText(renderer())->setText(m_data); } else { if (attached()) detach(); @@ -292,42 +296,40 @@ void Text::recalcStyle(StyleChange change) setNeedsStyleRecalc(NoStyleChange); } +// DOM Section 1.1.1 bool Text::childTypeAllowed(NodeType) { return false; } -PassRefPtr<Text> Text::virtualCreate(const String& data) +PassRefPtr<Text> Text::createNew(PassRefPtr<StringImpl> string) { - return create(document(), data); + return new Text(document(), string); } -PassRefPtr<Text> Text::createWithLengthLimit(Document* document, const String& data, unsigned& charsLeft, unsigned maxChars) +PassRefPtr<Text> Text::createWithLengthLimit(Document* doc, const String& text, unsigned& charsLeft, unsigned maxChars) { - unsigned dataLength = data.length(); - - if (charsLeft == dataLength && charsLeft <= maxChars) { + if (charsLeft == text.length() && charsLeft <= maxChars) { charsLeft = 0; - return create(document, data); + return new Text(doc, text); } - - unsigned start = dataLength - charsLeft; - unsigned end = start + min(charsLeft, maxChars); - // Check we are not on an unbreakable boundary. - TextBreakIterator* it = characterBreakIterator(data.characters(), dataLength); - if (end < dataLength && !isTextBreak(it, end)) + unsigned start = text.length() - charsLeft; + unsigned end = start + std::min(charsLeft, maxChars); + + // check we are not on an unbreakable boundary + TextBreakIterator* it = characterBreakIterator(text.characters(), text.length()); + if (end < text.length() && !isTextBreak(it, end)) end = textBreakPreceding(it, end); - // If we have maxChars of unbreakable characters the above could lead to - // an infinite loop. - // FIXME: It would be better to just have the old value of end before calling - // textBreakPreceding rather than this, because this exceeds the length limit. + // maxChars of unbreakable characters could lead to infinite loop if (end <= start) - end = dataLength; + end = text.length(); - charsLeft = dataLength - end; - return create(document, data.substring(start, end - start)); + String nodeText = text.substring(start, end - start); + charsLeft = text.length() - end; + + return new Text(doc, nodeText); } #ifndef NDEBUG @@ -341,7 +343,7 @@ void Text::formatForDebugger(char *buffer, unsigned length) const result += s; } - s = data(); + s = nodeValue(); if (s.length() > 0) { if (result.length() > 0) result += "; "; diff --git a/WebCore/dom/Text.h b/WebCore/dom/Text.h index 4722736..e5a6e69 100644 --- a/WebCore/dom/Text.h +++ b/WebCore/dom/Text.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,39 +27,44 @@ namespace WebCore { +const unsigned cTextNodeLengthLimit = 1 << 16; + class Text : public CharacterData { public: - static const unsigned defaultLengthLimit = 1 << 16; + Text(Document *impl, const String &_text); + Text(Document *impl); + virtual ~Text(); - static PassRefPtr<Text> create(Document*, const String&); - static PassRefPtr<Text> createWithLengthLimit(Document*, const String&, unsigned& charsLeft, unsigned lengthLimit = defaultLengthLimit); + // DOM methods & attributes for CharacterData PassRefPtr<Text> splitText(unsigned offset, ExceptionCode&); // DOM Level 3: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772 - String wholeText() const; PassRefPtr<Text> replaceWholeText(const String&, ExceptionCode&); - virtual void attach(); - -protected: - Text(Document*, const String&); + // DOM methods overridden from parent classes -private: virtual String nodeName() const; virtual NodeType nodeType() const; virtual PassRefPtr<Node> cloneNode(bool deep); + + // Other methods (not part of DOM) + + virtual void attach(); virtual bool rendererIsNeeded(RenderStyle*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); virtual void recalcStyle(StyleChange = NoChange); virtual bool childTypeAllowed(NodeType); - virtual PassRefPtr<Text> virtualCreate(const String&); + static PassRefPtr<Text> createWithLengthLimit(Document*, const String&, unsigned& charsLeft, unsigned maxChars = cTextNodeLengthLimit); #ifndef NDEBUG virtual void formatForDebugger(char* buffer, unsigned length) const; #endif + +protected: + virtual PassRefPtr<Text> createNew(PassRefPtr<StringImpl>); }; } // namespace WebCore diff --git a/WebCore/dom/XMLTokenizer.cpp b/WebCore/dom/XMLTokenizer.cpp index 4d06343..1747c3c 100644 --- a/WebCore/dom/XMLTokenizer.cpp +++ b/WebCore/dom/XMLTokenizer.cpp @@ -136,7 +136,7 @@ bool XMLTokenizer::enterText() #if !USE(QXMLSTREAM) ASSERT(m_bufferedText.size() == 0); #endif - RefPtr<Node> newNode = Text::create(m_doc, ""); + RefPtr<Node> newNode = new Text(m_doc, ""); if (!m_currentNode->addChild(newNode.get())) return false; setCurrentNode(newNode.get()); diff --git a/WebCore/dom/XMLTokenizerLibxml2.cpp b/WebCore/dom/XMLTokenizerLibxml2.cpp index da2f9b6..4387a66 100644 --- a/WebCore/dom/XMLTokenizerLibxml2.cpp +++ b/WebCore/dom/XMLTokenizerLibxml2.cpp @@ -951,7 +951,7 @@ void XMLTokenizer::cdataBlock(const xmlChar* s, int len) exitText(); - RefPtr<Node> newNode = CDATASection::create(m_doc, toString(s, len)); + RefPtr<Node> newNode = new CDATASection(m_doc, toString(s, len)); if (!m_currentNode->addChild(newNode.get())) return; if (m_view && !newNode->attached()) @@ -970,7 +970,7 @@ void XMLTokenizer::comment(const xmlChar* s) exitText(); - RefPtr<Node> newNode = Comment::create(m_doc, toString(s)); + RefPtr<Node> newNode = new Comment(m_doc, toString(s)); m_currentNode->addChild(newNode.get()); if (m_view && !newNode->attached()) newNode->attach(); diff --git a/WebCore/dom/XMLTokenizerQt.cpp b/WebCore/dom/XMLTokenizerQt.cpp index 799eef3..16c637f 100644 --- a/WebCore/dom/XMLTokenizerQt.cpp +++ b/WebCore/dom/XMLTokenizerQt.cpp @@ -692,7 +692,7 @@ void XMLTokenizer::parseCdata() { exitText(); - RefPtr<Node> newNode = CDATASection::create(m_doc, m_stream.text()); + RefPtr<Node> newNode = new CDATASection(m_doc, m_stream.text()); if (!m_currentNode->addChild(newNode.get())) return; if (m_view && !newNode->attached()) @@ -703,7 +703,7 @@ void XMLTokenizer::parseComment() { exitText(); - RefPtr<Node> newNode = Comment::create(m_doc, m_stream.text()); + RefPtr<Node> newNode = new Comment(m_doc, m_stream.text()); m_currentNode->addChild(newNode.get()); if (m_view && !newNode->attached()) newNode->attach(); diff --git a/WebCore/dom/make_names.pl b/WebCore/dom/make_names.pl index 4e6eb38..e6d59a0 100755 --- a/WebCore/dom/make_names.pl +++ b/WebCore/dom/make_names.pl @@ -48,30 +48,28 @@ my %parameters = (); my $extraDefines = 0; my $preprocessor = "/usr/bin/gcc -E -P -x c++"; -GetOptions( - 'tags=s' => \$tagsFile, +GetOptions('tags=s' => \$tagsFile, 'attrs=s' => \$attrsFile, 'factory' => \$printFactory, 'outputDir=s' => \$outputDir, 'extraDefines=s' => \$extraDefines, 'preprocessor=s' => \$preprocessor, - 'wrapperFactory' => \$printWrapperFactory -); + 'wrapperFactory' => \$printWrapperFactory); die "You must specify at least one of --tags <file> or --attrs <file>" unless (length($tagsFile) || length($attrsFile)); readNames($tagsFile, "tags") if length($tagsFile); readNames($attrsFile, "attrs") if length($attrsFile); -die "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $parameters{namespace}; -die "You must specify a namespaceURI (e.g. http://www.w3.org/2000/svg)" unless $parameters{namespaceURI}; +die "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $parameters{'namespace'}; +die "You must specify a namespaceURI (e.g. http://www.w3.org/2000/svg)" unless $parameters{'namespaceURI'}; -$parameters{namespacePrefix} = $parameters{namespace} unless $parameters{namespacePrefix}; +$parameters{'namespacePrefix'} = $parameters{'namespace'} unless $parameters{'namespacePrefix'}; mkpath($outputDir); -my $namesBasePath = "$outputDir/$parameters{namespace}Names"; -my $factoryBasePath = "$outputDir/$parameters{namespace}ElementFactory"; -my $wrapperFactoryBasePath = "$outputDir/JS$parameters{namespace}ElementWrapperFactory"; +my $namesBasePath = "$outputDir/$parameters{'namespace'}Names"; +my $factoryBasePath = "$outputDir/$parameters{'namespace'}ElementFactory"; +my $wrapperFactoryBasePath = "$outputDir/JS$parameters{'namespace'}ElementWrapperFactory"; printNamesHeaderFile("$namesBasePath.h"); printNamesCppFile("$namesBasePath.cpp"); @@ -88,44 +86,39 @@ if ($printWrapperFactory) { ### Hash initialization -sub defaultTagPropertyHash +sub initializeTagPropertyHash { - return ( - 'constructorNeedsCreatedByParser' => 0, - 'constructorNeedsFormElement' => 0, - 'createWithNew' => 1, - 'exportString' => 0, - 'interfaceName' => defaultInterfaceName($_[0]), - # By default, the JSInterfaceName is the same as the interfaceName. - 'JSInterfaceName' => defaultInterfaceName($_[0]), - 'mapToTagName' => '', - 'wrapperOnlyIfMediaIsAvailable' => 0, - 'conditional' => 0 - ); + return ('constructorNeedsCreatedByParser' => 0, + 'constructorNeedsFormElement' => 0, + 'exportString' => 0, + 'interfaceName' => defaultInterfaceName($_[0]), + # By default, the JSInterfaceName is the same as the interfaceName. + 'JSInterfaceName' => defaultInterfaceName($_[0]), + 'mapToTagName' => '', + 'wrapperOnlyIfMediaIsAvailable' => 0, + 'conditional' => 0); } -sub defaultAttrPropertyHash +sub initializeAttrPropertyHash { return ('exportString' => 0); } -sub defaultParametersHash +sub initializeParametersHash { - return ( - 'namespace' => '', - 'namespacePrefix' => '', - 'namespaceURI' => '', - 'guardFactoryWith' => '', - 'tagsNullNamespace' => 0, - 'attrsNullNamespace' => 0, - 'exportStrings' => 0 - ); + return ('namespace' => '', + 'namespacePrefix' => '', + 'namespaceURI' => '', + 'guardFactoryWith' => '', + 'tagsNullNamespace' => 0, + 'attrsNullNamespace' => 0, + 'exportStrings' => 0); } sub defaultInterfaceName { - die "No namespace found" if !$parameters{namespace}; - return $parameters{namespace} . upperCaseName($_[0]) . "Element" + die "No namespace found" if !$parameters{'namespace'}; + return $parameters{'namespace'} . upperCaseName($_[0]) . "Element" } ### Parsing handlers @@ -136,16 +129,16 @@ sub tagsHandler $tag =~ s/-/_/g; - # Initialize default property values. - $tags{$tag} = { defaultTagPropertyHash($tag) } if !defined($tags{$tag}); + # Initialize default properties' values. + $tags{$tag} = { initializeTagPropertyHash($tag) } if !defined($tags{$tag}); if ($property) { die "Unknown property $property for tag $tag\n" if !defined($tags{$tag}{$property}); - - # The code relies on JSInterfaceName deriving from interfaceName to check for custom JSInterfaceName. - # So override JSInterfaceName if it was not already set. - $tags{$tag}{JSInterfaceName} = $value if $property eq "interfaceName" && $tags{$tag}{JSInterfaceName} eq $tags{$tag}{interfaceName}; - + # The code rely on JSInterfaceName deriving from interfaceName to check for custom JSInterfaceName. + # So just override JSInterfaceName if it was not already set. + if ($property eq "interfaceName" && $tags{$tag}{'JSInterfaceName'} eq $tags{$tag}{'interfaceName'}) { + $tags{$tag}{'JSInterfaceName'} = $value; + } $tags{$tag}{$property} = $value; } } @@ -157,7 +150,7 @@ sub attrsHandler $attr =~ s/-/_/g; # Initialize default properties' values. - $attrs{$attr} = { defaultAttrPropertyHash($attr) } if !defined($attrs{$attr}); + $attrs{$attr} = { initializeAttrPropertyHash($attr) } if !defined($attrs{$attr}); if ($property) { die "Unknown property $property for attribute $attr\n" if !defined($attrs{$attr}{$property}); @@ -170,7 +163,7 @@ sub parametersHandler my ($parameter, $value) = @_; # Initialize default properties' values. - %parameters = defaultParametersHash() if !(keys %parameters); + %parameters = initializeParametersHash() if !(keys %parameters); die "Unknown parameter $parameter for tags/attrs\n" if !defined($parameters{$parameter}); $parameters{$parameter} = $value; @@ -221,7 +214,7 @@ sub printMacros for my $name (sort keys %$namesRef) { print F "$macro $name","$suffix;\n"; - if ($parameters{exportStrings} or $names{$name}{exportString}) { + if ($parameters{'exportStrings'} or $names{$name}{"exportString"}) { print F "extern char $name", "${suffix}String[];\n"; } } @@ -230,7 +223,7 @@ sub printMacros sub usesDefaultWrapper { my $tagName = shift; - return $tagName eq $parameters{namespace} . "Element"; + return $tagName eq $parameters{'namespace'} . "Element"; } # Build a direct mapping from the tags to the Element to create, excluding @@ -239,16 +232,16 @@ sub buildConstructorMap { my %tagConstructorMap = (); for my $tagName (keys %tags) { - my $interfaceName = $tags{$tagName}{interfaceName}; + my $interfaceName = $tags{$tagName}{'interfaceName'}; next if (usesDefaultWrapper($interfaceName)); - if ($tags{$tagName}{mapToTagName}) { - die "Cannot handle multiple mapToTagName for $tagName\n" if $tags{$tags{$tagName}{mapToTagName}}{mapToTagName}; - $interfaceName = $tags{ $tags{$tagName}{mapToTagName} }{interfaceName}; + if ($tags{$tagName}{'mapToTagName'}) { + die "Cannot handle multiple mapToTagName for $tagName\n" if $tags{$tags{$tagName}{'mapToTagName'}}{'mapToTagName'}; + $interfaceName = $tags{ $tags{$tagName}{'mapToTagName'} }{'interfaceName'}; } # Chop the string to keep the interesting part. - $interfaceName =~ s/$parameters{namespace}(.*)Element/$1/; + $interfaceName =~ s/$parameters{'namespace'}(.*)Element/$1/; $tagConstructorMap{$tagName} = lc($interfaceName); } @@ -261,13 +254,17 @@ sub printConstructorSignature { my ($F, $tagName, $constructorName, $constructorTagName) = @_; - print F "static PassRefPtr<$parameters{namespace}Element> ${constructorName}Constructor(const QualifiedName& $constructorTagName, Document* document"; - if ($parameters{namespace} eq "HTML") { + print F "static PassRefPtr<$parameters{'namespace'}Element> ${constructorName}Constructor(const QualifiedName& $constructorTagName, Document* doc"; + if ($parameters{'namespace'} eq "HTML") { print F ", HTMLFormElement*"; - print F " formElement" if $tags{$tagName}{constructorNeedsFormElement}; + if ($tags{$tagName}{'constructorNeedsFormElement'}) { + print F " formElement"; + } } print F ", bool"; - print F " createdByParser" if $tags{$tagName}{constructorNeedsCreatedByParser}; + if ($tags{$tagName}{'constructorNeedsCreatedByParser'}) { + print F " createdByParser"; + } print F ")\n{\n"; } @@ -279,26 +276,22 @@ sub printConstructorInterior my ($F, $tagName, $interfaceName, $constructorTagName) = @_; # Handle media elements. - if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) { + if ($tags{$tagName}{'wrapperOnlyIfMediaIsAvailable'}) { print F <<END if (!MediaPlayer::isAvailable()) - return new HTMLElement($constructorTagName, document); + return new HTMLElement($constructorTagName, doc); END ; } - my $newPrefix = ""; - my $createSuffix = "::create"; - - if ($tags{$tagName}{createWithNew}) { - $newPrefix = "new "; - $createSuffix = ""; + # Now call the constructor with the right parameters. + print F " return new ${interfaceName}($constructorTagName, doc"; + if ($tags{$tagName}{'constructorNeedsFormElement'}) { + print F ", formElement"; + } + if ($tags{$tagName}{'constructorNeedsCreatedByParser'}) { + print F ", createdByParser"; } - - # Call the constructor with the right parameters. - print F " return $newPrefix$interfaceName${createSuffix}($constructorTagName, document"; - print F ", formElement" if $tags{$tagName}{constructorNeedsFormElement}; - print F ", createdByParser" if $tags{$tagName}{constructorNeedsCreatedByParser}; print F ");\n}\n\n"; } @@ -307,20 +300,20 @@ sub printConstructors my ($F, $tagConstructorMapRef) = @_; my %tagConstructorMap = %$tagConstructorMapRef; - print F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith}; + print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; # This is to avoid generating the same constructor several times. my %uniqueTags = (); for my $tagName (sort keys %tagConstructorMap) { - my $interfaceName = $tags{$tagName}{interfaceName}; + my $interfaceName = $tags{$tagName}{'interfaceName'}; # Ignore the mapped tag # FIXME: It could be moved inside this loop but was split for readibility. - next if (defined($uniqueTags{$interfaceName}) || $tags{$tagName}{mapToTagName}); + next if (defined($uniqueTags{$interfaceName}) || $tags{$tagName}{'mapToTagName'}); $uniqueTags{$interfaceName} = '1'; - my $conditional = $tags{$tagName}{conditional}; + my $conditional = $tags{$tagName}{"conditional"}; if ($conditional) { my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; print F "#if ${conditionalString}\n\n"; @@ -330,20 +323,20 @@ sub printConstructors printConstructorInterior($F, $tagName, $interfaceName, "tagName"); if ($conditional) { - print F "#endif\n"; + print F "#endif\n\n"; } } # Mapped tag name uses a special wrapper to keep their prefix and namespaceURI while using the mapped localname. for my $tagName (sort keys %tagConstructorMap) { - if ($tags{$tagName}{mapToTagName}) { - my $mappedName = $tags{$tagName}{mapToTagName}; + if ($tags{$tagName}{'mapToTagName'}) { + my $mappedName = $tags{$tagName}{'mapToTagName'}; printConstructorSignature($F, $mappedName, $mappedName . "To" . $tagName, "tagName"); - printConstructorInterior($F, $mappedName, $tags{$mappedName}{interfaceName}, "QualifiedName(tagName.prefix(), ${mappedName}Tag.localName(), tagName.namespaceURI())"); + printConstructorInterior($F, $mappedName, $tags{$mappedName}{'interfaceName'}, "QualifiedName(tagName.prefix(), ${mappedName}Tag.localName(), tagName.namespaceURI())"); } } - print F "#endif\n" if $parameters{guardFactoryWith}; + print F "#endif\n" if $parameters{'guardFactoryWith'}; } sub printFunctionInits @@ -353,14 +346,14 @@ sub printFunctionInits for my $tagName (sort keys %tagConstructorMap) { - my $conditional = $tags{$tagName}{conditional}; + my $conditional = $tags{$tagName}{"conditional"}; if ($conditional) { my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; print F "#if ${conditionalString}\n"; } - if ($tags{$tagName}{mapToTagName}) { - print F " addTag(${tagName}Tag, $tags{$tagName}{mapToTagName}To${tagName}Constructor);\n"; + if ($tags{$tagName}{'mapToTagName'}) { + print F " addTag(${tagName}Tag, $tags{$tagName}{'mapToTagName'}To${tagName}Constructor);\n"; } else { print F " addTag(${tagName}Tag, $tagConstructorMap{$tagName}Constructor);\n"; } @@ -375,7 +368,9 @@ sub svgCapitalizationHacks { my $name = shift; - $name = "FE" . ucfirst $1 if $name =~ /^fe(.+)$/; + if ($name =~ /^fe(.+)$/) { + $name = "FE" . ucfirst $1; + } return $name; } @@ -384,7 +379,7 @@ sub upperCaseName { my $name = shift; - $name = svgCapitalizationHacks($name) if ($parameters{namespace} eq "SVG"); + $name = svgCapitalizationHacks($name) if ($parameters{'namespace'} eq "SVG"); while ($name =~ /^(.*?)_(.*)/) { $name = $1 . ucfirst $2; @@ -397,11 +392,10 @@ sub printLicenseHeader { my $F = shift; print F "/* - * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. + * THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT. * - * This file was generated by the dom/make_names.pl script. * - * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -422,9 +416,10 @@ sub printLicenseHeader * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + "; } @@ -433,16 +428,16 @@ sub printNamesHeaderFile my ($headerPath) = shift; my $F; open F, ">$headerPath"; - + printLicenseHeader($F); - print F "#ifndef DOM_$parameters{namespace}NAMES_H\n"; - print F "#define DOM_$parameters{namespace}NAMES_H\n\n"; + print F "#ifndef DOM_$parameters{'namespace'}NAMES_H\n"; + print F "#define DOM_$parameters{'namespace'}NAMES_H\n\n"; print F "#include \"QualifiedName.h\"\n\n"; - - print F "namespace WebCore {\n\n namespace $parameters{namespace}Names {\n\n"; - - my $lowerNamespace = lc($parameters{namespacePrefix}); - print F "#ifndef DOM_$parameters{namespace}NAMES_HIDE_GLOBALS\n"; + + print F "namespace WebCore {\n\n namespace $parameters{'namespace'}Names {\n\n"; + + my $lowerNamespace = lc($parameters{'namespacePrefix'}); + print F "#ifndef DOM_$parameters{'namespace'}NAMES_HIDE_GLOBALS\n"; print F "// Namespace\n"; print F "extern const WebCore::AtomicString ${lowerNamespace}NamespaceURI;\n\n"; @@ -456,19 +451,19 @@ sub printNamesHeaderFile printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%attrs); } print F "#endif\n\n"; - + if (keys %tags) { - print F "WebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size);\n"; + print F "WebCore::QualifiedName** get$parameters{'namespace'}Tags(size_t* size);\n"; } if (keys %attrs) { - print F "WebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size);\n"; + print F "WebCore::QualifiedName** get$parameters{'namespace'}Attrs(size_t* size);\n"; } - + print F "\nvoid init();\n\n"; print F "} }\n\n"; print F "#endif\n\n"; - + close F; } @@ -480,25 +475,25 @@ sub printNamesCppFile printLicenseHeader($F); - my $lowerNamespace = lc($parameters{namespacePrefix}); + my $lowerNamespace = lc($parameters{'namespacePrefix'}); print F "#include \"config.h\"\n"; print F "#ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC\n"; -print F "#define DOM_$parameters{namespace}NAMES_HIDE_GLOBALS 1\n"; +print F "#define DOM_$parameters{'namespace'}NAMES_HIDE_GLOBALS 1\n"; print F "#else\n"; print F "#define QNAME_DEFAULT_CONSTRUCTOR 1\n"; print F "#endif\n\n"; -print F "#include \"$parameters{namespace}Names.h\"\n\n"; +print F "#include \"$parameters{'namespace'}Names.h\"\n\n"; print F "#include \"StaticConstructors.h\"\n"; -print F "namespace WebCore {\n\n namespace $parameters{namespace}Names { +print F "namespace WebCore {\n\n namespace $parameters{'namespace'}Names { using namespace WebCore; -DEFINE_GLOBAL(AtomicString, ${lowerNamespace}NamespaceURI, \"$parameters{namespaceURI}\") +DEFINE_GLOBAL(AtomicString, ${lowerNamespace}NamespaceURI, \"$parameters{'namespaceURI'}\") "; if (keys %tags) { @@ -507,14 +502,14 @@ DEFINE_GLOBAL(AtomicString, ${lowerNamespace}NamespaceURI, \"$parameters{namespa print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Tag, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n"; } - print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size)\n"; - print F "{\n static WebCore::QualifiedName* $parameters{namespace}Tags[] = {\n"; + print F "\n\nWebCore::QualifiedName** get$parameters{'namespace'}Tags(size_t* size)\n"; + print F "{\n static WebCore::QualifiedName* $parameters{'namespace'}Tags[] = {\n"; for my $name (sort keys %tags) { print F " (WebCore::QualifiedName*)&${name}Tag,\n"; } print F " };\n"; print F " *size = ", scalar(keys %tags), ";\n"; - print F " return $parameters{namespace}Tags;\n"; + print F " return $parameters{'namespace'}Tags;\n"; print F "}\n"; } @@ -523,14 +518,14 @@ DEFINE_GLOBAL(AtomicString, ${lowerNamespace}NamespaceURI, \"$parameters{namespa for my $name (sort keys %attrs) { print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Attr, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n"; } - print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size)\n"; - print F "{\n static WebCore::QualifiedName* $parameters{namespace}Attr[] = {\n"; + print F "\n\nWebCore::QualifiedName** get$parameters{'namespace'}Attrs(size_t* size)\n"; + print F "{\n static WebCore::QualifiedName* $parameters{'namespace'}Attr[] = {\n"; for my $name (sort keys %attrs) { print F " (WebCore::QualifiedName*)&${name}Attr,\n"; } print F " };\n"; print F " *size = ", scalar(keys %attrs), ";\n"; - print F " return $parameters{namespace}Attr;\n"; + print F " return $parameters{'namespace'}Attr;\n"; print F "}\n"; } @@ -554,16 +549,16 @@ print F "\nvoid init() AtomicString::init(); "; - print(F " AtomicString ${lowerNamespace}NS(\"$parameters{namespaceURI}\");\n\n"); + print(F " AtomicString ${lowerNamespace}NS(\"$parameters{'namespaceURI'}\");\n\n"); print(F " // Namespace\n"); print(F " new ((void*)&${lowerNamespace}NamespaceURI) AtomicString(${lowerNamespace}NS);\n\n"); if (keys %tags) { - my $tagsNamespace = $parameters{tagsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS"; + my $tagsNamespace = $parameters{'tagsNullNamespace'} ? "nullAtom" : "${lowerNamespace}NS"; printDefinitions($F, \%tags, "tags", $tagsNamespace); } if (keys %attrs) { - my $attrsNamespace = $parameters{attrsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS"; + my $attrsNamespace = $parameters{'attrsNullNamespace'} ? "nullAtom" : "${lowerNamespace}NS"; printDefinitions($F, \%attrs, "attributes", $attrsNamespace); } @@ -577,7 +572,7 @@ sub printJSElementIncludes my %tagsSeen; for my $tagName (sort keys %tags) { - my $JSInterfaceName = $tags{$tagName}{JSInterfaceName}; + my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"}; next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); $tagsSeen{$JSInterfaceName} = 1; @@ -591,7 +586,7 @@ sub printElementIncludes my %tagsSeen; for my $tagName (sort keys %tags) { - my $interfaceName = $tags{$tagName}{interfaceName}; + my $interfaceName = $tags{$tagName}{"interfaceName"}; next if defined($tagsSeen{$interfaceName}); $tagsSeen{$interfaceName} = 1; @@ -609,7 +604,7 @@ sub printDefinitionStrings my %names = %$namesRef; for my $name (sort keys %$namesRef) { - next if (!$parameters{exportStrings} and !$names{$name}{exportString}); + next if (!$parameters{'exportStrings'} and !$names{$name}{"exportString"}); my $realName = $name; $realName =~ s/_/-/g; @@ -630,7 +625,7 @@ sub printDefinitions my %names = %$namesRef; for my $name (sort keys %$namesRef) { - next if ($parameters{exportStrings} or $names{$name}{exportString}); + next if ($parameters{'exportStrings'} or $names{$name}{"exportString"}); my $realName = $name; $realName =~ s/_/-/g; @@ -656,31 +651,39 @@ printLicenseHeader($F); print F <<END #include "config.h" -#include "$parameters{namespace}ElementFactory.h" +#include "$parameters{'namespace'}ElementFactory.h" + +#include "$parameters{'namespace'}Names.h" +#if ENABLE(DASHBOARD_SUPPORT) +#include "Document.h" +#include "Settings.h" +#endif -#include "$parameters{namespace}Names.h" END ; +if ($parameters{'namespace'} eq "HTML") { + print F "#include \"HTMLFormElement.h\"\n"; +} + printElementIncludes($F); print F <<END #include <wtf/HashMap.h> -#if ENABLE(DASHBOARD_SUPPORT) -#include "Document.h" -#include "Settings.h" -#endif - namespace WebCore { -using namespace $parameters{namespace}Names; +using namespace $parameters{'namespace'}Names; END ; -print F "typedef PassRefPtr<$parameters{namespace}Element> (*ConstructorFunction)(const QualifiedName&, Document*"; -print F ", HTMLFormElement*" if $parameters{namespace} eq "HTML"; +print F "typedef PassRefPtr<$parameters{'namespace'}Element> (*ConstructorFunction)(const QualifiedName&, Document*"; + +if ($parameters{'namespace'} eq "HTML") { + print F ", HTMLFormElement*"; +} + print F ", bool createdByParser);\n"; print F <<END typedef HashMap<AtomicStringImpl*, ConstructorFunction> FunctionMap; @@ -694,7 +697,7 @@ my %tagConstructorMap = buildConstructorMap(); printConstructors($F, \%tagConstructorMap); -print F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith}; +print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; print F <<END static void addTag(const QualifiedName& tag, ConstructorFunction func) @@ -702,10 +705,10 @@ static void addTag(const QualifiedName& tag, ConstructorFunction func) gFunctionMap->set(tag.localName().impl(), func); } -static void createFunctionMap() +static inline void createFunctionMapIfNecessary() { - ASSERT(!gFunctionMap); - + if (gFunctionMap) + return; // Create the table. gFunctionMap = new FunctionMap; @@ -716,25 +719,30 @@ END printFunctionInits($F, \%tagConstructorMap); print F "}\n"; -print F "#endif\n" if $parameters{guardFactoryWith}; +print F "#endif\n" if $parameters{'guardFactoryWith'}; + +print F "\nPassRefPtr<$parameters{'namespace'}Element> $parameters{'namespace'}ElementFactory::create$parameters{'namespace'}Element(const QualifiedName& qName, Document* doc"; + +if ($parameters{"namespace"} eq "HTML") { + print F ", HTMLFormElement* formElement"; +} -print F "\nPassRefPtr<$parameters{namespace}Element> $parameters{namespace}ElementFactory::create$parameters{namespace}Element(const QualifiedName& qName, Document* document"; -print F ", HTMLFormElement* formElement" if $parameters{namespace} eq "HTML"; print F ", bool createdByParser)\n{\n"; -print F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith}; +print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; print F <<END - if (!document) + // Don't make elements without a document + if (!doc) return 0; END ; -if ($parameters{namespace} ne "HTML") { +if ($parameters{'namespace'} ne "HTML") { print F <<END #if ENABLE(DASHBOARD_SUPPORT) - Settings* settings = document->settings(); + Settings* settings = doc->settings(); if (settings && settings->usesDashboardBackwardCompatibilityMode()) return 0; #endif @@ -744,21 +752,21 @@ END } print F <<END - if (!gFunctionMap) - createFunctionMap(); - if (ConstructorFunction function = gFunctionMap->get(qName.localName().impl())) + createFunctionMapIfNecessary(); + ConstructorFunction func = gFunctionMap->get(qName.localName().impl()); + if (func) END ; -if ($parameters{namespace} eq "HTML") { - print F " return function(qName, document, formElement, createdByParser);\n"; +if ($parameters{"namespace"} eq "HTML") { + print F " return func(qName, doc, formElement, createdByParser);\n"; } else { - print F " return function(qName, document, createdByParser);\n"; + print F " return func(qName, doc, createdByParser);\n"; } -print F " return new $parameters{namespace}Element(qName, document);\n"; +print F " return new $parameters{'namespace'}Element(qName, doc);\n"; -if ($parameters{guardFactoryWith}) { +if ($parameters{'guardFactoryWith'}) { print F <<END #else @@ -789,8 +797,8 @@ sub printFactoryHeaderFile printLicenseHeader($F); print F<<END -#ifndef $parameters{namespace}ElementFactory_h -#define $parameters{namespace}ElementFactory_h +#ifndef $parameters{'namespace'}ElementFactory_h +#define $parameters{'namespace'}ElementFactory_h #include <wtf/PassRefPtr.h> @@ -803,29 +811,35 @@ namespace WebCore { namespace WebCore { - class $parameters{namespace}Element; + class $parameters{'namespace'}Element; END ; -print F " class HTMLFormElement;\n" if $parameters{namespace} eq "HTML"; +if ($parameters{'namespace'} eq "HTML") { + print F " class HTMLFormElement;\n"; +} print F<<END // The idea behind this class is that there will eventually be a mapping from namespace URIs to ElementFactories that can dispense // elements. In a compound document world, the generic createElement function (will end up being virtual) will be called. - class $parameters{namespace}ElementFactory { + class $parameters{'namespace'}ElementFactory { public: PassRefPtr<Element> createElement(const WebCore::QualifiedName&, WebCore::Document*, bool createdByParser = true); END ; -print F " static PassRefPtr<$parameters{namespace}Element> create$parameters{namespace}Element(const WebCore::QualifiedName&, WebCore::Document*"; -print F ", HTMLFormElement* = 0" if $parameters{namespace} eq "HTML"; +print F " static PassRefPtr<$parameters{'namespace'}Element> create$parameters{'namespace'}Element(const WebCore::QualifiedName&, WebCore::Document*"; + +if ($parameters{'namespace'} eq "HTML") { + print F ", HTMLFormElement* = 0"; +} + print F ", bool /*createdByParser*/ = true);\n"; printf F<<END }; } -#endif // $parameters{namespace}ElementFactory_h +#endif // $parameters{'namespace'}ElementFactory_h END ; @@ -840,7 +854,7 @@ sub usesDefaultJSWrapper my $name = shift; # A tag reuses the default wrapper if its JSInterfaceName matches the default namespace Element. - return $tags{$name}{JSInterfaceName} eq $parameters{namespace} . "Element" || $tags{$name}{JSInterfaceName} eq "HTMLNoScriptElement"; + return $tags{$name}{'JSInterfaceName'} eq $parameters{"namespace"} . "Element" || $tags{$name}{'JSInterfaceName'} eq "HTMLNoScriptElement"; } sub printWrapperFunctions @@ -850,11 +864,11 @@ sub printWrapperFunctions my %tagsSeen; for my $tagName (sort keys %tags) { # Avoid defining the same wrapper method twice. - my $JSInterfaceName = $tags{$tagName}{JSInterfaceName}; + my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"}; next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); $tagsSeen{$JSInterfaceName} = 1; - my $conditional = $tags{$tagName}{conditional}; + my $conditional = $tags{$tagName}{"conditional"}; if ($conditional) { my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; print F "#if ${conditionalString}\n\n"; @@ -862,12 +876,12 @@ sub printWrapperFunctions # Hack for the media tags # FIXME: This should have been done via a CustomWrapper attribute and a separate *Custom file. - if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) { + if ($tags{$tagName}{"wrapperOnlyIfMediaIsAvailable"}) { print F <<END -static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{'namespace'}Element> element) { if (!MediaPlayer::isAvailable()) - return CREATE_DOM_NODE_WRAPPER(exec, globalObject, $parameters{namespace}Element, element.get()); + return CREATE_DOM_NODE_WRAPPER(exec, globalObject, $parameters{'namespace'}Element, element.get()); return CREATE_DOM_NODE_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get()); } @@ -875,7 +889,7 @@ END ; } else { print F <<END -static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{'namespace'}Element> element) { return CREATE_DOM_NODE_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get()); } @@ -883,7 +897,6 @@ static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObjec END ; } - if ($conditional) { print F "#endif\n\n"; } @@ -900,13 +913,13 @@ sub printWrapperFactoryCppFile print F "#include \"config.h\"\n\n"; - print F "#if $parameters{guardFactoryWith}\n\n" if $parameters{guardFactoryWith}; + print F "#if $parameters{'guardFactoryWith'}\n\n" if $parameters{'guardFactoryWith'}; - print F "#include \"JS$parameters{namespace}ElementWrapperFactory.h\"\n"; + print F "#include \"JS$parameters{'namespace'}ElementWrapperFactory.h\"\n"; printJSElementIncludes($F); - print F "\n#include \"$parameters{namespace}Names.h\"\n\n"; + print F "\n#include \"$parameters{'namespace'}Names.h\"\n\n"; printElementIncludes($F); @@ -917,9 +930,9 @@ using namespace JSC; namespace WebCore { -using namespace $parameters{namespace}Names; +using namespace $parameters{'namespace'}Names; -typedef JSNode* (*Create$parameters{namespace}ElementWrapperFunction)(ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{namespace}Element>); +typedef JSNode* (*Create$parameters{'namespace'}ElementWrapperFunction)(ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{'namespace'}Element>); END ; @@ -927,9 +940,9 @@ END printWrapperFunctions($F); print F <<END -JSNode* createJS$parameters{namespace}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +JSNode* createJS$parameters{'namespace'}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{'namespace'}Element> element) { - typedef HashMap<WebCore::AtomicStringImpl*, Create$parameters{namespace}ElementWrapperFunction> FunctionMap; + typedef HashMap<WebCore::AtomicStringImpl*, Create$parameters{'namespace'}ElementWrapperFunction> FunctionMap; DEFINE_STATIC_LOCAL(FunctionMap, map, ()); if (map.isEmpty()) { END @@ -939,13 +952,13 @@ END # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper. next if usesDefaultJSWrapper($tag, \%tags); - my $conditional = $tags{$tag}{conditional}; + my $conditional = $tags{$tag}{"conditional"}; if ($conditional) { my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")"; print F "#if ${conditionalString}\n"; } - my $ucTag = $tags{$tag}{JSInterfaceName}; + my $ucTag = $tags{$tag}{"JSInterfaceName"}; print F " map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n"; if ($conditional) { @@ -955,10 +968,10 @@ END print F <<END } - Create$parameters{namespace}ElementWrapperFunction createWrapperFunction = map.get(element->localName().impl()); + Create$parameters{'namespace'}ElementWrapperFunction createWrapperFunction = map.get(element->localName().impl()); if (createWrapperFunction) return createWrapperFunction(exec, globalObject, element); - return CREATE_DOM_NODE_WRAPPER(exec, globalObject, $parameters{namespace}Element, element.get()); + return CREATE_DOM_NODE_WRAPPER(exec, globalObject, $parameters{'namespace'}Element, element.get()); } } @@ -966,7 +979,7 @@ END END ; - print F "#endif\n" if $parameters{guardFactoryWith}; + print F "#endif\n" if $parameters{'guardFactoryWith'}; close F; } @@ -979,10 +992,10 @@ sub printWrapperFactoryHeaderFile printLicenseHeader($F); - print F "#ifndef JS$parameters{namespace}ElementWrapperFactory_h\n"; - print F "#define JS$parameters{namespace}ElementWrapperFactory_h\n\n"; + print F "#ifndef JS$parameters{'namespace'}ElementWrapperFactory_h\n"; + print F "#define JS$parameters{'namespace'}ElementWrapperFactory_h\n\n"; - print F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith}; + print F "#if $parameters{'guardFactoryWith'}\n" if $parameters{'guardFactoryWith'}; print F <<END #include <wtf/Forward.h> @@ -995,18 +1008,18 @@ namespace WebCore { class JSNode; class JSDOMGlobalObject; - class $parameters{namespace}Element; + class $parameters{'namespace'}Element; - JSNode* createJS$parameters{namespace}Wrapper(JSC::ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{namespace}Element>); + JSNode* createJS$parameters{'namespace'}Wrapper(JSC::ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{'namespace'}Element>); } END ; - print F "#endif // $parameters{guardFactoryWith}\n\n" if $parameters{guardFactoryWith}; + print F "#endif // $parameters{'guardFactoryWith'}\n\n" if $parameters{'guardFactoryWith'}; - print F "#endif // JS$parameters{namespace}ElementWrapperFactory_h\n"; + print F "#endif // JS$parameters{'namespace'}ElementWrapperFactory_h\n"; close F; } |