Title: [261279] trunk
Revision
261279
Author
[email protected]
Date
2020-05-07 04:16:30 -0700 (Thu, 07 May 2020)

Log Message

Add basic support for generating accurate wheel event listener region
https://bugs.webkit.org/show_bug.cgi?id=211512

Reviewed by Simon Fraser.

Source/WebCore:

Add fake properties for wheel event listeners to RenderStyle and use them to
generate regions in EventRegion. There is a separate region for non-passive
wheel event listeners (that will require synchronous handling).

The generated regions are not used for anything in this patch.
Style is not yet invalided on event listener additions and removals.

Test: fast/scrolling/mac/wheel-event-listener-region-basic.html

* dom/Node.h:
* rendering/EventRegion.cpp:
(WebCore::EventRegion::unite):
(WebCore::EventRegion::uniteEventListeners):
(WebCore::EventRegion::dump const):
* rendering/EventRegion.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateEventRegion):
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::eventListenerRegionTypes const):
(WebCore::RenderStyle::setEventListenerRegionTypes):
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleRareInheritedData.cpp:
(WebCore::StyleRareInheritedData::StyleRareInheritedData):
(WebCore::StyleRareInheritedData::operator== const):
* rendering/style/StyleRareInheritedData.h:
* style/StyleAdjuster.cpp:
(WebCore::Style::computeEventListenerRegionTypes):
(WebCore::Style::Adjuster::adjust const):

LayoutTests:

* fast/scrolling/mac/wheel-event-listener-region-basic-expected.txt: Added.
* fast/scrolling/mac/wheel-event-listener-region-basic.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (261278 => 261279)


--- trunk/LayoutTests/ChangeLog	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/LayoutTests/ChangeLog	2020-05-07 11:16:30 UTC (rev 261279)
@@ -1,3 +1,13 @@
+2020-05-07  Antti Koivisto  <[email protected]>
+
+        Add basic support for generating accurate wheel event listener region
+        https://bugs.webkit.org/show_bug.cgi?id=211512
+
+        Reviewed by Simon Fraser.
+
+        * fast/scrolling/mac/wheel-event-listener-region-basic-expected.txt: Added.
+        * fast/scrolling/mac/wheel-event-listener-region-basic.html: Added.
+
 2020-05-07  Diego Pino Garcia  <[email protected]>
 
         [GTK][WPE] Gardening, update test expectations after r259705

Added: trunk/LayoutTests/fast/scrolling/mac/wheel-event-listener-region-basic-expected.txt (0 => 261279)


--- trunk/LayoutTests/fast/scrolling/mac/wheel-event-listener-region-basic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/wheel-event-listener-region-basic-expected.txt	2020-05-07 11:16:30 UTC (rev 261279)
@@ -0,0 +1,26 @@
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (drawsContent 1)
+      (backgroundColor #FFFFFF)
+      (event region
+        (rect (0,0) width=800 height=600)
+      (wheel event listener region
+        (rect (8,8) width=250 height=50)
+        (rect (8,58) width=200 height=150)
+        (rect (208,208) width=250 height=50)
+        (rect (208,258) width=200 height=150)
+        (non-passive
+          (rect (8,8) width=250 height=50)
+          (rect (8,58) width=200 height=150)
+        )
+      )
+      )
+    )
+  )
+)
+

Added: trunk/LayoutTests/fast/scrolling/mac/wheel-event-listener-region-basic.html (0 => 261279)


--- trunk/LayoutTests/fast/scrolling/mac/wheel-event-listener-region-basic.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/wheel-event-listener-region-basic.html	2020-05-07 11:16:30 UTC (rev 261279)
@@ -0,0 +1,44 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<style>
+.event {
+    position:relative;
+    background-color:blue;
+    width:200px;
+    height:200px;
+}
+.child {
+    position:relative;
+    background-color:blue;
+    left:200px;
+    width:50px;
+    height:50px;
+}
+.offset {
+    left: 200px;
+}
+
+</style>
+<script>
+window._onload_ = () => {
+    if (window.testRunner)
+        testRunner.dumpAsText();
+
+    if (window.internals)
+        results.innerText = internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_EVENT_REGION | internals.LAYER_TREE_INCLUDES_ROOT_LAYER_PROPERTIES);
+}
+</script>
+<body>
+<div class="event" _onwheel_="results.textContent += 'wheel\n'">
+    <div class="child"></div>
+</div>
+<div class="event offset" id="passive">
+    <div class="child"></div>
+</div>
+<script>
+passive.addEventListener('wheel', () => { results.textContent += 'passive wheel\n' }, { passive: true });
+</script>
+<pre id="results"></pre>
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (261278 => 261279)


--- trunk/Source/WebCore/ChangeLog	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/ChangeLog	2020-05-07 11:16:30 UTC (rev 261279)
@@ -1,3 +1,39 @@
+2020-05-07  Antti Koivisto  <[email protected]>
+
+        Add basic support for generating accurate wheel event listener region
+        https://bugs.webkit.org/show_bug.cgi?id=211512
+
+        Reviewed by Simon Fraser.
+
+        Add fake properties for wheel event listeners to RenderStyle and use them to
+        generate regions in EventRegion. There is a separate region for non-passive
+        wheel event listeners (that will require synchronous handling).
+
+        The generated regions are not used for anything in this patch.
+        Style is not yet invalided on event listener additions and removals.
+
+        Test: fast/scrolling/mac/wheel-event-listener-region-basic.html
+
+        * dom/Node.h:
+        * rendering/EventRegion.cpp:
+        (WebCore::EventRegion::unite):
+        (WebCore::EventRegion::uniteEventListeners):
+        (WebCore::EventRegion::dump const):
+        * rendering/EventRegion.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateEventRegion):
+        * rendering/style/RenderStyle.h:
+        (WebCore::RenderStyle::eventListenerRegionTypes const):
+        (WebCore::RenderStyle::setEventListenerRegionTypes):
+        * rendering/style/RenderStyleConstants.h:
+        * rendering/style/StyleRareInheritedData.cpp:
+        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
+        (WebCore::StyleRareInheritedData::operator== const):
+        * rendering/style/StyleRareInheritedData.h:
+        * style/StyleAdjuster.cpp:
+        (WebCore::Style::computeEventListenerRegionTypes):
+        (WebCore::Style::Adjuster::adjust const):
+
 2020-05-07  Youenn Fablet  <[email protected]>
 
         Sending WebRTC network packets should not go through the main thread

Modified: trunk/Source/WebCore/dom/Node.h (261278 => 261279)


--- trunk/Source/WebCore/dom/Node.h	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/dom/Node.h	2020-05-07 11:16:30 UTC (rev 261279)
@@ -482,6 +482,7 @@
     bool m_adoptionIsRequired { true };
 #endif
 
+    using EventTarget::eventTargetData;
     EventTargetData* eventTargetData() final;
     EventTargetData* eventTargetDataConcurrently() final;
     EventTargetData& ensureEventTargetData() final;

Modified: trunk/Source/WebCore/rendering/EventRegion.cpp (261278 => 261279)


--- trunk/Source/WebCore/rendering/EventRegion.cpp	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/EventRegion.cpp	2020-05-07 11:16:30 UTC (rev 261279)
@@ -112,6 +112,7 @@
     m_region.unite(region);
 
     uniteTouchActions(region, style.effectiveTouchActions());
+    uniteEventListeners(region, style.eventListenerRegionTypes());
 
 #if ENABLE(EDITABLE_REGION)
     if (overrideUserModifyIsEditable || style.userModify() != UserModify::ReadOnly)
@@ -220,6 +221,14 @@
     return actions;
 }
 
+void EventRegion::uniteEventListeners(const Region& region, OptionSet<EventListenerRegionType> eventListenerRegionTypes)
+{
+    if (eventListenerRegionTypes.contains(EventListenerRegionType::Wheel))
+        m_wheelEventListenerRegion.unite(region);
+    if (eventListenerRegionTypes.contains(EventListenerRegionType::NonPassiveWheel))
+        m_nonPassiveWheelEventListenerRegion.unite(region);
+}
+
 #if ENABLE(EDITABLE_REGION)
 
 bool EventRegion::containsEditableElementsInRect(const IntRect& rect) const
@@ -247,6 +256,16 @@
         ts << indent << ")\n";
     }
 
+    if (!m_wheelEventListenerRegion.isEmpty()) {
+        ts << indent << "(wheel event listener region" << m_wheelEventListenerRegion;
+        if (!m_nonPassiveWheelEventListenerRegion.isEmpty()) {
+            TextStream::IndentScope indentScope(ts);
+            ts << indent << "(non-passive" << m_nonPassiveWheelEventListenerRegion;
+            ts << indent << ")\n";
+        }
+        ts << indent << ")\n";
+    }
+
 #if ENABLE(EDITABLE_REGION)
     if (!m_editableRegion.isEmpty()) {
         ts << indent << "(editable region" << m_editableRegion;

Modified: trunk/Source/WebCore/rendering/EventRegion.h (261278 => 261279)


--- trunk/Source/WebCore/rendering/EventRegion.h	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/EventRegion.h	2020-05-07 11:16:30 UTC (rev 261279)
@@ -27,6 +27,7 @@
 
 #include "AffineTransform.h"
 #include "Region.h"
+#include "RenderStyleConstants.h"
 #include "TouchAction.h"
 #include <wtf/OptionSet.h>
 #include <wtf/Vector.h>
@@ -76,7 +77,6 @@
 
     bool hasTouchActions() const { return !m_touchActionRegions.isEmpty(); }
     WEBCORE_EXPORT OptionSet<TouchAction> touchActionsForPoint(const IntPoint&) const;
-
     const Region* regionForTouchAction(TouchAction) const;
 
 #if ENABLE(EDITABLE_REGION)
@@ -93,9 +93,12 @@
 
 private:
     void uniteTouchActions(const Region&, OptionSet<TouchAction>);
+    void uniteEventListeners(const Region&, OptionSet<EventListenerRegionType>);
 
     Region m_region;
     Vector<Region> m_touchActionRegions;
+    Region m_wheelEventListenerRegion;
+    Region m_nonPassiveWheelEventListenerRegion;
 #if ENABLE(EDITABLE_REGION)
     Region m_editableRegion;
 #endif

Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (261278 => 261279)


--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2020-05-07 11:16:30 UTC (rev 261279)
@@ -1653,10 +1653,13 @@
 #if ENABLE(ASYNC_SCROLLING)
 void RenderLayerBacking::updateEventRegion()
 {
-    if (paintsIntoCompositedAncestor())
-        return;
+    auto needsUpdate = [&] {
+        if (!m_owningLayer.page().scrollingCoordinator())
+            return false;
 
-    auto needsUpdate = [&] {
+        if (paintsIntoCompositedAncestor())
+            return false;
+
         if (renderer().view().needsEventRegionUpdateForNonCompositedFrame())
             return true;
         
@@ -1668,6 +1671,10 @@
         if (renderer().document().mayHaveEditableElements())
             return true;
 #endif
+#if !PLATFORM(IOS_FAMILY)
+        if (renderer().document().wheelEventTargets())
+            return true;
+#endif
         if (m_owningLayer.isRenderViewLayer())
             return false;
 

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (261278 => 261279)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2020-05-07 11:16:30 UTC (rev 261279)
@@ -691,9 +691,10 @@
     int initialLetterDrop() const { return initialLetter().width(); }
     int initialLetterHeight() const { return initialLetter().height(); }
 
-    OptionSet<TouchAction> touchActions() const { return OptionSet<TouchAction>::fromRaw(m_rareNonInheritedData->touchActions); }
+    OptionSet<TouchAction> touchActions() const { return m_rareNonInheritedData->touchActions; }
     // 'touch-action' behavior depends on values in ancestors. We use an additional inherited property to implement that.
-    OptionSet<TouchAction> effectiveTouchActions() const { return OptionSet<TouchAction>::fromRaw(m_rareInheritedData->effectiveTouchActions); }
+    OptionSet<TouchAction> effectiveTouchActions() const { return m_rareInheritedData->effectiveTouchActions; }
+    OptionSet<EventListenerRegionType> eventListenerRegionTypes() const { return m_rareInheritedData->eventListenerRegionTypes; }
 
 #if ENABLE(CSS_SCROLL_SNAP)
     // Scroll snap port style.
@@ -1226,8 +1227,9 @@
     
     void setInitialLetter(const IntSize& size) { SET_VAR(m_rareNonInheritedData, initialLetter, size); }
     
-    void setTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareNonInheritedData, touchActions, touchActions.toRaw()); }
-    void setEffectiveTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareInheritedData, effectiveTouchActions, touchActions.toRaw()); }
+    void setTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareNonInheritedData, touchActions, touchActions); }
+    void setEffectiveTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareInheritedData, effectiveTouchActions, touchActions); }
+    void setEventListenerRegionTypes(OptionSet<EventListenerRegionType> eventListenerTypes) { SET_VAR(m_rareInheritedData, eventListenerRegionTypes, eventListenerTypes); }
 
 #if ENABLE(CSS_SCROLL_SNAP)
     void setScrollSnapType(const ScrollSnapType&);

Modified: trunk/Source/WebCore/rendering/style/RenderStyleConstants.h (261278 => 261279)


--- trunk/Source/WebCore/rendering/style/RenderStyleConstants.h	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/style/RenderStyleConstants.h	2020-05-07 11:16:30 UTC (rev 261279)
@@ -1180,6 +1180,11 @@
     Optional
 };
 
+enum class EventListenerRegionType : uint8_t {
+    Wheel           = 1 << 0,
+    NonPassiveWheel = 1 << 1,
+};
+
 extern const float defaultMiterLimit;
 
 WTF::TextStream& operator<<(WTF::TextStream&, AnimationFillMode);

Modified: trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp (261278 => 261279)


--- trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp	2020-05-07 11:16:30 UTC (rev 261279)
@@ -133,7 +133,7 @@
     , joinStyle(RenderStyle::initialJoinStyle())
     , hasSetStrokeWidth(false)
     , hasSetStrokeColor(false)
-    , effectiveTouchActions(static_cast<unsigned>(RenderStyle::initialTouchActions()))
+    , effectiveTouchActions(RenderStyle::initialTouchActions())
     , strokeWidth(RenderStyle::initialStrokeWidth())
     , strokeColor(RenderStyle::initialStrokeColor())
     , miterLimit(RenderStyle::initialStrokeMiterLimit())
@@ -228,6 +228,7 @@
     , hasSetStrokeWidth(o.hasSetStrokeWidth)
     , hasSetStrokeColor(o.hasSetStrokeColor)
     , effectiveTouchActions(o.effectiveTouchActions)
+    , eventListenerRegionTypes(o.eventListenerRegionTypes)
     , strokeWidth(o.strokeWidth)
     , strokeColor(o.strokeColor)
     , visitedLinkStrokeColor(o.visitedLinkStrokeColor)
@@ -349,6 +350,7 @@
         && hasSetStrokeWidth == o.hasSetStrokeWidth
         && hasSetStrokeColor == o.hasSetStrokeColor
         && effectiveTouchActions == o.effectiveTouchActions
+        && eventListenerRegionTypes == o.eventListenerRegionTypes
         && strokeWidth == o.strokeWidth
         && strokeColor == o.strokeColor
         && visitedLinkStrokeColor == o.visitedLinkStrokeColor

Modified: trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h (261278 => 261279)


--- trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h	2020-05-07 11:16:30 UTC (rev 261279)
@@ -30,6 +30,7 @@
 #include "TabSize.h"
 #include "TextDecorationThickness.h"
 #include "TextUnderlineOffset.h"
+#include "TouchAction.h"
 #include <wtf/DataRef.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/AtomString.h>
@@ -154,7 +155,8 @@
     unsigned hasSetStrokeWidth : 1;
     unsigned hasSetStrokeColor : 1;
 
-    unsigned effectiveTouchActions : 6; // OptionSet<TouchAction>
+    OptionSet<TouchAction> effectiveTouchActions;
+    OptionSet<EventListenerRegionType> eventListenerRegionTypes;
 
     Length strokeWidth;
     Color strokeColor;

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp (261278 => 261279)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2020-05-07 11:16:30 UTC (rev 261279)
@@ -81,7 +81,7 @@
     , justifyItems(RenderStyle::initialJustifyItems())
     , justifySelf(RenderStyle::initialSelfAlignment())
     , customProperties(StyleCustomPropertyData::create())
-    , touchActions(static_cast<unsigned>(RenderStyle::initialTouchActions()))
+    , touchActions(RenderStyle::initialTouchActions())
     , pageSizeType(PAGE_SIZE_AUTO)
     , transformStyle3D(static_cast<unsigned>(RenderStyle::initialTransformStyle3D()))
     , backfaceVisibility(static_cast<unsigned>(RenderStyle::initialBackfaceVisibility()))

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h (261278 => 261279)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h	2020-05-07 11:16:30 UTC (rev 261279)
@@ -173,7 +173,7 @@
     DataRef<StyleCustomPropertyData> customProperties;
     std::unique_ptr<HashSet<String>> customPaintWatchedProperties;
 
-    unsigned touchActions : 6; // TouchAction
+    OptionSet<TouchAction> touchActions;
 
     unsigned pageSizeType : 2; // PageSizeType
     unsigned transformStyle3D : 1; // TransformStyle3D

Modified: trunk/Source/WebCore/style/StyleAdjuster.cpp (261278 => 261279)


--- trunk/Source/WebCore/style/StyleAdjuster.cpp	2020-05-07 09:36:48 UTC (rev 261278)
+++ trunk/Source/WebCore/style/StyleAdjuster.cpp	2020-05-07 11:16:30 UTC (rev 261279)
@@ -33,6 +33,7 @@
 #include "AnimationBase.h"
 #include "CSSFontSelector.h"
 #include "Element.h"
+#include "EventNames.h"
 #include "FrameView.h"
 #include "HTMLDivElement.h"
 #include "HTMLInputElement.h"
@@ -192,6 +193,44 @@
     return sharedTouchActions;
 }
 
+static OptionSet<EventListenerRegionType> computeEventListenerRegionTypes(const Element& element, OptionSet<EventListenerRegionType> parentTypes)
+{
+#if !PLATFORM(IOS_FAMILY)
+    if (!element.hasEventListeners())
+        return parentTypes;
+
+    auto types = parentTypes;
+
+    auto findListeners = [&](auto& eventName, auto type, auto nonPassiveType) {
+        auto* eventListenerVector = element.eventTargetData()->eventListenerMap.find(eventName);
+        if (!eventListenerVector)
+            return;
+
+        types.add(type);
+
+        auto isPassiveOnly = [&] {
+            for (auto& listener : *eventListenerVector) {
+                if (!listener->isPassive())
+                    return false;
+            }
+            return true;
+        }();
+
+        if (!isPassiveOnly)
+            types.add(nonPassiveType);
+    };
+
+    findListeners(eventNames().wheelEvent, EventListenerRegionType::Wheel, EventListenerRegionType::NonPassiveWheel);
+    findListeners(eventNames().mousewheelEvent, EventListenerRegionType::Wheel, EventListenerRegionType::NonPassiveWheel);
+
+    return types;
+#else
+    UNUSED_PARAM(element);
+    UNUSED_PARAM(parentTypes);
+    return { };
+#endif
+}
+
 void Adjuster::adjust(RenderStyle& style, const RenderStyle* userAgentAppearanceStyle) const
 {
     // Cache our original display.
@@ -437,6 +476,9 @@
 
     style.setEffectiveTouchActions(computeEffectiveTouchActions(style, m_parentStyle.effectiveTouchActions()));
 
+    if (m_element)
+        style.setEventListenerRegionTypes(computeEventListenerRegionTypes(*m_element, m_parentStyle.eventListenerRegionTypes()));
+
 #if ENABLE(TEXT_AUTOSIZING)
     if (m_element)
         adjustForTextAutosizing(style, *m_element);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to