Commit 667f001d authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

Add use counter for document level wheel event listeners.

This cl adds use counters to find out the ratio of the web pages that
add document level wheel event listeners with passive:false, true, or
unspecified. It also counts the number of document level wheel event
listeners with passive:unspecified that preventDefault wheel events.

This information is useful to investigate the potential performance
benefits and risks of changing the default value of the passive option
to be true for document level wheel/mousewheel event listeners.

Bug: 626196
Change-Id: Ib0ee64b1a5085813d9b70073747ec3f544fbb660
Reviewed-on: https://chromium-review.googlesource.com/1148783
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578695}
parent ae08f33b
...@@ -1974,6 +1974,10 @@ enum WebFeature { ...@@ -1974,6 +1974,10 @@ enum WebFeature {
kV8RTCRtpTransceiver_Direction_AttributeSetter = 2515, kV8RTCRtpTransceiver_Direction_AttributeSetter = 2515,
kHTMLLinkElementDisabledByParser = 2516, kHTMLLinkElementDisabledByParser = 2516,
kRequestIsHistoryNavigation = 2517, kRequestIsHistoryNavigation = 2517,
kAddDocumentLevelPassiveTrueWheelEventListener = 2518,
kAddDocumentLevelPassiveFalseWheelEventListener = 2519,
kAddDocumentLevelPassiveDefaultWheelEventListener = 2520,
kDocumentLevelPassiveDefaultEventListenerPreventedWheel = 2521,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -97,10 +97,14 @@ bool IsTouchScrollBlockingEvent(const AtomicString& event_type) { ...@@ -97,10 +97,14 @@ bool IsTouchScrollBlockingEvent(const AtomicString& event_type) {
event_type == EventTypeNames::touchmove; event_type == EventTypeNames::touchmove;
} }
bool IsWheelScrollBlockingEvent(const AtomicString& event_type) {
return event_type == EventTypeNames::mousewheel ||
event_type == EventTypeNames::wheel;
}
bool IsScrollBlockingEvent(const AtomicString& event_type) { bool IsScrollBlockingEvent(const AtomicString& event_type) {
return IsTouchScrollBlockingEvent(event_type) || return IsTouchScrollBlockingEvent(event_type) ||
event_type == EventTypeNames::mousewheel || IsWheelScrollBlockingEvent(event_type);
event_type == EventTypeNames::wheel;
} }
bool IsInstrumentedForAsyncStack(const AtomicString& event_type) { bool IsInstrumentedForAsyncStack(const AtomicString& event_type) {
...@@ -208,6 +212,22 @@ inline LocalDOMWindow* EventTarget::ExecutingWindow() { ...@@ -208,6 +212,22 @@ inline LocalDOMWindow* EventTarget::ExecutingWindow() {
return nullptr; return nullptr;
} }
bool EventTarget::IsTopLevelNode() {
if (ToLocalDOMWindow())
return true;
Node* node = ToNode();
if (!node)
return false;
if (node->IsDocumentNode() || node->GetDocument().documentElement() == node ||
node->GetDocument().body() == node) {
return true;
}
return false;
}
void EventTarget::SetDefaultAddEventListenerOptions( void EventTarget::SetDefaultAddEventListenerOptions(
const AtomicString& event_type, const AtomicString& event_type,
EventListener* event_listener, EventListener* event_listener,
...@@ -232,19 +252,25 @@ void EventTarget::SetDefaultAddEventListenerOptions( ...@@ -232,19 +252,25 @@ void EventTarget::SetDefaultAddEventListenerOptions(
if (RuntimeEnabledFeatures::PassiveDocumentEventListenersEnabled() && if (RuntimeEnabledFeatures::PassiveDocumentEventListenersEnabled() &&
IsTouchScrollBlockingEvent(event_type)) { IsTouchScrollBlockingEvent(event_type)) {
if (!options.hasPassive()) { if (!options.hasPassive() && IsTopLevelNode()) {
if (Node* node = ToNode()) { options.setPassive(true);
if (node->IsDocumentNode() || options.SetPassiveForcedForDocumentTarget(true);
node->GetDocument().documentElement() == node || return;
node->GetDocument().body() == node) { }
options.setPassive(true); }
options.SetPassiveForcedForDocumentTarget(true);
return; if (IsWheelScrollBlockingEvent(event_type) && IsTopLevelNode()) {
} if (executing_window) {
} else if (ToLocalDOMWindow()) { if (options.hasPassive()) {
options.setPassive(true); UseCounter::Count(
options.SetPassiveForcedForDocumentTarget(true); executing_window->document(),
return; options.passive()
? WebFeature::kAddDocumentLevelPassiveTrueWheelEventListener
: WebFeature::kAddDocumentLevelPassiveFalseWheelEventListener);
} else {
UseCounter::Count(
executing_window->document(),
WebFeature::kAddDocumentLevelPassiveDefaultWheelEventListener);
} }
} }
} }
......
...@@ -180,6 +180,9 @@ class CORE_EXPORT EventTarget : public ScriptWrappable { ...@@ -180,6 +180,9 @@ class CORE_EXPORT EventTarget : public ScriptWrappable {
virtual bool KeepEventInNode(Event*) { return false; } virtual bool KeepEventInNode(Event*) { return false; }
// Returns true if the target is window, window.document, or window.document.body.
bool IsTopLevelNode();
protected: protected:
EventTarget(); EventTarget();
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "third_party/blink/renderer/core/events/wheel_event.h" #include "third_party/blink/renderer/core/events/wheel_event.h"
#include "third_party/blink/renderer/core/clipboard/data_transfer.h" #include "third_party/blink/renderer/core/clipboard/data_transfer.h"
#include "third_party/blink/renderer/core/frame/use_counter.h"
namespace blink { namespace blink {
...@@ -115,6 +116,19 @@ bool WheelEvent::IsWheelEvent() const { ...@@ -115,6 +116,19 @@ bool WheelEvent::IsWheelEvent() const {
return true; return true;
} }
void WheelEvent::preventDefault() {
UIEventWithKeyState::preventDefault();
if (HandlingPassive() == PassiveMode::kNotPassiveDefault &&
currentTarget()->IsTopLevelNode()) {
if (ExecutionContext* context = currentTarget()->GetExecutionContext()) {
UseCounter::Count(
context,
WebFeature::kDocumentLevelPassiveDefaultEventListenerPreventedWheel);
}
}
}
DispatchEventResult WheelEvent::DispatchEvent(EventDispatcher& dispatcher) { DispatchEventResult WheelEvent::DispatchEvent(EventDispatcher& dispatcher) {
return dispatcher.Dispatch(); return dispatcher.Dispatch();
} }
......
...@@ -70,6 +70,8 @@ class CORE_EXPORT WheelEvent final : public MouseEvent { ...@@ -70,6 +70,8 @@ class CORE_EXPORT WheelEvent final : public MouseEvent {
bool IsMouseEvent() const override; bool IsMouseEvent() const override;
bool IsWheelEvent() const override; bool IsWheelEvent() const override;
void preventDefault() override;
const WebMouseWheelEvent& NativeEvent() const { return native_event_; } const WebMouseWheelEvent& NativeEvent() const { return native_event_; }
// WheelEvent doesn't modify the event path, but its parent MouseEvent does. // WheelEvent doesn't modify the event path, but its parent MouseEvent does.
......
...@@ -19469,6 +19469,11 @@ Called by update_net_error_codes.py.--> ...@@ -19469,6 +19469,11 @@ Called by update_net_error_codes.py.-->
<int value="2515" label="V8RTCRtpTransceiver_Direction_AttributeSetter"/> <int value="2515" label="V8RTCRtpTransceiver_Direction_AttributeSetter"/>
<int value="2516" label="HTMLLinkElementDisabledByParser"/> <int value="2516" label="HTMLLinkElementDisabledByParser"/>
<int value="2517" label="RequestIsHistoryNavigation"/> <int value="2517" label="RequestIsHistoryNavigation"/>
<int value="2518" label="AddDocumentLevelPassiveTrueWheelEventListener"/>
<int value="2519" label="AddDocumentLevelPassiveFalseWheelEventListener"/>
<int value="2520" label="AddDocumentLevelPassiveDefaultWheelEventListener"/>
<int value="2521"
label="DocumentLevelPassiveDefaultEventListenerPreventedWheel"/>
</enum> </enum>
<enum name="FeedbackSource"> <enum name="FeedbackSource">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment