Use is<>() / downcast<>() for Element
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Sep 2014 19:59:49 +0000 (19:59 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Sep 2014 19:59:49 +0000 (19:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137241

Reviewed by Andreas Kling.

Use is<>() / downcast<>() for Element instead of isElementNode() /
toElement().

Source/WebCore:

No new tests, no behavior change.

* accessibility/AXObjectCache.cpp:
(WebCore::nodeHasRole):
(WebCore::createFromRenderer):
(WebCore::AXObjectCache::handleLiveRegionCreated):
(WebCore::AXObjectCache::handleMenuItemSelected):
(WebCore::AXObjectCache::rootAXEditableElement):
(WebCore::isNodeAriaVisible):
* accessibility/AccessibilityMenuList.cpp:
(WebCore::AccessibilityMenuList::canSetFocusAttribute):
* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::determineAccessibilityRole):
(WebCore::AccessibilityNodeObject::canvasHasFallbackContent):
(WebCore::AccessibilityNodeObject::isEnabled):
(WebCore::AccessibilityNodeObject::isPressed):
(WebCore::AccessibilityNodeObject::isHovered):
(WebCore::AccessibilityNodeObject::anchorElement):
(WebCore::nativeActionElement):
(WebCore::AccessibilityNodeObject::actionElement):
(WebCore::AccessibilityNodeObject::mouseButtonListener):
(WebCore::AccessibilityNodeObject::titleElementText):
(WebCore::AccessibilityNodeObject::helpText):
(WebCore::AccessibilityNodeObject::hierarchicalLevel):
(WebCore::AccessibilityNodeObject::title):
(WebCore::AccessibilityNodeObject::text):
(WebCore::accessibleNameForNode):
(WebCore::AccessibilityNodeObject::canSetFocusAttribute):
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::press):
(WebCore::AccessibilityObject::hasTagName):
(WebCore::AccessibilityObject::hasAttribute):
(WebCore::AccessibilityObject::element):
(WebCore::AccessibilityObject::classList):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::anchorElement):
(WebCore::AccessibilityRenderObject::helpText):
(WebCore::AccessibilityRenderObject::checkboxOrRadioRect):
(WebCore::AccessibilityRenderObject::titleUIElement):
(WebCore::AccessibilityRenderObject::accessKey):
(WebCore::AccessibilityRenderObject::setElementAttributeValue):
(WebCore::AccessibilityRenderObject::setFocused):
(WebCore::AccessibilityRenderObject::setValue):
(WebCore::AccessibilityRenderObject::handleActiveDescendantChanged):
(WebCore::AccessibilityRenderObject::correspondingLabelForControlElement):
(WebCore::AccessibilityRenderObject::renderObjectIsObservable):
(WebCore::AccessibilityRenderObject::inheritsPresentationalRole):
(WebCore::AccessibilityRenderObject::setAccessibleName):
(WebCore::AccessibilityRenderObject::stringRoleForMSAA):
* accessibility/AccessibilitySearchFieldButtons.cpp:
(WebCore::AccessibilitySearchFieldCancelButton::press):
* accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
(webkitAccessibleGetAttributes):
* bindings/gobject/WebKitDOMPrivate.cpp:
(WebKit::wrap):
* bindings/js/JSNodeCustom.cpp:
(WebCore::isReachableFromDOM):
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::styledNode):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::locateCousinList):
* dom/ContainerNode.cpp:
(WebCore::destroyRenderTreeIfNeeded):
(WebCore::ContainerNode::notifyChildRemoved):
* dom/ContainerNodeAlgorithms.cpp:
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
(WebCore::ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument):
(WebCore::ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree):
(WebCore::assertConnectedSubrameCountIsConsistent):
* dom/Document.cpp:
(WebCore::Document::importNode):
(WebCore::Document::elementFromPoint):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::collectActiveStyleSheets):
* dom/Element.cpp:
(WebCore::Element::computeInheritedLanguage):
* dom/Element.h:
(WebCore::isElement):
(WebCore::Node::hasAttributes):
(WebCore::Node::attributes):
(WebCore::Node::parentElement):
* dom/ElementTraversal.h:
(WebCore::Traversal<Element>::nextTemplate):
(WebCore::ElementTraversal::previousIncludingPseudo):
(WebCore::ElementTraversal::nextIncludingPseudo):
(WebCore::ElementTraversal::nextIncludingPseudoSkippingChildren):
(WebCore::ElementTraversal::pseudoAwarePreviousSibling):
* dom/LiveNodeList.cpp:
(WebCore::LiveNodeList::namedItem):
* dom/Node.cpp:
(WebCore::Node::dumpStatistics):
(WebCore::Node::normalize):
(WebCore::Node::pseudoAwareFirstChild):
(WebCore::Node::pseudoAwareLastChild):
(WebCore::Node::computedStyle):
(WebCore::Node::parentOrShadowHostElement):
(WebCore::Node::rootEditableElement):
(WebCore::Node::isEqualNode):
(WebCore::Node::isDefaultNamespace):
(WebCore::Node::lookupNamespacePrefix):
(WebCore::Node::ancestorElement):
(WebCore::appendAttributeDesc):
(WebCore::Node::showNodePathForThis):
(WebCore::Node::enclosingLinkEventParentOrSelf):
(WebCore::Node::handleLocalEvents):
(WebCore::Node::willRespondToMouseMoveEvents):
(WebCore::Node::willRespondToMouseClickEvents):
* dom/NodeRenderingTraversal.cpp:
(WebCore::NodeRenderingTraversal::nodeCanBeDistributed):
* dom/Position.cpp:
(WebCore::Position::element):
* dom/Range.cpp:
(WebCore::Range::getBorderAndTextQuads):
* dom/ShadowRoot.h:
(WebCore::Node::shadowRoot):
* dom/StaticNodeList.cpp:
(WebCore::StaticNodeList::namedItem):
* dom/TreeScopeAdopter.cpp:
(WebCore::TreeScopeAdopter::moveTreeToNewScope):
* editing/ApplyStyleCommand.cpp:
(WebCore::dummySpanAncestorForNode):
(WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
(WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode):
(WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical):
(WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical):
(WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
* editing/BreakBlockquoteCommand.cpp:
(WebCore::BreakBlockquoteCommand::doApply):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::isRemovableBlock):
(WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
(WebCore::CompositeEditCommand::moveParagraphs):
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss):
* editing/Editor.cpp:
(WebCore::Editor::isSpellCheckingEnabledFor):
(WebCore::Editor::applyEditingStyleToBodyElement):
* editing/FormatBlockCommand.cpp:
(WebCore::isElementForFormatBlock):
(WebCore::FormatBlockCommand::elementForFormatBlockCommand):
* editing/FrameSelection.cpp:
(WebCore::removingNodeRemovesPosition):
(WebCore::CaretBase::paintCaret):
(WebCore::FrameSelection::debugRenderer):
* editing/IndentOutdentCommand.cpp:
(WebCore::IndentOutdentCommand::outdentParagraph):
* editing/InsertParagraphSeparatorCommand.cpp:
(WebCore::InsertParagraphSeparatorCommand::doApply):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::serializeNodesWithNamespaces):
(WebCore::MarkupAccumulator::appendStartMarkup):
* editing/MarkupAccumulator.h:
(WebCore::MarkupAccumulator::appendEndTag):
* editing/ModifySelectionListLevel.cpp:
(WebCore::IncreaseSelectionListLevelCommand::doApply):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::isMailPasteAsQuotationNode):
(WebCore::haveSameTagName):
(WebCore::handleStyleSpansBeforeInsertion):
(WebCore::ReplaceSelectionCommand::doApply):
* editing/SpellChecker.cpp:
(WebCore::SpellChecker::isCheckable):
* editing/SplitTextNodeContainingElementCommand.cpp:
(WebCore::SplitTextNodeContainingElementCommand::doApply):
* editing/TextIterator.cpp:
(WebCore::isRendererReplacedElement):
* editing/cocoa/HTMLConverter.mm:
(HTMLConverterCaches::propertyValueForNode):
(HTMLConverterCaches::floatPropertyValueForNode):
(HTMLConverterCaches::colorPropertyValueForNode):
(HTMLConverter::aggregatedAttributesForAncestors):
(HTMLConverter::aggregatedAttributesForElementAndItsAncestors):
(HTMLConverter::_traverseNode):
(WebCore::editingAttributedStringFromRange):
* editing/htmlediting.cpp:
(WebCore::unsplittableElementForPosition):
(WebCore::enclosingBlock):
(WebCore::enclosingElementWithTag):
(WebCore::enclosingTableCell):
(WebCore::enclosingAnchorElement):
(WebCore::areIdenticalElements):
(WebCore::isNonTableCellHTMLBlockElement):
(WebCore::deprecatedEnclosingBlockFlowElement):
(WebCore::rendererForCaretPainting):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::wrapWithNode):
(WebCore::createMarkupInternal):
(WebCore::createFragmentFromText):
* html/HTMLDetailsElement.cpp:
(WebCore::DetailsSummaryElement::fallbackSummary):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::insertAdjacentElement):
(WebCore::contextElementForInsertion):
(WebCore::HTMLElement::directionality):
* html/HTMLFormControlElement.h:
(WebCore::isHTMLFormControlElement):
* html/HTMLMediaElement.h:
(WebCore::isHTMLMediaElement):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateDocNamedItem):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::collectOptionInnerText):
* html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::removedFrom):
* html/HTMLSummaryElement.cpp:
(WebCore::isClickableControl):
* html/HTMLTextFormControlElement.h:
(WebCore::isHTMLTextFormControlElement):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::attachLater):
* html/parser/HTMLElementStack.cpp:
(WebCore::HTMLElementStack::htmlElement):
* html/parser/HTMLStackItem.h:
(WebCore::HTMLStackItem::element):
* html/shadow/InsertionPoint.h:
(WebCore::parentElementForDistribution):
(WebCore::shadowRootOfParentForDistribution):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler):
* html/track/VTTCue.cpp:
(WebCore::VTTCue::markFutureAndPastNodes):
* inspector/DOMPatchSupport.cpp:
(WebCore::DOMPatchSupport::innerPatchNode):
(WebCore::DOMPatchSupport::createDigest):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::elementForId):
(WebCore::InspectorCSSAgent::buildArrayForRegions):
(WebCore::InspectorCSSAgent::resetPseudoStates):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::unbind):
(WebCore::InspectorDOMAgent::assertElement):
(WebCore::InspectorDOMAgent::setAttributesAsText):
(WebCore::InspectorDOMAgent::setNodeName):
(WebCore::InspectorDOMAgent::buildObjectForNode):
(WebCore::InspectorDOMAgent::buildObjectForAccessibilityProperties):
(WebCore::InspectorDOMAgent::didInvalidateStyleAttr):
* inspector/InspectorNodeFinder.cpp:
(WebCore::InspectorNodeFinder::searchUsingDOMTreeTraversal):
* inspector/InspectorOverlay.cpp:
(WebCore::buildObjectForElementInfo):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::inlineStyleSheetText):
* page/DragController.cpp:
(WebCore::elementUnderMouse):
* page/EventHandler.cpp:
(WebCore::findDropZone):
(WebCore::EventHandler::updateDragAndDrop):
(WebCore::EventHandler::updateMouseEventTargetNode):
* page/FocusController.cpp:
(WebCore::FocusNavigationScope::focusNavigationScopeOwnedByShadowHost):
(WebCore::isFocusableShadowHost):
(WebCore::adjustedTabIndex):
(WebCore::FocusController::findFocusableElementAcrossFocusScope):
(WebCore::FocusController::findElementWithExactTabIndex):
(WebCore::nextElementWithGreaterTabIndex):
(WebCore::previousElementWithLowerTabIndex):
(WebCore::FocusController::nextFocusableElement):
(WebCore::FocusController::previousFocusableElement):
(WebCore::FocusController::advanceFocusDirectionallyInContainer):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::serializeFrame):
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::title):
(WebCore::HitTestResult::innerTextIfTruncated):
(WebCore::HitTestResult::absoluteImageURL):
(WebCore::HitTestResult::innerElement):
(WebCore::HitTestResult::innerNonSharedElement):
* rendering/RenderDeprecatedFlexibleBox.h:
* rendering/RenderDetailsMarker.cpp:
(WebCore::RenderDetailsMarker::isOpen):
* rendering/RenderElement.h:
(WebCore::RenderElement::element):
(WebCore::RenderElement::nonPseudoElement):
(WebCore::RenderElement::generatingElement):
* rendering/RenderGrid.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::isRestartedPlugin):
* rendering/RenderListItem.h:
* rendering/RenderNamedFlowThread.cpp:
(WebCore::RenderNamedFlowThread::isChildAllowed):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::addPDFURLRect):
(WebCore::RenderObject::updateDragState):
(WebCore::RenderObject::getUncachedPseudoStyle):
* rendering/RenderRuby.h:
* rendering/RenderRubyText.h:
* rendering/RenderTableCaption.h:
* rendering/RenderTableCol.h:
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::isEnabled):
(WebCore::RenderTheme::isFocused):
(WebCore::RenderTheme::isPressed):
(WebCore::RenderTheme::isSpinUpButtonPartPressed):
(WebCore::RenderTheme::isReadOnlyControl):
(WebCore::RenderTheme::isHovered):
(WebCore::RenderTheme::isSpinUpButtonPartHovered):
* rendering/RenderThemeGtk.cpp:
(WebCore::nodeHasClass):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::updatePressedState):
(WebCore::RenderThemeMac::paintSliderThumb):
(WebCore::RenderThemeMac::paintSearchFieldCancelButton):
* rendering/RenderTreeAsText.cpp:
(WebCore::RenderTreeAsText::writeRenderObject):
* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::isAutosizingContainer):
(WebCore::TextAutosizer::containerContainsOneOfTags):
* rendering/mathml/RenderMathMLBlock.cpp:
(WebCore::RenderMathMLBlock::isChildAllowed):
* style/StyleResolveTree.cpp:
(WebCore::Style::attachChildren):
(WebCore::Style::attachDistributedChildren):
(WebCore::Style::detachDistributedChildren):
(WebCore::Style::detachChildren):
(WebCore::Style::resolveShadowTree):
(WebCore::Style::resolveTree):
* svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::expandSymbolElementsInShadowTree):
* svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::buildPendingResource):
* xml/XPathFunctions.cpp:
(WebCore::XPath::FunLang::evaluate):
* xml/XPathNodeSet.cpp:
(WebCore::XPath::NodeSet::traversalSort):
* xml/XPathStep.cpp:
(WebCore::XPath::nodeMatchesBasicTest):
(WebCore::XPath::Step::nodesInAxis):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::XMLDocumentParser):
(WebCore::XMLDocumentParser::endElementNs):

Source/WebKit/mac:

* WebView/WebRenderLayer.mm:
(+[WebRenderLayer nameForLayer:]):

Source/WebKit/win:

* DOMEventsClasses.cpp:
(DOMMouseEvent::toElement):
* DOMEventsClasses.h:

Source/WebKit2:

* Shared/WebRenderObject.cpp:
(WebKit::WebRenderObject::WebRenderObject):
* WebProcess/InjectedBundle/API/mac/WKDOMElement.mm:
(-[WKDOMElement hasAttribute:]):
(-[WKDOMElement getAttribute:]):
(-[WKDOMElement setAttribute:value:]):
(-[WKDOMElement tagName]):
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::elementBounds):
* WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
(WebKit::InjectedBundleHitTestResult::mediaType):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::sendTapHighlightForNodeIfNecessary):
(WebKit::WebPage::blurAssistedNode):
(WebKit::WebPage::getPositionInformation):
(WebKit::nextFocusableElement):
(WebKit::WebPage::elementDidFocus):

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

108 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AccessibilityMenuList.cpp
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilitySearchFieldButtons.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
Source/WebCore/bindings/js/JSNodeCustom.cpp
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/ContainerNodeAlgorithms.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementTraversal.h
Source/WebCore/dom/LiveNodeList.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/NodeRenderingTraversal.cpp
Source/WebCore/dom/Position.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/ShadowRoot.h
Source/WebCore/dom/StaticNodeList.cpp
Source/WebCore/dom/TreeScopeAdopter.cpp
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/BreakBlockquoteCommand.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FormatBlockCommand.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/IndentOutdentCommand.cpp
Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
Source/WebCore/editing/MarkupAccumulator.cpp
Source/WebCore/editing/MarkupAccumulator.h
Source/WebCore/editing/ModifySelectionListLevel.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/SpellChecker.cpp
Source/WebCore/editing/SplitTextNodeContainingElementCommand.cpp
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/cocoa/HTMLConverter.mm
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/html/HTMLDetailsElement.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLSourceElement.cpp
Source/WebCore/html/HTMLSummaryElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.h
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/html/parser/HTMLElementStack.cpp
Source/WebCore/html/parser/HTMLStackItem.h
Source/WebCore/html/shadow/InsertionPoint.h
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/track/VTTCue.cpp
Source/WebCore/inspector/DOMPatchSupport.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorNodeFinder.cpp
Source/WebCore/inspector/InspectorOverlay.cpp
Source/WebCore/inspector/InspectorStyleSheet.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/PageSerializer.cpp
Source/WebCore/rendering/HitTestResult.cpp
Source/WebCore/rendering/RenderDeprecatedFlexibleBox.h
Source/WebCore/rendering/RenderDetailsMarker.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/RenderGrid.h
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderListItem.h
Source/WebCore/rendering/RenderNamedFlowThread.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderRuby.h
Source/WebCore/rendering/RenderRubyText.h
Source/WebCore/rendering/RenderTableCaption.h
Source/WebCore/rendering/RenderTableCol.h
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderThemeGtk.cpp
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/rendering/TextAutosizer.cpp
Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
Source/WebCore/style/StyleResolveTree.cpp
Source/WebCore/svg/SVGUseElement.cpp
Source/WebCore/svg/animation/SVGSMILElement.cpp
Source/WebCore/xml/XPathFunctions.cpp
Source/WebCore/xml/XPathNodeSet.cpp
Source/WebCore/xml/XPathStep.cpp
Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebRenderLayer.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/DOMEventsClasses.cpp
Source/WebKit/win/DOMEventsClasses.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebRenderObject.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMElement.mm
Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 69dedc1..4565363 100644 (file)
@@ -1,3 +1,344 @@
+2014-09-30  Chris Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Element
+        https://bugs.webkit.org/show_bug.cgi?id=137241
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Element instead of isElementNode() /
+        toElement().
+
+        No new tests, no behavior change.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::nodeHasRole):
+        (WebCore::createFromRenderer):
+        (WebCore::AXObjectCache::handleLiveRegionCreated):
+        (WebCore::AXObjectCache::handleMenuItemSelected):
+        (WebCore::AXObjectCache::rootAXEditableElement):
+        (WebCore::isNodeAriaVisible):
+        * accessibility/AccessibilityMenuList.cpp:
+        (WebCore::AccessibilityMenuList::canSetFocusAttribute):
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::determineAccessibilityRole):
+        (WebCore::AccessibilityNodeObject::canvasHasFallbackContent):
+        (WebCore::AccessibilityNodeObject::isEnabled):
+        (WebCore::AccessibilityNodeObject::isPressed):
+        (WebCore::AccessibilityNodeObject::isHovered):
+        (WebCore::AccessibilityNodeObject::anchorElement):
+        (WebCore::nativeActionElement):
+        (WebCore::AccessibilityNodeObject::actionElement):
+        (WebCore::AccessibilityNodeObject::mouseButtonListener):
+        (WebCore::AccessibilityNodeObject::titleElementText):
+        (WebCore::AccessibilityNodeObject::helpText):
+        (WebCore::AccessibilityNodeObject::hierarchicalLevel):
+        (WebCore::AccessibilityNodeObject::title):
+        (WebCore::AccessibilityNodeObject::text):
+        (WebCore::accessibleNameForNode):
+        (WebCore::AccessibilityNodeObject::canSetFocusAttribute):
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::press):
+        (WebCore::AccessibilityObject::hasTagName):
+        (WebCore::AccessibilityObject::hasAttribute):
+        (WebCore::AccessibilityObject::element):
+        (WebCore::AccessibilityObject::classList):
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::anchorElement):
+        (WebCore::AccessibilityRenderObject::helpText):
+        (WebCore::AccessibilityRenderObject::checkboxOrRadioRect):
+        (WebCore::AccessibilityRenderObject::titleUIElement):
+        (WebCore::AccessibilityRenderObject::accessKey):
+        (WebCore::AccessibilityRenderObject::setElementAttributeValue):
+        (WebCore::AccessibilityRenderObject::setFocused):
+        (WebCore::AccessibilityRenderObject::setValue):
+        (WebCore::AccessibilityRenderObject::handleActiveDescendantChanged):
+        (WebCore::AccessibilityRenderObject::correspondingLabelForControlElement):
+        (WebCore::AccessibilityRenderObject::renderObjectIsObservable):
+        (WebCore::AccessibilityRenderObject::inheritsPresentationalRole):
+        (WebCore::AccessibilityRenderObject::setAccessibleName):
+        (WebCore::AccessibilityRenderObject::stringRoleForMSAA):
+        * accessibility/AccessibilitySearchFieldButtons.cpp:
+        (WebCore::AccessibilitySearchFieldCancelButton::press):
+        * accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
+        (webkitAccessibleGetAttributes):
+        * bindings/gobject/WebKitDOMPrivate.cpp:
+        (WebKit::wrap):
+        * bindings/js/JSNodeCustom.cpp:
+        (WebCore::isReachableFromDOM):
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::styledNode):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::locateCousinList):
+        * dom/ContainerNode.cpp:
+        (WebCore::destroyRenderTreeIfNeeded):
+        (WebCore::ContainerNode::notifyChildRemoved):
+        * dom/ContainerNodeAlgorithms.cpp:
+        (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
+        (WebCore::ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument):
+        (WebCore::ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree):
+        (WebCore::assertConnectedSubrameCountIsConsistent):
+        * dom/Document.cpp:
+        (WebCore::Document::importNode):
+        (WebCore::Document::elementFromPoint):
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::collectActiveStyleSheets):
+        * dom/Element.cpp:
+        (WebCore::Element::computeInheritedLanguage):
+        * dom/Element.h:
+        (WebCore::isElement):
+        (WebCore::Node::hasAttributes):
+        (WebCore::Node::attributes):
+        (WebCore::Node::parentElement):
+        * dom/ElementTraversal.h:
+        (WebCore::Traversal<Element>::nextTemplate):
+        (WebCore::ElementTraversal::previousIncludingPseudo):
+        (WebCore::ElementTraversal::nextIncludingPseudo):
+        (WebCore::ElementTraversal::nextIncludingPseudoSkippingChildren):
+        (WebCore::ElementTraversal::pseudoAwarePreviousSibling):
+        * dom/LiveNodeList.cpp:
+        (WebCore::LiveNodeList::namedItem):
+        * dom/Node.cpp:
+        (WebCore::Node::dumpStatistics):
+        (WebCore::Node::normalize):
+        (WebCore::Node::pseudoAwareFirstChild):
+        (WebCore::Node::pseudoAwareLastChild):
+        (WebCore::Node::computedStyle):
+        (WebCore::Node::parentOrShadowHostElement):
+        (WebCore::Node::rootEditableElement):
+        (WebCore::Node::isEqualNode):
+        (WebCore::Node::isDefaultNamespace):
+        (WebCore::Node::lookupNamespacePrefix):
+        (WebCore::Node::ancestorElement):
+        (WebCore::appendAttributeDesc):
+        (WebCore::Node::showNodePathForThis):
+        (WebCore::Node::enclosingLinkEventParentOrSelf):
+        (WebCore::Node::handleLocalEvents):
+        (WebCore::Node::willRespondToMouseMoveEvents):
+        (WebCore::Node::willRespondToMouseClickEvents):
+        * dom/NodeRenderingTraversal.cpp:
+        (WebCore::NodeRenderingTraversal::nodeCanBeDistributed):
+        * dom/Position.cpp:
+        (WebCore::Position::element):
+        * dom/Range.cpp:
+        (WebCore::Range::getBorderAndTextQuads):
+        * dom/ShadowRoot.h:
+        (WebCore::Node::shadowRoot):
+        * dom/StaticNodeList.cpp:
+        (WebCore::StaticNodeList::namedItem):
+        * dom/TreeScopeAdopter.cpp:
+        (WebCore::TreeScopeAdopter::moveTreeToNewScope):
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::dummySpanAncestorForNode):
+        (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
+        (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode):
+        (WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical):
+        (WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical):
+        (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
+        * editing/BreakBlockquoteCommand.cpp:
+        (WebCore::BreakBlockquoteCommand::doApply):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::isRemovableBlock):
+        (WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss):
+        * editing/Editor.cpp:
+        (WebCore::Editor::isSpellCheckingEnabledFor):
+        (WebCore::Editor::applyEditingStyleToBodyElement):
+        * editing/FormatBlockCommand.cpp:
+        (WebCore::isElementForFormatBlock):
+        (WebCore::FormatBlockCommand::elementForFormatBlockCommand):
+        * editing/FrameSelection.cpp:
+        (WebCore::removingNodeRemovesPosition):
+        (WebCore::CaretBase::paintCaret):
+        (WebCore::FrameSelection::debugRenderer):
+        * editing/IndentOutdentCommand.cpp:
+        (WebCore::IndentOutdentCommand::outdentParagraph):
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::doApply):
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::serializeNodesWithNamespaces):
+        (WebCore::MarkupAccumulator::appendStartMarkup):
+        * editing/MarkupAccumulator.h:
+        (WebCore::MarkupAccumulator::appendEndTag):
+        * editing/ModifySelectionListLevel.cpp:
+        (WebCore::IncreaseSelectionListLevelCommand::doApply):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::isMailPasteAsQuotationNode):
+        (WebCore::haveSameTagName):
+        (WebCore::handleStyleSpansBeforeInsertion):
+        (WebCore::ReplaceSelectionCommand::doApply):
+        * editing/SpellChecker.cpp:
+        (WebCore::SpellChecker::isCheckable):
+        * editing/SplitTextNodeContainingElementCommand.cpp:
+        (WebCore::SplitTextNodeContainingElementCommand::doApply):
+        * editing/TextIterator.cpp:
+        (WebCore::isRendererReplacedElement):
+        * editing/cocoa/HTMLConverter.mm:
+        (HTMLConverterCaches::propertyValueForNode):
+        (HTMLConverterCaches::floatPropertyValueForNode):
+        (HTMLConverterCaches::colorPropertyValueForNode):
+        (HTMLConverter::aggregatedAttributesForAncestors):
+        (HTMLConverter::aggregatedAttributesForElementAndItsAncestors):
+        (HTMLConverter::_traverseNode):
+        (WebCore::editingAttributedStringFromRange):
+        * editing/htmlediting.cpp:
+        (WebCore::unsplittableElementForPosition):
+        (WebCore::enclosingBlock):
+        (WebCore::enclosingElementWithTag):
+        (WebCore::enclosingTableCell):
+        (WebCore::enclosingAnchorElement):
+        (WebCore::areIdenticalElements):
+        (WebCore::isNonTableCellHTMLBlockElement):
+        (WebCore::deprecatedEnclosingBlockFlowElement):
+        (WebCore::rendererForCaretPainting):
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::wrapWithNode):
+        (WebCore::createMarkupInternal):
+        (WebCore::createFragmentFromText):
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::DetailsSummaryElement::fallbackSummary):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::insertAdjacentElement):
+        (WebCore::contextElementForInsertion):
+        (WebCore::HTMLElement::directionality):
+        * html/HTMLFormControlElement.h:
+        (WebCore::isHTMLFormControlElement):
+        * html/HTMLMediaElement.h:
+        (WebCore::isHTMLMediaElement):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::collectOptionInnerText):
+        * html/HTMLSourceElement.cpp:
+        (WebCore::HTMLSourceElement::removedFrom):
+        * html/HTMLSummaryElement.cpp:
+        (WebCore::isClickableControl):
+        * html/HTMLTextFormControlElement.h:
+        (WebCore::isHTMLTextFormControlElement):
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::HTMLConstructionSite::attachLater):
+        * html/parser/HTMLElementStack.cpp:
+        (WebCore::HTMLElementStack::htmlElement):
+        * html/parser/HTMLStackItem.h:
+        (WebCore::HTMLStackItem::element):
+        * html/shadow/InsertionPoint.h:
+        (WebCore::parentElementForDistribution):
+        (WebCore::shadowRootOfParentForDistribution):
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler):
+        * html/track/VTTCue.cpp:
+        (WebCore::VTTCue::markFutureAndPastNodes):
+        * inspector/DOMPatchSupport.cpp:
+        (WebCore::DOMPatchSupport::innerPatchNode):
+        (WebCore::DOMPatchSupport::createDigest):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::elementForId):
+        (WebCore::InspectorCSSAgent::buildArrayForRegions):
+        (WebCore::InspectorCSSAgent::resetPseudoStates):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::unbind):
+        (WebCore::InspectorDOMAgent::assertElement):
+        (WebCore::InspectorDOMAgent::setAttributesAsText):
+        (WebCore::InspectorDOMAgent::setNodeName):
+        (WebCore::InspectorDOMAgent::buildObjectForNode):
+        (WebCore::InspectorDOMAgent::buildObjectForAccessibilityProperties):
+        (WebCore::InspectorDOMAgent::didInvalidateStyleAttr):
+        * inspector/InspectorNodeFinder.cpp:
+        (WebCore::InspectorNodeFinder::searchUsingDOMTreeTraversal):
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::buildObjectForElementInfo):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyleSheet::inlineStyleSheetText):
+        * page/DragController.cpp:
+        (WebCore::elementUnderMouse):
+        * page/EventHandler.cpp:
+        (WebCore::findDropZone):
+        (WebCore::EventHandler::updateDragAndDrop):
+        (WebCore::EventHandler::updateMouseEventTargetNode):
+        * page/FocusController.cpp:
+        (WebCore::FocusNavigationScope::focusNavigationScopeOwnedByShadowHost):
+        (WebCore::isFocusableShadowHost):
+        (WebCore::adjustedTabIndex):
+        (WebCore::FocusController::findFocusableElementAcrossFocusScope):
+        (WebCore::FocusController::findElementWithExactTabIndex):
+        (WebCore::nextElementWithGreaterTabIndex):
+        (WebCore::previousElementWithLowerTabIndex):
+        (WebCore::FocusController::nextFocusableElement):
+        (WebCore::FocusController::previousFocusableElement):
+        (WebCore::FocusController::advanceFocusDirectionallyInContainer):
+        * page/PageSerializer.cpp:
+        (WebCore::PageSerializer::serializeFrame):
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::title):
+        (WebCore::HitTestResult::innerTextIfTruncated):
+        (WebCore::HitTestResult::absoluteImageURL):
+        (WebCore::HitTestResult::innerElement):
+        (WebCore::HitTestResult::innerNonSharedElement):
+        * rendering/RenderDeprecatedFlexibleBox.h:
+        * rendering/RenderDetailsMarker.cpp:
+        (WebCore::RenderDetailsMarker::isOpen):
+        * rendering/RenderElement.h:
+        (WebCore::RenderElement::element):
+        (WebCore::RenderElement::nonPseudoElement):
+        (WebCore::RenderElement::generatingElement):
+        * rendering/RenderGrid.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::isRestartedPlugin):
+        * rendering/RenderListItem.h:
+        * rendering/RenderNamedFlowThread.cpp:
+        (WebCore::RenderNamedFlowThread::isChildAllowed):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::addPDFURLRect):
+        (WebCore::RenderObject::updateDragState):
+        (WebCore::RenderObject::getUncachedPseudoStyle):
+        * rendering/RenderRuby.h:
+        * rendering/RenderRubyText.h:
+        * rendering/RenderTableCaption.h:
+        * rendering/RenderTableCol.h:
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::isEnabled):
+        (WebCore::RenderTheme::isFocused):
+        (WebCore::RenderTheme::isPressed):
+        (WebCore::RenderTheme::isSpinUpButtonPartPressed):
+        (WebCore::RenderTheme::isReadOnlyControl):
+        (WebCore::RenderTheme::isHovered):
+        (WebCore::RenderTheme::isSpinUpButtonPartHovered):
+        * rendering/RenderThemeGtk.cpp:
+        (WebCore::nodeHasClass):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::updatePressedState):
+        (WebCore::RenderThemeMac::paintSliderThumb):
+        (WebCore::RenderThemeMac::paintSearchFieldCancelButton):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::RenderTreeAsText::writeRenderObject):
+        * rendering/TextAutosizer.cpp:
+        (WebCore::TextAutosizer::isAutosizingContainer):
+        (WebCore::TextAutosizer::containerContainsOneOfTags):
+        * rendering/mathml/RenderMathMLBlock.cpp:
+        (WebCore::RenderMathMLBlock::isChildAllowed):
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::attachChildren):
+        (WebCore::Style::attachDistributedChildren):
+        (WebCore::Style::detachDistributedChildren):
+        (WebCore::Style::detachChildren):
+        (WebCore::Style::resolveShadowTree):
+        (WebCore::Style::resolveTree):
+        * svg/SVGUseElement.cpp:
+        (WebCore::SVGUseElement::expandSymbolElementsInShadowTree):
+        * svg/animation/SVGSMILElement.cpp:
+        (WebCore::SVGSMILElement::buildPendingResource):
+        * xml/XPathFunctions.cpp:
+        (WebCore::XPath::FunLang::evaluate):
+        * xml/XPathNodeSet.cpp:
+        (WebCore::XPath::NodeSet::traversalSort):
+        * xml/XPathStep.cpp:
+        (WebCore::XPath::nodeMatchesBasicTest):
+        (WebCore::XPath::Step::nodesInAxis):
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::XMLDocumentParser):
+        (WebCore::XMLDocumentParser::endElementNs):
+
 2014-09-30  Brian J. Burg  <burg@cs.washington.edu>
 
         Web Replay: use static Strings instead of AtomicStrings for replay input type tags
index 67475c2..6d2f32c 100644 (file)
@@ -253,10 +253,10 @@ AccessibilityObject* AXObjectCache::get(Node* node)
 // FIXME: This should take a const char*, but one caller passes nullAtom.
 bool nodeHasRole(Node* node, const String& role)
 {
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return false;
 
-    auto& roleValue = toElement(node)->fastGetAttribute(roleAttr);
+    auto& roleValue = downcast<Element>(*node).fastGetAttribute(roleAttr);
     if (role.isNull())
         return roleValue.isEmpty();
     if (roleValue.isEmpty())
@@ -294,7 +294,7 @@ static PassRefPtr<AccessibilityObject> createFromRenderer(RenderObject* renderer
         return AccessibilitySVGRoot::create(renderer);
     
     // Search field buttons
-    if (node && node->isElementNode() && toElement(node)->isSearchFieldCancelButtonElement())
+    if (node && is<Element>(node) && downcast<Element>(*node).isSearchFieldCancelButtonElement())
         return AccessibilitySearchFieldCancelButton::create(renderer);
     
     if (renderer->isBoxModelObject()) {
@@ -653,10 +653,10 @@ void AXObjectCache::handleMenuOpened(Node* node)
     
 void AXObjectCache::handleLiveRegionCreated(Node* node)
 {
-    if (!node || !node->renderer() || !node->isElementNode())
+    if (!node || !node->renderer() || !is<Element>(node))
         return;
     
-    Element* element = toElement(node);
+    Element* element = downcast<Element>(node);
     String liveRegionStatus = element->fastGetAttribute(aria_liveAttr);
     if (liveRegionStatus.isEmpty()) {
         const AtomicString& ariaRole = element->fastGetAttribute(roleAttr);
@@ -820,7 +820,7 @@ void AXObjectCache::handleMenuItemSelected(Node* node)
     if (!nodeHasRole(node, "menuitem") && !nodeHasRole(node, "menuitemradio") && !nodeHasRole(node, "menuitemcheckbox"))
         return;
     
-    if (!toElement(node)->focused() && !equalIgnoringCase(toElement(node)->fastGetAttribute(aria_selectedAttr), "true"))
+    if (!downcast<Element>(*node).focused() && !equalIgnoringCase(downcast<Element>(*node).fastGetAttribute(aria_selectedAttr), "true"))
         return;
     
     postNotification(getOrCreate(node), &document(), AXMenuListItemSelected);
@@ -1030,7 +1030,7 @@ void AXObjectCache::textMarkerDataForVisiblePosition(TextMarkerData& textMarkerD
 const Element* AXObjectCache::rootAXEditableElement(const Node* node)
 {
     const Element* result = node->rootEditableElement();
-    const Element* element = node->isElementNode() ? toElement(node) : node->parentElement();
+    const Element* element = is<Element>(node) ? downcast<Element>(node) : node->parentElement();
 
     for (; element; element = element->parentElement()) {
         if (nodeIsTextControl(element))
@@ -1073,8 +1073,8 @@ bool isNodeAriaVisible(Node* node)
     // To determine if a node is ARIA visible, we need to check the parent hierarchy to see if anyone specifies
     // aria-hidden explicitly.
     for (Node* testNode = node; testNode; testNode = testNode->parentNode()) {
-        if (testNode->isElementNode()) {
-            const AtomicString& ariaHiddenValue = toElement(testNode)->fastGetAttribute(aria_hiddenAttr);
+        if (is<Element>(testNode)) {
+            const AtomicString& ariaHiddenValue = downcast<Element>(*testNode).fastGetAttribute(aria_hiddenAttr);
             if (equalIgnoringCase(ariaHiddenValue, "false"))
                 return true;
             if (equalIgnoringCase(ariaHiddenValue, "true"))
index 04c7987..6e2ce54 100644 (file)
@@ -100,7 +100,7 @@ bool AccessibilityMenuList::canSetFocusAttribute() const
     if (!node())
         return false;
 
-    return !toElement(node())->isDisabledFormControl();
+    return !downcast<Element>(*node()).isDisabledFormControl();
 }
 
 void AccessibilityMenuList::didUpdateActiveOption(int optionIndex)
index 0262ffd..bdbe344 100644 (file)
@@ -42,6 +42,7 @@
 #include "FrameSelection.h"
 #include "FrameView.h"
 #include "HTMLAreaElement.h"
+#include "HTMLCanvasElement.h"
 #include "HTMLFieldSetElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLFrameElementBase.h"
@@ -324,7 +325,7 @@ AccessibilityRole AccessibilityNodeObject::determineAccessibilityRole()
         return ParagraphRole;
     if (is<HTMLLabelElement>(node()))
         return LabelRole;
-    if (node()->isElementNode() && toElement(node())->isFocusable())
+    if (is<Element>(node()) && downcast<Element>(*node()).isFocusable())
         return GroupRole;
     
     return UnknownRole;
@@ -441,9 +442,9 @@ bool AccessibilityNodeObject::computeAccessibilityIsIgnored() const
 bool AccessibilityNodeObject::canvasHasFallbackContent() const
 {
     Node* node = this->node();
-    if (!node || !node->hasTagName(canvasTag))
+    if (!node || !is<HTMLCanvasElement>(node))
         return false;
-    Element& canvasElement = toElement(*node);
+    HTMLCanvasElement& canvasElement = downcast<HTMLCanvasElement>(*node);
     // If it has any children that are elements, we'll assume it might be fallback
     // content. If it has no children or its only children are not elements
     // (e.g. just text nodes), it doesn't have fallback content.
@@ -642,10 +643,10 @@ bool AccessibilityNodeObject::isEnabled() const
         return false;
     
     Node* node = this->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return true;
 
-    return !toElement(node)->isDisabledFormControl();
+    return !downcast<Element>(*node).isDisabledFormControl();
 }
 
 bool AccessibilityNodeObject::isIndeterminate() const
@@ -677,9 +678,9 @@ bool AccessibilityNodeObject::isPressed() const
         return false;
     }
 
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return false;
-    return toElement(node)->active();
+    return downcast<Element>(*node).active();
 }
 
 bool AccessibilityNodeObject::isChecked() const
@@ -719,7 +720,7 @@ bool AccessibilityNodeObject::isHovered() const
     if (!node)
         return false;
 
-    return node->isElementNode() && toElement(node)->hovered();
+    return is<Element>(node) && downcast<Element>(*node).hovered();
 }
 
 bool AccessibilityNodeObject::isMultiSelectable() const
@@ -965,7 +966,7 @@ Element* AccessibilityNodeObject::anchorElement() const
     // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
     for ( ; node; node = node->parentNode()) {
         if (is<HTMLAnchorElement>(node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
-            return toElement(node);
+            return downcast<Element>(node);
     }
 
     return nullptr;
@@ -994,7 +995,7 @@ static Element* nativeActionElement(Node* start)
     
     for (Node* child = start->firstChild(); child; child = child->nextSibling()) {
         if (isNodeActionElement(child))
-            return toElement(child);
+            return downcast<Element>(child);
 
         if (Element* subChild = nativeActionElement(child))
             return subChild;
@@ -1009,10 +1010,10 @@ Element* AccessibilityNodeObject::actionElement() const
         return nullptr;
 
     if (isNodeActionElement(node))
-        return toElement(node);
+        return downcast<Element>(node);
     
     if (AccessibilityObject::isARIAInput(ariaRoleAttribute()))
-        return toElement(node);
+        return downcast<Element>(node);
 
     switch (roleValue()) {
     case ButtonRole:
@@ -1026,7 +1027,7 @@ Element* AccessibilityNodeObject::actionElement() const
         // Check if the author is hiding the real control element inside the ARIA element.
         if (Element* nativeElement = nativeActionElement(node))
             return nativeElement;
-        return toElement(node);
+        return downcast<Element>(node);
     default:
         break;
     }
@@ -1045,7 +1046,7 @@ Element* AccessibilityNodeObject::mouseButtonListener(MouseButtonListenerResultF
 
     // check if our parent is a mouse button listener
     // FIXME: Do the continuation search like anchorElement does
-    for (auto& element : elementLineage(node->isElementNode() ? toElement(node) : node->parentElement())) {
+    for (auto& element : elementLineage(is<Element>(node) ? downcast<Element>(node) : node->parentElement())) {
         // If we've reached the body and this is not a control element, do not expose press action for this element unless filter is IncludeBodyElement.
         // It can cause false positives, where every piece of text is labeled as accepting press actions.
         if (element.hasTagName(bodyTag) && isStaticText() && filter == ExcludeBodyElement)
@@ -1253,8 +1254,7 @@ void AccessibilityNodeObject::titleElementText(Vector<AccessibilityText>& textOr
     
     bool isInputTag = is<HTMLInputElement>(node);
     if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl()) {
-        HTMLLabelElement* label = labelForElement(toElement(node));
-        if (label) {
+        if (HTMLLabelElement* label = labelForElement(downcast<Element>(node))) {
             AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label);
             String innerText = label->innerText();
             // Only use the <label> text if there's no ARIA override.
@@ -1532,21 +1532,22 @@ String AccessibilityNodeObject::helpText() const
         return describedBy;
     
     String description = accessibilityDescription();
-    for (Node* curr = node; curr; curr = curr->parentNode()) {
-        if (curr->isHTMLElement()) {
-            const AtomicString& summary = toElement(curr)->getAttribute(summaryAttr);
+    for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
+        if (is<HTMLElement>(ancestor)) {
+            HTMLElement& element = downcast<HTMLElement>(*ancestor);
+            const AtomicString& summary = element.getAttribute(summaryAttr);
             if (!summary.isEmpty())
                 return summary;
             
             // The title attribute should be used as help text unless it is already being used as descriptive text.
-            const AtomicString& title = toElement(curr)->getAttribute(titleAttr);
+            const AtomicString& title = element.getAttribute(titleAttr);
             if (!title.isEmpty() && description != title)
                 return title;
         }
         
         // Only take help text from an ancestor element if its a group or an unknown role. If help was 
         // added to those kinds of elements, it is likely it was meant for a child element.
-        AccessibilityObject* axObj = axObjectCache()->getOrCreate(curr);
+        AccessibilityObject* axObj = axObjectCache()->getOrCreate(ancestor);
         if (axObj) {
             AccessibilityRole role = axObj->roleValue();
             if (role != GroupRole && role != UnknownRole)
@@ -1560,10 +1561,10 @@ String AccessibilityNodeObject::helpText() const
 unsigned AccessibilityNodeObject::hierarchicalLevel() const
 {
     Node* node = this->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return 0;
-    Element* element = toElement(node);
-    const AtomicString& ariaLevel = element->fastGetAttribute(aria_levelAttr);
+    Element& element = downcast<Element>(*node);
+    const AtomicString& ariaLevel = element.fastGetAttribute(aria_levelAttr);
     if (!ariaLevel.isEmpty())
         return ariaLevel.toInt();
     
@@ -1705,7 +1706,7 @@ String AccessibilityNodeObject::title() const
     }
 
     if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl()) {
-        HTMLLabelElement* label = labelForElement(toElement(node));
+        HTMLLabelElement* label = labelForElement(downcast<Element>(node));
         // Use the label text as the title if 1) the title element is NOT an exposed element and 2) there's no ARIA override.
         if (label && !exposesTitleUIElement() && !ariaAccessibilityDescription().length())
             return label->innerText();
@@ -1771,7 +1772,7 @@ String AccessibilityNodeObject::text() const
     if (!node->isElementNode())
         return String();
 
-    return toElement(node)->innerText();
+    return downcast<Element>(node)->innerText();
 }
 
 String AccessibilityNodeObject::stringValue() const
@@ -1843,15 +1844,15 @@ void AccessibilityNodeObject::colorValue(int& r, int& g, int& b) const
 static String accessibleNameForNode(Node* node)
 {
     ASSERT(node);
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return String();
     
-    Element* element = toElement(node);
-    const AtomicString& ariaLabel = element->fastGetAttribute(aria_labelAttr);
+    Element& element = downcast<Element>(*node);
+    const AtomicString& ariaLabel = element.fastGetAttribute(aria_labelAttr);
     if (!ariaLabel.isEmpty())
         return ariaLabel;
     
-    const AtomicString& alt = element->fastGetAttribute(altAttr);
+    const AtomicString& alt = element.fastGetAttribute(altAttr);
     if (!alt.isEmpty())
         return alt;
 
@@ -1872,12 +1873,12 @@ static String accessibleNameForNode(Node* node)
         if (axObject->accessibleNameDerivesFromContent())
             text = axObject->textUnderElement(AccessibilityTextUnderElementMode(AccessibilityTextUnderElementMode::TextUnderElementModeIncludeNameFromContentsChildren, true));
     } else
-        text = element->innerText();
+        text = element.innerText();
 
     if (!text.isEmpty())
         return text;
     
-    const AtomicString& title = element->fastGetAttribute(titleAttr);
+    const AtomicString& title = element.fastGetAttribute(titleAttr);
     if (!title.isEmpty())
         return title;
     
@@ -1943,15 +1944,15 @@ bool AccessibilityNodeObject::canSetFocusAttribute() const
     if (!node)
         return false;
 
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return false;
 
-    Element* element = toElement(node);
+    Element& element = downcast<Element>(*node);
 
-    if (element->isDisabledFormControl())
+    if (element.isDisabledFormControl())
         return false;
 
-    return element->supportsFocus();
+    return element.supportsFocus();
 }
 
 AccessibilityRole AccessibilityNodeObject::determineAriaRoleAttribute() const
index 2cf40c3..914dbdd 100644 (file)
@@ -851,8 +851,8 @@ bool AccessibilityObject::press()
         document->renderView()->hitTest(request, hitTestResult);
         if (hitTestResult.innerNode()) {
             Node* innerNode = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
-            if (innerNode->isElementNode())
-                hitTestElement = toElement(innerNode);
+            if (is<Element>(innerNode))
+                hitTestElement = downcast<Element>(innerNode);
         }
     }
     
@@ -1759,20 +1759,19 @@ String AccessibilityObject::invalidStatus() const
 bool AccessibilityObject::hasTagName(const QualifiedName& tagName) const
 {
     Node* node = this->node();
-    return node && node->isElementNode() && toElement(*node).hasTagName(tagName);
+    return node && is<Element>(node) && downcast<Element>(*node).hasTagName(tagName);
 }
     
 bool AccessibilityObject::hasAttribute(const QualifiedName& attribute) const
 {
-    Node* elementNode = node();
-    if (!elementNode)
+    Node* node = this->node();
+    if (!node)
         return false;
     
-    if (!elementNode->isElementNode())
+    if (!is<Element>(node))
         return false;
     
-    Element* element = toElement(elementNode);
-    return element->fastHasAttribute(attribute);
+    return downcast<Element>(*node).fastHasAttribute(attribute);
 }
     
 const AtomicString& AccessibilityObject::getAttribute(const QualifiedName& attribute) const
@@ -1967,8 +1966,8 @@ bool AccessibilityObject::hasHighlighting() const
 Element* AccessibilityObject::element() const
 {
     Node* node = this->node();
-    if (node && node->isElementNode())
-        return toElement(node);
+    if (node && is<Element>(node))
+        return downcast<Element>(node);
     return nullptr;
 }
 
@@ -2115,10 +2114,10 @@ String AccessibilityObject::identifierAttribute() const
 void AccessibilityObject::classList(Vector<String>& classList) const
 {
     Node* node = this->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return;
     
-    Element* element = toElement(node);
+    Element* element = downcast<Element>(node);
     DOMTokenList& list = element->classList();
     unsigned length = list.length();
     for (unsigned k = 0; k < length; k++)
index 85605e9..970eb2e 100644 (file)
@@ -586,7 +586,7 @@ Element* AccessibilityRenderObject::anchorElement() const
     Node* node = currRenderer->node();
     for ( ; node; node = node->parentNode()) {
         if (is<HTMLAnchorElement>(node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
-            return toElement(node);
+            return downcast<Element>(node);
     }
     
     return nullptr;
@@ -606,21 +606,22 @@ String AccessibilityRenderObject::helpText() const
         return describedBy;
     
     String description = accessibilityDescription();
-    for (RenderObject* curr = m_renderer; curr; curr = curr->parent()) {
-        if (curr->node() && curr->node()->isHTMLElement()) {
-            const AtomicString& summary = toElement(curr->node())->getAttribute(summaryAttr);
+    for (RenderObject* ancestor = m_renderer; ancestor; ancestor = ancestor->parent()) {
+        if (ancestor->node() && is<HTMLElement>(ancestor->node())) {
+            HTMLElement& element = downcast<HTMLElement>(*ancestor->node());
+            const AtomicString& summary = element.getAttribute(summaryAttr);
             if (!summary.isEmpty())
                 return summary;
             
             // The title attribute should be used as help text unless it is already being used as descriptive text.
-            const AtomicString& title = toElement(curr->node())->getAttribute(titleAttr);
+            const AtomicString& title = element.getAttribute(titleAttr);
             if (!title.isEmpty() && description != title)
                 return title;
         }
         
         // Only take help text from an ancestor element if its a group or an unknown role. If help was 
         // added to those kinds of elements, it is likely it was meant for a child element.
-        AccessibilityObject* axObj = axObjectCache()->getOrCreate(curr);
+        AccessibilityObject* axObj = axObjectCache()->getOrCreate(ancestor);
         if (axObj) {
             AccessibilityRole role = axObj->roleValue();
             if (role != GroupRole && role != UnknownRole)
@@ -845,7 +846,7 @@ LayoutRect AccessibilityRenderObject::checkboxOrRadioRect() const
     if (!m_renderer)
         return LayoutRect();
     
-    HTMLLabelElement* label = labelForElement(toElement(m_renderer->node()));
+    HTMLLabelElement* label = labelForElement(downcast<Element>(m_renderer->node()));
     if (!label || !label->renderer())
         return boundingBoxRect();
     
@@ -1105,9 +1106,9 @@ AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
         return axObjectCache()->getOrCreate(toRenderFieldset(m_renderer)->findLegend(RenderFieldset::IncludeFloatingOrOutOfFlow));
     
     Node* node = m_renderer->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return nullptr;
-    HTMLLabelElement* label = labelForElement(toElement(node));
+    HTMLLabelElement* label = labelForElement(downcast<Element>(node));
     if (label && label->renderer())
         return axObjectCache()->getOrCreate(label);
 
@@ -1466,9 +1467,9 @@ const AtomicString& AccessibilityRenderObject::accessKey() const
     Node* node = m_renderer->node();
     if (!node)
         return nullAtom;
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return nullAtom;
-    return toElement(node)->getAttribute(accesskeyAttr);
+    return downcast<Element>(*node).getAttribute(accesskeyAttr);
 }
 
 VisibleSelection AccessibilityRenderObject::selection() const
@@ -1542,11 +1543,10 @@ void AccessibilityRenderObject::setElementAttributeValue(const QualifiedName& at
         return;
     
     Node* node = m_renderer->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return;
     
-    Element* element = toElement(node);
-    element->setAttribute(attributeName, (value) ? "true" : "false");        
+    downcast<Element>(*node).setAttribute(attributeName, (value) ? "true" : "false");
 }
     
 bool AccessibilityRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
@@ -1646,7 +1646,7 @@ void AccessibilityRenderObject::setFocused(bool on)
     Document* document = this->document();
     Node* node = this->node();
 
-    if (!on || !node || !node->isElementNode()) {
+    if (!on || !node || !is<Element>(node)) {
         document->setFocusedElement(nullptr);
         return;
     }
@@ -1657,7 +1657,7 @@ void AccessibilityRenderObject::setFocused(bool on)
     if (document->focusedElement() == node)
         document->setFocusedElement(nullptr);
 
-    toElement(node)->focus();
+    downcast<Element>(*node).focus();
 }
 
 void AccessibilityRenderObject::setSelectedRows(AccessibilityChildrenVector& selectedRows)
@@ -1678,9 +1678,9 @@ void AccessibilityRenderObject::setSelectedRows(AccessibilityChildrenVector& sel
     
 void AccessibilityRenderObject::setValue(const String& string)
 {
-    if (!m_renderer || !m_renderer->node() || !m_renderer->node()->isElementNode())
+    if (!m_renderer || !m_renderer->node() || !is<Element>(m_renderer->node()))
         return;
-    Element& element = toElement(*m_renderer->node());
+    Element& element = downcast<Element>(*m_renderer->node());
 
     if (!m_renderer->isBoxModelObject())
         return;
@@ -2343,7 +2343,7 @@ void AccessibilityRenderObject::handleAriaExpandedChanged()
 
 void AccessibilityRenderObject::handleActiveDescendantChanged()
 {
-    Element* element = toElement(renderer()->node());
+    Element* element = downcast<Element>(renderer()->node());
     if (!element)
         return;
     if (!renderer()->frame().selection().isFocusedAndActive() || renderer()->document().focusedElement() != element)
@@ -2381,9 +2381,8 @@ AccessibilityObject* AccessibilityRenderObject::correspondingLabelForControlElem
         return nullptr;
 
     Node* node = m_renderer->node();
-    if (node && node->isHTMLElement()) {
-        HTMLLabelElement* label = labelForElement(toElement(node));
-        if (label)
+    if (node && is<HTMLElement>(node)) {
+        if (HTMLLabelElement* label = labelForElement(downcast<HTMLElement>(node)))
             return axObjectCache()->getOrCreate(label);
     }
 
@@ -2405,7 +2404,7 @@ bool AccessibilityRenderObject::renderObjectIsObservable(RenderObject* renderer)
         return true;
 
     // Textboxes should send out notifications.
-    if (nodeHasRole(node, "textbox") || (node->isElementNode() && contentEditableAttributeIsEnabled(toElement(node))))
+    if (nodeHasRole(node, "textbox") || (is<Element>(node) && contentEditableAttributeIsEnabled(downcast<Element>(node))))
         return true;
     
     return false;
@@ -2695,13 +2694,13 @@ bool AccessibilityRenderObject::inheritsPresentationalRole() const
         if (!parent->isAccessibilityRenderObject())
             continue;
         
-        Node* elementNode = toAccessibilityRenderObject(parent)->node();
-        if (!elementNode || !elementNode->isElementNode())
+        Node* node = toAccessibilityRenderObject(parent)->node();
+        if (!node || !is<Element>(node))
             continue;
         
         // If native tag of the parent element matches an acceptable name, then return
         // based on its presentational status.
-        if (possibleParentTagNames->contains(toElement(elementNode)->tagQName()))
+        if (possibleParentTagNames->contains(downcast<Element>(node)->tagQName()))
             return parent->roleValue() == PresentationalRole;
     }
     
@@ -3244,15 +3243,15 @@ void AccessibilityRenderObject::setAccessibleName(const AtomicString& name)
     if (!m_renderer)
         return;
 
-    Node* domNode = nullptr;
+    Node* node = nullptr;
     // For web areas, set the aria-label on the HTML element.
     if (isWebArea())
-        domNode = m_renderer->document().documentElement();
+        node = m_renderer->document().documentElement();
     else
-        domNode = m_renderer->node();
+        node = m_renderer->node();
 
-    if (domNode && domNode->isElementNode())
-        toElement(domNode)->setAttribute(aria_labelAttr, name);
+    if (node && is<Element>(node))
+        downcast<Element>(*node).setAttribute(aria_labelAttr, name);
 }
     
 static bool isLinkable(const AccessibilityRenderObject& object)
@@ -3372,14 +3371,14 @@ String AccessibilityRenderObject::stringRoleForMSAA() const
         return String();
 
     Node* node = m_renderer->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return String();
 
-    Element* element = toElement(node);
-    if (!shouldReturnTagNameAsRoleForMSAA(*element))
+    Element& element = downcast<Element>(*node);
+    if (!shouldReturnTagNameAsRoleForMSAA(element))
         return String();
 
-    return element->tagName();
+    return element.tagName();
 }
 
 String AccessibilityRenderObject::positionalDescriptionForMSAA() const
index fa3dccd..2c5c246 100644 (file)
@@ -58,13 +58,13 @@ void AccessibilitySearchFieldCancelButton::accessibilityText(Vector<Accessibilit
 bool AccessibilitySearchFieldCancelButton::press()
 {
     Node* node = this->node();
-    if (!node || !node->isElementNode())
+    if (!node || !is<Element>(node))
         return false;
     
-    Element* element = toElement(node);
+    Element& element = downcast<Element>(*node);
     // The default event handler on SearchFieldCancelButtonElement requires hover.
-    element->setHovered(true);
-    element->accessKeyAction(true);
+    element.setHovered(true);
+    element.accessKeyAction(true);
     return true;
 }
 
index 057427e..e1d2a82 100644 (file)
@@ -506,8 +506,8 @@ static AtkAttributeSet* webkitAccessibleGetAttributes(AtkObject* object)
     // cannot be done from the UIProcess. Assistive technologies have no need
     // for this information.
     Node* node = coreObject->node();
-    if (node && node->isElementNode()) {
-        String id = toElement(node)->getIdAttribute().string();
+    if (node && is<Element>(node)) {
+        String id = downcast<Element>(*node).getIdAttribute().string();
         if (!id.isEmpty())
             attributeSet = addToAtkAttributeSet(attributeSet, "html-id", id.utf8().data());
     }
index e6c9504..08c5f02 100644 (file)
@@ -86,7 +86,7 @@ WebKitDOMNode* wrap(Node* node)
     case Node::ELEMENT_NODE:
         if (is<HTMLElement>(node))
             return WEBKIT_DOM_NODE(wrap(downcast<HTMLElement>(node)));
-        return WEBKIT_DOM_NODE(wrapElement(toElement(node)));
+        return WEBKIT_DOM_NODE(wrapElement(downcast<Element>(node)));
     case Node::ATTRIBUTE_NODE:
         return WEBKIT_DOM_NODE(wrapAttr(static_cast<Attr*>(node)));
     case Node::TEXT_NODE:
index cf80609..d6c3c9d 100644 (file)
@@ -97,8 +97,8 @@ static inline bool isObservable(JSNode* jsNode, Node* node)
 static inline bool isReachableFromDOM(JSNode* jsNode, Node* node, SlotVisitor& visitor)
 {
     if (!node->inDocument()) {
-        if (node->isElementNode()) {
-            auto& element = toElement(*node);
+        if (is<Element>(node)) {
+            auto& element = downcast<Element>(*node);
 
             // If a wrapper is the last reference to an image element
             // that is loading but not in the document, the wrapper is observable
index 82b65ba..0790167 100644 (file)
@@ -1629,15 +1629,15 @@ Node* ComputedStyleExtractor::styledNode() const
 {
     if (!m_node)
         return nullptr;
-    if (!m_node->isElementNode())
+    if (!is<Element>(*m_node))
         return m_node.get();
-    Element* element = toElement(m_node.get());
+    Element& element = downcast<Element>(*m_node);
     PseudoElement* pseudoElement;
-    if (m_pseudoElementSpecifier == BEFORE && (pseudoElement = element->beforePseudoElement()))
+    if (m_pseudoElementSpecifier == BEFORE && (pseudoElement = element.beforePseudoElement()))
         return pseudoElement;
-    if (m_pseudoElementSpecifier == AFTER && (pseudoElement = element->afterPseudoElement()))
+    if (m_pseudoElementSpecifier == AFTER && (pseudoElement = element.afterPseudoElement()))
         return pseudoElement;
-    return element;
+    return &element;
 }
 
 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
index db4a4b1..078a5ca 100644 (file)
@@ -467,7 +467,7 @@ Node* StyleResolver::locateCousinList(Element* parent, unsigned& visitedNodeCoun
         while (currentNode) {
             ++subcount;
             if (currentNode->renderStyle() == parentStyle && currentNode->lastChild()
-                && currentNode->isElementNode() && !parentElementPreventsSharing(toElement(currentNode))
+                && is<Element>(currentNode) && !parentElementPreventsSharing(downcast<Element>(currentNode))
                 ) {
                 // Adjust for unused reserved tries.
                 visitedNodeCount -= cStyleSearchThreshold - subcount;
index 653f697..dcb1991 100644 (file)
@@ -100,8 +100,8 @@ static inline void destroyRenderTreeIfNeeded(Node& child)
     // FIXME: Get rid of the named flow test.
     if (!child.renderer() && !child.isNamedFlowContentNode())
         return;
-    if (child.isElementNode())
-        Style::detachRenderTree(toElement(child));
+    if (is<Element>(child))
+        Style::detachRenderTree(downcast<Element>(child));
     else if (is<Text>(child))
         Style::detachTextRenderer(downcast<Text>(child));
 }
@@ -347,9 +347,9 @@ void ContainerNode::notifyChildInserted(Node& child, ChildChangeSource source)
 void ContainerNode::notifyChildRemoved(Node& child, Node* previousSibling, Node* nextSibling, ChildChangeSource source)
 {
     ChildChange change;
-    change.type = child.isElementNode() ? ElementRemoved : child.isTextNode() ? TextRemoved : NonContentsChildChanged;
-    change.previousSiblingElement = (!previousSibling || previousSibling->isElementNode()) ? toElement(previousSibling) : ElementTraversal::previousSibling(previousSibling);
-    change.nextSiblingElement = (!nextSibling || nextSibling->isElementNode()) ? toElement(nextSibling) : ElementTraversal::nextSibling(nextSibling);
+    change.type = is<Element>(child) ? ElementRemoved : is<Text>(child) ? TextRemoved : NonContentsChildChanged;
+    change.previousSiblingElement = (!previousSibling || is<Element>(previousSibling)) ? downcast<Element>(previousSibling) : ElementTraversal::previousSibling(previousSibling);
+    change.nextSiblingElement = (!nextSibling || is<Element>(nextSibling)) ? downcast<Element>(nextSibling) : ElementTraversal::nextSibling(nextSibling);
     change.source = source;
 
     childrenChanged(change);
index 217918e..af5d410 100644 (file)
@@ -40,10 +40,10 @@ void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerN
             notifyNodeInsertedIntoDocument(*child);
     }
 
-    if (!node.isElementNode())
+    if (!is<Element>(node))
         return;
 
-    if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot()) {
+    if (RefPtr<ShadowRoot> root = downcast<Element>(node).shadowRoot()) {
         if (node.inDocument() && root->hostElement() == &node)
             notifyNodeInsertedIntoDocument(*root);
     }
@@ -71,13 +71,13 @@ void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode
             notifyNodeRemovedFromDocument(*child.get());
     }
 
-    if (!node.isElementNode())
+    if (!is<Element>(node))
         return;
 
     if (node.document().cssTarget() == &node)
         node.document().setCSSTarget(0);
 
-    if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot()) {
+    if (RefPtr<ShadowRoot> root = downcast<Element>(node).shadowRoot()) {
         if (!node.inDocument() && root->hostElement() == &node)
             notifyNodeRemovedFromDocument(*root.get());
     }
@@ -90,10 +90,10 @@ void ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree(ContainerNode& no
             notifyNodeRemovedFromTree(*toContainerNode(child));
     }
 
-    if (!node.isElementNode())
+    if (!is<Element>(node))
         return;
 
-    if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot())
+    if (RefPtr<ShadowRoot> root = downcast<Element>(node).shadowRoot())
         notifyNodeRemovedFromTree(*root.get());
 }
 
@@ -102,11 +102,11 @@ static unsigned assertConnectedSubrameCountIsConsistent(ContainerNode& node)
 {
     unsigned count = 0;
 
-    if (node.isElementNode()) {
+    if (is<Element>(node)) {
         if (is<HTMLFrameOwnerElement>(node) && downcast<HTMLFrameOwnerElement>(node).contentFrame())
             ++count;
 
-        if (ShadowRoot* root = toElement(node).shadowRoot())
+        if (ShadowRoot* root = downcast<Element>(node).shadowRoot())
             count += assertConnectedSubrameCountIsConsistent(*root);
     }
 
index 8e83e91..3e8acbc 100644 (file)
@@ -941,7 +941,7 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo
     case COMMENT_NODE:
         return createComment(importedNode->nodeValue());
     case ELEMENT_NODE: {
-        Element& oldElement = toElement(*importedNode);
+        Element& oldElement = downcast<Element>(*importedNode);
         // FIXME: The following check might be unnecessary. Is it possible that
         // oldElement has mismatched prefix/namespace?
         if (!hasValidNamespaceForElements(oldElement.tagQName())) {
@@ -1414,13 +1414,13 @@ Element* Document::elementFromPoint(const LayoutPoint& clientPoint)
         return nullptr;
 
     Node* node = nodeFromPoint(clientPoint);
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = node->parentNode();
 
     if (node)
         node = ancestorInThisScope(node);
 
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
index 78b0847..cda6c07 100644 (file)
@@ -281,7 +281,7 @@ void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleS
             }
 #endif
         } else if (is<HTMLLinkElement>(*node) || is<HTMLStyleElement>(*node) || is<SVGStyleElement>(*node)) {
-            Element& element = toElement(*node);
+            Element& element = downcast<Element>(*node);
             AtomicString title = element.fastGetAttribute(titleAttr);
             bool enabledViaScript = false;
             if (is<HTMLLinkElement>(element)) {
index 21ad566..e9cbe07 100644 (file)
@@ -2195,8 +2195,8 @@ AtomicString Element::computeInheritedLanguage() const
     // The language property is inherited, so we iterate over the parents to find the first language.
     const Node* currentNode = this;
     while ((currentNode = currentNode->parentNode())) {
-        if (currentNode->isElementNode()) {
-            if (const ElementData* elementData = toElement(*currentNode).elementData()) {
+        if (is<Element>(currentNode)) {
+            if (const ElementData* elementData = downcast<Element>(*currentNode).elementData()) {
                 if (const Attribute* attribute = elementData->findLanguageAttribute())
                     return attribute->value();
             }
index 5239355..187e9d3 100644 (file)
@@ -666,29 +666,24 @@ private:
     RefPtr<ElementData> m_elementData;
 };
 
-inline bool isElement(const Node& node) { return node.isElementNode(); }
-
-NODE_TYPE_CASTS(Element)
-
-template <>
-struct NodeTypeCastTraits<const Element, const Node> {
-    static bool isType(const Node& node) { return node.isElementNode(); }
-};
+SPECIALIZE_TYPE_TRAITS_BEGIN(Element)
+    static bool isElement(const Node& node) { return node.isElementNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 inline bool Node::hasAttributes() const
 {
-    return isElementNode() && toElement(this)->hasAttributes();
+    return is<Element>(*this) && downcast<Element>(*this).hasAttributes();
 }
 
 inline NamedNodeMap* Node::attributes() const
 {
-    return isElementNode() ? &toElement(this)->attributes() : nullptr;
+    return is<Element>(*this) ? &downcast<Element>(*this).attributes() : nullptr;
 }
 
 inline Element* Node::parentElement() const
 {
     ContainerNode* parent = parentNode();
-    return parent && parent->isElementNode() ? toElement(parent) : nullptr;
+    return parent && is<Element>(parent) ? downcast<Element>(parent) : nullptr;
 }
 
 inline bool Element::fastHasAttribute(const QualifiedName& name) const
index 1bbe589..02ffd33 100644 (file)
@@ -95,9 +95,9 @@ template <typename CurrentType>
 inline Element* Traversal<Element>::nextTemplate(CurrentType* current)
 {
     Node* node = NodeTraversal::next(current);
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = NodeTraversal::nextSkippingChildren(node);
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 template <>
@@ -105,9 +105,9 @@ template <typename CurrentType>
 inline Element* Traversal<Element>::nextTemplate(CurrentType* current, const Node* stayWithin)
 {
     Node* node = NodeTraversal::next(current, stayWithin);
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = NodeTraversal::nextSkippingChildren(node, stayWithin);
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 // Generic versions.
@@ -258,33 +258,33 @@ inline ElementType* Traversal<ElementType>::next(const Node* current, const Node
 inline Element* ElementTraversal::previousIncludingPseudo(const Node* current, const Node* stayWithin)
 {
     Node* node = NodeTraversal::previousIncludingPseudo(current, stayWithin);
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = NodeTraversal::previousIncludingPseudo(node, stayWithin);
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 inline Element* ElementTraversal::nextIncludingPseudo(const Node* current, const Node* stayWithin)
 {
     Node* node = NodeTraversal::nextIncludingPseudo(current, stayWithin);
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = NodeTraversal::nextIncludingPseudo(node, stayWithin);
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 inline Element* ElementTraversal::nextIncludingPseudoSkippingChildren(const Node* current, const Node* stayWithin)
 {
     Node* node = NodeTraversal::nextIncludingPseudoSkippingChildren(current, stayWithin);
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = NodeTraversal::nextIncludingPseudoSkippingChildren(node, stayWithin);
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 inline Element* ElementTraversal::pseudoAwarePreviousSibling(const Node* current)
 {
     Node* node = current->pseudoAwarePreviousSibling();
-    while (node && !node->isElementNode())
+    while (node && !is<Element>(node))
         node = node->pseudoAwarePreviousSibling();
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 }
index 4f8a45c..ee20e11 100644 (file)
@@ -68,11 +68,11 @@ Node* LiveNodeList::namedItem(const AtomicString& elementId) const
     unsigned length = this->length();
     for (unsigned i = 0; i < length; i++) {
         Node* node = item(i);
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
-        Element* element = toElement(node);
+        Element& element = downcast<Element>(*node);
         // FIXME: This should probably be using getIdAttribute instead of idForStyleResolution.
-        if (element->hasID() && element->idForStyleResolution() == elementId)
+        if (element.hasID() && element.idForStyleResolution() == elementId)
             return node;
     }
 
index ea92da8..22892be 100644 (file)
@@ -137,9 +137,9 @@ void Node::dumpStatistics()
 
         if (node->hasRareData()) {
             ++nodesWithRareData;
-            if (node->isElementNode()) {
+            if (is<Element>(node)) {
                 ++elementsWithRareData;
-                if (toElement(node)->hasNamedNodeMap())
+                if (downcast<Element>(*node).hasNamedNodeMap())
                     ++elementsWithNamedNodeMap;
             }
         }
@@ -149,12 +149,12 @@ void Node::dumpStatistics()
                 ++elementNodes;
 
                 // Tag stats
-                Element* element = toElement(node);
-                HashMap<String, size_t>::AddResult result = perTagCount.add(element->tagName(), 1);
+                Element& element = downcast<Element>(*node);
+                HashMap<String, size_t>::AddResult result = perTagCount.add(element.tagName(), 1);
                 if (!result.isNewEntry)
                     result.iterator->value++;
 
-                if (ElementData* elementData = element->elementData()) {
+                if (ElementData* elementData = element.elementData()) {
                     unsigned length = elementData->length();
                     attributes += length;
                     ++elementsWithAttributeStorage;
@@ -479,7 +479,7 @@ void Node::normalize()
     while (node) {
         NodeType type = node->nodeType();
         if (type == ELEMENT_NODE)
-            toElement(node.get())->normalizeAttributes();
+            downcast<Element>(*node).normalizeAttributes();
 
         if (node == this)
             break;
@@ -896,14 +896,14 @@ Node* Node::pseudoAwareNextSibling() const
 
 Node* Node::pseudoAwareFirstChild() const
 {
-    if (isElementNode()) {
-        const Element* currentElement = toElement(this);
-        Node* first = currentElement->beforePseudoElement();
+    if (is<Element>(*this)) {
+        const Element& currentElement = downcast<Element>(*this);
+        Node* first = currentElement.beforePseudoElement();
         if (first)
             return first;
-        first = currentElement->firstChild();
+        first = currentElement.firstChild();
         if (!first)
-            first = currentElement->afterPseudoElement();
+            first = currentElement.afterPseudoElement();
         return first;
     }
     return firstChild();
@@ -911,14 +911,14 @@ Node* Node::pseudoAwareFirstChild() const
 
 Node* Node::pseudoAwareLastChild() const
 {
-    if (isElementNode()) {
-        const Element* currentElement = toElement(this);
-        Node* last = currentElement->afterPseudoElement();
+    if (is<Element>(*this)) {
+        const Element& currentElement = downcast<Element>(*this);
+        Node* last = currentElement.afterPseudoElement();
         if (last)
             return last;
-        last = currentElement->lastChild();
+        last = currentElement.lastChild();
         if (!last)
-            last = currentElement->beforePseudoElement();
+            last = currentElement.beforePseudoElement();
         return last;
     }
     return lastChild();
@@ -927,8 +927,8 @@ Node* Node::pseudoAwareLastChild() const
 RenderStyle* Node::computedStyle(PseudoId pseudoElementSpecifier)
 {
     for (Node* node = this; node; node = node->parentOrShadowHostNode()) {
-        if (node->isElementNode())
-            return toElement(node)->computedStyle(pseudoElementSpecifier);
+        if (is<Element>(node))
+            return downcast<Element>(*node).computedStyle(pseudoElementSpecifier);
     }
     return nullptr;
 }
@@ -1007,10 +1007,10 @@ Element* Node::parentOrShadowHostElement() const
     if (is<ShadowRoot>(parent))
         return downcast<ShadowRoot>(parent)->hostElement();
 
-    if (!parent->isElementNode())
+    if (!is<Element>(parent))
         return nullptr;
 
-    return toElement(parent);
+    return downcast<Element>(parent);
 }
 
 Node* Node::insertionParentForBinding() const
@@ -1055,11 +1055,11 @@ Element* Node::rootEditableElement(EditableType editableType) const
 
 Element* Node::rootEditableElement() const
 {
-    Element* result = 0;
-    for (Node* n = const_cast<Node*>(this); n && n->hasEditableStyle(); n = n->parentNode()) {
-        if (n->isElementNode())
-            result = toElement(n);
-        if (n->hasTagName(bodyTag))
+    Element* result = nullptr;
+    for (Node* node = const_cast<Node*>(this); node && node->hasEditableStyle(); node = node->parentNode()) {
+        if (is<Element>(node))
+            result = downcast<Element>(node);
+        if (is<HTMLBodyElement>(node))
             break;
     }
     return result;
@@ -1102,7 +1102,7 @@ bool Node::isEqualNode(Node* other) const
     if (nodeValue() != other->nodeValue())
         return false;
     
-    if (isElementNode() && !toElement(this)->hasEquivalentAttributes(toElement(other)))
+    if (is<Element>(*this) && !downcast<Element>(*this).hasEquivalentAttributes(downcast<Element>(other)))
         return false;
     
     Node* child = firstChild();
@@ -1144,13 +1144,13 @@ bool Node::isDefaultNamespace(const AtomicString& namespaceURIMaybeEmpty) const
 
     switch (nodeType()) {
         case ELEMENT_NODE: {
-            const Element* elem = toElement(this);
+            const Element& element = downcast<Element>(*this);
             
-            if (elem->prefix().isNull())
-                return elem->namespaceURI() == namespaceURI;
+            if (element.prefix().isNull())
+                return element.namespaceURI() == namespaceURI;
 
-            if (elem->hasAttributes()) {
-                for (const Attribute& attribute : elem->attributesIterator()) {
+            if (element.hasAttributes()) {
+                for (const Attribute& attribute : element.attributesIterator()) {
                     if (attribute.localName() == xmlnsAtom)
                         return attribute.value() == namespaceURI;
                 }
@@ -1284,10 +1284,10 @@ String Node::lookupNamespacePrefix(const AtomicString &_namespaceURI, const Elem
     if (originalElement->lookupNamespaceURI(prefix()) == _namespaceURI)
         return prefix();
     
-    ASSERT(isElementNode());
-    const Element* thisElement = toElement(this);
-    if (thisElement->hasAttributes()) {
-        for (const Attribute& attribute : thisElement->attributesIterator()) {
+    ASSERT(is<Element>(*this));
+    const Element& thisElement = downcast<Element>(*this);
+    if (thisElement.hasAttributes()) {
+        for (const Attribute& attribute : thisElement.attributesIterator()) {
             if (attribute.prefix() == xmlnsAtom && attribute.value() == _namespaceURI
                 && originalElement->lookupNamespaceURI(attribute.localName()) == _namespaceURI)
                 return attribute.localName();
@@ -1383,11 +1383,11 @@ void Node::setTextContent(const String& text, ExceptionCode& ec)
 Element* Node::ancestorElement() const
 {
     // In theory, there can be EntityReference nodes between elements, but this is currently not supported.
-    for (ContainerNode* n = parentNode(); n; n = n->parentNode()) {
-        if (n->isElementNode())
-            return toElement(n);
+    for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+        if (is<Element>(ancestor))
+            return downcast<Element>(ancestor);
     }
-    return 0;
+    return nullptr;
 }
 
 bool Node::offsetInCharacters() const
@@ -1529,10 +1529,10 @@ FloatPoint Node::convertFromPage(const FloatPoint& p) const
 
 static void appendAttributeDesc(const Node* node, StringBuilder& stringBuilder, const QualifiedName& name, const char* attrDesc)
 {
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return;
 
-    String attr = toElement(node)->getAttribute(name);
+    const AtomicString& attr = downcast<Element>(*node).getAttribute(name);
     if (attr.isEmpty())
         return;
 
@@ -1584,8 +1584,8 @@ void Node::showNodePathForThis() const
         case ELEMENT_NODE: {
             fprintf(stderr, "/%s", node->nodeName().utf8().data());
 
-            const Element* element = toElement(node);
-            const AtomicString& idattr = element->getIdAttribute();
+            const Element& element = downcast<Element>(*node);
+            const AtomicString& idattr = element.getIdAttribute();
             bool hasIdAttr = !idattr.isNull() && !idattr.isEmpty();
             if (node->previousSibling() || node->nextSibling()) {
                 int count = 0;
@@ -1724,10 +1724,10 @@ Element* Node::enclosingLinkEventParentOrSelf()
         // So we don't let images be the enclosing link element, even though isLink sometimes returns
         // true for them.
         if (node->isLink() && !is<HTMLImageElement>(node))
-            return toElement(node);
+            return downcast<Element>(node);
     }
 
-    return 0;
+    return nullptr;
 }
 
 EventTargetInterface Node::eventTargetInterface() const
@@ -2018,7 +2018,7 @@ void Node::handleLocalEvents(Event& event)
     if (!hasEventTargetData())
         return;
 
-    if (isElementNode() && toElement(*this).isDisabledFormControl() && event.isMouseEvent())
+    if (is<Element>(*this) && downcast<Element>(*this).isDisabledFormControl() && event.isMouseEvent())
         return;
 
     fireEventListeners(&event);
@@ -2164,9 +2164,9 @@ bool Node::willRespondToMouseMoveEvents()
 {
     // FIXME: Why is the iOS code path different from the non-iOS code path?
 #if !PLATFORM(IOS)
-    if (!isElementNode())
+    if (!is<Element>(*this))
         return false;
-    if (toElement(this)->isDisabledFormControl())
+    if (downcast<Element>(*this).isDisabledFormControl())
         return false;
 #endif
     return hasEventListeners(eventNames().mousemoveEvent) || hasEventListeners(eventNames().mouseoverEvent) || hasEventListeners(eventNames().mouseoutEvent);
@@ -2178,9 +2178,9 @@ bool Node::willRespondToMouseClickEvents()
 #if PLATFORM(IOS)
     return isContentEditable() || hasEventListeners(eventNames().mouseupEvent) || hasEventListeners(eventNames().mousedownEvent) || hasEventListeners(eventNames().clickEvent);
 #else
-    if (!isElementNode())
+    if (!is<Element>(*this))
         return false;
-    if (toElement(this)->isDisabledFormControl())
+    if (downcast<Element>(*this).isDisabledFormControl())
         return false;
     return isContentEditable(UserSelectAllIsAlwaysNonEditable) || hasEventListeners(eventNames().mouseupEvent) || hasEventListeners(eventNames().mousedownEvent) || hasEventListeners(eventNames().clickEvent) || hasEventListeners(eventNames().DOMActivateEvent);
 #endif
index 28d1431..82ec7db 100644 (file)
@@ -52,7 +52,7 @@ static inline bool nodeCanBeDistributed(const Node* node)
     if (parent->isShadowRoot())
         return false;
 
-    if (parent->isElementNode() && toElement(parent)->shadowRoot())
+    if (is<Element>(parent) && downcast<Element>(*parent).shadowRoot())
         return true;
     
     return false;
index 39a4784..dc82190 100644 (file)
@@ -290,10 +290,10 @@ Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo
 // FIXME: This method is confusing (does it return anchorNode() or containerNode()?) and should be renamed or removed
 Element* Position::element() const
 {
-    Node* n = anchorNode();
-    while (n && !n->isElementNode())
-        n = n->parentNode();
-    return toElement(n);
+    Node* node = anchorNode();
+    while (node && !is<Element>(node))
+        node = node->parentNode();
+    return downcast<Element>(node);
 }
 
 Position Position::previous(PositionMoveType moveType) const
index 88b9b61..9eb0dc0 100644 (file)
@@ -2224,8 +2224,8 @@ void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const
         selectedElementsSet.remove(parent);
 
     for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(node)) {
-        if (node->isElementNode() && selectedElementsSet.contains(node) && !selectedElementsSet.contains(node->parentNode())) {
-            if (RenderBoxModelObject* renderBoxModelObject = toElement(node)->renderBoxModelObject()) {
+        if (is<Element>(node) && selectedElementsSet.contains(node) && !selectedElementsSet.contains(node->parentNode())) {
+            if (RenderBoxModelObject* renderBoxModelObject = downcast<Element>(*node).renderBoxModelObject()) {
                 Vector<FloatQuad> elementQuads;
                 renderBoxModelObject->absoluteQuads(elementQuads);
                 ownerDocument().adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(elementQuads, renderBoxModelObject->style());
index 70d12f8..bfe5b6f 100644 (file)
@@ -101,9 +101,9 @@ SPECIALIZE_TYPE_TRAITS_END()
 
 inline ShadowRoot* Node::shadowRoot() const
 {
-    if (!isElementNode())
+    if (!is<Element>(*this))
         return nullptr;
-    return toElement(this)->shadowRoot();
+    return downcast<Element>(*this).shadowRoot();
 }
 
 inline ContainerNode* Node::parentOrShadowHostNode() const
index 7e1f4c2..94967b7 100644 (file)
@@ -47,7 +47,7 @@ Node* StaticNodeList::namedItem(const AtomicString& elementId) const
 {
     for (unsigned i = 0, length = m_nodes.size(); i < length; ++i) {
         Node& node = const_cast<Node&>(m_nodes[i].get());
-        if (node.isElementNode() && toElement(node).getIdAttribute() == elementId)
+        if (is<Element>(node) && downcast<Element>(node).getIdAttribute() == elementId)
             return &node;
     }
     return nullptr;
index 6410f2c..045e88e 100644 (file)
@@ -60,11 +60,11 @@ void TreeScopeAdopter::moveTreeToNewScope(Node* root) const
                 rareData->nodeLists()->adoptTreeScope();
         }
 
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
 
         if (node->hasSyntheticAttrChildNodes()) {
-            const Vector<RefPtr<Attr>>& attrs = toElement(node)->attrNodeList();
+            const Vector<RefPtr<Attr>>& attrs = downcast<Element>(*node).attrNodeList();
             for (unsigned i = 0; i < attrs.size(); ++i)
                 moveTreeToNewScope(attrs[i].get());
         }
index f21852f..86d4a54 100644 (file)
@@ -420,10 +420,10 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
 
 static ContainerNode* dummySpanAncestorForNode(const Node* node)
 {
-    while (node && (!node->isElementNode() || !isStyleSpanOrSpanWithOnlyStyleAttribute(toElement(node))))
+    while (node && (!is<Element>(node) || !isStyleSpanOrSpanWithOnlyStyleAttribute(downcast<Element>(node))))
         node = node->parentNode();
     
-    return node ? node->parentNode() : 0;
+    return node ? node->parentNode() : nullptr;
 }
 
 void ApplyStyleCommand::cleanupUnstyledAppleStyleSpans(ContainerNode* dummySpanAncestor)
@@ -486,7 +486,7 @@ HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool b
     // Split every ancestor through highest ancestor with embedding.
     RefPtr<Node> currentNode = node;
     while (currentNode) {
-        RefPtr<Element> parent = toElement(currentNode->parentNode());
+        RefPtr<Element> parent = downcast<Element>(currentNode->parentNode());
         if (before ? currentNode->previousSibling() : currentNode->nextSibling())
             splitElement(parent, before ? currentNode : currentNode->nextSibling());
         if (parent == highestAncestorWithUnicodeBidi)
@@ -1040,7 +1040,7 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
         getChildNodes(*current.get(), currentChildren);
 
         RefPtr<StyledElement> styledElement;
-        if (is<StyledElement>(*current) && isStyledInlineElementToRemove(toElement(current.get()))) {
+        if (is<StyledElement>(*current) && isStyledInlineElementToRemove(downcast<Element>(current.get()))) {
             styledElement = downcast<StyledElement>(current.get());
             elementsToPushDown.append(*styledElement);
         }
@@ -1286,8 +1286,8 @@ bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start,
     Node* previousSibling = startNode->previousSibling();
 
     if (previousSibling && areIdenticalElements(startNode, previousSibling)) {
-        Element* previousElement = toElement(previousSibling);
-        Element* element = toElement(startNode);
+        Element* previousElement = downcast<Element>(previousSibling);
+        Element* element = downcast<Element>(startNode);
         Node* startChild = element->firstChild();
         ASSERT(startChild);
         mergeIdenticalElements(previousElement, element);
@@ -1319,8 +1319,8 @@ bool ApplyStyleCommand::mergeEndWithNextIfIdentical(const Position& start, const
 
     Node* nextSibling = endNode->nextSibling();
     if (nextSibling && areIdenticalElements(endNode, nextSibling)) {
-        Element* nextElement = toElement(nextSibling);
-        Element* element = toElement(endNode);
+        Element* nextElement = downcast<Element>(nextSibling);
+        Element* element = downcast<Element>(endNode);
         Node* nextChild = nextElement->firstChild();
 
         mergeIdenticalElements(element, nextElement);
@@ -1359,15 +1359,15 @@ void ApplyStyleCommand::surroundNodeRangeWithElement(PassRefPtr<Node> passedStar
 
     RefPtr<Node> nextSibling = element->nextSibling();
     RefPtr<Node> previousSibling = element->previousSibling();
-    if (nextSibling && nextSibling->isElementNode() && nextSibling->hasEditableStyle()
-        && areIdenticalElements(element.get(), toElement(nextSibling.get())))
-        mergeIdenticalElements(element.get(), toElement(nextSibling.get()));
+    if (nextSibling && is<Element>(*nextSibling) && nextSibling->hasEditableStyle()
+        && areIdenticalElements(element.get(), downcast<Element>(nextSibling.get())))
+        mergeIdenticalElements(element.get(), downcast<Element>(nextSibling.get()));
 
-    if (previousSibling && previousSibling->isElementNode() && previousSibling->hasEditableStyle()) {
+    if (previousSibling && is<Element>(*previousSibling) && previousSibling->hasEditableStyle()) {
         Node* mergedElement = previousSibling->nextSibling();
-        if (mergedElement->isElementNode() && mergedElement->hasEditableStyle()
-            && areIdenticalElements(toElement(previousSibling.get()), toElement(mergedElement)))
-            mergeIdenticalElements(toElement(previousSibling.get()), toElement(mergedElement));
+        if (is<Element>(mergedElement) && mergedElement->hasEditableStyle()
+            && areIdenticalElements(downcast<Element>(previousSibling.get()), downcast<Element>(mergedElement)))
+            mergeIdenticalElements(downcast<Element>(previousSibling.get()), downcast<Element>(mergedElement));
     }
 
     // FIXME: We should probably call updateStartEnd if the start or end was in the node
index f61711a..55233c5 100644 (file)
@@ -131,7 +131,7 @@ void BreakBlockquoteCommand::doApply()
         ancestors.append(node);
     
     // Insert a clone of the top blockquote after the break.
-    RefPtr<Element> clonedBlockquote = toElement(topBlockquote)->cloneElementWithoutChildren();
+    RefPtr<Element> clonedBlockquote = downcast<Element>(*topBlockquote).cloneElementWithoutChildren();
     insertNodeAfter(clonedBlockquote.get(), breakNode.get());
     
     // Clone startNode's ancestors into the cloned blockquote.
index 5dd4c30..a6e5541 100644 (file)
@@ -39,7 +39,9 @@
 #include "ElementTraversal.h"
 #include "ExceptionCodePlaceholder.h"
 #include "Frame.h"
+#include "HTMLDivElement.h"
 #include "HTMLElement.h"
+#include "HTMLLIElement.h"
 #include "HTMLNames.h"
 #include "InlineTextBox.h"
 #include "InsertIntoTextNodeCommand.h"
@@ -322,14 +324,14 @@ void CompositeEditCommand::insertLineBreak()
 
 bool CompositeEditCommand::isRemovableBlock(const Node* node)
 {
-    if (!node->hasTagName(divTag))
+    if (!is<HTMLDivElement>(node))
         return false;
 
     Node* parentNode = node->parentNode();
     if (parentNode && parentNode->firstChild() != parentNode->lastChild())
         return false;
 
-    if (!toElement(node)->hasAttributes())
+    if (!downcast<HTMLDivElement>(*node).hasAttributes())
         return true;
 
     return false;
@@ -1069,7 +1071,7 @@ void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
         for (size_t i = ancestors.size(); i != 0; --i) {
             Node* item = ancestors[i - 1].get();
             RefPtr<Node> child = item->cloneNode(isRenderedTable(item));
-            appendNode(child, toElement(lastNode.get()));
+            appendNode(child, downcast<Element>(lastNode.get()));
             lastNode = child.release();
         }
     }
@@ -1347,13 +1349,13 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
 
     RefPtr<Element> newBlock = 0;
     if (ContainerNode* blockEnclosingList = listNode->parentNode()) {
-        if (blockEnclosingList->hasTagName(liTag)) { // listNode is inside another list item
+        if (is<HTMLLIElement>(blockEnclosingList)) { // listNode is inside another list item
             if (visiblePositionAfterNode(blockEnclosingList) == visiblePositionAfterNode(listNode.get())) {
                 // If listNode appears at the end of the outer list item, then move listNode outside of this list item
                 // e.g. <ul><li>hello <ul><li><br></li></ul> </li></ul> should become <ul><li>hello</li> <ul><li><br></li></ul> </ul> after this section
                 // If listNode does NOT appear at the end, then we should consider it as a regular paragraph.
                 // e.g. <ul><li> <ul><li><br></li></ul> hello</li></ul> should become <ul><li> <div><br></div> hello</li></ul> at the end
-                splitElement(toElement(blockEnclosingList), listNode);
+                splitElement(downcast<HTMLLIElement>(blockEnclosingList), listNode);
                 removeNodePreservingChildren(listNode->parentNode());
                 newBlock = createListItemElement(document());
             }
@@ -1369,7 +1371,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
     if (isListItem(nextListNode.get()) || isListElement(nextListNode.get())) {
         // If emptyListItem follows another list item or nested list, split the list node.
         if (isListItem(previousListNode.get()) || isListElement(previousListNode.get()))
-            splitElement(toElement(listNode.get()), emptyListItem);
+            splitElement(downcast<Element>(listNode.get()), emptyListItem);
 
         // If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node.
         // Because we have splitted the element, emptyListItem is the first element in the list node.
@@ -1522,13 +1524,13 @@ PassRefPtr<Node> CompositeEditCommand::splitTreeToNode(Node* start, Node* end, b
 
     RefPtr<Node> endNode = end;
     for (node = start; node && node->parentNode() != endNode; node = node->parentNode()) {
-        if (!node->parentNode()->isElementNode())
+        if (!is<Element>(node->parentNode()))
             break;
         // Do not split a node when doing so introduces an empty node.
         VisiblePosition positionInParent = firstPositionInNode(node->parentNode());
         VisiblePosition positionInNode = firstPositionInOrBeforeNode(node.get());
         if (positionInParent != positionInNode)
-            splitElement(toElement(node->parentNode()), node);
+            splitElement(downcast<Element>(node->parentNode()), node);
     }
 
     return node.release();
index be376ff..abc5336 100644 (file)
@@ -34,7 +34,9 @@
 #include "Frame.h"
 #include "htmlediting.h"
 #include "HTMLInputElement.h"
+#include "HTMLLinkElement.h"
 #include "HTMLNames.h"
+#include "HTMLStyleElement.h"
 #include "HTMLTableElement.h"
 #include "NodeTraversal.h"
 #include "RenderTableCell.h"
@@ -434,7 +436,7 @@ void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr
     RefPtr<Node> node = range->firstNode();
     while (node && node != range->pastLastNode()) {
         RefPtr<Node> nextNode = NodeTraversal::next(node.get());
-        if ((node->hasTagName(styleTag) && !(toElement(node.get())->hasAttribute(scopedAttr))) || node->hasTagName(linkTag)) {
+        if ((is<HTMLStyleElement>(*node) && !downcast<HTMLStyleElement>(*node).hasAttribute(scopedAttr)) || is<HTMLLinkElement>(*node)) {
             nextNode = NodeTraversal::nextSkippingChildren(node.get());
             RefPtr<ContainerNode> rootEditableElement = node->rootEditableElement();
             if (rootEditableElement) {
index 90da019..ac458ac 100644 (file)
@@ -2378,7 +2378,7 @@ bool Editor::isSpellCheckingEnabledFor(Node* node) const
 {
     if (!node)
         return false;
-    const Element* focusedElement = node->isElementNode() ? toElement(node) : node->parentElement();
+    const Element* focusedElement = is<Element>(node) ? downcast<Element>(node) : node->parentElement();
     if (!focusedElement)
         return false;
     return focusedElement->isSpellCheckingEnabled();
@@ -3100,7 +3100,7 @@ void Editor::applyEditingStyleToBodyElement() const
     RefPtr<NodeList> list = document().getElementsByTagName("body");
     unsigned len = list->length();
     for (unsigned i = 0; i < len; i++)
-        applyEditingStyleToElement(toElement(list->item(i)));
+        applyEditingStyleToElement(downcast<Element>(list->item(i)));
 }
 
 void Editor::applyEditingStyleToElement(Element* element) const
index 4690f21..31745f9 100644 (file)
@@ -43,7 +43,7 @@ static Node* enclosingBlockToSplitTreeTo(Node* startNode);
 static bool isElementForFormatBlock(const QualifiedName& tagName);
 static inline bool isElementForFormatBlock(Node* node)
 {
-    return node->isElementNode() && isElementForFormatBlock(toElement(node)->tagQName());
+    return is<Element>(node) && isElementForFormatBlock(downcast<Element>(*node).tagQName());
 }
 
 FormatBlockCommand::FormatBlockCommand(Document& document, const QualifiedName& tagName)
@@ -100,20 +100,20 @@ void FormatBlockCommand::formatRange(const Position& start, const Position& end,
 Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range)
 {
     if (!range)
-        return 0;
+        return nullptr;
 
     Node* commonAncestor = range->commonAncestorContainer(IGNORE_EXCEPTION);
     while (commonAncestor && !isElementForFormatBlock(commonAncestor))
         commonAncestor = commonAncestor->parentNode();
 
     if (!commonAncestor)
-        return 0;
+        return nullptr;
 
     Element* rootEditableElement = range->startContainer()->rootEditableElement();
     if (!rootEditableElement || commonAncestor->contains(rootEditableElement))
-        return 0;
+        return nullptr;
 
-    return commonAncestor->isElementNode() ? toElement(commonAncestor) : 0;
+    return commonAncestor->isElementNode() ? downcast<Element>(commonAncestor) : nullptr;
 }
 
 bool isElementForFormatBlock(const QualifiedName& tagName)
index f4b2168..ba3be11 100644 (file)
@@ -398,10 +398,10 @@ static bool removingNodeRemovesPosition(Node* node, const Position& position)
     if (position.anchorNode() == node)
         return true;
 
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return false;
 
-    Element* element = toElement(node);
+    Element* element = downcast<Element>(node);
     return element->containsIncludingShadowDOM(position.anchorNode());
 }
 
@@ -1491,7 +1491,7 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
 
     Color caretColor = Color::black;
     ColorSpace colorSpace = ColorSpaceDeviceRGB;
-    Element* element = node->isElementNode() ? toElement(node) : node->parentElement();
+    Element* element = is<Element>(node) ? downcast<Element>(node) : node->parentElement();
     Element* rootEditableElement = node->rootEditableElement();
 
     if (element && element->renderer()) {
@@ -1520,13 +1520,13 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
 #endif
 }
 
-void FrameSelection::debugRenderer(RenderObject* r, bool selected) const
+void FrameSelection::debugRenderer(RenderObject* renderer, bool selected) const
 {
-    if (r->node()->isElementNode()) {
-        Element* element = toElement(r->node());
+    if (is<Element>(renderer->node())) {
+        Element* element = downcast<Element>(renderer->node());
         fprintf(stderr, "%s%s\n", selected ? "==> " : "    ", element->localName().string().utf8().data());
-    } else if (r->isText()) {
-        RenderText* textRenderer = toRenderText(r);
+    } else if (renderer->isText()) {
+        RenderText* textRenderer = toRenderText(renderer);
         if (!textRenderer->textLength() || !textRenderer->firstTextBox()) {
             fprintf(stderr, "%s#text (empty)\n", selected ? "==> " : "    ");
             return;
@@ -1537,9 +1537,9 @@ void FrameSelection::debugRenderer(RenderObject* r, bool selected) const
         int textLength = text.length();
         if (selected) {
             int offset = 0;
-            if (r->node() == m_selection.start().containerNode())
+            if (renderer->node() == m_selection.start().containerNode())
                 offset = m_selection.start().computeOffsetInContainerNode();
-            else if (r->node() == m_selection.end().containerNode())
+            else if (renderer->node() == m_selection.end().containerNode())
                 offset = m_selection.end().computeOffsetInContainerNode();
 
             int pos;
index 3a1c1e6..a7c7c71 100644 (file)
@@ -156,7 +156,7 @@ void IndentOutdentCommand::outdentParagraph()
                 if (splitPointParent->hasTagName(blockquoteTag)
                     && !splitPoint->hasTagName(blockquoteTag)
                     && splitPointParent->parentNode()->hasEditableStyle()) // We can't outdent if there is no place to go!
-                    splitElement(toElement(splitPointParent), splitPoint);
+                    splitElement(downcast<Element>(splitPointParent), splitPoint);
             }
         }
 
@@ -177,7 +177,7 @@ void IndentOutdentCommand::outdentParagraph()
     else {
         // We split the blockquote at where we start outdenting.
         Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfParagraph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockFlow);
-        splitElement(toElement(enclosingNode), (highestInlineNode) ? highestInlineNode : visibleStartOfParagraph.deepEquivalent().deprecatedNode());
+        splitElement(downcast<Element>(enclosingNode), highestInlineNode ? highestInlineNode : visibleStartOfParagraph.deepEquivalent().deprecatedNode());
     }
     RefPtr<Node> placeholder = createBreakElement(document());
     insertNodeBefore(placeholder, splitBlockquoteNode);
index 2bfc107..e9fe5ad 100644 (file)
@@ -227,7 +227,7 @@ void InsertParagraphSeparatorCommand::doApply()
             // into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted.
             if (m_pasteBlockqutoeIntoUnquotedArea) {
                 if (Node* highestBlockquote = highestEnclosingNodeOfType(canonicalPos, &isMailBlockquote))
-                    startBlock = toElement(highestBlockquote);
+                    startBlock = downcast<Element>(highestBlockquote);
             }
 
             // Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists).  However,
index 73e19ba..1d7efa3 100644 (file)
@@ -139,9 +139,9 @@ void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, Node* nod
     if (&targetNode == nodeToSkip)
         return;
 
-    if (tagNamesToSkip && targetNode.isElementNode()) {
+    if (tagNamesToSkip && is<Element>(targetNode)) {
         for (auto& name : *tagNamesToSkip) {
-            if (toElement(targetNode).hasTagName(name))
+            if (downcast<Element>(targetNode).hasTagName(name))
                 return;
         }
     }
@@ -570,7 +570,7 @@ void MarkupAccumulator::appendStartMarkup(StringBuilder& result, const Node& nod
         appendProcessingInstruction(result, downcast<ProcessingInstruction>(node).target(), downcast<ProcessingInstruction>(node).data());
         break;
     case Node::ELEMENT_NODE:
-        appendElement(result, toElement(node), namespaces);
+        appendElement(result, downcast<Element>(node), namespaces);
         break;
     case Node::CDATA_SECTION_NODE:
         appendCDATASection(result, downcast<CDATASection>(node).data());
index fcf05eb..8b30d46 100644 (file)
@@ -76,8 +76,8 @@ protected:
     void appendString(const String&);
     void appendEndTag(const Node& node)
     {
-        if (node.isElementNode())
-            appendEndTag(toElement(node));
+        if (is<Element>(node))
+            appendEndTag(downcast<Element>(node));
     }
 
     virtual void appendEndTag(const Element&);
index e5f884a..dfce553 100644 (file)
@@ -178,7 +178,7 @@ void IncreaseSelectionListLevelCommand::doApply()
     Node* previousItem = startListChild->renderer()->previousSibling()->node();
     if (isListElement(previousItem)) {
         // move nodes up into preceding list
-        appendSiblingNodeRange(startListChild, endListChild, toElement(previousItem));
+        appendSiblingNodeRange(startListChild, endListChild, downcast<Element>(previousItem));
         m_listElement = previousItem;
     } else {
         // create a sublist for the preceding element and move nodes there
index 8e88d50..155e17a 100644 (file)
@@ -430,7 +430,7 @@ bool ReplaceSelectionCommand::shouldMergeEnd(bool selectionEndWasEndOfParagraph)
 
 static bool isMailPasteAsQuotationNode(const Node* node)
 {
-    return node && node->hasTagName(blockquoteTag) && node->isElementNode() && toElement(node)->getAttribute(classAttr) == ApplePasteAsQuotation;
+    return node && node->hasTagName(blockquoteTag) && downcast<Element>(node)->getAttribute(classAttr) == ApplePasteAsQuotation;
 }
 
 static bool isHeaderElement(const Node* a)
@@ -448,7 +448,7 @@ static bool isHeaderElement(const Node* a)
 
 static bool haveSameTagName(Node* a, Node* b)
 {
-    return a && b && a->isElementNode() && b->isElementNode() && toElement(a)->tagName() == toElement(b)->tagName();
+    return a && b && is<Element>(a) && is<Element>(b) && downcast<Element>(*a).tagName() == downcast<Element>(*b).tagName();
 }
 
 bool ReplaceSelectionCommand::shouldMerge(const VisiblePosition& source, const VisiblePosition& destination)
@@ -755,7 +755,7 @@ static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const
 
     // FIXME: This string comparison is a naive way of comparing two styles.
     // We should be taking the diff and check that the diff is empty.
-    if (styleText != toElement(wrappingStyleSpan)->getAttribute(styleAttr))
+    if (styleText != downcast<Element>(*wrappingStyleSpan).getAttribute(styleAttr))
         return false;
 
     fragment.removeNodePreservingChildren(wrappingStyleSpan);
@@ -1234,7 +1234,7 @@ void ReplaceSelectionCommand::doApply()
         mergeEndIfNeeded();
 
     if (Node* mailBlockquote = enclosingNodeOfType(positionAtStartOfInsertedContent().deepEquivalent(), isMailPasteAsQuotationNode))
-        removeNodeAttribute(toElement(mailBlockquote), classAttr);
+        removeNodeAttribute(downcast<Element>(mailBlockquote), classAttr);
 
     if (shouldPerformSmartReplace())
         addSpacesForSmartReplace();
index 70776fc..e95d854 100644 (file)
@@ -151,7 +151,7 @@ bool SpellChecker::isCheckable(Range* range) const
     if (!range || !range->firstNode() || !range->firstNode()->renderer())
         return false;
     const Node* node = range->startContainer();
-    if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnabled())
+    if (node && is<Element>(node) && !downcast<Element>(*node).isSpellCheckingEnabled())
         return false;
     return true;
 }
index 70d5b57..8f7bdf5 100644 (file)
@@ -57,9 +57,9 @@ void SplitTextNodeContainingElementCommand::doApply()
     if (!parentRenderer || !parentRenderer->isInline()) {
         wrapContentsInDummySpan(parent);
         Node* firstChild = parent->firstChild();
-        if (!firstChild || !firstChild->isElementNode())
+        if (!firstChild || !is<Element>(firstChild))
             return;
-        parent = toElement(firstChild);
+        parent = downcast<Element>(firstChild);
     }
 
     splitElement(parent, m_text);
index 257f4b4..a5d286c 100644 (file)
@@ -255,8 +255,8 @@ bool isRendererReplacedElement(RenderObject* renderer)
     if (renderer->isImage() || renderer->isWidget() || renderer->isMedia())
         return true;
 
-    if (renderer->node() && renderer->node()->isElementNode()) {
-        Element& element = toElement(*renderer->node());
+    if (renderer->node() && is<Element>(renderer->node())) {
+        Element& element = downcast<Element>(*renderer->node());
         if (is<HTMLFormControlElement>(element) || is<HTMLLegendElement>(element) || is<HTMLMeterElement>(element) || is<HTMLProgressElement>(element))
             return true;
         if (equalIgnoringCase(element.fastGetAttribute(roleAttr), "img"))
index d48da0e..a7e0b47 100644 (file)
@@ -42,6 +42,7 @@
 #import "FrameLoader.h"
 #import "HTMLElement.h"
 #import "HTMLFrameElementBase.h"
+#import "HTMLImageElement.h"
 #import "HTMLInputElement.h"
 #import "HTMLMetaElement.h"
 #import "HTMLNames.h"
@@ -738,14 +739,14 @@ static bool stringFromCSSValue(CSSValue& value, String& result)
 
 String HTMLConverterCaches::propertyValueForNode(Node& node, CSSPropertyID propertyId)
 {
-    if (!node.isElementNode()) {
+    if (!is<Element>(node)) {
         if (Node* parent = node.parentNode())
             return propertyValueForNode(*parent, propertyId);
         return String();
     }
 
     bool inherit = false;
-    Element& element = toElement(node);
+    Element& element = downcast<Element>(node);
     if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
         String result;
         if (stringFromCSSValue(*value, result))
@@ -883,13 +884,13 @@ static inline bool floatValueFromPrimitiveValue(CSSPrimitiveValue& primitiveValu
 
 bool HTMLConverterCaches::floatPropertyValueForNode(Node& node, CSSPropertyID propertyId, float& result)
 {
-    if (!node.isElementNode()) {
+    if (!is<Element>(node)) {
         if (ContainerNode* parent = node.parentNode())
             return floatPropertyValueForNode(*parent, propertyId, result);
         return false;
     }
 
-    Element& element = toElement(node);
+    Element& element = downcast<Element>(node);
     if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
         if (value->isPrimitiveValue() && floatValueFromPrimitiveValue(toCSSPrimitiveValue(*value), result))
             return true;
@@ -1052,13 +1053,13 @@ static Color normalizedColor(Color color, bool ignoreBlack)
 
 Color HTMLConverterCaches::colorPropertyValueForNode(Node& node, CSSPropertyID propertyId)
 {
-    if (!node.isElementNode()) {
+    if (!is<Element>(node)) {
         if (Node* parent = node.parentNode())
             return colorPropertyValueForNode(*parent, propertyId);
         return Color();
     }
 
-    Element& element = toElement(node);
+    Element& element = downcast<Element>(node);
     if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
         if (value->isPrimitiveValue() && toCSSPrimitiveValue(*value).isRGBColor())
             return normalizedColor(Color(toCSSPrimitiveValue(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
@@ -1356,11 +1357,11 @@ NSDictionary* HTMLConverter::attributesForElement(Element& element)
 NSDictionary* HTMLConverter::aggregatedAttributesForAncestors(CharacterData& node)
 {
     Node* ancestor = node.parentNode();
-    while (ancestor && !ancestor->isElementNode())
+    while (ancestor && !is<Element>(ancestor))
         ancestor = ancestor->parentNode();
     if (!ancestor)
         return nullptr;
-    return aggregatedAttributesForElementAndItsAncestors(*toElement(ancestor));
+    return aggregatedAttributesForElementAndItsAncestors(downcast<Element>(*ancestor));
 }
 
 NSDictionary* HTMLConverter::aggregatedAttributesForElementAndItsAncestors(Element& element)
@@ -1373,7 +1374,7 @@ NSDictionary* HTMLConverter::aggregatedAttributesForElementAndItsAncestors(Eleme
     ASSERT(attributesForCurrentElement);
 
     Node* ancestor = element.parentNode();
-    while (ancestor && !ancestor->isElementNode())
+    while (ancestor && !is<Element>(ancestor))
         ancestor = ancestor->parentNode();
 
     if (!ancestor) {
@@ -1381,7 +1382,7 @@ NSDictionary* HTMLConverter::aggregatedAttributesForElementAndItsAncestors(Eleme
         return attributesForCurrentElement;
     }
 
-    RetainPtr<NSMutableDictionary> attributesForAncestors = adoptNS([aggregatedAttributesForElementAndItsAncestors(*toElement(ancestor)) mutableCopy]);
+    RetainPtr<NSMutableDictionary> attributesForAncestors = adoptNS([aggregatedAttributesForElementAndItsAncestors(downcast<Element>(*ancestor)) mutableCopy]);
     [attributesForAncestors addEntriesFromDictionary:attributesForCurrentElement];
     m_aggregatedAttributesForElements.set(&element, attributesForAncestors);
 
@@ -2394,8 +2395,8 @@ void HTMLConverter::_traverseNode(Node& node, unsigned depth, bool embedded)
                 break;
             child = child->nextSibling();
         }
-    } else if (node.isElementNode()) {
-        Element& element = toElement(node);
+    } else if (is<Element>(node)) {
+        Element& element = downcast<Element>(node);
         if (_enterElement(element, embedded)) {
             NSUInteger startIndex = [_attrStr length];
             if (_processElement(element, depth)) {
@@ -2570,8 +2571,8 @@ NSAttributedString *editingAttributedStringFromRange(Range& range)
         
         if (startContainer == endContainer && (startOffset == endOffset - 1)) {
             Node* node = startContainer->traverseToChildAt(startOffset);
-            if (node && node->hasTagName(imgTag)) {
-                NSFileWrapper* fileWrapper = fileWrapperForElement(toElement(node));
+            if (node && is<HTMLImageElement>(node)) {
+                NSFileWrapper* fileWrapper = fileWrapperForElement(downcast<HTMLImageElement>(node));
                 NSTextAttachment* attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
                 [string appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
                 [attachment release];
index d10b11b..ebf5b5c 100644 (file)
@@ -194,7 +194,7 @@ Element* unsplittableElementForPosition(const Position& p)
 {
     // Since enclosingNodeOfType won't search beyond the highest root editable node,
     // this code works even if the closest table cell was outside of the root editable node.
-    Element* enclosingCell = toElement(enclosingNodeOfType(p, &isTableCell));
+    Element* enclosingCell = downcast<Element>(enclosingNodeOfType(p, &isTableCell));
     if (enclosingCell)
         return enclosingCell;
 
@@ -316,7 +316,7 @@ bool isInline(const Node* node)
 Element* enclosingBlock(Node* node, EditingBoundaryCrossingRule rule)
 {
     Node* enclosingNode = enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule);
-    return enclosingNode && enclosingNode->isElementNode() ? toElement(enclosingNode) : 0;
+    return enclosingNode && is<Element>(enclosingNode) ? downcast<Element>(enclosingNode) : nullptr;
 }
 
 TextDirection directionOfEnclosingBlock(const Position& position)
@@ -550,10 +550,10 @@ Element* enclosingElementWithTag(const Position& position, const QualifiedName&
     for (Node* node = position.deprecatedNode(); node; node = node->parentNode()) {
         if (root && !node->hasEditableStyle())
             continue;
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
-        if (toElement(*node).hasTagName(tagName))
-            return toElement(node);
+        if (downcast<Element>(*node).hasTagName(tagName))
+            return downcast<Element>(node);
         if (node == root)
             return nullptr;
     }
@@ -629,7 +629,7 @@ Node* highestNodeToRemoveInPruning(Node* node)
 
 Node* enclosingTableCell(const Position& p)
 {
-    return toElement(enclosingNodeOfType(p, isTableCell));
+    return downcast<Element>(enclosingNodeOfType(p, isTableCell));
 }
 
 Element* enclosingAnchorElement(const Position& p)
@@ -638,8 +638,8 @@ Element* enclosingAnchorElement(const Position& p)
         return nullptr;
 
     for (Node* node = p.deprecatedNode(); node; node = node->parentNode()) {
-        if (node->isElementNode() && node->isLink())
-            return toElement(node);
+        if (is<Element>(node) && node->isLink())
+            return downcast<Element>(node);
     }
     return nullptr;
 }
@@ -1184,11 +1184,11 @@ bool isRenderedAsNonInlineTableImageOrHR(const Node* node)
 
 bool areIdenticalElements(const Node* first, const Node* second)
 {
-    if (!first->isElementNode() || !second->isElementNode())
+    if (!is<Element>(first) || !is<Element>(second))
         return false;
 
-    const Element* firstElement = toElement(first);
-    const Element* secondElement = toElement(second);
+    const Element* firstElement = downcast<Element>(first);
+    const Element* secondElement = downcast<Element>(second);
     if (!firstElement->hasTagName(secondElement->tagQName()))
         return false;
 
@@ -1197,21 +1197,17 @@ bool areIdenticalElements(const Node* first, const Node* second)
 
 bool isNonTableCellHTMLBlockElement(const Node* node)
 {
-    if (!node->isElementNode())
-        return false;
-
-    const Element* element = toElement(node);
-    return element->hasTagName(listingTag)
-        || element->hasTagName(olTag)
-        || element->hasTagName(preTag)
-        || is<HTMLTableElement>(element)
-        || element->hasTagName(ulTag)
-        || element->hasTagName(xmpTag)
-        || element->hasTagName(h1Tag)
-        || element->hasTagName(h2Tag)
-        || element->hasTagName(h3Tag)
-        || element->hasTagName(h4Tag)
-        || element->hasTagName(h5Tag);
+    return node->hasTagName(listingTag)
+        || node->hasTagName(olTag)
+        || node->hasTagName(preTag)
+        || is<HTMLTableElement>(node)
+        || node->hasTagName(ulTag)
+        || node->hasTagName(xmpTag)
+        || node->hasTagName(h1Tag)
+        || node->hasTagName(h2Tag)
+        || node->hasTagName(h3Tag)
+        || node->hasTagName(h4Tag)
+        || node->hasTagName(h5Tag);
 }
 
 Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selection)
@@ -1251,14 +1247,14 @@ bool isBlockFlowElement(const Node* node)
 Element* deprecatedEnclosingBlockFlowElement(Node* node)
 {
     if (!node)
-        return 0;
+        return nullptr;
     if (isBlockFlowElement(node))
-        return toElement(node);
+        return downcast<Element>(node);
     while ((node = node->parentNode())) {
-        if (isBlockFlowElement(node) || node->hasTagName(bodyTag))
-            return toElement(node);
+        if (isBlockFlowElement(node) || is<HTMLBodyElement>(node))
+            return downcast<Element>(node);
     }
-    return 0;
+    return nullptr;
 }
 
 static inline bool caretRendersInsideNode(Node* node)
@@ -1269,11 +1265,11 @@ static inline bool caretRendersInsideNode(Node* node)
 RenderObject* rendererForCaretPainting(Node* node)
 {
     if (!node)
-        return 0;
+        return nullptr;
 
     RenderObject* renderer = node->renderer();
     if (!renderer)
-        return 0;
+        return nullptr;
 
     // If caretNode is a block and caret is inside it, then caret should be painted by that block.
     bool paintedByBlock = renderer->isRenderBlockFlow() && caretRendersInsideNode(node);
index d91002d..1b90be2 100644 (file)
@@ -181,10 +181,10 @@ inline StyledMarkupAccumulator::StyledMarkupAccumulator(Vector<Node*>* nodes, EA
 void StyledMarkupAccumulator::wrapWithNode(Node& node, bool convertBlocksToInlines, RangeFullySelectsNode rangeFullySelectsNode)
 {
     StringBuilder markup;
-    if (node.isElementNode())
-        appendElement(markup, toElement(node), convertBlocksToInlines && isBlock(&node), rangeFullySelectsNode);
+    if (is<Element>(node))
+        appendElement(markup, downcast<Element>(node), convertBlocksToInlines && isBlock(&node), rangeFullySelectsNode);
     else
-        appendStartMarkup(markup, node, 0);
+        appendStartMarkup(markup, node, nullptr);
     m_reversedPrecedingMarkup.append(markup.toString());
     appendEndTag(node);
     if (m_nodes)
@@ -571,7 +571,7 @@ static String createMarkupInternal(Document& document, const Range& range, const
     document.updateLayoutIgnorePendingStylesheets();
 
     auto* body = enclosingElementWithTag(firstPositionInNode(commonAncestor), bodyTag);
-    Node* fullySelectedRoot = 0;
+    Element* fullySelectedRoot = nullptr;
     // FIXME: Do this for all fully selected blocks, not just the body.
     if (body && VisiblePosition(firstPositionInNode(body)) == VisiblePosition(range.startPosition())
         && VisiblePosition(lastPositionInNode(body)) == VisiblePosition(range.endPosition()))
@@ -608,8 +608,8 @@ static String createMarkupInternal(Document& document, const Range& range, const
                 // Bring the background attribute over, but not as an attribute because a background attribute on a div
                 // appears to have no effect.
                 if ((!fullySelectedRootStyle || !fullySelectedRootStyle->style() || !fullySelectedRootStyle->style()->getPropertyCSSValue(CSSPropertyBackgroundImage))
-                    && toElement(fullySelectedRoot)->hasAttribute(backgroundAttr))
-                    fullySelectedRootStyle->style()->setProperty(CSSPropertyBackgroundImage, "url('" + toElement(fullySelectedRoot)->getAttribute(backgroundAttr) + "')");
+                    && fullySelectedRoot->hasAttribute(backgroundAttr))
+                    fullySelectedRootStyle->style()->setProperty(CSSPropertyBackgroundImage, "url('" + fullySelectedRoot->getAttribute(backgroundAttr) + "')");
 
                 if (fullySelectedRootStyle->style()) {
                     // Reset the CSS properties to avoid an assertion error in addStyleMarkup().
@@ -804,7 +804,7 @@ PassRefPtr<DocumentFragment> createFragmentFromText(Range& context, const String
 
     // Break string into paragraphs. Extra line breaks turn into empty paragraphs.
     Node* blockNode = enclosingBlock(context.firstNode());
-    Element* block = toElement(blockNode);
+    Element* block = downcast<Element>(blockNode);
     bool useClonesOfEnclosingBlock = blockNode
         && blockNode->isElementNode()
         && !block->hasTagName(bodyTag)
index 23d2193..26fa14a 100644 (file)
@@ -70,7 +70,7 @@ public:
     Element* fallbackSummary()
     {
         ASSERT(firstChild() && firstChild()->hasTagName(summaryTag));
-        return toElement(firstChild());
+        return downcast<Element>(firstChild());
     }
 
 private:
index bcd267d..9ac413f 100644 (file)
@@ -642,8 +642,8 @@ Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi
     }
 
     Node* returnValue = insertAdjacent(where, newChild, ec);
-    ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || returnValue->isElementNode());
-    return toElement(returnValue); 
+    ASSERT_WITH_SECURITY_IMPLICATION(!returnValue || is<Element>(returnValue));
+    return downcast<Element>(returnValue); 
 }
 
 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#insertadjacenthtml()
@@ -651,12 +651,12 @@ static Element* contextElementForInsertion(const String& where, Element* element
 {
     if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "afterEnd")) {
         ContainerNode* parent = element->parentNode();
-        if (parent && !parent->isElementNode()) {
+        if (parent && !is<Element>(parent)) {
             ec = NO_MODIFICATION_ALLOWED_ERR;
             return nullptr;
         }
-        ASSERT_WITH_SECURITY_IMPLICATION(!parent || parent->isElementNode());
-        return toElement(parent);
+        ASSERT_WITH_SECURITY_IMPLICATION(!parent || is<Element>(parent));
+        return downcast<Element>(parent);
     }
     if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "beforeEnd"))
         return element;
@@ -934,14 +934,14 @@ TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) c
     while (node) {
         // Skip bdi, script, style and text form controls.
         if (equalIgnoringCase(node->nodeName(), "bdi") || node->hasTagName(scriptTag) || node->hasTagName(styleTag) 
-            || (node->isElementNode() && toElement(node)->isTextFormControl())) {
+            || (is<Element>(node) && downcast<Element>(*node).isTextFormControl())) {
             node = NodeTraversal::nextSkippingChildren(node, this);
             continue;
         }
 
         // Skip elements with valid dir attribute
-        if (node->isElementNode()) {
-            AtomicString dirAttributeValue = toElement(node)->fastGetAttribute(dirAttr);
+        if (is<Element>(node)) {
+            AtomicString dirAttributeValue = downcast<Element>(*node).fastGetAttribute(dirAttr);
             if (isLTROrRTLIgnoringCase(dirAttributeValue) || equalIgnoringCase(dirAttributeValue, "auto")) {
                 node = NodeTraversal::nextSkippingChildren(node, this);
                 continue;
index d92083a..c224e6e 100644 (file)
@@ -192,7 +192,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLFormControlElement)
     static bool isHTMLFormControlElement(const Element& element) { return element.isFormControlElement(); }
-    static bool isHTMLFormControlElement(const Node& node) { return node.isElementNode() && toElement(node).isFormControlElement(); }
+    static bool isHTMLFormControlElement(const Node& node) { return is<Element>(node) && downcast<Element>(node).isFormControlElement(); }
     static bool isHTMLFormControlElement(const FormAssociatedElement& element) { return element.isFormControlElement(); }
 SPECIALIZE_TYPE_TRAITS_END()
 
index d37a141..27fcdd2 100644 (file)
@@ -911,7 +911,7 @@ struct ValueToString<TextTrackCue*> {
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLMediaElement)
     static bool isHTMLMediaElement(const Element& element) { return element.isMediaElement(); }
-    static bool isHTMLMediaElement(const Node& node) { return node.isElementNode() && isHTMLMediaElement(toElement(node)); }
+    static bool isHTMLMediaElement(const Node& node) { return is<Element>(node) && isHTMLMediaElement(downcast<Element>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 #ifndef NDEBUG
index 8da943f..14938fa 100644 (file)
@@ -423,10 +423,10 @@ void HTMLObjectElement::updateDocNamedItem()
     bool isNamedItem = true;
     Node* child = firstChild();
     while (child && isNamedItem) {
-        if (child->isElementNode()) {
-            Element* element = toElement(child);
+        if (is<Element>(child)) {
+            Element& element = downcast<Element>(*child);
             // FIXME: Use of isRecognizedTagName is almost certainly wrong here.
-            if (isRecognizedTagName(element->tagQName()) && !element->hasTagName(paramTag))
+            if (isRecognizedTagName(element.tagQName()) && !element.hasTagName(paramTag))
                 isNamedItem = false;
         } else if (is<Text>(child)) {
             if (!downcast<Text>(*child).containsOnlyWhitespace())
index 4f75916..7713589 100644 (file)
@@ -338,10 +338,10 @@ String HTMLOptionElement::collectOptionInnerText() const
 {
     StringBuilder text;
     for (Node* node = firstChild(); node; ) {
-        if (node->isTextNode())
+        if (is<Text>(node))
             text.append(node->nodeValue());
         // Text nodes inside script elements are not part of the option text.
-        if (node->isElementNode() && toScriptElementIfPossible(toElement(node)))
+        if (is<Element>(node) && toScriptElementIfPossible(downcast<Element>(node)))
             node = NodeTraversal::nextSkippingChildren(node, this);
         else
             node = NodeTraversal::next(node, this);
index 8daf340..9ce9e5c 100644 (file)
@@ -63,8 +63,8 @@ Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode
 void HTMLSourceElement::removedFrom(ContainerNode& removalRoot)
 {
     Element* parent = parentElement();
-    if (!parent && removalRoot.isElementNode())
-        parent = &toElement(removalRoot);
+    if (!parent && is<Element>(removalRoot))
+        parent = &downcast<Element>(removalRoot);
     if (parent && is<HTMLMediaElement>(parent))
         downcast<HTMLMediaElement>(*parent).sourceWasRemoved(this);
     HTMLElement::removedFrom(removalRoot);
index 44b4dfd..ec6c3a2 100644 (file)
@@ -102,12 +102,12 @@ bool HTMLSummaryElement::isMainSummary() const
 
 static bool isClickableControl(Node* node)
 {
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return false;
-    Element* element = toElement(node);
+    Element& element = downcast<Element>(*node);
     if (is<HTMLFormControlElement>(element))
         return true;
-    Element* host = element->shadowHost();
+    Element* host = element.shadowHost();
     return host && is<HTMLFormControlElement>(host);
 }
 
index 3337fd9..9dc7d92 100644 (file)
@@ -153,7 +153,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLTextFormControlElement)
     static bool isHTMLTextFormControlElement(const Element& element) { return element.isTextFormControl(); }
-    static bool isHTMLTextFormControlElement(const Node& node) { return node.isElementNode() && isHTMLTextFormControlElement(toElement(node)); }
+    static bool isHTMLTextFormControlElement(const Node& node) { return is<Element>(node) && isHTMLTextFormControlElement(downcast<Element>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
index a9f0f8d..d74c145 100644 (file)
@@ -158,7 +158,7 @@ static inline void executeTask(HTMLConstructionSiteTask& task)
 
 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr<Node> prpChild, bool selfClosing)
 {
-    ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get())));
+    ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !is<Element>(prpChild.get()) || !toScriptElementIfPossible(downcast<Element>(prpChild.get())));
     ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->isPluginElement());
 
     HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert);
index cd6a201..919ac0e 100644 (file)
@@ -541,7 +541,7 @@ bool HTMLElementStack::hasTemplateInHTMLScope() const
 Element* HTMLElementStack::htmlElement() const
 {
     ASSERT(m_rootNode);
-    return toElement(m_rootNode);
+    return downcast<Element>(m_rootNode);
 }
 
 Element* HTMLElementStack::headElement() const
index 953a679..3701354 100644 (file)
@@ -59,7 +59,7 @@ public:
         return adoptRef(new HTMLStackItem(node, token, namespaceURI));
     }
 
-    Element* element() const { return toElement(m_node.get()); }
+    Element* element() const { return downcast<Element>(m_node.get()); }
     ContainerNode* node() const { return m_node.get(); }
 
     bool isDocumentFragmentNode() const { return m_isDocumentFragmentNode; }
index 6e8b7cc..9f04264 100644 (file)
@@ -100,11 +100,11 @@ inline Node* parentNodeForDistribution(const Node* node)
 inline Element* parentElementForDistribution(const Node* node)
 {
     if (Node* parent = parentNodeForDistribution(node)) {
-        if (parent->isElementNode())
-            return toElement(parent);
+        if (is<Element>(parent))
+            return downcast<Element>(parent);
     }
 
-    return 0;
+    return nullptr;
 }
 
 inline ShadowRoot* shadowRootOfParentForDistribution(const Node* node)
@@ -113,7 +113,7 @@ inline ShadowRoot* shadowRootOfParentForDistribution(const Node* node)
     if (Element* parent = parentElementForDistribution(node))
         return parent->shadowRoot();
 
-    return 0;
+    return nullptr;
 }
 
 InsertionPoint* findInsertionPointOf(const Node*);
index d42d5a4..d5a456b 100644 (file)
@@ -689,7 +689,7 @@ void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* even
 #if ENABLE(VIDEO_TRACK)
     if (event->type() == eventNames().clickEvent) {
         Node* target = event->target()->toNode();
-        if (!target || !target->isElementNode())
+        if (!target || !is<Element>(target))
             return;
 
         // When we created the elements in the track list, we gave them a custom
@@ -698,7 +698,7 @@ void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* even
         // tell the HTMLMediaElement to enable that track.
 
         RefPtr<TextTrack> textTrack;
-        MenuItemToTrackMap::iterator iter = m_menuToTrackMap.find(toElement(target));
+        MenuItemToTrackMap::iterator iter = m_menuToTrackMap.find(downcast<Element>(target));
         if (iter != m_menuToTrackMap.end())
             textTrack = iter->value;
         m_menuToTrackMap.clear();
index 59cf6e9..3db0bfc 100644 (file)
@@ -770,7 +770,7 @@ void VTTCue::markFutureAndPastNodes(ContainerNode* root, const MediaTime& previo
             downcast<WebVTTElement>(*child).setIsPastNode(isPastNode);
             // Make an elemenet id match a cue id for style matching purposes.
             if (!id().isEmpty())
-                toElement(child)->setIdAttribute(id());
+                downcast<WebVTTElement>(*child).setIdAttribute(id());
         }
     }
 }
index 672e5be..03d3c06 100644 (file)
@@ -181,8 +181,8 @@ bool DOMPatchSupport::innerPatchNode(Digest* oldDigest, Digest* newDigest, Excep
         return true;
 
     // Patch attributes
-    Element* oldElement = toElement(oldNode);
-    Element* newElement = toElement(newNode);
+    Element* oldElement = downcast<Element>(oldNode);
+    Element* newElement = downcast<Element>(newNode);
     if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) {
         // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important.
         if (oldElement->hasAttributesWithoutUpdate()) {
@@ -426,7 +426,7 @@ std::unique_ptr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* nod
             child = child->nextSibling();
             digest->m_children.append(WTF::move(childInfo));
         }
-        Element* element = toElement(node);
+        Element* element = downcast<Element>(node);
 
         if (element->hasAttributesWithoutUpdate()) {
             SHA1 attrsSHA1;
index 5aac174..7785f9a 100644 (file)
@@ -896,11 +896,11 @@ Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId)
         *errorString = "No node with given id found";
         return nullptr;
     }
-    if (!node->isElementNode()) {
+    if (!is<Element>(node)) {
         *errorString = "Not an element node";
         return nullptr;
     }
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document)
@@ -1108,7 +1108,7 @@ PassRefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::Region>> Inspect
     for (unsigned i = 0; i < regionList->length(); ++i) {
         Inspector::Protocol::CSS::Region::RegionOverset regionOverset;
 
-        switch (toElement(regionList->item(i))->regionOversetState()) {
+        switch (downcast<Element>(regionList->item(i))->regionOversetState()) {
         case RegionFit:
             regionOverset = Inspector::Protocol::CSS::Region::RegionOverset::Fit;
             break;
@@ -1201,7 +1201,7 @@ void InspectorCSSAgent::resetPseudoStates()
 {
     HashSet<Document*> documentsToChange;
     for (NodeIdToForcedPseudoState::iterator it = m_nodeIdToForcedPseudoState.begin(), end = m_nodeIdToForcedPseudoState.end(); it != end; ++it) {
-        if (Element* element = toElement(m_domAgent->nodeForId(it->key)))
+        if (Element* element = downcast<Element>(m_domAgent->nodeForId(it->key)))
             documentsToChange.add(&element->document());
     }
 
index d249b9e..1c2fb60 100644 (file)
@@ -339,8 +339,8 @@ void InspectorDOMAgent::unbind(Node* node, NodeToIdMap* nodesMap)
             unbind(contentDocument, nodesMap);
     }
 
-    if (node->isElementNode()) {
-        if (ShadowRoot* root = toElement(node)->shadowRoot())
+    if (is<Element>(node)) {
+        if (ShadowRoot* root = downcast<Element>(*node).shadowRoot())
             unbind(root, nodesMap);
     }
 
@@ -387,11 +387,11 @@ Element* InspectorDOMAgent::assertElement(ErrorString* errorString, int nodeId)
     Node* node = assertNode(errorString, nodeId);
     if (!node)
         return nullptr;
-    if (!node->isElementNode()) {
+    if (!is<Element>(node)) {
         *errorString = "Node is not an Element";
         return nullptr;
     }
-    return toElement(node);
+    return downcast<Element>(node);
 }
 
 Node* InspectorDOMAgent::assertEditableNode(ErrorString* errorString, int nodeId)
@@ -671,7 +671,7 @@ void InspectorDOMAgent::setAttributesAsText(ErrorString* errorString, int elemen
         return;
     }
 
-    Element* childElement = toElement(child);
+    Element* childElement = downcast<Element>(child);
     if (!childElement->hasAttributes() && name) {
         m_domEditor->removeAttribute(element, *name, errorString);
         return;
@@ -718,7 +718,7 @@ void InspectorDOMAgent::setNodeName(ErrorString* errorString, int nodeId, const
     *newId = 0;
 
     Node* oldNode = nodeForId(nodeId);
-    if (!oldNode || !oldNode->isElementNode())
+    if (!oldNode || !is<Element>(oldNode))
         return;
 
     ExceptionCode ec = 0;
@@ -727,7 +727,7 @@ void InspectorDOMAgent::setNodeName(ErrorString* errorString, int nodeId, const
         return;
 
     // Copy over the original node's attributes.
-    newElem->cloneAttributesFromElement(*toElement(oldNode));
+    newElem->cloneAttributesFromElement(*downcast<Element>(oldNode));
 
     // Copy over the original node's children.
     Node* child;
@@ -1269,11 +1269,11 @@ PassRefPtr<Inspector::Protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode
             value->setChildren(children.release());
     }
 
-    if (node->isElementNode()) {
-        Element* element = toElement(node);
-        value->setAttributes(buildArrayForElementAttributes(element));
-        if (is<HTMLFrameOwnerElement>(node)) {
-            HTMLFrameOwnerElement& frameOwner = downcast<HTMLFrameOwnerElement>(*node);
+    if (is<Element>(node)) {
+        Element& element = downcast<Element>(*node);
+        value->setAttributes(buildArrayForElementAttributes(&element));
+        if (is<HTMLFrameOwnerElement>(element)) {
+            HTMLFrameOwnerElement& frameOwner = downcast<HTMLFrameOwnerElement>(element);
             Frame* frame = frameOwner.contentFrame();
             if (frame)
                 value->setFrameId(m_pageAgent->frameId(frame));
@@ -1282,7 +1282,7 @@ PassRefPtr<Inspector::Protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode
                 value->setContentDocument(buildObjectForNode(document, 0, nodesMap));
         }
 
-        if (ShadowRoot* root = element->shadowRoot()) {
+        if (ShadowRoot* root = element.shadowRoot()) {
             RefPtr<Inspector::Protocol::Array<Inspector::Protocol::DOM::Node>> shadowRoots = Inspector::Protocol::Array<Inspector::Protocol::DOM::Node>::create();
             shadowRoots->addItem(buildObjectForNode(root, 0, nodesMap));
             value->setShadowRoots(shadowRoots);
@@ -1290,7 +1290,7 @@ PassRefPtr<Inspector::Protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode
 
 #if ENABLE(TEMPLATE_ELEMENT)
         if (is<HTMLTemplateElement>(element))
-            value->setTemplateContent(buildObjectForNode(downcast<HTMLTemplateElement>(*element).content(), 0, nodesMap));
+            value->setTemplateContent(buildObjectForNode(downcast<HTMLTemplateElement>(element).content(), 0, nodesMap));
 #endif
 
     } else if (is<Document>(node)) {
@@ -1522,8 +1522,8 @@ PassRefPtr<Inspector::Protocol::DOM::AccessibilityProperties> InspectorDOMAgent:
                 }
             }
             
-            if (node->isElementNode()) {
-                supportsFocused = toElement(node)->isFocusable();
+            if (is<Element>(node)) {
+                supportsFocused = downcast<Element>(*node).isFocusable();
                 if (supportsFocused)
                     focused = axObject->isFocused();
             }
@@ -1884,7 +1884,7 @@ void InspectorDOMAgent::didInvalidateStyleAttr(Node* node)
 
     if (!m_revalidateStyleAttrTask)
         m_revalidateStyleAttrTask = std::make_unique<RevalidateStyleAttributeTask>(this);
-    m_revalidateStyleAttrTask->scheduleFor(toElement(node));
+    m_revalidateStyleAttrTask->scheduleFor(downcast<Element>(node));
 }
 
 void InspectorDOMAgent::didPushShadowRoot(Element* host, ShadowRoot* root)
index 494dae2..dd15a8d 100644 (file)
@@ -85,7 +85,7 @@ void InspectorNodeFinder::searchUsingDOMTreeTraversal(Node* parentNode)
             break;
         }
         case Node::ELEMENT_NODE: {
-            if (matchesElement(*toElement(node)))
+            if (matchesElement(downcast<Element>(*node)))
                 m_results.add(node);
 
             // Search inside frame elements.
index e257f1a..6e65a81 100644 (file)
@@ -676,19 +676,19 @@ static PassRefPtr<InspectorObject> buildObjectForShapeOutside(Frame* containingF
 
 static PassRefPtr<InspectorObject> buildObjectForElementInfo(Node* node)
 {
-    if (!node->isElementNode() || !node->document().frame())
+    if (!is<Element>(node) || !node->document().frame())
         return nullptr;
 
     RefPtr<InspectorObject> elementInfo = InspectorObject::create();
 
-    Element* element = toElement(node);
-    bool isXHTML = element->document().isXHTMLDocument();
-    elementInfo->setString("tagName", isXHTML ? element->nodeName() : element->nodeName().lower());
-    elementInfo->setString("idValue", element->getIdAttribute());
+    Element& element = downcast<Element>(*node);
+    bool isXHTML = element.document().isXHTMLDocument();
+    elementInfo->setString("tagName", isXHTML ? element.nodeName() : element.nodeName().lower());
+    elementInfo->setString("idValue", element.getIdAttribute());
     HashSet<AtomicString> usedClassNames;
-    if (element->hasClass() && is<StyledElement>(element)) {
+    if (element.hasClass() && is<StyledElement>(element)) {
         StringBuilder classNames;
-        const SpaceSplitString& classNamesString = downcast<StyledElement>(*element).classNames();
+        const SpaceSplitString& classNamesString = downcast<StyledElement>(element).classNames();
         size_t classNameCount = classNamesString.size();
         for (size_t i = 0; i < classNameCount; ++i) {
             const AtomicString& className = classNamesString[i];
@@ -701,7 +701,7 @@ static PassRefPtr<InspectorObject> buildObjectForElementInfo(Node* node)
         elementInfo->setString("className", classNames.toString());
     }
 
-    RenderElement* renderer = element->renderer();
+    RenderElement* renderer = element.renderer();
     Frame* containingFrame = node->document().frame();
     FrameView* containingView = containingFrame->view();
     IntRect boundingBox = snappedIntRect(containingView->contentsToRootView(renderer->absoluteBoundingBoxRect()));
index 2da91d1..6d36748 100644 (file)
@@ -1388,13 +1388,13 @@ bool InspectorStyleSheet::inlineStyleSheetText(String* result) const
         return false;
 
     Node* ownerNode = m_pageStyleSheet->ownerNode();
-    if (!ownerNode || !ownerNode->isElementNode())
+    if (!ownerNode || !is<Element>(ownerNode))
         return false;
-    Element* ownerElement = toElement(ownerNode);
+    Element& ownerElement = downcast<Element>(*ownerNode);
 
     if (!is<HTMLStyleElement>(ownerElement) && !is<SVGStyleElement>(ownerElement))
         return false;
-    *result = ownerElement->textContent();
+    *result = ownerElement.textContent();
     return true;
 }
 
index 616d131..4a7430b 100644 (file)
@@ -289,13 +289,13 @@ static Element* elementUnderMouse(Document* documentUnderMouse, const IntPoint&
     HitTestResult result(point);
     documentUnderMouse->renderView()->hitTest(HitTestRequest(), result);
 
-    Node* n = result.innerNode();
-    while (n && !n->isElementNode())
-        n = n->parentNode();
-    if (n)
-        n = n->deprecatedShadowAncestorNode();
+    Node* node = result.innerNode();
+    while (node && !is<Element>(node))
+        node = node->parentNode();
+    if (node)
+        node = node->deprecatedShadowAncestorNode();
 
-    return toElement(n);
+    return downcast<Element>(node);
 }
 
 bool DragController::tryDocumentDrag(DragData& dragData, DragDestinationAction actionMask, DragOperation& dragOperation)
index 5d910f3..33a9a53 100644 (file)
@@ -2186,7 +2186,7 @@ static bool hasDropZoneType(DataTransfer& dataTransfer, const String& keyword)
 
 static bool findDropZone(Node* target, DataTransfer* dataTransfer)
 {
-    Element* element = target->isElementNode() ? toElement(target) : target->parentElement();
+    Element* element = is<Element>(target) ? downcast<Element>(target) : target->parentElement();
     for (; element; element = element->parentElement()) {
         bool matched = false;
         String dropZoneStr = element->fastGetAttribute(webkitdropzoneAttr);
@@ -2233,10 +2233,10 @@ bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, DataTransf
     RefPtr<Element> newTarget;
     if (Node* targetNode = mouseEvent.targetNode()) {
         // Drag events should never go to non-element nodes (following IE, and proper mouseover/out dispatch)
-        if (!targetNode->isElementNode())
+        if (!is<Element>(targetNode))
             newTarget = targetNode->parentOrShadowHostElement();
         else
-            newTarget = toElement(targetNode);
+            newTarget = downcast<Element>(targetNode);
     }
 
     m_autoscrollController->updateDragAndDrop(newTarget.get(), event.position(), event.timestamp());
@@ -2394,10 +2394,10 @@ void EventHandler::updateMouseEventTargetNode(Node* targetNode, const PlatformMo
         targetElement = m_capturingMouseEventsElement.get();
     else if (targetNode) {
         // If the target node is a non-element, dispatch on the parent. <rdar://problem/4196646>
-        if (!targetNode->isElementNode())
+        if (!is<Element>(targetNode))
             targetElement = targetNode->parentOrShadowHostElement();
         else
-            targetElement = toElement(targetNode);
+            targetElement = downcast<Element>(targetNode);
     }
 
     m_elementUnderMouse = targetElement;
index c14d097..13e51c2 100644 (file)
@@ -103,8 +103,8 @@ FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node)
 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(Node* node)
 {
     ASSERT(node);
-    ASSERT(toElement(node)->shadowRoot());
-    return FocusNavigationScope(toElement(node)->shadowRoot());
+    ASSERT(downcast<Element>(*node).shadowRoot());
+    return FocusNavigationScope(downcast<Element>(*node).shadowRoot());
 }
 
 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOwnedByIFrame(HTMLFrameOwnerElement* frame)
@@ -145,14 +145,14 @@ static inline bool isNonFocusableShadowHost(Element& element, KeyboardEvent& eve
 
 static inline bool isFocusableShadowHost(Node& node, KeyboardEvent& event)
 {
-    return node.isElementNode() && toElement(node).isKeyboardFocusable(&event) && toElement(node).shadowRoot() && !hasCustomFocusLogic(toElement(node));
+    return is<Element>(node) && downcast<Element>(node).isKeyboardFocusable(&event) && downcast<Element>(node).shadowRoot() && !hasCustomFocusLogic(downcast<Element>(node));
 }
 
 static inline int adjustedTabIndex(Node& node, KeyboardEvent& event)
 {
-    if (!node.isElementNode())
+    if (!is<Element>(node))
         return 0;
-    return isNonFocusableShadowHost(toElement(node), event) ? 0 : toElement(node).tabIndex();
+    return isNonFocusableShadowHost(downcast<Element>(node), event) ? 0 : downcast<Element>(node).tabIndex();
 }
 
 static inline bool shouldVisit(Element& element, KeyboardEvent& event)
@@ -350,7 +350,7 @@ bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, Keyb
 
 Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection direction, FocusNavigationScope scope, Node* currentNode, KeyboardEvent* event)
 {
-    ASSERT(!currentNode || !currentNode->isElementNode() || !isNonFocusableShadowHost(*toElement(currentNode), *event));
+    ASSERT(!currentNode || !is<Element>(currentNode) || !isNonFocusableShadowHost(*downcast<Element>(currentNode), *event));
     Element* found;
     if (currentNode && direction == FocusDirectionForward && isFocusableShadowHost(*currentNode, *event)) {
         Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(currentNode), 0, event);
@@ -410,9 +410,9 @@ Element* FocusController::findElementWithExactTabIndex(Node* start, int tabIndex
     // Search is inclusive of start
     using namespace NodeRenderingTraversal;
     for (Node* node = start; node; node = direction == FocusDirectionForward ? nextInScope(node) : previousInScope(node)) {
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
-        Element& element = toElement(*node);
+        Element& element = downcast<Element>(*node);
         if (shouldVisit(element, *event) && adjustedTabIndex(element, *event) == tabIndex)
             return &element;
     }
@@ -425,9 +425,9 @@ static Element* nextElementWithGreaterTabIndex(Node* start, int tabIndex, Keyboa
     int winningTabIndex = std::numeric_limits<short>::max() + 1;
     Element* winner = nullptr;
     for (Node* node = start; node; node = NodeRenderingTraversal::nextInScope(node)) {
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
-        Element& element = toElement(*node);
+        Element& element = downcast<Element>(*node);
         if (shouldVisit(element, event) && element.tabIndex() > tabIndex && element.tabIndex() < winningTabIndex) {
             winner = &element;
             winningTabIndex = element.tabIndex();
@@ -443,9 +443,9 @@ static Element* previousElementWithLowerTabIndex(Node* start, int tabIndex, Keyb
     int winningTabIndex = 0;
     Element* winner = nullptr;
     for (Node* node = start; node; node = NodeRenderingTraversal::previousInScope(node)) {
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
-        Element& element = toElement(*node);
+        Element& element = downcast<Element>(*node);
         int currentTabIndex = adjustedTabIndex(element, event);
         if ((shouldVisit(element, event) || isNonFocusableShadowHost(element, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
             winner = &element;
@@ -464,9 +464,9 @@ Element* FocusController::nextFocusableElement(FocusNavigationScope scope, Node*
         // If a node is excluded from the normal tabbing cycle, the next focusable node is determined by tree order
         if (tabIndex < 0) {
             for (Node* node = nextInScope(start); node; node = nextInScope(node)) {
-                if (!node->isElementNode())
+                if (!is<Element>(node))
                     continue;
-                Element& element = toElement(*node);
+                Element& element = downcast<Element>(*node);
                 if (shouldVisit(element, *event) && adjustedTabIndex(element, *event) >= 0)
                     return &element;
             }
@@ -516,9 +516,9 @@ Element* FocusController::previousFocusableElement(FocusNavigationScope scope, N
     // However, if a node is excluded from the normal tabbing cycle, the previous focusable node is determined by tree order
     if (startingTabIndex < 0) {
         for (Node* node = startingNode; node; node = previousInScope(node)) {
-            if (!node->isElementNode())
+            if (!is<Element>(node))
                 continue;
-            Element& element = toElement(*node);
+            Element& element = downcast<Element>(*node);
             if (shouldVisit(element, *event) && adjustedTabIndex(element, *event) >= 0)
                 return &element;
         }
@@ -860,7 +860,7 @@ bool FocusController::advanceFocusDirectionallyInContainer(Node* container, cons
     }
 
     // We found a new focus node, navigate to it.
-    Element* element = toElement(focusCandidate.focusableNode);
+    Element* element = downcast<Element>(focusCandidate.focusableNode);
     ASSERT(element);
 
     element->focus(false, direction);
index f6134ed..54ca967 100644 (file)
@@ -222,10 +222,10 @@ void PageSerializer::serializeFrame(Frame* frame)
 
     for (Vector<Node*>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
         Node* node = *iter;
-        if (!node->isElementNode())
+        if (!is<Element>(node))
             continue;
 
-        Element& element = toElement(*node);
+        Element& element = downcast<Element>(*node);
         // We have to process in-line style as it might contain some resources (typically background images).
         if (is<StyledElement>(element))
             retrieveResourcesForProperties(downcast<StyledElement>(element).inlineStyle(), document);
index ebbabd1..721bd58 100644 (file)
@@ -223,10 +223,11 @@ String HitTestResult::title(TextDirection& dir) const
     // Find the title in the nearest enclosing DOM node.
     // 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 = toElement(titleNode)->title();
+        if (is<Element>(titleNode)) {
+            Element& titleElement = downcast<Element>(*titleNode);
+            String title = titleElement.title();
             if (!title.isEmpty()) {
-                if (auto renderer = titleNode->renderer())
+                if (auto renderer = titleElement.renderer())
                     dir = renderer->style().direction();
                 return title;
             }
@@ -238,17 +239,17 @@ String HitTestResult::title(TextDirection& dir) const
 String HitTestResult::innerTextIfTruncated(TextDirection& dir) const
 {
     for (Node* truncatedNode = m_innerNode.get(); truncatedNode; truncatedNode = truncatedNode->parentNode()) {
-        if (!truncatedNode->isElementNode())
+        if (!is<Element>(truncatedNode))
             continue;
 
-        if (auto renderer = toElement(truncatedNode)->renderer()) {
+        if (auto renderer = downcast<Element>(*truncatedNode).renderer()) {
             if (renderer->isRenderBlockFlow()) {
                 RenderBlockFlow* block = toRenderBlockFlow(renderer);
                 if (block->style().textOverflow()) {
                     for (RootInlineBox* line = block->firstRootBox(); line; line = line->nextRootBox()) {
                         if (line->hasEllipsisBox()) {
                             dir = block->style().direction();
-                            return toElement(truncatedNode)->innerText();
+                            return downcast<Element>(*truncatedNode).innerText();
                         }
                     }
                 }
@@ -322,7 +323,7 @@ URL HitTestResult::absoluteImageURL() const
         || is<HTMLInputElement>(*m_innerNonSharedNode)
         || is<HTMLObjectElement>(*m_innerNonSharedNode)
         || is<SVGImageElement>(*m_innerNonSharedNode)) {
-        urlString = toElement(*m_innerNonSharedNode).imageSourceURL();
+        urlString = downcast<Element>(*m_innerNonSharedNode).imageSourceURL();
     } else
         return URL();
 
@@ -674,9 +675,9 @@ Element* HitTestResult::innerElement() const
 {
     Node* node = m_innerNode.get();
     if (!node)
-        return 0;
-    if (node->isElementNode())
-        return toElement(node);
+        return nullptr;
+    if (is<Element>(node))
+        return downcast<Element>(node);
     return node->parentElement();
 }
 
@@ -684,9 +685,9 @@ Element* HitTestResult::innerNonSharedElement() const
 {
     Node* node = m_innerNonSharedNode.get();
     if (!node)
-        return 0;
-    if (node->isElementNode())
-        return toElement(node);
+        return nullptr;
+    if (is<Element>(node))
+        return downcast<Element>(node);
     return node->parentElement();
 }
 
index e5c6c03..9474e88 100644 (file)
@@ -34,7 +34,7 @@ public:
     RenderDeprecatedFlexibleBox(Element&, PassRef<RenderStyle>);
     virtual ~RenderDeprecatedFlexibleBox();
 
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     virtual const char* renderName() const;
 
index 93f06b2..c9566df 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "Element.h"
 #include "GraphicsContext.h"
+#include "HTMLDetailsElement.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "PaintInfo.h"
@@ -143,8 +144,8 @@ bool RenderDetailsMarker::isOpen() const
     for (RenderObject* renderer = parent(); renderer; renderer = renderer->parent()) {
         if (!renderer->node())
             continue;
-        if (renderer->node()->hasTagName(detailsTag))
-            return !toElement(renderer->node())->getAttribute(openAttr).isNull();
+        if (is<HTMLDetailsElement>(renderer->node()))
+            return !downcast<HTMLDetailsElement>(*renderer->node()).getAttribute(openAttr).isNull();
         if (is<HTMLInputElement>(renderer->node()))
             return true;
     }
index 42b5dc0..05ce794 100644 (file)
@@ -48,8 +48,8 @@ public:
     void setAnimatableStyle(PassRef<RenderStyle>);
 
     // This is null for anonymous renderers.
-    Element* element() const { return toElement(RenderObject::node()); }
-    Element* nonPseudoElement() const { return toElement(RenderObject::nonPseudoNode()); }
+    Element* element() const { return downcast<Element>(RenderObject::node()); }
+    Element* nonPseudoElement() const { return downcast<Element>(RenderObject::nonPseudoNode()); }
     Element* generatingElement() const;
 
     RenderObject* firstChild() const { return m_firstChild; }
@@ -316,7 +316,7 @@ inline Element* RenderElement::generatingElement() const
 {
     if (parent() && isRenderNamedFlowFragment())
         return parent()->generatingElement();
-    return toElement(RenderObject::generatingNode());
+    return downcast<Element>(RenderObject::generatingNode());
 }
 
 inline bool RenderObject::isRenderLayerModelObject() const
index 0243b63..9194610 100644 (file)
@@ -45,7 +45,7 @@ public:
     RenderGrid(Element&, PassRef<RenderStyle>);
     virtual ~RenderGrid();
 
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
 
index 64a6f47..213cc90 100644 (file)
@@ -1680,7 +1680,7 @@ static bool isRestartedPlugin(RenderObject* renderer)
     if (!renderer->isEmbeddedObject())
         return false;
 
-    Element* element = toElement(renderer->node());
+    Element* element = downcast<Element>(renderer->node());
     if (!element || !is<HTMLPlugInElement>(element))
         return false;
 
index d2e38bd..795de3a 100644 (file)
@@ -34,7 +34,7 @@ class RenderListMarker;
 class RenderListItem final : public RenderBlockFlow {
 public:
     RenderListItem(Element&, PassRef<RenderStyle>);
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     int value() const { if (!m_isValueUpToDate) updateValueNow(); return m_value; }
     void updateValue();
index 6fe8ab9..81dc9fe 100644 (file)
@@ -545,13 +545,13 @@ bool RenderNamedFlowThread::isChildAllowed(const RenderObject& child, const Rend
     if (!child.node())
         return true;
 
-    ASSERT(child.node()->isElementNode());
+    ASSERT(is<Element>(child.node()));
 
     Node* originalParent = NodeRenderingTraversal::parent(child.node());
-    if (!originalParent || !originalParent->isElementNode() || !originalParent->renderer())
+    if (!originalParent || !is<Element>(originalParent) || !originalParent->renderer())
         return true;
 
-    return toElement(originalParent)->renderer()->isChildAllowed(child, style);
+    return downcast<Element>(*originalParent).renderer()->isChildAllowed(child, style);
 }
 
 void RenderNamedFlowThread::dispatchRegionOversetChangeEventIfNeeded()
index 6de35d0..24ef496 100644 (file)
@@ -1033,13 +1033,13 @@ void RenderObject::addPDFURLRect(PaintInfo& paintInfo, const LayoutPoint& paintO
 
     if (urlRect.isEmpty())
         return;
-    Node* n = node();
-    if (!n || !n->isLink() || !n->isElementNode())
+    Node* node = this->node();
+    if (!node || !node->isLink() || !is<Element>(node))
         return;
-    const AtomicString& href = toElement(n)->getAttribute(hrefAttr);
+    const AtomicString& href = downcast<Element>(*node).getAttribute(hrefAttr);
     if (href.isNull())
         return;
-    paintInfo.context->setURLForRect(n->document().completeURL(href), snappedIntRect(urlRect));
+    paintInfo.context->setURLForRect(node->document().completeURL(href), snappedIntRect(urlRect));
 }
 
 void RenderObject::paintOutline(PaintInfo& paintInfo, const LayoutRect& paintRect)
@@ -2141,7 +2141,7 @@ void RenderObject::updateDragState(bool dragOn)
 {
     bool valueChanged = (dragOn != isDragging());
     setIsDragging(dragOn);
-    if (valueChanged && node() && (style().affectedByDrag() || (node()->isElementNode() && toElement(node())->childrenAffectedByDrag())))
+    if (valueChanged && node() && (style().affectedByDrag() || (is<Element>(node()) && downcast<Element>(*node()).childrenAffectedByDrag())))
         node()->setNeedsStyleRecalc();
     for (RenderObject* curr = firstChildSlow(); curr; curr = curr->nextSibling())
         curr->updateDragState(dragOn);
@@ -2225,7 +2225,7 @@ RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* pa
 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(const PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle, RenderStyle* ownStyle) const
 {
     if (pseudoStyleRequest.pseudoId < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style().hasPseudoStyle(pseudoStyleRequest.pseudoId))
-        return 0;
+        return nullptr;
     
     if (!parentStyle) {
         ASSERT(!ownStyle);
@@ -2233,20 +2233,20 @@ PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(const PseudoStyleRe
     }
 
     // FIXME: This "find nearest element parent" should be a helper function.
-    Node* n = node();
-    while (n && !n->isElementNode())
-        n = n->parentNode();
-    if (!n)
-        return 0;
-    Element* element = toElement(n);
+    Node* node = this->node();
+    while (node && !is<Element>(node))
+        node = node->parentNode();
+    if (!node)
+        return nullptr;
+    Element& element = downcast<Element>(*node);
 
     if (pseudoStyleRequest.pseudoId == FIRST_LINE_INHERITED) {
-        RefPtr<RenderStyle> result = document().ensureStyleResolver().styleForElement(element, parentStyle, DisallowStyleSharing);
+        RefPtr<RenderStyle> result = document().ensureStyleResolver().styleForElement(&element, parentStyle, DisallowStyleSharing);
         result->setStyleType(FIRST_LINE_INHERITED);
         return result.release();
     }
 
-    return document().ensureStyleResolver().pseudoStyleForElement(element, pseudoStyleRequest, parentStyle);
+    return document().ensureStyleResolver().pseudoStyleForElement(&element, pseudoStyleRequest, parentStyle);
 }
 
 static Color decorationColor(RenderStyle* style)
index d8cc7d4..8795de0 100644 (file)
@@ -74,7 +74,7 @@ public:
     RenderRubyAsBlock(Element&, PassRef<RenderStyle>);
     virtual ~RenderRubyAsBlock();
 
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) override;
     virtual RenderObject* removeChild(RenderObject& child) override;
index 163b204..567f01e 100644 (file)
@@ -40,7 +40,7 @@ public:
     RenderRubyText(Element&, PassRef<RenderStyle>);
     virtual ~RenderRubyText();
 
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     virtual bool isChildAllowed(const RenderObject&, const RenderStyle&) const override;
 
index 6441609..14ba9d2 100644 (file)
@@ -31,7 +31,7 @@ public:
     RenderTableCaption(Element&, PassRef<RenderStyle>);
     virtual ~RenderTableCaption();
 
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     virtual LayoutUnit containingBlockLogicalWidthForContent() const override;
     
index 270a8a4..9dd9356 100644 (file)
@@ -36,7 +36,7 @@ class RenderTableCell;
 class RenderTableCol final : public RenderBox {
 public:
     RenderTableCol(Element&, PassRef<RenderStyle>);
-    Element& element() const { return toElement(nodeForNonAnonymous()); }
+    Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
     void clearPreferredLogicalWidthsDirtyBits();
 
index ba675f0..9747b4a 100644 (file)
@@ -802,67 +802,67 @@ bool RenderTheme::isIndeterminate(const RenderObject& o) const
     return inputElement->shouldAppearIndeterminate();
 }
 
-bool RenderTheme::isEnabled(const RenderObject& o) const
+bool RenderTheme::isEnabled(const RenderObject& renderer) const
 {
-    Node* node = o.node();
-    if (!node || !node->isElementNode())
+    Node* node = renderer.node();
+    if (!node || !is<Element>(node))
         return true;
-    return !toElement(node)->isDisabledFormControl();
+    return !downcast<Element>(*node).isDisabledFormControl();
 }
 
-bool RenderTheme::isFocused(const RenderObject& o) const
+bool RenderTheme::isFocused(const RenderObject& renderer) const
 {
-    Node* node = o.node();
-    if (!node || !node->isElementNode())
+    Node* node = renderer.node();
+    if (!node || !is<Element>(node))
         return false;
 
-    Element* focusDelegate = toElement(node)->focusDelegate();
+    Element* focusDelegate = downcast<Element>(*node).focusDelegate();
     Document& document = focusDelegate->document();
     Frame* frame = document.frame();
     return focusDelegate == document.focusedElement() && frame && frame->selection().isFocusedAndActive();
 }
 
-bool RenderTheme::isPressed(const RenderObject& o) const
+bool RenderTheme::isPressed(const RenderObject& renderer) const
 {
-    if (!o.node() || !o.node()->isElementNode())
+    if (!renderer.node() || !is<Element>(renderer.node()))
         return false;
-    return toElement(o.node())->active();
+    return downcast<Element>(*renderer.node()).active();
 }
 
-bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject& o) const
+bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject& renderer) const
 {
-    Node* node = o.node();
-    if (!node || !node->isElementNode())
+    Node* node = renderer.node();
+    if (!node || !is<Element>(node))
         return false;
-    Element* element = toElement(node);
-    if (!element->active() || !element->isSpinButtonElement())
+    Element& element = downcast<Element>(*node);
+    if (!element.active() || !element.isSpinButtonElement())
         return false;
-    return static_cast<SpinButtonElement*>(element)->upDownState() == SpinButtonElement::Up;
+    return static_cast<SpinButtonElement&>(element).upDownState() == SpinButtonElement::Up;
 }
 
-bool RenderTheme::isReadOnlyControl(const RenderObject& o) const
+bool RenderTheme::isReadOnlyControl(const RenderObject& renderer) const
 {
-    Node* node = o.node();
+    Node* node = renderer.node();
     if (!node || !is<HTMLFormControlElement>(node))
         return false;
-    return !toElement(*node).matchesReadWritePseudoClass();
+    return !downcast<Element>(*node).matchesReadWritePseudoClass();
 }
 
-bool RenderTheme::isHovered(const RenderObject& o) const
+bool RenderTheme::isHovered(const RenderObject& renderer) const
 {
-    Node* node = o.node();
-    if (!node || !node->isElementNode())
+    Node* node = renderer.node();
+    if (!node || !is<Element>(node))
         return false;
-    if (!toElement(node)->isSpinButtonElement())
-        return toElement(node)->hovered();
+    if (!downcast<Element>(*node).isSpinButtonElement())
+        return downcast<Element>(*node).hovered();
     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
     return element->hovered() && element->upDownState() != SpinButtonElement::Indeterminate;
 }
 
-bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject& o) const
+bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject& renderer) const
 {
-    Node* node = o.node();
-    if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement())
+    Node* node = renderer.node();
+    if (!node || !is<Element>(node) || !downcast<Element>(*node).isSpinButtonElement())
         return false;
     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
     return element->upDownState() == SpinButtonElement::Up;
index cbd92ab..48388eb 100644 (file)
@@ -316,15 +316,15 @@ static bool nodeHasPseudo(Node* node, const char* pseudo)
 
 static bool nodeHasClass(Node* node, const char* className)
 {
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return false;
 
-    Element* element = toElement(node);
+    Element& element = downcast<Element>(*node);
 
-    if (!element->hasClass())
+    if (!element.hasClass())
         return false;
 
-    return element->classNames().contains(className);
+    return element.classNames().contains(className);
 }
 
 RenderThemeGtk::RenderThemeGtk()
index 36e0771..920026c 100644 (file)
@@ -729,7 +729,7 @@ void RenderThemeMac::updateFocusedState(NSCell* cell, const RenderObject& o)
 void RenderThemeMac::updatePressedState(NSCell* cell, const RenderObject& o)
 {
     bool oldPressed = [cell isHighlighted];
-    bool pressed = o.node() && o.node()->isElementNode() && toElement(o.node())->active();
+    bool pressed = o.node() && is<Element>(o.node()) && downcast<Element>(*o.node()).active();
     if (pressed != oldPressed)
         [cell setHighlighted:pressed];
 }
@@ -1531,7 +1531,7 @@ bool RenderThemeMac::paintSliderThumb(const RenderObject& o, const PaintInfo& pa
 
     // Update the various states we respond to.
     updateEnabledState(sliderThumbCell, o);
-        Element* focusDelegate = (o.node() && o.node()->isElementNode()) ? toElement(o.node())->focusDelegate() : 0;
+        Element* focusDelegate = (o.node() && is<Element>(o.node())) ? downcast<Element>(o.node())->focusDelegate() : nullptr;
     if (focusDelegate)
         updateFocusedState(sliderThumbCell, *focusDelegate->renderer());
 
@@ -1673,7 +1673,7 @@ bool RenderThemeMac::paintSearchFieldCancelButton(const RenderObject& o, const P
 {
     Element* input = o.node()->shadowHost();
     if (!input)
-        input = toElement(o.node());
+        input = downcast<Element>(o.node());
 
     if (!input->renderer()->isBox())
         return false;
index 1e7d752..d45bc5b 100644 (file)
@@ -393,7 +393,7 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
     }
     
     if (behavior & RenderAsTextShowIDAndClass) {
-        if (Element* element = o.node() && o.node()->isElementNode() ? toElement(o.node()) : 0) {
+        if (Element* element = o.node() && is<Element>(o.node()) ? downcast<Element>(o.node()) : nullptr) {
             if (element->hasID())
                 ts << " id=\"" + element->getIdAttribute() + "\"";
 
index b2d95a9..d392d88 100644 (file)
@@ -276,8 +276,8 @@ bool TextAutosizer::isAutosizingContainer(const RenderObject* renderer)
     if (renderer->isListItem())
         return renderer->isFloating() || renderer->isOutOfFlowPositioned();
     // Avoid creating containers for text within text controls, buttons, or <select> buttons.
-    Node* parentNode = renderer->parent() ? renderer->parent()->generatingNode() : 0;
-    if (parentNode && parentNode->isElementNode() && formInputTags().contains(toElement(parentNode)->tagQName()))
+    Node* parentNode = renderer->parent() ? renderer->parent()->generatingNode() : nullptr;
+    if (parentNode && is<Element>(parentNode) && formInputTags().contains(downcast<Element>(*parentNode).tagQName()))
         return false;
 
     return true;
@@ -388,8 +388,8 @@ bool TextAutosizer::containerContainsOneOfTags(const RenderBlock* container, con
     const RenderObject* renderer = container;
     while (renderer) {
         const Node* rendererNode = renderer->node();
-        if (rendererNode && rendererNode->isElementNode()) {
-            if (tags.contains(toElement(rendererNode)->tagQName()))
+        if (rendererNode && is<Element>(rendererNode)) {
+            if (tags.contains(downcast<Element>(*rendererNode).tagQName()))
                 return true;
         }
         renderer = nextInPreOrderSkippingDescendantsOfContainers(renderer, container);
index 0af9160..24c190d 100644 (file)
@@ -55,7 +55,7 @@ RenderMathMLBlock::RenderMathMLBlock(Document& document, PassRef<RenderStyle> st
 
 bool RenderMathMLBlock::isChildAllowed(const RenderObject& child, const RenderStyle&) const
 {
-    return child.node() && isElement(*child.node());
+    return child.node() && is<Element>(*child.node());
 }
 
 RenderPtr<RenderMathMLBlock> RenderMathMLBlock::createAnonymousMathMLBlock()
index 8a86a95..22e8e1a 100644 (file)
@@ -482,8 +482,8 @@ static void attachChildren(ContainerNode& current, RenderStyle& inheritedStyle,
             attachTextRenderer(downcast<Text>(*child), renderTreePosition);
             continue;
         }
-        if (child->isElementNode())
-            attachRenderTree(*toElement(child), inheritedStyle, renderTreePosition, nullptr);
+        if (is<Element>(child))
+            attachRenderTree(downcast<Element>(*child), inheritedStyle, renderTreePosition, nullptr);
     }
 }
 
@@ -501,8 +501,8 @@ static void attachDistributedChildren(InsertionPoint& insertionPoint, RenderStyl
             attachTextRenderer(downcast<Text>(*current), renderTreePosition);
             continue;
         }
-        if (current->isElementNode()) {
-            Element& currentElement = toElement(*current);
+        if (is<Element>(current)) {
+            Element& currentElement = downcast<Element>(*current);
             if (currentElement.renderer())
                 detachRenderTree(currentElement);
             attachRenderTree(currentElement, inheritedStyle, renderTreePosition, nullptr);
@@ -655,8 +655,8 @@ static void detachDistributedChildren(InsertionPoint& insertionPoint)
             detachTextRenderer(downcast<Text>(*current));
             continue;
         }
-        if (current->isElementNode())
-            detachRenderTree(*toElement(current));
+        if (is<Element>(current))
+            detachRenderTree(downcast<Element>(*current));
     }
 }
 
@@ -670,8 +670,8 @@ static void detachChildren(ContainerNode& current, DetachType detachType)
             Style::detachTextRenderer(downcast<Text>(*child));
             continue;
         }
-        if (child->isElementNode())
-            detachRenderTree(*toElement(child), detachType);
+        if (is<Element>(child))
+            detachRenderTree(downcast<Element>(*child), detachType);
     }
     current.clearChildNeedsStyleRecalc();
 }
@@ -819,8 +819,8 @@ static void resolveShadowTree(ShadowRoot& shadowRoot, Element& host, Style::Chan
             resolveTextNode(downcast<Text>(*child), renderTreePosition);
             continue;
         }
-        if (child->isElementNode())
-            resolveTree(*toElement(child), host.renderer()->style(), renderTreePosition, change);
+        if (is<Element>(child))
+            resolveTree(downcast<Element>(*child), host.renderer()->style(), renderTreePosition, change);
     }
 
     shadowRoot.clearNeedsStyleRecalc();
@@ -943,19 +943,19 @@ void resolveTree(Element& current, RenderStyle& inheritedStyle, RenderTreePositi
                 resolveTextNode(downcast<Text>(*child), childRenderTreePosition);
                 continue;
             }
-            if (!child->isElementNode())
+            if (!is<Element>(child))
                 continue;
 
-            Element* childElement = toElement(child);
+            Element& childElement = downcast<Element>(*child);
             if (elementNeedingStyleRecalcAffectsNextSiblingElementStyle) {
-                if (childElement->styleIsAffectedByPreviousSibling())
-                    childElement->setNeedsStyleRecalc();
-                elementNeedingStyleRecalcAffectsNextSiblingElementStyle = childElement->affectsNextSiblingElementStyle();
-            } else if (childElement->styleChangeType() >= FullStyleChange)
-                elementNeedingStyleRecalcAffectsNextSiblingElementStyle = childElement->affectsNextSiblingElementStyle();
-            if (change >= Inherit || childElement->childNeedsStyleRecalc() || childElement->needsStyleRecalc()) {
+                if (childElement.styleIsAffectedByPreviousSibling())
+                    childElement.setNeedsStyleRecalc();
+                elementNeedingStyleRecalcAffectsNextSiblingElementStyle = childElement.affectsNextSiblingElementStyle();
+            } else if (childElement.styleChangeType() >= FullStyleChange)
+                elementNeedingStyleRecalcAffectsNextSiblingElementStyle = childElement.affectsNextSiblingElementStyle();
+            if (change >= Inherit || childElement.childNeedsStyleRecalc() || childElement.needsStyleRecalc()) {
                 parentPusher.push();
-                resolveTree(*childElement, renderer->style(), childRenderTreePosition, change);
+                resolveTree(childElement, renderer->style(), childRenderTreePosition, change);
             }
         }
 
index 849df89..667cdfc 100644 (file)
@@ -760,9 +760,9 @@ void SVGUseElement::expandUseElementsInShadowTree(Node* element)
         expandUseElementsInShadowTree(child.get());
 }
 
-void SVGUseElement::expandSymbolElementsInShadowTree(Node* element)
+void SVGUseElement::expandSymbolElementsInShadowTree(Node* node)
 {
-    if (element->hasTagName(SVGNames::symbolTag)) {
+    if (is<SVGSymbolElement>(node)) {
         // Spec: The referenced 'symbol' and its contents are deep-cloned into the generated tree,
         // with the exception that the 'symbol' is replaced by an 'svg'. This generated 'svg' will
         // always have explicit values for attributes width and height. If attributes width and/or
@@ -772,10 +772,10 @@ void SVGUseElement::expandSymbolElementsInShadowTree(Node* element)
         RefPtr<SVGSVGElement> svgElement = SVGSVGElement::create(SVGNames::svgTag, *referencedDocument());
 
         // Transfer all data (attributes, etc.) from <symbol> to the new <svg> element.
-        svgElement->cloneDataFromElement(*toElement(element));
+        svgElement->cloneDataFromElement(downcast<SVGSymbolElement>(*node));
 
         // Only clone symbol children, and add them to the new <svg> element
-        for (Node* child = element->firstChild(); child; child = child->nextSibling()) {
+        for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
             RefPtr<Node> newChild = child->cloneNode(true);
             svgElement->appendChild(newChild.release());
         }
@@ -788,19 +788,19 @@ void SVGUseElement::expandSymbolElementsInShadowTree(Node* element)
         if (subtreeContainsDisallowedElement(*svgElement))
             removeDisallowedElementsFromSubtree(*svgElement);
 
-        RefPtr<Node> replacingElement(svgElement.get());
+        RefPtr<SVGSVGElement> replacingElement(svgElement.get());
 
         // Replace <symbol> with <svg>.
-        element->parentNode()->replaceChild(svgElement.release(), element);
+        node->parentNode()->replaceChild(svgElement.release(), node);
 
         // Expand the siblings because the *element* is replaced and we will
         // lose the sibling chain when we are back from recursion.
-        element = replacingElement.get();
-        for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = sibling->nextSibling())
+        node = replacingElement.get();
+        for (RefPtr<Node> sibling = node->nextSibling(); sibling; sibling = sibling->nextSibling())
             expandSymbolElementsInShadowTree(sibling.get());
     }
 
-    for (RefPtr<Node> child = element->firstChild(); child; child = child->nextSibling())
+    for (RefPtr<Node> child = node->firstChild(); child; child = child->nextSibling())
         expandSymbolElementsInShadowTree(child.get());
 }
 
index 1049e6b..d545e9d 100644 (file)
@@ -157,7 +157,7 @@ void SVGSMILElement::buildPendingResource()
 
     if (!inDocument()) {
         // Reset the target element if we are no longer in the document.
-        setTargetElement(0);
+        setTargetElement(nullptr);
         return;
     }
 
@@ -165,7 +165,7 @@ void SVGSMILElement::buildPendingResource()
     String href = getAttribute(XLinkNames::hrefAttr);
     Element* target;
     if (href.isEmpty())
-        target = parentNode() && parentNode()->isElementNode() ? toElement(parentNode()) : nullptr;
+        target = parentNode() && is<Element>(parentNode()) ? downcast<Element>(parentNode()) : nullptr;
     else
         target = SVGURIReference::targetElementFromIRIString(href, document(), &id);
     SVGElement* svgTarget = target && is<SVGElement>(target) ? downcast<SVGElement>(target) : nullptr;
index 1e36e9b..1ff8384 100644 (file)
@@ -580,13 +580,13 @@ Value FunLang::evaluate() const
 {
     String lang = argument(0).evaluate().toString();
 
-    const Attribute* languageAttribute = 0;
+    const Attribute* languageAttribute = nullptr;
     Node* node = evaluationContext().node.get();
     while (node) {
-        if (node->isElementNode()) {
-            Element* element = toElement(node);
-            if (element->hasAttributes())
-                languageAttribute = element->findAttributeByName(XMLNames::langAttr);
+        if (is<Element>(node)) {
+            Element& element = downcast<Element>(*node);
+            if (element.hasAttributes())
+                languageAttribute = element.findAttributeByName(XMLNames::langAttr);
         }
         if (languageAttribute)
             break;
index 0fd410c..b861681 100644 (file)
@@ -207,19 +207,19 @@ void NodeSet::traversalSort() const
     Vector<RefPtr<Node>> sortedNodes;
     sortedNodes.reserveInitialCapacity(nodeCount);
 
-    for (Node* n = findRootNode(m_nodes.first().get()); n; n = NodeTraversal::next(n)) {
-        if (nodes.contains(n))
-            sortedNodes.append(n);
+    for (Node* node = findRootNode(m_nodes.first().get()); node; node = NodeTraversal::next(node)) {
+        if (nodes.contains(node))
+            sortedNodes.append(node);
 
-        if (!containsAttributeNodes || !n->isElementNode())
+        if (!containsAttributeNodes || !is<Element>(node))
             continue;
 
-        Element* element = toElement(n);
-        if (!element->hasAttributes())
+        Element& element = downcast<Element>(*node);
+        if (!element.hasAttributes())
             continue;
 
-        for (const Attribute& attribute : element->attributesIterator()) {
-            RefPtr<Attr> attr = element->attrIfExists(attribute.name());
+        for (const Attribute& attribute : element.attributesIterator()) {
+            RefPtr<Attr> attr = element.attrIfExists(attribute.name());
             if (attr && nodes.contains(attr.get()))
                 sortedNodes.append(attr);
         }
index 4916c73..c4cfd5a 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "Attr.h"
 #include "Document.h"
+#include "HTMLDocument.h"
 #include "HTMLElement.h"
 #include "NodeTraversal.h"
 #include "XMLNSNames.h"
@@ -201,21 +202,21 @@ inline bool nodeMatchesBasicTest(Node& node, Step::Axis axis, const Step::NodeTe
 
             // For other axes, the principal node type is element.
             ASSERT(primaryNodeType(axis) == Node::ELEMENT_NODE);
-            if (!node.isElementNode())
+            if (!is<Element>(node))
                 return false;
 
             if (name == starAtom)
                 return namespaceURI.isEmpty() || namespaceURI == node.namespaceURI();
 
-            if (node.document().isHTMLDocument()) {
+            if (is<HTMLDocument>(node.document())) {
                 if (is<HTMLElement>(node)) {
                     // Paths without namespaces should match HTML elements in HTML documents despite those having an XHTML namespace. Names are compared case-insensitively.
                     return equalIgnoringCase(downcast<HTMLElement>(node).localName(), name) && (namespaceURI.isNull() || namespaceURI == node.namespaceURI());
                 }
                 // An expression without any prefix shouldn't match no-namespace nodes (because HTML5 says so).
-                return toElement(node).hasLocalName(name) && namespaceURI == node.namespaceURI() && !namespaceURI.isNull();
+                return downcast<Element>(node).hasLocalName(name) && namespaceURI == node.namespaceURI() && !namespaceURI.isNull();
             }
-            return toElement(node).hasLocalName(name) && namespaceURI == node.namespaceURI();
+            return downcast<Element>(node).hasLocalName(name) && namespaceURI == node.namespaceURI();
         }
     }
     ASSERT_NOT_REACHED();
@@ -343,10 +344,10 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
             return;
         }
         case AttributeAxis: {
-            if (!context.isElementNode())
+            if (!is<Element>(context))
                 return;
 
-            Element& contextElement = toElement(context);
+            Element& contextElement = downcast<Element>(context);
 
             // Avoid lazily creating attribute nodes for attributes that we do not need anyway.
             if (m_nodeTest.m_kind == NodeTest::NameTest && m_nodeTest.m_data != starAtom) {
index 8ae511d..96dacf7 100644 (file)
@@ -621,10 +621,10 @@ XMLDocumentParser::XMLDocumentParser(DocumentFragment& fragment, Element* parent
     while (parentElement) {
         elemStack.append(parentElement);
 
-        ContainerNode* n = parentElement->parentNode();
-        if (!n || !n->isElementNode())
+        ContainerNode* node = parentElement->parentNode();
+        if (!node || !is<Element>(node))
             break;
-        parentElement = toElement(n);
+        parentElement = downcast<Element>(node);
     }
 
     if (elemStack.isEmpty())
@@ -881,34 +881,34 @@ void XMLDocumentParser::endElementNs()
 
     exitText();
 
-    RefPtr<ContainerNode> n = m_currentNode;
-    n->finishParsingChildren();
+    RefPtr<ContainerNode> node = m_currentNode;
+    node->finishParsingChildren();
 
     // Once we reach the depth again where entity expansion started, stop executing the work-around.
     if (hackAroundLibXMLEntityParsingBug() && context()->depth <= depthTriggeringEntityExpansion())
         setDepthTriggeringEntityExpansion(-1);
 
-    if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptElementIfPossible(toElement(n.get()))) {
+    if (!scriptingContentIsAllowed(parserContentPolicy()) && is<Element>(*node) && toScriptElementIfPossible(downcast<Element>(node.get()))) {
         popCurrentNode();
-        n->remove(IGNORE_EXCEPTION);
+        node->remove(IGNORE_EXCEPTION);
         return;
     }
 
-    if (!n->isElementNode() || !m_view) {
+    if (!node->isElementNode() || !m_view) {
         popCurrentNode();
         return;
     }
 
-    Element* element = toElement(n.get());
+    Element& element = downcast<Element>(*node);
 
     // The element's parent may have already been removed from document.
     // Parsing continues in this case, but scripts aren't executed.
-    if (!element->inDocument()) {
+    if (!element.inDocument()) {
         popCurrentNode();
         return;
     }
 
-    ScriptElement* scriptElement = toScriptElementIfPossible(element);
+    ScriptElement* scriptElement = toScriptElementIfPossible(&element);
     if (!scriptElement) {
         popCurrentNode();
         return;
@@ -926,14 +926,14 @@ void XMLDocumentParser::endElementNs()
             scriptElement->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition));
         else if (scriptElement->willBeParserExecuted()) {
             m_pendingScript = scriptElement->cachedScript();
-            m_scriptElement = element;
+            m_scriptElement = &element;
             m_pendingScript->addClient(this);
 
             // m_pendingScript will be 0 if script was already loaded and addClient() executed it.
             if (m_pendingScript)
                 pauseParsing();
         } else
-            m_scriptElement = 0;
+            m_scriptElement = nullptr;
 
         // JavaScript may have detached the parser
         if (isDetached())
index bf6d8eb..8f925d1 100644 (file)
@@ -1,3 +1,16 @@
+2014-09-30  Chris Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Element
+        https://bugs.webkit.org/show_bug.cgi?id=137241
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Element instead of isElementNode() /
+        toElement().
+
+        * WebView/WebRenderLayer.mm:
+        (+[WebRenderLayer nameForLayer:]):
+
 2014-09-28  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Move ColorInputType class to std::unique_ptr
index 2f4578d..84fb376 100644 (file)
@@ -52,7 +52,7 @@ using namespace WebCore;
     const RenderObject& renderer = layer->renderer();
     NSString *name = [NSString stringWithUTF8String:renderer.renderName()];
 
-    if (Element* element = renderer.node() && renderer.node()->isElementNode() ? toElement(renderer.node()) : 0) {
+    if (Element* element = renderer.node() && is<Element>(renderer.node()) ? downcast<Element>(renderer.node()) : nullptr) {
         name = [name stringByAppendingFormat:@" %@", (NSString *)element->tagName()];
         if (element->hasID())
             name = [name stringByAppendingFormat:@" id=\"%@\"", (NSString *)element->getIdAttribute()];
index f6712fe..4e51fc7 100644 (file)
@@ -1,3 +1,17 @@
+2014-09-30  Chris Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Element
+        https://bugs.webkit.org/show_bug.cgi?id=137241
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Element instead of isElementNode() /
+        toElement().
+
+        * DOMEventsClasses.cpp:
+        (DOMMouseEvent::toElement):
+        * DOMEventsClasses.h:
+
 2014-09-29  Christophe Dumez  <cdumez@apple.com>
 
         Make is<>() / downcast<>() work for HTMLDocument and its subclasses
index b1b6fe6..511bd8e 100644 (file)
@@ -550,7 +550,7 @@ HRESULT STDMETHODCALLTYPE DOMMouseEvent::fromElement(
     return E_NOTIMPL;
 }
 
-HRESULT STDMETHODCALLTYPE DOMMouseEvent::toElement( 
+HRESULT STDMETHODCALLTYPE DOMMouseEvent::toElement(
     /* [retval][out] */ IDOMNode** /*result*/)
 {
     return E_NOTIMPL;
index b881604..71c576e 100644 (file)
@@ -613,7 +613,7 @@ public:
     virtual HRESULT STDMETHODCALLTYPE fromElement( 
         /* [retval][out] */ IDOMNode** result);
     
-    virtual HRESULT STDMETHODCALLTYPE toElement( 
+    virtual HRESULT STDMETHODCALLTYPE toElement(
         /* [retval][out] */ IDOMNode** result);
 };
 
index 360abef..bac4ca3 100644 (file)
@@ -1,3 +1,31 @@
+2014-09-30  Chris Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Element
+        https://bugs.webkit.org/show_bug.cgi?id=137241
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Element instead of isElementNode() /
+        toElement().
+
+        * Shared/WebRenderObject.cpp:
+        (WebKit::WebRenderObject::WebRenderObject):
+        * WebProcess/InjectedBundle/API/mac/WKDOMElement.mm:
+        (-[WKDOMElement hasAttribute:]):
+        (-[WKDOMElement getAttribute:]):
+        (-[WKDOMElement setAttribute:value:]):
+        (-[WKDOMElement tagName]):
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::InjectedBundleNodeHandle::elementBounds):
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
+        (WebKit::InjectedBundleHitTestResult::mediaType):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::sendTapHighlightForNodeIfNecessary):
+        (WebKit::WebPage::blurAssistedNode):
+        (WebKit::WebPage::getPositionInformation):
+        (WebKit::nextFocusableElement):
+        (WebKit::WebPage::elementDidFocus):
+
 2014-09-30  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         REGRESSION(r173929): [GTK] TestInspector fails after r173929
index 6cedada..19603c5 100644 (file)
@@ -66,17 +66,17 @@ WebRenderObject::WebRenderObject(RenderObject* renderer, bool shouldIncludeDesce
     m_name = renderer->renderName();
 
     if (Node* node = renderer->node()) {
-        if (node->isElementNode()) {
-            Element* element = toElement(node);
-            m_elementTagName = element->tagName();
-            m_elementID = element->getIdAttribute();
+        if (is<Element>(node)) {
+            Element& element = downcast<Element>(*node);
+            m_elementTagName = element.tagName();
+            m_elementID = element.getIdAttribute();
             
-            if (element->isStyledElement() && element->hasClass()) {
+            if (element.isStyledElement() && element.hasClass()) {
                 Vector<RefPtr<API::Object>> classNames;
-                classNames.reserveInitialCapacity(element->classNames().size());
+                classNames.reserveInitialCapacity(element.classNames().size());
 
-                for (size_t i = 0, size = element->classNames().size(); i < size; ++i)
-                    classNames.append(API::String::create(element->classNames()[i]));
+                for (size_t i = 0, size = element.classNames().size(); i < size; ++i)
+                    classNames.append(API::String::create(element.classNames()[i]));
 
                 m_elementClassNames = API::Array::create(WTF::move(classNames));
             }
index 4e9b2ff..cf71b1a 100644 (file)
 
 - (BOOL)hasAttribute:(NSString *)attribute
 {
-    return WebCore::toElement(_impl.get())->hasAttribute(attribute);
+    return WebCore::downcast<WebCore::Element>(*_impl).hasAttribute(attribute);
 }
 
 - (NSString *)getAttribute:(NSString *)attribute
 {
-    return WebCore::toElement(_impl.get())->getAttribute(attribute);
+    return WebCore::downcast<WebCore::Element>(*_impl).getAttribute(attribute);
 }
 
 - (void)setAttribute:(NSString *)name value:(NSString *)value
 {
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec;
-    WebCore::toElement(_impl.get())->setAttribute(name, value, ec);
+    WebCore::downcast<WebCore::Element>(*_impl).setAttribute(name, value, ec);
 }
 
 - (NSString *)tagName
 {
-    return WebCore::toElement(_impl.get())->tagName();
+    return WebCore::downcast<WebCore::Element>(*_impl).tagName();
 }
 
 @end
index 32e187b..16a0263 100644 (file)
@@ -118,10 +118,10 @@ PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::document()
 
 IntRect InjectedBundleNodeHandle::elementBounds() const
 {
-    if (!m_node->isElementNode())
+    if (!is<Element>(*m_node))
         return IntRect();
 
-    return toElement(m_node.get())->boundsInRootViewSpace();
+    return downcast<Element>(*m_node).boundsInRootViewSpace();
 }
     
 IntRect InjectedBundleNodeHandle::renderRect(bool* isReplaced) const
index dfbb792..f444734 100644 (file)
@@ -114,10 +114,10 @@ BundleHitTestResultMediaType InjectedBundleHitTestResult::mediaType() const
     return BundleHitTestResultMediaTypeNone;
 #else
     WebCore::Node* node = m_hitTestResult.innerNonSharedNode();
-    if (!node->isElementNode())
+    if (!is<Element>(node))
         return BundleHitTestResultMediaTypeNone;
     
-    if (!toElement(node)->isMediaElement())
+    if (!downcast<Element>(*node).isMediaElement())
         return BundleHitTestResultMediaTypeNone;
     
     return m_hitTestResult.mediaIsVideo() ? BundleHitTestResultMediaTypeVideo : BundleHitTestResultMediaTypeAudio;    
index 6631161..7d29c03 100644 (file)
@@ -515,8 +515,8 @@ void WebPage::sendTapHighlightForNodeIfNecessary(uint64_t requestID, Node* node)
     if (!node)
         return;
 
-    if (isElement(*node))
-        prefetchDNS(toElement(*node).absoluteLinkURL().host());
+    if (is<Element>(*node))
+        prefetchDNS(downcast<Element>(*node).absoluteLinkURL().host());
 
     Vector<FloatQuad> quads;
     if (RenderObject *renderer = node->renderer()) {
@@ -604,8 +604,8 @@ void WebPage::inspectorNodeSearchEndedAtPosition(const FloatPoint& position)
 
 void WebPage::blurAssistedNode()
 {
-    if (m_assistedNode && m_assistedNode->isElementNode())
-        toElement(m_assistedNode.get())->blur();
+    if (m_assistedNode && is<Element>(*m_assistedNode))
+        downcast<Element>(*m_assistedNode).blur();
 }
 
 void WebPage::setAssistedNodeValue(const String& value)
@@ -1888,7 +1888,7 @@ void WebPage::getPositionInformation(const IntPoint& point, InteractionInformati
     if (hitNode) {
         info.clickableElementName = hitNode->nodeName();
 
-        Element* element = hitNode->isElementNode() ? toElement(hitNode) : 0;
+        Element* element = is<Element>(hitNode) ? downcast<Element>(hitNode) : nullptr;
         if (element) {
             Element* linkElement = nullptr;
             if (element->renderer() && element->renderer()->isRenderImage()) {
@@ -2006,7 +2006,7 @@ static inline Element* nextFocusableElement(Node* startNode, Page* page, bool is
 {
     RefPtr<KeyboardEvent> key = KeyboardEvent::create();
 
-    Element* nextElement = toElement(startNode);
+    Element* nextElement = downcast<Element>(startNode);
     do {
         nextElement = isForward ? page->focusController().nextFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&nextElement->document()), nextElement, key.get())
             : page->focusController().previousFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&nextElement->document()), nextElement, key.get());
@@ -2163,7 +2163,7 @@ void WebPage::elementDidFocus(WebCore::Node* node)
         // a programmatic focus happening while the keyboard is already shown. Once we have a way to
         // know the keyboard state in the Web Process, we should refine the condition.
         if (m_userIsInteracting)
-            m_formClient->willBeginInputSession(this, toElement(node), WebFrame::fromCoreFrame(*node->document().frame()), userData);
+            m_formClient->willBeginInputSession(this, downcast<Element>(node), WebFrame::fromCoreFrame(*node->document().frame()), userData);
 
         send(Messages::WebPageProxy::StartAssistingNode(information, m_userIsInteracting, m_hasPendingBlurNotification, InjectedBundleUserMessageEncoder(userData.get())));
         m_hasPendingBlurNotification = false;