Title: [87123] trunk/Source/WebCore
Revision
87123
Author
[email protected]
Date
2011-05-23 20:31:34 -0700 (Mon, 23 May 2011)

Log Message

2011-05-20  MORITA Hajime  <[email protected]>

        Reviewed by Dimitri Glazkov.

        [Refactoring] attach() following detach() should be replaced with Node::reattach()
        https://bugs.webkit.org/show_bug.cgi?id=61011

        - Renamed forceReattach() to reattach()
        - Introduced reattachIfAttached() as a variant.

        No new tests. No behavior change.

        * dom/CharacterData.cpp:
        (WebCore::CharacterData::updateRenderer):
        * dom/Element.cpp:
        (WebCore::Element::recalcStyle):
        * dom/Node.h:
        (WebCore::Node::reattach):
        (WebCore::Node::reattachIfAttached):
        * dom/Text.cpp:
        (WebCore::Text::recalcStyle):
        * html/HTMLDetailsElement.cpp:
        (WebCore::HTMLDetailsElement::refreshMainSummary):
        (WebCore::HTMLDetailsElement::parseMappedAttribute):
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::parseMappedAttribute):
        * html/HTMLObjectElement.cpp:
        (WebCore::HTMLObjectElement::renderFallbackContent):
        * html/HTMLPlugInImageElement.cpp:
        (WebCore::HTMLPlugInImageElement::recalcStyle):
        * html/HTMLSelectElement.cpp:
        (WebCore::HTMLSelectElement::parseMappedAttribute):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (87122 => 87123)


--- trunk/Source/WebCore/ChangeLog	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/ChangeLog	2011-05-24 03:31:34 UTC (rev 87123)
@@ -1,3 +1,36 @@
+2011-05-20  MORITA Hajime  <[email protected]>
+
+        Reviewed by Dimitri Glazkov.
+        
+        [Refactoring] attach() following detach() should be replaced with Node::reattach()
+        https://bugs.webkit.org/show_bug.cgi?id=61011
+
+        - Renamed forceReattach() to reattach()
+        - Introduced reattachIfAttached() as a variant.
+        
+        No new tests. No behavior change.
+
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::updateRenderer):
+        * dom/Element.cpp:
+        (WebCore::Element::recalcStyle):
+        * dom/Node.h:
+        (WebCore::Node::reattach):
+        (WebCore::Node::reattachIfAttached):
+        * dom/Text.cpp:
+        (WebCore::Text::recalcStyle):
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::HTMLDetailsElement::refreshMainSummary):
+        (WebCore::HTMLDetailsElement::parseMappedAttribute):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::parseMappedAttribute):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::renderFallbackContent):
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::recalcStyle):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::parseMappedAttribute):
+
 2011-05-23  Mark Rowe  <[email protected]>
 
         Build fix after r87117.

Modified: trunk/Source/WebCore/dom/CharacterData.cpp (87122 => 87123)


--- trunk/Source/WebCore/dom/CharacterData.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/dom/CharacterData.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -182,8 +182,7 @@
 void CharacterData::updateRenderer(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData)
 {
     if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) {
-        detach();
-        attach();
+        reattach();
     } else if (renderer())
         toRenderText(renderer())->setTextWithOffset(m_data, offsetOfReplacedData, lengthOfReplacedData);
 }

Modified: trunk/Source/WebCore/dom/Element.cpp (87122 => 87123)


--- trunk/Source/WebCore/dom/Element.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/dom/Element.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -1086,9 +1086,8 @@
         RefPtr<RenderStyle> newStyle = styleForRenderer();
         StyleChange ch = diff(currentStyle.get(), newStyle.get());
         if (ch == Detach || !currentStyle) {
-            if (attached())
-                detach();
-            attach(); // FIXME: The style gets computed twice by calling attach. We could do better if we passed the style along.
+            // FIXME: The style gets computed twice by calling attach. We could do better if we passed the style along.
+            reattach();
             // attach recalulates the style for all children. No need to do it twice.
             clearNeedsStyleRecalc();
             clearChildNeedsStyleRecalc();

Modified: trunk/Source/WebCore/dom/Node.h (87122 => 87123)


--- trunk/Source/WebCore/dom/Node.h	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/dom/Node.h	2011-05-24 03:31:34 UTC (rev 87123)
@@ -451,7 +451,8 @@
     // the node's rendering object from the rendering tree and delete it.
     virtual void detach();
 
-    void forceReattach();
+    void reattach();
+    void reattachIfAttached();
 
     virtual void willRemove();
     void createRendererIfNeeded();
@@ -739,14 +740,19 @@
     return parentOrHostNode();
 }
 
-inline void Node::forceReattach()
+inline void Node::reattach()
 {
-    if (!attached())
-        return;
-    detach();
+    if (attached())
+        detach();
     attach();
 }
 
+inline void Node::reattachIfAttached()
+{
+    if (attached())
+        reattach();
+}
+
 } //namespace
 
 #ifndef NDEBUG

Modified: trunk/Source/WebCore/dom/ShadowContentSelector.cpp (87122 => 87123)


--- trunk/Source/WebCore/dom/ShadowContentSelector.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/dom/ShadowContentSelector.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -62,7 +62,7 @@
         if (!contentElement->shouldInclude(child))
             continue;
 
-        child->forceReattach();
+        child->reattach();
         m_children[i] = 0;
     }
 

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (87122 => 87123)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -84,7 +84,7 @@
 void ShadowRoot::recalcStyle(StyleChange change)
 {
     if (hasContentElement())
-        forceReattach();
+        reattach();
     else {
         for (Node* n = firstChild(); n; n = n->nextSibling())
             n->recalcStyle(change);

Modified: trunk/Source/WebCore/dom/Text.cpp (87122 => 87123)


--- trunk/Source/WebCore/dom/Text.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/dom/Text.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -265,11 +265,8 @@
         if (renderer()) {
             if (renderer()->isText())
                 toRenderText(renderer())->setText(dataImpl());
-        } else {
-            if (attached())
-                detach();
-            attach();
-        }
+        } else
+            reattach();
     }
     clearNeedsStyleRecalc();
 }

Modified: trunk/Source/WebCore/html/HTMLDetailsElement.cpp (87122 => 87123)


--- trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -146,15 +146,10 @@
     if (oldSummary == m_mainSummary || !attached())
         return;
 
-    if (oldSummary && oldSummary->parentNodeForRenderingAndStyle()) {
-        oldSummary->detach();
-        oldSummary->attach();
-    }
-        
-    if (m_mainSummary && refreshRenderer == RefreshRendererAllowed) {
-        m_mainSummary->detach();
-        m_mainSummary->attach();
-    }
+    if (oldSummary && oldSummary->parentNodeForRenderingAndStyle())
+        oldSummary->reattach();
+    if (m_mainSummary && refreshRenderer == RefreshRendererAllowed)
+        m_mainSummary->reattach();
 }
 
 void HTMLDetailsElement::createShadowSubtree()
@@ -196,10 +191,8 @@
     if (attr->name() == openAttr) {
         bool oldValue = m_isOpen;
         m_isOpen =  !attr->value().isNull();
-        if (attached() && oldValue != m_isOpen) {
-            detach();
-            attach();
-        }
+        if (oldValue != m_isOpen)
+            reattachIfAttached();
     } else
         HTMLElement::parseMappedAttribute(attr);
 }

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (87122 => 87123)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -721,10 +721,8 @@
         m_maxResults = !attr->isNull() ? std::min(attr->value().toInt(), maxSavedResults) : -1;
         // FIXME: Detaching just for maxResults change is not ideal.  We should figure out the right
         // time to relayout for this change.
-        if (m_maxResults != oldResults && (m_maxResults <= 0 || oldResults <= 0) && attached()) {
-            detach();
-            attach();
-        }
+        if (m_maxResults != oldResults && (m_maxResults <= 0 || oldResults <= 0))
+            reattachIfAttached();
         setNeedsStyleRecalc();
     } else if (attr->name() == autosaveAttr || attr->name() == incrementalAttr)
         setNeedsStyleRecalc();

Modified: trunk/Source/WebCore/html/HTMLObjectElement.cpp (87122 => 87123)


--- trunk/Source/WebCore/html/HTMLObjectElement.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/html/HTMLObjectElement.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -378,9 +378,8 @@
         m_serviceType = m_imageLoader->image()->response().mimeType();
         if (!isImageType()) {
             // If we don't think we have an image type anymore, then clear the image from the loader.
-            m_imageLoader->setImage(0);        
-            detach();
-            attach();
+            m_imageLoader->setImage(0);
+            reattach();
             return;
         }
     }

Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp (87122 => 87123)


--- trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -124,10 +124,8 @@
 void HTMLPlugInImageElement::recalcStyle(StyleChange ch)
 {
     // FIXME: Why is this necessary?  Manual re-attach is almost always wrong.
-    if (!useFallbackContent() && needsWidgetUpdate() && renderer() && !isImageType()) {
-        detach();
-        attach();
-    }
+    if (!useFallbackContent() && needsWidgetUpdate() && renderer() && !isImageType())
+        reattach();
     HTMLPlugInElement::recalcStyle(ch);
 }
 

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (87122 => 87123)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2011-05-24 03:26:30 UTC (rev 87122)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2011-05-24 03:31:34 UTC (rev 87123)
@@ -264,8 +264,7 @@
         m_data.setSize(size);
         setNeedsValidityCheck();
         if ((oldUsesMenuList != m_data.usesMenuList() || (!oldUsesMenuList && m_data.size() != oldSize)) && attached()) {
-            detach();
-            attach();
+            reattach();
             setRecalcListItems();
         }
     } else if (attr->name() == multipleAttr)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to