Changeset 261279 in webkit


Ignore:
Timestamp:
May 7, 2020 4:16:30 AM (4 years ago)
Author:
Antti Koivisto
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.
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r261272 r261279  
     12020-05-07  Antti Koivisto  <antti@apple.com>
     2
     3        Add basic support for generating accurate wheel event listener region
     4        https://bugs.webkit.org/show_bug.cgi?id=211512
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/scrolling/mac/wheel-event-listener-region-basic-expected.txt: Added.
     9        * fast/scrolling/mac/wheel-event-listener-region-basic.html: Added.
     10
    1112020-05-07  Diego Pino Garcia  <dpino@igalia.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r261277 r261279  
     12020-05-07  Antti Koivisto  <antti@apple.com>
     2
     3        Add basic support for generating accurate wheel event listener region
     4        https://bugs.webkit.org/show_bug.cgi?id=211512
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add fake properties for wheel event listeners to RenderStyle and use them to
     9        generate regions in EventRegion. There is a separate region for non-passive
     10        wheel event listeners (that will require synchronous handling).
     11
     12        The generated regions are not used for anything in this patch.
     13        Style is not yet invalided on event listener additions and removals.
     14
     15        Test: fast/scrolling/mac/wheel-event-listener-region-basic.html
     16
     17        * dom/Node.h:
     18        * rendering/EventRegion.cpp:
     19        (WebCore::EventRegion::unite):
     20        (WebCore::EventRegion::uniteEventListeners):
     21        (WebCore::EventRegion::dump const):
     22        * rendering/EventRegion.h:
     23        * rendering/RenderLayerBacking.cpp:
     24        (WebCore::RenderLayerBacking::updateEventRegion):
     25        * rendering/style/RenderStyle.h:
     26        (WebCore::RenderStyle::eventListenerRegionTypes const):
     27        (WebCore::RenderStyle::setEventListenerRegionTypes):
     28        * rendering/style/RenderStyleConstants.h:
     29        * rendering/style/StyleRareInheritedData.cpp:
     30        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
     31        (WebCore::StyleRareInheritedData::operator== const):
     32        * rendering/style/StyleRareInheritedData.h:
     33        * style/StyleAdjuster.cpp:
     34        (WebCore::Style::computeEventListenerRegionTypes):
     35        (WebCore::Style::Adjuster::adjust const):
     36
    1372020-05-07  Youenn Fablet  <youenn@apple.com>
    238
  • trunk/Source/WebCore/dom/Node.h

    r261253 r261279  
    483483#endif
    484484
     485    using EventTarget::eventTargetData;
    485486    EventTargetData* eventTargetData() final;
    486487    EventTargetData* eventTargetDataConcurrently() final;
  • trunk/Source/WebCore/rendering/EventRegion.cpp

    r261253 r261279  
    113113
    114114    uniteTouchActions(region, style.effectiveTouchActions());
     115    uniteEventListeners(region, style.eventListenerRegionTypes());
    115116
    116117#if ENABLE(EDITABLE_REGION)
     
    221222}
    222223
     224void EventRegion::uniteEventListeners(const Region& region, OptionSet<EventListenerRegionType> eventListenerRegionTypes)
     225{
     226    if (eventListenerRegionTypes.contains(EventListenerRegionType::Wheel))
     227        m_wheelEventListenerRegion.unite(region);
     228    if (eventListenerRegionTypes.contains(EventListenerRegionType::NonPassiveWheel))
     229        m_nonPassiveWheelEventListenerRegion.unite(region);
     230}
     231
    223232#if ENABLE(EDITABLE_REGION)
    224233
     
    243252            ts << indent << "(" << toTouchAction(i);
    244253            ts << indent << m_touchActionRegions[i];
     254            ts << indent << ")\n";
     255        }
     256        ts << indent << ")\n";
     257    }
     258
     259    if (!m_wheelEventListenerRegion.isEmpty()) {
     260        ts << indent << "(wheel event listener region" << m_wheelEventListenerRegion;
     261        if (!m_nonPassiveWheelEventListenerRegion.isEmpty()) {
     262            TextStream::IndentScope indentScope(ts);
     263            ts << indent << "(non-passive" << m_nonPassiveWheelEventListenerRegion;
    245264            ts << indent << ")\n";
    246265        }
  • trunk/Source/WebCore/rendering/EventRegion.h

    r261253 r261279  
    2828#include "AffineTransform.h"
    2929#include "Region.h"
     30#include "RenderStyleConstants.h"
    3031#include "TouchAction.h"
    3132#include <wtf/OptionSet.h>
     
    7778    bool hasTouchActions() const { return !m_touchActionRegions.isEmpty(); }
    7879    WEBCORE_EXPORT OptionSet<TouchAction> touchActionsForPoint(const IntPoint&) const;
    79 
    8080    const Region* regionForTouchAction(TouchAction) const;
    8181
     
    9494private:
    9595    void uniteTouchActions(const Region&, OptionSet<TouchAction>);
     96    void uniteEventListeners(const Region&, OptionSet<EventListenerRegionType>);
    9697
    9798    Region m_region;
    9899    Vector<Region> m_touchActionRegions;
     100    Region m_wheelEventListenerRegion;
     101    Region m_nonPassiveWheelEventListenerRegion;
    99102#if ENABLE(EDITABLE_REGION)
    100103    Region m_editableRegion;
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r261253 r261279  
    16541654void RenderLayerBacking::updateEventRegion()
    16551655{
    1656     if (paintsIntoCompositedAncestor())
    1657         return;
    1658 
    16591656    auto needsUpdate = [&] {
     1657        if (!m_owningLayer.page().scrollingCoordinator())
     1658            return false;
     1659
     1660        if (paintsIntoCompositedAncestor())
     1661            return false;
     1662
    16601663        if (renderer().view().needsEventRegionUpdateForNonCompositedFrame())
    16611664            return true;
     
    16671670#if ENABLE(EDITABLE_REGION)
    16681671        if (renderer().document().mayHaveEditableElements())
     1672            return true;
     1673#endif
     1674#if !PLATFORM(IOS_FAMILY)
     1675        if (renderer().document().wheelEventTargets())
    16691676            return true;
    16701677#endif
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r261253 r261279  
    692692    int initialLetterHeight() const { return initialLetter().height(); }
    693693
    694     OptionSet<TouchAction> touchActions() const { return OptionSet<TouchAction>::fromRaw(m_rareNonInheritedData->touchActions); }
     694    OptionSet<TouchAction> touchActions() const { return m_rareNonInheritedData->touchActions; }
    695695    // 'touch-action' behavior depends on values in ancestors. We use an additional inherited property to implement that.
    696     OptionSet<TouchAction> effectiveTouchActions() const { return OptionSet<TouchAction>::fromRaw(m_rareInheritedData->effectiveTouchActions); }
     696    OptionSet<TouchAction> effectiveTouchActions() const { return m_rareInheritedData->effectiveTouchActions; }
     697    OptionSet<EventListenerRegionType> eventListenerRegionTypes() const { return m_rareInheritedData->eventListenerRegionTypes; }
    697698
    698699#if ENABLE(CSS_SCROLL_SNAP)
     
    12271228    void setInitialLetter(const IntSize& size) { SET_VAR(m_rareNonInheritedData, initialLetter, size); }
    12281229   
    1229     void setTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareNonInheritedData, touchActions, touchActions.toRaw()); }
    1230     void setEffectiveTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareInheritedData, effectiveTouchActions, touchActions.toRaw()); }
     1230    void setTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareNonInheritedData, touchActions, touchActions); }
     1231    void setEffectiveTouchActions(OptionSet<TouchAction> touchActions) { SET_VAR(m_rareInheritedData, effectiveTouchActions, touchActions); }
     1232    void setEventListenerRegionTypes(OptionSet<EventListenerRegionType> eventListenerTypes) { SET_VAR(m_rareInheritedData, eventListenerRegionTypes, eventListenerTypes); }
    12311233
    12321234#if ENABLE(CSS_SCROLL_SNAP)
  • trunk/Source/WebCore/rendering/style/RenderStyleConstants.h

    r261253 r261279  
    11791179    Fallback,
    11801180    Optional
     1181};
     1182
     1183enum class EventListenerRegionType : uint8_t {
     1184    Wheel           = 1 << 0,
     1185    NonPassiveWheel = 1 << 1,
    11811186};
    11821187
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp

    r261253 r261279  
    134134    , hasSetStrokeWidth(false)
    135135    , hasSetStrokeColor(false)
    136     , effectiveTouchActions(static_cast<unsigned>(RenderStyle::initialTouchActions()))
     136    , effectiveTouchActions(RenderStyle::initialTouchActions())
    137137    , strokeWidth(RenderStyle::initialStrokeWidth())
    138138    , strokeColor(RenderStyle::initialStrokeColor())
     
    229229    , hasSetStrokeColor(o.hasSetStrokeColor)
    230230    , effectiveTouchActions(o.effectiveTouchActions)
     231    , eventListenerRegionTypes(o.eventListenerRegionTypes)
    231232    , strokeWidth(o.strokeWidth)
    232233    , strokeColor(o.strokeColor)
     
    350351        && hasSetStrokeColor == o.hasSetStrokeColor
    351352        && effectiveTouchActions == o.effectiveTouchActions
     353        && eventListenerRegionTypes == o.eventListenerRegionTypes
    352354        && strokeWidth == o.strokeWidth
    353355        && strokeColor == o.strokeColor
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h

    r261253 r261279  
    3131#include "TextDecorationThickness.h"
    3232#include "TextUnderlineOffset.h"
     33#include "TouchAction.h"
    3334#include <wtf/DataRef.h>
    3435#include <wtf/RefCounted.h>
     
    155156    unsigned hasSetStrokeColor : 1;
    156157
    157     unsigned effectiveTouchActions : 6; // OptionSet<TouchAction>
     158    OptionSet<TouchAction> effectiveTouchActions;
     159    OptionSet<EventListenerRegionType> eventListenerRegionTypes;
    158160
    159161    Length strokeWidth;
  • trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp

    r261253 r261279  
    8282    , justifySelf(RenderStyle::initialSelfAlignment())
    8383    , customProperties(StyleCustomPropertyData::create())
    84     , touchActions(static_cast<unsigned>(RenderStyle::initialTouchActions()))
     84    , touchActions(RenderStyle::initialTouchActions())
    8585    , pageSizeType(PAGE_SIZE_AUTO)
    8686    , transformStyle3D(static_cast<unsigned>(RenderStyle::initialTransformStyle3D()))
  • trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h

    r261253 r261279  
    174174    std::unique_ptr<HashSet<String>> customPaintWatchedProperties;
    175175
    176     unsigned touchActions : 6; // TouchAction
     176    OptionSet<TouchAction> touchActions;
    177177
    178178    unsigned pageSizeType : 2; // PageSizeType
  • trunk/Source/WebCore/style/StyleAdjuster.cpp

    r261253 r261279  
    3434#include "CSSFontSelector.h"
    3535#include "Element.h"
     36#include "EventNames.h"
    3637#include "FrameView.h"
    3738#include "HTMLDivElement.h"
     
    193194}
    194195
     196static OptionSet<EventListenerRegionType> computeEventListenerRegionTypes(const Element& element, OptionSet<EventListenerRegionType> parentTypes)
     197{
     198#if !PLATFORM(IOS_FAMILY)
     199    if (!element.hasEventListeners())
     200        return parentTypes;
     201
     202    auto types = parentTypes;
     203
     204    auto findListeners = [&](auto& eventName, auto type, auto nonPassiveType) {
     205        auto* eventListenerVector = element.eventTargetData()->eventListenerMap.find(eventName);
     206        if (!eventListenerVector)
     207            return;
     208
     209        types.add(type);
     210
     211        auto isPassiveOnly = [&] {
     212            for (auto& listener : *eventListenerVector) {
     213                if (!listener->isPassive())
     214                    return false;
     215            }
     216            return true;
     217        }();
     218
     219        if (!isPassiveOnly)
     220            types.add(nonPassiveType);
     221    };
     222
     223    findListeners(eventNames().wheelEvent, EventListenerRegionType::Wheel, EventListenerRegionType::NonPassiveWheel);
     224    findListeners(eventNames().mousewheelEvent, EventListenerRegionType::Wheel, EventListenerRegionType::NonPassiveWheel);
     225
     226    return types;
     227#else
     228    UNUSED_PARAM(element);
     229    UNUSED_PARAM(parentTypes);
     230    return { };
     231#endif
     232}
     233
    195234void Adjuster::adjust(RenderStyle& style, const RenderStyle* userAgentAppearanceStyle) const
    196235{
     
    437476
    438477    style.setEffectiveTouchActions(computeEffectiveTouchActions(style, m_parentStyle.effectiveTouchActions()));
     478
     479    if (m_element)
     480        style.setEventListenerRegionTypes(computeEventListenerRegionTypes(*m_element, m_parentStyle.eventListenerRegionTypes()));
    439481
    440482#if ENABLE(TEXT_AUTOSIZING)
Note: See TracChangeset for help on using the changeset viewer.