Title: [136574] trunk/Source/WebCore
Revision
136574
Author
[email protected]
Date
2012-12-04 14:42:57 -0800 (Tue, 04 Dec 2012)

Log Message

Automatically handle suspend and resume of post attach callbacks
https://bugs.webkit.org/show_bug.cgi?id=103910

Patch by Elliott Sprehn <[email protected]> on 2012-12-04
Reviewed by Eric Seidel.

Use RAII to handle suspend and resume of post attach callbacks since
they should always be called in pairs.

No new tests, just refactoring.

* dom/ContainerNode.h:
(PostAttachCallbackDisabler):
(WebCore::PostAttachCallbackDisabler::PostAttachCallbackDisabler):
(WebCore::PostAttachCallbackDisabler::~PostAttachCallbackDisabler):
(ContainerNode):
* dom/Document.cpp:
(WebCore::Document::recalcStyle):
* dom/Element.cpp:
(WebCore::Element::attach):
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::attach):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::attach):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::attach):
(WebCore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (136573 => 136574)


--- trunk/Source/WebCore/ChangeLog	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/ChangeLog	2012-12-04 22:42:57 UTC (rev 136574)
@@ -1,5 +1,34 @@
 2012-12-04  Elliott Sprehn  <[email protected]>
 
+        Automatically handle suspend and resume of post attach callbacks
+        https://bugs.webkit.org/show_bug.cgi?id=103910
+
+        Reviewed by Eric Seidel.
+
+        Use RAII to handle suspend and resume of post attach callbacks since
+        they should always be called in pairs.
+
+        No new tests, just refactoring.
+
+        * dom/ContainerNode.h:
+        (PostAttachCallbackDisabler):
+        (WebCore::PostAttachCallbackDisabler::PostAttachCallbackDisabler):
+        (WebCore::PostAttachCallbackDisabler::~PostAttachCallbackDisabler):
+        (ContainerNode):
+        * dom/Document.cpp:
+        (WebCore::Document::recalcStyle):
+        * dom/Element.cpp:
+        (WebCore::Element::attach):
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::attach):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::attach):
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::attach):
+        (WebCore):
+
+2012-12-04  Elliott Sprehn  <[email protected]>
+
         createRareData should return a PassOwnPtr
         https://bugs.webkit.org/show_bug.cgi?id=103851
 

Modified: trunk/Source/WebCore/dom/ContainerNode.h (136573 => 136574)


--- trunk/Source/WebCore/dom/ContainerNode.h	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2012-12-04 22:42:57 UTC (rev 136574)
@@ -78,6 +78,7 @@
 };
 
 class ContainerNode : public Node {
+    friend class PostAttachCallbackDisabler;
 public:
     virtual ~ContainerNode();
 
@@ -150,8 +151,6 @@
 
     static void queuePostAttachCallback(NodeCallback, Node*, unsigned = 0);
     static bool postAttachCallbacksAreSuspended();
-    void suspendPostAttachCallbacks();
-    void resumePostAttachCallbacks();
 
     template<class GenericNode, class GenericNodeContainer>
     friend void appendChildToContainer(GenericNode* child, GenericNodeContainer*);
@@ -167,6 +166,8 @@
     void insertBeforeCommon(Node* nextChild, Node* oldChild);
 
     static void dispatchPostAttachCallbacks();
+    void suspendPostAttachCallbacks();
+    void resumePostAttachCallbacks();
 
     bool getUpperLeftCorner(FloatPoint&) const;
     bool getLowerRightCorner(FloatPoint&) const;
@@ -394,6 +395,24 @@
     ChildNodesLazySnapshot* m_nextSnapshot;
 };
 
+class PostAttachCallbackDisabler {
+public:
+    PostAttachCallbackDisabler(ContainerNode* node)
+        : m_node(node)
+    {
+        ASSERT(m_node);
+        m_node->suspendPostAttachCallbacks();
+    }
+
+    ~PostAttachCallbackDisabler()
+    {
+        m_node->resumePostAttachCallbacks();
+    }
+
+private:
+    ContainerNode* m_node;
+};
+
 } // namespace WebCore
 
 #endif // ContainerNode_h

Modified: trunk/Source/WebCore/dom/Document.cpp (136573 => 136574)


--- trunk/Source/WebCore/dom/Document.cpp	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-12-04 22:42:57 UTC (rev 136574)
@@ -1813,8 +1813,8 @@
         m_styleSheetCollection->setUsesRemUnit(true);
 
     m_inStyleRecalc = true;
-    suspendPostAttachCallbacks();
     {
+        PostAttachCallbackDisabler disabler(this);
         WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
 
         RefPtr<FrameView> frameView = view();
@@ -1870,7 +1870,6 @@
             frameView->endDeferredRepaints();
         }
     }
-    resumePostAttachCallbacks();
 
     // If we wanted to call implicitClose() during recalcStyle, do so now that we're finished.
     if (m_closeAfterStyleRecalc) {

Modified: trunk/Source/WebCore/dom/Element.cpp (136573 => 136574)


--- trunk/Source/WebCore/dom/Element.cpp	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-12-04 22:42:57 UTC (rev 136574)
@@ -1143,36 +1143,32 @@
 
 void Element::attach()
 {
-    suspendPostAttachCallbacks();
-    {
-        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
-        createRendererIfNeeded();
+    PostAttachCallbackDisabler callbackDisabler(this);
+    StyleResolverParentPusher parentPusher(this);
+    WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
 
-        StyleResolverParentPusher parentPusher(this);
+    createRendererIfNeeded();
 
-        if (parentElement() && parentElement()->isInCanvasSubtree())
-            setIsInCanvasSubtree(true);
+    if (parentElement() && parentElement()->isInCanvasSubtree())
+        setIsInCanvasSubtree(true);
 
-        // When a shadow root exists, it does the work of attaching the children.
-        if (ElementShadow* shadow = this->shadow()) {
-            parentPusher.push();
-            shadow->attach();
-        } else {
-            if (firstChild())
-                parentPusher.push();
-        }
-        ContainerNode::attach();
+    // When a shadow root exists, it does the work of attaching the children.
+    if (ElementShadow* shadow = this->shadow()) {
+        parentPusher.push();
+        shadow->attach();
+    } else if (firstChild())
+        parentPusher.push();
 
-        if (hasRareData()) {   
-            ElementRareData* data = ""
-            if (data->needsFocusAppearanceUpdateSoonAfterAttach()) {
-                if (isFocusable() && document()->focusedNode() == this)
-                    document()->updateFocusAppearanceSoon(false /* don't restore selection */);
-                data->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
-            }
+    ContainerNode::attach();
+
+    if (hasRareData()) {   
+        ElementRareData* data = ""
+        if (data->needsFocusAppearanceUpdateSoonAfterAttach()) {
+            if (isFocusable() && document()->focusedNode() == this)
+                document()->updateFocusAppearanceSoon(false /* don't restore selection */);
+            data->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
         }
     }
-    resumePostAttachCallbacks();
 }
 
 void Element::unregisterNamedFlowContentNode()

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (136573 => 136574)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2012-12-04 22:42:57 UTC (rev 136574)
@@ -204,10 +204,8 @@
 
 void HTMLFormControlElement::attach()
 {
-    ASSERT(!attached());
+    PostAttachCallbackDisabler disabler(this);
 
-    suspendPostAttachCallbacks();
-
     HTMLElement::attach();
 
     // The call to updateFromElement() needs to go after the call through
@@ -221,8 +219,6 @@
         ref();
         queuePostAttachCallback(focusPostAttach, this);
     }
-
-    resumePostAttachCallbacks();
 }
 
 void HTMLFormControlElement::didMoveToNewDocument(Document* oldDocument)

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (136573 => 136574)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-12-04 22:42:57 UTC (rev 136574)
@@ -774,7 +774,7 @@
 
 void HTMLInputElement::attach()
 {
-    suspendPostAttachCallbacks();
+    PostAttachCallbackDisabler disabler(this);
 
     if (!m_hasType)
         updateType();
@@ -785,8 +785,6 @@
 
     if (document()->focusedNode() == this)
         document()->updateFocusAppearanceSoon(true /* restore selection */);
-
-    resumePostAttachCallbacks();
 }
 
 void HTMLInputElement::detach()

Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp (136573 => 136574)


--- trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2012-12-04 22:42:23 UTC (rev 136573)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2012-12-04 22:42:57 UTC (rev 136574)
@@ -154,7 +154,7 @@
 
 void HTMLPlugInImageElement::attach()
 {
-    suspendPostAttachCallbacks();
+    PostAttachCallbackDisabler disabler(this);
 
     bool isImage = isImageType();
     
@@ -168,10 +168,8 @@
             m_imageLoader = adoptPtr(new HTMLImageLoader(this));
         m_imageLoader->updateFromElement();
     }
-
-    resumePostAttachCallbacks();
 }
-    
+
 void HTMLPlugInImageElement::detach()
 {
     // FIXME: Because of the insanity that is HTMLPlugInImageElement::recalcStyle,
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to