Title: [159023] trunk/Source/WebCore
Revision
159023
Author
[email protected]
Date
2013-11-10 02:59:50 -0800 (Sun, 10 Nov 2013)

Log Message

Generate type casting helpers for Widget classes.
<https://webkit.org/b/124120>

Add a WIDGET_TYPE_CASTS macro and replace all the hand-written
toFoo() helpers we had for Widget subclasses. Fixed up a handful
of places that were still using static_cast.

Reviewed by Antti Koivisto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (159022 => 159023)


--- trunk/Source/WebCore/ChangeLog	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/ChangeLog	2013-11-10 10:59:50 UTC (rev 159023)
@@ -1,5 +1,16 @@
 2013-11-10  Andreas Kling  <[email protected]>
 
+        Generate type casting helpers for Widget classes.
+        <https://webkit.org/b/124120>
+
+        Add a WIDGET_TYPE_CASTS macro and replace all the hand-written
+        toFoo() helpers we had for Widget subclasses. Fixed up a handful
+        of places that were still using static_cast.
+
+        Reviewed by Antti Koivisto.
+
+2013-11-10  Andreas Kling  <[email protected]>
+
         Remove unused FragmentationDisabler class.
         <https://webkit.org/b/124118>
 

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (159022 => 159023)


--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2013-11-10 10:59:50 UTC (rev 159023)
@@ -329,9 +329,9 @@
     
     RefPtr<AccessibilityObject> newObj = 0;
     if (widget->isFrameView())
-        newObj = AccessibilityScrollView::create(static_cast<ScrollView*>(widget));
+        newObj = AccessibilityScrollView::create(toScrollView(widget));
     else if (widget->isScrollbar())
-        newObj = AccessibilityScrollbar::create(static_cast<Scrollbar*>(widget));
+        newObj = AccessibilityScrollbar::create(toScrollbar(widget));
 
     // Will crash later if we have two objects for the same widget.
     ASSERT(!get(widget));

Modified: trunk/Source/WebCore/html/HTMLPlugInElement.cpp (159022 => 159023)


--- trunk/Source/WebCore/html/HTMLPlugInElement.cpp	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/html/HTMLPlugInElement.cpp	2013-11-10 10:59:50 UTC (rev 159023)
@@ -78,7 +78,7 @@
 
 bool HTMLPlugInElement::canProcessDrag() const
 {
-    const PluginViewBase* plugin = pluginWidget() && pluginWidget()->isPluginViewBase() ? static_cast<const PluginViewBase*>(pluginWidget()) : 0;
+    const PluginViewBase* plugin = pluginWidget() && pluginWidget()->isPluginViewBase() ? toPluginViewBase(pluginWidget()) : nullptr;
     return plugin ? plugin->canProcessDrag() : false;
 }
 

Modified: trunk/Source/WebCore/page/DragController.cpp (159022 => 159023)


--- trunk/Source/WebCore/page/DragController.cpp	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/page/DragController.cpp	2013-11-10 10:59:50 UTC (rev 159023)
@@ -398,7 +398,7 @@
 
     if (doc && doc->isPluginDocument()) {
         const Widget* widget = toPluginDocument(doc)->pluginWidget();
-        const PluginViewBase* pluginView = (widget && widget->isPluginViewBase()) ? static_cast<const PluginViewBase*>(widget) : 0;
+        const PluginViewBase* pluginView = (widget && widget->isPluginViewBase()) ? toPluginViewBase(widget) : nullptr;
 
         if (pluginView)
             pluginDocumentAcceptsDrags = pluginView->shouldAllowNavigationFromDrags();

Modified: trunk/Source/WebCore/page/FrameView.h (159022 => 159023)


--- trunk/Source/WebCore/page/FrameView.h	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/page/FrameView.h	2013-11-10 10:59:50 UTC (rev 159023)
@@ -688,21 +688,8 @@
     updateIsVisuallyNonEmpty();
 }
 
-inline FrameView* toFrameView(Widget* widget)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isFrameView());
-    return static_cast<FrameView*>(widget);
-}
+WIDGET_TYPE_CASTS(FrameView, isFrameView());
 
-inline const FrameView* toFrameView(const Widget* widget)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isFrameView());
-    return static_cast<const FrameView*>(widget);
-}
-
-// This will catch anyone doing an unnecessary cast.
-void toFrameView(const FrameView*);
-
 } // namespace WebCore
 
 #endif // FrameView_h

Modified: trunk/Source/WebCore/platform/ScrollView.h (159022 => 159023)


--- trunk/Source/WebCore/platform/ScrollView.h	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/platform/ScrollView.h	2013-11-10 10:59:50 UTC (rev 159023)
@@ -415,21 +415,8 @@
 #endif
 }; // class ScrollView
 
-inline ScrollView* toScrollView(Widget* widget)
-{
-    ASSERT(!widget || widget->isScrollView());
-    return static_cast<ScrollView*>(widget);
-}
+WIDGET_TYPE_CASTS(ScrollView, isScrollView());
 
-inline const ScrollView* toScrollView(const Widget* widget)
-{
-    ASSERT(!widget || widget->isScrollView());
-    return static_cast<const ScrollView*>(widget);
-}
-
-// This will catch anyone doing an unnecessary cast.
-void toScrollView(const ScrollView*);
-
 } // namespace WebCore
 
 #endif // ScrollView_h

Modified: trunk/Source/WebCore/platform/Scrollbar.h (159022 => 159023)


--- trunk/Source/WebCore/platform/Scrollbar.h	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/platform/Scrollbar.h	2013-11-10 10:59:50 UTC (rev 159023)
@@ -201,6 +201,8 @@
     virtual bool isScrollbar() const OVERRIDE { return true; }
 };
 
+WIDGET_TYPE_CASTS(Scrollbar, isScrollbar());
+
 } // namespace WebCore
 
 #endif // Scrollbar_h

Modified: trunk/Source/WebCore/platform/Widget.cpp (159022 => 159023)


--- trunk/Source/WebCore/platform/Widget.cpp	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/platform/Widget.cpp	2013-11-10 10:59:50 UTC (rev 159023)
@@ -59,8 +59,8 @@
     while (top->parent())
         top = top->parent();
     if (top->isFrameView())
-        return const_cast<ScrollView*>(static_cast<const ScrollView*>(top));
-    return 0;
+        return const_cast<ScrollView*>(toScrollView(top));
+    return nullptr;
 }
     
 void Widget::removeFromParent()

Modified: trunk/Source/WebCore/platform/Widget.h (159022 => 159023)


--- trunk/Source/WebCore/platform/Widget.h	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/platform/Widget.h	2013-11-10 10:59:50 UTC (rev 159023)
@@ -233,6 +233,9 @@
 #endif
 };
 
+#define WIDGET_TYPE_CASTS(ToValueTypeName, predicate) \
+    TYPE_CASTS_BASE(ToValueTypeName, Widget, object, object->predicate, object.predicate)
+
 #if !PLATFORM(MAC)
 
 inline PlatformWidget Widget::platformWidget() const

Modified: trunk/Source/WebCore/plugins/PluginViewBase.h (159022 => 159023)


--- trunk/Source/WebCore/plugins/PluginViewBase.h	2013-11-10 10:58:54 UTC (rev 159022)
+++ trunk/Source/WebCore/plugins/PluginViewBase.h	2013-11-10 10:59:50 UTC (rev 159023)
@@ -75,21 +75,8 @@
     explicit PluginViewBase(PlatformWidget widget = 0) : Widget(widget) { }
 };
 
-inline PluginViewBase* toPluginViewBase(Widget* widget)
-{
-    ASSERT(!widget || widget->isPluginViewBase());
-    return static_cast<PluginViewBase*>(widget);
-}
+WIDGET_TYPE_CASTS(PluginViewBase, isPluginViewBase());
 
-inline const PluginViewBase* toPluginViewBase(const Widget* widget)
-{
-    ASSERT(!widget || widget->isPluginViewBase());
-    return static_cast<const PluginViewBase*>(widget);
-}
-
-// This will catch anyone doing an unnecessary cast.
-void toPluginViewBase(const PluginViewBase*);
-
 } // namespace WebCore
 
 #endif // PluginWidget_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to