Title: [161200] trunk/Source/WebCore
Revision
161200
Author
[email protected]
Date
2014-01-01 16:52:55 -0800 (Wed, 01 Jan 2014)

Log Message

RenderScrollbar: Map of scrollbar parts should use RenderPtr.
<https://webkit.org/b/126367>

Turn RenderScrollbar::m_parts into HashMap of RenderPtrs. This makes
renderer destruction automatic and lets us remove some code.

Reviewed by Antti Koivisto.

* rendering/RenderPtr.h:

    Add HashTraits for RenderPtr so we can use them as values in
    WTF hash tables.

* rendering/RenderScrollbar.h:
* rendering/RenderScrollbar.cpp:
(WebCore::RenderScrollbar::~RenderScrollbar):
(WebCore::RenderScrollbar::setParent):
(WebCore::RenderScrollbar::updateScrollbarParts):
(WebCore::RenderScrollbar::updateScrollbarPart):

    Remove now-unneeded kludges of logic to manually delete scrollbar
    part renderers in various scenarios.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161199 => 161200)


--- trunk/Source/WebCore/ChangeLog	2014-01-02 00:31:40 UTC (rev 161199)
+++ trunk/Source/WebCore/ChangeLog	2014-01-02 00:52:55 UTC (rev 161200)
@@ -1,3 +1,28 @@
+2014-01-01  Andreas Kling  <[email protected]>
+
+        RenderScrollbar: Map of scrollbar parts should use RenderPtr.
+        <https://webkit.org/b/126367>
+
+        Turn RenderScrollbar::m_parts into HashMap of RenderPtrs. This makes
+        renderer destruction automatic and lets us remove some code.
+
+        Reviewed by Antti Koivisto.
+
+        * rendering/RenderPtr.h:
+
+            Add HashTraits for RenderPtr so we can use them as values in
+            WTF hash tables.
+
+        * rendering/RenderScrollbar.h:
+        * rendering/RenderScrollbar.cpp:
+        (WebCore::RenderScrollbar::~RenderScrollbar):
+        (WebCore::RenderScrollbar::setParent):
+        (WebCore::RenderScrollbar::updateScrollbarParts):
+        (WebCore::RenderScrollbar::updateScrollbarPart):
+
+            Remove now-unneeded kludges of logic to manually delete scrollbar
+            part renderers in various scenarios.
+
 2014-01-01  Antti Koivisto  <[email protected]>
 
         Remove reattachRenderTree

Modified: trunk/Source/WebCore/rendering/RenderPtr.h (161199 => 161200)


--- trunk/Source/WebCore/rendering/RenderPtr.h	2014-01-02 00:31:40 UTC (rev 161199)
+++ trunk/Source/WebCore/rendering/RenderPtr.h	2014-01-02 00:52:55 UTC (rev 161200)
@@ -26,10 +26,11 @@
 #ifndef RenderPtr_h
 #define RenderPtr_h
 
-#include <wtf/Assertions.h>
 #include <algorithm>
 #include <cstddef>
 #include <memory>
+#include <wtf/Assertions.h>
+#include <wtf/HashTraits.h>
 
 namespace WebCore {
 
@@ -159,4 +160,17 @@
 
 } // namespace WebCore
 
+namespace WTF {
+
+template<typename T> struct HashTraits<WebCore::RenderPtr<T>> : SimpleClassHashTraits<WebCore::RenderPtr<T>> {
+    typedef std::nullptr_t EmptyValueType;
+    static EmptyValueType emptyValue() { return nullptr; }
+
+    typedef T* PeekType;
+    static T* peek(const WebCore::RenderPtr<T>& value) { return value.get(); }
+    static T* peek(std::nullptr_t) { return nullptr; }
+};
+
+} // namespace WTF
+
 #endif // RenderPtr_h

Modified: trunk/Source/WebCore/rendering/RenderScrollbar.cpp (161199 => 161200)


--- trunk/Source/WebCore/rendering/RenderScrollbar.cpp	2014-01-02 00:31:40 UTC (rev 161199)
+++ trunk/Source/WebCore/rendering/RenderScrollbar.cpp	2014-01-02 00:52:55 UTC (rev 161200)
@@ -68,15 +68,6 @@
 
 RenderScrollbar::~RenderScrollbar()
 {
-    if (!m_parts.isEmpty()) {
-        // When a scrollbar is detached from its parent (causing all parts removal) and 
-        // ready to be destroyed, its destruction can be delayed because of RefPtr
-        // maintained in other classes such as EventHandler (m_lastScrollbarUnderMouse).
-        // Meanwhile, we can have a call to updateScrollbarPart which recreates the 
-        // scrollbar part. So, we need to destroy these parts since we don't want them
-        // to call on a destroyed scrollbar. See webkit bug 68009.
-        updateScrollbarParts(true);
-    }
 }
 
 RenderBox* RenderScrollbar::owningRenderer() const
@@ -92,10 +83,8 @@
 void RenderScrollbar::setParent(ScrollView* parent)
 {
     Scrollbar::setParent(parent);
-    if (!parent) {
-        // Destroy all of the scrollbar's RenderBoxes.
-        updateScrollbarParts(true);
-    }
+    if (!parent)
+        m_parts.clear();
 }
 
 void RenderScrollbar::setEnabled(bool e)
@@ -163,21 +152,18 @@
     return result;
 }
 
-void RenderScrollbar::updateScrollbarParts(bool destroy)
+void RenderScrollbar::updateScrollbarParts()
 {
-    updateScrollbarPart(ScrollbarBGPart, destroy);
-    updateScrollbarPart(BackButtonStartPart, destroy);
-    updateScrollbarPart(ForwardButtonStartPart, destroy);
-    updateScrollbarPart(BackTrackPart, destroy);
-    updateScrollbarPart(ThumbPart, destroy);
-    updateScrollbarPart(ForwardTrackPart, destroy);
-    updateScrollbarPart(BackButtonEndPart, destroy);
-    updateScrollbarPart(ForwardButtonEndPart, destroy);
-    updateScrollbarPart(TrackBGPart, destroy);
+    updateScrollbarPart(ScrollbarBGPart);
+    updateScrollbarPart(BackButtonStartPart);
+    updateScrollbarPart(ForwardButtonStartPart);
+    updateScrollbarPart(BackTrackPart);
+    updateScrollbarPart(ThumbPart);
+    updateScrollbarPart(ForwardTrackPart);
+    updateScrollbarPart(BackButtonEndPart);
+    updateScrollbarPart(ForwardButtonEndPart);
+    updateScrollbarPart(TrackBGPart);
     
-    if (destroy)
-        return;
-
     // See if the scrollbar's thickness changed.  If so, we need to mark our owning object as needing a layout.
     bool isHorizontal = orientation() == HorizontalScrollbar;    
     int oldThickness = isHorizontal ? height() : width();
@@ -220,12 +206,12 @@
     return SCROLLBAR;
 }
 
-void RenderScrollbar::updateScrollbarPart(ScrollbarPart partType, bool destroy)
+void RenderScrollbar::updateScrollbarPart(ScrollbarPart partType)
 {
     if (partType == NoPart)
         return;
 
-    RefPtr<RenderStyle> partStyle = destroy ? nullptr : getScrollbarPseudoStyle(partType, pseudoForScrollbarPart(partType));
+    RefPtr<RenderStyle> partStyle = getScrollbarPseudoStyle(partType, pseudoForScrollbarPart(partType));
     bool needRenderer = partStyle && partStyle->display() != NONE;
 
     if (needRenderer && partStyle->display() != BLOCK) {
@@ -251,18 +237,17 @@
         }
     }
 
-    if (needRenderer) {
-        RenderScrollbarPart*& partRendererSlot = m_parts.add(partType, nullptr).iterator->value;
-        if (partRendererSlot)
-            partRendererSlot->setStyle(partStyle.releaseNonNull());
-        else {
-            partRendererSlot = new RenderScrollbarPart(owningRenderer()->document(), partStyle.releaseNonNull(), this, partType);
-            partRendererSlot->initializeStyle();
-        }
-    } else {
-        if (RenderScrollbarPart* partRenderer = m_parts.take(partType))
-            partRenderer->destroy();
+    if (!needRenderer) {
+        m_parts.remove(partType);
+        return;
     }
+
+    if (auto& partRendererSlot = m_parts.add(partType, nullptr).iterator->value)
+        partRendererSlot->setStyle(partStyle.releaseNonNull());
+    else {
+        partRendererSlot = createRenderer<RenderScrollbarPart>(owningRenderer()->document(), partStyle.releaseNonNull(), this, partType);
+        partRendererSlot->initializeStyle();
+    }
 }
 
 void RenderScrollbar::paintPart(GraphicsContext* graphicsContext, ScrollbarPart partType, const IntRect& rect)

Modified: trunk/Source/WebCore/rendering/RenderScrollbar.h (161199 => 161200)


--- trunk/Source/WebCore/rendering/RenderScrollbar.h	2014-01-02 00:31:40 UTC (rev 161199)
+++ trunk/Source/WebCore/rendering/RenderScrollbar.h	2014-01-02 00:52:55 UTC (rev 161200)
@@ -26,6 +26,7 @@
 #ifndef RenderScrollbar_h
 #define RenderScrollbar_h
 
+#include "RenderPtr.h"
 #include "RenderStyleConstants.h"
 #include "Scrollbar.h"
 #include <wtf/HashMap.h>
@@ -75,9 +76,9 @@
 
     virtual bool isCustomScrollbar() const OVERRIDE { return true; }
 
-    void updateScrollbarParts(bool destroy = false);
+    void updateScrollbarParts();
 
-    void updateScrollbarPart(ScrollbarPart, bool destroy = false);
+    void updateScrollbarPart(ScrollbarPart);
 
     // This Scrollbar(Widget) may outlive the DOM which created it (during tear down),
     // so we keep a reference to the Element which caused this custom scrollbar creation.
@@ -86,7 +87,7 @@
     RefPtr<Element> m_ownerElement;
 
     Frame* m_owningFrame;
-    HashMap<unsigned, RenderScrollbarPart*> m_parts;
+    HashMap<unsigned, RenderPtr<RenderScrollbarPart>> m_parts;
 };
 
 inline RenderScrollbar* toRenderScrollbar(ScrollbarThemeClient* scrollbar)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to