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: http://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/MouseRelatedEvent.cpp b/Source/WebCore/dom/MouseRelatedEvent.cpp
index 2d9b49a..853714d 100644
--- a/Source/WebCore/dom/MouseRelatedEvent.cpp
+++ b/Source/WebCore/dom/MouseRelatedEvent.cpp
@@ -146,19 +146,19 @@
void MouseRelatedEvent::computeRelativePosition()
{
- auto targetNode = target() ? target()->toNode() : nullptr;
- if (!targetNode)
+ if (!is<Node>(target()))
return;
+ auto& targetNode = downcast<Node>(*target());
// Compute coordinates that are based on the target.
m_layerLocation = m_pageLocation;
m_offsetLocation = m_pageLocation;
// Must have an updated render tree for this math to work correctly.
- targetNode->document().updateLayoutIgnorePendingStylesheets();
+ targetNode.document().updateLayoutIgnorePendingStylesheets();
// Adjust offsetLocation to be relative to the target's position.
- if (RenderObject* r = targetNode->renderer()) {
+ if (RenderObject* r = targetNode.renderer()) {
m_offsetLocation = LayoutPoint(r->absoluteToLocal(absoluteLocation(), UseTransforms));
float scaleFactor = 1 / documentToAbsoluteScaleFactor();
if (scaleFactor != 1.0f)
@@ -169,7 +169,7 @@
// FIXME: event.layerX and event.layerY are poorly defined,
// and probably don't always correspond to RenderLayer offsets.
// https://bugs.webkit.org/show_bug.cgi?id=21868
- Node* n = targetNode.get();
+ Node* n = &targetNode;
while (n && !n->renderer())
n = n->parentNode();