More is<> and downcast<>, less static_cast<>
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2017 06:12:09 +0000 (06:12 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2017 06:12:09 +0000 (06:12 +0000)
commitc9ac12b71dd4573bbf963ea851c5a29bb072ad51
treebfeeb11f9f29dc711cfd15d8d0590a0f13e61a58
parentb3155eadf378de58860bc85dab0f0f87f70dec2c
More is<> and downcast<>, less static_cast<>
https://bugs.webkit.org/show_bug.cgi?id=179600

Reviewed by Chris Dumez.

Source/JavaScriptCore:

* runtime/JSString.h:
(JSC::jsSubstring): Removed unneeded static_cast; length already returns unsigned.
(JSC::jsSubstringOfResolved): Ditto.

Source/WebCore:

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract): Use downcast instead of static_cast.
(WebCore::FetchBody::bodyAsFormData const): Ditto.
* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::putOrAdd): Ditto.
* Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
(WebCore::CanvasCaptureMediaStreamTrack::Source::canvasChanged): Ditto.
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::libWebRTCProvider): Ditto.

* accessibility/AccessibilityMediaControls.cpp:
(WebCore::AccessibilityMediaTimeDisplay::stringValue const): Got rid of local
variable and used std::abs instead of fabsf. Did not use downcast here because
it doesn't exist for this class.

* bindings/js/JSEventTargetCustom.h:
(WebCore::IDLOperation<JSEventTarget>::call): Use downcast instead of toDOMWindow.
* dom/DocumentEventQueue.cpp:
(WebCore::DocumentEventQueue::dispatchEvent): Ditto.

* dom/Element.h: Added is/downcast for EventTarget.

* dom/EventContext.cpp:
(WebCore::TouchEventContext::checkReachability const): Use downcast instead
of toNode.
* dom/EventContext.h:
(WebCore::EventContext::isUnreachableNode const): Ditto.
* dom/EventPath.cpp:
(WebCore::shouldEventCrossShadowBoundary): Ditto.
(WebCore::EventPath::setRelatedTarget): Ditto.
(WebCore::EventPath::retargetTouch): Ditto.
(WebCore::EventPath::EventPath): Ditto.

* dom/EventTarget.cpp:
(WebCore::EventTarget::toNode): Deleted.
(WebCore::EventTarget::isNode const): Added.
(WebCore::EventTarget::toDOMWindow): Deleted.
(WebCore::EventTarget::isMessagePort const): Deleted. This was not used.
(WebCore::EventTarget::addEventListener): Use downcast instead of toDOMWindow
and toNode.
* dom/EventTarget.h: Updated for the above.

* dom/MessagePort.h: Deleted unused isMessagePort.

* dom/MouseEvent.cpp:
(WebCore::MouseEvent::toElement const): Use downcast instead of toNode.
Also refactored to make function a little smaller.
(WebCore::MouseEvent::fromElement const): Ditto.

* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::computeRelativePosition): Use downcast
instead of toNode.

* dom/Node.cpp:
(WebCore::Node::isNode const): Added.
(WebCore::Node::toNode): Deleted.
* dom/Node.h: Updated for the above. Also added SPECIALIZE_TYPE_TRAITS
so we can do is/downcast.

* dom/ScopedEventQueue.cpp:
(WebCore::ScopedEventQueue::enqueueEvent): Use is instead of toNode.
(WebCore::ScopedEventQueue::dispatchEvent const): Use downcast instead of toNode.

* dom/make_names.pl:
(printTypeHelpers): Added support for is/downcast from EventTarget.

* editing/Editor.cpp:
(WebCore::Editor::selectionForCommand): Use is/downcast instead of toNode.
* editing/EditorCommand.cpp:
(WebCore::targetFrame): Ditto.
* html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition): Ditto.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::createContextWebGL): Use downcast instead of
static_cast.
(WebCore::HTMLCanvasElement::getContextWebGL): Ditto.
(WebCore::HTMLCanvasElement::getImageData): Ditto.

* html/HTMLElement.h: Added support for is/downcast from EventTarget.

* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::handleLocalEvents): Use is instead of toNode.
(WebCore::submitElementFromEvent): Deleted. Was a duplicate of findSubmitButton.
(WebCore::HTMLFormElement::prepareForSubmission): Rewrote code that calls
submitElementFromEvent to call findSubmitButton instead. Also don't bother
finding the submit button unless we are going to validate, since all we do
after finding it is reconsider whether we should validate.
(WebCore::HTMLFormElement::findSubmitButton const): Rewrote to use is,
downcast, and lineageOfType rather than a handwritten loop and toNode.
Relies on the fact that the target is an element, never a text node.

* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::defaultEventHandler): Use is and downcast instead
of toNode.

* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::partOfSnapshotOverlay const): Changed argument
type to EventTarget so we can do the type checking and casting here instead of at
each of the callers.
* html/HTMLPlugInImageElement.h: Updated for the above.

* html/HTMLSummaryElement.cpp:
(WebCore::isClickableControl): Changed argument type to EventTarget so we can do
the type checking and casting here instead of at each of the callers.
(WebCore::HTMLSummaryElement::defaultEventHandler): Removed call to toNode.

* html/HTMLTextFormControlElement.h: Added support for is/downcast from EventTarget.

* html/MediaDocument.cpp:
(WebCore::MediaDocument::defaultEventHandler): Use is/downcast instead of toNode.
* html/RangeInputType.cpp:
(WebCore::RangeInputType::handleMouseDownEvent): Ditto.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlVolumeSliderContainerElement::defaultEventHandler): Ditto.
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Ditto.
Also use get instead of find/end.

* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::containsRelatedTarget): Use is/downcast instead of toNode.
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::dispatchEventAsContextMenuEvent): Ditto.
* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::didAddEventListener): Ditto.
(WebCore::InspectorDOMAgent::willRemoveEventListener): Ditto.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::maybeCreateContextMenu): Ditto.

* page/DOMWindow.cpp:
(WebCore::DOMWindow::toDOMWindow): Deleted.
* page/DOMWindow.h: Updated for the above. Also added SPECIALIZE_TYPE_TRAITS
so we can do is/downcast.

* page/EventHandler.cpp:
(WebCore::EventHandler::handleTouchEvent): Use is/downcast instead of toNode.

* platform/graphics/WidthCache.h:
(WebCore::WidthCache::add): Removed unneeded static_cast; length already returns unsigned.

* rendering/RenderSnapshottedPlugIn.cpp:
(WebCore::RenderSnapshottedPlugIn::handleEvent): Removed unneeded toNode now that
partOfSnapshotOverlay takes an EventTarget.

Source/WebKit:

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMPrivate.cpp:
(WebKit::wrap): Use is/downcast.
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::handleKeyboardEvent): Ditto.
* WebProcess/WebCoreSupport/wpe/WebEditorClientWPE.cpp:
(WebKit::WebEditorClient::handleKeyboardEvent): Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::handleEditingKeyboardEvent): Ditto.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::frameForEvent): Ditto.

Source/WebKitLegacy/mac:

* DOM/DOM.mm:
(kit): Use is/downcast.
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::handleKeyboardEvent): Ditto.
(WebEditorClient::handleInputMethodKeydown): Ditto.
* WebView/WebHTMLView.mm:
(-[WebHTMLView _interpretKeyEvent:savingCommands:]): Ditto.

Source/WebKitLegacy/win:

* WebView.cpp:
(WebView::handleEditingKeyboardEvent): Use downcast.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
58 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSString.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp
Source/WebCore/accessibility/AccessibilityMediaControls.cpp
Source/WebCore/bindings/js/JSEventTargetCustom.h
Source/WebCore/dom/DocumentEventQueue.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/EventContext.cpp
Source/WebCore/dom/EventContext.h
Source/WebCore/dom/EventPath.cpp
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/EventTarget.h
Source/WebCore/dom/MessagePort.h
Source/WebCore/dom/MouseEvent.cpp
Source/WebCore/dom/MouseRelatedEvent.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/ScopedEventQueue.cpp
Source/WebCore/dom/make_names.pl
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/EditorCommand.cpp
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/HTMLElement.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLLabelElement.cpp
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/html/HTMLPlugInImageElement.h
Source/WebCore/html/HTMLSummaryElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.h
Source/WebCore/html/MediaDocument.cpp
Source/WebCore/html/RangeInputType.cpp
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MediaControls.cpp
Source/WebCore/inspector/InspectorFrontendHost.cpp
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/EventHandler.cpp
Source/WebCore/platform/graphics/WidthCache.h
Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMPrivate.cpp
Source/WebKit/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp
Source/WebKit/WebProcess/WebCoreSupport/wpe/WebEditorClientWPE.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/DOM.mm
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebView.cpp