Get rid of Node::createRareData
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2013 07:36:55 +0000 (07:36 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2013 07:36:55 +0000 (07:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=106981

Reviewed by Benjamin Poulain.

Deleted Node::createRareData. Node::ensureRareData() instantiates NodeRareData
or ElementRareData according to the node type. Also encapsulate new by create
functions in NodeRareData and ElementRareData.

* dom/Element.cpp:
(WebCore):
* dom/Element.h:
(Element):
* dom/ElementRareData.h:
(WebCore::ElementRareData::create):
(ElementRareData):
(WebCore::ElementRareData::ElementRareData):
* dom/Node.cpp:
(WebCore::Node::ensureRareData):
(WebCore):
* dom/Node.h:
(WebCore::NodeRareDataBase::NodeRareDataBase):
* dom/NodeRareData.h:
(NodeRareData):
(WebCore::NodeRareData::create):
(WebCore::NodeRareData::NodeRareData):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139839 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementRareData.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/NodeRareData.h

index 515d9ef4298ff801f97075d8a8323383fcccd09a..70975ddde991316fff9ea18f2b9e0950bcbacf2f 100644 (file)
@@ -1,3 +1,32 @@
+2013-01-16  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Get rid of Node::createRareData
+        https://bugs.webkit.org/show_bug.cgi?id=106981
+
+        Reviewed by Benjamin Poulain.
+
+        Deleted Node::createRareData. Node::ensureRareData() instantiates NodeRareData
+        or ElementRareData according to the node type. Also encapsulate new by create
+        functions in NodeRareData and ElementRareData.
+
+        * dom/Element.cpp:
+        (WebCore):
+        * dom/Element.h:
+        (Element):
+        * dom/ElementRareData.h:
+        (WebCore::ElementRareData::create):
+        (ElementRareData):
+        (WebCore::ElementRareData::ElementRareData):
+        * dom/Node.cpp:
+        (WebCore::Node::ensureRareData):
+        (WebCore):
+        * dom/Node.h:
+        (WebCore::NodeRareDataBase::NodeRareDataBase):
+        * dom/NodeRareData.h:
+        (NodeRareData):
+        (WebCore::NodeRareData::create):
+        (WebCore::NodeRareData::NodeRareData):
+
 2013-01-15  Ryosuke Niwa  <rniwa@webkit.org>
 
         GTK+ and Qt build fix after r139833.
index f79aa323877bb82f9cd88e1fe981454b9bbb0635..fcd0cdf453e9fd2708ed23e7ac4493b8269a43a1 100644 (file)
@@ -223,11 +223,6 @@ inline ElementRareData* Element::ensureElementRareData()
     return static_cast<ElementRareData*>(ensureRareData());
 }
 
-PassOwnPtr<NodeRareData> Element::createRareData()
-{
-    return adoptPtr(new ElementRareData());
-}
-
 void Element::clearTabIndexExplicitlyIfNeeded()
 {
     if (hasRareData())
index 685de35fa23f68481b0cfb4aa00a112064f6a026..0ba54d2703ed26d92f4c4dd77da2ec810a87404e 100644 (file)
@@ -580,7 +580,6 @@ private:
     virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren();
 
     QualifiedName m_tagName;
-    virtual PassOwnPtr<NodeRareData> createRareData();
     bool rareDataStyleAffectedByEmpty() const;
     bool rareDataChildrenAffectedByHover() const;
     bool rareDataChildrenAffectedByActive() const;
index 8c73beff95b4495d7f7c97d2b8fa2b06692f5156..8ab594405dd7946dcc08321e4feac2b918e9f145 100644 (file)
@@ -35,7 +35,8 @@ namespace WebCore {
 
 class ElementRareData : public NodeRareData {
 public:
-    ElementRareData();
+    static PassOwnPtr<ElementRareData> create(RenderObject* renderer) { return adoptPtr(new ElementRareData(renderer)); }
+
     ~ElementRareData();
 
     void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
@@ -172,6 +173,7 @@ private:
     RefPtr<PseudoElement> m_generatedBefore;
     RefPtr<PseudoElement> m_generatedAfter;
 
+    ElementRareData(RenderObject*);
     void releasePseudoElement(PseudoElement*);
 };
 
@@ -180,8 +182,9 @@ inline IntSize defaultMinimumSizeForResizing()
     return IntSize(LayoutUnit::max(), LayoutUnit::max());
 }
 
-inline ElementRareData::ElementRareData()
-    : m_tabIndex(0)
+inline ElementRareData::ElementRareData(RenderObject* renderer)
+    : NodeRareData(renderer)
+    , m_tabIndex(0)
     , m_childIndex(0)
     , m_tabIndexWasSetExplicitly(false)
     , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
index a0d1fef35bf81282da9bb92fd0db8d6fc7feda3c..540bc17afb7507da967b0f7443812686b199ccd0 100644 (file)
@@ -452,19 +452,18 @@ NodeRareData* Node::ensureRareData()
     if (hasRareData())
         return rareData();
 
-    NodeRareData* data = createRareData().leakPtr();
+    NodeRareData* data;
+    if (isElementNode())
+        data = ElementRareData::create(m_data.m_renderer).leakPtr();
+    else
+        data = NodeRareData::create(m_data.m_renderer).leakPtr();
     ASSERT(data);
-    data->setRenderer(m_data.m_renderer);
+
     m_data.m_rareData = data;
     setFlag(HasRareDataFlag);
     return data;
 }
 
-PassOwnPtr<NodeRareData> Node::createRareData()
-{
-    return adoptPtr(new NodeRareData());
-}
-
 void Node::clearRareData()
 {
     ASSERT(hasRareData());
index 1845ff8839a5891fe143b2b28245f04fbe169fde..0e01cee8558c5e82ae7ec8ed1556936481fe4199 100644 (file)
@@ -116,7 +116,9 @@ public:
     void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
 
 protected:
-    NodeRareDataBase() { }
+    NodeRareDataBase(RenderObject* renderer)
+        : m_renderer(renderer)
+    { }
 
 private:
     RenderObject* m_renderer;
@@ -785,8 +787,6 @@ private:
     virtual void refEventTarget();
     virtual void derefEventTarget();
 
-    virtual PassOwnPtr<NodeRareData> createRareData();
-
     virtual RenderStyle* nonRendererStyle() const { return 0; }
 
     virtual const AtomicString& virtualPrefix() const;
index 2720af6725fb609802e6884dffeb287244a70612..9228b76cb71ac0f61be3a030d00933ac528485d6 100644 (file)
@@ -276,9 +276,8 @@ private:
 
 class NodeRareData : public NodeRareDataBase {
     WTF_MAKE_NONCOPYABLE(NodeRareData); WTF_MAKE_FAST_ALLOCATED;
-public:    
-    NodeRareData()
-    { }
+public:
+    static PassOwnPtr<NodeRareData> create(RenderObject* renderer) { return adoptPtr(new NodeRareData(renderer)); }
 
     void clearNodeLists() { m_nodeLists.clear(); }
     NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
@@ -309,6 +308,11 @@ public:
     // This member function is intentionially not virtual to avoid adding a vtable pointer.
     void reportMemoryUsage(MemoryObjectInfo*) const;
 
+protected:
+    NodeRareData(RenderObject* renderer)
+        : NodeRareDataBase(renderer)
+    { }
+
 private:
     OwnPtr<NodeListsNodeData> m_nodeLists;
     OwnPtr<NodeMutationObserverData> m_mutationObserverData;