Replace static_casts with to* helper functions.
authorinferno@chromium.org <inferno@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 22:21:28 +0000 (22:21 +0000)
committerinferno@chromium.org <inferno@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 22:21:28 +0000 (22:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112164

Reviewed by Philip Rogers.

to* helper functions are preferred over static_cast calls since they
help to catch bad casts easily on the testing infrastructure.

Source/WebCore:

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::collectMatchingRulesForRegion):
* platform/gtk/PasteboardGtk.cpp:
(WebCore::getURLForImageNode):
(WebCore::Pasteboard::writeImage):
* platform/gtk/RenderThemeGtk.cpp:
(WebCore::getMediaElementFromRenderObject):
* platform/qt/RenderThemeQtMobile.cpp:
(WebCore::RenderThemeQtMobile::checkMultiple):
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::title):
(WebCore::HitTestResult::absoluteImageURL):
(WebCore::HitTestResult::absolutePDFURL):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::resize):
(WebCore::RenderLayer::hitTest):
* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::valueChanged):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::addPDFURLRect):
* rendering/RenderPart.cpp:
(WebCore::RenderPart::requiresAcceleratedCompositing):
* rendering/RenderRegion.cpp:
(WebCore::RenderRegion::checkRegionStyle):
* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::computePreferredLogicalWidths):
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::isEnabled):
(WebCore::RenderTheme::isSpinUpButtonPartPressed):
(WebCore::RenderTheme::isHovered):
(WebCore::RenderTheme::isSpinUpButtonPartHovered):
(WebCore::RenderTheme::paintSliderTicks):
* rendering/RenderThemeWinCE.cpp:
(WebCore::mediaElementParent):
* rendering/RenderTreeAsText.cpp:
(WebCore::isEmptyOrUnstyledAppleStyleSpan):
(WebCore::RenderTreeAsText::writeRenderObject):
(WebCore::writeRenderRegionList):
* rendering/svg/SVGRenderTreeAsText.cpp:
(WebCore::writeSVGResourceContainer):

Source/WebKit/win:

* DOMHTMLClasses.cpp:
(DOMHTMLElement::idName):
(DOMHTMLElement::innerText):
(DOMHTMLElement::setInnerText):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145596 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/ElementRuleCollector.cpp
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/gtk/RenderThemeGtk.cpp
Source/WebCore/platform/qt/RenderThemeQtMobile.cpp
Source/WebCore/rendering/HitTestResult.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderPart.cpp
Source/WebCore/rendering/RenderRegion.cpp
Source/WebCore/rendering/RenderTableCell.cpp
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderThemeWinCE.cpp
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/DOMHTMLClasses.cpp

index b582f72..ac38af4 100644 (file)
@@ -1,3 +1,54 @@
+2013-03-12  Abhishek Arya  <inferno@chromium.org>
+
+        Replace static_casts with to* helper functions.
+        https://bugs.webkit.org/show_bug.cgi?id=112164
+
+        Reviewed by Philip Rogers.
+
+        to* helper functions are preferred over static_cast calls since they
+        help to catch bad casts easily on the testing infrastructure.
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::collectMatchingRulesForRegion):
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::getURLForImageNode):
+        (WebCore::Pasteboard::writeImage):
+        * platform/gtk/RenderThemeGtk.cpp:
+        (WebCore::getMediaElementFromRenderObject):
+        * platform/qt/RenderThemeQtMobile.cpp:
+        (WebCore::RenderThemeQtMobile::checkMultiple):
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::title):
+        (WebCore::HitTestResult::absoluteImageURL):
+        (WebCore::HitTestResult::absolutePDFURL):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::resize):
+        (WebCore::RenderLayer::hitTest):
+        * rendering/RenderMenuList.cpp:
+        (WebCore::RenderMenuList::valueChanged):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::addPDFURLRect):
+        * rendering/RenderPart.cpp:
+        (WebCore::RenderPart::requiresAcceleratedCompositing):
+        * rendering/RenderRegion.cpp:
+        (WebCore::RenderRegion::checkRegionStyle):
+        * rendering/RenderTableCell.cpp:
+        (WebCore::RenderTableCell::computePreferredLogicalWidths):
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::isEnabled):
+        (WebCore::RenderTheme::isSpinUpButtonPartPressed):
+        (WebCore::RenderTheme::isHovered):
+        (WebCore::RenderTheme::isSpinUpButtonPartHovered):
+        (WebCore::RenderTheme::paintSliderTicks):
+        * rendering/RenderThemeWinCE.cpp:
+        (WebCore::mediaElementParent):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::isEmptyOrUnstyledAppleStyleSpan):
+        (WebCore::RenderTreeAsText::writeRenderObject):
+        (WebCore::writeRenderRegionList):
+        * rendering/svg/SVGRenderTreeAsText.cpp:
+        (WebCore::writeSVGResourceContainer):
+
 2013-03-12  Geoffrey Garen  <ggaren@apple.com>
 
         Moved RunLoopTimer and SchedulePair to WTF
index 64fb3d1..6ff2062 100644 (file)
@@ -191,7 +191,7 @@ void ElementRuleCollector::collectMatchingRulesForRegion(const MatchRequest& mat
     unsigned size = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.size();
     for (unsigned i = 0; i < size; ++i) {
         const CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).selector;
-        if (checkRegionSelector(regionSelector, static_cast<Element*>(m_regionForStyling->node()))) {
+        if (checkRegionSelector(regionSelector, toElement(m_regionForStyling->node()))) {
             RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).ruleSet.get();
             ASSERT(regionRules);
             collectMatchingRules(MatchRequest(regionRules, matchRequest.includeEmptyRules, matchRequest.scope), ruleRange);
index d6d867e..ef394c4 100644 (file)
@@ -100,13 +100,13 @@ static KURL getURLForImageNode(Node* node)
     // FIXME: Later this code should be shared with Chromium somehow. Chances are all platforms want it.
     AtomicString urlString;
     if (node->hasTagName(HTMLNames::imgTag) || node->hasTagName(HTMLNames::inputTag))
-        urlString = static_cast<Element*>(node)->getAttribute(HTMLNames::srcAttr);
+        urlString = toElement(node)->getAttribute(HTMLNames::srcAttr);
 #if ENABLE(SVG)
     else if (node->hasTagName(SVGNames::imageTag))
-        urlString = static_cast<Element*>(node)->getAttribute(XLinkNames::hrefAttr);
+        urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr);
 #endif
     else if (node->hasTagName(HTMLNames::embedTag) || node->hasTagName(HTMLNames::objectTag)) {
-        Element* element = static_cast<Element*>(node);
+        Element* element = toElement(node);
         urlString = element->getAttribute(element->imageSourceAttributeName());
     }
     return urlString.isEmpty() ? KURL() : node->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
@@ -134,7 +134,7 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String& title)
     if (!url.isEmpty()) {
         dataObject->setURL(url, title);
 
-        dataObject->setMarkup(createMarkup(static_cast<Element*>(node), IncludeNode, 0, ResolveAllURLs));
+        dataObject->setMarkup(createMarkup(toElement(node), IncludeNode, 0, ResolveAllURLs));
     }
 
     GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf());
index a2f2727..deb2f5f 100644 (file)
@@ -71,7 +71,7 @@ static HTMLMediaElement* getMediaElementFromRenderObject(RenderObject* o)
     Node* mediaNode = node ? node->shadowHost() : 0;
     if (!mediaNode)
         mediaNode = node;
-    if (!mediaNode || !mediaNode->isElementNode() || !static_cast<Element*>(mediaNode)->isMediaElement())
+    if (!mediaNode || !mediaNode->isElementNode() || !toElement(mediaNode)->isMediaElement())
         return 0;
 
     return static_cast<HTMLMediaElement*>(mediaNode);
index 702eda4..9667bc3 100644 (file)
@@ -901,7 +901,7 @@ bool RenderThemeQtMobile::paintSliderThumb(RenderObject* o, const PaintInfo& pi,
 
 bool RenderThemeQtMobile::checkMultiple(RenderObject* o) const
 {
-    HTMLSelectElement* select = o ? static_cast<HTMLSelectElement*>(o->node()) : 0;
+    HTMLSelectElement* select = o ? toHTMLSelectElement(o->node()) : 0;
     return select ? select->multiple() : false;
 }
 
index a9228f0..23da31c 100644 (file)
@@ -218,7 +218,7 @@ String HitTestResult::title(TextDirection& dir) const
     // For <area> tags in image maps, walk the tree for the <area>, not the <img> using it.
     for (Node* titleNode = m_innerNode.get(); titleNode; titleNode = titleNode->parentNode()) {
         if (titleNode->isElementNode()) {
-            String title = static_cast<Element*>(titleNode)->title();
+            String title = toElement(titleNode)->title();
             if (!title.isEmpty()) {
                 if (RenderObject* renderer = titleNode->renderer())
                     dir = renderer->style()->direction();
@@ -319,7 +319,7 @@ KURL HitTestResult::absoluteImageURL() const
         || m_innerNonSharedNode->hasTagName(SVGNames::imageTag)
 #endif
        ) {
-        Element* element = static_cast<Element*>(m_innerNonSharedNode.get());
+        Element* element = toElement(m_innerNonSharedNode.get());
         urlString = element->getAttribute(element->imageSourceAttributeName());
     } else
         return KURL();
@@ -335,7 +335,7 @@ KURL HitTestResult::absolutePDFURL() const
     if (!m_innerNonSharedNode->hasTagName(embedTag) && !m_innerNonSharedNode->hasTagName(objectTag))
         return KURL();
 
-    HTMLPlugInImageElement* element = static_cast<HTMLPlugInImageElement*>(m_innerNonSharedNode.get());
+    HTMLPlugInImageElement* element = toHTMLPlugInImageElement(m_innerNonSharedNode.get());
     KURL url = m_innerNonSharedNode->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(element->url()));
     if (!url.isValid())
         return KURL();
index 9845f27..6c0fe22 100644 (file)
@@ -2447,7 +2447,7 @@ void RenderLayer::resize(const PlatformMouseEvent& evt, const LayoutSize& oldOff
         return;
 
     ASSERT(renderer()->node()->isElementNode());
-    Element* element = static_cast<Element*>(renderer()->node());
+    Element* element = toElement(renderer()->node());
     RenderBox* renderer = toRenderBox(element->renderer());
 
     Document* document = element->document();
@@ -4333,7 +4333,7 @@ bool RenderLayer::hitTest(const HitTestRequest& request, const HitTestLocation&
     // Now determine if the result is inside an anchor - if the urlElement isn't already set.
     Node* node = result.innerNode();
     if (node && !result.URLElement())
-        result.setURLElement(static_cast<Element*>(node->enclosingLinkEventParentOrSelf()));
+        result.setURLElement(toElement(node->enclosingLinkEventParentOrSelf()));
 
     // Now return whether we were inside this layer (this will always be true for the root
     // layer).
index cffe9d5..548ce85 100644 (file)
@@ -341,7 +341,7 @@ void RenderMenuList::valueChanged(unsigned listIndex, bool fireOnChange)
 {
     // Check to ensure a page navigation has not occurred while
     // the popup was up.
-    Document* doc = static_cast<Element*>(node())->document();
+    Document* doc = toElement(node())->document();
     if (!doc || doc != doc->frame()->document())
         return;
     
index 706d1ec..b39d58d 100644 (file)
@@ -1111,7 +1111,7 @@ void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rec
     Node* n = node();
     if (!n || !n->isLink() || !n->isElementNode())
         return;
-    const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
+    const AtomicString& href = toElement(n)->getAttribute(hrefAttr);
     if (href.isNull())
         return;
     context->setURLForRect(n->document()->completeURL(href), pixelSnappedIntRect(rect));
index a8751e8..4fa7ad1 100644 (file)
@@ -86,7 +86,7 @@ bool RenderPart::requiresAcceleratedCompositing() const
     if (!node() || !node()->isFrameOwnerElement())
         return false;
 
-    HTMLFrameOwnerElement* element = static_cast<HTMLFrameOwnerElement*>(node());
+    HTMLFrameOwnerElement* element = toFrameOwnerElement(node());
     if (Document* contentDocument = element->contentDocument()) {
         if (RenderView* view = contentDocument->renderView())
             return view->usesCompositing();
index 6c01f22..eb465dc 100644 (file)
@@ -189,7 +189,7 @@ void RenderRegion::checkRegionStyle()
 
     // FIXME: Region styling doesn't work for pseudo elements.
     if (node()) {
-        Element* regionElement = static_cast<Element*>(node());
+        Element* regionElement = toElement(node());
         customRegionStyle = view()->document()->styleResolver()->checkRegionStyle(regionElement);
     }
     setHasCustomRegionStyle(customRegionStyle);
index ec7f0b1..3ef9245 100644 (file)
@@ -168,7 +168,7 @@ void RenderTableCell::computePreferredLogicalWidths()
     if (node() && style()->autoWrap()) {
         // See if nowrap was set.
         Length w = styleOrColLogicalWidth();
-        String nowrap = static_cast<Element*>(node())->getAttribute(nowrapAttr);
+        String nowrap = toElement(node())->getAttribute(nowrapAttr);
         if (!nowrap.isNull() && w.isFixed())
             // Nowrap is set, but we didn't actually use it because of the
             // fixed width set on the cell.  Even so, it is a WinIE/Moz trait
index 181b73c..95f69e5 100644 (file)
@@ -788,7 +788,7 @@ bool RenderTheme::isEnabled(const RenderObject* o) const
     Node* node = o->node();
     if (!node || !node->isElementNode())
         return true;
-    return static_cast<Element*>(node)->isEnabledFormControl();
+    return toElement(node)->isEnabledFormControl();
 }
 
 bool RenderTheme::isFocused(const RenderObject* o) const
@@ -814,7 +814,7 @@ bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject* o) const
 {
     Node* node = o->node();
     if (!node || !node->active() || !node->isElementNode()
-        || !static_cast<Element*>(node)->isSpinButtonElement())
+        || !toElement(node)->isSpinButtonElement())
         return false;
     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
     return element->upDownState() == SpinButtonElement::Up;
@@ -833,7 +833,7 @@ bool RenderTheme::isHovered(const RenderObject* o) const
     Node* node = o->node();
     if (!node)
         return false;
-    if (!node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
+    if (!node->isElementNode() || !toElement(node)->isSpinButtonElement())
         return node->hovered();
     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
     return element->hovered() && element->upDownState() != SpinButtonElement::Indeterminate;
@@ -842,7 +842,7 @@ bool RenderTheme::isHovered(const RenderObject* o) const
 bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject* o) const
 {
     Node* node = o->node();
-    if (!node || !node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
+    if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement())
         return false;
     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
     return element->upDownState() == SpinButtonElement::Up;
@@ -1032,7 +1032,7 @@ void RenderTheme::paintSliderTicks(RenderObject* o, const PaintInfo& paintInfo,
     paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB);
     for (unsigned i = 0; Node* node = options->item(i); i++) {
         ASSERT(node->hasTagName(optionTag));
-        HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
+        HTMLOptionElement* optionElement = toHTMLOptionElement(node);
         String value = optionElement->value();
         if (!input->isValidValue(value))
             continue;
index 950df31..090b15a 100644 (file)
@@ -482,7 +482,7 @@ static HTMLMediaElement* mediaElementParent(Node* node)
     Node* mediaNode = node->shadowHost();
     if (!mediaNode)
         mediaNode = node;
-    if (!mediaNode || !mediaNode->isElementNode() || !static_cast<Element*>(mediaNode)->isMediaElement())
+    if (!mediaNode || !mediaNode->isElementNode() || !toElement(mediaNode)->isMediaElement())
         return 0;
 
     return static_cast<HTMLMediaElement*>(mediaNode);
index a3b4af2..1191f61 100644 (file)
@@ -168,7 +168,7 @@ static bool isEmptyOrUnstyledAppleStyleSpan(const Node* node)
     if (!node || !node->isHTMLElement() || !node->hasTagName(spanTag))
         return false;
 
-    const HTMLElement* elem = static_cast<const HTMLElement*>(node);
+    const HTMLElement* elem = toHTMLElement(node);
     if (elem->getAttribute(classAttr) != "Apple-style-span")
         return false;
 
@@ -430,7 +430,7 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
     if (behavior & RenderAsTextShowIDAndClass) {
         if (Node* node = o.node()) {
             if (node->hasID())
-                ts << " id=\"" + static_cast<Element*>(node)->getIdAttribute() + "\"";
+                ts << " id=\"" + toElement(node)->getIdAttribute() + "\"";
 
             if (node->hasClass()) {
                 ts << " class=\"";
@@ -669,7 +669,7 @@ static void writeRenderRegionList(const RenderRegionList& flowThreadRegionList,
             if (!tagName.isEmpty())
                 ts << " {" << tagName << "}";
             if (renderRegion->generatingNode()->isElementNode() && renderRegion->generatingNode()->hasID()) {
-                Element* element = static_cast<Element*>(renderRegion->generatingNode());
+                Element* element = toElement(renderRegion->generatingNode());
                 ts << " #" << element->idForStyleResolution();
             }
             if (renderRegion->hasCustomRegionStyle())
index a93afd0..96c8403 100644 (file)
@@ -493,7 +493,7 @@ void writeSVGResourceContainer(TextStream& ts, const RenderObject& object, int i
 {
     writeStandardPrefix(ts, object, indent);
 
-    Element* element = static_cast<Element*>(object.node());
+    Element* element = toElement(object.node());
     const AtomicString& id = element->getIdAttribute();
     writeNameAndQuotedValue(ts, "id", id);    
 
index 7353b18..85f670e 100644 (file)
@@ -1,3 +1,18 @@
+2013-03-12  Abhishek Arya  <inferno@chromium.org>
+
+        Replace static_casts with to* helper functions.
+        https://bugs.webkit.org/show_bug.cgi?id=112164
+
+        Reviewed by Philip Rogers.
+
+        to* helper functions are preferred over static_cast calls since they
+        help to catch bad casts easily on the testing infrastructure.
+
+        * DOMHTMLClasses.cpp:
+        (DOMHTMLElement::idName):
+        (DOMHTMLElement::innerText):
+        (DOMHTMLElement::setInnerText):
+
 2013-03-11  Jochen Eisinger  <jochen@chromium.org>
 
         Rename DefinitelyProcessingUserGesture to DefinitelyProcessingNewUserGesture
index d58fc69..5500025 100644 (file)
@@ -396,7 +396,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLElement::idName(
         return E_POINTER;
 
     ASSERT(m_element && m_element->isHTMLElement());
-    String idString = static_cast<HTMLElement*>(m_element)->getAttribute(idAttr);
+    String idString = toHTMLElement(m_element)->getAttribute(idAttr);
     *result = BString(idString).release();
     return S_OK;
 }
@@ -482,7 +482,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLElement::innerText(
         /* [retval][out] */ BSTR* result)
 {
     ASSERT(m_element && m_element->isHTMLElement());
-    WTF::String innerTextString = static_cast<HTMLElement*>(m_element)->innerText();
+    WTF::String innerTextString = toHTMLElement(m_element)->innerText();
     *result = BString(innerTextString.characters(), innerTextString.length()).release();
     return S_OK;
 }
@@ -491,7 +491,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLElement::setInnerText(
         /* [in] */ BSTR text)
 {
     ASSERT(m_element && m_element->isHTMLElement());
-    HTMLElement* htmlEle = static_cast<HTMLElement*>(m_element);
+    HTMLElement* htmlEle = toHTMLElement(m_element);
     WTF::String textString(text, SysStringLen(text));
     WebCore::ExceptionCode ec = 0;
     htmlEle->setInnerText(textString, ec);