Commit 953e265a authored by akling@apple.com's avatar akling@apple.com

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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159023 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 188ce2e8
2013-11-10 Andreas Kling <akling@apple.com>
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 <akling@apple.com>
Remove unused FragmentationDisabler class.
......
......@@ -329,9 +329,9 @@ AccessibilityObject* AXObjectCache::getOrCreate(Widget* widget)
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));
......
......@@ -78,7 +78,7 @@ HTMLPlugInElement::~HTMLPlugInElement()
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;
}
......
......@@ -398,7 +398,7 @@ DragOperation DragController::operationForLoad(DragData& dragData)
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();
......
......@@ -688,20 +688,7 @@ inline void FrameView::incrementVisuallyNonEmptyPixelCount(const IntSize& size)
updateIsVisuallyNonEmpty();
}
inline FrameView* toFrameView(Widget* widget)
{
ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isFrameView());
return static_cast<FrameView*>(widget);
}
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*);
WIDGET_TYPE_CASTS(FrameView, isFrameView());
} // namespace WebCore
......
......@@ -415,20 +415,7 @@ private:
#endif
}; // class ScrollView
inline ScrollView* toScrollView(Widget* widget)
{
ASSERT(!widget || widget->isScrollView());
return static_cast<ScrollView*>(widget);
}
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*);
WIDGET_TYPE_CASTS(ScrollView, isScrollView());
} // namespace WebCore
......
......@@ -201,6 +201,8 @@ private:
virtual bool isScrollbar() const OVERRIDE { return true; }
};
WIDGET_TYPE_CASTS(Scrollbar, isScrollbar());
} // namespace WebCore
#endif // Scrollbar_h
......@@ -59,8 +59,8 @@ ScrollView* Widget::root() const
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()
......
......@@ -233,6 +233,9 @@ private:
#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
......
......@@ -75,20 +75,7 @@ protected:
explicit PluginViewBase(PlatformWidget widget = 0) : Widget(widget) { }
};
inline PluginViewBase* toPluginViewBase(Widget* widget)
{
ASSERT(!widget || widget->isPluginViewBase());
return static_cast<PluginViewBase*>(widget);
}
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*);
WIDGET_TYPE_CASTS(PluginViewBase, isPluginViewBase());
} // namespace WebCore
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment