⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 295291 in webkit


Ignore:
Timestamp:
Jun 6, 2022, 10:50:50 AM (4 years ago)
Author:
timothy_horton@apple.com
Message:

InteractionRegionOverlay should use RenderLayer-cached regions instead of computing them itself
​https://bugs.webkit.org/show_bug.cgi?id=241338

Reviewed by Simon Fraser.

  • Source/WebCore/page/DebugPageOverlays.cpp:

(WebCore::RegionOverlay::shouldPaintOverlayIntoLayer):
(WebCore::InteractionRegionOverlay::updateRegion):
Stop computing InteractionRegions ourselves.

(WebCore::InteractionRegionOverlay::activeLayer):
Determine the layer from which to retrieve InteractionRegions. For now, we just
use the root layer, because that's where we stash all regions. Later, we'll
do a hit-test here to find the region under the mouse.

(WebCore::InteractionRegionOverlay::activeRegion):
Look up InteractionRegions cached on the aforementioned active layer, instead of
computing them ourselves.

(WebCore::InteractionRegionOverlay::drawRect):
Stop painting region-indicating borders into the overlay (see RenderLayerBacking changes).

(WebCore::InteractionRegionOverlay::mouseEvent):
Correctly map into layer coordinates. For now this is a no-op because we're using
the root layer, but it will be important in a future patch where we use regions
on a per-layer basis.

(WebCore::DebugPageOverlays::shouldPaintOverlayIntoLayer):

  • Source/WebCore/page/DebugPageOverlays.h:

(WebCore::DebugPageOverlays::shouldPaintOverlayIntoLayerForRegionType):

  • Source/WebCore/rendering/RenderLayerBacking.cpp:

(WebCore::RenderLayerBacking::paintDebugOverlays):
(WebCore::RenderLayerBacking::paintContents):
Paint region-indicating borders into the layer, instead of into the page overlay.
This will make them correctly scroll along with the content, and layer correctly.

Canonical link: ​https://commits.webkit.org/251337@main

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/page/DebugPageOverlays.cpp

    r294614 r295291  
    4141#include "PlatformMouseEvent.h"
    4242#include "Region.h"
     43#include "RenderLayer.h"
     44#include "RenderLayerBacking.h"
     45#include "RenderView.h"
    4346#include "ScrollingCoordinator.h"
    4447#include "Settings.h"
    … …  
    5861
    5962    void setRegionChanged() { m_regionChanged = true; }
     63
     64    virtual bool shouldPaintOverlayIntoLayer() const { return true; }
    6065
    6166protected:
    … …  
    258263    bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) final;
    259264
    260     FloatRect rectForSettingAtIndex(unsigned);
    261     bool valueForSetting(ASCIILiteral);
    262        
    263     std::optional<InteractionRegion> activeRegion();
     265    FloatRect rectForSettingAtIndex(unsigned) const;
     266    bool valueForSetting(ASCIILiteral) const;
     267
     268    std::optional<std::pair<RenderLayer&, GraphicsLayer&>> activeLayer() const;
     269    std::optional<InteractionRegion> activeRegion() const;
     270
     271    bool shouldPaintOverlayIntoLayer() const override { return valueForSetting("regions"_s); }
    264272
    265273    struct Setting {
    … …  
    279287        { "regions"_s, "Show Regions"_s, false }
    280288    };
    281    
    282     Vector<InteractionRegion> m_regions;
     289
    283290    IntPoint m_mouseLocationInContentCoordinates;
    284291};
    … …  
    287294{
    288295    m_overlay->setNeedsDisplay();
    289     m_regions = interactionRegions(m_page, { { 0, 0 }, m_page.mainFrame().view()->contentsSize() });
    290    
    291296    return true;
    292297}
    … …  
    302307}
    303308
    304 std::optional<InteractionRegion> InteractionRegionOverlay::activeRegion()
    305 {
     309std::optional<std::pair<RenderLayer&, GraphicsLayer&>> InteractionRegionOverlay::activeLayer() const
     310{
     311    // FIXME: This should hit-test to find the correct layer, once we store InteractionRegions
     312    // on each layer instead of keeping them all on the root.
     313    auto* frameView = m_page.mainFrame().view();
     314    if (!frameView || !frameView->renderView())
     315        return std::nullopt;
     316
     317    auto* layer = frameView->renderView()->enclosingLayer();
     318    if (!layer || !layer->backing())
     319        return std::nullopt;
     320
     321    auto* graphicsLayer = layer->backing()->graphicsLayer();
     322    if (!graphicsLayer)
     323        return std::nullopt;
     324
     325    return { { *layer, *graphicsLayer } };
     326}
     327
     328std::optional<InteractionRegion> InteractionRegionOverlay::activeRegion() const
     329{
     330#if ENABLE(INTERACTION_REGIONS_IN_EVENT_REGION)
     331    auto layerPair = activeLayer();
     332    if (!layerPair)
     333        return std::nullopt;
     334    auto& [layer, graphicsLayer] = *layerPair;
     335
    306336    std::optional<InteractionRegion> hitRegion;
    307337    float hitRegionArea = 0;
    308338   
    309     for (const auto& region : m_regions) {
     339    FloatSize offset(layer.offsetFromAncestor(&layer.compositor().rootRenderLayer()));
     340    FloatPoint mouseLocationInLayerCoordinates = m_mouseLocationInContentCoordinates - offset;
     341
     342    auto regions = graphicsLayer.eventRegion().interactionRegions();
     343    for (const auto& region : regions) {
    310344        float area = 0;
    311345        FloatRect boundingRect;
    … …  
    318352        }
    319353
    320         if (!boundingRect.contains(m_mouseLocationInContentCoordinates))
     354        if (!boundingRect.contains(mouseLocationInLayerCoordinates))
    321355            continue;
    322356
    … …  
    324358        bool didHitRegion = false;
    325359        for (const auto& path : paths) {
    326             if (path.contains(m_mouseLocationInContentCoordinates)) {
     360            if (path.contains(mouseLocationInLayerCoordinates)) {
    327361                didHitRegion = true;
    328362                break;
    … …  
    342376    }
    343377   
     378    if (hitRegion)
     379        hitRegion->regionInLayerCoordinates.translate(roundedIntSize(offset));
     380
    344381    return hitRegion;
     382#else
     383    return std::nullopt;
     384#endif
    345385}
    346386
    … …  
    370410}
    371411
    372 FloatRect InteractionRegionOverlay::rectForSettingAtIndex(unsigned index)
     412FloatRect InteractionRegionOverlay::rectForSettingAtIndex(unsigned index) const
    373413{
    374414    auto viewSize = m_page.mainFrame().view()->layoutSize();
    … …  
    382422}
    383423
    384 bool InteractionRegionOverlay::valueForSetting(ASCIILiteral name)
     424bool InteractionRegionOverlay::valueForSetting(ASCIILiteral name) const
    385425{
    386426    for (const auto& setting : m_settings) {
    … …  
    428468   
    429469    context.clearRect(dirtyRect);
    430 
    431     if (valueForSetting("regions"_s)) {
    432         context.setStrokeThickness(2);
    433         context.setStrokeColor(Color::green);
    434 
    435         for (const auto& region : m_regions) {
    436             for (const auto& rect : region.regionInLayerCoordinates.rects())
    437                 context.strokeRect(rect, 2);
    438         }
    439     }
    440470
    441471    auto region = activeRegion();
    … …  
    537567        if (event.button() == LeftButton && event.type() == PlatformEvent::MousePressed) {
    538568            m_settings[i].value = !m_settings[i].value;
     569            m_page.forceRepaintAllFrames();
    539570            return true;
    540571        }
    … …  
    739770}
    740771
    741 }
     772bool DebugPageOverlays::shouldPaintOverlayIntoLayer(Page& page, RegionType regionType) const
     773{
     774    if (auto* overlay = regionOverlayForPage(page, regionType))
     775        return overlay->shouldPaintOverlayIntoLayer();
     776    return false;
     777}
     778
     779}
  • trunk/Source/WebCore/page/DebugPageOverlays.h

    r292208 r295291  
    4141    static DebugPageOverlays& singleton();
    4242
    43     enum class RegionType {
     43    enum class RegionType : uint8_t {
    4444        WheelEventHandlers,
    4545        NonFastScrollableRegion,
    … …  
    5151    static void didChangeEventHandlers(Frame&);
    5252    static void doAfterUpdateRendering(Page&);
     53
     54    static bool shouldPaintOverlayIntoLayerForRegionType(Page&, RegionType);
    5355
    5456    WEBCORE_EXPORT static void settingsChanged(Page&);
    … …  
    7072   
    7173    void updateOverlayRegionVisibility(Page&, OptionSet<DebugOverlayRegions>);
     74
     75    bool shouldPaintOverlayIntoLayer(Page&, RegionType) const;
    7276
    7377    RegionOverlay* regionOverlayForPage(Page&, RegionType) const;
    … …  
    117121}
    118122
     123inline bool DebugPageOverlays::shouldPaintOverlayIntoLayerForRegionType(Page& page, RegionType regionType)
     124{
     125    if (LIKELY(!hasOverlays(page)))
     126        return false;
     127    return sharedDebugOverlays->shouldPaintOverlayIntoLayer(page, regionType);
     128}
     129
    119130} // namespace WebCore
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r294973 r295291  
    34773477    }
    34783478#endif
     3479
     3480#if ENABLE(INTERACTION_REGIONS_IN_EVENT_REGION)
     3481    if (DebugPageOverlays::shouldPaintOverlayIntoLayerForRegionType(renderer().page(), DebugPageOverlays::RegionType::InteractionRegion)) {
     3482        context.setStrokeColor(Color::green);
     3483        context.setStrokeThickness(1);
     3484
     3485        for (const auto& region : eventRegion.interactionRegions()) {
     3486            for (auto rect : region.regionInLayerCoordinates.rects()) {
     3487                Path path;
     3488                path.addRoundedRect(rect, { region.borderRadius, region.borderRadius });
     3489                context.strokePath(path);
     3490            }
     3491        }
     3492    }
     3493#endif
    34793494}
    34803495
    … …  
    35193534
    35203535        auto visibleDebugOverlayRegions = OptionSet<DebugOverlayRegions>::fromRaw(renderer().settings().visibleDebugOverlayRegions());
    3521         if (visibleDebugOverlayRegions.containsAny({ DebugOverlayRegions::TouchActionRegion, DebugOverlayRegions::EditableElementRegion, DebugOverlayRegions::WheelEventHandlerRegion }))
     3536        if (visibleDebugOverlayRegions.containsAny({ DebugOverlayRegions::TouchActionRegion, DebugOverlayRegions::EditableElementRegion, DebugOverlayRegions::WheelEventHandlerRegion, DebugOverlayRegions::InteractionRegion }))
    35223537            paintDebugOverlays(graphicsLayer, context);
    35233538
Note: See TracChangeset for help on using the changeset viewer.