Diff
Modified: trunk/Source/WebCore/ChangeLog (139750 => 139751)
--- trunk/Source/WebCore/ChangeLog 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/ChangeLog 2013-01-15 18:11:30 UTC (rev 139751)
@@ -1,3 +1,50 @@
+2013-01-15 Antti Koivisto <an...@apple.com>
+
+ Move parent pointer from TreeShared to subclass
+ https://bugs.webkit.org/show_bug.cgi?id=106910
+
+ Reviewed by Darin Adler.
+
+ This simplifies both TreeShared and clients, and makes code dealing with parents more understandable in general.
+
+ * dom/Document.h:
+ (WebCore::Node::Node):
+ * dom/Node.cpp:
+ (WebCore::Node::reportMemoryUsage):
+ * dom/Node.h:
+
+ Add m_parentOrHostNode variable (matching the accessor names).
+
+ (Node):
+ (WebCore::Node::hasTreeSharedParent):
+ (WebCore::Node::parentNode):
+ (WebCore::Node::setParentOrHostNode):
+ (WebCore::Node::parentOrHostNode):
+ * platform/TreeShared.h:
+ (WebCore):
+ (WebCore::TreeShared::TreeShared):
+ (WebCore::TreeShared::deref):
+
+ Call subclass hasTreeSharedParent() to figure out if it is time to delete.
+
+ (TreeShared):
+
+ Remove parent pointer and accessors.
+ Remove ParentNodeType template parameter.
+ Remove now unnecessay reportMemoryUsage().
+
+ (WebCore::adopted):
+ * svg/SVGElementInstance.cpp:
+ (WebCore::SVGElementInstance::SVGElementInstance):
+ * svg/SVGElementInstance.h:
+
+ Add m_parentInstance variable.
+
+ (WebCore::SVGElementInstance::setParentOrHostNode):
+ (WebCore::SVGElementInstance::parentNode):
+ (SVGElementInstance):
+ (WebCore::SVGElementInstance::hasTreeSharedParent):
+
2013-01-15 Simon Fraser <simon.fra...@apple.com>
Allow tiled WKViews to have transparent backgrounds
Modified: trunk/Source/WebCore/dom/Document.h (139750 => 139751)
--- trunk/Source/WebCore/dom/Document.h 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/dom/Document.h 2013-01-15 18:11:30 UTC (rev 139751)
@@ -1588,6 +1588,7 @@
inline Node::Node(Document* document, ConstructionType type)
: m_nodeFlags(type)
+ , m_parentOrHostNode(0)
, m_treeScope(document)
, m_previous(0)
, m_next(0)
Modified: trunk/Source/WebCore/dom/Node.cpp (139750 => 139751)
--- trunk/Source/WebCore/dom/Node.cpp 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/dom/Node.cpp 2013-01-15 18:11:30 UTC (rev 139751)
@@ -2572,8 +2572,8 @@
void Node::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
- TreeShared<Node, ContainerNode>::reportMemoryUsage(memoryObjectInfo);
ScriptWrappable::reportMemoryUsage(memoryObjectInfo);
+ info.addMember(m_parentOrHostNode);
info.addMember(m_treeScope);
info.addMember(m_next);
info.addMember(m_previous);
Modified: trunk/Source/WebCore/dom/Node.h (139750 => 139751)
--- trunk/Source/WebCore/dom/Node.h 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/dom/Node.h 2013-01-15 18:11:30 UTC (rev 139751)
@@ -122,7 +122,7 @@
RenderObject* m_renderer;
};
-class Node : public EventTarget, public ScriptWrappable, public TreeShared<Node, ContainerNode> {
+class Node : public EventTarget, public ScriptWrappable, public TreeShared<Node> {
friend class Document;
friend class TreeScope;
friend class TreeScopeAdopter;
@@ -644,8 +644,8 @@
// to event listeners, and prevents DOMActivate events from being sent at all.
virtual bool disabled() const;
- using TreeShared<Node, ContainerNode>::ref;
- using TreeShared<Node, ContainerNode>::deref;
+ using TreeShared<Node>::ref;
+ using TreeShared<Node>::deref;
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
@@ -763,9 +763,10 @@
void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
private:
- friend class TreeShared<Node, ContainerNode>;
+ friend class TreeShared<Node>;
void removedLastRef();
+ bool hasTreeSharedParent() const { return !!parentOrHostNode(); }
enum EditableLevel { Editable, RichlyEditable };
bool rendererIsEditable(EditableLevel, UserSelectAllTreatment = UserSelectAllIsAlwaysNonEditable) const;
@@ -795,18 +796,13 @@
Element* ancestorElement() const;
- // Use Node::parentNode as the consistent way of querying a parent node.
- // This method is made private to ensure a compiler error on call sites that
- // don't follow this rule.
- using TreeShared<Node, ContainerNode>::parent;
- using TreeShared<Node, ContainerNode>::setParent;
-
void trackForDebugging();
Vector<OwnPtr<MutationObserverRegistration> >* mutationObserverRegistry();
HashSet<MutationObserverRegistration*>* transientMutationObserverRegistry();
mutable uint32_t m_nodeFlags;
+ ContainerNode* m_parentOrHostNode;
TreeScope* m_treeScope;
Node* m_previous;
Node* m_next;
@@ -842,19 +838,21 @@
urls.add(url);
}
-inline ContainerNode* Node::parentNode() const
+inline void Node::setParentOrHostNode(ContainerNode* parent)
{
- return isShadowRoot() ? 0 : parent();
+ ASSERT(isMainThread());
+ m_parentOrHostNode = parent;
}
-inline void Node::setParentOrHostNode(ContainerNode* parent)
+inline ContainerNode* Node::parentOrHostNode() const
{
- setParent(parent);
+ ASSERT(isMainThreadOrGCThread());
+ return m_parentOrHostNode;
}
-inline ContainerNode* Node::parentOrHostNode() const
+inline ContainerNode* Node::parentNode() const
{
- return parent();
+ return isShadowRoot() ? 0 : parentOrHostNode();
}
inline ContainerNode* Node::parentNodeGuaranteedHostFree() const
Modified: trunk/Source/WebCore/platform/TreeShared.h (139750 => 139751)
--- trunk/Source/WebCore/platform/TreeShared.h 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/platform/TreeShared.h 2013-01-15 18:11:30 UTC (rev 139751)
@@ -28,16 +28,15 @@
namespace WebCore {
#ifndef NDEBUG
-template<typename NodeType, typename ParentNodeType> class TreeShared;
-template<typename NodeType, typename ParentNodeType> void adopted(TreeShared<NodeType, ParentNodeType>*);
+template<typename NodeType> class TreeShared;
+template<typename NodeType> void adopted(TreeShared<NodeType>*);
#endif
-template<typename NodeType, typename ParentNodeType> class TreeShared {
+template<typename NodeType> class TreeShared {
WTF_MAKE_NONCOPYABLE(TreeShared);
protected:
TreeShared()
- : m_parent(0)
- , m_refCount(1)
+ : m_refCount(1)
#ifndef NDEBUG
, m_adoptionIsRequired(true)
#endif
@@ -74,11 +73,12 @@
ASSERT(!m_deletionHasBegun);
ASSERT(!m_inRemovedLastRefFunction);
ASSERT(!m_adoptionIsRequired);
- if (--m_refCount <= 0 && !m_parent) {
+ NodeType* thisNode = static_cast<NodeType*>(this);
+ if (--m_refCount <= 0 && !thisNode->hasTreeSharedParent()) {
#ifndef NDEBUG
m_inRemovedLastRefFunction = true;
#endif
- static_cast<NodeType*>(this)->removedLastRef();
+ thisNode->removedLastRef();
}
}
@@ -94,35 +94,16 @@
return m_refCount;
}
- void setParent(ParentNodeType* parent)
- {
- ASSERT(isMainThread());
- m_parent = parent;
- }
-
- ParentNodeType* parent() const
- {
- ASSERT(isMainThreadOrGCThread());
- return m_parent;
- }
-
#ifndef NDEBUG
bool m_deletionHasBegun;
bool m_inRemovedLastRefFunction;
#endif
- void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
- {
- MemoryClassInfo info(memoryObjectInfo, this);
- info.addMember(m_parent);
- }
-
private:
#ifndef NDEBUG
- friend void adopted<>(TreeShared<NodeType, ParentNodeType>*);
+ friend void adopted<>(TreeShared<NodeType>*);
#endif
- ParentNodeType* m_parent;
int m_refCount;
#ifndef NDEBUG
@@ -132,7 +113,7 @@
#ifndef NDEBUG
-template<typename NodeType, typename ParentNodeType> inline void adopted(TreeShared<NodeType, ParentNodeType>* object)
+template<typename NodeType> inline void adopted(TreeShared<NodeType>* object)
{
if (!object)
return;
Modified: trunk/Source/WebCore/svg/SVGElementInstance.cpp (139750 => 139751)
--- trunk/Source/WebCore/svg/SVGElementInstance.cpp 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/svg/SVGElementInstance.cpp 2013-01-15 18:11:30 UTC (rev 139751)
@@ -41,7 +41,8 @@
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, instanceCounter, ("WebCoreSVGElementInstance"));
SVGElementInstance::SVGElementInstance(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement)
- : m_correspondingUseElement(correspondingUseElement)
+ : m_parentInstance(0)
+ , m_correspondingUseElement(correspondingUseElement)
, m_directUseElement(directUseElement)
, m_element(originalElement)
, m_previousSibling(0)
Modified: trunk/Source/WebCore/svg/SVGElementInstance.h (139750 => 139751)
--- trunk/Source/WebCore/svg/SVGElementInstance.h 2013-01-15 18:10:28 UTC (rev 139750)
+++ trunk/Source/WebCore/svg/SVGElementInstance.h 2013-01-15 18:11:30 UTC (rev 139751)
@@ -38,7 +38,7 @@
class SVGStyledElement;
// SVGElementInstance mimics Node, but without providing all its functionality
-class SVGElementInstance : public EventTarget, public TreeShared<SVGElementInstance, SVGElementInstance> {
+class SVGElementInstance : public EventTarget, public TreeShared<SVGElementInstance> {
public:
static PassRefPtr<SVGElementInstance> create(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement)
{
@@ -47,7 +47,7 @@
virtual ~SVGElementInstance();
- void setParentOrHostNode(SVGElementInstance* instance) { setParent(instance); }
+ void setParentOrHostNode(SVGElementInstance* instance) { m_parentInstance = instance; }
virtual const AtomicString& interfaceName() const;
virtual ScriptExecutionContext* scriptExecutionContext() const;
@@ -66,7 +66,7 @@
void detach();
- SVGElementInstance* parentNode() const { return parent(); }
+ SVGElementInstance* parentNode() const { return m_parentInstance; }
PassRefPtr<SVGElementInstanceList> childNodes();
SVGElementInstance* previousSibling() const { return m_previousSibling; }
@@ -98,8 +98,8 @@
static void invalidateAllInstancesOfElement(SVGElement*);
- using TreeShared<SVGElementInstance, SVGElementInstance>::ref;
- using TreeShared<SVGElementInstance, SVGElementInstance>::deref;
+ using TreeShared<SVGElementInstance>::ref;
+ using TreeShared<SVGElementInstance>::deref;
// EventTarget API
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), abort);
@@ -145,13 +145,12 @@
private:
friend class SVGUseElement;
- friend class TreeShared<SVGElementInstance, SVGElementInstance>;
+ friend class TreeShared<SVGElementInstance>;
- using TreeShared<SVGElementInstance, SVGElementInstance>::parent;
- using TreeShared<SVGElementInstance, SVGElementInstance>::setParent;
+ SVGElementInstance(SVGUseElement*, SVGUseElement*, PassRefPtr<SVGElement> originalElement);
- SVGElementInstance(SVGUseElement*, SVGUseElement*, PassRefPtr<SVGElement> originalElement);
void removedLastRef();
+ bool hasTreeSharedParent() const { return !!m_parentInstance; }
virtual Node* toNode() { return shadowTreeElement(); }
@@ -180,6 +179,8 @@
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
+ SVGElementInstance* m_parentInstance;
+
SVGUseElement* m_correspondingUseElement;
SVGUseElement* m_directUseElement;
RefPtr<SVGElement> m_element;