Use downcast<HTML*Element>() instead of toHTML*Element()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Sep 2014 22:03:15 +0000 (22:03 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Sep 2014 22:03:15 +0000 (22:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137007

Reviewed by Benjamin Poulain.

Source/WebCore:

Use downcast<HTML*Element>() instead of toHTML*Element() and drop
transition macros for toHTML*Element().

This patch also cleans up the surrounding code.

No new tests, no behavior change.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::focusedUIElementForPage):
(WebCore::AXObjectCache::labelChanged):
* accessibility/AccessibilityListBox.cpp:
(WebCore::AccessibilityListBox::canSetSelectedChildrenAttribute):
(WebCore::AccessibilityListBox::addChildren):
* accessibility/AccessibilityListBoxOption.cpp:
(WebCore::AccessibilityListBoxOption::isSelected):
(WebCore::AccessibilityListBoxOption::stringValue):
(WebCore::AccessibilityListBoxOption::listBoxOptionParentNode):
* accessibility/AccessibilityMediaControls.cpp:
(WebCore::AccessibilityMediaTimeline::valueDescription):
* accessibility/AccessibilityMenuListOption.cpp:
(WebCore::AccessibilityMenuListOption::isEnabled):
(WebCore::AccessibilityMenuListOption::isSelected):
(WebCore::AccessibilityMenuListOption::setSelected):
(WebCore::AccessibilityMenuListOption::stringValue):
* accessibility/AccessibilityMenuListPopup.cpp:
(WebCore::AccessibilityMenuListPopup::addChildren):
* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::determineAccessibilityRole):
(WebCore::AccessibilityNodeObject::isNativeTextControl):
(WebCore::AccessibilityNodeObject::isNativeImage):
(WebCore::AccessibilityNodeObject::isInputImage):
(WebCore::AccessibilityNodeObject::isMultiSelectable):
(WebCore::AccessibilityNodeObject::isReadOnly):
(WebCore::AccessibilityNodeObject::valueForRange):
(WebCore::AccessibilityNodeObject::maxValueForRange):
(WebCore::AccessibilityNodeObject::minValueForRange):
(WebCore::isNodeActionElement):
(WebCore::AccessibilityNodeObject::alternativeText):
(WebCore::AccessibilityNodeObject::visibleText):
(WebCore::AccessibilityNodeObject::title):
(WebCore::AccessibilityNodeObject::text):
(WebCore::AccessibilityNodeObject::stringValue):
(WebCore::AccessibilityNodeObject::colorValue):
(WebCore::accessibleNameForNode):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::isFileUploadButton):
(WebCore::AccessibilityRenderObject::stringValue):
(WebCore::AccessibilityRenderObject::labelElementContainer):
(WebCore::AccessibilityRenderObject::internalLinkElement):
(WebCore::AccessibilityRenderObject::addRadioButtonGroupMembers):
(WebCore::AccessibilityRenderObject::url):
(WebCore::AccessibilityRenderObject::setValue):
(WebCore::AccessibilityRenderObject::getDocumentLinks):
(WebCore::AccessibilityRenderObject::accessibilityImageMapHitTest):
(WebCore::AccessibilityRenderObject::accessibilityHitTest):
(WebCore::AccessibilityRenderObject::determineAccessibilityRole):
(WebCore::AccessibilityRenderObject::addTextFieldChildren):
(WebCore::AccessibilityRenderObject::stringValueForMSAA):
(WebCore::AccessibilityRenderObject::isLinked):
* accessibility/AccessibilitySlider.cpp:
(WebCore::AccessibilitySlider::inputElement):
(WebCore::AccessibilitySliderThumb::elementRect):
* accessibility/AccessibilityTable.cpp:
(WebCore::AccessibilityTable::tableElement):
(WebCore::AccessibilityTable::title):
* accessibility/atk/AXObjectCacheAtk.cpp:
(WebCore::notifyChildrenSelectionChange):
* accessibility/atk/WebKitAccessibleInterfaceSelection.cpp:
(optionFromSelection):
(webkitAccessibleSelectionGetSelectionCount):
* accessibility/atk/WebKitAccessibleInterfaceTable.cpp:
(webkitAccessibleTableGetCaption):
* accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
(webkitAccessibleGetDescription):
* accessibility/ios/AccessibilityObjectIOS.mm:
(WebCore::AccessibilityObject::accessibilityPasswordFieldLength):
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::namedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
* bindings/js/JSHTMLDocumentCustom.cpp:
(WebCore::JSHTMLDocument::nameGetter):
* bindings/js/JSHTMLFrameSetElementCustom.cpp:
(WebCore::JSHTMLFrameSetElement::nameGetter):
* bindings/js/JSNodeCustom.cpp:
(WebCore::isReachableFromDOM):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* css/SelectorCheckerTestFunctions.h:
(WebCore::isChecked):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::adjustRenderStyle):
* css/StyleSheetList.cpp:
(WebCore::StyleSheetList::getNamedItem):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::makeContextStyleUniqueIfNecessaryAndTestIsPlaceholderShown):
(WebCore::SelectorCompiler::makeElementStyleUniqueIfNecessaryAndTestIsPlaceholderShown):
(WebCore::SelectorCompiler::isPlaceholderShown):
* dom/CurrentScriptIncrementer.h:
(WebCore::CurrentScriptIncrementer::CurrentScriptIncrementer):
* dom/DataTransfer.cpp:
(WebCore::DataTransfer::setDragImage):
* dom/Document.cpp:
(WebCore::Document::setTitle):
(WebCore::Document::processHttpEquiv):
(WebCore::Document::iconURLs):
* dom/DocumentOrderedMap.cpp:
(WebCore::keyMatchesMapName):
(WebCore::keyMatchesLowercasedMapName):
(WebCore::keyMatchesLowercasedUsemap):
(WebCore::DocumentOrderedMap::getElementByMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedUsemap):
(WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::collectActiveStyleSheets):
* dom/Element.cpp:
(WebCore::Element::insertedInto):
(WebCore::Element::removedFrom):
(WebCore::Element::updateName):
(WebCore::Element::updateId):
(WebCore::Element::updateLabel):
(WebCore::Element::ensureCachedHTMLCollection):
* dom/EventDispatcher.cpp:
(WebCore::EventDispatcher::dispatchEvent):
* dom/ScriptElement.cpp:
(WebCore::toScriptElementIfPossible):
* dom/VisitedLinkState.cpp:
(WebCore::linkHashForElement):
(WebCore::VisitedLinkState::determineLinkStateSlowCase):
* dom/make_names.pl:
(printTypeHelpers):
* editing/Editor.cpp:
(WebCore::Editor::selectionForCommand):
(WebCore::imageElementFromImageDocument):
(WebCore::findFirstMarkable):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::selectAll):
(WebCore::scanForForm):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::serializeNodesWithNamespaces):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::shouldPerformSmartReplace):
* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::nonBoundaryShadowTreeRootNode):
(WebCore::VisibleSelection::isInPasswordField):
* editing/cocoa/HTMLConverter.mm:
(HTMLConverter::_processElement):
* editing/ios/EditorIOS.mm:
(WebCore::Editor::setTextAlignmentForChangedBaseWritingDirection):
* editing/markup.cpp:
(WebCore::isPlainTextMarkup):
* html/ColorInputType.cpp:
(WebCore::ColorInputType::suggestions):
* html/FTPDirectoryDocument.cpp:
(WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate):
(WebCore::FTPDirectoryDocumentParser::createBasicDocument):
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::findAssociatedForm):
* html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition):
* html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::imageElement):
* html/HTMLCollection.cpp:
(WebCore::isMatchingElement):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::matchesReadWritePseudoClass):
(WebCore::HTMLElement::setInnerHTML):
(WebCore::HTMLElement::directionality):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::rendererIsNeeded):
* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::refreshElementsIfNeeded):
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::computeIsDisabledByFieldsetAncestor):
(WebCore::shouldAutofocus):
* html/HTMLFormControlsCollection.cpp:
(WebCore::HTMLFormControlsCollection::formControlElements):
(WebCore::HTMLFormControlsCollection::formImageElements):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::getTextFieldValues):
(WebCore::HTMLFormElement::assertItemCanBeInPastNamesMap):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute):
* html/HTMLImageLoader.cpp:
(WebCore::HTMLImageLoader::notifyFinished):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::dataList):
(WebCore::HTMLInputElement::setupDateTimeChooserParameters):
* html/HTMLKeygenElement.cpp:
(WebCore::HTMLKeygenElement::shadowSelect):
* html/HTMLLegendElement.cpp:
(WebCore::HTMLLegendElement::virtualForm):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute):
* html/HTMLNameCollection.cpp:
(WebCore::DocumentNameCollection::elementMatchesIfIdAttributeMatch):
(WebCore::DocumentNameCollection::elementMatchesIfNameAttributeMatch):
(WebCore::DocumentNameCollection::elementMatches):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateDocNamedItem):
(WebCore::HTMLObjectElement::containsJavaApplet):
* html/HTMLOptGroupElement.cpp:
(WebCore::HTMLOptGroupElement::recalcSelectOptions):
(WebCore::HTMLOptGroupElement::ownerSelectElement):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::ownerDataListElement):
(WebCore::HTMLOptionElement::ownerSelectElement):
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::add):
* html/HTMLOptionsCollection.h:
* html/HTMLPlugInImageElement.cpp:
(WebCore::addPlugInsFromNodeListMatchingPlugInOrigin):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::hasPlaceholderLabelOption):
(WebCore::HTMLSelectElement::value):
(WebCore::HTMLSelectElement::setValue):
(WebCore::HTMLSelectElement::saveLastSelection):
(WebCore::HTMLSelectElement::setActiveSelectionAnchorIndex):
(WebCore::HTMLSelectElement::updateListBoxSelection):
(WebCore::HTMLSelectElement::listBoxOnChange):
(WebCore::HTMLSelectElement::recalcListItems):
(WebCore::HTMLSelectElement::selectedIndex):
(WebCore::HTMLSelectElement::selectOption):
(WebCore::HTMLSelectElement::deselectItemsWithoutValidation):
(WebCore::HTMLSelectElement::saveFormControlState):
(WebCore::HTMLSelectElement::searchOptionsForValue):
(WebCore::HTMLSelectElement::restoreFormControlState):
(WebCore::HTMLSelectElement::appendFormData):
(WebCore::HTMLSelectElement::reset):
(WebCore::HTMLSelectElement::updateSelectedState):
(WebCore::HTMLSelectElement::lastSelectedListIndex):
(WebCore::HTMLSelectElement::optionAtIndex):
(WebCore::HTMLSelectElement::accessKeySetSelectedIndex):
* html/HTMLSummaryElement.cpp:
(WebCore::HTMLSummaryElement::detailsElement):
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::caption):
* html/HTMLTablePartElement.cpp:
(WebCore::HTMLTablePartElement::findParentTable):
* html/HTMLTableRowElement.cpp:
(WebCore::HTMLTableRowElement::rowIndex):
* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::rowAfter):
(WebCore::HTMLTableRowsCollection::lastRow):
(WebCore::HTMLTableRowsCollection::customElementAfter):
* html/HTMLTableRowsCollection.h:
* html/HTMLTemplateElement.cpp:
(WebCore::HTMLTemplateElement::cloneNode):
* html/HTMLTextFormControlElement.cpp:
(WebCore::enclosingTextFormControl):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::createDocumentStructure):
* html/LabelsNodeList.cpp:
(WebCore::LabelsNodeList::elementMatches):
* html/MediaDocument.cpp:
(WebCore::MediaDocumentParser::createDocumentStructure):
(WebCore::descendentVideoElement):
(WebCore::ancestorVideoElement):
(WebCore::MediaDocument::replaceMediaElementTimerFired):
* html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::createDocumentStructure):
* html/RadioInputType.cpp:
(WebCore::RadioInputType::handleKeydownEvent):
(WebCore::RadioInputType::isKeyboardFocusable):
* html/RadioNodeList.cpp:
(WebCore::RadioNodeList::checkElementMatchesRadioNodeListFilter):
* html/RangeInputType.cpp:
(WebCore::RangeInputType::updateTickMarkValues):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::insert):
(WebCore::HTMLConstructionSite::insertTextNode):
(WebCore::HTMLConstructionSite::ownerDocumentForCurrentNode):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
* html/shadow/DetailsMarkerControl.cpp:
(WebCore::DetailsMarkerControl::rendererIsNeeded):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::updateDisplay):
* html/shadow/MeterShadowElement.cpp:
(WebCore::MeterShadowElement::meterElement):
* html/shadow/ProgressShadowElement.cpp:
(WebCore::ProgressShadowElement::progressElement):
* html/shadow/TextControlInnerElements.cpp:
(WebCore::SearchFieldResultsButtonElement::defaultEventHandler):
(WebCore::SearchFieldCancelButtonElement::defaultEventHandler):
(WebCore::SearchFieldCancelButtonElement::willRespondToMouseClickEvents):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::buildObjectForNode):
* loader/FormSubmission.cpp:
(WebCore::FormSubmission::create):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::handleFallbackContent):
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::dispatchPendingBeforeLoadEvent):
* loader/SubframeLoader.cpp:
(WebCore::SubframeLoader::requestObject):
* page/Chrome.cpp:
(WebCore::Chrome::setToolTip):
* page/DragController.cpp:
(WebCore::DragController::draggableElement):
* page/EventHandler.cpp:
(WebCore::isSubmitImage):
* page/FocusController.cpp:
(WebCore::FocusController::advanceFocusDirectionally):
* page/FrameView.cpp:
(WebCore::FrameView::addEmbeddedObjectToUpdate):
(WebCore::FrameView::updateEmbeddedObject):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::serializeFrame):
* page/SpatialNavigation.cpp:
(WebCore::FocusCandidate::FocusCandidate):
* page/ios/FrameIOS.mm:
(WebCore::ancestorRespondingToClickEvents):
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::altDisplayString):
(WebCore::HitTestResult::absolutePDFURL):
(WebCore::HitTestResult::enterFullscreenForVideo):
(WebCore::HitTestResult::mediaControlsEnabled):
(WebCore::HitTestResult::isLiveLink):
(WebCore::HitTestResult::isContentEditable):
* rendering/RenderButton.cpp:
(WebCore::RenderButton::updateFromElement):
* rendering/RenderCounter.cpp:
(WebCore::planCounter):
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::paintContents):
(WebCore::RenderEmbeddedObject::layout):
* rendering/RenderFieldset.h:
* rendering/RenderFileUploadControl.cpp:
(WebCore::RenderFileUploadControl::inputElement):
(WebCore::RenderFileUploadControl::uploadButton):
* rendering/RenderFrame.cpp:
(WebCore::RenderFrame::frameElement):
* rendering/RenderFrameSet.cpp:
(WebCore::RenderFrameSet::frameSetElement):
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::canvasElement):
* rendering/RenderIFrame.cpp:
(WebCore::RenderIFrame::iframeElement):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::RenderImage):
(WebCore::RenderImage::paintAreaElementFocusRing):
(WebCore::RenderImage::paintIntoRect):
(WebCore::RenderImage::imageMap):
(WebCore::RenderImage::updateAltText):
* rendering/RenderLayerBacking.cpp:
(WebCore::canvasCompositingStrategy):
(WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):
(WebCore::RenderLayerBacking::updateConfiguration):
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::requiresCompositingForCanvas):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::selectElement):
(WebCore::RenderListBox::updateFromElement):
(WebCore::RenderListBox::paintItemForeground):
(WebCore::RenderListBox::paintItemBackground):
* rendering/RenderListItem.cpp:
(WebCore::RenderListItem::calcValue):
(WebCore::RenderListItem::updateListMarkerNumbers):
* rendering/RenderMarquee.cpp:
(WebCore::RenderMarquee::marqueeSpeed):
* rendering/RenderMenuList.cpp:
(WebCore::selectedOptionCount):
(RenderMenuList::selectElement):
(RenderMenuList::updateOptionsWidth):
(RenderMenuList::setTextFromOption):
(RenderMenuList::itemText):
(RenderMenuList::itemIsSelected):
* rendering/RenderMeter.cpp:
(WebCore::RenderMeter::meterElement):
* rendering/RenderProgress.cpp:
(WebCore::RenderProgress::progressElement):
* rendering/RenderSlider.cpp:
(WebCore::RenderSlider::element):
* rendering/RenderSnapshottedPlugIn.cpp:
(WebCore::RenderSnapshottedPlugIn::plugInImageElement):
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::textFormControlElement):
* rendering/RenderTextControlMultiLine.cpp:
(WebCore::RenderTextControlMultiLine::textAreaElement):
* rendering/RenderTextControlSingleLine.cpp:
(WebCore::RenderTextControlSingleLine::inputElement):
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::paintSliderTicks):
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::paintMenuListButtonDecorations):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintSearchFieldCancelButton):
(WebCore::RenderThemeMac::paintSnapshottedPluginOverlay):
* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::videoElement):
* svg/graphics/SVGImageCache.cpp:
(WebCore::SVGImageCache::imageForRenderer):
* svg/svgtags.in:
Generate helpers to SVGAElement so that isSVGAElement() can be used
instead of hasTagName(SVGNames::aTag). I did such update in this
patch.

* testing/Internals.cpp:
(WebCore::Internals::visiblePlaceholder):
(WebCore::Internals::wasLastChangeUserEdit):
(WebCore::Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks):
(WebCore::Internals::isSelectPopupVisible):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::startElementNs):

Source/WebKit/ios:

Use downcast<HTML*Element>() instead of toHTML*Element().

* WebCoreSupport/WebChromeClientIOS.mm:
(WebChromeClientIOS::focusedElementChanged):

Source/WebKit/mac:

Use downcast<HTML*Element>() instead of toHTML*Element().

* DOM/WebDOMOperations.mm:
(-[DOMHTMLInputElement _setAutofilled:]):
* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::focusedElementChanged):
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::textFieldDidBeginEditing):
(WebEditorClient::textFieldDidEndEditing):
(WebEditorClient::textDidChangeInTextField):
(WebEditorClient::doTextFieldCommandFromEvent):
(WebEditorClient::textWillBeDeletedInTextField):
(WebEditorClient::textDidChangeInTextArea):
* WebView/WebHTMLRepresentation.mm:
(inputElementFromDOMElement):

Source/WebKit/win:

Use downcast<HTML*Element>() instead of toHTML*Element().

* DOMHTMLClasses.cpp:
(DOMHTMLDocument::URL):
(DOMHTMLDocument::body):
(DOMHTMLDocument::forms):
(DOMHTMLFormElement::action):
(DOMHTMLFormElement::method):
(DOMHTMLSelectElement::options):
(DOMHTMLSelectElement::activateItemAtIndex):
(DOMHTMLOptionElement::text):
(DOMHTMLOptionElement::label):
(DOMHTMLInputElement::form):
(DOMHTMLInputElement::disabled):
(DOMHTMLInputElement::readOnly):
(DOMHTMLInputElement::setType):
(DOMHTMLInputElement::value):
(DOMHTMLInputElement::setValue):
(DOMHTMLInputElement::setValueForUser):
(DOMHTMLInputElement::select):
(DOMHTMLInputElement::setSelectionStart):
(DOMHTMLInputElement::selectionStart):
(DOMHTMLInputElement::setSelectionEnd):
(DOMHTMLInputElement::selectionEnd):
(DOMHTMLInputElement::isTextField):
(DOMHTMLInputElement::replaceCharactersInRange):
(DOMHTMLInputElement::selectedRange):
(DOMHTMLInputElement::setAutofilled):
(DOMHTMLInputElement::isAutofilled):
(DOMHTMLInputElement::isUserEdited):
(DOMHTMLTextAreaElement::form):
(DOMHTMLTextAreaElement::value):
(DOMHTMLTextAreaElement::setValue):
(DOMHTMLTextAreaElement::select):
(DOMHTMLTextAreaElement::isUserEdited):
(DOMHTMLIFrameElement::contentFrame):
* WebFrame.cpp:
(formElementFromDOMElement):
(inputElementFromDOMElement):

Source/WebKit2:

Use downcast<HTML*Element>() instead of toHTML*Element().

* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementValueForUser):
(WebKit::InjectedBundleNodeHandle::isHTMLInputElementAutofilled):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementAutofilled):
(WebKit::InjectedBundleNodeHandle::htmlInputElementLastChangeWasUserEdit):
(WebKit::InjectedBundleNodeHandle::htmlTextAreaElementLastChangeWasUserEdit):
(WebKit::InjectedBundleNodeHandle::isTextField):
(WebKit::InjectedBundleNodeHandle::htmlTableCellElementCellAbove):
(WebKit::InjectedBundleNodeHandle::htmlIFrameElementContentFrame):
* WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
(WebKit::PDFPluginChoiceAnnotation::commit):
* WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
(WebKit::PDFPluginTextAnnotation::createAnnotationElement):
(WebKit::PDFPluginTextAnnotation::value):
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::initializePlugin):
(WebKit::PluginView::pluginSnapshotTimerFired):
(WebKit::PluginView::pluginDidReceiveUserInteraction):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::focusedElementChanged):
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::textFieldDidBeginEditing):
(WebKit::WebEditorClient::textFieldDidEndEditing):
(WebKit::WebEditorClient::textDidChangeInTextField):
(WebKit::WebEditorClient::textDidChangeInTextArea):
(WebKit::WebEditorClient::doTextFieldCommandFromEvent):
(WebKit::WebEditorClient::textWillBeDeletedInTextField):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createPlugin):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::setAssistedNodeValue):
(WebKit::WebPage::setAssistedNodeValueAsNumber):
(WebKit::WebPage::setAssistedNodeSelectedIndex):
(WebKit::isAssistableNode): Deleted.
(WebKit::WebPage::getAssistedNodeInformation): Deleted.

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

155 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AccessibilityListBox.cpp
Source/WebCore/accessibility/AccessibilityListBoxOption.cpp
Source/WebCore/accessibility/AccessibilityMediaControls.cpp
Source/WebCore/accessibility/AccessibilityMenuListOption.cpp
Source/WebCore/accessibility/AccessibilityMenuListPopup.cpp
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilitySlider.cpp
Source/WebCore/accessibility/AccessibilityTable.cpp
Source/WebCore/accessibility/atk/AXObjectCacheAtk.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceSelection.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceTable.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
Source/WebCore/accessibility/ios/AccessibilityObjectIOS.mm
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp
Source/WebCore/bindings/js/JSNodeCustom.cpp
Source/WebCore/css/SelectorChecker.cpp
Source/WebCore/css/SelectorCheckerTestFunctions.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/StyleSheetList.cpp
Source/WebCore/cssjit/SelectorCompiler.cpp
Source/WebCore/dom/CurrentScriptIncrementer.h
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/DocumentOrderedMap.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/EventDispatcher.cpp
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/VisitedLinkState.cpp
Source/WebCore/dom/make_names.pl
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/MarkupAccumulator.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/VisibleSelection.cpp
Source/WebCore/editing/cocoa/HTMLConverter.mm
Source/WebCore/editing/ios/EditorIOS.mm
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/FTPDirectoryDocument.cpp
Source/WebCore/html/FormAssociatedElement.cpp
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/html/HTMLAreaElement.cpp
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLEmbedElement.cpp
Source/WebCore/html/HTMLFieldSetElement.cpp
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlsCollection.cpp
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageLoader.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLKeygenElement.cpp
Source/WebCore/html/HTMLLegendElement.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLNameCollection.cpp
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLOptGroupElement.cpp
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLOptionsCollection.cpp
Source/WebCore/html/HTMLOptionsCollection.h
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSummaryElement.cpp
Source/WebCore/html/HTMLTableElement.cpp
Source/WebCore/html/HTMLTablePartElement.cpp
Source/WebCore/html/HTMLTableRowElement.cpp
Source/WebCore/html/HTMLTableRowsCollection.cpp
Source/WebCore/html/HTMLTableRowsCollection.h
Source/WebCore/html/HTMLTemplateElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/html/LabelsNodeList.cpp
Source/WebCore/html/MediaDocument.cpp
Source/WebCore/html/PluginDocument.cpp
Source/WebCore/html/RadioInputType.cpp
Source/WebCore/html/RadioNodeList.cpp
Source/WebCore/html/RangeInputType.cpp
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/html/parser/HTMLTreeBuilder.cpp
Source/WebCore/html/shadow/DetailsMarkerControl.cpp
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MeterShadowElement.cpp
Source/WebCore/html/shadow/ProgressShadowElement.cpp
Source/WebCore/html/shadow/TextControlInnerElements.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/loader/FormSubmission.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/SubframeLoader.cpp
Source/WebCore/page/Chrome.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/PageSerializer.cpp
Source/WebCore/page/SpatialNavigation.cpp
Source/WebCore/page/ios/FrameIOS.mm
Source/WebCore/rendering/HitTestResult.cpp
Source/WebCore/rendering/RenderButton.cpp
Source/WebCore/rendering/RenderCounter.cpp
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderFieldset.h
Source/WebCore/rendering/RenderFileUploadControl.cpp
Source/WebCore/rendering/RenderFrame.cpp
Source/WebCore/rendering/RenderFrameSet.cpp
Source/WebCore/rendering/RenderHTMLCanvas.cpp
Source/WebCore/rendering/RenderIFrame.cpp
Source/WebCore/rendering/RenderImage.cpp
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebCore/rendering/RenderListBox.cpp
Source/WebCore/rendering/RenderListItem.cpp
Source/WebCore/rendering/RenderMarquee.cpp
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderMeter.cpp
Source/WebCore/rendering/RenderProgress.cpp
Source/WebCore/rendering/RenderSlider.cpp
Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp
Source/WebCore/rendering/RenderTextControl.cpp
Source/WebCore/rendering/RenderTextControlMultiLine.cpp
Source/WebCore/rendering/RenderTextControlSingleLine.cpp
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/RenderVideo.cpp
Source/WebCore/svg/graphics/SVGImageCache.cpp
Source/WebCore/svg/svgtags.in
Source/WebCore/testing/Internals.cpp
Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Source/WebKit/ios/ChangeLog
Source/WebKit/ios/WebCoreSupport/WebChromeClientIOS.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/WebDOMOperations.mm
Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit/mac/WebView/WebHTMLRepresentation.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/DOMHTMLClasses.cpp
Source/WebKit/win/WebFrame.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm
Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 56ab1e1..d1f6680 100644 (file)
@@ -1,5 +1,421 @@
 2014-09-23  Chris Dumez  <cdumez@apple.com>
 
+        Use downcast<HTML*Element>() instead of toHTML*Element()
+        https://bugs.webkit.org/show_bug.cgi?id=137007
+
+        Reviewed by Benjamin Poulain.
+
+        Use downcast<HTML*Element>() instead of toHTML*Element() and drop
+        transition macros for toHTML*Element().
+
+        This patch also cleans up the surrounding code.
+
+        No new tests, no behavior change.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::focusedUIElementForPage):
+        (WebCore::AXObjectCache::labelChanged):
+        * accessibility/AccessibilityListBox.cpp:
+        (WebCore::AccessibilityListBox::canSetSelectedChildrenAttribute):
+        (WebCore::AccessibilityListBox::addChildren):
+        * accessibility/AccessibilityListBoxOption.cpp:
+        (WebCore::AccessibilityListBoxOption::isSelected):
+        (WebCore::AccessibilityListBoxOption::stringValue):
+        (WebCore::AccessibilityListBoxOption::listBoxOptionParentNode):
+        * accessibility/AccessibilityMediaControls.cpp:
+        (WebCore::AccessibilityMediaTimeline::valueDescription):
+        * accessibility/AccessibilityMenuListOption.cpp:
+        (WebCore::AccessibilityMenuListOption::isEnabled):
+        (WebCore::AccessibilityMenuListOption::isSelected):
+        (WebCore::AccessibilityMenuListOption::setSelected):
+        (WebCore::AccessibilityMenuListOption::stringValue):
+        * accessibility/AccessibilityMenuListPopup.cpp:
+        (WebCore::AccessibilityMenuListPopup::addChildren):
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::determineAccessibilityRole):
+        (WebCore::AccessibilityNodeObject::isNativeTextControl):
+        (WebCore::AccessibilityNodeObject::isNativeImage):
+        (WebCore::AccessibilityNodeObject::isInputImage):
+        (WebCore::AccessibilityNodeObject::isMultiSelectable):
+        (WebCore::AccessibilityNodeObject::isReadOnly):
+        (WebCore::AccessibilityNodeObject::valueForRange):
+        (WebCore::AccessibilityNodeObject::maxValueForRange):
+        (WebCore::AccessibilityNodeObject::minValueForRange):
+        (WebCore::isNodeActionElement):
+        (WebCore::AccessibilityNodeObject::alternativeText):
+        (WebCore::AccessibilityNodeObject::visibleText):
+        (WebCore::AccessibilityNodeObject::title):
+        (WebCore::AccessibilityNodeObject::text):
+        (WebCore::AccessibilityNodeObject::stringValue):
+        (WebCore::AccessibilityNodeObject::colorValue):
+        (WebCore::accessibleNameForNode):
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::isFileUploadButton):
+        (WebCore::AccessibilityRenderObject::stringValue):
+        (WebCore::AccessibilityRenderObject::labelElementContainer):
+        (WebCore::AccessibilityRenderObject::internalLinkElement):
+        (WebCore::AccessibilityRenderObject::addRadioButtonGroupMembers):
+        (WebCore::AccessibilityRenderObject::url):
+        (WebCore::AccessibilityRenderObject::setValue):
+        (WebCore::AccessibilityRenderObject::getDocumentLinks):
+        (WebCore::AccessibilityRenderObject::accessibilityImageMapHitTest):
+        (WebCore::AccessibilityRenderObject::accessibilityHitTest):
+        (WebCore::AccessibilityRenderObject::determineAccessibilityRole):
+        (WebCore::AccessibilityRenderObject::addTextFieldChildren):
+        (WebCore::AccessibilityRenderObject::stringValueForMSAA):
+        (WebCore::AccessibilityRenderObject::isLinked):
+        * accessibility/AccessibilitySlider.cpp:
+        (WebCore::AccessibilitySlider::inputElement):
+        (WebCore::AccessibilitySliderThumb::elementRect):
+        * accessibility/AccessibilityTable.cpp:
+        (WebCore::AccessibilityTable::tableElement):
+        (WebCore::AccessibilityTable::title):
+        * accessibility/atk/AXObjectCacheAtk.cpp:
+        (WebCore::notifyChildrenSelectionChange):
+        * accessibility/atk/WebKitAccessibleInterfaceSelection.cpp:
+        (optionFromSelection):
+        (webkitAccessibleSelectionGetSelectionCount):
+        * accessibility/atk/WebKitAccessibleInterfaceTable.cpp:
+        (webkitAccessibleTableGetCaption):
+        * accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
+        (webkitAccessibleGetDescription):
+        * accessibility/ios/AccessibilityObjectIOS.mm:
+        (WebCore::AccessibilityObject::accessibilityPasswordFieldLength):
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::namedItemGetter):
+        (WebCore::JSDOMWindow::getOwnPropertySlot):
+        (WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
+        * bindings/js/JSHTMLDocumentCustom.cpp:
+        (WebCore::JSHTMLDocument::nameGetter):
+        * bindings/js/JSHTMLFrameSetElementCustom.cpp:
+        (WebCore::JSHTMLFrameSetElement::nameGetter):
+        * bindings/js/JSNodeCustom.cpp:
+        (WebCore::isReachableFromDOM):
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::checkOne):
+        * css/SelectorCheckerTestFunctions.h:
+        (WebCore::isChecked):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::adjustRenderStyle):
+        * css/StyleSheetList.cpp:
+        (WebCore::StyleSheetList::getNamedItem):
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::makeContextStyleUniqueIfNecessaryAndTestIsPlaceholderShown):
+        (WebCore::SelectorCompiler::makeElementStyleUniqueIfNecessaryAndTestIsPlaceholderShown):
+        (WebCore::SelectorCompiler::isPlaceholderShown):
+        * dom/CurrentScriptIncrementer.h:
+        (WebCore::CurrentScriptIncrementer::CurrentScriptIncrementer):
+        * dom/DataTransfer.cpp:
+        (WebCore::DataTransfer::setDragImage):
+        * dom/Document.cpp:
+        (WebCore::Document::setTitle):
+        (WebCore::Document::processHttpEquiv):
+        (WebCore::Document::iconURLs):
+        * dom/DocumentOrderedMap.cpp:
+        (WebCore::keyMatchesMapName):
+        (WebCore::keyMatchesLowercasedMapName):
+        (WebCore::keyMatchesLowercasedUsemap):
+        (WebCore::DocumentOrderedMap::getElementByMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedUsemap):
+        (WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::collectActiveStyleSheets):
+        * dom/Element.cpp:
+        (WebCore::Element::insertedInto):
+        (WebCore::Element::removedFrom):
+        (WebCore::Element::updateName):
+        (WebCore::Element::updateId):
+        (WebCore::Element::updateLabel):
+        (WebCore::Element::ensureCachedHTMLCollection):
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventDispatcher::dispatchEvent):
+        * dom/ScriptElement.cpp:
+        (WebCore::toScriptElementIfPossible):
+        * dom/VisitedLinkState.cpp:
+        (WebCore::linkHashForElement):
+        (WebCore::VisitedLinkState::determineLinkStateSlowCase):
+        * dom/make_names.pl:
+        (printTypeHelpers):
+        * editing/Editor.cpp:
+        (WebCore::Editor::selectionForCommand):
+        (WebCore::imageElementFromImageDocument):
+        (WebCore::findFirstMarkable):
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::selectAll):
+        (WebCore::scanForForm):
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::serializeNodesWithNamespaces):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::shouldPerformSmartReplace):
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::nonBoundaryShadowTreeRootNode):
+        (WebCore::VisibleSelection::isInPasswordField):
+        * editing/cocoa/HTMLConverter.mm:
+        (HTMLConverter::_processElement):
+        * editing/ios/EditorIOS.mm:
+        (WebCore::Editor::setTextAlignmentForChangedBaseWritingDirection):
+        * editing/markup.cpp:
+        (WebCore::isPlainTextMarkup):
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::suggestions):
+        * html/FTPDirectoryDocument.cpp:
+        (WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate):
+        (WebCore::FTPDirectoryDocumentParser::createBasicDocument):
+        * html/FormAssociatedElement.cpp:
+        (WebCore::FormAssociatedElement::findAssociatedForm):
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::appendServerMapMousePosition):
+        * html/HTMLAreaElement.cpp:
+        (WebCore::HTMLAreaElement::imageElement):
+        * html/HTMLCollection.cpp:
+        (WebCore::isMatchingElement):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::matchesReadWritePseudoClass):
+        (WebCore::HTMLElement::setInnerHTML):
+        (WebCore::HTMLElement::directionality):
+        * html/HTMLEmbedElement.cpp:
+        (WebCore::HTMLEmbedElement::rendererIsNeeded):
+        * html/HTMLFieldSetElement.cpp:
+        (WebCore::HTMLFieldSetElement::refreshElementsIfNeeded):
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::computeIsDisabledByFieldsetAncestor):
+        (WebCore::shouldAutofocus):
+        * html/HTMLFormControlsCollection.cpp:
+        (WebCore::HTMLFormControlsCollection::formControlElements):
+        (WebCore::HTMLFormControlsCollection::formImageElements):
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::getTextFieldValues):
+        (WebCore::HTMLFormElement::assertItemCanBeInPastNamesMap):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::parseAttribute):
+        * html/HTMLImageLoader.cpp:
+        (WebCore::HTMLImageLoader::notifyFinished):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::dataList):
+        (WebCore::HTMLInputElement::setupDateTimeChooserParameters):
+        * html/HTMLKeygenElement.cpp:
+        (WebCore::HTMLKeygenElement::shadowSelect):
+        * html/HTMLLegendElement.cpp:
+        (WebCore::HTMLLegendElement::virtualForm):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::parseAttribute):
+        * html/HTMLNameCollection.cpp:
+        (WebCore::DocumentNameCollection::elementMatchesIfIdAttributeMatch):
+        (WebCore::DocumentNameCollection::elementMatchesIfNameAttributeMatch):
+        (WebCore::DocumentNameCollection::elementMatches):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+        (WebCore::HTMLObjectElement::containsJavaApplet):
+        * html/HTMLOptGroupElement.cpp:
+        (WebCore::HTMLOptGroupElement::recalcSelectOptions):
+        (WebCore::HTMLOptGroupElement::ownerSelectElement):
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::ownerDataListElement):
+        (WebCore::HTMLOptionElement::ownerSelectElement):
+        * html/HTMLOptionsCollection.cpp:
+        (WebCore::HTMLOptionsCollection::add):
+        * html/HTMLOptionsCollection.h:
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::addPlugInsFromNodeListMatchingPlugInOrigin):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::hasPlaceholderLabelOption):
+        (WebCore::HTMLSelectElement::value):
+        (WebCore::HTMLSelectElement::setValue):
+        (WebCore::HTMLSelectElement::saveLastSelection):
+        (WebCore::HTMLSelectElement::setActiveSelectionAnchorIndex):
+        (WebCore::HTMLSelectElement::updateListBoxSelection):
+        (WebCore::HTMLSelectElement::listBoxOnChange):
+        (WebCore::HTMLSelectElement::recalcListItems):
+        (WebCore::HTMLSelectElement::selectedIndex):
+        (WebCore::HTMLSelectElement::selectOption):
+        (WebCore::HTMLSelectElement::deselectItemsWithoutValidation):
+        (WebCore::HTMLSelectElement::saveFormControlState):
+        (WebCore::HTMLSelectElement::searchOptionsForValue):
+        (WebCore::HTMLSelectElement::restoreFormControlState):
+        (WebCore::HTMLSelectElement::appendFormData):
+        (WebCore::HTMLSelectElement::reset):
+        (WebCore::HTMLSelectElement::updateSelectedState):
+        (WebCore::HTMLSelectElement::lastSelectedListIndex):
+        (WebCore::HTMLSelectElement::optionAtIndex):
+        (WebCore::HTMLSelectElement::accessKeySetSelectedIndex):
+        * html/HTMLSummaryElement.cpp:
+        (WebCore::HTMLSummaryElement::detailsElement):
+        * html/HTMLTableElement.cpp:
+        (WebCore::HTMLTableElement::caption):
+        * html/HTMLTablePartElement.cpp:
+        (WebCore::HTMLTablePartElement::findParentTable):
+        * html/HTMLTableRowElement.cpp:
+        (WebCore::HTMLTableRowElement::rowIndex):
+        * html/HTMLTableRowsCollection.cpp:
+        (WebCore::HTMLTableRowsCollection::rowAfter):
+        (WebCore::HTMLTableRowsCollection::lastRow):
+        (WebCore::HTMLTableRowsCollection::customElementAfter):
+        * html/HTMLTableRowsCollection.h:
+        * html/HTMLTemplateElement.cpp:
+        (WebCore::HTMLTemplateElement::cloneNode):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::enclosingTextFormControl):
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::createDocumentStructure):
+        * html/LabelsNodeList.cpp:
+        (WebCore::LabelsNodeList::elementMatches):
+        * html/MediaDocument.cpp:
+        (WebCore::MediaDocumentParser::createDocumentStructure):
+        (WebCore::descendentVideoElement):
+        (WebCore::ancestorVideoElement):
+        (WebCore::MediaDocument::replaceMediaElementTimerFired):
+        * html/PluginDocument.cpp:
+        (WebCore::PluginDocumentParser::createDocumentStructure):
+        * html/RadioInputType.cpp:
+        (WebCore::RadioInputType::handleKeydownEvent):
+        (WebCore::RadioInputType::isKeyboardFocusable):
+        * html/RadioNodeList.cpp:
+        (WebCore::RadioNodeList::checkElementMatchesRadioNodeListFilter):
+        * html/RangeInputType.cpp:
+        (WebCore::RangeInputType::updateTickMarkValues):
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::insert):
+        (WebCore::HTMLConstructionSite::insertTextNode):
+        (WebCore::HTMLConstructionSite::ownerDocumentForCurrentNode):
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
+        * html/shadow/DetailsMarkerControl.cpp:
+        (WebCore::DetailsMarkerControl::rendererIsNeeded):
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
+        * html/shadow/MeterShadowElement.cpp:
+        (WebCore::MeterShadowElement::meterElement):
+        * html/shadow/ProgressShadowElement.cpp:
+        (WebCore::ProgressShadowElement::progressElement):
+        * html/shadow/TextControlInnerElements.cpp:
+        (WebCore::SearchFieldResultsButtonElement::defaultEventHandler):
+        (WebCore::SearchFieldCancelButtonElement::defaultEventHandler):
+        (WebCore::SearchFieldCancelButtonElement::willRespondToMouseClickEvents):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::buildObjectForNode):
+        * loader/FormSubmission.cpp:
+        (WebCore::FormSubmission::create):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::handleFallbackContent):
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::dispatchPendingBeforeLoadEvent):
+        * loader/SubframeLoader.cpp:
+        (WebCore::SubframeLoader::requestObject):
+        * page/Chrome.cpp:
+        (WebCore::Chrome::setToolTip):
+        * page/DragController.cpp:
+        (WebCore::DragController::draggableElement):
+        * page/EventHandler.cpp:
+        (WebCore::isSubmitImage):
+        * page/FocusController.cpp:
+        (WebCore::FocusController::advanceFocusDirectionally):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::addEmbeddedObjectToUpdate):
+        (WebCore::FrameView::updateEmbeddedObject):
+        * page/PageSerializer.cpp:
+        (WebCore::PageSerializer::serializeFrame):
+        * page/SpatialNavigation.cpp:
+        (WebCore::FocusCandidate::FocusCandidate):
+        * page/ios/FrameIOS.mm:
+        (WebCore::ancestorRespondingToClickEvents):
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::altDisplayString):
+        (WebCore::HitTestResult::absolutePDFURL):
+        (WebCore::HitTestResult::enterFullscreenForVideo):
+        (WebCore::HitTestResult::mediaControlsEnabled):
+        (WebCore::HitTestResult::isLiveLink):
+        (WebCore::HitTestResult::isContentEditable):
+        * rendering/RenderButton.cpp:
+        (WebCore::RenderButton::updateFromElement):
+        * rendering/RenderCounter.cpp:
+        (WebCore::planCounter):
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::paintContents):
+        (WebCore::RenderEmbeddedObject::layout):
+        * rendering/RenderFieldset.h:
+        * rendering/RenderFileUploadControl.cpp:
+        (WebCore::RenderFileUploadControl::inputElement):
+        (WebCore::RenderFileUploadControl::uploadButton):
+        * rendering/RenderFrame.cpp:
+        (WebCore::RenderFrame::frameElement):
+        * rendering/RenderFrameSet.cpp:
+        (WebCore::RenderFrameSet::frameSetElement):
+        * rendering/RenderHTMLCanvas.cpp:
+        (WebCore::RenderHTMLCanvas::canvasElement):
+        * rendering/RenderIFrame.cpp:
+        (WebCore::RenderIFrame::iframeElement):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::RenderImage):
+        (WebCore::RenderImage::paintAreaElementFocusRing):
+        (WebCore::RenderImage::paintIntoRect):
+        (WebCore::RenderImage::imageMap):
+        (WebCore::RenderImage::updateAltText):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::canvasCompositingStrategy):
+        (WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):
+        (WebCore::RenderLayerBacking::updateConfiguration):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::requiresCompositingForCanvas):
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::selectElement):
+        (WebCore::RenderListBox::updateFromElement):
+        (WebCore::RenderListBox::paintItemForeground):
+        (WebCore::RenderListBox::paintItemBackground):
+        * rendering/RenderListItem.cpp:
+        (WebCore::RenderListItem::calcValue):
+        (WebCore::RenderListItem::updateListMarkerNumbers):
+        * rendering/RenderMarquee.cpp:
+        (WebCore::RenderMarquee::marqueeSpeed):
+        * rendering/RenderMenuList.cpp:
+        (WebCore::selectedOptionCount):
+        (RenderMenuList::selectElement):
+        (RenderMenuList::updateOptionsWidth):
+        (RenderMenuList::setTextFromOption):
+        (RenderMenuList::itemText):
+        (RenderMenuList::itemIsSelected):
+        * rendering/RenderMeter.cpp:
+        (WebCore::RenderMeter::meterElement):
+        * rendering/RenderProgress.cpp:
+        (WebCore::RenderProgress::progressElement):
+        * rendering/RenderSlider.cpp:
+        (WebCore::RenderSlider::element):
+        * rendering/RenderSnapshottedPlugIn.cpp:
+        (WebCore::RenderSnapshottedPlugIn::plugInImageElement):
+        * rendering/RenderTextControl.cpp:
+        (WebCore::RenderTextControl::textFormControlElement):
+        * rendering/RenderTextControlMultiLine.cpp:
+        (WebCore::RenderTextControlMultiLine::textAreaElement):
+        * rendering/RenderTextControlSingleLine.cpp:
+        (WebCore::RenderTextControlSingleLine::inputElement):
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::paintSliderTicks):
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::paintMenuListButtonDecorations):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintSearchFieldCancelButton):
+        (WebCore::RenderThemeMac::paintSnapshottedPluginOverlay):
+        * rendering/RenderVideo.cpp:
+        (WebCore::RenderVideo::videoElement):
+        * svg/graphics/SVGImageCache.cpp:
+        (WebCore::SVGImageCache::imageForRenderer):
+        * svg/svgtags.in:
+        Generate helpers to SVGAElement so that isSVGAElement() can be used
+        instead of hasTagName(SVGNames::aTag). I did such update in this
+        patch.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::visiblePlaceholder):
+        (WebCore::Internals::wasLastChangeUserEdit):
+        (WebCore::Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks):
+        (WebCore::Internals::isSelectPopupVisible):
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::startElementNs):
+
+2014-09-23  Chris Dumez  <cdumez@apple.com>
+
         Have DataTransfer::files() return a reference
         https://bugs.webkit.org/show_bug.cgi?id=137039
 
index f1953d6..eaa1623 100644 (file)
@@ -177,7 +177,7 @@ AccessibilityObject* AXObjectCache::focusedUIElementForPage(const Page* page)
     Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
     Element* focusedElement = focusedDocument->focusedElement();
     if (focusedElement && isHTMLAreaElement(focusedElement))
-        return focusedImageMapUIElement(toHTMLAreaElement(focusedElement));
+        return focusedImageMapUIElement(downcast<HTMLAreaElement>(focusedElement));
 
     AccessibilityObject* obj = focusedDocument->axObjectCache()->getOrCreate(focusedElement ? static_cast<Node*>(focusedElement) : focusedDocument);
     if (!obj)
@@ -948,7 +948,7 @@ void AXObjectCache::handleAttributeChanged(const QualifiedName& attrName, Elemen
 void AXObjectCache::labelChanged(Element* element)
 {
     ASSERT(isHTMLLabelElement(element));
-    HTMLElement* correspondingControl = toHTMLLabelElement(element)->control();
+    HTMLElement* correspondingControl = downcast<HTMLLabelElement>(element)->control();
     textChanged(correspondingControl);
 }
 
index 62b934d..0f8e1d9 100644 (file)
@@ -61,7 +61,7 @@ bool AccessibilityListBox::canSetSelectedChildrenAttribute() const
     if (!selectNode)
         return false;
     
-    return !toHTMLSelectElement(selectNode)->isDisabledFormControl();
+    return !downcast<HTMLSelectElement>(*selectNode).isDisabledFormControl();
 }
 
 void AccessibilityListBox::addChildren()
@@ -72,7 +72,7 @@ void AccessibilityListBox::addChildren()
     
     m_haveChildren = true;
     
-    for (const auto& listItem : toHTMLSelectElement(selectNode)->listItems()) {
+    for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems()) {
         // The cast to HTMLElement below is safe because the only other possible listItem type
         // would be a WMLElement, but WML builds don't use accessibility features at all.
         AccessibilityObject* listOption = listBoxOptionAccessibilityObject(listItem);
index a9fad8d..d865c89 100644 (file)
@@ -84,7 +84,7 @@ bool AccessibilityListBoxOption::isSelected() const
     if (!isHTMLOptionElement(m_optionElement))
         return false;
 
-    return toHTMLOptionElement(m_optionElement)->selected();
+    return downcast<HTMLOptionElement>(*m_optionElement).selected();
 }
 
 bool AccessibilityListBoxOption::isSelectedOptionActive() const
@@ -157,10 +157,10 @@ String AccessibilityListBoxOption::stringValue() const
         return ariaLabel;
     
     if (isHTMLOptionElement(m_optionElement))
-        return toHTMLOptionElement(m_optionElement)->text();
+        return downcast<HTMLOptionElement>(*m_optionElement).text();
     
     if (isHTMLOptGroupElement(m_optionElement))
-        return toHTMLOptGroupElement(m_optionElement)->groupLabelText();
+        return downcast<HTMLOptGroupElement>(*m_optionElement).groupLabelText();
     
     return String();
 }
@@ -203,10 +203,10 @@ HTMLSelectElement* AccessibilityListBoxOption::listBoxOptionParentNode() const
         return nullptr;
 
     if (isHTMLOptionElement(m_optionElement))
-        return toHTMLOptionElement(m_optionElement)->ownerSelectElement();
+        return downcast<HTMLOptionElement>(*m_optionElement).ownerSelectElement();
 
     if (isHTMLOptGroupElement(m_optionElement))
-        return toHTMLOptGroupElement(m_optionElement)->ownerSelectElement();
+        return downcast<HTMLOptGroupElement>(*m_optionElement).ownerSelectElement();
 
     return nullptr;
 }
index a0735b4..deb0920 100644 (file)
@@ -277,7 +277,7 @@ String AccessibilityMediaTimeline::valueDescription() const
     if (!isHTMLInputElement(node))
         return String();
 
-    float time = toHTMLInputElement(node)->value().toFloat();
+    float time = downcast<HTMLInputElement>(*node).value().toFloat();
     return localizedMediaTimeDescription(time);
 }
 
index 88e2e6e..c69211a 100644 (file)
@@ -54,7 +54,7 @@ bool AccessibilityMenuListOption::isEnabled() const
 {
     // isDisabledFormControl() returns true if the parent <select> element is disabled,
     // which we don't want.
-    return !toHTMLOptionElement(m_element.get())->ownElementDisabled();
+    return !downcast<HTMLOptionElement>(*m_element).ownElementDisabled();
 }
 
 bool AccessibilityMenuListOption::isVisible() const
@@ -75,15 +75,15 @@ bool AccessibilityMenuListOption::isOffScreen() const
 
 bool AccessibilityMenuListOption::isSelected() const
 {
-    return toHTMLOptionElement(m_element.get())->selected();
+    return downcast<HTMLOptionElement>(*m_element).selected();
 }
 
-void AccessibilityMenuListOption::setSelected(bool b)
+void AccessibilityMenuListOption::setSelected(bool selected)
 {
     if (!canSetSelectedAttribute())
         return;
 
-    toHTMLOptionElement(m_element.get())->setSelected(b);
+    downcast<HTMLOptionElement>(*m_element).setSelected(selected);
 }
 
 String AccessibilityMenuListOption::nameForMSAA() const
@@ -114,7 +114,7 @@ LayoutRect AccessibilityMenuListOption::elementRect() const
 
 String AccessibilityMenuListOption::stringValue() const
 {
-    return toHTMLOptionElement(m_element.get())->text();
+    return downcast<HTMLOptionElement>(*m_element).text();
 }
 
 } // namespace WebCore
index 1d5219d..fc2585d 100644 (file)
@@ -102,7 +102,7 @@ void AccessibilityMenuListPopup::addChildren()
 
     m_haveChildren = true;
 
-    for (const auto& listItem : toHTMLSelectElement(selectNode)->listItems()) {
+    for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems()) {
         AccessibilityMenuListOption* option = menuListOptionAccessibilityObject(listItem);
         if (option) {
             option->setParent(this);
index 6ecae18..8e6e247 100644 (file)
@@ -291,18 +291,18 @@ AccessibilityRole AccessibilityNodeObject::determineAccessibilityRole()
     if (node()->hasTagName(buttonTag))
         return buttonRoleType();
     if (isHTMLInputElement(node())) {
-        HTMLInputElement* input = toHTMLInputElement(node());
-        if (input->isCheckbox())
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node());
+        if (input.isCheckbox())
             return CheckBoxRole;
-        if (input->isRadioButton())
+        if (input.isRadioButton())
             return RadioButtonRole;
-        if (input->isTextButton())
+        if (input.isTextButton())
             return buttonRoleType();
-        if (input->isRangeControl())
+        if (input.isRangeControl())
             return SliderRole;
 
 #if ENABLE(INPUT_TYPE_COLOR)
-        const AtomicString& type = input->getAttribute(typeAttr);
+        const AtomicString& type = input.getAttribute(typeAttr);
         if (equalIgnoringCase(type, "color"))
             return ColorWellRole;
 #endif
@@ -310,8 +310,8 @@ AccessibilityRole AccessibilityNodeObject::determineAccessibilityRole()
         return TextFieldRole;
     }
     if (node()->hasTagName(selectTag)) {
-        HTMLSelectElement* selectElement = toHTMLSelectElement(node());
-        return selectElement->multiple() ? ListBoxRole : PopUpButtonRole;
+        HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*node());
+        return selectElement.multiple() ? ListBoxRole : PopUpButtonRole;
     }
     if (isHTMLTextAreaElement(node()))
         return TextAreaRole;
@@ -469,8 +469,8 @@ bool AccessibilityNodeObject::isNativeTextControl() const
         return true;
 
     if (isHTMLInputElement(node)) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        return input->isText() || input->isNumberField();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        return input.isText() || input.isNumberField();
     }
 
     return false;
@@ -519,8 +519,8 @@ bool AccessibilityNodeObject::isNativeImage() const
         return true;
 
     if (isHTMLInputElement(node)) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        return input->isImageButton();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        return input.isImageButton();
     }
 
     return false;
@@ -554,8 +554,8 @@ bool AccessibilityNodeObject::isInputImage() const
         return false;
  
     if (roleValue() == ButtonRole && isHTMLInputElement(node)) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        return input->isImageButton();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        return input.isImageButton();
     }
 
     return false;
@@ -729,7 +729,7 @@ bool AccessibilityNodeObject::isMultiSelectable() const
     if (equalIgnoringCase(ariaMultiSelectable, "false"))
         return false;
     
-    return node() && node()->hasTagName(selectTag) && toHTMLSelectElement(node())->multiple();
+    return node() && node()->hasTagName(selectTag) && downcast<HTMLSelectElement>(*node()).multiple();
 }
 
 bool AccessibilityNodeObject::isReadOnly() const
@@ -742,9 +742,9 @@ bool AccessibilityNodeObject::isReadOnly() const
         return toHTMLFormControlElement(node)->isReadOnly();
 
     if (isHTMLInputElement(node)) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        if (input->isTextField())
-            return input->isReadOnly();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        if (input.isTextField())
+            return input.isReadOnly();
     }
 
     return !node->hasEditableStyle();
@@ -838,9 +838,9 @@ String AccessibilityNodeObject::valueDescription() const
 float AccessibilityNodeObject::valueForRange() const
 {
     if (node() && isHTMLInputElement(node())) {
-        HTMLInputElement* input = toHTMLInputElement(node());
-        if (input->isRangeControl())
-            return input->valueAsNumber();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node());
+        if (input.isRangeControl())
+            return input.valueAsNumber();
     }
 
     if (!isRangeControl())
@@ -852,9 +852,9 @@ float AccessibilityNodeObject::valueForRange() const
 float AccessibilityNodeObject::maxValueForRange() const
 {
     if (node() && isHTMLInputElement(node())) {
-        HTMLInputElement* input = toHTMLInputElement(node());
-        if (input->isRangeControl())
-            return input->maximum();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node());
+        if (input.isRangeControl())
+            return input.maximum();
     }
 
     if (!isRangeControl())
@@ -866,9 +866,9 @@ float AccessibilityNodeObject::maxValueForRange() const
 float AccessibilityNodeObject::minValueForRange() const
 {
     if (node() && isHTMLInputElement(node())) {
-        HTMLInputElement* input = toHTMLInputElement(node());
-        if (input->isRangeControl())
-            return input->minimum();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node());
+        if (input.isRangeControl())
+            return input.minimum();
     }
 
     if (!isRangeControl())
@@ -974,8 +974,8 @@ Element* AccessibilityNodeObject::anchorElement() const
 static bool isNodeActionElement(Node* node)
 {
     if (isHTMLInputElement(node)) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        if (!input->isDisabledFormControl() && (input->isRadioButton() || input->isCheckbox() || input->isTextButton() || input->isFileUpload() || input->isImageButton()))
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        if (!input.isDisabledFormControl() && (input.isRadioButton() || input.isCheckbox() || input.isTextButton() || input.isFileUpload() || input.isImageButton()))
             return true;
     } else if (node->hasTagName(buttonTag) || node->hasTagName(selectTag))
         return true;
@@ -1307,7 +1307,7 @@ void AccessibilityNodeObject::alternativeText(Vector<AccessibilityText>& textOrd
     
     // The fieldset element derives its alternative text from the first associated legend element if one is available.
     if (isHTMLFieldSetElement(node)) {
-        AccessibilityObject* object = axObjectCache()->getOrCreate(toHTMLFieldSetElement(node)->legend());
+        AccessibilityObject* object = axObjectCache()->getOrCreate(downcast<HTMLFieldSetElement>(*node).legend());
         if (object && !object->isHidden())
             textOrder.append(AccessibilityText(accessibleNameForNode(object->node()), AlternativeText));
     }
@@ -1330,9 +1330,9 @@ void AccessibilityNodeObject::visibleText(Vector<AccessibilityText>& textOrder)
     
     bool isInputTag = isHTMLInputElement(node);
     if (isInputTag) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        if (input->isTextButton()) {
-            textOrder.append(AccessibilityText(input->valueWithDefault(), VisibleText));
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        if (input.isTextButton()) {
+            textOrder.append(AccessibilityText(input.valueWithDefault(), VisibleText));
             return;
         }
     }
@@ -1685,9 +1685,9 @@ String AccessibilityNodeObject::title() const
 
     bool isInputTag = isHTMLInputElement(node);
     if (isInputTag) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        if (input->isTextButton())
-            return input->valueWithDefault();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        if (input.isTextButton())
+            return input.valueWithDefault();
     }
 
     if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl()) {
@@ -1751,8 +1751,8 @@ String AccessibilityNodeObject::text() const
     if (!node)
         return String();
 
-    if (isNativeTextControl() && (isHTMLTextAreaElement(node) || isHTMLInputElement(node)))
-        return toHTMLTextFormControlElement(node)->value();
+    if (isNativeTextControl() && isHTMLTextFormControlElement(*node))
+        return downcast<HTMLTextFormControlElement>(*node).value();
 
     if (!node->isElementNode())
         return String();
@@ -1777,16 +1777,16 @@ String AccessibilityNodeObject::stringValue() const
         return textUnderElement();
 
     if (node->hasTagName(selectTag)) {
-        HTMLSelectElement* selectElement = toHTMLSelectElement(node);
-        int selectedIndex = selectElement->selectedIndex();
-        const Vector<HTMLElement*>& listItems = selectElement->listItems();
+        HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*node);
+        int selectedIndex = selectElement.selectedIndex();
+        const Vector<HTMLElement*>& listItems = selectElement.listItems();
         if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
             const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
             if (!overriddenDescription.isNull())
                 return overriddenDescription;
         }
-        if (!selectElement->multiple())
-            return selectElement->value();
+        if (!selectElement.multiple())
+            return selectElement.value();
         return String();
     }
 
@@ -1812,13 +1812,13 @@ void AccessibilityNodeObject::colorValue(int& r, int& g, int& b) const
     if (!node() || !isHTMLInputElement(node()))
         return;
 
-    HTMLInputElement* input = toHTMLInputElement(node());
-    const AtomicString& type = input->getAttribute(typeAttr);
+    HTMLInputElement& input = downcast<HTMLInputElement>(*node());
+    const AtomicString& type = input.getAttribute(typeAttr);
     if (!equalIgnoringCase(type, "color"))
         return;
 
     // HTMLInputElement::value always returns a string parseable by Color().
-    Color color(input->value());
+    Color color(input.value());
     r = color.red();
     g = color.green();
     b = color.blue();
@@ -1842,7 +1842,7 @@ static String accessibleNameForNode(Node* node)
         return alt;
     
     if (isHTMLInputElement(node))
-        return toHTMLInputElement(node)->value();
+        return downcast<HTMLInputElement>(*node).value();
     
     // If the node can be turned into an AX object, we can use standard name computation rules.
     // If however, the node cannot (because there's no renderer e.g.) fallback to using the basic text underneath.
index a45748a..b596f8d 100644 (file)
@@ -524,8 +524,8 @@ bool AccessibilityRenderObject::isAttachment() const
 bool AccessibilityRenderObject::isFileUploadButton() const
 {
     if (m_renderer && m_renderer->node() && isHTMLInputElement(m_renderer->node())) {
-        HTMLInputElement* input = toHTMLInputElement(m_renderer->node());
-        return input->isFileUpload();
+        HTMLInputElement& input = downcast<HTMLInputElement>(*m_renderer->node());
+        return input.isFileUpload();
     }
     
     return false;
@@ -741,9 +741,9 @@ String AccessibilityRenderObject::stringValue() const
     if (cssBox && cssBox->isMenuList()) {
         // RenderMenuList will go straight to the text() of its selected item.
         // This has to be overridden in the case where the selected item has an ARIA label.
-        HTMLSelectElement* selectElement = toHTMLSelectElement(m_renderer->node());
-        int selectedIndex = selectElement->selectedIndex();
-        const Vector<HTMLElement*>& listItems = selectElement->listItems();
+        HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*m_renderer->node());
+        int selectedIndex = selectElement.selectedIndex();
+        const Vector<HTMLElement*>& listItems = selectElement.listItems();
         if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
             const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
             if (!overriddenDescription.isNull())
@@ -783,7 +783,7 @@ HTMLLabelElement* AccessibilityRenderObject::labelElementContainer() const
     // find if this has a parent that is a label
     for (Node* parentNode = m_renderer->node(); parentNode; parentNode = parentNode->parentNode()) {
         if (isHTMLLabelElement(parentNode))
-            return toHTMLLabelElement(parentNode);
+            return downcast<HTMLLabelElement>(parentNode);
     }
     
     return nullptr;
@@ -916,9 +916,9 @@ AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
     // Right now, we do not support ARIA links as internal link elements
     if (!isHTMLAnchorElement(element))
         return nullptr;
-    HTMLAnchorElement* anchor = toHTMLAnchorElement(element);
+    HTMLAnchorElement& anchor = downcast<HTMLAnchorElement>(*element);
     
-    URL linkURL = anchor->href();
+    URL linkURL = anchor.href();
     String fragmentIdentifier = linkURL.fragmentIdentifier();
     if (fragmentIdentifier.isEmpty())
         return nullptr;
@@ -953,24 +953,25 @@ void AccessibilityRenderObject::addRadioButtonGroupMembers(AccessibilityChildren
     if (!node || !isHTMLInputElement(node))
         return;
     
-    HTMLInputElement* input = toHTMLInputElement(node);
+    HTMLInputElement& input = downcast<HTMLInputElement>(*node);
     // if there's a form, then this is easy
-    if (input->form()) {
+    if (input.form()) {
         Vector<Ref<Element>> formElements;
-        input->form()->getNamedElements(input->name(), formElements);
+        input.form()->getNamedElements(input.name(), formElements);
         
         for (auto& associateElement : formElements) {
             if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement.get()))
                 linkedUIElements.append(object);        
         } 
     } else {
-        RefPtr<NodeList> list = node->document().getElementsByTagName("input");
-        unsigned len = list->length();
-        for (unsigned i = 0; i < len; ++i) {
-            if (isHTMLInputElement(list->item(i))) {
-                HTMLInputElement* associateElement = toHTMLInputElement(list->item(i));
-                if (associateElement->isRadioButton() && associateElement->name() == input->name()) {
-                    if (AccessibilityObject* object = axObjectCache()->getOrCreate(associateElement))
+        RefPtr<NodeList> list = node->document().getElementsByTagName(inputTag.localName());
+        unsigned length = list->length();
+        for (unsigned i = 0; i < length; ++i) {
+            Node* item = list->item(i);
+            if (isHTMLInputElement(item)) {
+                HTMLInputElement& associateElement = downcast<HTMLInputElement>(*item);
+                if (associateElement.isRadioButton() && associateElement.name() == input.name()) {
+                    if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement))
                         linkedUIElements.append(object);
                 }
             }
@@ -1507,7 +1508,7 @@ void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range
 URL AccessibilityRenderObject::url() const
 {
     if (isAnchor() && isHTMLAnchorElement(m_renderer->node())) {
-        if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement()))
+        if (HTMLAnchorElement* anchor = downcast<HTMLAnchorElement>(anchorElement()))
             return anchor->href();
     }
     
@@ -1515,10 +1516,10 @@ URL AccessibilityRenderObject::url() const
         return m_renderer->document().url();
     
     if (isImage() && m_renderer->node() && isHTMLImageElement(m_renderer->node()))
-        return toHTMLImageElement(m_renderer->node())->src();
+        return downcast<HTMLImageElement>(*m_renderer->node()).src();
     
     if (isInputImage())
-        return toHTMLInputElement(m_renderer->node())->src();
+        return downcast<HTMLInputElement>(*m_renderer->node()).src();
     
     return URL();
 }
@@ -1679,20 +1680,17 @@ void AccessibilityRenderObject::setValue(const String& string)
 {
     if (!m_renderer || !m_renderer->node() || !m_renderer->node()->isElementNode())
         return;
-    Element* element = toElement(m_renderer->node());
+    Element& element = toElement(*m_renderer->node());
 
     if (!m_renderer->isBoxModelObject())
         return;
     RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
 
     // FIXME: Do we want to do anything here for ARIA textboxes?
-    if (renderer->isTextField()) {
-        // FIXME: This is not safe!  Other elements could have a TextField renderer.
-        toHTMLInputElement(element)->setValue(string);
-    } else if (renderer->isTextArea()) {
-        // FIXME: This is not safe!  Other elements could have a TextArea renderer.
-        toHTMLTextAreaElement(element)->setValue(string);
-    }
+    if (renderer->isTextField() && isHTMLInputElement(element))
+        downcast<HTMLInputElement>(element).setValue(string);
+    else if (renderer->isTextArea() && isHTMLTextAreaElement(element))
+        downcast<HTMLTextAreaElement>(element).setValue(string);
 }
 
 void AccessibilityRenderObject::ariaOwnsElements(AccessibilityChildrenVector& axObjects) const
@@ -1763,10 +1761,10 @@ void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& re
             Node* parent = curr->parentNode();
             if (parent && isHTMLAreaElement(curr) && isHTMLMapElement(parent)) {
                 AccessibilityImageMapLink* areaObject = toAccessibilityImageMapLink(axObjectCache()->getOrCreate(ImageMapLinkRole));
-                HTMLMapElement* map = toHTMLMapElement(parent);
-                areaObject->setHTMLAreaElement(toHTMLAreaElement(curr));
-                areaObject->setHTMLMapElement(map);
-                areaObject->setParent(accessibilityParentForImageMap(map));
+                HTMLMapElement& map = downcast<HTMLMapElement>(*parent);
+                areaObject->setHTMLAreaElement(downcast<HTMLAreaElement>(curr));
+                areaObject->setHTMLMapElement(&map);
+                areaObject->setParent(accessibilityParentForImageMap(&map));
 
                 result.append(areaObject);
             }
@@ -2161,7 +2159,7 @@ AccessibilityObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTM
     AccessibilityObject* parent = nullptr;
     for (Element* mapParent = area->parentElement(); mapParent; mapParent = mapParent->parentElement()) {
         if (isHTMLMapElement(mapParent)) {
-            parent = accessibilityParentForImageMap(toHTMLMapElement(mapParent));
+            parent = accessibilityParentForImageMap(downcast<HTMLMapElement>(mapParent));
             break;
         }
     }
@@ -2211,10 +2209,10 @@ AccessibilityObject* AccessibilityRenderObject::accessibilityHitTest(const IntPo
     Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
 
     if (isHTMLAreaElement(node))
-        return accessibilityImageMapHitTest(toHTMLAreaElement(node), point);
+        return accessibilityImageMapHitTest(downcast<HTMLAreaElement>(node), point);
     
     if (isHTMLOptionElement(node))
-        node = toHTMLOptionElement(node)->ownerSelectElement();
+        node = downcast<HTMLOptionElement>(*node).ownerSelectElement();
     
     RenderObject* obj = node->renderer();
     if (!obj)
@@ -2505,21 +2503,22 @@ AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
         return TextAreaRole;
 
     if (node && isHTMLInputElement(node)) {
-        HTMLInputElement* input = toHTMLInputElement(node);
-        if (input->isCheckbox())
+        HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+        if (input.isCheckbox())
             return CheckBoxRole;
-        if (input->isRadioButton())
+        if (input.isRadioButton())
             return RadioButtonRole;
-        if (input->isTextButton())
+        if (input.isTextButton())
             return buttonRoleType();
         // On iOS, the date field is a popup button. On other platforms this is a text field.
 #if PLATFORM(IOS)
-        if (input->isDateField())
+        if (input.isDateField())
             return PopUpButtonRole;
 #endif
         
 #if ENABLE(INPUT_TYPE_COLOR)
-        const AtomicString& type = input->getAttribute(typeAttr);
+        // FIXME: Shouldn't this use input.isColorControl()?
+        const AtomicString& type = input.getAttribute(typeAttr);
         if (equalIgnoringCase(type, "color"))
             return ColorWellRole;
 #endif
@@ -2840,8 +2839,8 @@ void AccessibilityRenderObject::addTextFieldChildren()
     if (!node || !isHTMLInputElement(node))
         return;
     
-    HTMLInputElement* input = toHTMLInputElement(node);
-    HTMLElement* spinButtonElement = input->innerSpinButtonElement();
+    HTMLInputElement& input = downcast<HTMLInputElement>(*node);
+    HTMLElement* spinButtonElement = input.innerSpinButtonElement();
     if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
         return;
 
@@ -3271,7 +3270,7 @@ String AccessibilityRenderObject::stringValueForMSAA() const
     if (isLinkable(*this)) {
         Element* anchor = anchorElement();
         if (anchor && isHTMLAnchorElement(anchor))
-            return toHTMLAnchorElement(anchor)->href();
+            return downcast<HTMLAnchorElement>(*anchor).href();
     }
 
     return stringValue();
@@ -3286,7 +3285,7 @@ bool AccessibilityRenderObject::isLinked() const
     if (!anchor || !isHTMLAnchorElement(anchor))
         return false;
 
-    return !toHTMLAnchorElement(anchor)->href().isEmpty();
+    return !downcast<HTMLAnchorElement>(*anchor).href().isEmpty();
 }
 
 bool AccessibilityRenderObject::hasBoldFont() const
index 950f982..b5e346d 100644 (file)
@@ -138,7 +138,7 @@ void AccessibilitySlider::setValue(const String& value)
 
 HTMLInputElement* AccessibilitySlider::inputElement() const
 {
-    return toHTMLInputElement(m_renderer->node());
+    return downcast<HTMLInputElement>(m_renderer->node());
 }
 
 
@@ -159,7 +159,7 @@ LayoutRect AccessibilitySliderThumb::elementRect() const
     RenderObject* sliderRenderer = m_parent->renderer();
     if (!sliderRenderer || !sliderRenderer->isSlider())
         return LayoutRect();
-    return toHTMLInputElement(sliderRenderer->node())->sliderThumbElement()->boundingBox();
+    return downcast<HTMLInputElement>(sliderRenderer->node())->sliderThumbElement()->boundingBox();
 }
 
 bool AccessibilitySliderThumb::computeAccessibilityIsIgnored() const
index d9d435f..e25443c 100644 (file)
@@ -97,7 +97,7 @@ HTMLTableElement* AccessibilityTable::tableElement() const
     
     RenderTable* table = toRenderTable(m_renderer);
     if (table->element() && isHTMLTableElement(table->element()))
-        return toHTMLTableElement(table->element());
+        return downcast<HTMLTableElement>(table->element());
     
     // If the table has a display:table-row-group, then the RenderTable does not have a pointer to it's HTMLTableElement.
     // We can instead find it by asking the firstSection for its parent.
@@ -109,7 +109,7 @@ HTMLTableElement* AccessibilityTable::tableElement() const
     if (!actualTable || !isHTMLTableElement(actualTable))
         return nullptr;
     
-    return toHTMLTableElement(actualTable);
+    return downcast<HTMLTableElement>(actualTable);
 }
     
 bool AccessibilityTable::isDataTable() const
@@ -608,8 +608,7 @@ String AccessibilityTable::title() const
     // see if there is a caption
     Node* tableElement = m_renderer->node();
     if (tableElement && isHTMLTableElement(tableElement)) {
-        HTMLTableCaptionElement* caption = toHTMLTableElement(tableElement)->caption();
-        if (caption)
+        if (HTMLTableCaptionElement* caption = downcast<HTMLTableElement>(*tableElement).caption())
             title = caption->innerText();
     }
     
index 930ef3b..b865118 100644 (file)
@@ -140,10 +140,8 @@ static void notifyChildrenSelectionChange(AccessibilityObject* object)
     g_signal_emit_by_name(object->wrapper(), "selection-changed");
 
     // Find the item where the selection change was triggered from.
-    HTMLSelectElement* select = toHTMLSelectElement(node);
-    if (!select)
-        return;
-    int changedItemIndex = select->activeSelectionStartListIndex();
+    HTMLSelectElement& select = downcast<HTMLSelectElement>(*node);
+    int changedItemIndex = select.activeSelectionStartListIndex();
 
     AccessibilityObject* listObject = getListObject(object);
     if (!listObject) {
index 6c4cbf9..9e87f4f 100644 (file)
@@ -108,7 +108,7 @@ static AccessibilityObject* optionFromSelection(AtkSelection* selection, gint in
         if (!renderer)
             return nullptr;
 
-        HTMLSelectElement* selectNode = toHTMLSelectElement(renderer->node());
+        HTMLSelectElement* selectNode = downcast<HTMLSelectElement>(renderer->node());
         if (!selectNode)
             return nullptr;
 
@@ -195,8 +195,8 @@ static gint webkitAccessibleSelectionGetSelectionCount(AtkSelection* selection)
         if (!renderer)
             return 0;
 
-        int selectedIndex = toHTMLSelectElement(renderer->node())->selectedIndex();
-        return selectedIndex >= 0 && selectedIndex < static_cast<int>(toHTMLSelectElement(renderer->node())->listItems().size());
+        int selectedIndex = downcast<HTMLSelectElement>(renderer->node())->selectedIndex();
+        return selectedIndex >= 0 && selectedIndex < static_cast<int>(downcast<HTMLSelectElement>(renderer->node())->listItems().size());
     }
 
     return 0;
index f6ed19c..659b88f 100644 (file)
@@ -238,19 +238,19 @@ static AtkObject* webkitAccessibleTableGetRowHeader(AtkTable* table, gint row)
 
 static AtkObject* webkitAccessibleTableGetCaption(AtkTable* table)
 {
-    g_return_val_if_fail(ATK_TABLE(table), 0);
-    returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(table), 0);
+    g_return_val_if_fail(ATK_TABLE(table), nullptr);
+    returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(table), nullptr);
 
     AccessibilityObject* accTable = core(table);
     if (accTable->isAccessibilityRenderObject()) {
         Node* node = accTable->node();
         if (node && isHTMLTableElement(node)) {
-            HTMLTableCaptionElement* caption = toHTMLTableElement(node)->caption();
+            HTMLTableCaptionElement* caption = downcast<HTMLTableElement>(*node).caption();
             if (caption)
                 return AccessibilityObject::firstAccessibleObjectFromNode(caption->renderer()->element())->wrapper();
         }
     }
-    return 0;
+    return nullptr;
 }
 
 static const gchar* webkitAccessibleTableGetColumnDescription(AtkTable* table, gint column)
index 34d0cb9..074535a 100644 (file)
@@ -171,7 +171,7 @@ static const gchar* webkitAccessibleGetDescription(AtkObject* object)
     returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
 
     AccessibilityObject* coreObject = core(object);
-    Node* node = 0;
+    Node* node = nullptr;
     if (coreObject->isAccessibilityRenderObject())
         node = coreObject->node();
     if (!node || !node->isHTMLElement() || coreObject->ariaRoleAttribute() != UnknownRole || coreObject->isImage())
@@ -179,7 +179,7 @@ static const gchar* webkitAccessibleGetDescription(AtkObject* object)
 
     // atk_table_get_summary returns an AtkObject. We have no summary object, so expose summary here.
     if (coreObject->roleValue() == TableRole) {
-        String summary = toHTMLTableElement(node)->summary();
+        const AtomicString& summary = downcast<HTMLTableElement>(*node).summary();
         if (!summary.isEmpty())
             return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, summary);
     }
index e1fdc3b..1c9b939 100644 (file)
@@ -67,11 +67,8 @@ int AccessibilityObject::accessibilityPasswordFieldLength()
     if (!renderObject || !renderObject->node() || !renderObject->node()->isHTMLElement())
         return false;
     
-    HTMLInputElement* inputElement = toHTMLInputElement(renderObject->node());
-    if (!inputElement)
-        return false;
-    
-    return inputElement->value().length();
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*renderObject->node());
+    return inputElement.value().length();
 }
 
 bool AccessibilityObject::accessibilityIgnoreAttachment() const
index b0fdf65..6fba199 100644 (file)
@@ -83,16 +83,16 @@ static EncodedJSValue namedItemGetter(ExecState* exec, JSObject* slotBase, Encod
     ASSERT(document->isHTMLDocument());
 
     AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-    if (!atomicPropertyName || !toHTMLDocument(document)->hasWindowNamedItem(*atomicPropertyName))
+    if (!atomicPropertyName || !downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName))
         return JSValue::encode(jsUndefined());
 
-    if (UNLIKELY(toHTMLDocument(document)->windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
+    if (UNLIKELY(downcast<HTMLDocument>(*document).windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
         RefPtr<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
         ASSERT(collection->length() > 1);
         return JSValue::encode(toJS(exec, thisObj->globalObject(), WTF::getPtr(collection)));
     }
 
-    return JSValue::encode(toJS(exec, thisObj->globalObject(), toHTMLDocument(document)->windowNamedItem(*atomicPropertyName)));
+    return JSValue::encode(toJS(exec, thisObj->globalObject(), downcast<HTMLDocument>(*document).windowNamedItem(*atomicPropertyName)));
 }
 
 #if ENABLE(USER_MESSAGE_HANDLERS)
@@ -246,7 +246,7 @@ bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, Property
     Document* document = thisObject->impl().frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(*atomicPropertyName)) {
+        if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
             slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
             return true;
         }
@@ -323,7 +323,7 @@ bool JSDOMWindow::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, u
     Document* document = thisObject->impl().frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(*atomicPropertyName)) {
+        if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
             slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
             return true;
         }
index 1ad3c62..7953c6c 100644 (file)
@@ -73,8 +73,8 @@ EncodedJSValue JSHTMLDocument::nameGetter(ExecState* exec, JSObject* slotBase, E
     }
 
     Element* element = document.documentNamedItem(*atomicPropertyName);
-    if (UNLIKELY(element->hasTagName(iframeTag))) {
-        if (Frame* frame = toHTMLIFrameElement(element)->contentFrame())
+    if (UNLIKELY(isHTMLIFrameElement(element))) {
+        if (Frame* frame = downcast<HTMLIFrameElement>(*element).contentFrame())
             return JSValue::encode(toJS(exec, frame));
     }
 
index f251eb2..77eaff5 100644 (file)
@@ -51,7 +51,7 @@ EncodedJSValue JSHTMLFrameSetElement::nameGetter(ExecState* exec, JSObject* slot
 {
     HTMLElement& element = jsCast<JSHTMLElement*>(slotBase)->impl();
     Node* frameElement = element.children()->namedItem(propertyNameToAtomicString(propertyName));
-    if (Document* document = toHTMLFrameElement(frameElement)->contentDocument()) {
+    if (Document* document = downcast<HTMLFrameElement>(frameElement)->contentDocument()) {
         if (JSDOMWindowShell* window = toJSDOMWindowShell(document->frame(), currentWorld(exec)))
             return JSValue::encode(window);
     }
index 63a2dc6..2e1d126 100644 (file)
@@ -106,12 +106,12 @@ static inline bool isReachableFromDOM(JSNode* jsNode, Node* node, SlotVisitor& v
             // the element is destroyed, its load event will not fire.
             // FIXME: The DOM should manage this issue without the help of JavaScript wrappers.
             if (isHTMLImageElement(element)) {
-                if (toHTMLImageElement(element).hasPendingActivity())
+                if (downcast<HTMLImageElement>(element).hasPendingActivity())
                     return true;
             }
 #if ENABLE(VIDEO)
             else if (isHTMLAudioElement(element)) {
-                if (!toHTMLAudioElement(element).paused())
+                if (!downcast<HTMLAudioElement>(element).paused())
                     return true;
             }
 #endif
index f82ed27..626321c 100644 (file)
@@ -655,7 +655,7 @@ bool SelectorChecker::checkOne(const CheckingContextWithStatus& context) const
                     if (RenderStyle* style = context.elementStyle ? context.elementStyle : element->renderStyle())
                         style->setUnique();
                 }
-                return toHTMLTextFormControlElement(*element).isPlaceholderVisible();
+                return downcast<HTMLTextFormControlElement>(*element).isPlaceholderVisible();
             }
             return false;
 #endif
index 1db19ec..7fa4dc5 100644 (file)
@@ -86,7 +86,7 @@ ALWAYS_INLINE bool isChecked(Element* element)
     const HTMLInputElement* inputElement = element->toInputElement();
     if (inputElement && inputElement->shouldAppearChecked() && !inputElement->shouldAppearIndeterminate())
         return true;
-    if (isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected())
+    if (isHTMLOptionElement(element) && downcast<HTMLOptionElement>(*element).selected())
         return true;
     return false;
 }
index 215c79c..429c84a 100644 (file)
@@ -1338,7 +1338,7 @@ void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& par
     if (e && e->isFormControlElement() && style.fontSize() >= 11) {
         // Don't apply intrinsic margins to image buttons. The designer knows how big the images are,
         // so we have to treat all image buttons as though they were explicitly sized.
-        if (!isHTMLInputElement(e) || !toHTMLInputElement(e)->isImageButton())
+        if (!isHTMLInputElement(e) || !downcast<HTMLInputElement>(*e).isImageButton())
             addIntrinsicMargins(style);
     }
 
index 103e641..0720037 100644 (file)
@@ -68,7 +68,7 @@ StyleSheet* StyleSheetList::item(unsigned index)
 HTMLStyleElement* StyleSheetList::getNamedItem(const String& name) const
 {
     if (!m_document)
-        return 0;
+        return nullptr;
 
     // IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
     // (this is consistent with all the other collections)
@@ -77,8 +77,8 @@ HTMLStyleElement* StyleSheetList::getNamedItem(const String& name) const
     // But unicity of stylesheet ids is good practice anyway ;)
     Element* element = m_document->getElementById(name);
     if (element && isHTMLStyleElement(element))
-        return toHTMLStyleElement(element);
-    return 0;
+        return downcast<HTMLStyleElement>(element);
+    return nullptr;
 }
 
 } // namespace WebCore
index c0f180c..2037bb7 100644 (file)
@@ -2785,7 +2785,7 @@ static bool makeContextStyleUniqueIfNecessaryAndTestIsPlaceholderShown(Element*
     if (isHTMLTextFormControlElement(*element)) {
         if (checkingContext->resolvingMode == SelectorChecker::Mode::ResolvingStyle)
             checkingContext->elementStyle->setUnique();
-        return toHTMLTextFormControlElement(*element).isPlaceholderVisible();
+        return downcast<HTMLTextFormControlElement>(*element).isPlaceholderVisible();
     }
     return false;
 }
@@ -2797,14 +2797,14 @@ static bool makeElementStyleUniqueIfNecessaryAndTestIsPlaceholderShown(Element*
             if (RenderStyle* style = element->renderStyle())
                 style->setUnique();
         }
-        return toHTMLTextFormControlElement(*element).isPlaceholderVisible();
+        return downcast<HTMLTextFormControlElement>(*element).isPlaceholderVisible();
     }
     return false;
 }
 
 static bool isPlaceholderShown(Element* element)
 {
-    return isHTMLTextFormControlElement(*element) && toHTMLTextFormControlElement(*element).isPlaceholderVisible();
+    return isHTMLTextFormControlElement(*element) && downcast<HTMLTextFormControlElement>(*element).isPlaceholderVisible();
 }
 
 void SelectorCodeGenerator::generateElementHasPlaceholderShown(Assembler::JumpList& failureCases, const SelectorFragment& fragment)
index f7e841a..7c488c0 100644 (file)
@@ -42,7 +42,7 @@ public:
         , m_isHTMLScriptElement(isHTMLScriptElement(element))
     {
         if (m_isHTMLScriptElement)
-            m_document->pushCurrentScript(toHTMLScriptElement(element));
+            m_document->pushCurrentScript(downcast<HTMLScriptElement>(element));
     }
 
     ~CurrentScriptIncrementer()
index 0e2dc6c..aa01ae1 100644 (file)
@@ -253,11 +253,9 @@ void DataTransfer::setDragImage(Element* element, int x, int y)
     if (!canSetDragImage())
         return;
 
-    CachedImage* image;
+    CachedImage* image = nullptr;
     if (element && isHTMLImageElement(element) && !element->inDocument())
-        image = toHTMLImageElement(element)->cachedImage();
-    else
-        image = 0;
+        image = downcast<HTMLImageElement>(*element).cachedImage();
 
     m_dragLocation = IntPoint(x, y);
 
@@ -270,7 +268,7 @@ void DataTransfer::setDragImage(Element* element, int x, int y)
         m_dragImageLoader->startLoading(m_dragImage);
     }
 
-    m_dragImageElement = image ? 0 : element;
+    m_dragImageElement = image ? nullptr : element;
 
     updateDragImage();
 }
index 24ecfd4..82a877c 100644 (file)
@@ -1551,8 +1551,8 @@ void Document::setTitle(const String& title)
     // The DOM API has no method of specifying direction, so assume LTR.
     updateTitle(StringWithDirection(title, LTR));
 
-    if (m_titleElement && isHTMLTitleElement(m_titleElement.get()))
-        toHTMLTitleElement(m_titleElement.get())->setText(title);
+    if (m_titleElement && isHTMLTitleElement(*m_titleElement))
+        downcast<HTMLTitleElement>(*m_titleElement).setText(title);
 }
 
 void Document::setTitleElement(const StringWithDirection& title, Element* titleElement)
@@ -2881,7 +2881,7 @@ void Document::processHttpEquiv(const String& equiv, const String& content)
         // FIXME: make setCookie work on XML documents too; e.g. in case of <html:meta .....>
         if (isHTMLDocument()) {
             // Exception (for sandboxed documents) ignored.
-            toHTMLDocument(this)->setCookie(content, IGNORE_EXCEPTION);
+            downcast<HTMLDocument>(*this).setCookie(content, IGNORE_EXCEPTION);
         }
         break;
 
@@ -4652,14 +4652,14 @@ const Vector<IconURL>& Document::iconURLs(int iconTypesMask)
         Node* child = children->item(i);
         if (!child->hasTagName(linkTag))
             continue;
-        HTMLLinkElement* linkElement = toHTMLLinkElement(child);
-        if (!(linkElement->iconType() & iconTypesMask))
+        HTMLLinkElement& linkElement = downcast<HTMLLinkElement>(*child);
+        if (!(linkElement.iconType() & iconTypesMask))
             continue;
-        if (linkElement->href().isEmpty())
+        if (linkElement.href().isEmpty())
             continue;
 
         // Put it at the front to ensure that icons seen later take precedence as required by the spec.
-        IconURL newURL(linkElement->href(), linkElement->iconSizes(), linkElement->type(), linkElement->iconType());
+        IconURL newURL(linkElement.href(), linkElement.iconSizes(), linkElement.type(), linkElement.iconType());
         m_iconURLs.append(newURL);
     }
 
index 08b6c1e..77eec3b 100644 (file)
@@ -53,18 +53,18 @@ inline bool keyMatchesName(const AtomicStringImpl& key, const Element& element)
 
 inline bool keyMatchesMapName(const AtomicStringImpl& key, const Element& element)
 {
-    return isHTMLMapElement(element) && toHTMLMapElement(element).getName().impl() == &key;
+    return isHTMLMapElement(element) && downcast<HTMLMapElement>(element).getName().impl() == &key;
 }
 
 inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, const Element& element)
 {
-    return isHTMLMapElement(element) && toHTMLMapElement(element).getName().lower().impl() == &key;
+    return isHTMLMapElement(element) && downcast<HTMLMapElement>(element).getName().lower().impl() == &key;
 }
 
 inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, const Element& element)
 {
     // FIXME: HTML5 specification says we should match both image and object elements.
-    return isHTMLImageElement(element) && toHTMLImageElement(element).matchesLowercasedUsemap(key);
+    return isHTMLImageElement(element) && downcast<HTMLImageElement>(element).matchesLowercasedUsemap(key);
 }
 
 inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, const Element& element)
@@ -168,22 +168,22 @@ Element* DocumentOrderedMap::getElementByName(const AtomicStringImpl& key, const
 
 HTMLMapElement* DocumentOrderedMap::getElementByMapName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return toHTMLMapElement(get<keyMatchesMapName>(key, scope));
+    return downcast<HTMLMapElement>(get<keyMatchesMapName>(key, scope));
 }
 
 HTMLMapElement* DocumentOrderedMap::getElementByLowercasedMapName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return toHTMLMapElement(get<keyMatchesLowercasedMapName>(key, scope));
+    return downcast<HTMLMapElement>(get<keyMatchesLowercasedMapName>(key, scope));
 }
 
 HTMLImageElement* DocumentOrderedMap::getElementByLowercasedUsemap(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return toHTMLImageElement(get<keyMatchesLowercasedUsemap>(key, scope));
+    return downcast<HTMLImageElement>(get<keyMatchesLowercasedUsemap>(key, scope));
 }
 
 HTMLLabelElement* DocumentOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return toHTMLLabelElement(get<keyMatchesLabelForAttribute>(key, scope));
+    return downcast<HTMLLabelElement>(get<keyMatchesLabelForAttribute>(key, scope));
 }
 
 Element* DocumentOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
index d7a9d66..61d99a7 100644 (file)
@@ -286,7 +286,7 @@ void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleS
             bool enabledViaScript = false;
             if (isHTMLLinkElement(element)) {
                 // <LINK> element
-                HTMLLinkElement& linkElement = toHTMLLinkElement(element);
+                HTMLLinkElement& linkElement = downcast<HTMLLinkElement>(element);
                 if (linkElement.isDisabled())
                     continue;
                 enabledViaScript = linkElement.isEnabledViaScript();
@@ -308,9 +308,9 @@ void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleS
             if (isSVGStyleElement(element))
                 sheet = downcast<SVGStyleElement>(element).sheet();
             else if (isHTMLLinkElement(element))
-                sheet = toHTMLLinkElement(element).sheet();
+                sheet = downcast<HTMLLinkElement>(element).sheet();
             else
-                sheet = toHTMLStyleElement(element).sheet();
+                sheet = downcast<HTMLStyleElement>(element).sheet();
             // Check to see if this sheet belongs to a styleset
             // (thus making it PREFERRED or ALTERNATE rather than
             // PERSISTENT).
index c96cfad..826475b 100644 (file)
@@ -1338,7 +1338,7 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode& insertio
         elementRareData()->clearClassListValueForQuirksMode();
 
     TreeScope* newScope = &insertionPoint.treeScope();
-    HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope().isHTMLDocument() ? toHTMLDocument(&newScope->documentScope()) : nullptr;
+    HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope().isHTMLDocument() ? downcast<HTMLDocument>(&newScope->documentScope()) : nullptr;
     if (newScope != &treeScope())
         newScope = nullptr;
 
@@ -1381,7 +1381,7 @@ void Element::removedFrom(ContainerNode& insertionPoint)
 
     if (insertionPoint.isInTreeScope()) {
         TreeScope* oldScope = &insertionPoint.treeScope();
-        HTMLDocument* oldDocument = inDocument() && oldScope->documentScope().isHTMLDocument() ? toHTMLDocument(&oldScope->documentScope()) : nullptr;
+        HTMLDocument* oldDocument = inDocument() && oldScope->documentScope().isHTMLDocument() ? downcast<HTMLDocument>(&oldScope->documentScope()) : nullptr;
         if (oldScope != &treeScope() || !isInTreeScope())
             oldScope = nullptr;
 
@@ -2590,7 +2590,7 @@ inline void Element::updateName(const AtomicString& oldName, const AtomicString&
         return;
     if (!document().isHTMLDocument())
         return;
-    updateNameForDocument(toHTMLDocument(document()), oldName, newName);
+    updateNameForDocument(downcast<HTMLDocument>(document()), oldName, newName);
 }
 
 void Element::updateNameForTreeScope(TreeScope& scope, const AtomicString& oldName, const AtomicString& newName)
@@ -2638,7 +2638,7 @@ inline void Element::updateId(const AtomicString& oldId, const AtomicString& new
         return;
     if (!document().isHTMLDocument())
         return;
-    updateIdForDocument(toHTMLDocument(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
+    updateIdForDocument(downcast<HTMLDocument>(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
 }
 
 void Element::updateIdForTreeScope(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId)
@@ -2685,9 +2685,9 @@ void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeV
         return;
 
     if (!oldForAttributeValue.isEmpty())
-        scope.removeLabel(*oldForAttributeValue.impl(), *toHTMLLabelElement(this));
+        scope.removeLabel(*oldForAttributeValue.impl(), downcast<HTMLLabelElement>(*this));
     if (!newForAttributeValue.isEmpty())
-        scope.addLabel(*newForAttributeValue.impl(), *toHTMLLabelElement(this));
+        scope.addLabel(*newForAttributeValue.impl(), downcast<HTMLLabelElement>(*this));
 }
 
 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
@@ -2741,11 +2741,10 @@ PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType ty
     if (HTMLCollection* collection = cachedHTMLCollection(type))
         return collection;
 
-    RefPtr<HTMLCollection> collection;
     if (type == TableRows) {
-        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLTableRowsCollection>(toHTMLTableElement(*this), type);
+        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLTableRowsCollection>(downcast<HTMLTableElement>(*this), type);
     } else if (type == SelectOptions) {
-        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLOptionsCollection>(toHTMLSelectElement(*this), type);
+        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLOptionsCollection>(downcast<HTMLSelectElement>(*this), type);
     } else if (type == FormControls) {
         ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag));
         return ensureRareData().ensureNodeLists().addCachedCollection<HTMLFormControlsCollection>(*this, type);
index aa1a00a..4094f33 100644 (file)
@@ -357,17 +357,17 @@ bool EventDispatcher::dispatchEvent(Node* origin, PassRefPtr<Event> prpEvent)
 
     InputElementClickState clickHandlingState;
     if (isHTMLInputElement(node.get()))
-        toHTMLInputElement(*node).willDispatchEvent(*event, clickHandlingState);
+        downcast<HTMLInputElement>(*node).willDispatchEvent(*event, clickHandlingState);
 
     if (!event->propagationStopped() && !eventPath.isEmpty())
         dispatchEventInDOM(*event, eventPath, windowEventContext);
 
     event->setTarget(&eventTargetRespectingTargetRules(*node));
-    event->setCurrentTarget(0);
+    event->setCurrentTarget(nullptr);
     event->setEventPhase(0);
 
     if (clickHandlingState.stateful)
-        toHTMLInputElement(*node).didDispatchClickEvent(*event, clickHandlingState);
+        downcast<HTMLInputElement>(*node).didDispatchClickEvent(*event, clickHandlingState);
 
     // Call default event handlers. While the DOM does have a concept of preventing
     // default handling, the detail of which handlers are called is an internal
index 6096c58..e3056c3 100644 (file)
@@ -383,7 +383,7 @@ String ScriptElement::scriptContent() const
 ScriptElement* toScriptElementIfPossible(Element* element)
 {
     if (isHTMLScriptElement(element))
-        return toHTMLScriptElement(element);
+        return downcast<HTMLScriptElement>(element);
 
     if (isSVGScriptElement(element))
         return downcast<SVGScriptElement>(element);
index 75b9689..4c22d00 100644 (file)
@@ -70,7 +70,7 @@ void VisitedLinkState::invalidateStyleForAllLinks()
 inline static LinkHash linkHashForElement(Document& document, Element& element)
 {
     if (isHTMLAnchorElement(element))
-        return toHTMLAnchorElement(element).visitedLinkHash();
+        return downcast<HTMLAnchorElement>(element).visitedLinkHash();
     if (const AtomicString* attribute = linkAttribute(element))
         return WebCore::visitedLinkHash(document.baseURL(), *attribute);
     return 0;
@@ -101,7 +101,7 @@ EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element& element)
 
     LinkHash hash;
     if (isHTMLAnchorElement(element))
-        hash = toHTMLAnchorElement(element).visitedLinkHash();
+        hash = downcast<HTMLAnchorElement>(element).visitedLinkHash();
     else
         hash = WebCore::visitedLinkHash(element.document().baseURL(), *attribute);
 
index 45b8db5..4ddedc1 100755 (executable)
@@ -666,14 +666,6 @@ struct ElementTypeCastTraits<const $class, ArgType> {
 };
 END
         ;
-        if ($parameters{namespace} eq "HTML") {
-            print F <<END
-// FIXME: Remove these macros once the code has been ported to using
-// downcast<*Element>().
-#define to$class(x) WebCore::downcast<WebCore::$class>(x)
-END
-            ;
-        }
         print F "\n";
     }
 }
index b2e5d3a..e90fdfa 100644 (file)
@@ -209,7 +209,7 @@ VisibleSelection Editor::selectionForCommand(Event* event)
     // If the target is a text control, and the current selection is outside of its shadow tree,
     // then use the saved selection for that text control.
     HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextFormControl(selection.start());
-    HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlElement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target()->toNode()) : nullptr;
+    HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlElement(*event->target()->toNode()) ? downcast<HTMLTextFormControlElement>(event->target()->toNode()) : nullptr;
     if (textFromControlOfTarget && (selection.start().isNull() || textFromControlOfTarget != textFormControlOfSelectionStart)) {
         if (RefPtr<Range> range = textFromControlOfTarget->selection())
             return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirectional());
@@ -321,18 +321,18 @@ bool Editor::canCut() const
 static HTMLImageElement* imageElementFromImageDocument(Document& document)
 {
     if (!document.isImageDocument())
-        return 0;
+        return nullptr;
     
     HTMLElement* body = document.body();
     if (!body)
-        return 0;
+        return nullptr;
     
     Node* node = body->firstChild();
     if (!node)
-        return 0;
+        return nullptr;
     if (!isHTMLImageElement(node))
-        return 0;
-    return toHTMLImageElement(node);
+        return nullptr;
+    return downcast<HTMLImageElement>(node);
 }
 
 bool Editor::canCopy() const
@@ -3533,18 +3533,18 @@ static Node* findFirstMarkable(Node* node)
 {
     while (node) {
         if (!node->renderer())
-            return 0;
+            return nullptr;
         if (node->renderer()->isTextOrLineBreak())
             return node;
         if (isHTMLTextFormControlElement(*node))
-            node = toHTMLTextFormControlElement(node)->visiblePositionForIndex(1).deepEquivalent().deprecatedNode();
+            node = downcast<HTMLTextFormControlElement>(*node).visiblePositionForIndex(1).deepEquivalent().deprecatedNode();
         else if (node->firstChild())
             node = node->firstChild();
         else
             node = node->nextSibling();
     }
 
-    return 0;
+    return nullptr;
 }
 
 bool Editor::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const
index 0e3f3fe..8db72cf 100644 (file)
@@ -1670,16 +1670,16 @@ void FrameSelection::selectAll()
     Document* document = m_frame->document();
 
     Element* focusedElement = document->focusedElement();
-    if (focusedElement && focusedElement->hasTagName(selectTag)) {
-        HTMLSelectElement* selectElement = toHTMLSelectElement(document->focusedElement());
-        if (selectElement->canSelectAll()) {
-            selectElement->selectAll();
+    if (focusedElement && isHTMLSelectElement(focusedElement)) {
+        HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*focusedElement);
+        if (selectElement.canSelectAll()) {
+            selectElement.selectAll();
             return;
         }
     }
 
-    RefPtr<Node> root = 0;
-    Node* selectStartTarget = 0;
+    RefPtr<Node> root;
+    Node* selectStartTarget = nullptr;
     if (m_selection.isContentEditable()) {
         root = highestEditableRoot(m_selection.start());
         if (Node* shadowRoot = m_selection.nonBoundaryShadowTreeRootNode())
@@ -1689,7 +1689,7 @@ void FrameSelection::selectAll()
     } else {
         if (m_selection.isNone() && focusedElement) {
             if (focusedElement->isTextFormControl()) {
-                toHTMLTextFormControlElement(focusedElement)->select();
+                downcast<HTMLTextFormControlElement>(*focusedElement).select();
                 return;
             }
             root = focusedElement->nonBoundaryShadowTreeRootNode();
@@ -2024,7 +2024,7 @@ static HTMLFormElement* scanForForm(Element* start)
     for (auto it = descendants.from(*start), end = descendants.end(); it != end; ++it) {
         HTMLElement& element = *it;
         if (isHTMLFormElement(&element))
-            return toHTMLFormElement(&element);
+            return downcast<HTMLFormElement>(&element);
         if (isHTMLFormControlElement(element))
             return toHTMLFormControlElement(element).form();
         if (isHTMLFrameElementBase(element)) {
index 215aa7a..18e5894 100644 (file)
@@ -160,7 +160,7 @@ void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, Node* nod
 
     if (!(targetNode.document().isHTMLDocument() && elementCannotHaveEndTag(targetNode))) {
 #if ENABLE(TEMPLATE_ELEMENT)
-        Node* current = targetNode.hasTagName(templateTag) ? toHTMLTemplateElement(targetNode).content()->firstChild() : targetNode.firstChild();
+        Node* current = targetNode.hasTagName(templateTag) ? downcast<HTMLTemplateElement>(targetNode).content()->firstChild() : targetNode.firstChild();
 #else
         Node* current = targetNode.firstChild();
 #endif
index 0b02462..bd536f0 100644 (file)
@@ -1273,7 +1273,7 @@ bool ReplaceSelectionCommand::shouldPerformSmartReplace() const
         return false;
 
     Element* textControl = enclosingTextFormControl(positionAtStartOfInsertedContent().deepEquivalent());
-    if (textControl && isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->isPasswordField())
+    if (textControl && isHTMLInputElement(textControl) && downcast<HTMLInputElement>(*textControl).isPasswordField())
         return false; // Disable smart replace for password fields.
 
     return true;
index 40225f0..ba8325f 100644 (file)
@@ -658,13 +658,13 @@ Element* VisibleSelection::rootEditableElement() const
 
 Node* VisibleSelection::nonBoundaryShadowTreeRootNode() const
 {
-    return start().deprecatedNode() ? start().deprecatedNode()->nonBoundaryShadowTreeRootNode() : 0;
+    return start().deprecatedNode() ? start().deprecatedNode()->nonBoundaryShadowTreeRootNode() : nullptr;
 }
 
 bool VisibleSelection::isInPasswordField() const
 {
     HTMLTextFormControlElement* textControl = enclosingTextFormControl(start());
-    return textControl && isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->isPasswordField();
+    return textControl && isHTMLInputElement(textControl) && downcast<HTMLInputElement>(*textControl).isPasswordField();
 }
 
 #ifndef NDEBUG
index 8bb7496..24ba5e1 100644 (file)
@@ -2035,7 +2035,7 @@ BOOL HTMLConverter::_processElement(Element& element, NSInteger depth)
             listStyleType = "decimal";
         list = adoptNS([[PlatformNSTextList alloc] initWithMarkerFormat:String("{" + listStyleType + "}") options:0]);
         if (isHTMLOListElement(element)) {
-            NSInteger startingItemNumber = toHTMLOListElement(element).start();;
+            NSInteger startingItemNumber = downcast<HTMLOListElement>(element).start();
             [list setStartingItemNumber:startingItemNumber];
         }
         [_textLists addObject:list.get()];
@@ -2043,7 +2043,7 @@ BOOL HTMLConverter::_processElement(Element& element, NSInteger depth)
         _addQuoteForElement(element, YES, _quoteLevel++);
     } else if (element.hasTagName(inputTag)) {
         if (isHTMLInputElement(element)) {
-            HTMLInputElement& inputElement = toHTMLInputElement(element);
+            HTMLInputElement& inputElement = downcast<HTMLInputElement>(element);
             if (inputElement.type() == "text") {
                 NSString *value = inputElement.value();
                 if (value && [value length] > 0)
@@ -2052,7 +2052,7 @@ BOOL HTMLConverter::_processElement(Element& element, NSInteger depth)
         }
     } else if (element.hasTagName(textareaTag)) {
         if (isHTMLTextAreaElement(element)) {
-            HTMLTextAreaElement& textAreaElement = toHTMLTextAreaElement(element);
+            HTMLTextAreaElement& textAreaElement = downcast<HTMLTextAreaElement>(element);
             NSString *value = textAreaElement.value();
             if (value && [value length] > 0)
                 _addValue(value, element);
index 0aacad4..e0eb369 100644 (file)
@@ -181,12 +181,12 @@ void Editor::setTextAlignmentForChangedBaseWritingDirection(WritingDirection dir
         return;
 
     Element* focusedElement = m_frame.document()->focusedElement();
-    if (focusedElement && (focusedElement->hasTagName(textareaTag) || (focusedElement->hasTagName(inputTag) &&
-        (toHTMLInputElement(focusedElement)->isTextField() ||
-         toHTMLInputElement(focusedElement)->isSearchField())))) {
+    if (focusedElement && (isHTMLTextAreaElement(focusedElement) || (isHTMLInputElement(focusedElement)
+        && (downcast<HTMLInputElement>(*focusedElement).isTextField()
+            || downcast<HTMLInputElement>(*focusedElement).isSearchField())))) {
         if (direction == NaturalWritingDirection)
             return;
-        toHTMLElement(focusedElement)->setAttribute(alignAttr, newValue);
+        toHTMLElement(*focusedElement).setAttribute(alignAttr, newValue);
         m_frame.document()->updateStyleIfNeeded();
         return;
     }
index 2e2d9bd..98e8a92 100644 (file)
@@ -228,7 +228,7 @@ Vector<Color> ColorInputType::suggestions() const
     HTMLDataListElement* dataList = element().dataList();
     if (dataList) {
         RefPtr<HTMLCollection> options = dataList->options();
-        for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement(options->item(i)); i++) {
+        for (unsigned i = 0; HTMLOptionElement* option = downcast<HTMLOptionElement>(options->item(i)); ++i) {
             if (!element().isValidValue(option->value()))
                 continue;
             Color color(option->value());
index 35e32d3..d6f14d7 100644 (file)
@@ -303,7 +303,7 @@ bool FTPDirectoryDocumentParser::loadDocumentTemplate()
     else if (!isHTMLTableElement(tableElement.get()))
         LOG_ERROR("Element of id \"ftpDirectoryTable\" is not a table element");
     else 
-        m_tableElement = toHTMLTableElement(tableElement.get());
+        m_tableElement = downcast<HTMLTableElement>(tableElement.get());
 
     // Bail if we found the table element
     if (m_tableElement)
@@ -311,7 +311,7 @@ bool FTPDirectoryDocumentParser::loadDocumentTemplate()
 
     // Otherwise create one manually
     tableElement = document()->createElement(tableTag, false);
-    m_tableElement = toHTMLTableElement(tableElement.get());
+    m_tableElement = downcast<HTMLTableElement>(tableElement.get());
     m_tableElement->setAttribute(HTMLNames::idAttr, "ftpDirectoryTable");
 
     // If we didn't find the table element, lets try to append our own to the body
@@ -336,7 +336,7 @@ void FTPDirectoryDocumentParser::createBasicDocument()
     document()->appendChild(bodyElement, IGNORE_EXCEPTION);
 
     RefPtr<Element> tableElement = document()->createElement(tableTag, false);
-    m_tableElement = toHTMLTableElement(tableElement.get());
+    m_tableElement = downcast<HTMLTableElement>(tableElement.get());
     m_tableElement->setAttribute(HTMLNames::idAttr, "ftpDirectoryTable");
     m_tableElement->setAttribute(HTMLNames::styleAttr, "width:100%");
 
index 44ee050..9df4059 100644 (file)
@@ -96,10 +96,10 @@ HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el
         // the first element in the document to have an ID that equal to
         // the value of form attribute, so we put the result of
         // treeScope().getElementById() over the given element.
-        HTMLFormElement* newForm = 0;
+        HTMLFormElement* newForm = nullptr;
         Element* newFormCandidate = element->treeScope().getElementById(formId);
         if (newFormCandidate && isHTMLFormElement(newFormCandidate))
-            newForm = toHTMLFormElement(newFormCandidate);
+            newForm = downcast<HTMLFormElement>(newFormCandidate);
         return newForm;
     }
 
index f160a2b..34afeb9 100644 (file)
@@ -161,16 +161,16 @@ static void appendServerMapMousePosition(StringBuilder& url, Event* event)
     if (!isHTMLImageElement(target))
         return;
 
-    HTMLImageElement* imageElement = toHTMLImageElement(target);
-    if (!imageElement || !imageElement->isServerMap())
+    HTMLImageElement& imageElement = downcast<HTMLImageElement>(*target);
+    if (!imageElement.isServerMap())
         return;
 
-    if (!imageElement->renderer() || !imageElement->renderer()->isRenderImage())
+    if (!imageElement.renderer() || !imageElement.renderer()->isRenderImage())
         return;
-    RenderImage* renderer = toRenderImage(imageElement->renderer());
+    RenderImage& renderer = toRenderImage(*imageElement.renderer());
 
     // FIXME: This should probably pass true for useTransforms.
-    FloatPoint absolutePosition = renderer->absoluteToLocal(FloatPoint(toMouseEvent(event)->pageX(), toMouseEvent(event)->pageY()));
+    FloatPoint absolutePosition = renderer.absoluteToLocal(FloatPoint(toMouseEvent(event)->pageX(), toMouseEvent(event)->pageY()));
     int x = absolutePosition.x();
     int y = absolutePosition.y();
     url.append('?');
index b37956c..dd84bdc 100644 (file)
@@ -183,9 +183,9 @@ HTMLImageElement* HTMLAreaElement::imageElement() const
 {
     Node* mapElement = parentNode();
     if (!mapElement || !isHTMLMapElement(mapElement))
-        return 0;
+        return nullptr;
     
-    return toHTMLMapElement(mapElement)->imageElement();
+    return downcast<HTMLMapElement>(*mapElement).imageElement();
 }
 
 bool HTMLAreaElement::isKeyboardFocusable(KeyboardEvent*) const
index 3327abb..91bb281 100644 (file)
@@ -191,10 +191,10 @@ inline bool isMatchingElement(const HTMLCollection& htmlCollection, Element& ele
     case SelectOptions:
         return element.hasTagName(optionTag);
     case SelectedOptions:
-        return element.hasTagName(optionTag) && toHTMLOptionElement(element).selected();
+        return isHTMLOptionElement(element) && downcast<HTMLOptionElement>(element).selected();
     case DataListOptions:
-        if (element.hasTagName(optionTag)) {
-            HTMLOptionElement& option = toHTMLOptionElement(element);
+        if (isHTMLOptionElement(element)) {
+            HTMLOptionElement& option = downcast<HTMLOptionElement>(element);
             if (!option.isDisabledFormControl() && !option.value().isEmpty())
                 return true;
         }
@@ -202,7 +202,7 @@ inline bool isMatchingElement(const HTMLCollection& htmlCollection, Element& ele
     case MapAreas:
         return element.hasTagName(areaTag);
     case DocApplets:
-        return element.hasTagName(appletTag) || (element.hasTagName(objectTag) && toHTMLObjectElement(element).containsJavaApplet());
+        return element.hasTagName(appletTag) || (isHTMLObjectElement(element) && downcast<HTMLObjectElement>(element).containsJavaApplet());
     case DocEmbeds:
         return element.hasTagName(embedTag);
     case DocLinks:
index f469ec5..92e51f6 100644 (file)
@@ -379,7 +379,7 @@ bool HTMLElement::matchesReadWritePseudoClass() const
 
     const Document& document = this->document();
     if (document.isHTMLDocument()) {
-        const HTMLDocument& htmlDocument = toHTMLDocument(document);
+        const HTMLDocument& htmlDocument = downcast<HTMLDocument>(document);
         return htmlDocument.inDesignMode();
     }
     return false;
@@ -427,8 +427,8 @@ void HTMLElement::setInnerHTML(const String& html, ExceptionCode& ec)
     if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, ec)) {
         ContainerNode* container = this;
 #if ENABLE(TEMPLATE_ELEMENT)
-        if (hasTagName(templateTag))
-            container = toHTMLTemplateElement(this)->content();
+        if (isHTMLTemplateElement(*this))
+            container = downcast<HTMLTemplateElement>(*this).content();
 #endif
         replaceChildrenWithFragment(*container, fragment.release(), ec);
     }
@@ -920,11 +920,11 @@ TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) con
 TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const
 {
     if (isHTMLTextFormControlElement(*this)) {
-        HTMLTextFormControlElement* textElement = toHTMLTextFormControlElement(const_cast<HTMLElement*>(this));
+        HTMLTextFormControlElement& textElement = downcast<HTMLTextFormControlElement>(const_cast<HTMLElement&>(*this));
         bool hasStrongDirectionality;
-        UCharDirection textDirection = textElement->value().defaultWritingDirection(&hasStrongDirectionality);
+        UCharDirection textDirection = textElement.value().defaultWritingDirection(&hasStrongDirectionality);
         if (strongDirectionalityTextNode)
-            *strongDirectionalityTextNode = hasStrongDirectionality ? textElement : nullptr;
+            *strongDirectionalityTextNode = hasStrongDirectionality ? &textElement : nullptr;
         return (textDirection == U_LEFT_TO_RIGHT) ? LTR : RTL;
     }
 
index ca2564a..3642b85 100644 (file)
@@ -188,12 +188,12 @@ bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style)
 
     // If my parent is an <object> and is not set to use fallback content, I
     // should be ignored and not get a renderer.
-    ContainerNode* p = parentNode();
-    if (p && p->hasTagName(objectTag)) {
-        if (!p->renderer())
+    ContainerNode* parent = parentNode();
+    if (parent && isHTMLObjectElement(parent)) {
+        if (!parent->renderer())
             return false;
-        if (!toHTMLObjectElement(p)->useFallbackContent()) {
-            ASSERT(!p->renderer()->isEmbeddedObject());
+        if (!downcast<HTMLObjectElement>(*parent).useFallbackContent()) {
+            ASSERT(!parent->renderer()->isEmbeddedObject());
             return false;
         }
     }
index db50b27..04619b5 100644 (file)
@@ -166,7 +166,7 @@ void HTMLFieldSetElement::refreshElementsIfNeeded() const
 
     for (auto& element : descendantsOfType<Element>(const_cast<HTMLFieldSetElement&>(*this))) {
         if (element.hasTagName(objectTag))
-            m_associatedElements.append(&toHTMLObjectElement(element));
+            m_associatedElements.append(&downcast<HTMLObjectElement>(element));
         else if (element.isFormControlElement())
             m_associatedElements.append(&toHTMLFormControlElement(element));
     }
index a31f926..12acfb3 100644 (file)
@@ -104,7 +104,7 @@ bool HTMLFormControlElement::computeIsDisabledByFieldsetAncestor() const
     Element* previousAncestor = nullptr;
     for (Element* ancestor = parentElement(); ancestor; ancestor = ancestor->parentElement()) {
         if (isHTMLFieldSetElement(ancestor) && ancestor->fastHasAttribute(disabledAttr)) {
-            HTMLFieldSetElement& fieldSetAncestor = toHTMLFieldSetElement(*ancestor);
+            HTMLFieldSetElement& fieldSetAncestor = downcast<HTMLFieldSetElement>(*ancestor);
             bool isInFirstLegend = previousAncestor && isHTMLLegendElement(previousAncestor) && previousAncestor == fieldSetAncestor.legend();
             return !isInFirstLegend;
         }
@@ -193,7 +193,7 @@ static bool shouldAutofocus(HTMLFormControlElement* element)
     // FIXME: Should this set of hasTagName checks be replaced by a
     // virtual member function?
     if (isHTMLInputElement(element))
-        return !toHTMLInputElement(element)->isInputTypeHidden();
+        return !downcast<HTMLInputElement>(*element).isInputTypeHidden();
     if (element->hasTagName(selectTag))
         return true;
     if (element->hasTagName(keygenTag))
index 77ad742..68c1dee 100644 (file)
@@ -56,14 +56,14 @@ const Vector<FormAssociatedElement*>& HTMLFormControlsCollection::formControlEle
 {
     ASSERT(isHTMLFormElement(ownerNode()) || ownerNode().hasTagName(fieldsetTag));
     if (isHTMLFormElement(ownerNode()))
-        return toHTMLFormElement(ownerNode()).associatedElements();
-    return toHTMLFieldSetElement(ownerNode()).associatedElements();
+        return downcast<HTMLFormElement>(ownerNode()).associatedElements();
+    return downcast<HTMLFieldSetElement>(ownerNode()).associatedElements();
 }
 
 const Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements() const
 {
     ASSERT(isHTMLFormElement(ownerNode()));
-    return toHTMLFormElement(ownerNode()).imageElements();
+    return downcast<HTMLFormElement>(ownerNode()).imageElements();
 }
 
 static unsigned findFormAssociatedElement(const Vector<FormAssociatedElement*>& elements, const Element& element)
index c88eac9..4589b47 100644 (file)
@@ -318,7 +318,7 @@ void HTMLFormElement::getTextFieldValues(StringPairVector& fieldNamesAndValues)
         HTMLElement& element = control.asHTMLElement();
         if (!isHTMLInputElement(element))
             continue;
-        HTMLInputElement& input = toHTMLInputElement(element);
+        HTMLInputElement& input = downcast<HTMLInputElement>(element);
         if (!input.isTextField())
             continue;
         fieldNamesAndValues.append(std::make_pair(input.name().string(), input.value()));
@@ -745,7 +745,7 @@ void HTMLFormElement::assertItemCanBeInPastNamesMap(FormNamedItem* item) const
     }
 
     ASSERT_WITH_SECURITY_IMPLICATION(element.hasTagName(imgTag));
-    ASSERT_WITH_SECURITY_IMPLICATION(m_imageElements.find(&toHTMLImageElement(element)) != notFound);
+    ASSERT_WITH_SECURITY_IMPLICATION(m_imageElements.find(&downcast<HTMLImageElement>(element)) != notFound);
 }
 #else
 inline void HTMLFormElement::assertItemCanBeInPastNamesMap(FormNamedItem*) const
index 738a919..28cf302 100644 (file)
@@ -183,13 +183,13 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
         if (name == nameAttr) {
             bool willHaveName = !value.isNull();
             if (hasName() != willHaveName && inDocument() && document().isHTMLDocument()) {
-                HTMLDocument* document = toHTMLDocument(&this->document());
+                HTMLDocument& document = downcast<HTMLDocument>(this->document());
                 const AtomicString& id = getIdAttribute();
                 if (!id.isEmpty() && id != getNameAttribute()) {
                     if (willHaveName)
-                        document->addDocumentNamedItem(*id.impl(), *this);
+                        document.addDocumentNamedItem(*id.impl(), *this);
                     else
-                        document->removeDocumentNamedItem(*id.impl(), *this);
+                        document.removeDocumentNamedItem(*id.impl(), *this);
                 }
             }
         }
index 1879dbc..fb34c8c 100644 (file)
@@ -86,7 +86,7 @@ void HTMLImageLoader::notifyFinished(CachedResource*)
     }
 
     if (loadError && isHTMLObjectElement(element()))
-        toHTMLObjectElement(element()).renderFallbackContent();
+        downcast<HTMLObjectElement>(element()).renderFallbackContent();
 }
 
 }
index a8ebaa9..e2d55e3 100644 (file)
@@ -1515,18 +1515,16 @@ HTMLElement* HTMLInputElement::list() const
 HTMLDataListElement* HTMLInputElement::dataList() const
 {
     if (!m_hasNonEmptyList)
-        return 0;
+        return nullptr;
 
     if (!m_inputType->shouldRespectListAttribute())
-        return 0;
+        return nullptr;
 
     Element* element = treeScope().getElementById(fastGetAttribute(listAttr));
-    if (!element)
-        return 0;
-    if (!element->hasTagName(datalistTag))
-        return 0;
+    if (!element || !isHTMLDataListElement(element))
+        return nullptr;
 
-    return toHTMLDataListElement(element);
+    return downcast<HTMLDataListElement>(element);
 }
 
 void HTMLInputElement::resetListAttributeTargetObserver()
@@ -1855,7 +1853,7 @@ bool HTMLInputElement::setupDateTimeChooserParameters(DateTimeChooserParameters&
 #if ENABLE(DATALIST_ELEMENT)
     if (HTMLDataListElement* dataList = this->dataList()) {
         RefPtr<HTMLCollection> options = dataList->options();
-        for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement(options->item(i)); ++i) {
+        for (unsigned i = 0; HTMLOptionElement* option = downcast<HTMLOptionElement>(options->item(i)); ++i) {
             if (!isValidValue(option->value()))
                 continue;
             parameters.suggestionValues.append(sanitizeValue(option->value()));
index 714bdb2..1f5d67f 100644 (file)
@@ -129,7 +129,7 @@ bool HTMLKeygenElement::shouldSaveAndRestoreFormControlState() const
 HTMLSelectElement* HTMLKeygenElement::shadowSelect() const
 {
     ShadowRoot* root = userAgentShadowRoot();
-    return root ? toHTMLSelectElement(root->firstChild()) : 0;
+    return root ? downcast<HTMLSelectElement>(root->firstChild()) : nullptr;
 }
 
 } // namespace
index 5973bc2..2fb4d25 100644 (file)
@@ -79,10 +79,10 @@ HTMLFormElement* HTMLLegendElement::virtualForm() const
     // its parent, then the form attribute must return the same value as the
     // form attribute on that fieldset element. Otherwise, it must return null.
     ContainerNode* fieldset = parentNode();
-    if (!fieldset || !fieldset->hasTagName(fieldsetTag))
-        return 0;
+    if (!fieldset || !isHTMLFieldSetElement(fieldset))
+        return nullptr;
 
-    return toHTMLFieldSetElement(fieldset)->form();
+    return downcast<HTMLFieldSetElement>(*fieldset).form();
 }
     
 } // namespace
index 3d21c52..d368bad 100644 (file)
@@ -3876,7 +3876,7 @@ URL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* ke
     }
 
     URL mediaURL;
-    HTMLSourceElement* source = 0;
+    HTMLSourceElement* source = nullptr;
     String type;
     String system;
     bool lookingForStartNode = m_nextChildNodeToConsider;
@@ -3897,7 +3897,7 @@ URL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* ke
         if (node.parentNode() != this)
             continue;
 
-        source = toHTMLSourceElement(&node);
+        source = downcast<HTMLSourceElement>(&node);
 
         // If candidate does not have a src attribute, or if its src attribute's value is the empty string ... jump down to the failed step below
         mediaURL = source->getNonEmptyURLAttribute(srcAttr);
@@ -4883,9 +4883,9 @@ void HTMLMediaElement::enterFullscreen()
     if (hasMediaControls())
         mediaControls()->enteredFullscreen();
     if (document().page() && isHTMLVideoElement(this)) {
-        HTMLVideoElement* asVideo = toHTMLVideoElement(this);
+        HTMLVideoElement& asVideo = downcast<HTMLVideoElement>(*this);
         if (document().page()->chrome().client().supportsVideoFullscreen()) {
-            document().page()->chrome().client().enterVideoFullscreenForVideoElement(asVideo);
+            document().page()->chrome().client().enterVideoFullscreenForVideoElement(&asVideo);
             scheduleEvent(eventNames().webkitbeginfullscreenEvent);
         }
     }
index 6601746..fef41fd 100644 (file)
@@ -66,14 +66,14 @@ bool WindowNameCollection::elementMatches(const Element& element, const AtomicSt
 bool DocumentNameCollection::elementMatchesIfIdAttributeMatch(const Element& element)
 {
     // FIXME: we need to fix HTMLImageElement to update the hash map for us when name attribute has been removed.
-    return element.hasTagName(appletTag) || (element.hasTagName(objectTag) && toHTMLObjectElement(element).isDocNamedItem())
+    return element.hasTagName(appletTag) || (isHTMLObjectElement(element) && downcast<HTMLObjectElement>(element).isDocNamedItem())
         || (isHTMLImageElement(element) && element.hasName());
 }
 
 bool DocumentNameCollection::elementMatchesIfNameAttributeMatch(const Element& element)
 {
     return isHTMLFormElement(element) || element.hasTagName(embedTag) || element.hasTagName(iframeTag)
-        || element.hasTagName(appletTag) || (element.hasTagName(objectTag) && toHTMLObjectElement(element).isDocNamedItem())
+        || element.hasTagName(appletTag) || (isHTMLObjectElement(element) && downcast<HTMLObjectElement>(element).isDocNamedItem())
         || isHTMLImageElement(element);
 }
 
@@ -85,8 +85,8 @@ bool DocumentNameCollection::elementMatches(const Element& element, const Atomic
         return element.getNameAttribute().impl() == name;
     if (element.hasTagName(appletTag))
         return element.getNameAttribute().impl() == name || element.getIdAttribute().impl() == name;
-    if (element.hasTagName(objectTag))
-        return (element.getNameAttribute().impl() == name || element.getIdAttribute().impl() == name) && toHTMLObjectElement(element).isDocNamedItem();
+    if (isHTMLObjectElement(element))
+        return (element.getNameAttribute().impl() == name || element.getIdAttribute().impl() == name) && downcast<HTMLObjectElement>(element).isDocNamedItem();
     if (isHTMLImageElement(element))
         return element.getNameAttribute().impl() == name || (element.getIdAttribute().impl() == name && element.hasName());
     return false;
index 9177eaa..c05a405 100644 (file)
@@ -436,22 +436,22 @@ void HTMLObjectElement::updateDocNamedItem()
         child = child->nextSibling();
     }
     if (isNamedItem != wasNamedItem && inDocument() && document().isHTMLDocument()) {
-        HTMLDocument* document = toHTMLDocument(&this->document());
+        HTMLDocument& document = downcast<HTMLDocument>(this->document());
 
         const AtomicString& id = getIdAttribute();
         if (!id.isEmpty()) {
             if (isNamedItem)
-                document->addDocumentNamedItem(*id.impl(), *this);
+                document.addDocumentNamedItem(*id.impl(), *this);
             else
-                document->removeDocumentNamedItem(*id.impl(), *this);
+                document.removeDocumentNamedItem(*id.impl(), *this);
         }
 
         const AtomicString& name = getNameAttribute();
         if (!name.isEmpty() && id != name) {
             if (isNamedItem)
-                document->addDocumentNamedItem(*name.impl(), *this);
+                document.addDocumentNamedItem(*name.impl(), *this);
             else
-                document->removeDocumentNamedItem(*name.impl(), *this);
+                document.removeDocumentNamedItem(*name.impl(), *this);
         }
     }
     m_docNamedItem = isNamedItem;
@@ -466,7 +466,7 @@ bool HTMLObjectElement::containsJavaApplet() const
         if (child.hasTagName(paramTag) && equalIgnoringCase(child.getNameAttribute(), "type")
             && MIMETypeRegistry::isJavaAppletMIMEType(child.getAttribute(valueAttr).string()))
             return true;
-        if (child.hasTagName(objectTag) && toHTMLObjectElement(child).containsJavaApplet())
+        if (child.hasTagName(objectTag) && downcast<HTMLObjectElement>(child).containsJavaApplet())
             return true;
         if (child.hasTagName(appletTag))
             return true;
index c0ab70d..95d6abc 100644 (file)
@@ -86,10 +86,10 @@ void HTMLOptGroupElement::parseAttribute(const QualifiedName& name, const Atomic
 void HTMLOptGroupElement::recalcSelectOptions()
 {
     ContainerNode* select = parentNode();
-    while (select && !select->hasTagName(selectTag))
+    while (select && !isHTMLSelectElement(select))
         select = select->parentNode();
     if (select)
-        toHTMLSelectElement(select)->setRecalcListItems();
+        downcast<HTMLSelectElement>(*select).setRecalcListItems();
 }
 
 String HTMLOptGroupElement::groupLabelText() const
@@ -107,13 +107,13 @@ String HTMLOptGroupElement::groupLabelText() const
 HTMLSelectElement* HTMLOptGroupElement::ownerSelectElement() const
 {
     ContainerNode* select = parentNode();
-    while (select && !select->hasTagName(selectTag))
+    while (select && !isHTMLSelectElement(select))
         select = select->parentNode();
     
     if (!select)
-       return 0;
+        return nullptr;
     
-    return toHTMLSelectElement(select);
+    return downcast<HTMLSelectElement>(select);
 }
 
 void HTMLOptGroupElement::accessKeyAction(bool)
index a6b1470..1ab7a04 100644 (file)
@@ -257,23 +257,23 @@ void HTMLOptionElement::childrenChanged(const ChildChange& change)
 HTMLDataListElement* HTMLOptionElement::ownerDataListElement() const
 {
     for (ContainerNode* parent = parentNode(); parent ; parent = parent->parentNode()) {
-        if (parent->hasTagName(datalistTag))
-            return toHTMLDataListElement(parent);
+        if (isHTMLDataListElement(parent))
+            return downcast<HTMLDataListElement>(parent);
     }
-    return 0;
+    return nullptr;
 }
 #endif
 
 HTMLSelectElement* HTMLOptionElement::ownerSelectElement() const
 {
     ContainerNode* select = parentNode();
-    while (select && !select->hasTagName(selectTag))
+    while (select && !isHTMLSelectElement(select))
         select = select->parentNode();
 
     if (!select)
-        return 0;
+        return nullptr;
 
-    return toHTMLSelectElement(select);
+    return downcast<HTMLSelectElement>(select);
 }
 
 String HTMLOptionElement::label() const
index f1df4c4..f29212d 100644 (file)
@@ -58,9 +58,9 @@ void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index
     ec = 0;
 
     if (index == -1 || unsigned(index) >= length())
-        selectElement().add(newOption, 0, ec);
+        selectElement().add(newOption, nullptr, ec);
     else
-        selectElement().add(newOption, toHTMLOptionElement(item(index)), ec);
+        selectElement().add(newOption, downcast<HTMLOptionElement>(item(index)), ec);
 
     ASSERT(!ec);
 }
index 1c5e688..9c79256 100644 (file)
@@ -37,8 +37,8 @@ class HTMLOptionsCollection final : public HTMLCollection {
 public:
     static PassRef<HTMLOptionsCollection> create(HTMLSelectElement&, CollectionType);
 
-    HTMLSelectElement& selectElement() { return toHTMLSelectElement(ownerNode()); }
-    const HTMLSelectElement& selectElement() const { return toHTMLSelectElement(ownerNode()); }
+    HTMLSelectElement& selectElement() { return downcast<HTMLSelectElement>(ownerNode()); }
+    const HTMLSelectElement& selectElement() const { return downcast<HTMLSelectElement>(ownerNode()); }
 
     void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
     void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
index 496ed5b..98f5c85 100644 (file)
@@ -417,11 +417,11 @@ static void addPlugInsFromNodeListMatchingPlugInOrigin(HTMLPlugInImageElementLis
         if (node->isPluginElement()) {
             HTMLPlugInElement* plugInElement = toHTMLPlugInElement(node);
             if (plugInElement->isPlugInImageElement()) {
-                HTMLPlugInImageElement* plugInImageElement = toHTMLPlugInImageElement(node);
-                const URL& loadedURL = plugInImageElement->loadedUrl();
-                String otherMimeType = plugInImageElement->loadedMimeType();
+                HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(*node);
+                const URL& loadedURL = plugInImageElement.loadedUrl();
+                String otherMimeType = plugInImageElement.loadedMimeType();
                 if (plugInOrigin == loadedURL.host() && mimeType == otherMimeType)
-                    plugInList.append(plugInImageElement);
+                    plugInList.append(&plugInImageElement);
             }
         }
     }
index 4142759..482b82f 100644 (file)
@@ -149,8 +149,8 @@ bool HTMLSelectElement::hasPlaceholderLabelOption() const
     ASSERT(listIndex >= 0);
     if (listIndex < 0)
         return false;
-    HTMLOptionElement* option = toHTMLOptionElement(listItems()[listIndex]);
-    return !listIndex && option->value().isEmpty();
+    HTMLOptionElement& option = downcast<HTMLOptionElement>(*listItems()[listIndex]);
+    return !listIndex && option.value().isEmpty();
 }
 
 String HTMLSelectElement::validationMessage() const
@@ -251,7 +251,7 @@ String HTMLSelectElement::value() const
 {
     for (auto* item : listItems()) {
         if (isHTMLOptionElement(*item)) {
-            HTMLOptionElement& option = toHTMLOptionElement(*item);
+            HTMLOptionElement& option = downcast<HTMLOptionElement>(*item);
             if (option.selected())
                 return option.value();
         }
@@ -271,7 +271,7 @@ void HTMLSelectElement::setValue(const String &value)
     unsigned optionIndex = 0;
     for (auto* item : listItems()) {
         if (isHTMLOptionElement(*item)) {
-            if (toHTMLOptionElement(*item).value() == value) {
+            if (downcast<HTMLOptionElement>(*item).value() == value) {
                 setSelectedIndex(optionIndex);
                 return;
             }
@@ -605,7 +605,7 @@ void HTMLSelectElement::saveLastSelection()
     const Vector<HTMLElement*>& items = listItems();
     for (unsigned i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
-        m_lastOnChangeSelection.append(isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected());
+        m_lastOnChangeSelection.append(isHTMLOptionElement(element) && downcast<HTMLOptionElement>(element)->selected());
     }
 }
 
@@ -620,7 +620,7 @@ void HTMLSelectElement::setActiveSelectionAnchorIndex(int index)
     const Vector<HTMLElement*>& items = listItems();
     for (unsigned i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
-        m_cachedStateForActiveSelection.append(isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected());
+        m_cachedStateForActiveSelection.append(isHTMLOptionElement(element) && downcast<HTMLOptionElement>(element)->selected());
     }
 }
 
@@ -644,15 +644,15 @@ void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions)
     const Vector<HTMLElement*>& items = listItems();
     for (unsigned i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
-        if (!isHTMLOptionElement(element) || toHTMLOptionElement(element)->isDisabledFormControl())
+        if (!isHTMLOptionElement(element) || downcast<HTMLOptionElement>(*element).isDisabledFormControl())
             continue;
 
         if (i >= start && i <= end)
-            toHTMLOptionElement(element)->setSelectedState(m_activeSelectionState);
+            downcast<HTMLOptionElement>(*element).setSelectedState(m_activeSelectionState);
         else if (deselectOtherOptions || i >= m_cachedStateForActiveSelection.size())
-            toHTMLOptionElement(element)->setSelectedState(false);
+            downcast<HTMLOptionElement>(*element).setSelectedState(false);
         else
-            toHTMLOptionElement(element)->setSelectedState(m_cachedStateForActiveSelection[i]);
+            downcast<HTMLOptionElement>(*element).setSelectedState(m_cachedStateForActiveSelection[i]);
     }
 
     scrollToSelection();
@@ -676,7 +676,7 @@ void HTMLSelectElement::listBoxOnChange()
     bool fireOnChange = false;
     for (unsigned i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
-        bool selected = isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected();
+        bool selected = isHTMLOptionElement(element) && downcast<HTMLOptionElement>(*element).selected();
         if (selected != m_lastOnChangeSelection[i])
             fireOnChange = true;
         m_lastOnChangeSelection[i] = selected;
@@ -802,15 +802,15 @@ void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const
             m_listItems.append(current);
 
             if (updateSelectedStates && !m_multiple) {
-                HTMLOptionElement* option = toHTMLOptionElement(current);
+                HTMLOptionElement& option = downcast<HTMLOptionElement>(*current);
                 if (!firstOption)
-                    firstOption = option;
-                if (option->selected()) {
+                    firstOption = &option;
+                if (option.selected()) {
                     if (foundSelected)
                         foundSelected->setSelectedState(false);
-                    foundSelected = option;
-                } else if (m_size <= 1 && !foundSelected && !option->isDisabledFormControl()) {
-                    foundSelected = option;
+                    foundSelected = &option;
+                } else if (m_size <= 1 && !foundSelected && !option.isDisabledFormControl()) {
+                    foundSelected = &option;
                     foundSelected->setSelectedState(true);
                 }
             }
@@ -841,7 +841,7 @@ int HTMLSelectElement::selectedIndex() const
     for (size_t i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
         if (isHTMLOptionElement(element)) {
-            if (toHTMLOptionElement(element)->selected())
+            if (downcast<HTMLOptionElement>(*element).selected())
                 return index;
             ++index;
         }
@@ -873,7 +873,7 @@ void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)
     const Vector<HTMLElement*>& items = listItems();
     int listIndex = optionToListIndex(optionIndex);
 
-    HTMLElement* element = 0;
+    HTMLElement* element = nullptr;
     if (listIndex >= 0) {
         element = items[listIndex];
         if (isHTMLOptionElement(element)) {
@@ -881,7 +881,7 @@ void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)
                 setActiveSelectionAnchorIndex(listIndex);
             if (m_activeSelectionEndIndex < 0 || shouldDeselect)
                 setActiveSelectionEndIndex(listIndex);
-            toHTMLOptionElement(element)->setSelectedState(true);
+            downcast<HTMLOptionElement>(*element).setSelectedState(true);
         }
     }
 
@@ -969,7 +969,7 @@ void HTMLSelectElement::deselectItemsWithoutValidation(HTMLElement* excludeEleme
     for (unsigned i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
         if (element != excludeElement && isHTMLOptionElement(element))
-            toHTMLOptionElement(element)->setSelectedState(false);
+            downcast<HTMLOptionElement>(*element).setSelectedState(false);
     }
 }
 
@@ -981,10 +981,10 @@ FormControlState HTMLSelectElement::saveFormControlState() const
     for (unsigned i = 0; i < length; ++i) {
         if (!isHTMLOptionElement(items[i]))
             continue;
-        HTMLOptionElement* option = toHTMLOptionElement(items[i]);
-        if (!option->selected())
+        HTMLOptionElement& option = downcast<HTMLOptionElement>(*items[i]);
+        if (!option.selected())
             continue;
-        state.append(option->value());
+        state.append(option.value());
         if (!multiple())
             break;
     }
@@ -998,7 +998,7 @@ size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list
     for (size_t i = listIndexStart; i < loopEndIndex; ++i) {
         if (!isHTMLOptionElement(items[i]))
             continue;
-        if (toHTMLOptionElement(items[i])->value() == value)
+        if (downcast<HTMLOptionElement>(*items[i]).value() == value)
             return i;
     }
     return notFound;
@@ -1016,13 +1016,13 @@ void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
     for (size_t i = 0; i < itemsSize; ++i) {
         if (!isHTMLOptionElement(items[i]))
             continue;
-        toHTMLOptionElement(items[i])->setSelectedState(false);
+        downcast<HTMLOptionElement>(*items[i]).setSelectedState(false);
     }
 
     if (!multiple()) {
         size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
         if (foundIndex != notFound)
-            toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+            downcast<HTMLOptionElement>(*items[foundIndex]).setSelectedState(true);
     } else {
         size_t startIndex = 0;
         for (size_t i = 0; i < state.valueSize(); ++i) {
@@ -1032,7 +1032,7 @@ void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
                 foundIndex = searchOptionsForValue(value, 0, startIndex);
             if (foundIndex == notFound)
                 continue;
-            toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+            downcast<HTMLOptionElement>(*items[foundIndex]).setSelectedState(true);
             startIndex = foundIndex + 1;
         }
     }
@@ -1061,8 +1061,8 @@ bool HTMLSelectElement::appendFormData(FormDataList& list, bool)
 
     for (unsigned i = 0; i < items.size(); ++i) {
         HTMLElement* element = items[i];
-        if (isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected() && !toHTMLOptionElement(element)->isDisabledFormControl()) {
-            list.appendData(name, toHTMLOptionElement(element)->value());
+        if (isHTMLOptionElement(element) && downcast<HTMLOptionElement>(*element).selected() && !downcast<HTMLOptionElement>(*element).isDisabledFormControl()) {
+            list.appendData(name, downcast<HTMLOptionElement>(*element).value());
             successful = true;
         }
     }
@@ -1075,8 +1075,8 @@ bool HTMLSelectElement::appendFormData(FormDataList& list, bool)
 
 void HTMLSelectElement::reset()
 {
-    HTMLOptionElement* firstOption = 0;
-    HTMLOptionElement* selectedOption = 0;
+    HTMLOptionElement* firstOption = nullptr;
+    HTMLOptionElement* selectedOption = nullptr;
 
     const Vector<HTMLElement*>& items = listItems();
     for (unsigned i = 0; i < items.size(); ++i) {
@@ -1084,16 +1084,17 @@ void HTMLSelectElement::reset()
         if (!isHTMLOptionElement(element))
             continue;
 
-        if (items[i]->fastHasAttribute(selectedAttr)) {
+        HTMLOptionElement& option = downcast<HTMLOptionElement>(*element);
+        if (option.fastHasAttribute(selectedAttr)) {
             if (selectedOption && !m_multiple)
                 selectedOption->setSelectedState(false);
-            toHTMLOptionElement(element)->setSelectedState(true);
-            selectedOption = toHTMLOptionElement(element);
+            option.setSelectedState(true);
+            selectedOption = &option;
         } else
-            toHTMLOptionElement(element)->setSelectedState(false);
+            option.setSelectedState(false);
 
         if (!firstOption)
-            firstOption = toHTMLOptionElement(element);
+            firstOption = &option;
     }
 
     if (!selectedOption && firstOption && !m_multiple && m_size <= 1)
@@ -1299,10 +1300,10 @@ void HTMLSelectElement::updateSelectedState(int listIndex, bool multi, bool shif
     if (isHTMLOptionElement(clickedElement)) {
         // Keep track of whether an active selection (like during drag
         // selection), should select or deselect.
-        if (toHTMLOptionElement(clickedElement)->selected() && multiSelect)
+        if (downcast<HTMLOptionElement>(*clickedElement).selected() && multiSelect)
             m_activeSelectionState = false;
         if (!m_activeSelectionState)
-            toHTMLOptionElement(clickedElement)->setSelectedState(false);
+            downcast<HTMLOptionElement>(*clickedElement).setSelectedState(false);
     }
 
     // If we're not in any special multiple selection mode, then deselect all
@@ -1317,8 +1318,8 @@ void HTMLSelectElement::updateSelectedState(int listIndex, bool multi, bool shif
         setActiveSelectionAnchorIndex(selectedIndex());
 
     // Set the selection state of the clicked option.
-    if (isHTMLOptionElement(clickedElement) && !toHTMLOptionElement(clickedElement)->isDisabledFormControl())
-        toHTMLOptionElement(clickedElement)->setSelectedState(true);
+    if (isHTMLOptionElement(clickedElement) && !downcast<HTMLOptionElement>(*clickedElement).isDisabledFormControl())
+        downcast<HTMLOptionElement>(*clickedElement).setSelectedState(true);
 
     // If there was no selectedIndex() for the previous initialization, or If
     // we're doing a single selection, or a multiple selection (using cmd or
@@ -1538,7 +1539,7 @@ int HTMLSelectElement::lastSelectedListIndex() const
     const Vector<HTMLElement*>& items = listItems();
     for (size_t i = items.size(); i;) {
         HTMLElement* element = items[--i];
-        if (isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected())
+        if (isHTMLOptionElement(element) && downcast<HTMLOptionElement>(*element).selected())
             return i;
     }
     return -1;
@@ -1559,9 +1560,9 @@ String HTMLSelectElement::optionAtIndex(int index) const
     const Vector<HTMLElement*>& items = listItems();
     
     HTMLElement* element = items[index];
-    if (!isHTMLOptionElement(element) || toHTMLOptionElement(element)->isDisabledFormControl())
+    if (!isHTMLOptionElement(element) || downcast<HTMLOptionElement>(*element).isDisabledFormControl())
         return String();
-    return toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
+    return downcast<HTMLOptionElement>(*element).textIndentedToRespectGroupLabel();
 }
 
 void HTMLSelectElement::typeAheadFind(KeyboardEvent* event)
@@ -1596,8 +1597,8 @@ void HTMLSelectElement::accessKeySetSelectedIndex(int index)
     if (listIndex >= 0) {
         HTMLElement* element = items[listIndex];
         if (isHTMLOptionElement(element)) {
-            if (toHTMLOptionElement(element)->selected())
-                toHTMLOptionElement(element)->setSelectedState(false);
+            if (downcast<HTMLOptionElement>(*element).selected())
+                downcast<HTMLOptionElement>(*element).setSelectedState(false);
             else
                 selectOption(index, DispatchChangeEvent | UserDriven);
         }
index f65cb00..b1e4eee 100644 (file)
@@ -87,8 +87,8 @@ HTMLDetailsElement* HTMLSummaryElement::detailsElement() const
 {
     Node* mayDetails = NodeRenderingTraversal::parent(this);
     if (!mayDetails || !mayDetails->hasTagName(detailsTag))
-        return 0;
-    return toHTMLDetailsElement(mayDetails);
+        return nullptr;
+    return downcast<HTMLDetailsElement>(mayDetails);
 }
 
 bool HTMLSummaryElement::isMainSummary() const
index 59feebe..ab701f3 100644 (file)
@@ -70,10 +70,10 @@ PassRefPtr<HTMLTableElement> HTMLTableElement::create(const QualifiedName& tagNa
 HTMLTableCaptionElement* HTMLTableElement::caption() const
 {
     for (Node* child = firstChild(); child; child = child->nextSibling()) {
-        if (child->hasTagName(captionTag))
-            return toHTMLTableCaptionElement(child);
+        if (isHTMLTableCaptionElement(child))
+            return downcast<HTMLTableCaptionElement>(child);
     }
-    return 0;
+    return nullptr;
 }
 
 void HTMLTableElement::setCaption(PassRefPtr<HTMLTableCaptionElement> newCaption, ExceptionCode& ec)
index fc7e85a..f510824 100644 (file)
@@ -88,7 +88,7 @@ HTMLTableElement* HTMLTablePartElement::findParentTable() const
     ContainerNode* parent = parentNode();
     while (parent && !isHTMLTableElement(parent))
         parent = parent->parentNode();
-    return toHTMLTableElement(parent);
+    return downcast<HTMLTableElement>(parent);
 }
 
 }
index 4c4d979..47ff33b 100644 (file)
@@ -70,7 +70,7 @@ int HTMLTableRowElement::rowIndex() const
 
     int rIndex = 0;
 
-    if (HTMLTableSectionElement* head = toHTMLTableElement(table)->tHead()) {
+    if (HTMLTableSectionElement* head = downcast<HTMLTableElement>(*table).tHead()) {
         for (Node *row = head->firstChild(); row; row = row->nextSibling()) {
             if (row == this)
                 return rIndex;
@@ -91,7 +91,7 @@ int HTMLTableRowElement::rowIndex() const
         }
     }
 
-    if (HTMLTableSectionElement* foot = toHTMLTableElement(table)->tFoot()) {
+    if (HTMLTableSectionElement* foot = downcast<HTMLTableElement>(*table).tFoot()) {
         for (Node *row = foot->firstChild(); row; row = row->nextSibling()) {
             if (row == this)
                 return rIndex;
index 7e5f664..04a9604 100644 (file)
@@ -98,7 +98,7 @@ HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table,
         child = ElementTraversal::nextSibling(previous->parentNode());
     for (; child; child = ElementTraversal::nextSibling(child)) {
         if (isHTMLTableRowElement(child))
-            return toHTMLTableRowElement(child);
+            return downcast<HTMLTableRowElement>(child);
         if (child->hasTagName(tbodyTag)) {
             if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
                 return row;
@@ -131,7 +131,7 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
 
     for (auto* child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
         if (isHTMLTableRowElement(child))
-            return toHTMLTableRowElement(child);
+            return downcast<HTMLTableRowElement>(child);
         if (child->hasTagName(tbodyTag)) {
             if (auto* row = childrenOfType<HTMLTableRowElement>(*child).last())
                 return row;
@@ -161,7 +161,7 @@ PassRef<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElemen
 
 Element* HTMLTableRowsCollection::customElementAfter(Element* previous) const
 {
-    return rowAfter(const_cast<HTMLTableElement*>(&tableElement()), toHTMLTableRowElement(previous));
+    return rowAfter(const_cast<HTMLTableElement*>(&tableElement()), downcast<HTMLTableRowElement>(previous));
 }
 
 }
index 6322c35..f7ca604 100644 (file)
@@ -40,8 +40,8 @@ class HTMLTableRowsCollection final : public HTMLCollection {
 public:
     static PassRef<HTMLTableRowsCollection> create(HTMLTableElement&, CollectionType);
 
-    HTMLTableElement& tableElement() { return toHTMLTableElement(ownerNode()); }
-    const HTMLTableElement& tableElement() const { return toHTMLTableElement(ownerNode()); }
+    HTMLTableElement& tableElement() { return downcast<HTMLTableElement>(ownerNode()); }
+    const HTMLTableElement& tableElement() const { return downcast<HTMLTableElement>(ownerNode()); }
 
     static HTMLTableRowElement* rowAfter(HTMLTableElement*, HTMLTableRowElement*);
     static HTMLTableRowElement* lastRow(HTMLTableElement*);
index 6989dfa..f108849 100644 (file)
@@ -75,7 +75,7 @@ PassRefPtr<Node> HTMLTemplateElement::cloneNode(bool deep)
 
     RefPtr<Node> clone = cloneElementWithChildren();
     if (m_content)
-        content()->cloneChildNodes(toHTMLTemplateElement(clone.get())->content());
+        content()->cloneChildNodes(downcast<HTMLTemplateElement>(clone.get())->content());
     return clone.release();
 }
 
index 8cb151b..35f8ead 100644 (file)
@@ -717,7 +717,7 @@ HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
     if (!container)
         return nullptr;
     Element* ancestor = container->shadowHost();
-    return ancestor && isHTMLTextFormControlElement(*ancestor) ? toHTMLTextFormControlElement(ancestor) : nullptr;
+    return ancestor && isHTMLTextFormControlElement(*ancestor) ? downcast<HTMLTextFormControlElement>(ancestor) : nullptr;
 }
 
 static const Element* parentHTMLElement(const Element* element)
index 8d63af3..5babb05 100644 (file)
@@ -211,14 +211,14 @@ void ImageDocument::createDocumentStructure()
 {
     RefPtr<Element> rootElement = Document::createElement(htmlTag, false);
     appendChild(rootElement);
-    toHTMLHtmlElement(rootElement.get())->insertedByParser();
+    downcast<HTMLHtmlElement>(*rootElement).insertedByParser();
 
     frame()->injectUserScripts(InjectAtDocumentStart);
 
     RefPtr<Element> body = Document::createElement(bodyTag, false);
     body->setAttribute(styleAttr, "margin: 0px");
     if (MIMETypeRegistry::isPDFMIMEType(document().loader()->responseMIMEType()))
-        toHTMLBodyElement(body.get())->setInlineStyleProperty(CSSPropertyBackgroundColor, "white", CSSPrimitiveValue::CSS_IDENT);
+        downcast<HTMLBodyElement>(*body).setInlineStyleProperty(CSSPropertyBackgroundColor, "white", CSSPrimitiveValue::CSS_IDENT);
     rootElement->appendChild(body);
     
     RefPtr<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this);
index 31f675e..8c29620 100644 (file)
@@ -45,7 +45,7 @@ LabelsNodeList::~LabelsNodeList()
     
 bool LabelsNodeList::elementMatches(Element& testNode) const
 {
-    return isHTMLLabelElement(testNode) && toHTMLLabelElement(testNode).control() == &ownerNode();
+    return isHTMLLabelElement(testNode) && downcast<HTMLLabelElement>(testNode).control() == &ownerNode();
 }
 
 } // namespace WebCore
index c9b773b..0c25b3b 100644 (file)
@@ -78,7 +78,7 @@ void MediaDocumentParser::createDocumentStructure()
     RefPtr<Element> rootElement = document()->createElement(htmlTag, false);
     document()->appendChild(rootElement, IGNORE_EXCEPTION);
     document()->setCSSTarget(rootElement.get());
-    toHTMLHtmlElement(rootElement.get())->insertedByParser();
+    downcast<HTMLHtmlElement>(*rootElement).insertedByParser();
 
     if (document()->frame())
         document()->frame()->injectUserScripts(InjectAtDocumentStart);
@@ -98,9 +98,9 @@ void MediaDocumentParser::createDocumentStructure()
 
     RefPtr<Element> mediaElement = document()->createElement(videoTag, false);
 
-    m_mediaElement = toHTMLVideoElement(mediaElement.get());
-    m_mediaElement->setAttribute(controlsAttr, "");
-    m_mediaElement->setAttribute(autoplayAttr, "");
+    m_mediaElement = downcast<HTMLVideoElement>(mediaElement.get());
+    m_mediaElement->setAttribute(controlsAttr, emptyAtom);
+    m_mediaElement->setAttribute(autoplayAttr, emptyAtom);
 
     m_mediaElement->setAttribute(nameAttr, "media");
 
@@ -112,7 +112,7 @@ void MediaDocumentParser::createDocumentStructure()
     m_mediaElement->setAttribute(styleAttr, elementStyle.toString());
 
     RefPtr<Element> sourceElement = document()->createElement(sourceTag, false);
-    HTMLSourceElement& source = toHTMLSourceElement(*sourceElement);
+    HTMLSourceElement& source = downcast<HTMLSourceElement>(*sourceElement);
     source.setSrc(document()->url());
 
     if (DocumentLoader* loader = document()->loader())
@@ -161,22 +161,22 @@ PassRefPtr<DocumentParser> MediaDocument::createParser()
 static inline HTMLVideoElement* descendentVideoElement(ContainerNode& node)
 {
     if (isHTMLVideoElement(node))
-        return toHTMLVideoElement(&node);
+        return downcast<HTMLVideoElement>(&node);
 
     RefPtr<NodeList> nodeList = node.getElementsByTagNameNS(videoTag.namespaceURI(), videoTag.localName());
    
-    if (nodeList.get()->length() > 0)
-        return toHTMLVideoElement(nodeList.get()->item(0));
+    if (nodeList->length() > 0)
+        return downcast<HTMLVideoElement>(nodeList->item(0));
 
-    return 0;
+    return nullptr;
 }
 
 static inline HTMLVideoElement* ancestorVideoElement(Node* node)
 {
-    while (node && !node->hasTagName(videoTag))
+    while (node && !isHTMLVideoElement(node))
         node = node->parentOrShadowHostNode();
 
-    return toHTMLVideoElement(node);
+    return downcast<HTMLVideoElement>(node);
 }
 
 void MediaDocument::defaultEventHandler(Event* event)
@@ -243,19 +243,19 @@ void MediaDocument::replaceMediaElementTimerFired(Timer<MediaDocument>&)
 
     if (HTMLVideoElement* videoElement = descendentVideoElement(*htmlBody)) {
         RefPtr<Element> element = Document::createElement(embedTag, false);
-        HTMLEmbedElement* embedElement = toHTMLEmbedElement(element.get());
+        HTMLEmbedElement& embedElement = downcast<HTMLEmbedElement>(*element);
 
-        embedElement->setAttribute(widthAttr, "100%");
-        embedElement->setAttribute(heightAttr, "100%");
-        embedElement->setAttribute(nameAttr, "plugin");
-        embedElement->setAttribute(srcAttr, url().string());
+        embedElement.setAttribute(widthAttr, "100%");
+        embedElement.setAttribute(heightAttr, "100%");
+        embedElement.setAttribute(nameAttr, "plugin");
+        embedElement.setAttribute(srcAttr, url().string());
 
         DocumentLoader* documentLoader = loader();
         ASSERT(documentLoader);
         if (documentLoader)
-            embedElement->setAttribute(typeAttr, documentLoader->writer().mimeType());
+            embedElement.setAttribute(typeAttr, documentLoader->writer().mimeType());
 
-        videoElement->parentNode()->replaceChild(embedElement, videoElement, IGNORE_EXCEPTION);
+        videoElement->parentNode()->replaceChild(&embedElement, videoElement, IGNORE_EXCEPTION);
     }
 }
 
index f716b27..8b0f52e 100644 (file)
@@ -69,7 +69,7 @@ void PluginDocumentParser::createDocumentStructure()
 {
     RefPtr<Element> rootElement = document()->createElement(htmlTag, false);
     document()->appendChild(rootElement, IGNORE_EXCEPTION);
-    toHTMLHtmlElement(rootElement.get())->insertedByParser();
+    downcast<HTMLHtmlElement>(*rootElement).insertedByParser();
 
     if (document()->frame())
         document()->frame()->injectUserScripts(InjectAtDocumentStart);
@@ -92,7 +92,7 @@ void PluginDocumentParser::createDocumentStructure()
         
     RefPtr<Element> embedElement = document()->createElement(embedTag, false);
         
-    m_embedElement = toHTMLEmbedElement(embedElement.get());
+    m_embedElement = downcast<HTMLEmbedElement>(embedElement.get());
     m_embedElement->setAttribute(widthAttr, "100%");
     m_embedElement->setAttribute(heightAttr, "100%");
     
index 239a9ce..6edc0e9 100644 (file)
@@ -86,7 +86,7 @@ void RadioInputType::handleKeydownEvent(KeyboardEvent* event)
         // Look for more radio buttons.
         if (!isHTMLInputElement(node))
             continue;
-        RefPtr<HTMLInputElement> inputElement = toHTMLInputElement(node);
+        RefPtr<HTMLInputElement> inputElement = downcast<HTMLInputElement>(node);
         if (inputElement->form() != element().form())
             break;
         if (inputElement->isRadioButton() && inputElement->name() == element().name() && inputElement->isFocusable()) {
@@ -123,8 +123,8 @@ bool RadioInputType::isKeyboardFocusable(KeyboardEvent* event) const
     // skip any other elements in the group.
     Element* currentFocusedNode = element().document().focusedElement();
     if (currentFocusedNode && isHTMLInputElement(currentFocusedNode)) {
-        HTMLInputElement* focusedInput = toHTMLInputElement(currentFocusedNode);
-        if (focusedInput->isRadioButton() && focusedInput->form() == element().form() && focusedInput->name() == element().name())
+        HTMLInputElement& focusedInput = downcast<HTMLInputElement>(*currentFocusedNode);
+        if (focusedInput.isRadioButton() && focusedInput.form() == element().form() && focusedInput.name() == element().name())
             return false;
     }
 
index b2044f6..702f21b 100644 (file)
@@ -87,9 +87,9 @@ bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl
 {
     ASSERT(testElement.hasTagName(objectTag) || testElement.isFormControlElement());
     if (isHTMLFormElement(ownerNode())) {
-        HTMLFormElement* formElement = 0;
+        HTMLFormElement* formElement = nullptr;
         if (testElement.hasTagName(objectTag))
-            formElement = toHTMLObjectElement(testElement).form();
+            formElement = downcast<HTMLObjectElement>(testElement).form();
         else
             formElement = toHTMLFormControlElement(testElement).form();
         if (!formElement || formElement != &ownerNode())
index 0023984..68f00f5 100644 (file)
@@ -372,8 +372,8 @@ void RangeInputType::updateTickMarkValues()
     m_tickMarkValues.reserveCapacity(options->length());
     for (unsigned i = 0; i < options->length(); ++i) {
         Node* node = options->item(i);
-        HTMLOptionElement* optionElement = toHTMLOptionElement(node);
-        String optionValue = optionElement->value();
+        HTMLOptionElement& optionElement = downcast<HTMLOptionElement>(*node);
+        String optionValue = optionElement.value();
         if (!element().isValidValue(optionValue))
             continue;
         m_tickMarkValues.append(parseToNumber(optionValue, Decimal::nan()));
index fe204ec..9390557 100644 (file)
@@ -85,8 +85,8 @@ static inline bool isAllWhitespace(const String& string)
 static inline void insert(HTMLConstructionSiteTask& task)
 {
 #if ENABLE(TEMPLATE_ELEMENT)
-    if (task.parent->hasTagName(templateTag))
-        task.parent = toHTMLTemplateElement(task.parent.get())->content();
+    if (isHTMLTemplateElement(*task.parent))
+        task.parent = downcast<HTMLTemplateElement>(*task.parent).content();
 #endif
 
     if (ContainerNode* parent = task.child->parentNode())
@@ -531,8 +531,8 @@ void HTMLConstructionSite::insertTextNode(const String& characters, WhitespaceMo
         findFosterSite(task);
 
 #if ENABLE(TEMPLATE_ELEMENT)
-    if (task.parent->hasTagName(templateTag))
-        task.parent = toHTMLTemplateElement(task.parent.get())->content();
+    if (isHTMLTemplateElement(*task.parent))
+        task.parent = downcast<HTMLTemplateElement>(*task.parent).content();
 #endif
 
     // Strings composed entirely of whitespace are likely to be repeated.
@@ -618,8 +618,8 @@ PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token,
 inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode()
 {
 #if ENABLE(TEMPLATE_ELEMENT)
-    if (currentNode()->hasTagName(templateTag))
-        return toHTMLTemplateElement(currentElement())->content()->document();
+    if (isHTMLTemplateElement(currentNode()))
+        return downcast<HTMLTemplateElement>(*currentElement()).content()->document();
 #endif
     return currentNode()->document();
 }
index 31f5492..b9368df 100644 (file)
@@ -297,7 +297,7 @@ HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser& parser, DocumentFragment& f
 #endif
 
         resetInsertionModeAppropriately();
-        m_tree.setForm(!contextElement || isHTMLFormElement(contextElement) ? toHTMLFormElement(contextElement) : HTMLFormElement::findClosestFormAncestor(*contextElement));
+        m_tree.setForm(!contextElement || isHTMLFormElement(contextElement) ? downcast<HTMLFormElement>(contextElement) : HTMLFormElement::findClosestFormAncestor(*contextElement));
     }
 }
 
index a26ff4d..5e3abd2 100644 (file)
@@ -57,7 +57,7 @@ RenderPtr<RenderElement> DetailsMarkerControl::createElementRenderer(PassRef<Ren
 
 bool DetailsMarkerControl::rendererIsNeeded(const RenderStyle& style)
 {
-    return toHTMLSummaryElement(shadowHost())->isMainSummary() && HTMLDivElement::rendererIsNeeded(style);
+    return downcast<HTMLSummaryElement>(shadowHost())->isMainSummary() && HTMLDivElement::rendererIsNeeded(style);
 }
 
 }
index a92b872..d42d5a4 100644 (file)
@@ -1111,7 +1111,7 @@ void MediaControlTextTrackContainerElement::updateDisplay()
         return;
 
     // 2. Let video be the media element or other playback mechanism.
-    HTMLVideoElement* video = toHTMLVideoElement(mediaElement);
+    HTMLVideoElement& video = downcast<HTMLVideoElement>(*mediaElement);
 
     // 3. Let output be an empty list of absolutely positioned CSS block boxes.
     Vector<RefPtr<HTMLDivElement>> output;
@@ -1135,7 +1135,7 @@ void MediaControlTextTrackContainerElement::updateDisplay()
     // 7. Let cues be an empty list of text track cues.
     // 8. For each track track in tracks, append to cues all the cues from
     // track's list of cues that have their text track cue active flag set.
-    CueList activeCues = video->currentlyActiveCues();
+    CueList activeCues = video.currentlyActiveCues();
 
     // 9. If reset is false, then, for each text track cue cue in cues: if cue's
     // text track cue display state has a set of CSS boxes, then add those boxes
index a576334..6ec4e55 100644 (file)
@@ -51,7 +51,7 @@ MeterShadowElement::MeterShadowElement(Document& document)
 
 HTMLMeterElement* MeterShadowElement::meterElement() const
 {
-    return toHTMLMeterElement(shadowHost());
+    return downcast<HTMLMeterElement>(shadowHost());
 }
 
 bool MeterShadowElement::rendererIsNeeded(const RenderStyle& style)
index dcd228b..90417f1 100644 (file)
@@ -46,7 +46,7 @@ ProgressShadowElement::ProgressShadowElement(Document& document)
 
 HTMLProgressElement* ProgressShadowElement::progressElement() const
 {
-    return toHTMLProgressElement(shadowHost());
+    return downcast<HTMLProgressElement>(shadowHost());
 }
 
 bool ProgressShadowElement::rendererIsNeeded(const RenderStyle& style)
index 20628c7..192f8e0 100644 (file)
@@ -141,7 +141,7 @@ PassRefPtr<SearchFieldResultsButtonElement> SearchFieldResultsButtonElement::cre
 void SearchFieldResultsButtonElement::defaultEventHandler(Event* event)
 {
     // On mousedown, bring up a menu, if needed
-    HTMLInputElement* input = toHTMLInputElement(shadowHost());
+    HTMLInputElement* input = downcast<HTMLInputElement>(shadowHost());
     if (input && event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
         input->focus();
         input->select();
@@ -192,7 +192,7 @@ void SearchFieldCancelButtonElement::willDetachRenderers()
 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
 {
     // If the element is visible, on mouseup, clear the value, and set selection
-    RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost()));
+    RefPtr<HTMLInputElement> input(downcast<HTMLInputElement>(shadowHost()));
     if (!input || input->isDisabledOrReadOnly()) {
         if (!event->defaultHandled())
             HTMLDivElement::defaultEventHandler(event);
@@ -232,7 +232,7 @@ void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
 #if !PLATFORM(IOS)
 bool SearchFieldCancelButtonElement::willRespondToMouseClickEvents()
 {
-    const HTMLInputElement* input = toHTMLInputElement(shadowHost());
+    const HTMLInputElement* input = downcast<HTMLInputElement>(shadowHost());
     if (input && !input->isDisabledOrReadOnly())
         return true;
 
index fbe88d5..2c73db9 100644 (file)
@@ -975,7 +975,7 @@ InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* documen
 
     CSSStyleSheet* cssStyleSheet = nullptr;
     if (styleElement->isHTMLElement())
-        cssStyleSheet = toHTMLStyleElement(styleElement.get())->sheet();
+        cssStyleSheet = downcast<HTMLStyleElement>(*styleElement).sheet();
     else if (styleElement->isSVGElement())
         cssStyleSheet = downcast<SVGStyleElement>(*styleElement).sheet();
 
index d2df4a8..bba39f6 100644 (file)
@@ -1297,8 +1297,8 @@ PassRefPtr<Inspector::Protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode
         }
 
 #if ENABLE(TEMPLATE_ELEMENT)
-        if (element->hasTagName(HTMLNames::templateTag))
-            value->setTemplateContent(buildObjectForNode(toHTMLTemplateElement(element)->content(), 0, nodesMap));
+        if (isHTMLTemplateElement(element))
+            value->setTemplateContent(buildObjectForNode(downcast<HTMLTemplateElement>(*element).content(), 0, nodesMap));
 #endif
 
     } else if (node->isDocumentNode()) {
index 5278f4a..e06b56d 100644 (file)
@@ -190,7 +190,7 @@ PassRefPtr<FormSubmission> FormSubmission::create(HTMLFormElement* form, const A
         if (!element.isDisabledFormControl())
             control.appendFormData(*domFormData, isMultiPartForm);
         if (isHTMLInputElement(element)) {
-            HTMLInputElement& input = toHTMLInputElement(element);
+            HTMLInputElement& input = downcast<HTMLInputElement>(element);
             if (input.isTextField()) {
                 formValues.append(std::pair<String, String>(input.name().string(), input.value()));
                 input.addSearchResult();
index cd716d9..cc4037a 100644 (file)
@@ -1033,9 +1033,9 @@ void FrameLoader::setOpener(Frame* opener)
 void FrameLoader::handleFallbackContent()
 {
     HTMLFrameOwnerElement* owner = m_frame.ownerElement();
-    if (!owner || !owner->hasTagName(objectTag))
+    if (!owner || !isHTMLObjectElement(owner))
         return;
-    toHTMLObjectElement(owner)->renderFallbackContent();
+    downcast<HTMLObjectElement>(*owner).renderFallbackContent();
 }
 
 void FrameLoader::provisionalLoadStarted()
index 9bad9b4..975497a 100644 (file)
@@ -406,14 +406,14 @@ void ImageLoader::dispatchPendingBeforeLoadEvent()
     }
     if (m_image) {
         m_image->removeClient(this);
-        m_image = 0;
+        m_image = nullptr;
     }
 
     loadEventSender().cancelEvent(*this);
     m_hasPendingLoadEvent = false;
     
     if (isHTMLObjectElement(element()))
-        toHTMLObjectElement(element()).renderFallbackContent();
+        downcast<HTMLObjectElement>(element()).renderFallbackContent();
 
     // Only consider updating the protection ref-count of the Element immediately before returning
     // from this function as doing so might result in the destruction of this ImageLoader.
index f9adf6c..97bdac1 100644 (file)
@@ -213,7 +213,7 @@ bool SubframeLoader::requestObject(HTMLPlugInImageElement& ownerElement, const S
     if (!url.isEmpty())
         completedURL = completeURL(url);
 
-    bool hasFallbackContent = isHTMLObjectElement(ownerElement) && toHTMLObjectElement(ownerElement).hasFallbackContent();
+    bool hasFallbackContent = isHTMLObjectElement(ownerElement) && downcast<HTMLObjectElement>(ownerElement).hasFallbackContent();
 
     bool useFallback;
     if (shouldUsePlugin(completedURL, mimeType, ownerElement.shouldPreferPlugInsForImages(), hasFallbackContent, useFallback)) {
index ea4079c..d32d369 100644 (file)
@@ -409,9 +409,9 @@ void Chrome::setToolTip(const HitTestResult& result)
         if (Element* element = result.innerNonSharedElement()) {
             // Get tooltip representing form action, if relevant
             if (isHTMLInputElement(element)) {
-                HTMLInputElement* input = toHTMLInputElement(element);
-                if (input->isSubmitButton()) {
-                    if (HTMLFormElement* form = input->form()) {
+                HTMLInputElement& input = downcast<HTMLInputElement>(*element);
+                if (input.isSubmitButton()) {
+                    if (HTMLFormElement* form = input.form()) {
                         toolTip = form->action();
                         if (form->renderer())
                             toolTipDirection = form->renderer()->style().direction();
@@ -442,7 +442,7 @@ void Chrome::setToolTip(const HitTestResult& result)
     if (toolTip.isEmpty()) {
         if (Element* element = result.innerNonSharedElement()) {
             if (isHTMLInputElement(element)) {
-                toolTip = toHTMLInputElement(element)->defaultToolTip();
+                toolTip = downcast<HTMLInputElement>(*element).defaultToolTip();
 
                 // FIXME: We should obtain text direction of tooltip from
                 // ChromeClient or platform. As of October 2011, all client
index 5159624..5ad33bc 100644 (file)
@@ -623,7 +623,7 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
 {
     state.type = (sourceFrame->selection().contains(dragOrigin)) ? DragSourceActionSelection : DragSourceActionNone;
     if (!startElement)
-        return 0;
+        return nullptr;
 
     for (auto renderer = startElement->renderer(); renderer; renderer = renderer->parent()) {
         Element* element = renderer->nonPseudoElement();
@@ -646,7 +646,7 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
             }
             if ((m_dragSourceAction & DragSourceActionLink)
                 && isHTMLAnchorElement(element)
-                && toHTMLAnchorElement(element)->isLiveLink()) {
+                && downcast<HTMLAnchorElement>(*element).isLiveLink()) {
                 state.type = static_cast<DragSourceAction>(state.type | DragSourceActionLink);
                 return element;
             }
@@ -654,7 +654,7 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
     }
 
     // We either have nothing to drag or we have a selection and we're not over a draggable element.
-    return (state.type & DragSourceActionSelection) ? startElement : 0;
+    return (state.type & DragSourceActionSelection) ? startElement : nullptr;
 }
 
 static CachedImage* getCachedImage(Element& element)
index 54949ee..cef181f 100644 (file)
@@ -1267,7 +1267,7 @@ Frame* EventHandler::subframeForTargetNode(Node* node)
 #if ENABLE(CURSOR_SUPPORT)
 static bool isSubmitImage(Node* node)
 {
-    return node && isHTMLInputElement(node) && toHTMLInputElement(node)->isImageButton();
+    return node && isHTMLInputElement(node) && downcast<HTMLInputElement>(*node).isImageButton();
 }
 
 // Returns true if the node's editable block is not current focused for editing
index 75d8c5d..a03aa0d 100644 (file)
@@ -885,9 +885,9 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction, Keyboa
             container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direction, focusedElement);
             startingRect = nodeRectInAbsoluteCoordinates(focusedElement, true /* ignore border */);
         } else if (isHTMLAreaElement(focusedElement)) {
-            HTMLAreaElement* area = toHTMLAreaElement(focusedElement);
-            container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direction, area->imageElement());
-            startingRect = virtualRectForAreaElementAndDirection(area, direction);
+            HTMLAreaElement& area = downcast<HTMLAreaElement>(*focusedElement);
+            container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direction, area.imageElement());
+            startingRect = virtualRectForAreaElementAndDirection(&area, direction);
         }
     }
 
index f5a0dde..a86e40c 100644 (file)
@@ -1416,7 +1416,7 @@ void FrameView::addEmbeddedObjectToUpdate(RenderEmbeddedObject& embeddedObject)
     HTMLFrameOwnerElement& element = embeddedObject.frameOwnerElement();
     if (isHTMLObjectElement(element) || isHTMLEmbedElement(element)) {
         // Tell the DOM element that it needs a widget update.
-        HTMLPlugInImageElement& pluginElement = toHTMLPlugInImageElement(element);
+        HTMLPlugInImageElement& pluginElement = downcast<HTMLPlugInImageElement>(element);
         if (!pluginElement.needsCheckForSizeChange())
             pluginElement.setNeedsWidgetUpdate(true);
     }
@@ -2789,7 +2789,7 @@ void FrameView::updateEmbeddedObject(RenderEmbeddedObject& embeddedObject)
 
     if (embeddedObject.isSnapshottedPlugIn()) {
         if (isHTMLObjectElement(element) || isHTMLEmbedElement(element)) {
-            HTMLPlugInImageElement& pluginElement = toHTMLPlugInImageElement(element);
+            HTMLPlugInImageElement& pluginElement = downcast<HTMLPlugInImageElement>(element);
             pluginElement.checkSnapshotStatus();
         }
         return;
@@ -2800,7 +2800,7 @@ void FrameView::updateEmbeddedObject(RenderEmbeddedObject& embeddedObject)
     // FIXME: This could turn into a real virtual dispatch if we defined
     // updateWidget(PluginCreationOption) on HTMLElement.
     if (isHTMLObjectElement(element) || isHTMLEmbedElement(element) || isHTMLAppletElement(element)) {
-        HTMLPlugInImageElement& pluginElement = toHTMLPlugInImageElement(element);
+        HTMLPlugInImageElement& pluginElement = downcast<HTMLPlugInImageElement>(element);
         if (pluginElement.needsCheckForSizeChange()) {
             pluginElement.checkSnapshotStatus();
             return;
index 6ea0cda..890938c 100644 (file)
@@ -231,19 +231,19 @@ void PageSerializer::serializeFrame(Frame* frame)
             retrieveResourcesForProperties(toStyledElement(element)->inlineStyle(), document);
 
         if (isHTMLImageElement(element)) {
-            HTMLImageElement* imageElement = toHTMLImageElement(element);
-            URL url = document->completeURL(imageElement->fastGetAttribute(HTMLNames::srcAttr));
-            CachedImage* cachedImage = imageElement->cachedImage();
-            addImageToResources(cachedImage, imageElement->renderer(), url);
-        } else if (element->hasTagName(HTMLNames::linkTag)) {
-            HTMLLinkElement* linkElement = toHTMLLinkElement(element);
-            if (CSSStyleSheet* sheet = linkElement->sheet()) {
-                URL url = document->completeURL(linkElement->getAttribute(HTMLNames::hrefAttr));
+            HTMLImageElement& imageElement = downcast<HTMLImageElement>(*element);
+            URL url = document->completeURL(imageElement.fastGetAttribute(HTMLNames::srcAttr));
+            CachedImage* cachedImage = imageElement.cachedImage();
+            addImageToResources(cachedImage, imageElement.renderer(), url);
+        } else if (isHTMLLinkElement(element)) {
+            HTMLLinkElement& linkElement = downcast<HTMLLinkElement>(*element);
+            if (CSSStyleSheet* sheet = linkElement.sheet()) {
+                URL url = document->completeURL(linkElement.getAttribute(HTMLNames::hrefAttr));
                 serializeCSSStyleSheet(sheet, url);
                 ASSERT(m_resourceURLs.contains(url));
             }
         } else if (isHTMLStyleElement(element)) {
-            if (CSSStyleSheet* sheet = toHTMLStyleElement(element)->sheet())
+            if (CSSStyleSheet* sheet = downcast<HTMLStyleElement>(*element).sheet())
                 serializeCSSStyleSheet(sheet, URL());
         }
     }
index b8c8851..9d623a1 100644 (file)
@@ -67,13 +67,13 @@ FocusCandidate::FocusCandidate(Node* node, FocusDirection direction)
     ASSERT(node->isElementNode());
 
     if (isHTMLAreaElement(node)) {
-        HTMLAreaElement* area = toHTMLAreaElement(node);
-        HTMLImageElement* image = area->imageElement();
+        HTMLAreaElement& area = downcast<HTMLAreaElement>(*node);
+        HTMLImageElement* image = area.imageElement();
         if (!image || !image->renderer())
             return;
 
         visibleNode = image;
-        rect = virtualRectForAreaElementAndDirection(area, direction);
+        rect = virtualRectForAreaElementAndDirection(&area, direction);
     } else {
         if (!node->renderer())
             return;
index 514807b..b82f9eb 100644 (file)
@@ -351,8 +351,8 @@ static Node* ancestorRespondingToClickEvents(const HitTestResult& hitTestResult,
             // If we are interested about the frame, use it.
             if (nodeBounds) {
                 // This is a check to see whether this node is an area element.  The only way this can happen is if this is the first check.
-                if (node == hitTestResult.innerNode() && node != hitTestResult.innerNonSharedNode() && node->hasTagName(HTMLNames::areaTag))
-                    *nodeBounds = snappedIntRect(toHTMLAreaElement(node)->computeRect(hitTestResult.innerNonSharedNode()->renderer()));
+                if (node == hitTestResult.innerNode() && node != hitTestResult.innerNonSharedNode() && isHTMLAreaElement(node))
+                    *nodeBounds = snappedIntRect(downcast<HTMLAreaElement>(*node).computeRect(hitTestResult.innerNonSharedNode()->renderer()));
                 else if (node && node->renderer())
                     *nodeBounds = node->renderer()->absoluteBoundingBoxRect(true);
             }
index 9593b76..09d6758 100644 (file)
 #include "RenderBlockFlow.h"
 #include "RenderImage.h"
 #include "RenderInline.h"
-#include "Scrollbar.h"
-#include "ShadowRoot.h"
+#include "SVGAElement.h"
 #include "SVGImageElement.h"
 #include "SVGNames.h"
+#include "Scrollbar.h"
+#include "ShadowRoot.h"
 #include "UserGestureIndicator.h"
 #include "XLinkNames.h"
 
@@ -272,14 +273,14 @@ String HitTestResult::altDisplayString() const
     if (!m_innerNonSharedNode)
         return String();
     
-    if (isHTMLImageElement(m_innerNonSharedNode.get())) {
-        HTMLImageElement* image = toHTMLImageElement(m_innerNonSharedNode.get());
-        return displayString(image->fastGetAttribute(altAttr), m_innerNonSharedNode.get());
+    if (isHTMLImageElement(*m_innerNonSharedNode)) {
+        HTMLImageElement& image = downcast<HTMLImageElement>(*m_innerNonSharedNode);
+        return displayString(image.fastGetAttribute(altAttr), m_innerNonSharedNode.get());
     }
     
-    if (isHTMLInputElement(m_innerNonSharedNode.get())) {
-        HTMLInputElement* input = toHTMLInputElement(m_innerNonSharedNode.get());
-        return displayString(input->alt(), m_innerNonSharedNode.get());
+    if (isHTMLInputElement(*m_innerNonSharedNode)) {
+        HTMLInputElement& input = downcast<HTMLInputElement>(*m_innerNonSharedNode);
+        return displayString(input.alt(), m_innerNonSharedNode.get());
     }
 
     return String();
@@ -335,15 +336,15 @@ URL HitTestResult::absolutePDFURL() const
     if (!m_innerNonSharedNode)
         return URL();
 
-    if (!m_innerNonSharedNode->hasTagName(embedTag) && !m_innerNonSharedNode->hasTagName(objectTag))
+    if (!isHTMLEmbedElement(*m_innerNonSharedNode) && !isHTMLObjectElement(*m_innerNonSharedNode))
         return URL();
 
-    HTMLPlugInImageElement* element = toHTMLPlugInImageElement(m_innerNonSharedNode.get());
-    URL url = m_innerNonSharedNode->document().completeURL(stripLeadingAndTrailingHTMLSpaces(element->url()));
+    HTMLPlugInImageElement& element = downcast<HTMLPlugInImageElement>(*m_innerNonSharedNode);
+    URL url = m_innerNonSharedNode->document().completeURL(stripLeadingAndTrailingHTMLSpaces(element.url()));
     if (!url.isValid())
         return URL();
 
-    if (element->serviceType() == "application/pdf" || (element->serviceType().isEmpty() && url.path().lower().endsWith(".pdf")))
+    if (element.serviceType() == "application/pdf" || (element.serviceType().isEmpty() && url.path().endsWith(".pdf", false)))
         return url;
     return URL();
 }
@@ -424,12 +425,12 @@ void HitTestResult::toggleMediaFullscreenState() const
 void HitTestResult::enterFullscreenForVideo() const
 {
 #if ENABLE(VIDEO)
-    HTMLMediaElement* mediaElt(mediaElement());
-    if (mediaElt && isHTMLVideoElement(mediaElt)) {
-        HTMLVideoElement* videoElt = toHTMLVideoElement(mediaElt);
-        if (!videoElt->isFullscreen() && mediaElt->supportsFullscreen()) {
+    HTMLMediaElement* mediaElement(this->mediaElement());
+    if (mediaElement && isHTMLVideoElement(mediaElement)) {
+        HTMLVideoElement& videoElement = downcast<HTMLVideoElement>(*mediaElement);
+        if (!videoElement.isFullscreen() && mediaElement->supportsFullscreen()) {
             UserGestureIndicator indicator(DefinitelyProcessingUserGesture);
-            videoElt->enterFullscreen();
+            videoElement.enterFullscreen();
         }
     }
 #endif
@@ -438,8 +439,8 @@ void HitTestResult::enterFullscreenForVideo() const
 bool HitTestResult::mediaControlsEnabled() const
 {
 #if ENABLE(VIDEO)
-    if (HTMLMediaElement* mediaElt = mediaElement())
-        return mediaElt->controls();
+    if (HTMLMediaElement* mediaElement = this->mediaElement())
+        return mediaElement->controls();
 #endif
     return false;
 }
@@ -517,10 +518,10 @@ bool HitTestResult::isLiveLink() const
     if (!m_innerURLElement)
         return false;
 
-    if (isHTMLAnchorElement(m_innerURLElement.get()))
-        return toHTMLAnchorElement(m_innerURLElement.get())->isLiveLink();
+    if (isHTMLAnchorElement(*m_innerURLElement))
+        return downcast<HTMLAnchorElement>(*m_innerURLElement).isLiveLink();
 
-    if (m_innerURLElement->hasTagName(SVGNames::aTag))
+    if (isSVGAElement(*m_innerURLElement))
         return m_innerURLElement->isLink();
 
     return false;
@@ -555,11 +556,11 @@ bool HitTestResult::isContentEditable() const
     if (!m_innerNonSharedNode)
         return false;
 
-    if (isHTMLTextAreaElement(m_innerNonSharedNode.get()))
+    if (isHTMLTextAreaElement(*m_innerNonSharedNode))
         return true;
 
-    if (isHTMLInputElement(m_innerNonSharedNode.get()))
-        return toHTMLInputElement(m_innerNonSharedNode.get())->isTextField();
+    if (isHTMLInputElement(*m_innerNonSharedNode))
+        return downcast<HTMLInputElement>(*m_innerNonSharedNode).isTextField();
 
     return m_innerNonSharedNode->hasEditableStyle();
 }
index f4dacfa..139cb97 100644 (file)
@@ -145,7 +145,7 @@ void RenderButton::updateFromElement()
 {
     // If we're an input element, we may need to change our button text.
     if (isHTMLInputElement(formControlElement())) {
-        HTMLInputElement& input = toHTMLInputElement(formControlElement());
+        HTMLInputElement& input = downcast<HTMLInputElement>(formControlElement());
         String value = input.valueWithDefault();
         setText(value);
     }
index bedd1c7..4970c04 100644 (file)
@@ -142,8 +142,8 @@ static bool planCounter(RenderElement& renderer, const AtomicString& identifier,
             return true;
         }
         if (Element* element = renderer.element()) {
-            if (element->hasTagName(olTag)) {
-                value = toHTMLOListElement(element)->start();
+            if (isHTMLOListElement(element)) {
+                value = downcast<HTMLOListElement>(*element).start();
                 isReset = true;
                 return true;
             }
index cb920af..ba73ec7 100644 (file)
@@ -238,8 +238,7 @@ void RenderEmbeddedObject::paintContents(PaintInfo& paintInfo, const LayoutPoint
     if (!plugInElement.isPlugInImageElement())
         return;
 
-    Image* snapshot = toHTMLPlugInImageElement(plugInElement).snapshotImage();
-    if (snapshot)
+    if (Image* snapshot = downcast<HTMLPlugInImageElement>(plugInElement).snapshotImage())
         paintSnapshotImage(paintInfo, paintOffset, snapshot);
 }
 
@@ -495,7 +494,7 @@ void RenderEmbeddedObject::layout()
     if (!wasMissingWidget && newSize.width() >= oldSize.width() && newSize.height() >= oldSize.height()) {
         HTMLFrameOwnerElement& element = frameOwnerElement();
         if (element.isPluginElement() && toHTMLPlugInElement(element).isPlugInImageElement()) {
-            HTMLPlugInImageElement& plugInImageElement = toHTMLPlugInImageElement(element);
+            HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(element);
             if (plugInImageElement.displayState() > HTMLPlugInElement::DisplayingSnapshot && plugInImageElement.snapshotDecision() == HTMLPlugInImageElement::MaySnapshotWhenResized) {
                 plugInImageElement.setNeedsCheckForSizeChange();
                 view().frameView().addEmbeddedObjectToUpdate(*this);
index a405aa4..9f672d7 100644 (file)
@@ -38,7 +38,7 @@ public:
     enum FindLegendOption { IgnoreFloatingOrOutOfFlow, IncludeFloatingOrOutOfFlow };
     RenderBox* findLegend(FindLegendOption = IgnoreFloatingOrOutOfFlow) const;
 
-    HTMLFieldSetElement& fieldSetElement() const { return toHTMLFieldSetElement(nodeForNonAnonymous()); }
+    HTMLFieldSetElement& fieldSetElement() const { return downcast<HTMLFieldSetElement>(nodeForNonAnonymous()); }
 
 private:
     void element() const = delete;
index 501c51e..2951cfa 100644 (file)
@@ -70,7 +70,7 @@ RenderFileUploadControl::~RenderFileUploadControl()
 
 HTMLInputElement& RenderFileUploadControl::inputElement() const
 {
-    return toHTMLInputElement(nodeForNonAnonymous());
+    return downcast<HTMLInputElement>(nodeForNonAnonymous());
 }
 
 void RenderFileUploadControl::updateFromElement()
@@ -255,7 +255,7 @@ HTMLInputElement* RenderFileUploadControl::uploadButton() const
 {
     ASSERT(inputElement().shadowRoot());
     Node* buttonNode = inputElement().shadowRoot()->firstChild();
-    return buttonNode && buttonNode->isHTMLElement() && isHTMLInputElement(buttonNode) ? toHTMLInputElement(buttonNode) : 0;
+    return buttonNode && buttonNode->isHTMLElement() && isHTMLInputElement(buttonNode) ? downcast<HTMLInputElement>(buttonNode) : nullptr;
 }
 
 String RenderFileUploadControl::buttonValue()
index d8ba31a..43938cf 100644 (file)
@@ -35,7 +35,7 @@ RenderFrame::RenderFrame(HTMLFrameElement& frame, PassRef<RenderStyle> style)
 
 HTMLFrameElement& RenderFrame::frameElement() const
 {
-    return toHTMLFrameElement(RenderFrameBase::frameOwnerElement());
+    return downcast<HTMLFrameElement>(RenderFrameBase::frameOwnerElement());
 }
 
 FrameEdgeInfo RenderFrame::edgeInfo() const
index 4485137..17717d8 100644 (file)
@@ -59,7 +59,7 @@ RenderFrameSet::~RenderFrameSet()
 
 HTMLFrameSetElement& RenderFrameSet::frameSetElement() const
 {
-    return toHTMLFrameSetElement(nodeForNonAnonymous());
+    return downcast<HTMLFrameSetElement>(nodeForNonAnonymous());
 }
 
 RenderFrameSet::GridAxis::GridAxis()
index e42fe8d..621cf28 100644 (file)
@@ -50,7 +50,7 @@ RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element, PassRef<RenderSty
 
 HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const
 {
-    return toHTMLCanvasElement(nodeForNonAnonymous());
+    return downcast<HTMLCanvasElement>(nodeForNonAnonymous());
 }
 
 bool RenderHTMLCanvas::requiresLayer() const
index 0edce2d..90c6357 100644 (file)
@@ -46,7 +46,7 @@ RenderIFrame::RenderIFrame(HTMLIFrameElement& element, PassRef<RenderStyle> styl
 
 HTMLIFrameElement& RenderIFrame::iframeElement() const
 {
-    return toHTMLIFrameElement(RenderFrameBase::frameOwnerElement());
+    return downcast<HTMLIFrameElement>(RenderFrameBase::frameOwnerElement());
 }
 
 bool RenderIFrame::shouldComputeSizeAsReplaced() const
index d6155fc..e858582 100644 (file)
@@ -131,7 +131,7 @@ RenderImage::RenderImage(Element& element, PassRef<RenderStyle> style, StyleImag
     imageResource().initialize(this);
 
     if (isHTMLImageElement(element))
-        m_hasShadowControls = toHTMLImageElement(element).hasShadowControls();
+        m_hasShadowControls = downcast<HTMLImageElement>(element).hasShadowControls();
 }
 
 RenderImage::RenderImage(Document& document, PassRef<RenderStyle> style, StyleImage* styleImage)
@@ -517,20 +517,20 @@ void RenderImage::paintAreaElementFocusRing(PaintInfo& paintInfo)
     if (!focusedElement || !isHTMLAreaElement(focusedElement))
         return;
 
-    HTMLAreaElement* areaElement = toHTMLAreaElement(focusedElement);
-    if (areaElement->imageElement() != element())
+    HTMLAreaElement& areaElement = downcast<HTMLAreaElement>(*focusedElement);
+    if (areaElement.imageElement() != element())
         return;
 
     // Even if the theme handles focus ring drawing for entire elements, it won't do it for
     // an area within an image, so we don't call RenderTheme::supportsFocusRing here.
 
-    Path path = areaElement->computePath(this);
+    Path path = areaElement.computePath(this);
     if (path.isEmpty())
         return;
 
     // FIXME: Do we need additional code to clip the path to the image's bounding box?
 
-    RenderStyle* areaElementStyle = areaElement->computedStyle();
+    RenderStyle* areaElementStyle = areaElement.computedStyle();
     unsigned short outlineWidth = areaElementStyle->outlineWidth();
     if (!outlineWidth)
         return;
@@ -560,8 +560,8 @@ void RenderImage::paintIntoRect(GraphicsContext* context, const FloatRect& rect)
     if (!img || img->isNull())
         return;
 
-    HTMLImageElement* imageElt = (element() && isHTMLImageElement(element())) ? toHTMLImageElement(element()) : 0;
-    CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : CompositeSourceOver;
+    HTMLImageElement* imageElement = (element() && isHTMLImageElement(element())) ? downcast<HTMLImageElement>(element()) : nullptr;
+    CompositeOperator compositeOperator = imageElement ? imageElement->compositeOperator() : CompositeSourceOver;
     Image* image = imageResource().image().get();
     bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, LayoutSize(rect.size()));
     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
@@ -622,8 +622,8 @@ LayoutUnit RenderImage::minimumReplacedHeight() const
 
 HTMLMapElement* RenderImage::imageMap() const
 {
-    HTMLImageElement* i = element() && isHTMLImageElement(element()) ? toHTMLImageElement(element()) : 0;
-    return i ? i->treeScope().getImageMap(i->fastGetAttribute(usemapAttr)) : 0;
+    HTMLImageElement* image = element() && isHTMLImageElement(element()) ? downcast<HTMLImageElement>(element()) : nullptr;
+    return image ? image->treeScope().getImageMap(image->fastGetAttribute(usemapAttr)) : nullptr;
 }
 
 bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
@@ -655,10 +655,10 @@ void RenderImage::updateAltText()
     if (!element())
         return;
 
-    if (isHTMLInputElement(element()))
-        m_altText = toHTMLInputElement(element())->altText();
-    else if (isHTMLImageElement(element()))
-        m_altText = toHTMLImageElement(element())->altText();
+    if (isHTMLInputElement(*element()))
+        m_altText = downcast<HTMLInputElement>(*element()).altText();
+    else if (isHTMLImageElement(*element()))
+        m_altText = downcast<HTMLImageElement>(*element()).altText();
 }
 
 bool RenderImage::canHaveChildren() const
index 21a0103..371df40 100644 (file)
@@ -74,7 +74,7 @@ CanvasCompositingStrategy canvasCompositingStrategy(const RenderObject& renderer
 {
     ASSERT(renderer.isCanvas());
     
-    const HTMLCanvasElement* canvas = toHTMLCanvasElement(renderer.node());
+    const HTMLCanvasElement* canvas = downcast<HTMLCanvasElement>(renderer.node());
     CanvasRenderingContext* context = canvas->renderingContext();
     if (!context || !context->isAccelerated())
         return UnacceleratedCanvas;
@@ -300,7 +300,7 @@ void RenderLayerBacking::createPrimaryGraphicsLayer()
 
 #if PLATFORM(COCOA) && USE(CA)
     if (!compositor().acceleratedDrawingEnabled() && renderer().isCanvas()) {
-        const HTMLCanvasElement* canvas = toHTMLCanvasElement(renderer().element());
+        const HTMLCanvasElement* canvas = downcast<HTMLCanvasElement>(renderer().element());
         if (canvas->shouldAccelerate(canvas->size()))
             m_graphicsLayer->setAcceleratesDrawing(true);
     }
@@ -592,7 +592,7 @@ bool RenderLayerBacking::updateConfiguration()
 #endif
 #if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
     else if (renderer().isCanvas() && canvasCompositingStrategy(renderer()) == CanvasAsLayerContents) {
-        const HTMLCanvasElement* canvas = toHTMLCanvasElement(renderer().element());
+        const HTMLCanvasElement* canvas = downcast<HTMLCanvasElement>(renderer().element());
         if (CanvasRenderingContext* context = canvas->renderingContext())
             m_graphicsLayer->setContentsToPlatformLayer(context->platformLayer(), GraphicsLayer::ContentsLayerForCanvas);
         layerConfigChanged = true;
index 1553822..4be4691 100644 (file)
@@ -2435,7 +2435,7 @@ bool RenderLayerCompositor::requiresCompositingForCanvas(RenderLayerModelObject&
 #if USE(COMPOSITING_FOR_SMALL_CANVASES)
         bool isCanvasLargeEnoughToForceCompositing = true;
 #else
-        HTMLCanvasElement* canvas = toHTMLCanvasElement(renderer.element());
+        HTMLCanvasElement* canvas = downcast<HTMLCanvasElement>(renderer.element());
         bool isCanvasLargeEnoughToForceCompositing = canvas->size().area() >= canvasAreaThresholdRequiringCompositing;
 #endif
         CanvasCompositingStrategy compositingStrategy = canvasCompositingStrategy(renderer);
index 5759abc..62aedc3 100644 (file)
@@ -100,7 +100,7 @@ RenderListBox::~RenderListBox()
 
 HTMLSelectElement& RenderListBox::selectElement() const
 {
-    return toHTMLSelectElement(nodeForNonAnonymous());
+    return downcast<HTMLSelectElement>(nodeForNonAnonymous());
 }
 
 void RenderListBox::updateFromElement()
@@ -117,9 +117,9 @@ void RenderListBox::updateFromElement()
             String text;
             Font itemFont = style().font();
             if (isHTMLOptionElement(element))
-                text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
+                text = downcast<HTMLOptionElement>(*element).textIndentedToRespectGroupLabel();
             else if (isHTMLOptGroupElement(element)) {
-                text = toHTMLOptGroupElement(element)->groupLabelText();
+                text = downcast<HTMLOptGroupElement>(*element).groupLabelText();
                 FontDescription d = itemFont.fontDescription();
                 d.setWeight(d.bolderWeight());
                 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
@@ -387,13 +387,13 @@ void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
     String itemText;
     bool isOptionElement = isHTMLOptionElement(listItemElement);
     if (isOptionElement)
-        itemText = toHTMLOptionElement(listItemElement)->textIndentedToRespectGroupLabel();
+        itemText = downcast<HTMLOptionElement>(*listItemElement).textIndentedToRespectGroupLabel();
     else if (isHTMLOptGroupElement(listItemElement))
-        itemText = toHTMLOptGroupElement(listItemElement)->groupLabelText();
+        itemText = downcast<HTMLOptGroupElement>(*listItemElement).groupLabelText();
     applyTextTransform(style(), itemText, ' ');
 
     Color textColor = listItemElement->renderStyle() ? listItemElement->renderStyle()->visitedDependentColor(CSSPropertyColor) : style().visitedDependentColor(CSSPropertyColor);
-    if (isOptionElement && toHTMLOptionElement(listItemElement)->selected()) {
+    if (isOptionElement && downcast<HTMLOptionElement>(*listItemElement).selected()) {
         if (frame().selection().isFocusedAndActive() && document().focusedElement() == &selectElement())
             textColor = theme().activeListBoxSelectionForegroundColor();
         // Honor the foreground color for disabled items
@@ -426,7 +426,7 @@ void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint&
     HTMLElement* listItemElement = listItems[listIndex];
 
     Color backColor;
-    if (isHTMLOptionElement(listItemElement) && toHTMLOptionElement(listItemElement)->selected()) {
+    if (isHTMLOptionElement(listItemElement) && downcast<HTMLOptionElement>(*listItemElement).selected()) {
         if (frame().selection().isFocusedAndActive() && document().focusedElement() == &selectElement())
             backColor = theme().activeListBoxSelectionBackgroundColor();
         else
index 368ed9e..fa012c9 100644 (file)
@@ -189,7 +189,7 @@ inline int RenderListItem::calcValue() const
         return m_explicitValue;
 
     Element* list = enclosingList(this);
-    HTMLOListElement* oListElement = (list && list->hasTagName(olTag)) ? toHTMLOListElement(list) : nullptr;
+    HTMLOListElement* oListElement = (list && list->hasTagName(olTag)) ? downcast<HTMLOListElement>(list) : nullptr;
     int valueStep = 1;
     if (oListElement && oListElement->isReversed())
         valueStep = -1;
@@ -501,7 +501,7 @@ void RenderListItem::updateListMarkerNumbers()
         return;
 
     bool isListReversed = false;
-    HTMLOListElement* oListElement = (listNode && listNode->hasTagName(olTag)) ? toHTMLOListElement(listNode) : nullptr;
+    HTMLOListElement* oListElement = (listNode && listNode->hasTagName(olTag)) ? downcast<HTMLOListElement>(listNode) : nullptr;
     if (oListElement) {
         oListElement->itemCountChanged();
         isListReversed = oListElement->isReversed();
index bdea979..25a97e6 100644 (file)
@@ -73,8 +73,8 @@ int RenderMarquee::marqueeSpeed() const
 {
     int result = m_layer->renderer().style().marqueeSpeed();
     Element* element = m_layer->renderer().element();
-    if (element && element->hasTagName(marqueeTag))
-        result = std::max(result, toHTMLMarqueeElement(element)->minimumDelay());
+    if (element && isHTMLMarqueeElement(element))
+        result = std::max(result, downcast<HTMLMarqueeElement>(*element).minimumDelay());
     return result;
 }
 
index 134cf94..37eea5e 100644 (file)
@@ -64,7 +64,7 @@ static size_t selectedOptionCount(const RenderMenuList& renderMenuList)
 
     size_t count = 0;
     for (size_t i = 0; i < numberOfItems; ++i) {
-        if (listItems[i]->hasTagName(optionTag) && toHTMLOptionElement(listItems[i])->selected())
+        if (isHTMLOptionElement(listItems[i]) && downcast<HTMLOptionElement>(*listItems[i]).selected())
             ++count;
     }
     return count;
@@ -168,7 +168,7 @@ void RenderMenuList::adjustInnerStyle()
 
 HTMLSelectElement& RenderMenuList::selectElement() const
 {
-    return toHTMLSelectElement(nodeForNonAnonymous());
+    return downcast<HTMLSelectElement>(nodeForNonAnonymous());
 }
 
 void RenderMenuList::addChild(RenderObject* newChild, RenderObject* beforeChild)
@@ -217,7 +217,7 @@ void RenderMenuList::updateOptionsWidth()
         if (!isHTMLOptionElement(element))
             continue;
 
-        String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
+        String text = downcast<HTMLOptionElement>(*element).textIndentedToRespectGroupLabel();
         applyTextTransform(style(), text, ' ');
         if (theme().popupOptionSupportsTextIndent()) {
             // Add in the option's text indent.  We can't calculate percentage values for now.
@@ -271,7 +271,7 @@ void RenderMenuList::setTextFromOption(int optionIndex)
     if (i >= 0 && i < size) {
         Element* element = listItems[i];
         if (isHTMLOptionElement(element)) {
-            text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
+            text = downcast<HTMLOptionElement>(*element).textIndentedToRespectGroupLabel();
             m_optionStyle = element->computedStyle();
         }
     }
@@ -451,9 +451,9 @@ String RenderMenuList::itemText(unsigned listIndex) const
     String itemString;
     Element* element = listItems[listIndex];
     if (isHTMLOptGroupElement(element))
-        itemString = toHTMLOptGroupElement(element)->groupLabelText();
+        itemString = downcast<HTMLOptGroupElement>(*element).groupLabelText();
     else if (isHTMLOptionElement(element))
-        itemString = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
+        itemString = downcast<HTMLOptionElement>(*element).textIndentedToRespectGroupLabel();
 
     applyTextTransform(style(), itemString, ' ');
     return itemString;
@@ -654,7 +654,7 @@ bool RenderMenuList::itemIsSelected(unsigned listIndex) const
     if (listIndex >= listItems.size())
         return false;
     HTMLElement* element = listItems[listIndex];
-    return isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected();
+    return isHTMLOptionElement(element) && downcast<HTMLOptionElement>(*element).selected();
 }
 
 void RenderMenuList::setTextFromItem(unsigned listIndex)
index e624686..9edbbd9 100644 (file)
@@ -44,10 +44,10 @@ HTMLMeterElement* RenderMeter::meterElement() const
     ASSERT(element());
 
     if (isHTMLMeterElement(element()))
-        return toHTMLMeterElement(element());
+        return downcast<HTMLMeterElement>(element());
 
     ASSERT(element()->shadowHost());
-    return toHTMLMeterElement(element()->shadowHost());
+    return downcast<HTMLMeterElement>(element()->shadowHost());
 }
 
 void RenderMeter::updateLogicalWidth()
index 2425f06..2b4f057 100644 (file)
@@ -108,13 +108,13 @@ void RenderProgress::updateAnimationState()
 HTMLProgressElement* RenderProgress::progressElement() const
 {
     if (!element())
-        return 0;
+        return nullptr;
 
     if (isHTMLProgressElement(element()))
-        return toHTMLProgressElement(element());
+        return downcast<HTMLProgressElement>(element());
 
     ASSERT(element()->shadowHost());
-    return toHTMLProgressElement(element()->shadowHost());
+    return downcast<HTMLProgressElement>(element()->shadowHost());
 }    
 
 } // namespace WebCore
index aeb88be..107979e 100644 (file)
@@ -60,7 +60,7 @@ RenderSlider::~RenderSlider()
 
 HTMLInputElement& RenderSlider::element() const
 {
-    return toHTMLInputElement(nodeForNonAnonymous());
+    return downcast<HTMLInputElement>(nodeForNonAnonymous());
 }
 
 int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const
index 7978fe2..de3726d 100644 (file)
@@ -64,7 +64,7 @@ RenderSnapshottedPlugIn::~RenderSnapshottedPlugIn()
 
 HTMLPlugInImageElement& RenderSnapshottedPlugIn::plugInImageElement() const
 {
-    return toHTMLPlugInImageElement(RenderEmbeddedObject::frameOwnerElement());
+    return downcast<HTMLPlugInImageElement>(RenderEmbeddedObject::frameOwnerElement());
 }
 
 void RenderSnapshottedPlugIn::layout()
index 8b0d0ef..4035f66 100644 (file)
@@ -48,7 +48,7 @@ RenderTextControl::~RenderTextControl()
 
 HTMLTextFormControlElement& RenderTextControl::textFormControlElement() const
 {
-    return toHTMLTextFormControlElement(nodeForNonAnonymous());
+    return downcast<HTMLTextFormControlElement>(nodeForNonAnonymous());
 }
 
 TextControlInnerTextElement* RenderTextControl::innerTextElement() const
index 91db53d..52718da 100644 (file)
@@ -45,7 +45,7 @@ RenderTextControlMultiLine::~RenderTextControlMultiLine()
 
 HTMLTextAreaElement& RenderTextControlMultiLine::textAreaElement() const
 {
-    return toHTMLTextAreaElement(RenderTextControl::textFormControlElement());
+    return downcast<HTMLTextAreaElement>(RenderTextControl::textFormControlElement());
 }
 
 bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
index 5957ee7..c2ec7d6 100644 (file)
@@ -481,7 +481,7 @@ bool RenderTextControlSingleLine::logicalScroll(ScrollLogicalDirection direction
 
 HTMLInputElement& RenderTextControlSingleLine::inputElement() const
 {
-    return toHTMLInputElement(RenderTextControl::textFormControlElement());
+    return downcast<HTMLInputElement>(RenderTextControl::textFormControlElement());
 }
 
 }
index a1508b8..fb5ee5c 100644 (file)
@@ -980,7 +980,7 @@ void RenderTheme::paintSliderTicks(const RenderObject& o, const PaintInfo& paint
     if (!input)
         return;
 
-    HTMLDataListElement* dataList = toHTMLDataListElement(input->list());
+    HTMLDataListElement* dataList = downcast<HTMLDataListElement>(input->list());
     if (!dataList)
         return;
 
@@ -1036,8 +1036,8 @@ void RenderTheme::paintSliderTicks(const RenderObject& o, const PaintInfo& paint
     paintInfo.context->setFillColor(o.style().visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB);
     for (unsigned i = 0; Node* node = options->item(i); i++) {
         ASSERT(isHTMLOptionElement(node));
-        HTMLOptionElement* optionElement = toHTMLOptionElement(node);
-        String value = optionElement->value();
+        HTMLOptionElement& optionElement = downcast<HTMLOptionElement>(*node);
+        String value = optionElement.value();
         if (!input->isValidValue(value))
             continue;
         double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(value));
index 94e1bdb..789bef5 100644 (file)
@@ -672,7 +672,7 @@ bool RenderThemeIOS::paintMenuListButtonDecorations(const RenderObject& box, con
 
     // Paint Indicators.
 
-    if (box.isMenuList() && toHTMLSelectElement(box.node())->multiple()) {
+    if (box.isMenuList() && downcast<HTMLSelectElement>(box.node())->multiple()) {
         int size = 2;
         int count = 3;
         int padding = 3;
index d4cab2b..c5afebd 100644 (file)
@@ -1678,7 +1678,7 @@ bool RenderThemeMac::paintSearchFieldCancelButton(const RenderObject& o, const P
 
     NSSearchFieldCell* search = this->search();
 
-    if (!input->isDisabledFormControl() && (input->isTextFormControl() && !toHTMLTextFormControlElement(input)->isReadOnly()))
+    if (!input->isDisabledFormControl() && (input->isTextFormControl() && !downcast<HTMLTextFormControlElement>(*input).isReadOnly()))
         updatePressedState([search cancelButtonCell], o);
     else if ([[search cancelButtonCell] isHighlighted])
         [[search cancelButtonCell] setHighlighted:NO];
@@ -1861,13 +1861,13 @@ bool RenderThemeMac::paintSnapshottedPluginOverlay(const RenderObject& o, const
     if (!plugInElement->isPlugInImageElement())
         return true;
 
-    HTMLPlugInImageElement* plugInImageElement = toHTMLPlugInImageElement(plugInElement);
+    HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(*plugInElement);
 
-    Image* snapshot = plugInImageElement->snapshotImage();
+    Image* snapshot = plugInImageElement.snapshotImage();
     if (!snapshot)
         return true;
 
-    RenderSnapshottedPlugIn* plugInRenderer = toRenderSnapshottedPlugIn(plugInImageElement->renderer());
+    RenderSnapshottedPlugIn* plugInRenderer = toRenderSnapshottedPlugIn(plugInImageElement.renderer());
     FloatPoint snapshotAbsPos = plugInRenderer->localToAbsolute();
     snapshotAbsPos.move(plugInRenderer->borderLeft() + plugInRenderer->paddingLeft(), plugInRenderer->borderTop() + plugInRenderer->paddingTop());
 
index 5c9606f..6eaff33 100644 (file)
@@ -205,7 +205,7 @@ void RenderVideo::layout()
     
 HTMLVideoElement& RenderVideo::videoElement() const
 {
-    return toHTMLVideoElement(RenderMedia::mediaElement());
+    return downcast<HTMLVideoElement>(RenderMedia::mediaElement());
 }
 
 void RenderVideo::updateFromElement()
index 748660f..3f2111f 100644 (file)
@@ -93,7 +93,7 @@ Image* SVGImageCache::imageForRenderer(const RenderObject* renderer)
     
     Node* node = renderer->node();
     if (node && isHTMLImageElement(node)) {
-        const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL();
+        const AtomicString& urlString = downcast<HTMLImageElement>(*node).imageSourceURL();
         URL url = node->document().completeURL(urlString);
         imageForContainer->setURL(url);
     }
index 67f72d8..b7708c1 100644 (file)
@@ -3,7 +3,7 @@ namespaceURI="http://www.w3.org/2000/svg"
 fallbackInterfaceName="SVGUnknownElement"
 fallbackJSInterfaceName="SVGElement"
 
-a
+a generateTypeHelpers
 #if ENABLE_SVG_FONTS
 altGlyph generateTypeHelpers
 altGlyphDef generateTypeHelpers
index df77d93..798d991 100644 (file)
@@ -624,7 +624,7 @@ void Internals::setShadowPseudoId(Element* element, const String& id, ExceptionC
 String Internals::visiblePlaceholder(Element* element)
 {
     if (element && isHTMLTextFormControlElement(*element)) {
-        const HTMLTextFormControlElement& textFormControlElement = toHTMLTextFormControlElement(*element);
+        const HTMLTextFormControlElement& textFormControlElement = downcast<HTMLTextFormControlElement>(*element);
         if (!textFormControlElement.isPlaceholderVisible())
             return String();
         if (HTMLElement* placeholderElement = textFormControlElement.placeholderElement())
@@ -912,9 +912,8 @@ bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionCode& ec)
     if (HTMLInputElement* inputElement = textField->toInputElement())
         return inputElement->lastChangeWasUserEdit();
 
-    // FIXME: We should be using hasTagName instead but Windows port doesn't link QualifiedNames properly.
-    if (textField->tagName() == "TEXTAREA")
-        return toHTMLTextAreaElement(textField)->lastChangeWasUserEdit();
+    if (isHTMLTextAreaElement(textField))
+        return downcast<HTMLTextAreaElement>(*textField).lastChangeWasUserEdit();
 
     ec = INVALID_NODE_TYPE_ERR;
     return false;
@@ -1920,8 +1919,8 @@ void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*
         document = contextDocument();
     else if (node->isDocumentNode())
         document = toDocument(node);
-    else if (node->hasTagName(HTMLNames::iframeTag))
-        document = toHTMLIFrameElement(node)->contentDocument();
+    else if (isHTMLIFrameElement(node))
+        document = downcast<HTMLIFrameElement>(*node).contentDocument();
     else {
         ec = TypeError;
         return;
@@ -2088,9 +2087,9 @@ bool Internals::isSelectPopupVisible(Node* node)
     if (!isHTMLSelectElement(node))
         return false;
 
-    HTMLSelectElement* select = toHTMLSelectElement(node);
+    HTMLSelectElement& select = downcast<HTMLSelectElement>(*node);
 
-    auto renderer = select->renderer();
+    auto renderer = select.renderer();
     if (!renderer->isMenuList())
         return false;
 
index d2fe7c0..9a1f8f5 100644 (file)
@@ -850,16 +850,16 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
         return;
 
 #if ENABLE(TEMPLATE_ELEMENT)
-    if (newElement->hasTagName(HTMLNames::templateTag))
-        pushCurrentNode(toHTMLTemplateElement(newElement.get())->content());
+    if (isHTMLTemplateElement(*newElement))
+        pushCurrentNode(downcast<HTMLTemplateElement>(*newElement).content());
     else
         pushCurrentNode(newElement.get());
 #else
     pushCurrentNode(newElement.get());
 #endif
 
-    if (newElement->hasTagName(HTMLNames::htmlTag))
-        toHTMLHtmlElement(newElement.get())->insertedByParser();
+    if (isHTMLHtmlElement(*newElement))
+        downcast<HTMLHtmlElement>(*newElement).insertedByParser();
 
     if (!m_parsingFragment && isFirstElement && document()->frame())
         document()->frame()->injectUserScripts(InjectAtDocumentStart);
index 47272e2..6e4ab3b 100644 (file)
@@ -1,3 +1,15 @@
+2014-09-23  Chris Dumez  <cdumez@apple.com>
+
+        Use downcast<HTML*Element>() instead of toHTML*Element()
+        https://bugs.webkit.org/show_bug.cgi?id=137007
+
+        Reviewed by Benjamin Poulain.
+
+        Use downcast<HTML*Element>() instead of toHTML*Element().
+
+        * WebCoreSupport/WebChromeClientIOS.mm:
+        (WebChromeClientIOS::focusedElementChanged):
+
 2014-09-17  Daniel Bates  <dabates@apple.com>
 
         Unreviewed, rolling out r173695.
index f664f95..2b65bb0 100644 (file)
@@ -314,11 +314,11 @@ void WebChromeClientIOS::focusedElementChanged(Element* element)
     if (!isHTMLInputElement(element))
         return;
 
-    HTMLInputElement* inputElement = toHTMLInputElement(element);
-    if (!inputElement->isText())
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*element);
+    if (!inputElement.isText())
         return;
 
-    CallFormDelegate(webView(), @selector(didFocusTextField:inFrame:), kit(inputElement), kit(inputElement->document().frame()));
+    CallFormDelegate(webView(), @selector(didFocusTextField:inFrame:), kit(&inputElement), kit(inputElement.document().frame()));
 }
 
 void WebChromeClientIOS::showPlaybackTargetPicker(bool hasVideo)
index 3e40d2a..a77e3f1 100644 (file)
@@ -1,3 +1,26 @@
+2014-09-23  Chris Dumez  <cdumez@apple.com>
+
+        Use downcast<HTML*Element>() instead of toHTML*Element()
+        https://bugs.webkit.org/show_bug.cgi?id=137007
+
+        Reviewed by Benjamin Poulain.
+
+        Use downcast<HTML*Element>() instead of toHTML*Element().
+
+        * DOM/WebDOMOperations.mm:
+        (-[DOMHTMLInputElement _setAutofilled:]):
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::focusedElementChanged):
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::textFieldDidBeginEditing):
+        (WebEditorClient::textFieldDidEndEditing):
+        (WebEditorClient::textDidChangeInTextField):
+        (WebEditorClient::doTextFieldCommandFromEvent):
+        (WebEditorClient::textWillBeDeletedInTextField):
+        (WebEditorClient::textDidChangeInTextArea):
+        * WebView/WebHTMLRepresentation.mm:
+        (inputElementFromDOMElement):
+
 2014-09-21  Chris Dumez  <cdumez@apple.com>
 
         Generate Element casting helper functions
index 50a9d8f..b1c2035 100644 (file)
@@ -214,7 +214,7 @@ using namespace JSC;
 
 - (void)_setAutofilled:(BOOL)autofilled
 {
-    toHTMLInputElement(core((DOMElement *)self))->setAutofilled(autofilled);
+    downcast<HTMLInputElement>(core((DOMElement *)self))->setAutofilled(autofilled);
 }
 
 @end
index 2254e2e..24de67a 100644 (file)
@@ -223,11 +223,11 @@ void WebChromeClient::focusedElementChanged(Element* element)
     if (!isHTMLInputElement(element))
         return;
 
-    HTMLInputElement* inputElement = toHTMLInputElement(element);
-    if (!inputElement->isText())
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*element);
+    if (!inputElement.isText())
         return;
 
-    CallFormDelegate(m_webView, @selector(didFocusTextField:inFrame:), kit(inputElement), kit(inputElement->document().frame()));
+    CallFormDelegate(m_webView, @selector(didFocusTextField:inFrame:), kit(&inputElement), kit(inputElement.document().frame()));
 }
 
 void WebChromeClient::focusedFrameChanged(Frame*)
index 7b6296e..a69492c 100644 (file)
@@ -708,7 +708,7 @@ void WebEditorClient::textFieldDidBeginEditing(Element* element)
     if (!isHTMLInputElement(element))
         return;
 
-    DOMHTMLInputElement* inputElement = kit(toHTMLInputElement(element));
+    DOMHTMLInputElement* inputElement = kit(downcast<HTMLInputElement>(element));
     FormDelegateLog(inputElement);
     CallFormDelegate(m_webView, @selector(textFieldDidBeginEditing:inFrame:), inputElement, kit(element->document().frame()));
 }
@@ -718,7 +718,7 @@ void WebEditorClient::textFieldDidEndEditing(Element* element)
     if (!isHTMLInputElement(element))
         return;
 
-    DOMHTMLInputElement* inputElement = kit(toHTMLInputElement(element));
+    DOMHTMLInputElement* inputElement = kit(downcast<HTMLInputElement>(element));
     FormDelegateLog(inputElement);
     CallFormDelegate(m_webView, @selector(textFieldDidEndEditing:inFrame:), inputElement, kit(element->document().frame()));
 }
@@ -733,7 +733,7 @@ void WebEditorClient::textDidChangeInTextField(Element* element)
         return;
 #endif
 
-    DOMHTMLInputElement* inputElement = kit(toHTMLInputElement(element));
+    DOMHTMLInputElement* inputElement = kit(downcast<HTMLInputElement>(element));
     FormDelegateLog(inputElement);
     CallFormDelegate(m_webView, @selector(textDidChangeInTextField:inFrame:), inputElement, kit(element->document().frame()));
 }
@@ -766,7 +766,7 @@ bool WebEditorClient::doTextFieldCommandFromEvent(Element* element, KeyboardEven
     if (!isHTMLInputElement(element))
         return NO;
 
-    DOMHTMLInputElement* inputElement = kit(toHTMLInputElement(element));
+    DOMHTMLInputElement* inputElement = kit(downcast<HTMLInputElement>(element));
     FormDelegateLog(inputElement);
     if (SEL commandSelector = selectorForKeyEvent(event))
         return CallFormDelegateReturningBoolean(NO, m_webView, @selector(textField:doCommandBySelector:inFrame:), inputElement, commandSelector, kit(element->document().frame()));
@@ -778,7 +778,7 @@ void WebEditorClient::textWillBeDeletedInTextField(Element* element)
     if (!isHTMLInputElement(element))
         return;
 
-    DOMHTMLInputElement* inputElement = kit(toHTMLInputElement(element));
+    DOMHTMLInputElement* inputElement = kit(downcast<HTMLInputElement>(element));
     FormDelegateLog(inputElement);
     // We're using the deleteBackward selector for all deletion operations since the autofill code treats all deletions the same way.
     CallFormDelegateReturningBoolean(NO, m_webView, @selector(textField:doCommandBySelector:inFrame:), inputElement, @selector(deleteBackward:), kit(element->document().frame()));
@@ -789,7 +789,7 @@ void WebEditorClient::textDidChangeInTextArea(Element* element)
     if (!isHTMLTextAreaElement(element))
         return;
 
-    DOMHTMLTextAreaElement* textAreaElement = kit(toHTMLTextAreaElement(element));
+    DOMHTMLTextAreaElement* textAreaElement = kit(downcast<HTMLTextAreaElement>(element));
     FormDelegateLog(textAreaElement);
     CallFormDelegate(m_webView, @selector(textDidChangeInTextArea:inFrame:), textAreaElement, kit(element->document().frame()));
 }
index 09ddc1d..092e58d 100644 (file)
@@ -305,7 +305,7 @@ static HTMLFormElement* formElementFromDOMElement(DOMElement *element)
 static HTMLInputElement* inputElementFromDOMElement(DOMElement* element)
 {
     Element* node = core(element);
-    return node && isHTMLInputElement(node) ? toHTMLInputElement(node) : 0;
+    return node && isHTMLInputElement(node) ? downcast<HTMLInputElement>(node) : nullptr;
 }
 
 - (BOOL)elementDoesAutoComplete:(DOMElement *)element
index 51f7c21..82e9fc6 100644 (file)
@@ -1,3 +1,50 @@
+2014-09-23  Chris Dumez  <cdumez@apple.com>
+
+        Use downcast<HTML*Element>() instead of toHTML*Element()
+        https://bugs.webkit.org/show_bug.cgi?id=137007
+
+        Reviewed by Benjamin Poulain.
+
+        Use downcast<HTML*Element>() instead of toHTML*Element().
+
+        * DOMHTMLClasses.cpp:
+        (DOMHTMLDocument::URL):
+        (DOMHTMLDocument::body):
+        (DOMHTMLDocument::forms):
+        (DOMHTMLFormElement::action):
+        (DOMHTMLFormElement::method):
+        (DOMHTMLSelectElement::options):
+        (DOMHTMLSelectElement::activateItemAtIndex):
+        (DOMHTMLOptionElement::text):
+        (DOMHTMLOptionElement::label):
+        (DOMHTMLInputElement::form):
+        (DOMHTMLInputElement::disabled):
+        (DOMHTMLInputElement::readOnly):
+        (DOMHTMLInputElement::setType):
+        (DOMHTMLInputElement::value):
+        (DOMHTMLInputElement::setValue):
+        (DOMHTMLInputElement::setValueForUser):
+        (DOMHTMLInputElement::select):
+        (DOMHTMLInputElement::setSelectionStart):
+        (DOMHTMLInputElement::selectionStart):
+        (DOMHTMLInputElement::setSelectionEnd):
+        (DOMHTMLInputElement::selectionEnd):
+        (DOMHTMLInputElement::isTextField):
+        (DOMHTMLInputElement::replaceCharactersInRange):
+        (DOMHTMLInputElement::selectedRange):
+        (DOMHTMLInputElement::setAutofilled):
+        (DOMHTMLInputElement::isAutofilled):
+        (DOMHTMLInputElement::isUserEdited):
+        (DOMHTMLTextAreaElement::form):
+        (DOMHTMLTextAreaElement::value):
+        (DOMHTMLTextAreaElement::setValue):
+        (DOMHTMLTextAreaElement::select):
+        (DOMHTMLTextAreaElement::isUserEdited):
+        (DOMHTMLIFrameElement::contentFrame):
+        * WebFrame.cpp:
+        (formElementFromDOMElement):
+        (inputElementFromDOMElement):
+
 2014-09-21  Chris Dumez  <cdumez@apple.com>
 
         Generate Element casting helper functions
index b38c77a..59e0fb5 100644 (file)
@@ -250,7 +250,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::URL(
     if (!result)
         return E_POINTER;
 
-    *result = BString(toHTMLDocument(m_document)->url()).release();
+    *result = BString(downcast<HTMLDocument>(m_document)->url()).release();
     return S_OK;
 }
     
@@ -261,9 +261,9 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::body(
     if (!m_document || !m_document->isHTMLDocument())
         return E_FAIL;
 
-    HTMLDocument* htmlDoc = toHTMLDocument(m_document);
+    HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document);
     COMPtr<IDOMElement> domElement;
-    domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc->body()));
+    domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc.body()));
     if (domElement)
         return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) bodyElement);
     return E_FAIL;
@@ -304,8 +304,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::forms(
     if (!m_document || !m_document->isHTMLDocument())
         return E_FAIL;
 
-    HTMLDocument* htmlDoc = toHTMLDocument(m_document);
-    RefPtr<HTMLCollection> forms = htmlDoc->forms();
+    HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document);
+    RefPtr<HTMLCollection> forms = htmlDoc.forms();
     *collection = DOMHTMLCollection::createInstance(forms.get());
     return S_OK;
 }
@@ -560,7 +560,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLFormElement::action(
         /* [retval][out] */ BSTR* result)
 {
     ASSERT(m_element && isHTMLFormElement(m_element));
-    WTF::String actionString = toHTMLFormElement(m_element)->action();
+    WTF::String actionString = downcast<HTMLFormElement>(*m_element).action();
     *result = BString(actionString).release();
     return S_OK;
 }
@@ -590,7 +590,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLFormElement::method(
         /* [retval][out] */ BSTR* result)
 {
     ASSERT(m_element && isHTMLFormElement(m_element));
-    WTF::String methodString = toHTMLFormElement(m_element)->method();
+    WTF::String methodString = downcast<HTMLFormElement>(*m_element).method();
     *result = BString(methodString).release();
     return S_OK;
 }
@@ -702,13 +702,13 @@ HRESULT STDMETHODCALLTYPE DOMHTMLSelectElement::options(
         return E_POINTER;
 
     ASSERT(m_element);
-    HTMLSelectElement* selectElement = toHTMLSelectElement(m_element);
+    HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*m_element);
 
-    if (!selectElement->options())
+    if (!selectElement.options())
         return E_FAIL;
 
-    *result = 0;
-    RefPtr<HTMLOptionsCollection> options = selectElement->options();
+    *result = nullptr;
+    RefPtr<HTMLOptionsCollection> options = selectElement.options();
     *result = DOMHTMLOptionsCollection::createInstance(options.get());
     return S_OK;
 }
@@ -804,12 +804,12 @@ HRESULT STDMETHODCALLTYPE DOMHTMLSelectElement::activateItemAtIndex(
     /* [in] */ int index)
 {
     ASSERT(m_element);
-    HTMLSelectElement* selectElement = toHTMLSelectElement(m_element);
+    HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*m_element);
 
-    if (index >= selectElement->length())
+    if (index >= selectElement.length())
         return E_FAIL;
 
-    selectElement->setSelectedIndex(index);
+    selectElement.setSelectedIndex(index);
     return S_OK;
 }
 
@@ -860,9 +860,9 @@ HRESULT STDMETHODCALLTYPE DOMHTMLOptionElement::text(
 
     ASSERT(m_element);
     ASSERT(isHTMLOptionElement(m_element));
-    HTMLOptionElement* optionElement = toHTMLOptionElement(m_element);
+    HTMLOptionElement& optionElement = downcast<HTMLOptionElement>(*m_element);
 
-    *result = BString(optionElement->text()).release();
+    *result = BString(optionElement.text()).release();
     return S_OK;
 }
     
@@ -897,9 +897,9 @@ HRESULT STDMETHODCALLTYPE DOMHTMLOptionElement::label(
 
     ASSERT(m_element);
     ASSERT(isHTMLOptionElement(m_element));
-    HTMLOptionElement* optionElement = toHTMLOptionElement(m_element);
+    HTMLOptionElement& optionElement = downcast<HTMLOptionElement>(*m_element);
 
-    *result = BString(optionElement->label()).release();
+    *result = BString(optionElement.label()).release();
     return S_OK;
 }
     
@@ -991,11 +991,11 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::form(
 {
     if (!result)
         return E_POINTER;
-    *result = 0;
+    *result = nullptr;
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
     COMPtr<IDOMElement> domElement;
-    domElement.adoptRef(DOMHTMLElement::createInstance(inputElement->form()));
+    domElement.adoptRef(DOMHTMLElement::createInstance(inputElement.form()));
     if (domElement)
         return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) result);
     return E_FAIL;
@@ -1075,8 +1075,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::disabled(
         /* [retval][out] */ BOOL* result)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *result = inputElement->isDisabledFormControl() ? TRUE : FALSE;
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *result = inputElement.isDisabledFormControl() ? TRUE : FALSE;
     return S_OK;
 }
     
@@ -1119,8 +1119,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::readOnly(
         /* [retval][out] */ BOOL* result)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *result = inputElement->isReadOnly() ? TRUE : FALSE;
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *result = inputElement.isReadOnly() ? TRUE : FALSE;
     return S_OK;
 }
     
@@ -1184,9 +1184,9 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::setType(
         /* [in] */ BSTR type)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
     WTF::String typeString(type, SysStringLen(type));
-    inputElement->setType(typeString);
+    inputElement.setType(typeString);
     return S_OK;
 }
     
@@ -1208,8 +1208,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::value(
         /* [retval][out] */ BSTR* result)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    WTF::String valueString = inputElement->value();
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    WTF::String valueString = inputElement.value();
     *result = BString(valueString).release();
     if (valueString.length() && !*result)
         return E_OUTOFMEMORY;
@@ -1220,8 +1220,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::setValue(
         /* [in] */ BSTR value)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    inputElement->setValue(String((UChar*) value, SysStringLen(value)));
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    inputElement.setValue(String((UChar*) value, SysStringLen(value)));
     return S_OK;
 }
 
@@ -1230,16 +1230,16 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::setValueForUser(
 {
     ASSERT(m_element);
     ASSERT(isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    inputElement->setValueForUser(String(static_cast<UChar*>(value), SysStringLen(value)));
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    inputElement.setValueForUser(String(static_cast<UChar*>(value), SysStringLen(value)));
     return S_OK;
 }
 
 HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::select( void)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    inputElement->select();
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    inputElement.select();
     return S_OK;
 }
     
@@ -1253,8 +1253,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::setSelectionStart(
     /* [in] */ long start)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    inputElement->setSelectionStart(start);
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    inputElement.setSelectionStart(start);
     return S_OK;
 }
 
@@ -1262,8 +1262,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::selectionStart(
     /* [retval][out] */ long *start)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *start = inputElement->selectionStart();
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *start = inputElement.selectionStart();
     return S_OK;
 }
 
@@ -1271,8 +1271,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::setSelectionEnd(
     /* [in] */ long end)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    inputElement->setSelectionEnd(end);
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    inputElement.setSelectionEnd(end);
     return S_OK;
 }
 
@@ -1280,8 +1280,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::selectionEnd(
     /* [retval][out] */ long *end)
 {
     ASSERT(m_element && isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *end = inputElement->selectionEnd();
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *end = inputElement.selectionEnd();
     return S_OK;
 }
 
@@ -1292,8 +1292,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::isTextField(
 {
     ASSERT(m_element);
     ASSERT(isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *result = inputElement->isTextField() ? TRUE : FALSE;
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *result = inputElement.isTextField() ? TRUE : FALSE;
     return S_OK;
 }
 
@@ -1328,13 +1328,13 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::replaceCharactersInRange(
 
     ASSERT(m_element);
     ASSERT(isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
 
-    String newValue = inputElement->value();
+    String newValue = inputElement.value();
     String webCoreReplacementString(static_cast<UChar*>(replacementString), SysStringLen(replacementString));
     newValue.replace(startTarget, endTarget - startTarget, webCoreReplacementString);
-    inputElement->setValue(newValue);
-    inputElement->setSelectionRange(index, newValue.length());
+    inputElement.setValue(newValue);
+    inputElement.setSelectionRange(index, newValue.length());
 
     return S_OK;
 }
@@ -1345,9 +1345,9 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::selectedRange(
 {
     ASSERT(m_element);
     ASSERT(isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *start = inputElement->selectionStart();
-    *end = inputElement->selectionEnd();
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *start = inputElement.selectionStart();
+    *end = inputElement.selectionEnd();
     return S_OK;
 }
 
@@ -1356,8 +1356,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::setAutofilled(
 {
     ASSERT(m_element);
     ASSERT(isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    inputElement->setAutofilled(!!filled);
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    inputElement.setAutofilled(!!filled);
     return S_OK;
 }
 
@@ -1366,8 +1366,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::isAutofilled(
 {
     ASSERT(m_element);
     ASSERT(isHTMLInputElement(m_element));
-    HTMLInputElement* inputElement = toHTMLInputElement(m_element);
-    *result = inputElement->isAutofilled() ? TRUE : FALSE;
+    HTMLInputElement& inputElement = downcast<HTMLInputElement>(*m_element);
+    *result = inputElement.isAutofilled() ? TRUE : FALSE;
     return S_OK;
 }
 
@@ -1384,7 +1384,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::isUserEdited(
     BOOL textField = FALSE;
     if (FAILED(isTextField(&textField)) || !textField)
         return S_OK;
-    if (toHTMLInputElement(m_element)->lastChangeWasUserEdit())
+    if (downcast<HTMLInputElement>(*m_element).lastChangeWasUserEdit())
         *result = TRUE;
     return S_OK;
 }
@@ -1428,9 +1428,9 @@ HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::form(
         return E_POINTER;
     *result = 0;
     ASSERT(m_element && isHTMLTextAreaElement(m_element));
-    HTMLTextAreaElement* textareaElement = toHTMLTextAreaElement(m_element);
+    HTMLTextAreaElement& textareaElement = downcast<HTMLTextAreaElement>(*m_element);
     COMPtr<IDOMElement> domElement;
-    domElement.adoptRef(DOMHTMLElement::createInstance(textareaElement->form()));
+    domElement.adoptRef(DOMHTMLElement::createInstance(textareaElement.form()));
     if (domElement)
         return domElement->QueryInterface(IID_IDOMHTMLElement, (void**) result);
     return E_FAIL;
@@ -1545,8 +1545,8 @@ HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::value(
         /* [retval][out] */ BSTR* result)
 {
     ASSERT(m_element && isHTMLTextAreaElement(m_element));
-    HTMLTextAreaElement* textareaElement = toHTMLTextAreaElement(m_element);
-    WTF::String valueString = textareaElement->value();
+    HTMLTextAreaElement& textareaElement = downcast<HTMLTextAreaElement>(*m_element);
+    WTF::String valueString = textareaElement.value();
     *result = BString(valueString).release();
     if (valueString.length() && !*result)
         return E_OUTOFMEMORY;
@@ -1557,16 +1557,16 @@ HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::setValue(
         /* [in] */ BSTR value)
 {
     ASSERT(m_element && isHTMLTextAreaElement(m_element));
-    HTMLTextAreaElement* textareaElement = toHTMLTextAreaElement(m_element);
-    textareaElement->setValue(String((UChar*) value, SysStringLen(value)));
+    HTMLTextAreaElement& textareaElement = downcast<HTMLTextAreaElement>(*m_element);
+    textareaElement.setValue(String((UChar*) value, SysStringLen(value)));
     return S_OK;
 }
     
 HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::select( void)
 {
     ASSERT(m_element && isHTMLTextAreaElement(m_element));
-    HTMLTextAreaElement* textareaElement = toHTMLTextAreaElement(m_element);
-    textareaElement->select();
+    HTMLTextAreaElement& textareaElement = downcast<HTMLTextAreaElement>(*m_element);
+    textareaElement.select();
     return S_OK;
 }
 
@@ -1580,7 +1580,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::isUserEdited(
 
     *result = FALSE;
     ASSERT(m_element && isHTMLTextAreaElement(m_element));
-    if (toHTMLTextAreaElement(m_element)->lastChangeWasUserEdit())
+    if (downcast<HTMLTextAreaElement>(*m_element).lastChangeWasUserEdit())
         *result = TRUE;
     return S_OK;
 }
@@ -1606,10 +1606,10 @@ HRESULT STDMETHODCALLTYPE DOMHTMLIFrameElement::contentFrame(
 {
     if (!result)
         return E_POINTER;
-    *result = 0;
+    *result = nullptr;
     ASSERT(m_element);
-    HTMLIFrameElement* iFrameElement = toHTMLIFrameElement(m_element);
-    COMPtr<IWebFrame> webFrame = kit(iFrameElement->contentFrame());
+    HTMLIFrameElement& iFrameElement = downcast<HTMLIFrameElement>(*m_element);
+    COMPtr<IWebFrame> webFrame = kit(iFrameElement.contentFrame());
     if (!webFrame)
         return E_FAIL;
     return webFrame.copyRefTo(result);
index 788a2e8..8c6c45c 100644 (file)
@@ -194,7 +194,7 @@ static Element *elementFromDOMElement(IDOMElement *element)
 static HTMLFormElement *formElementFromDOMElement(IDOMElement *element)
 {
     if (!element)
-        return 0;
+        return nullptr;
 
     IDOMElementPrivate* elePriv;
     HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
@@ -203,15 +203,15 @@ static HTMLFormElement *formElementFromDOMElement(IDOMElement *element)
         hr = elePriv->coreElement((void**)&ele);
         elePriv->Release();
         if (SUCCEEDED(hr) && ele && isHTMLFormElement(ele))
-            return toHTMLFormElement(ele);
+            return downcast<HTMLFormElement>(ele);
     }
-    return 0;
+    return nullptr;
 }
 
 static HTMLInputElement* inputElementFromDOMElement(IDOMElement* element)
 {
     if (!element)
-        return 0;
+        return nullptr;
 
     IDOMElementPrivate* elePriv;
     HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
@@ -220,9 +220,9 @@ static HTMLInputElement* inputElementFromDOMElement(IDOMElement* element)
         hr = elePriv->coreElement((void**)&ele);
         elePriv->Release();
         if (SUCCEEDED(hr) && ele && isHTMLInputElement(ele))
-            return toHTMLInputElement(ele);
+            return downcast<HTMLInputElement>(ele);
     }
-    return 0;
+    return nullptr;
 }
 
 // WebFramePrivate ------------------------------------------------------------
index 60c6cba..5945f45 100644 (file)
@@ -1,3 +1,48 @@
+2014-09-23  Chris Dumez  <cdumez@apple.com>
+
+        Use downcast<HTML*Element>() instead of toHTML*Element()
+        https://bugs.webkit.org/show_bug.cgi?id=137007
+
+        Reviewed by Benjamin Poulain.
+
+        Use downcast<HTML*Element>() instead of toHTML*Element().
+
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::InjectedBundleNodeHandle::setHTMLInputElementValueForUser):
+        (WebKit::InjectedBundleNodeHandle::isHTMLInputElementAutofilled):
+        (WebKit::InjectedBundleNodeHandle::setHTMLInputElementAutofilled):
+        (WebKit::InjectedBundleNodeHandle::htmlInputElementLastChangeWasUserEdit):
+        (WebKit::InjectedBundleNodeHandle::htmlTextAreaElementLastChangeWasUserEdit):
+        (WebKit::InjectedBundleNodeHandle::isTextField):
+        (WebKit::InjectedBundleNodeHandle::htmlTableCellElementCellAbove):
+        (WebKit::InjectedBundleNodeHandle::htmlIFrameElementContentFrame):
+        * WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
+        (WebKit::PDFPluginChoiceAnnotation::commit):
+        * WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
+        (WebKit::PDFPluginTextAnnotation::createAnnotationElement):
+        (WebKit::PDFPluginTextAnnotation::value):
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::initializePlugin):
+        (WebKit::PluginView::pluginSnapshotTimerFired):
+        (WebKit::PluginView::pluginDidReceiveUserInteraction):
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::focusedElementChanged):
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::textFieldDidBeginEditing):
+        (WebKit::WebEditorClient::textFieldDidEndEditing):
+        (WebKit::WebEditorClient::textDidChangeInTextField):
+        (WebKit::WebEditorClient::textDidChangeInTextArea):
+        (WebKit::WebEditorClient::doTextFieldCommandFromEvent):
+  &