Skip to content
Permalink
Browse files
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.

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):


Canonical link: https://commits.webkit.org/130508@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145596 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
inferno-chromium committed Mar 12, 2013
1 parent 86f0f5c commit a66c9856589d15965c704ea0528b0ea6681cc996
Showing 18 changed files with 96 additions and 30 deletions.
@@ -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
@@ -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);
@@ -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());
@@ -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);
@@ -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;
}

@@ -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();
@@ -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).
@@ -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;

@@ -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));
@@ -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();
@@ -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);
@@ -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
@@ -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;
@@ -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);
@@ -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())
@@ -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);

@@ -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
@@ -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);

0 comments on commit a66c985

Please sign in to comment.