haikuwebkit/Source/WebCore/dom/EventPath.cpp

420 lines
16 KiB
C++
Raw Permalink Normal View History

/*
* Copyright (C) 2013 Google Inc. All rights reserved.
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
* Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "EventPath.h"
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
#include "DOMWindow.h"
#include "Event.h"
#include "EventContext.h"
#include "EventNames.h"
Refactoring: Pull all fullscreen code out of Document and into its own helper class https://bugs.webkit.org/show_bug.cgi?id=197017 Reviewed by Eric Carlson. Source/WebCore: * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/CSSDefaultStyleSheets.cpp: (WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement): * css/SelectorCheckerTestFunctions.h: (WebCore::matchesFullScreenPseudoClass): (WebCore::matchesFullScreenAnimatingFullScreenTransitionPseudoClass): (WebCore::matchesFullScreenDocumentPseudoClass): (WebCore::matchesFullScreenControlsHiddenPseudoClass): * dom/Document.cpp: (WebCore::Document::removedLastRef): (WebCore::Document::prepareForDestruction): (WebCore::Document::nodeChildrenWillBeRemoved): (WebCore::Document::nodeWillBeRemoved): (WebCore::isAttributeOnAllOwners): Deleted. (WebCore::Document::fullScreenIsAllowedForElement const): Deleted. (WebCore::Document::requestFullScreenForElement): Deleted. (WebCore::Document::webkitCancelFullScreen): Deleted. (WebCore::Document::webkitExitFullscreen): Deleted. (WebCore::Document::webkitFullscreenEnabled const): Deleted. (WebCore::unwrapFullScreenRenderer): Deleted. (WebCore::Document::webkitWillEnterFullScreen): Deleted. (WebCore::Document::webkitDidEnterFullScreen): Deleted. (WebCore::Document::webkitWillExitFullScreen): Deleted. (WebCore::Document::webkitDidExitFullScreen): Deleted. (WebCore::Document::setFullScreenRenderer): Deleted. (WebCore::Document::dispatchFullScreenChangeEvents): Deleted. (WebCore::Document::dispatchFullScreenChangeOrErrorEvent): Deleted. (WebCore::Document::fullScreenElementRemoved): Deleted. (WebCore::Document::adjustFullScreenElementOnNodeRemoval): Deleted. (WebCore::Document::isAnimatingFullScreen const): Deleted. (WebCore::Document::setAnimatingFullScreen): Deleted. (WebCore::Document::areFullscreenControlsHidden const): Deleted. (WebCore::Document::setFullscreenControlsHidden): Deleted. (WebCore::Document::clearFullscreenElementStack): Deleted. (WebCore::Document::popFullscreenElementStack): Deleted. (WebCore::Document::pushFullscreenElementStack): Deleted. (WebCore::Document::addDocumentToFullScreenChangeEventQueue): Deleted. * dom/Document.h: (WebCore::Document::fullscreenManager): (WebCore::Document::webkitIsFullScreen const): Deleted. (WebCore::Document::webkitFullScreenKeyboardInputAllowed const): Deleted. (WebCore::Document::webkitCurrentFullScreenElement const): Deleted. (WebCore::Document::webkitCurrentFullScreenElementForBindings const): Deleted. (WebCore::Document::fullScreenRenderer const): Deleted. (WebCore::Document::webkitFullscreenElement const): Deleted. (WebCore::Document::webkitFullscreenElementForBindings const): Deleted. * dom/Document.idl: * dom/DocumentFullscreen.h: (WebCore::DocumentFullscreen::webkitFullscreenEnabled): (WebCore::DocumentFullscreen::webkitFullscreenElement): (WebCore::DocumentFullscreen::webkitExitFullscreen): (WebCore::DocumentFullscreen::webkitIsFullScreen): (WebCore::DocumentFullscreen::webkitFullScreenKeyboardInputAllowed): (WebCore::DocumentFullscreen::webkitCurrentFullScreenElement): (WebCore::DocumentFullscreen::webkitCancelFullScreen): * dom/DocumentFullscreen.idl: * dom/Element.cpp: (WebCore::Element::webkitRequestFullscreen): * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): * dom/FullscreenManager.cpp: Added. (WebCore::isAttributeOnAllOwners): (WebCore::FullscreenManager::FullscreenManager): (WebCore::FullscreenManager::fullscreenIsAllowedForElement const): (WebCore::FullscreenManager::requestFullscreenForElement): (WebCore::FullscreenManager::cancelFullscreen): (WebCore::FullscreenManager::requestExitFullscreen): (WebCore::FullscreenManager::exitFullscreen): (WebCore::FullscreenManager::isFullscreenEnabled const): (WebCore::unwrapFullscreenRenderer): (WebCore::FullscreenManager::willEnterFullscreen): (WebCore::FullscreenManager::didEnterFullscreen): (WebCore::FullscreenManager::willExitFullscreen): (WebCore::FullscreenManager::didExitFullscreen): (WebCore::FullscreenManager::setFullscreenRenderer): (WebCore::FullscreenManager::dispatchFullscreenChangeEvents): (WebCore::FullscreenManager::dispatchFullscreenChangeOrErrorEvent): (WebCore::FullscreenManager::fullscreenElementRemoved): (WebCore::FullscreenManager::adjustFullscreenElementOnNodeRemoval): (WebCore::FullscreenManager::isAnimatingFullscreen const): (WebCore::FullscreenManager::setAnimatingFullscreen): (WebCore::FullscreenManager::areFullscreenControlsHidden const): (WebCore::FullscreenManager::setFullscreenControlsHidden): (WebCore::FullscreenManager::clear): (WebCore::FullscreenManager::emptyEventQueue): (WebCore::FullscreenManager::clearFullscreenElementStack): (WebCore::FullscreenManager::popFullscreenElementStack): (WebCore::FullscreenManager::pushFullscreenElementStack): (WebCore::FullscreenManager::addDocumentToFullscreenChangeEventQueue): * dom/FullscreenManager.h: Added. (WebCore::FullscreenManager::document): (WebCore::FullscreenManager::document const): (WebCore::FullscreenManager::topDocument const): (WebCore::FullscreenManager::page const): (WebCore::FullscreenManager::frame const): (WebCore::FullscreenManager::documentElement const): (WebCore::FullscreenManager::hasLivingRenderTree const): (WebCore::FullscreenManager::pageCacheState const): (WebCore::FullscreenManager::scheduleFullStyleRebuild): (WebCore::FullscreenManager::fullscreenElement const): (WebCore::FullscreenManager::isFullscreen const): (WebCore::FullscreenManager::isFullscreenKeyboardInputAllowed const): (WebCore::FullscreenManager::currentFullscreenElement const): (WebCore::FullscreenManager::fullscreenRenderer const): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::isFullscreen const): (WebCore::HTMLMediaElement::isStandardFullscreen const): (WebCore::HTMLMediaElement::enterFullscreen): (WebCore::HTMLMediaElement::exitFullscreen): * html/MediaElementSession.cpp: (WebCore::MediaElementSession::canShowControlsManager const): * html/shadow/MediaControlElements.cpp: (WebCore::MediaControlFullscreenButtonElement::defaultEventHandler): * inspector/agents/InspectorDOMAgent.cpp: * page/EventHandler.cpp: (WebCore::EventHandler::isKeyEventAllowedInFullScreen const): (WebCore::EventHandler::internalKeyEvent): * page/Page.cpp: (WebCore::Page::setFullscreenControlsHidden): * rendering/RenderFullScreen.cpp: (WebCore::RenderFullScreen::wrapNewRenderer): (WebCore::RenderFullScreen::wrapExistingRenderer): * rendering/RenderLayerCompositor.cpp: (WebCore::isDescendantOfFullScreenLayer): * rendering/updating/RenderTreeBuilder.h: * rendering/updating/RenderTreeBuilderInline.cpp: (WebCore::RenderTreeBuilder::Inline::splitInlines): * rendering/updating/RenderTreeUpdater.cpp: (WebCore::RenderTreeUpdater::createRenderer): * style/StyleSharingResolver.cpp: (WebCore::Style::SharingResolver::canShareStyleWithElement const): * testing/Internals.cpp: (WebCore::Internals::webkitWillEnterFullScreenForElement): (WebCore::Internals::webkitDidEnterFullScreenForElement): (WebCore::Internals::webkitWillExitFullScreenForElement): (WebCore::Internals::webkitDidExitFullScreenForElement): (WebCore::Internals::isAnimatingFullScreen const): Source/WebKit: * WebProcess/FullScreen/WebFullScreenManager.cpp: (WebKit::WebFullScreenManager::willEnterFullScreen): (WebKit::WebFullScreenManager::didEnterFullScreen): (WebKit::WebFullScreenManager::willExitFullScreen): (WebKit::WebFullScreenManager::didExitFullScreen): (WebKit::WebFullScreenManager::setAnimatingFullScreen): (WebKit::WebFullScreenManager::requestExitFullScreen): * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp: (webkit_dom_document_webkit_cancel_fullscreen): (webkit_dom_document_webkit_exit_fullscreen): (webkit_dom_document_get_webkit_is_fullscreen): (webkit_dom_document_get_webkit_fullscreen_keyboard_input_allowed): (webkit_dom_document_get_webkit_current_fullscreen_element): (webkit_dom_document_get_webkit_fullscreen_element): * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::createWindow): Source/WebKitLegacy/mac: * DOM/DOMDocument.mm: (-[DOMDocument webkitIsFullScreen]): (-[DOMDocument webkitFullScreenKeyboardInputAllowed]): (-[DOMDocument webkitCurrentFullScreenElement]): (-[DOMDocument webkitFullscreenEnabled]): (-[DOMDocument webkitFullscreenElement]): (-[DOMDocument webkitCancelFullScreen]): (-[DOMDocument webkitExitFullscreen]): * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::createWindow): * WebCoreSupport/WebKitFullScreenListener.mm: (-[WebKitFullScreenListener webkitWillEnterFullScreen]): (-[WebKitFullScreenListener webkitDidEnterFullScreen]): (-[WebKitFullScreenListener webkitWillExitFullScreen]): (-[WebKitFullScreenListener webkitDidExitFullScreen]): * WebView/WebFullScreenController.mm: (-[WebFullScreenController enterFullScreen:]): (-[WebFullScreenController finishedEnterFullScreenAnimation:]): (-[WebFullScreenController requestExitFullScreen]): (-[WebFullScreenController exitFullScreen]): (-[WebFullScreenController finishedExitFullScreenAnimation:]): (-[WebFullScreenController _manager]): * WebView/WebView.mm: (-[WebView _didStartProvisionalLoadForFrame:]): Source/WebKitLegacy/win: * WebCoreSupport/WebChromeClient.cpp: (WebChromeClient::createWindow): * WebView.cpp: (WebView::fullScreenClientWillEnterFullScreen): (WebView::fullScreenClientDidEnterFullScreen): (WebView::fullScreenClientWillExitFullScreen): (WebView::fullScreenClientDidExitFullScreen): Canonical link: https://commits.webkit.org/211322@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244440 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-18 22:16:54 +00:00
#include "FullscreenManager.h"
#include "HTMLSlotElement.h"
WebCore should build successfully even with -DENABLE_UNIFIED_BUILDS=OFF https://bugs.webkit.org/show_bug.cgi?id=196762 Reviewed by Ryosuke Niwa. * Modules/indexeddb/IDBCursor.h: * Modules/indexeddb/client/IDBConnectionToServer.cpp: * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h: * Modules/websockets/WebSocketFrame.cpp: * accessibility/AccessibilityARIAGridRow.cpp: (WebCore::AccessibilityARIAGridRow::parentTable const): * accessibility/AccessibilityObject.cpp: * accessibility/AccessibilityRenderObject.cpp: * animation/CSSAnimation.cpp: * animation/DeclarativeAnimation.cpp: * bindings/js/DOMGCOutputConstraint.h: * bindings/js/JSCanvasRenderingContext2DCustom.cpp: (WebCore::root): (WebCore::JSCanvasRenderingContext2DOwner::isReachableFromOpaqueRoots): (WebCore::JSCanvasRenderingContext2D::visitAdditionalChildren): * bindings/js/JSDOMConvertNumbers.cpp: * bindings/js/JSDOMWindowCustom.cpp: * bindings/js/JSExtendableMessageEventCustom.cpp: * bindings/js/SerializedScriptValue.cpp: * css/CSSFontFaceSource.cpp: * css/CSSFontFaceSource.h: * css/MediaQueryMatcher.h: * css/parser/CSSPropertyParserHelpers.cpp: * dom/DocumentParser.cpp: * dom/EventPath.cpp: * dom/MouseEvent.h: * dom/SpectreGadget.cpp: * dom/SpectreGadget.h: * editing/ChangeListTypeCommand.cpp: * editing/EditAction.cpp: * editing/ReplaceSelectionCommand.cpp: * editing/TextGranularity.h: * html/HTMLFormControlsCollection.cpp: * html/HTMLImageElement.cpp: * html/canvas/CanvasRenderingContext2DBase.cpp: * inspector/InspectorController.cpp: * inspector/agents/InspectorApplicationCacheAgent.cpp: * inspector/agents/InspectorCanvasAgent.cpp: * inspector/agents/WebHeapAgent.cpp: * inspector/agents/page/PageAuditAgent.cpp: * inspector/agents/page/PageConsoleAgent.cpp: * inspector/agents/page/PageNetworkAgent.cpp: * inspector/agents/worker/WorkerAuditAgent.cpp: * loader/CrossOriginAccessControl.h: * loader/CrossOriginPreflightResultCache.h: * loader/NavigationAction.cpp: * loader/ResourceLoadObserver.cpp: * page/FrameTree.cpp: * page/IntersectionObserver.cpp: * page/PageConfiguration.cpp: * page/PerformanceResourceTiming.cpp: * page/ResizeObservation.cpp: * page/UndoManager.cpp: * plugins/PluginData.cpp: * rendering/Grid.h: * rendering/GridBaselineAlignment.cpp: * rendering/GridBaselineAlignment.h: * rendering/GridLayoutFunctions.cpp: * rendering/GridLayoutFunctions.h: * rendering/GridTrackSizingAlgorithm.h: * rendering/RenderDeprecatedFlexibleBox.cpp: * rendering/RenderFlexibleBox.cpp: * rendering/RenderIFrame.cpp: * rendering/RenderLayerFilters.cpp: * rendering/TextDecorationPainter.cpp: * rendering/TextDecorationPainter.h: * rendering/TextPainter.cpp: * rendering/TextPainter.h: * rendering/style/StyleRareNonInheritedData.cpp: * rendering/style/StyleRareNonInheritedData.h: * rendering/svg/SVGRenderSupport.h: * rendering/updating/RenderTreeBuilder.cpp: * rendering/updating/RenderTreeBuilderSVG.cpp: * style/InlineTextBoxStyle.cpp: * style/InlineTextBoxStyle.h: * style/StylePendingResources.cpp: * svg/SVGMatrix.h: * svg/SVGViewSpec.h: * svg/SVGZoomAndPan.h: * workers/WorkerScriptLoader.cpp: * workers/WorkerScriptLoader.h: * workers/service/ServiceWorker.cpp: * workers/service/ServiceWorkerClientData.cpp: * workers/service/ServiceWorkerClients.cpp: * workers/service/ServiceWorkerClients.h: * workers/service/ServiceWorkerGlobalScope.cpp: * workers/service/ServiceWorkerJob.cpp: * workers/service/ServiceWorkerProvider.cpp: * workers/service/context/ServiceWorkerFetch.cpp: * workers/service/context/ServiceWorkerInspectorProxy.h: * workers/service/context/ServiceWorkerThread.cpp: * workers/service/context/ServiceWorkerThreadProxy.cpp: * workers/service/server/SWServerJobQueue.cpp: * workers/service/server/SWServerToContextConnection.cpp: * workers/service/server/SWServerWorker.cpp: * workers/service/server/SWServerWorker.h: * worklets/Worklet.h: Canonical link: https://commits.webkit.org/211049@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244115 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-10 16:53:41 +00:00
#include "MouseEvent.h"
#include "Node.h"
#include "PseudoElement.h"
#include "ShadowRoot.h"
#include "TouchEvent.h"
namespace WebCore {
static inline bool shouldEventCrossShadowBoundary(Event& event, ShadowRoot& shadowRoot, EventTarget& target)
{
#if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
// Video-only full screen is a mode where we use the shadow DOM as an implementation
// detail that should not be detectable by the web content.
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. Canonical link: https://commits.webkit.org/195627@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-13 06:12:09 +00:00
if (is<Node>(target)) {
Refactoring: Pull all fullscreen code out of Document and into its own helper class https://bugs.webkit.org/show_bug.cgi?id=197017 Reviewed by Eric Carlson. Source/WebCore: * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/CSSDefaultStyleSheets.cpp: (WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement): * css/SelectorCheckerTestFunctions.h: (WebCore::matchesFullScreenPseudoClass): (WebCore::matchesFullScreenAnimatingFullScreenTransitionPseudoClass): (WebCore::matchesFullScreenDocumentPseudoClass): (WebCore::matchesFullScreenControlsHiddenPseudoClass): * dom/Document.cpp: (WebCore::Document::removedLastRef): (WebCore::Document::prepareForDestruction): (WebCore::Document::nodeChildrenWillBeRemoved): (WebCore::Document::nodeWillBeRemoved): (WebCore::isAttributeOnAllOwners): Deleted. (WebCore::Document::fullScreenIsAllowedForElement const): Deleted. (WebCore::Document::requestFullScreenForElement): Deleted. (WebCore::Document::webkitCancelFullScreen): Deleted. (WebCore::Document::webkitExitFullscreen): Deleted. (WebCore::Document::webkitFullscreenEnabled const): Deleted. (WebCore::unwrapFullScreenRenderer): Deleted. (WebCore::Document::webkitWillEnterFullScreen): Deleted. (WebCore::Document::webkitDidEnterFullScreen): Deleted. (WebCore::Document::webkitWillExitFullScreen): Deleted. (WebCore::Document::webkitDidExitFullScreen): Deleted. (WebCore::Document::setFullScreenRenderer): Deleted. (WebCore::Document::dispatchFullScreenChangeEvents): Deleted. (WebCore::Document::dispatchFullScreenChangeOrErrorEvent): Deleted. (WebCore::Document::fullScreenElementRemoved): Deleted. (WebCore::Document::adjustFullScreenElementOnNodeRemoval): Deleted. (WebCore::Document::isAnimatingFullScreen const): Deleted. (WebCore::Document::setAnimatingFullScreen): Deleted. (WebCore::Document::areFullscreenControlsHidden const): Deleted. (WebCore::Document::setFullscreenControlsHidden): Deleted. (WebCore::Document::clearFullscreenElementStack): Deleted. (WebCore::Document::popFullscreenElementStack): Deleted. (WebCore::Document::pushFullscreenElementStack): Deleted. (WebCore::Document::addDocumentToFullScreenChangeEventQueue): Deleted. * dom/Document.h: (WebCore::Document::fullscreenManager): (WebCore::Document::webkitIsFullScreen const): Deleted. (WebCore::Document::webkitFullScreenKeyboardInputAllowed const): Deleted. (WebCore::Document::webkitCurrentFullScreenElement const): Deleted. (WebCore::Document::webkitCurrentFullScreenElementForBindings const): Deleted. (WebCore::Document::fullScreenRenderer const): Deleted. (WebCore::Document::webkitFullscreenElement const): Deleted. (WebCore::Document::webkitFullscreenElementForBindings const): Deleted. * dom/Document.idl: * dom/DocumentFullscreen.h: (WebCore::DocumentFullscreen::webkitFullscreenEnabled): (WebCore::DocumentFullscreen::webkitFullscreenElement): (WebCore::DocumentFullscreen::webkitExitFullscreen): (WebCore::DocumentFullscreen::webkitIsFullScreen): (WebCore::DocumentFullscreen::webkitFullScreenKeyboardInputAllowed): (WebCore::DocumentFullscreen::webkitCurrentFullScreenElement): (WebCore::DocumentFullscreen::webkitCancelFullScreen): * dom/DocumentFullscreen.idl: * dom/Element.cpp: (WebCore::Element::webkitRequestFullscreen): * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): * dom/FullscreenManager.cpp: Added. (WebCore::isAttributeOnAllOwners): (WebCore::FullscreenManager::FullscreenManager): (WebCore::FullscreenManager::fullscreenIsAllowedForElement const): (WebCore::FullscreenManager::requestFullscreenForElement): (WebCore::FullscreenManager::cancelFullscreen): (WebCore::FullscreenManager::requestExitFullscreen): (WebCore::FullscreenManager::exitFullscreen): (WebCore::FullscreenManager::isFullscreenEnabled const): (WebCore::unwrapFullscreenRenderer): (WebCore::FullscreenManager::willEnterFullscreen): (WebCore::FullscreenManager::didEnterFullscreen): (WebCore::FullscreenManager::willExitFullscreen): (WebCore::FullscreenManager::didExitFullscreen): (WebCore::FullscreenManager::setFullscreenRenderer): (WebCore::FullscreenManager::dispatchFullscreenChangeEvents): (WebCore::FullscreenManager::dispatchFullscreenChangeOrErrorEvent): (WebCore::FullscreenManager::fullscreenElementRemoved): (WebCore::FullscreenManager::adjustFullscreenElementOnNodeRemoval): (WebCore::FullscreenManager::isAnimatingFullscreen const): (WebCore::FullscreenManager::setAnimatingFullscreen): (WebCore::FullscreenManager::areFullscreenControlsHidden const): (WebCore::FullscreenManager::setFullscreenControlsHidden): (WebCore::FullscreenManager::clear): (WebCore::FullscreenManager::emptyEventQueue): (WebCore::FullscreenManager::clearFullscreenElementStack): (WebCore::FullscreenManager::popFullscreenElementStack): (WebCore::FullscreenManager::pushFullscreenElementStack): (WebCore::FullscreenManager::addDocumentToFullscreenChangeEventQueue): * dom/FullscreenManager.h: Added. (WebCore::FullscreenManager::document): (WebCore::FullscreenManager::document const): (WebCore::FullscreenManager::topDocument const): (WebCore::FullscreenManager::page const): (WebCore::FullscreenManager::frame const): (WebCore::FullscreenManager::documentElement const): (WebCore::FullscreenManager::hasLivingRenderTree const): (WebCore::FullscreenManager::pageCacheState const): (WebCore::FullscreenManager::scheduleFullStyleRebuild): (WebCore::FullscreenManager::fullscreenElement const): (WebCore::FullscreenManager::isFullscreen const): (WebCore::FullscreenManager::isFullscreenKeyboardInputAllowed const): (WebCore::FullscreenManager::currentFullscreenElement const): (WebCore::FullscreenManager::fullscreenRenderer const): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::isFullscreen const): (WebCore::HTMLMediaElement::isStandardFullscreen const): (WebCore::HTMLMediaElement::enterFullscreen): (WebCore::HTMLMediaElement::exitFullscreen): * html/MediaElementSession.cpp: (WebCore::MediaElementSession::canShowControlsManager const): * html/shadow/MediaControlElements.cpp: (WebCore::MediaControlFullscreenButtonElement::defaultEventHandler): * inspector/agents/InspectorDOMAgent.cpp: * page/EventHandler.cpp: (WebCore::EventHandler::isKeyEventAllowedInFullScreen const): (WebCore::EventHandler::internalKeyEvent): * page/Page.cpp: (WebCore::Page::setFullscreenControlsHidden): * rendering/RenderFullScreen.cpp: (WebCore::RenderFullScreen::wrapNewRenderer): (WebCore::RenderFullScreen::wrapExistingRenderer): * rendering/RenderLayerCompositor.cpp: (WebCore::isDescendantOfFullScreenLayer): * rendering/updating/RenderTreeBuilder.h: * rendering/updating/RenderTreeBuilderInline.cpp: (WebCore::RenderTreeBuilder::Inline::splitInlines): * rendering/updating/RenderTreeUpdater.cpp: (WebCore::RenderTreeUpdater::createRenderer): * style/StyleSharingResolver.cpp: (WebCore::Style::SharingResolver::canShareStyleWithElement const): * testing/Internals.cpp: (WebCore::Internals::webkitWillEnterFullScreenForElement): (WebCore::Internals::webkitDidEnterFullScreenForElement): (WebCore::Internals::webkitWillExitFullScreenForElement): (WebCore::Internals::webkitDidExitFullScreenForElement): (WebCore::Internals::isAnimatingFullScreen const): Source/WebKit: * WebProcess/FullScreen/WebFullScreenManager.cpp: (WebKit::WebFullScreenManager::willEnterFullScreen): (WebKit::WebFullScreenManager::didEnterFullScreen): (WebKit::WebFullScreenManager::willExitFullScreen): (WebKit::WebFullScreenManager::didExitFullScreen): (WebKit::WebFullScreenManager::setAnimatingFullScreen): (WebKit::WebFullScreenManager::requestExitFullScreen): * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp: (webkit_dom_document_webkit_cancel_fullscreen): (webkit_dom_document_webkit_exit_fullscreen): (webkit_dom_document_get_webkit_is_fullscreen): (webkit_dom_document_get_webkit_fullscreen_keyboard_input_allowed): (webkit_dom_document_get_webkit_current_fullscreen_element): (webkit_dom_document_get_webkit_fullscreen_element): * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::createWindow): Source/WebKitLegacy/mac: * DOM/DOMDocument.mm: (-[DOMDocument webkitIsFullScreen]): (-[DOMDocument webkitFullScreenKeyboardInputAllowed]): (-[DOMDocument webkitCurrentFullScreenElement]): (-[DOMDocument webkitFullscreenEnabled]): (-[DOMDocument webkitFullscreenElement]): (-[DOMDocument webkitCancelFullScreen]): (-[DOMDocument webkitExitFullscreen]): * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::createWindow): * WebCoreSupport/WebKitFullScreenListener.mm: (-[WebKitFullScreenListener webkitWillEnterFullScreen]): (-[WebKitFullScreenListener webkitDidEnterFullScreen]): (-[WebKitFullScreenListener webkitWillExitFullScreen]): (-[WebKitFullScreenListener webkitDidExitFullScreen]): * WebView/WebFullScreenController.mm: (-[WebFullScreenController enterFullScreen:]): (-[WebFullScreenController finishedEnterFullScreenAnimation:]): (-[WebFullScreenController requestExitFullScreen]): (-[WebFullScreenController exitFullScreen]): (-[WebFullScreenController finishedExitFullScreenAnimation:]): (-[WebFullScreenController _manager]): * WebView/WebView.mm: (-[WebView _didStartProvisionalLoadForFrame:]): Source/WebKitLegacy/win: * WebCoreSupport/WebChromeClient.cpp: (WebChromeClient::createWindow): * WebView.cpp: (WebView::fullScreenClientWillEnterFullScreen): (WebView::fullScreenClientDidEnterFullScreen): (WebView::fullScreenClientWillExitFullScreen): (WebView::fullScreenClientDidExitFullScreen): Canonical link: https://commits.webkit.org/211322@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244440 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-18 22:16:54 +00:00
if (auto* element = downcast<Node>(target).document().fullscreenManager().currentFullscreenElement()) {
// FIXME: We assume that if the full screen element is a media element that it's
// the video-only full screen. Both here and elsewhere. But that is probably wrong.
if (element->isMediaElement() && shadowRoot.host() == element)
return false;
}
}
#endif
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. Canonical link: https://commits.webkit.org/195627@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-13 06:12:09 +00:00
bool targetIsInShadowRoot = is<Node>(target) && &downcast<Node>(target).treeScope().rootNode() == &shadowRoot;
Replace scoped flag in Event by composed flag https://bugs.webkit.org/show_bug.cgi?id=158415 Reviewed by Chris Dumez. Source/WebCore: Replace `scoped` flag with `composed` flag and negate its meaning per the latest spec: https://dom.spec.whatwg.org/#dom-event-composed https://github.com/w3c/webcomponents/issues/513 In the old spec, every event was assumed to be "composed" (crosses shadow boundaries) by default and there was `scoped` flag which prevented the event from crossing bondaries, and there was a handful of events for which `scoped` was set true when dispatched by UA. In the new spec, every event is assumed to be "scoped" and a handful of user-initiated events set `composed` flag to true, which is also exposed in EventInit dictionary. `relatedTargetScoped` flag has been removed. New behavior is identical to when this flag was set to true. No new tests since existing tests are updated to test the new flag and behavior. * dom/CompositionEvent.cpp: (WebCore::CompositionEvent::isCompositionEvent): Added. * dom/CompositionEvent.h: * dom/Event.cpp: (WebCore::Event::Event): Initialize m_composed. Also re-ordered m_type and m_isInitialized for better packing. (WebCore::Event::composed): Renamed from Event::composed. We return true whenever composed is set to true in EventInit, or the engine is dispatching an user-initiated event listed in: https://github.com/w3c/webcomponents/issues/513#issuecomment-224183937 as well as keypress, cut, paste, and, copy as discussed in: https://github.com/w3c/webcomponents/issues/513#issuecomment-230988170 (WebCore::Event::isCompositionEvent): Added. * dom/Event.h: (WebCore::Event::composed): Added. (WebCore::Event::scoped): Deleted. (WebCore::Event::relatedTargetScoped): Deleted. (WebCore::Event): Reordered m_type and m_isInitialized for better packing. Added m_composed and removed m_scoped and m_relatedTargetScoped. * dom/Event.idl: * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): Returns true if the event did not originate from a shadow tree (this event entered the current shadow tree via a slot so we need to proceed with the normal bubble path outside the shadow tree) or composed flag is set true. (WebCore::EventPath::EventPath): m_event no longer exists, which was only used to get the value of relatedTargetScoped which has been removed. (WebCore::EventPath::setRelatedTarget): Behave as if relatedTargetScoped is always set true since the flag has been removed. * dom/EventPath.h: * dom/FocusEvent.cpp: (WebCore::FocusEvent::relatedTargetScoped): Deleted. * dom/FocusEvent.h: * dom/MouseEvent.cpp: (WebCore::MouseEvent::relatedTargetScoped): Deleted. * dom/MouseEvent.h: LayoutTests: Updated the tests to reflect the rename of scoped to composed and the negation of its semantics. Now every Event is assumed to be scoped / non-composed by default, and we need to explicitly set composed to true in order for events to cross shadow boundaries. Also, every Event behaves as if related target is assumed to be scoped in the old terminology althoug the flag no longer exists. * fast/shadow-dom/Extensions-to-Event-Interface-expected.txt: * fast/shadow-dom/Extensions-to-Event-Interface.html: Removed a test case that was testing relatedTargetScoped to false since this flag no longer exists. * fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html: * fast/shadow-dom/event-inside-shadow-tree.html: * fast/shadow-dom/event-inside-slotted-node.html: * fast/shadow-dom/event-with-related-target.html: * fast/shadow-dom/trusted-event-scoped-flags-expected.txt: * fast/shadow-dom/trusted-event-scoped-flags.html: * fast/xmlhttprequest/xmlhttprequest-get-expected.txt: * http/tests/workers/worker-importScriptsOnError-expected.txt: * inspector/model/remote-object-get-properties-expected.txt: Canonical link: https://commits.webkit.org/177677@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202953 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 01:57:44 +00:00
return !targetIsInShadowRoot || event.composed();
}
static Node* nodeOrHostIfPseudoElement(Node* node)
{
return is<PseudoElement>(*node) ? downcast<PseudoElement>(*node).hostElement() : node;
}
class RelatedNodeRetargeter {
public:
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
RelatedNodeRetargeter(Node& relatedNode, Node& target);
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
Node* currentNode(Node& currentTreeScope);
void moveToNewTreeScope(TreeScope* previousTreeScope, TreeScope& newTreeScope);
private:
Node* nodeInLowestCommonAncestor();
void collectTreeScopes();
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
void checkConsistency(Node& currentTarget);
Node& m_relatedNode;
Node* m_retargetedRelatedNode;
Vector<TreeScope*, 8> m_ancestorTreeScopes;
unsigned m_lowestCommonAncestorIndex { 0 };
bool m_hasDifferentTreeRoot { false };
};
EventPath::EventPath(Node& originalTarget, Event& event)
{
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
buildPath(originalTarget, event);
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
if (auto* relatedTarget = event.relatedTarget(); is<Node>(relatedTarget) && !m_path.isEmpty())
setRelatedTarget(originalTarget, downcast<Node>(*relatedTarget));
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
#if ENABLE(TOUCH_EVENTS)
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
if (is<TouchEvent>(event))
retargetTouchLists(downcast<TouchEvent>(event));
#endif
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
}
void EventPath::buildPath(Node& originalTarget, Event& event)
{
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
EventContext::Type contextType = [&]() {
if (is<MouseEvent>(event) || event.isFocusEvent())
return EventContext::Type::MouseOrFocus;
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
#if ENABLE(TOUCH_EVENTS)
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
if (is<TouchEvent>(event))
return EventContext::Type::Touch;
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
#endif
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
return EventContext::Type::Normal;
}();
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
Node* node = nodeOrHostIfPseudoElement(&originalTarget);
Node* target = node ? eventTargetRespectingTargetRules(*node) : nullptr;
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
int closedShadowDepth = 0;
// Depths are used to decided which nodes are excluded in event.composedPath when the tree is mutated during event dispatching.
// They could be negative for nodes outside the shadow tree of the target node.
while (node) {
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
while (node) {
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
m_path.append(EventContext { contextType, *node, eventTargetRespectingTargetRules(*node), target, closedShadowDepth });
if (is<ShadowRoot>(*node))
break;
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
ContainerNode* parent = node->parentNode();
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
if (UNLIKELY(!parent)) {
// https://dom.spec.whatwg.org/#interface-document
if (is<Document>(*node) && event.type() != eventNames().loadEvent) {
ASSERT(target);
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
if (target) {
if (auto* window = downcast<Document>(*node).domWindow())
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
m_path.append(EventContext { EventContext::Type::Window, node, window, target, closedShadowDepth });
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
}
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
}
return;
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
}
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
if (auto* shadowRootOfParent = parent->shadowRoot(); UNLIKELY(shadowRootOfParent)) {
if (auto* assignedSlot = shadowRootOfParent->findAssignedSlot(*node)) {
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
if (shadowRootOfParent->mode() != ShadowRootMode::Open)
closedShadowDepth++;
// node is assigned to a slot. Continue dispatching the event at this slot.
parent = assignedSlot;
}
}
node = parent;
}
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
bool exitingShadowTreeOfTarget = &target->treeScope() == &node->treeScope();
ShadowRoot& shadowRoot = downcast<ShadowRoot>(*node);
if (!shouldEventCrossShadowBoundary(event, shadowRoot, originalTarget))
return;
node = shadowRoot.host();
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
if (shadowRoot.mode() != ShadowRootMode::Open)
closedShadowDepth--;
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
if (exitingShadowTreeOfTarget)
target = eventTargetRespectingTargetRules(*node);
}
}
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
void EventPath::setRelatedTarget(Node& origin, Node& relatedNode)
{
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
RelatedNodeRetargeter retargeter(relatedNode, *m_path[0].node());
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. Canonical link: https://commits.webkit.org/195627@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-13 06:12:09 +00:00
bool originIsRelatedTarget = &origin == &relatedNode;
Node& rootNodeInOriginTreeScope = origin.treeScope().rootNode();
TreeScope* previousTreeScope = nullptr;
size_t originalEventPathSize = m_path.size();
for (unsigned contextIndex = 0; contextIndex < originalEventPathSize; contextIndex++) {
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
auto& context = m_path[contextIndex];
if (!context.isMouseOrFocusEventContext()) {
ASSERT(context.isWindowContext());
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
continue;
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
}
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
Node& currentTarget = *context.node();
TreeScope& currentTreeScope = currentTarget.treeScope();
if (UNLIKELY(previousTreeScope && &currentTreeScope != previousTreeScope))
retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope);
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
Node* currentRelatedNode = retargeter.currentNode(currentTarget);
Replace scoped flag in Event by composed flag https://bugs.webkit.org/show_bug.cgi?id=158415 Reviewed by Chris Dumez. Source/WebCore: Replace `scoped` flag with `composed` flag and negate its meaning per the latest spec: https://dom.spec.whatwg.org/#dom-event-composed https://github.com/w3c/webcomponents/issues/513 In the old spec, every event was assumed to be "composed" (crosses shadow boundaries) by default and there was `scoped` flag which prevented the event from crossing bondaries, and there was a handful of events for which `scoped` was set true when dispatched by UA. In the new spec, every event is assumed to be "scoped" and a handful of user-initiated events set `composed` flag to true, which is also exposed in EventInit dictionary. `relatedTargetScoped` flag has been removed. New behavior is identical to when this flag was set to true. No new tests since existing tests are updated to test the new flag and behavior. * dom/CompositionEvent.cpp: (WebCore::CompositionEvent::isCompositionEvent): Added. * dom/CompositionEvent.h: * dom/Event.cpp: (WebCore::Event::Event): Initialize m_composed. Also re-ordered m_type and m_isInitialized for better packing. (WebCore::Event::composed): Renamed from Event::composed. We return true whenever composed is set to true in EventInit, or the engine is dispatching an user-initiated event listed in: https://github.com/w3c/webcomponents/issues/513#issuecomment-224183937 as well as keypress, cut, paste, and, copy as discussed in: https://github.com/w3c/webcomponents/issues/513#issuecomment-230988170 (WebCore::Event::isCompositionEvent): Added. * dom/Event.h: (WebCore::Event::composed): Added. (WebCore::Event::scoped): Deleted. (WebCore::Event::relatedTargetScoped): Deleted. (WebCore::Event): Reordered m_type and m_isInitialized for better packing. Added m_composed and removed m_scoped and m_relatedTargetScoped. * dom/Event.idl: * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): Returns true if the event did not originate from a shadow tree (this event entered the current shadow tree via a slot so we need to proceed with the normal bubble path outside the shadow tree) or composed flag is set true. (WebCore::EventPath::EventPath): m_event no longer exists, which was only used to get the value of relatedTargetScoped which has been removed. (WebCore::EventPath::setRelatedTarget): Behave as if relatedTargetScoped is always set true since the flag has been removed. * dom/EventPath.h: * dom/FocusEvent.cpp: (WebCore::FocusEvent::relatedTargetScoped): Deleted. * dom/FocusEvent.h: * dom/MouseEvent.cpp: (WebCore::MouseEvent::relatedTargetScoped): Deleted. * dom/MouseEvent.h: LayoutTests: Updated the tests to reflect the rename of scoped to composed and the negation of its semantics. Now every Event is assumed to be scoped / non-composed by default, and we need to explicitly set composed to true in order for events to cross shadow boundaries. Also, every Event behaves as if related target is assumed to be scoped in the old terminology althoug the flag no longer exists. * fast/shadow-dom/Extensions-to-Event-Interface-expected.txt: * fast/shadow-dom/Extensions-to-Event-Interface.html: Removed a test case that was testing relatedTargetScoped to false since this flag no longer exists. * fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html: * fast/shadow-dom/event-inside-shadow-tree.html: * fast/shadow-dom/event-inside-slotted-node.html: * fast/shadow-dom/event-with-related-target.html: * fast/shadow-dom/trusted-event-scoped-flags-expected.txt: * fast/shadow-dom/trusted-event-scoped-flags.html: * fast/xmlhttprequest/xmlhttprequest-get-expected.txt: * http/tests/workers/worker-importScriptsOnError-expected.txt: * inspector/model/remote-object-get-properties-expected.txt: Canonical link: https://commits.webkit.org/177677@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202953 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 01:57:44 +00:00
if (UNLIKELY(!originIsRelatedTarget && context.target() == currentRelatedNode)) {
m_path.shrink(contextIndex);
break;
}
context.setRelatedTarget(currentRelatedNode);
Replace scoped flag in Event by composed flag https://bugs.webkit.org/show_bug.cgi?id=158415 Reviewed by Chris Dumez. Source/WebCore: Replace `scoped` flag with `composed` flag and negate its meaning per the latest spec: https://dom.spec.whatwg.org/#dom-event-composed https://github.com/w3c/webcomponents/issues/513 In the old spec, every event was assumed to be "composed" (crosses shadow boundaries) by default and there was `scoped` flag which prevented the event from crossing bondaries, and there was a handful of events for which `scoped` was set true when dispatched by UA. In the new spec, every event is assumed to be "scoped" and a handful of user-initiated events set `composed` flag to true, which is also exposed in EventInit dictionary. `relatedTargetScoped` flag has been removed. New behavior is identical to when this flag was set to true. No new tests since existing tests are updated to test the new flag and behavior. * dom/CompositionEvent.cpp: (WebCore::CompositionEvent::isCompositionEvent): Added. * dom/CompositionEvent.h: * dom/Event.cpp: (WebCore::Event::Event): Initialize m_composed. Also re-ordered m_type and m_isInitialized for better packing. (WebCore::Event::composed): Renamed from Event::composed. We return true whenever composed is set to true in EventInit, or the engine is dispatching an user-initiated event listed in: https://github.com/w3c/webcomponents/issues/513#issuecomment-224183937 as well as keypress, cut, paste, and, copy as discussed in: https://github.com/w3c/webcomponents/issues/513#issuecomment-230988170 (WebCore::Event::isCompositionEvent): Added. * dom/Event.h: (WebCore::Event::composed): Added. (WebCore::Event::scoped): Deleted. (WebCore::Event::relatedTargetScoped): Deleted. (WebCore::Event): Reordered m_type and m_isInitialized for better packing. Added m_composed and removed m_scoped and m_relatedTargetScoped. * dom/Event.idl: * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): Returns true if the event did not originate from a shadow tree (this event entered the current shadow tree via a slot so we need to proceed with the normal bubble path outside the shadow tree) or composed flag is set true. (WebCore::EventPath::EventPath): m_event no longer exists, which was only used to get the value of relatedTargetScoped which has been removed. (WebCore::EventPath::setRelatedTarget): Behave as if relatedTargetScoped is always set true since the flag has been removed. * dom/EventPath.h: * dom/FocusEvent.cpp: (WebCore::FocusEvent::relatedTargetScoped): Deleted. * dom/FocusEvent.h: * dom/MouseEvent.cpp: (WebCore::MouseEvent::relatedTargetScoped): Deleted. * dom/MouseEvent.h: LayoutTests: Updated the tests to reflect the rename of scoped to composed and the negation of its semantics. Now every Event is assumed to be scoped / non-composed by default, and we need to explicitly set composed to true in order for events to cross shadow boundaries. Also, every Event behaves as if related target is assumed to be scoped in the old terminology althoug the flag no longer exists. * fast/shadow-dom/Extensions-to-Event-Interface-expected.txt: * fast/shadow-dom/Extensions-to-Event-Interface.html: Removed a test case that was testing relatedTargetScoped to false since this flag no longer exists. * fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html: * fast/shadow-dom/event-inside-shadow-tree.html: * fast/shadow-dom/event-inside-slotted-node.html: * fast/shadow-dom/event-with-related-target.html: * fast/shadow-dom/trusted-event-scoped-flags-expected.txt: * fast/shadow-dom/trusted-event-scoped-flags.html: * fast/xmlhttprequest/xmlhttprequest-get-expected.txt: * http/tests/workers/worker-importScriptsOnError-expected.txt: * inspector/model/remote-object-get-properties-expected.txt: Canonical link: https://commits.webkit.org/177677@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202953 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-07-08 01:57:44 +00:00
if (UNLIKELY(originIsRelatedTarget && context.node() == &rootNodeInOriginTreeScope)) {
m_path.shrink(contextIndex + 1);
break;
}
previousTreeScope = &currentTreeScope;
}
}
#if ENABLE(TOUCH_EVENTS)
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
void EventPath::retargetTouch(EventContext::TouchListType type, const Touch& touch)
{
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. Canonical link: https://commits.webkit.org/195627@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-13 06:12:09 +00:00
auto* eventTarget = touch.target();
if (!is<Node>(eventTarget))
return;
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
RelatedNodeRetargeter retargeter(downcast<Node>(*eventTarget), *m_path[0].node());
TreeScope* previousTreeScope = nullptr;
for (auto& context : m_path) {
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
Node& currentTarget = *context.node();
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
TreeScope& currentTreeScope = currentTarget.treeScope();
if (UNLIKELY(previousTreeScope && &currentTreeScope != previousTreeScope))
retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope);
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
if (context.isTouchEventContext()) {
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
Node* currentRelatedNode = retargeter.currentNode(currentTarget);
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
context.touchList(type).append(touch.cloneWithNewTarget(currentRelatedNode));
} else
ASSERT(context.isWindowContext());
previousTreeScope = &currentTreeScope;
}
}
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
void EventPath::retargetTouchList(EventContext::TouchListType type, const TouchList* list)
{
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
for (unsigned i = 0, length = list ? list->length() : 0; i < length; ++i)
retargetTouch(type, *list->item(i));
}
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
void EventPath::retargetTouchLists(const TouchEvent& event)
{
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
retargetTouchList(EventContext::TouchListType::Touches, event.touches());
retargetTouchList(EventContext::TouchListType::TargetTouches, event.targetTouches());
retargetTouchList(EventContext::TouchListType::ChangedTouches, event.changedTouches());
}
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
#endif
event.composedPath() does not include window https://bugs.webkit.org/show_bug.cgi?id=164609 <rdar://problem/29210383> Reviewed by Antti Koivisto. Source/WebCore: Fixed the bug by including WindowContext be a part of the regular EventPath. This also simplifies dispatchEventInDOM which used to had a special logic for dispatching an event on the window. Also fixed a bug in EventDispatcher::dispatchEvent that event.target would be nullptr when an event was dispatched inside a disconnected shadow tree or prevented from propagating to the document tree. Preserve the final target by simply saving event.target() prior to invoking the default event handler instead. Test: fast/shadow-dom/event-path-with-window.html * dom/EventDispatcher.cpp: (WebCore::WindowEventContext): Deleted. Moved to EventPath.cpp. (WebCore::dispatchEventInDOM): Removed the code for WindowContext. The generic event dispatching logic will do the same work now. (WebCore::EventDispatcher::dispatchEvent): Restore the original target instead of using that of WindowContext. * dom/EventPath.cpp: (WebCore::WindowEventContext): Moved from EventDispatcher.cpp. Also made it a subclass of EventContext. (WebCore::WindowEventContext::handleLocalEvents): Added. (WebCore::EventPath::EventPath): When the parent's nullptr, check if the current node is Document. If it is, follow https://dom.spec.whatwg.org/#interface-document where it says: "A document’s get the parent algorithm, given an event, returns null if event’s type attribute value is 'load' or document does not have a browsing context, and the document’s associated Window object otherwise." (WebCore::EventPath::setRelatedTarget): Skip over WindowContext. (WebCore::EventPath::retargetTouch): Ditto. (WebCore::EventPath::computePathUnclosedToTarget): When the target is DOMWindow, use its document as the target. Also, include any event target that is not a node in the event path. LayoutTests: Added a W3C style testharness.js test for dispatching an inside a shadow tree connected to a document. * fast/shadow-dom/event-path-with-window-expected.txt: Added. * fast/shadow-dom/event-path-with-window.html: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: (dispatchEventWithLog): Traverse from document to window. Also include the event object in the log. Canonical link: https://commits.webkit.org/182359@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 05:03:27 +00:00
// https://dom.spec.whatwg.org/#dom-event-composedpath
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
// Any node whose depth computed in EventPath::buildPath is greater than the context object is excluded.
// Because we can exit out of a closed shadow tree and re-enter another closed shadow tree via a slot,
// we decrease the *allowed depth* whenever we moved to a "shallower" (closer-to-document) tree.
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
Vector<EventTarget*> EventPath::computePathUnclosedToTarget(const EventTarget& target) const
Add Event.deepPath() and Event.scoped https://bugs.webkit.org/show_bug.cgi?id=153538 <rdar://problem/24363836> Reviewed by Darin Adler. Source/WebCore: Added the support for deepPath(), scoped, and relatedTargetScoped on Event.prototype for shadow DOM: http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-event-interface and updated the EventPath class to respect scoped and relatedTargetScoped flags as specified at: http://w3c.github.io/webcomponents/spec/shadow/#get-the-parent Tests: fast/shadow-dom/Extensions-to-Event-Interface.html fast/shadow-dom/trusted-event-scoped-flags.html * bindings/scripts/CodeGeneratorJS.pm: (GenerateConstructorDefinition): Added the support for Conditional for InitializedByEventConstructor. * bindings/scripts/test/GObject/WebKitDOMTestEventConstructor.cpp: * bindings/scripts/test/GObject/WebKitDOMTestEventConstructor.h: * bindings/scripts/test/JS/JSTestEventConstructor.cpp: * bindings/scripts/test/ObjC/DOMTestEventConstructor.h: * bindings/scripts/test/ObjC/DOMTestEventConstructor.mm: * bindings/scripts/test/TestEventConstructor.idl: Added a test case for using InitializedByEventConstructor with Conditional. * dom/Event.cpp: (WebCore::Event::Event): Initialize m_scoped and m_relatedTargetScoped from EventInit dictionary. (WebCore::Event::scoped): Added. Implements http://w3c.github.io/webcomponents/spec/shadow/#scoped-flag (WebCore::Event::deepPath): Added. * dom/Event.h: (WebCore::Event::relatedTargetScoped): Added. Overridden by FocusEvent and MouseEvent to implement http://w3c.github.io/webcomponents/spec/shadow/#relatedtargetscoped-flag (WebCore::Event::setEventPath): Added. (WebCore::Event::clearEventPath): Added. * dom/Event.idl: Added scoped, relatedTargetScoped, and deepPath() conditionally enabled for shadow DOM. * dom/EventContext.h: (WebCore::EventContext::currentTarget): * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Set the event path while the event is being dispatched. * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): Check event.scoped flag instead of hard-coding a list of events here which has been moved to Event::scoped. See above. (WebCore::EventPath::setRelatedTarget): Check m_event.relatedTargetScoped() instead of hard-coding a list of events here. relatedTargetScoped is overridden by FocusEvent and MouseEvent. (WebCore::EventPath::hasEventListeners): Fixed the misleading variable name. (WebCore::isUnclosedNodeOf): Added. Implements http://w3c.github.io/webcomponents/spec/shadow/#dfn-unclosed-node (WebCore::EventPath::computePathDisclosedToTarget): Added. Implements the algorithm to filter event targets: http://w3c.github.io/webcomponents/spec/shadow/#widl-Event-deepPath-sequence-EventTarget * dom/EventPath.h: * dom/FocusEvent.cpp: (WebCore::FocusEvent::relatedTargetScoped): Returns true when this is a trusted event per: http://w3c.github.io/webcomponents/spec/shadow/#relatedtargetscoped-flag * dom/FocusEvent.h: * dom/MouseEvent.cpp: (WebCore::MouseEvent::relatedTargetScoped): Ditto. * dom/MouseEvent.h: LayoutTests: Added a W3C style testharness.js tests for Event.prototype.scoped, Event.prototype.scopedRelatedTarget, Event.prototype.deepPath() and a test that uses eventSender to verify the values of the scoped and scopedRelatedTarget flags on trusted events. * fast/shadow-dom/Extensions-to-Event-Interface-expected.txt: Added. * fast/shadow-dom/Extensions-to-Event-Interface.html: Added. * fast/shadow-dom/event-with-related-target.html: * fast/shadow-dom/resources: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: Added. Extracted from event-with-related-target.html. * fast/shadow-dom/trusted-event-scoped-flags-expected.txt: Added. * fast/shadow-dom/trusted-event-scoped-flags.html: Added. * fast/xmlhttprequest/xmlhttprequest-get-expected.txt: * http/tests/workers/worker-importScriptsOnError-expected.txt: * inspector/model/remote-object-get-properties-expected.txt: * platform/ios-simulator/fast/shadow-dom/trusted-event-scoped-flags-expected.txt: Added. Canonical link: https://commits.webkit.org/173505@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198056 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-12 03:11:04 +00:00
{
Vector<EventTarget*> path;
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
auto pathSize = m_path.size();
RELEASE_ASSERT(pathSize);
path.reserveInitialCapacity(pathSize);
auto currentTargetIndex = m_path.findMatching([&target] (auto& context) {
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
return context.currentTarget() == &target;
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
});
RELEASE_ASSERT(currentTargetIndex != notFound);
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
auto currentTargetDepth = m_path[currentTargetIndex].closedShadowDepth();
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
auto appendTargetWithLesserDepth = [&path] (const EventContext& currentContext, int& currentDepthAllowed) {
auto depth = currentContext.closedShadowDepth();
bool contextIsInsideInnerShadowTree = depth > currentDepthAllowed;
if (contextIsInsideInnerShadowTree)
return;
bool movedOutOfShadowTree = depth < currentDepthAllowed;
if (movedOutOfShadowTree)
currentDepthAllowed = depth;
path.uncheckedAppend(currentContext.currentTarget());
};
auto currentDepthAllowed = currentTargetDepth;
auto i = currentTargetIndex;
do {
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
appendTargetWithLesserDepth(m_path[i], currentDepthAllowed);
Update composedPath to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=180378 <rdar://problem/42843004> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaselined the test now that all test cases pass. * web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation-expected.txt: Source/WebCore: This patch makes the check for whether a given node in the event path be included in composedPath pre-determined at the time of the event dispatching per https://github.com/whatwg/dom/issues/525. This was a fix for the issue that if an event listener in a closed shadow tree removes a node in the same tree in the event path, then composedPath called on its shadow host, for example, will include the removed node since it's no longer in the closed shadow tree. Naively, implementing this behavior would require remembering the original document or shadow root of each node in the event path as well as its parent shadow root, or worse which node is disclosed to every other node at the time of computing the event path. This patch takes a more novel and efficient approach to implement the new behavior by adding a single integer indicating the number of closed-mode shadow root ancestors of each node in the event path. In computePathUnclosedToTarget, any node whose *depth* is greater than the context object is excluded. Consider the following example: div ------- ShadowRoot (closed) +- span +- slot If an event is dispatched on span, then the event path would be [span, slot, ShadowRoot, div]. Then the values of integers assigned to each node would be: [0, 1, 1, 0] respectively. When composedPath is called on span or div, slot and ShadowRoot are excluded because they have a greater *depth* value. Unfortunately, this simplistic solution doesn't work when there are multiple shadow roots of the same depth through which an event is dispatched as in: section -- ShadowRoot (closed, SR2) | +- slot (s2) +div ------ ShadowRoot (closed, SR1) +- span +- slot (s1) If an event is dispatched on span, the event path would be [span, s1, SR1, div, s2, SR2, section]. The values of integers assigned are: [0, 1, 1, 0, 1, 1, 0] respectively. When composedPath is called on SR1, the simplistic approach would include s2 and SR2, which would be wrong. To account for this case, in computePathUnclosedToTarget, we traverse the event path upwards (i.e. ancestors) and downwards (i.e. descendants) from the context object and decrease the *allowed depth* of shadow trees when we traverse out of a shadow tree in either direction. When traversing upwards, therefore, moving out of a shadow root to its host would would decrease the allowed depth. When traversing dowards, moving from a slot element to its assigned node would decrease the allowed depth. Note that the depths can be negative when a composed event is dispatched inside a closed shadow tree, and it gets out of its shadow host. Unfortunately, the latest DOM specification has a bug and doesn't match the behavior of Chrome. This patch proposes a new algorithm which can be adopted in https://github.com/whatwg/dom/issues/684. Test: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-after-dom-mutation.html * dom/EventContext.cpp: (WebCore::EventContext::EventContext): (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): (WebCore::TouchEventContext::TouchEventContext): * dom/EventContext.h: (WebCore::EventContext::closedShadowDepth const): Added. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): (WebCore::EventPath::buildPath): Compute the closed shadow tree's depths for each node in the path. (WebCore::computePathUnclosedToTarget const): Implemented the aforementioned algorithm. (WebCore::EventPath::EventPath): Canonical link: https://commits.webkit.org/204659@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-18 07:47:35 +00:00
} while (i--);
path.reverse();
currentDepthAllowed = currentTargetDepth;
for (auto i = currentTargetIndex + 1; i < pathSize; ++i)
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
appendTargetWithLesserDepth(m_path[i], currentDepthAllowed);
Add Event.deepPath() and Event.scoped https://bugs.webkit.org/show_bug.cgi?id=153538 <rdar://problem/24363836> Reviewed by Darin Adler. Source/WebCore: Added the support for deepPath(), scoped, and relatedTargetScoped on Event.prototype for shadow DOM: http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-event-interface and updated the EventPath class to respect scoped and relatedTargetScoped flags as specified at: http://w3c.github.io/webcomponents/spec/shadow/#get-the-parent Tests: fast/shadow-dom/Extensions-to-Event-Interface.html fast/shadow-dom/trusted-event-scoped-flags.html * bindings/scripts/CodeGeneratorJS.pm: (GenerateConstructorDefinition): Added the support for Conditional for InitializedByEventConstructor. * bindings/scripts/test/GObject/WebKitDOMTestEventConstructor.cpp: * bindings/scripts/test/GObject/WebKitDOMTestEventConstructor.h: * bindings/scripts/test/JS/JSTestEventConstructor.cpp: * bindings/scripts/test/ObjC/DOMTestEventConstructor.h: * bindings/scripts/test/ObjC/DOMTestEventConstructor.mm: * bindings/scripts/test/TestEventConstructor.idl: Added a test case for using InitializedByEventConstructor with Conditional. * dom/Event.cpp: (WebCore::Event::Event): Initialize m_scoped and m_relatedTargetScoped from EventInit dictionary. (WebCore::Event::scoped): Added. Implements http://w3c.github.io/webcomponents/spec/shadow/#scoped-flag (WebCore::Event::deepPath): Added. * dom/Event.h: (WebCore::Event::relatedTargetScoped): Added. Overridden by FocusEvent and MouseEvent to implement http://w3c.github.io/webcomponents/spec/shadow/#relatedtargetscoped-flag (WebCore::Event::setEventPath): Added. (WebCore::Event::clearEventPath): Added. * dom/Event.idl: Added scoped, relatedTargetScoped, and deepPath() conditionally enabled for shadow DOM. * dom/EventContext.h: (WebCore::EventContext::currentTarget): * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Set the event path while the event is being dispatched. * dom/EventPath.cpp: (WebCore::shouldEventCrossShadowBoundary): Check event.scoped flag instead of hard-coding a list of events here which has been moved to Event::scoped. See above. (WebCore::EventPath::setRelatedTarget): Check m_event.relatedTargetScoped() instead of hard-coding a list of events here. relatedTargetScoped is overridden by FocusEvent and MouseEvent. (WebCore::EventPath::hasEventListeners): Fixed the misleading variable name. (WebCore::isUnclosedNodeOf): Added. Implements http://w3c.github.io/webcomponents/spec/shadow/#dfn-unclosed-node (WebCore::EventPath::computePathDisclosedToTarget): Added. Implements the algorithm to filter event targets: http://w3c.github.io/webcomponents/spec/shadow/#widl-Event-deepPath-sequence-EventTarget * dom/EventPath.h: * dom/FocusEvent.cpp: (WebCore::FocusEvent::relatedTargetScoped): Returns true when this is a trusted event per: http://w3c.github.io/webcomponents/spec/shadow/#relatedtargetscoped-flag * dom/FocusEvent.h: * dom/MouseEvent.cpp: (WebCore::MouseEvent::relatedTargetScoped): Ditto. * dom/MouseEvent.h: LayoutTests: Added a W3C style testharness.js tests for Event.prototype.scoped, Event.prototype.scopedRelatedTarget, Event.prototype.deepPath() and a test that uses eventSender to verify the values of the scoped and scopedRelatedTarget flags on trusted events. * fast/shadow-dom/Extensions-to-Event-Interface-expected.txt: Added. * fast/shadow-dom/Extensions-to-Event-Interface.html: Added. * fast/shadow-dom/event-with-related-target.html: * fast/shadow-dom/resources: Added. * fast/shadow-dom/resources/event-path-test-helpers.js: Added. Extracted from event-with-related-target.html. * fast/shadow-dom/trusted-event-scoped-flags-expected.txt: Added. * fast/shadow-dom/trusted-event-scoped-flags.html: Added. * fast/xmlhttprequest/xmlhttprequest-get-expected.txt: * http/tests/workers/worker-importScriptsOnError-expected.txt: * inspector/model/remote-object-get-properties-expected.txt: * platform/ios-simulator/fast/shadow-dom/trusted-event-scoped-flags-expected.txt: Added. Canonical link: https://commits.webkit.org/173505@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198056 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-12 03:11:04 +00:00
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
return path;
AX: AOM: Dispatch accessibleclick event https://bugs.webkit.org/show_bug.cgi?id=180898 <rdar://problem/36086710> Reviewed by Ryosuke Niwa. Source/WebCore: Accessibility events. Spec: https://wicg.github.io/aom/spec/phase2.html This patch allows developers to register event handlers on Elements for custom accessibility events. Accessibility events go through a capturing and bubbling phase just like DOM events, but in the accessibility tree. Implemented "accessibleclick" event. Test: accessibility/mac/AOM-events.html * accessibility/AccessibilityObject.cpp: (WebCore::AccessibilityObject::press): (WebCore::AccessibilityObject::dispatchAccessibilityEvent): * accessibility/AccessibilityObject.h: * accessibility/mac/WebAccessibilityObjectWrapperMac.mm: (-[WebAccessibilityObjectWrapper accessibilityPerformAction:]): * dom/Element.idl: * dom/EventDispatcher.cpp: (WebCore::dispatchEventWithType): (WebCore::EventDispatcher::dispatchEvent): * dom/EventDispatcher.h: * dom/EventNames.h: * dom/EventPath.cpp: (WebCore::EventPath::EventPath): * dom/EventPath.h: Tools: * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h: (WTR::AccessibilityUIElement::syncPress): * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl: * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm: (WTR::AccessibilityUIElement::syncPress): LayoutTests: * accessibility/mac/AOM-events-expected.txt: Added. * accessibility/mac/AOM-events.html: Added. * js/dom/dom-static-property-for-in-iteration-expected.txt: * platform/mac-wk1/TestExpectations: Canonical link: https://commits.webkit.org/198725@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228827 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-20 19:02:25 +00:00
}
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
EventPath::EventPath(const Vector<EventTarget*>& targets)
{
for (auto* target : targets) {
ASSERT(target);
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. Canonical link: https://commits.webkit.org/195627@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-13 06:12:09 +00:00
ASSERT(!is<Node>(target));
Avoid heap allocation for EventContexts https://bugs.webkit.org/show_bug.cgi?id=222095 <rdar://problem/74586915> Reviewed by Simon Fraser. This patch merges all subclasses of EventContext into itself to avoid heap allocation for each EventContext in EventPath::m_path. It also merges Node::handleLocalEvents into EventContext's handleLocalEvents to avoid the extra virtual function call. No new tests since there should be no observable behavioral differences. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Moved to the header to be inlined. (WebCore::EventContext::handleLocalEvents const): Merged handleLocalEvents of HTMLFormElement and Node. Moved the code to handle related target and touch targets from MouseOrFocusEventContext and TouchEventContext as they have been merged into this class. Also special case dispatching an event on window to preserve the behavior of WindowEventContext. (WebCore::EventContext::initializeTouchLists): Added. Creates TouchList objects. (WebCore::EventContext::isUnreachableNode const): Moved from the header. (WebCore::EventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::EventContext::isTouchEventContext const): Deleted. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Deleted. (WebCore::MouseOrFocusEventContext::isMouseOrFocusEventContext const): Deleted. (WebCore::TouchEventContext::TouchEventContext): Deleted. (WebCore::TouchEventContext::handleLocalEvents const): Deleted. (WebCore::TouchEventContext::isTouchEventContext const): Deleted. (WebCore::TouchEventContext::checkReachability const): Deleted. Merged into handleLocalEvents. * dom/EventContext.h: (WebCore::EventContext::isMouseOrFocusEventContext const): Now simply checks m_type. (WebCore::EventContext::isTouchEventContext const): Ditto. (WebCore::EventContext::isWindowContext const): Ditto. (WebCore::EventContext::relatedTarget const): Moved from MouseOrFocusEventContext. (WebCore::EventContext::setRelatedTarget): Ditto. (WebCore::EventContext::touchList): Moved from TouchEventContext. (WebCore::m_contextNodeIsFormElement): Added. Caching this state here instead of checking it at every event context during dispatching in EventContext::handleLocalEvents seems to be important to get a speed up in Intel processors. Apple silicons don't seem to be affected by this. (WebCore::m_type): Added. (WebCore::MouseOrFocusEventContext): Deleted. (WebCore::MouseOrFocusEventContext::relatedTarget const): Deleted. (WebCore::TouchEventContext): Deleted. (WebCore::EventContext::EventContext): Moved from cpp file to be inlined here. (WebCore::EventContext::isUnreachableNode const): Moved into cpp as this is only used for asserting shadow DOM related conditions. (WebCore::EventContext::touchList): Renamed from TouchEventContext::touchList. (isType): Deleted. * dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Deleted the variant that takes a vector of elements since it's not used anywhere. * dom/EventDispatcher.h: * dom/EventPath.cpp: (WebCore::WindowEventContext): Deleted. (WebCore::EventPath::EventPath): Avoid calling setRelatedTarget if related target is not a node or the path is empty. These were early return conditions in setRelatedTarget before this patch. (WebCore::EventPath::buildPath): Always create EventContext. Dramatically simplifies the code. (WebCore::EventPath::setRelatedTarget): Moved the early exit to EventPath::EventPath. (WebCore::EventPath::retargetTouch): (WebCore::EventPath::retargetTouchList): (WebCore::EventPath::retargetTouchLists): (WebCore::EventPath::EventPath): Deleted the variant which takes a vector of elements as it's not used anywhere. * dom/EventPath.h: (WebCore::EventPath::contextAt const): (WebCore::EventPath::contextAt): (WebCore::EventPath::m_path): Now allocates EventContext in place. The size of the inline buffer has been reduced to 16 entries for EventContext from 32 entries for std::unique_ptr<EventContext> since the former is considerably larger than the latter. * dom/Node.cpp: (WebCore::Node::handleLocalEvents): Deleted. Merged into EventContext::handleLocalEvents. * dom/Node.h: * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::handleLocalEvents): Ditto. * html/HTMLFormElement.h: Canonical link: https://commits.webkit.org/234556@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273477 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-25 08:30:59 +00:00
m_path.append(EventContext { EventContext::Type::Normal, nullptr, target, *targets.begin(), 0 });
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
}
}
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
static Node* moveOutOfAllShadowRoots(Node& startingNode)
{
Node* node = &startingNode;
while (node->isInShadowTree())
node = downcast<ShadowRoot>(node->treeScope().rootNode()).host();
return node;
}
RelatedNodeRetargeter::RelatedNodeRetargeter(Node& relatedNode, Node& target)
: m_relatedNode(relatedNode)
, m_retargetedRelatedNode(&relatedNode)
{
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
auto& targetTreeScope = target.treeScope();
TreeScope* currentTreeScope = &m_relatedNode.treeScope();
if (LIKELY(currentTreeScope == &targetTreeScope && target.isConnected() && m_relatedNode.isConnected()))
return;
if (&currentTreeScope->documentScope() != &targetTreeScope.documentScope()) {
m_hasDifferentTreeRoot = true;
m_retargetedRelatedNode = nullptr;
return;
}
if (relatedNode.isConnected() != target.isConnected()) {
m_hasDifferentTreeRoot = true;
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
m_retargetedRelatedNode = moveOutOfAllShadowRoots(relatedNode);
return;
}
collectTreeScopes();
// FIXME: We should collect this while constructing the event path.
Vector<TreeScope*, 8> targetTreeScopeAncestors;
for (TreeScope* currentTreeScope = &targetTreeScope; currentTreeScope; currentTreeScope = currentTreeScope->parentTreeScope())
targetTreeScopeAncestors.append(currentTreeScope);
ASSERT_WITH_SECURITY_IMPLICATION(!targetTreeScopeAncestors.isEmpty());
unsigned i = m_ancestorTreeScopes.size();
unsigned j = targetTreeScopeAncestors.size();
ASSERT_WITH_SECURITY_IMPLICATION(m_ancestorTreeScopes.last() == targetTreeScopeAncestors.last());
while (m_ancestorTreeScopes[i - 1] == targetTreeScopeAncestors[j - 1]) {
i--;
j--;
if (!i || !j)
break;
}
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
bool lowestCommonAncestorIsDocumentScope = i + 1 == m_ancestorTreeScopes.size();
if (lowestCommonAncestorIsDocumentScope && !relatedNode.isConnected() && !target.isConnected()) {
Import w3c shadow DOM tests and fix one assertion https://bugs.webkit.org/show_bug.cgi?id=162629 Reviewed by Chris Dumez. LayoutTests/imported/w3c: Import shadow DOM tests in web-platform-tests as of 7163d6eeed81e9e020545fbe0c4b11fc2c5963cd except untriaged tests for v0 API, which we obviously don't implement. Most of these tests are the ones we upstreamed from fast/shadow-dom/. * web-platform-tests/shadow-dom/Document-prototype-adoptNode-expected.txt: Renamed from LayoutTests/fast/shadow-dom/Document-prototype-adoptNode-expected.txt. * web-platform-tests/shadow-dom/Document-prototype-adoptNode.html: Renamed from LayoutTests/fast/shadow-dom/Document-prototype-adoptNode.html. * web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt: Renamed from LayoutTests/fast/shadow-dom/Document-prototype-currentScript-expected.txt. * web-platform-tests/shadow-dom/Document-prototype-currentScript.html: Renamed from LayoutTests/fast/shadow-dom/Document-prototype-currentScript.html. * web-platform-tests/shadow-dom/Document-prototype-importNode-expected.txt: Renamed from LayoutTests/fast/shadow-dom/Document-prototype-importNode-expected.txt. * web-platform-tests/shadow-dom/Document-prototype-importNode.html: Renamed from LayoutTests/fast/shadow-dom/Document-prototype-importNode.html. * web-platform-tests/shadow-dom/Element-interface-attachShadow-expected.txt: Added. * web-platform-tests/shadow-dom/Element-interface-attachShadow.html: Renamed from LayoutTests/fast/shadow-dom/Element-interface-attachShadow.html. * web-platform-tests/shadow-dom/Element-interface-shadowRoot-attribute-expected.txt: Renamed from LayoutTests/fast/shadow-dom/Element-interface-shadowRoot-attribute-expected.txt. * web-platform-tests/shadow-dom/Element-interface-shadowRoot-attribute.html: Renamed from LayoutTests/fast/shadow-dom/Element-interface-shadowRoot-attribute.html. * web-platform-tests/shadow-dom/Extensions-to-Event-Interface-expected.txt: Renamed from LayoutTests/fast/shadow-dom/Extensions-to-Event-Interface-expected.txt. * web-platform-tests/shadow-dom/Extensions-to-Event-Interface.html: Renamed from LayoutTests/fast/shadow-dom/Extensions-to-Event-Interface.html. * web-platform-tests/shadow-dom/HTMLSlotElement-interface-expected.txt: Renamed from LayoutTests/fast/shadow-dom/HTMLSlotElement-interface-expected.txt. * web-platform-tests/shadow-dom/HTMLSlotElement-interface.html: Renamed from LayoutTests/fast/shadow-dom/HTMLSlotElement-interface.html. * web-platform-tests/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt: Renamed from LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt. * web-platform-tests/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html: Renamed from LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html. * web-platform-tests/shadow-dom/Node-prototype-cloneNode-expected.txt: Added. * web-platform-tests/shadow-dom/Node-prototype-cloneNode.html: Renamed from LayoutTests/fast/shadow-dom/Node-prototype-cloneNode.html. * web-platform-tests/shadow-dom/OWNERS: Added. * web-platform-tests/shadow-dom/ShadowRoot-interface-expected.txt: Renamed from LayoutTests/fast/shadow-dom/ShadowRoot-interface-expected.txt. * web-platform-tests/shadow-dom/ShadowRoot-interface.html: Renamed from LayoutTests/fast/shadow-dom/ShadowRoot-interface.html. * web-platform-tests/shadow-dom/Slotable-interface-expected.txt: Renamed from LayoutTests/fast/shadow-dom/Slotable-interface-assignedSlot-expected.txt. * web-platform-tests/shadow-dom/Slotable-interface.html: Renamed from LayoutTests/fast/shadow-dom/Slotable-interface-assignedSlot.html. * web-platform-tests/shadow-dom/event-composed-expected.txt: Added. * web-platform-tests/shadow-dom/event-composed-path-expected.txt: Added. * web-platform-tests/shadow-dom/event-composed-path-with-related-target-expected.txt: Added. * web-platform-tests/shadow-dom/event-composed-path-with-related-target.html: Added. * web-platform-tests/shadow-dom/event-composed-path.html: Added. * web-platform-tests/shadow-dom/event-composed.html: Added. * web-platform-tests/shadow-dom/event-inside-shadow-tree-expected.txt: Renamed from LayoutTests/fast/shadow-dom/event-inside-shadow-tree-expected.txt. * web-platform-tests/shadow-dom/event-inside-shadow-tree.html: Renamed from LayoutTests/fast/shadow-dom/event-inside-shadow-tree.html. * web-platform-tests/shadow-dom/event-inside-slotted-node-expected.txt: Renamed from LayoutTests/fast/shadow-dom/event-inside-slotted-node-expected.txt. * web-platform-tests/shadow-dom/event-inside-slotted-node.html: Renamed from LayoutTests/fast/shadow-dom/event-inside-slotted-node.html. * web-platform-tests/shadow-dom/event-with-related-target-expected.txt: Renamed from LayoutTests/fast/shadow-dom/event-with-related-target-expected.txt. * web-platform-tests/shadow-dom/event-with-related-target.html: Renamed from LayoutTests/fast/shadow-dom/event-with-related-target.html. * web-platform-tests/shadow-dom/leaktests/get-elements-expected.txt: Added. * web-platform-tests/shadow-dom/leaktests/get-elements.html: Added. * web-platform-tests/shadow-dom/leaktests/html-collection-expected.txt: Added. * web-platform-tests/shadow-dom/leaktests/html-collection.html: Added. * web-platform-tests/shadow-dom/leaktests/w3c-import.log: Added. * web-platform-tests/shadow-dom/leaktests/window-frames-expected.txt: Added. * web-platform-tests/shadow-dom/leaktests/window-frames.html: Added. * web-platform-tests/shadow-dom/resources/Document-prototype-currentScript-helper.js: Renamed from LayoutTests/fast/shadow-dom/resources/Document-prototype-currentScript-helper.js. * web-platform-tests/shadow-dom/resources/event-path-test-helpers.js: Added. * web-platform-tests/shadow-dom/resources/shadow-dom-utils.js: Added. * web-platform-tests/shadow-dom/resources/shadow-dom.js: Added. * web-platform-tests/shadow-dom/resources/w3c-import.log: Added. * web-platform-tests/shadow-dom/scroll-to-the-fragment-in-shadow-tree-expected.txt: Added. * web-platform-tests/shadow-dom/scroll-to-the-fragment-in-shadow-tree.html: Added. * web-platform-tests/shadow-dom/slotchange-event-expected.txt: Renamed from LayoutTests/fast/shadow-dom/slotchange-event-expected.txt. * web-platform-tests/shadow-dom/slotchange-event.html: Renamed from LayoutTests/fast/shadow-dom/slotchange-event.html. * web-platform-tests/shadow-dom/slotchange-expected.txt: Added. * web-platform-tests/shadow-dom/slotchange.html: Added. * web-platform-tests/shadow-dom/slots-expected.txt: Added. * web-platform-tests/shadow-dom/slots-fallback-expected.txt: Added. * web-platform-tests/shadow-dom/slots-fallback.html: Added. * web-platform-tests/shadow-dom/slots.html: Added. * web-platform-tests/shadow-dom/w3c-import.log: Added. Source/WebCore: The assertion failure was caused by RelatedNodeRetargeter's constructor mixing up the ancestor tree scopes for the target and the related target. Fixed the bug by reversing the two. Tests: imported/w3c/web-platform-tests/shadow-dom/event-composed-path-with-related-target.html * dom/EventPath.cpp: (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): i and m_ancestorTreeScopes are for the related target and j and targetTreeScopeAncestors are for the target. LayoutTests: Deleted the duplicated copies of tests in fast/shadow/ since this patch re-imports them via web-platform-tests. * fast/shadow-dom/Element-interface-attachShadow-expected.txt: Removed. * fast/shadow-dom/Node-prototype-cloneNode-expected.txt: Removed. Canonical link: https://commits.webkit.org/180575@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206463 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-09-27 21:04:15 +00:00
Node& relatedNodeAncestorInDocumentScope = i ? *downcast<ShadowRoot>(m_ancestorTreeScopes[i - 1]->rootNode()).shadowHost() : relatedNode;
Node& targetAncestorInDocumentScope = j ? *downcast<ShadowRoot>(targetTreeScopeAncestors[j - 1]->rootNode()).shadowHost() : target;
if (&targetAncestorInDocumentScope.rootNode() != &relatedNodeAncestorInDocumentScope.rootNode()) {
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
m_hasDifferentTreeRoot = true;
m_retargetedRelatedNode = moveOutOfAllShadowRoots(relatedNode);
return;
}
}
m_lowestCommonAncestorIndex = i;
m_retargetedRelatedNode = nodeInLowestCommonAncestor();
}
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
inline Node* RelatedNodeRetargeter::currentNode(Node& currentTarget)
{
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
checkConsistency(currentTarget);
return m_retargetedRelatedNode;
}
void RelatedNodeRetargeter::moveToNewTreeScope(TreeScope* previousTreeScope, TreeScope& newTreeScope)
{
if (m_hasDifferentTreeRoot)
return;
auto& currentRelatedNodeScope = m_retargetedRelatedNode->treeScope();
if (previousTreeScope != &currentRelatedNodeScope) {
// currentRelatedNode is still outside our shadow tree. New tree scope may contain currentRelatedNode
// but there is no need to re-target it. Moving into a slot (thereby a deeper shadow tree) doesn't matter.
return;
}
bool enteredSlot = newTreeScope.parentTreeScope() == previousTreeScope;
if (enteredSlot) {
if (m_lowestCommonAncestorIndex) {
if (m_ancestorTreeScopes.isEmpty())
collectTreeScopes();
bool relatedNodeIsInSlot = m_ancestorTreeScopes[m_lowestCommonAncestorIndex - 1] == &newTreeScope;
if (relatedNodeIsInSlot) {
m_lowestCommonAncestorIndex--;
m_retargetedRelatedNode = nodeInLowestCommonAncestor();
ASSERT(&newTreeScope == &m_retargetedRelatedNode->treeScope());
}
} else
ASSERT(m_retargetedRelatedNode == &m_relatedNode);
} else {
ASSERT(previousTreeScope->parentTreeScope() == &newTreeScope);
m_lowestCommonAncestorIndex++;
ASSERT_WITH_SECURITY_IMPLICATION(m_ancestorTreeScopes.isEmpty() || m_lowestCommonAncestorIndex < m_ancestorTreeScopes.size());
m_retargetedRelatedNode = downcast<ShadowRoot>(currentRelatedNodeScope.rootNode()).host();
ASSERT(&newTreeScope == &m_retargetedRelatedNode->treeScope());
}
}
inline Node* RelatedNodeRetargeter::nodeInLowestCommonAncestor()
{
if (!m_lowestCommonAncestorIndex)
return &m_relatedNode;
auto& rootNode = m_ancestorTreeScopes[m_lowestCommonAncestorIndex - 1]->rootNode();
return downcast<ShadowRoot>(rootNode).host();
}
void RelatedNodeRetargeter::collectTreeScopes()
{
ASSERT(m_ancestorTreeScopes.isEmpty());
for (TreeScope* currentTreeScope = &m_relatedNode.treeScope(); currentTreeScope; currentTreeScope = currentTreeScope->parentTreeScope())
m_ancestorTreeScopes.append(currentTreeScope);
ASSERT_WITH_SECURITY_IMPLICATION(!m_ancestorTreeScopes.isEmpty());
}
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#if !ASSERT_ENABLED
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
inline void RelatedNodeRetargeter::checkConsistency(Node&)
{
}
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#else // ASSERT_ENABLED
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
event.target shouldn't be retargeted as the event bubbles into a slot https://bugs.webkit.org/show_bug.cgi?id=157369 Reviewed by Antti Koivisto. Source/WebCore: When an event bubbles up from an assigned node to its assigned slot, we shouldn't be adjusting event.target to point to the slot. Since a shadow tree should have access to nodes outside the shadow tree, event.target is accessible inside the shadow tree of such a slot. New behavior matches the behavior of Google Chrome Canary as well as the shadow DOM specification: http://w3c.github.io/webcomponents/spec/shadow/#dfn-retargeting-algorithm Test: fast/shadow-dom/event-inside-slotted-node.html * dom/Event.cpp: (WebCore::Event::deepPath): * dom/EventContext.h: (WebCore::EventContext::isUnreachableNode): Use Node::isUnclosedNode instead of isReachable. (WebCore::EventContext::isReachable): Deleted. * dom/EventPath.cpp: (WebCore::EventPath::EventPath): Don't set the target to the slot when entering a slot. Also moved the code to adjust the target as we exit a shadow tree to the end of the outer loop for clarity. (WebCore::isUnclosedNodeOf): Deleted. Renamed to Node::isUnclosedNode. (WebCore::EventPath::setRelatedTarget): (WebCore::EventPath::computePathUnclosedToTarget): Renamed from computePathDisclosedToTarget. (WebCore::moveOutOfAllShadowRoots): Extracted from RelatedNodeRetargeter::RelatedNodeRetargeter. (WebCore::RelatedNodeRetargeter::RelatedNodeRetargeter): Fixed a bug that we were exiting early without setting m_hasDifferentTreeRoot true when target and relatedNode are disconnected from a document. (WebCore::RelatedNodeRetargeter::currentNode): (WebCore::RelatedNodeRetargeter::checkConsistency): Updated to match the spec with one exception. We don't use null as the adjusted related target when the (original) related target and the target are in two distinct disconnected trees since such a behavior is not Web compatible. This spec bug is tracked by https://github.com/w3c/webcomponents/issues/494 * dom/EventPath.h: (WebCore::EventPath::eventTargetRespectingTargetRules): Returns Node* instead of EventTarget* since we need a Node in RelatedNodeRetargeter::checkConsistency. * dom/Node.cpp: (WebCore::Node::isUnclosedNode): Moved from RelatedNodeRetargeter.cpp * dom/Node.h: LayoutTests: Updated test cases to expect the target to be not adjusted to a slot element when the event path enters one as this didn't match the spec or the behavior of Google Chrome Canary. Both WebKit and Chrome passes the test with this change. * fast/shadow-dom/event-inside-slotted-node.html: Canonical link: https://commits.webkit.org/175496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-05-05 18:33:17 +00:00
void RelatedNodeRetargeter::checkConsistency(Node& currentTarget)
{
ShadowRoot interface should have elementFromPoint https://bugs.webkit.org/show_bug.cgi?id=162882 Reviewed by Chris Dumez. Source/WebCore: Add elementFromPoint to ShadowRoot's prototype as specified at: https://www.w3.org/TR/shadow-dom/#extensions-to-the-documentorshadowroot-mixin with changes proposed at https://github.com/w3c/csswg-drafts/issues/556 Added TreeScope::retargetToScope which implements This patch also factors DocumentOrShadowRoot.idl out of Document and ShadowRoot interfaces to better match the latest DOM specification: https://dom.spec.whatwg.org/#mixin-documentorshadowroot Test: fast/shadow-dom/Document-prototype-elementFromPoint.html * CMakeLists.txt: * DerivedSources.make: * WebCore.xcodeproj/project.pbxproj: * dom/Document.cpp: (WebCore::Document::nodeFromPoint): Moved to TreeScope. (WebCore::Document::elementFromPoint): Moved to TreeScope. * dom/Document.h: * dom/Document.idl: Moved elementFromPoint and activeElement to DocumentOrShadowRoot.idl. * dom/DocumentOrShadowRoot.idl: Added. * dom/EventPath.cpp: (WebCore::RelatedNodeRetargeter::checkConsistency): Use newly added TreeScope::retargetToScope. * dom/ShadowRoot.idl: Moved activeElement to DocumentOrShadowRoot.idl. * dom/TreeScope.cpp: (WebCore::TreeScope::retargetToScope): Added. Implements https://dom.spec.whatwg.org/#retarget efficiently. Instead of checking whether A (node) is a shadow-including inclusive ancestor of B (this scope) at each parent, find the lowest ancestor which contains both A and B, and return the self-inclusive ancestor of B in that tree. To find the lowest common ancestor in O(n), traverse all ancestors of A and B separately and do a top-down traversal. The last tree scope in which A's ancestor and B's ancestor match is the lowest common ancestor. (WebCore::TreeScope::nodeFromPoint): Moved from Document. (WebCore::TreeScope::elementFromPoint): Moved from Document. Use retargetToScope and parentInComposedTree instead of parentNode and ancestorInThisScope to match the semantics proposed in https://github.com/w3c/csswg-drafts/issues/556 * dom/TreeScope.h: LayoutTests: Add a W3C style testharness.js test for elementFromPoint on ShadowRoot. * fast/shadow-dom/DocumentOrShadowRoot-prototype-elementFromPoint-expected.txt: Added. * fast/shadow-dom/DocumentOrShadowRoot-prototype-elementFromPoint.html: Added. Canonical link: https://commits.webkit.org/180852@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206795 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-04 23:42:18 +00:00
if (!m_retargetedRelatedNode)
return;
ASSERT(!currentTarget.isClosedShadowHidden(*m_retargetedRelatedNode));
Change HitTestResult::NodeSet from set of RefPtrs to set of Refs https://bugs.webkit.org/show_bug.cgi?id=211306 Reviewed by Simon Fraser. HitTestResult::listBasedTestResult() never returns a set with nullptrs in it. So, change the set declaration from ListHashSet<RefPtr<Node>> to ListHashSet<Ref<Node>>. This way people are not tempted to unnecessarily null check the nodes in the set. As I made this change to TreeScope::elementsFromPoint() I noticed that retargetToScope(), which is called by it, returned a Node&. So, I changed it to return a Ref<Node>. That required me to fix up caretRangeFromPoint(), which lead me to fix up nodeFromPoint() as well. * dom/Document.cpp: (WebCore::Document::caretRangeFromPoint): * dom/EventPath.cpp: (WebCore::RelatedNodeRetargeter::checkConsistency): * dom/TreeScope.cpp: (WebCore::TreeScope::retargetToScope const): (WebCore::TreeScope::nodeFromPoint): (WebCore::TreeScope::elementFromPoint): (WebCore::TreeScope::elementsFromPoint): * dom/TreeScope.h: * page/Page.cpp: (WebCore::Page::editableElementsInRect const): * rendering/HitTestResult.cpp: (WebCore::appendToNodeSet): (WebCore::HitTestResult::HitTestResult): (WebCore::HitTestResult::operator=): (WebCore::HitTestResult::addNodeToListBasedTestResultCommon): (WebCore::HitTestResult::append): * rendering/HitTestResult.h: * testing/Internals.cpp: (WebCore::Internals::nodesFromRect const): Canonical link: https://commits.webkit.org/224205@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261028 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-01 22:16:19 +00:00
ASSERT(m_retargetedRelatedNode == currentTarget.treeScope().retargetToScope(m_relatedNode).ptr());
}
Simplify event dispatch code and make it a bit more consistent https://bugs.webkit.org/show_bug.cgi?id=178991 Reviewed by Chris Dumez. Source/WebCore: Straighten out event dispatch code in three ways: 1) Add an Event::resetAfterDispatch function, and use it instead of the multiple separate functions that were used before to reset after dispatching. This fixed an extremely minor bug where we would leave some kinds of state on some event objects in unusual cases after dispatching the events. 2) Remove IDBEventDispatcher and make its callers use EventDispatcher instead. This leaves us with one less event dispatch code path to maintain, more shared code. 3) Remove boolean return values from functions that take event objects and dispatch the events. The return values are redundant with various things that can be checked by looking at the event itself. The legacy return value indicates whether the event has its "canceled flag" set, which means that the default behavior should be prevented. If that is what we need to check, it's easier to read the code and see that it's correct if it calls the named function "defaultPrevented" directly. More importantly, callers can also call whatever other function is appropriate to ask the specific relevant question to their needs. The general rule is that default behavior that we want to allow even with an untrusted event can be inside a default event handler function. Default behavior that should only happen for the browser-generated event can and should be done after dispatching the event, in the code that dispatches it; but that requires explicitly checking "defaultPrevented". * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::dispatchEvent): Removed boolean return value. * Modules/indexeddb/IDBDatabase.h: Ditto. * Modules/indexeddb/IDBEventDispatcher.cpp: Removed. * Modules/indexeddb/IDBEventDispatcher.h: Removed. * Modules/indexeddb/IDBOpenDBRequest.cpp: (WebCore::IDBOpenDBRequest::dispatchEvent): Removed boolean return value. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBOpenDBRequest.h: Ditto. * Modules/indexeddb/IDBRequest.cpp: (WebCore::IDBRequest::dispatchEvent): Removed boolean return value. Instead of using IDBEventDispatcher, use EventDispatcher's new function that takes an initializer_list with a list of event targets. Added protection for "this" since the function accesses it after dispatching the event. * Modules/indexeddb/IDBRequest.h: Ditto. * Modules/indexeddb/IDBTransaction.cpp: (WebCore::IDBTransaction::dispatchEvent): Ditto. * Modules/indexeddb/IDBTransaction.h: Ditto. * Modules/mediastream/RTCPeerConnection.cpp: (WebCore::RTCPeerConnection::dispatchEvent): Removed boolean return value. * Modules/mediastream/RTCPeerConnection.h: Ditto. * Modules/paymentrequest/PaymentRequest.cpp: (WebCore::PaymentRequest::shippingAddressChanged): Don't dispatch an event if m_isUpdating is true; preserves behavior that was implemented in PaymentRequest::dispatchEvent before. Since this is the source of the trusted event, cleaner to implement the rule here instead of overriding dispatchEvent. (WebCore::PaymentRequest::shippingOptionChanged): Ditto. (WebCore::PaymentRequest::dispatchEvent): Deleted. * Modules/paymentrequest/PaymentRequest.h: Ditto. * Sources.txt: Removed IDBEventDispatcher.cpp. * WebCore.xcodeproj/project.pbxproj: Removed IDBEventDispatcher.h/cpp. * dom/Element.cpp: (WebCore::Element::dispatchMouseEvent): Updated to call defaultPrevented directly instead of using the return value of dispatchEvent. (WebCore::Element::dispatchWheelEvent): Ditto. (WebCore::Element::dispatchKeyEvent): Ditto. (WebCore::Element::dispatchFocusInEvent): Removed assertion, since the underlying event dispatching takes care of it. (WebCore::Element::dispatchFocusOutEvent): Ditto. (WebCore::Element::dispatchFocusEvent): Call dispatchEvent instead of calling EventDispatcher::dispatchEvent. There is no good reason to use EventDispatcher directly. (WebCore::Element::dispatchBlurEvent): Ditto. * dom/Event.cpp: (WebCore::Event::eventInterface const): Deleted. Moved into header since this is short and if called in a non-polymorphic context it's good to have it be inlined. (WebCore::Event::isUIEvent const): Ditto. (WebCore::Event::isMouseEvent const): Ditto. (WebCore::Event::isFocusEvent const): Ditto. (WebCore::Event::isKeyboardEvent const): Ditto. (WebCore::Event::isInputEvent const): Ditto. (WebCore::Event::isCompositionEvent const): Ditto. (WebCore::Event::isTouchEvent const): Ditto. (WebCore::Event::isClipboardEvent const): Ditto. (WebCore::Event::isBeforeTextInsertedEvent const): Ditto. (WebCore::Event::isBeforeUnloadEvent const): Ditto. (WebCore::Event::isErrorEvent const): Ditto. (WebCore::Event::isTextEvent const): Ditto. (WebCore::Event::isWheelEvent const): Ditto. (WebCore::Event::receivedTarget): Ditto. (WebCore::Event::resetAfterDispatch): Added. Replaces functions like clearEventPath and resetPropagationFlags, covering all the things we need to clear after dispatching an event. * dom/Event.h: Removed some unneeded includes and forward declarations. Moved bodies of multi-line inline member functions out of the class definition. Changed argument type of setEventPhase and m_eventPhase to an enum rather than just an integer, since only the getter is for use from the bindings. Removed clearEventPath, srcElement, and resetPropagationFlags. Sorted the isXXX functions alphabetically and removed previous attempts to make categories out of them. Marked the constructor explicit since it has a single argument. Moved trivially short bodies into the class definition. * dom/Event.idl: Use ImplementedAs to implement srcElement so we don't need it in the C++ code. * dom/EventContext.cpp: (WebCore::EventContext::EventContext): Removed assertion since we now handle event contexts without nodes so we can use this to dispatch events for IDB, for example. (WebCore::EventContext::handleLocalEvents const): Add code to handle non-node event targets by calling fireEventListeners directly. (WebCore::MouseOrFocusEventContext::MouseOrFocusEventContext): Take a reference insetad of a pointer for the node. (WebCore::TouchEventContext::TouchEventContext): Ditto. (WebCore::TouchEventContext::handleLocalEvents const): Streamline a bit by improving the checkReachability function to be easier to call. Also removed an unneeded assertion just before calling downcast<>, the same assertion that downcast<> itself does. (WebCore::TouchEventContext::checkReachability const): Chagned argument type to take a Ref& so the caller doesn't have to call get() or ptr(). * dom/EventContext.h: Removed unneeded FIXME and currentTargetSameAsTarget function. Changed arguemnt types to use Node& instead of Node* as appropriate. Removed unused functions from TouchEventContext, made more private, and changed data members to Ref instead of RefPtr. Removed unused NotTouchList value from TouchListType enumeration. Changed touchList function to return a reference instead of a pointer. * dom/EventDispatcher.cpp: Removed unneeded includes. (WebCore::dispatchEventInDOM): Removed use of currentTargetSameAsTarget since it's clearer if written out. (WebCore::EventDispatcher::dispatchEvent): Changed no-event dispatch assertion to use RELEASE_ASSERT_WITH_SECURITY_IMPLICATION since the style checker says so, but it still doesn't assert anything in release builds because the check in NoEventDispatchAssertion itself is debug-only. Moved the calls to EventPath's setRelatedTarget and retargetTouchLists functions inside the EventPath constructor. Removed the second no-event dispatch assertion because we only need one. Replaced calls to clearEventPath, setCurrentTarget(nullptr), resetPropagationFlags, and setEventPhase(NONE) and with a call to resetAfterDispatch. Moved the code that temporarily sets the target to a different value when calling default event handlers into the block that calls the default event handlers. Added a new overload that takes an initializer list of event targets so we can dispatch events that are not being sent to nodes. * dom/EventDispatcher.h: Fixed misleading copyright dates and names since this file just contains a couple of function declarations. Added new overload of dispatchEvent. * dom/EventPath.cpp: (WebCore::WindowEventContext::WindowEventContext): Take references instead of pointers. (WebCore::EventPath::EventPath): Moved the bulk of construction into a new function named buildPath, so it can still use "return" without skipping the additions here. Added calls to setRelatedTarget and retargetTouchLists and now both can be private. Also added a new overload that takes event targets that are not nodes. (WebCore::EventPath::buildPath): Added. Contains what used to be in the constructor. But use some references instead of pointers and refactor a bit using lambdas. (WebCore::EventPath::retargetTouchList): Added. Makes the retargetTouchLists function shorter and less repetetive. (WebCore::EventPath::retargetTouchLists): Updated to call retargetTouchList. (WebCore::EventPath::hasEventListeners const): Deleted. This was unused. * dom/EventPath.h: Added a constructor that takes an initializer list of event targets. Made retargetTouchEvents and setRelatedTarget private and used them in the constructor insead of expecting clients to call them. Removed unused hasEventListeners and lastContextIfExists functions. Moved body of the eventTargetRespectingTargetRules function out of the class definition. * dom/EventTarget.cpp: (WebCore::EventTarget::dispatchEventForBindings): Updated so it does not expect dispatchEvent to return a boolean. Instead call a function on the event after dispatching. Decided to use legacyReturnValue instead of !defaultPrevented, because this is exactly the return value that the returnValue property is referring to. (WebCore::EventTarget::dispatchEvent): Removed return value. Replaced calls to resetPropagationFlags and setEventPhase(NONE) with a call to resetAfterDispatch. I noticed that there was a local boolean here named "defaultPrevented", which was backwards; the value in that local was "default not prevented". Doesn't matter since the boolean return value was removed. (WebCore::EventTarget::fireEventListeners): Removed the boolean return value. * dom/EventTarget.h: Added initial values to members of ListenerOptions and AddEventListenerOptions; maybe we can get rid of the constructors some day. Removed booelan return values from dispatchEvent and fireEventListeners. * dom/KeyboardEvent.cpp: Removed unneeded include of EventDispatcher.h. * dom/Node.cpp: (WebCore::Node::dispatchEvent): Got rid of boolean return value. Removed special case code that sometimes called dispatchTouchEvent, since that just turns around and calls EventDispatcher::dispatchEvent just like this function. (WebCore::Node::dispatchDOMActivateEvent): Removed boolean return value, removed integer detail argument and moved the logic to compute the value of the detail peroprty and to call setDefaultHandled on the underlying click event in here. This is a private helper function used only in one place. (WebCore::Node::dispatchTouchEvent): Deleted. (WebCore::Node::defaultEventHandler): Updated for change to dispatchDOMActivateEvent. * dom/Node.h: Updated for the above changes. * dom/RejectedPromiseTracker.cpp: (WebCore::RejectedPromiseTracker::reportUnhandledRejections): Use defaultPrevented directly instead of the return value from dispatchEvent. * dom/ScopedEventQueue.cpp: (WebCore::ScopedEventQueue::enqueueEvent): Moved assertions here ... (WebCore::ScopedEventQueue::dispatchEvent const): ... from here. Also changed this to call Node::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * dom/SimulatedClick.cpp: (WebCore::simulateMouseEvent): Call Element::dispatchEvent instead of calling EventDispatcher::dispatchEvent directly. * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): Use defaultPrevented directly instead of the return value from dispatchEvent. * editing/FrameSelection.cpp: (WebCore::FrameSelection::selectAll): Ditto. (WebCore::FrameSelection::dispatchSelectStart): Ditto. * html/CheckboxInputType.cpp: (WebCore::CheckboxInputType::didDispatchClick): Take a reference instead of a pointer. * html/CheckboxInputType.h: Updated for above and to use final instead of override. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::checkValidity): Use defaultPrevented directly instead of the return value from dispatchEvent. * html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareForSubmission): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::HTMLFormElement::reset): Ditto. * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::didDispatchClickEvent): Updated to pass references instead of pointer. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::dispatchEvent): Got rid of boolean return value. * html/HTMLMediaElement.h: Ditto. * html/HTMLPlugInElement.h: Use "delete" instead of just a private function for something that should never be called. * html/InputType.cpp: (WebCore::InputType::didDispatchClick): Take a reference instead of a pointer. * html/InputType.h: Ditto. * html/RadioInputType.cpp: (WebCore::RadioInputType::didDispatchClick): Ditto. * html/RadioInputType.h: Updated for above and to use final instead of override. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::dispatchEvent): Got rid of boolean return value. * html/track/TextTrackCue.h: Ditto. * inspector/InspectorInstrumentation.cpp: Removed unneeded include of EventDispatcher.h. * page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Streamlined code a bit so we only have a single call to dispatchEvent. Improved comments. (WebCore::DOMWindow::dispatchEvent): Removed return value. Added comments. Replaced calls to setCurrentTarget(null), setEventPhase(NONE), and resetPropagationFlags with a call to resetAfterDispatch. * page/DOMWindow.h: Updated to get rid of the boolean return value. * page/DragController.cpp: (WebCore::DragController::dispatchTextInputEventFor): Use defaultPrevented directly instead of the return value from dispatchEvent. * page/EventHandler.cpp: (WebCore::dispatchSelectStart): Use defaultPrevented directly instead of the return value from dispatchEvent. (WebCore::EventHandler::accessibilityPreventsEventPropagation): Fixed spelling error in the name of this function. (WebCore::EventHandler::dispatchDragSrcEvent): Got rid of boolean return value. (WebCore::EventHandler::handleTouchEvent): Call dispatchEvent instead of dispatchTouchEvent; there was no difference between the two except that dispatchTouchEvent required downcasting and might some day lead to us missing some behavior implemented in an override to dispatchEvent. * page/EventHandler.h: Updated for above changes. * platform/graphics/filters/FilterOperation.h: (WebCore::FilterOperation::clone): Removed dead code that was causing a compiler warning. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Use defaultPrevented directly instead of the return value from dispatchEvent. Source/WebKit: * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMEvent.cpp: (webkit_dom_event_get_src_element): Call target instead of srcElement. Source/WebKitLegacy/mac: * DOM/DOMEvent.mm: (-[DOMEvent srcElement]): Call target instead of srcElement. Canonical link: https://commits.webkit.org/195384@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-04 21:19:11 +00:00
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#endif // ASSERT_ENABLED
}