Changeset 214483 in webkit


Ignore:
Timestamp:
Mar 28, 2017, 11:29:40 AM (9 years ago)
Author:
Simon Fraser
Message:

Enhance the touch region debug overlay to show regions for the different events
https://bugs.webkit.org/show_bug.cgi?id=170162

Reviewed by Tim Horton.

Have NonFastScrollableRegionOverlay use a different color for each region in EventTrackingRegions,
and to draw a legend showing what the colors mean.

On Mac, this overlay displays the non-fast scrollable region (which we don't keep separate from the wheel event
region).

  • page/DebugPageOverlays.cpp:

(WebCore::NonFastScrollableRegionOverlay::updateRegion):
(WebCore::touchEventRegionColors):
(WebCore::drawRightAlignedText):
(WebCore::NonFastScrollableRegionOverlay::drawRect):
(WebCore::RegionOverlay::drawRect):
(WebCore::RegionOverlay::drawRegion):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r214482 r214483  
     12017-03-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Enhance the touch region debug overlay to show regions for the different events
     4        https://bugs.webkit.org/show_bug.cgi?id=170162
     5
     6        Reviewed by Tim Horton.
     7
     8        Have NonFastScrollableRegionOverlay use a different color for each region in EventTrackingRegions,
     9        and to draw a legend showing what the colors mean.
     10       
     11        On Mac, this overlay displays the non-fast scrollable region (which we don't keep separate from the wheel event
     12        region).
     13
     14        * page/DebugPageOverlays.cpp:
     15        (WebCore::NonFastScrollableRegionOverlay::updateRegion):
     16        (WebCore::touchEventRegionColors):
     17        (WebCore::drawRightAlignedText):
     18        (WebCore::NonFastScrollableRegionOverlay::drawRect):
     19        (WebCore::RegionOverlay::drawRect):
     20        (WebCore::RegionOverlay::drawRegion):
     21
    1222017-03-27  Simon Fraser  <simon.fraser@apple.com>
    223
  • trunk/Source/WebCore/page/DebugPageOverlays.cpp

    r211033 r214483  
    5656    void willMoveToPage(PageOverlay&, Page*) final;
    5757    void didMoveToPage(PageOverlay&, Page*) final;
    58     void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) final;
     58    void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) override;
    5959    bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) final;
    6060    void didScrollFrame(PageOverlay&, Frame&) final;
     
    6363    // Returns true if the region changed.
    6464    virtual bool updateRegion() = 0;
     65    void drawRegion(GraphicsContext&, const Region&, const Color&, const IntRect& dirtyRect);
    6566   
    6667    MainFrame& m_frame;
     
    120121
    121122    bool updateRegion() override;
     123    void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) final;
     124   
     125    EventTrackingRegions m_eventTrackingRegions;
    122126};
    123127
    124128bool NonFastScrollableRegionOverlay::updateRegion()
    125129{
    126     auto region = std::make_unique<Region>();
     130    bool regionChanged = false;
    127131
    128132    if (Page* page = m_frame.page()) {
    129133        if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) {
    130134            EventTrackingRegions eventTrackingRegions = scrollingCoordinator->absoluteEventTrackingRegions();
    131             for (const auto& synchronousEventRegion : eventTrackingRegions.eventSpecificSynchronousDispatchRegions)
    132                 region->unite(synchronousEventRegion.value);
     135
     136            if (eventTrackingRegions != m_eventTrackingRegions) {
     137                m_eventTrackingRegions = eventTrackingRegions;
     138                regionChanged = true;
     139            }
    133140        }
    134141    }
    135142
    136     bool regionChanged = !m_region || !(*m_region == *region);
    137     m_region = WTFMove(region);
    138143    return regionChanged;
     144}
     145
     146static HashMap<String, Color>& touchEventRegionColors()
     147{
     148    static NeverDestroyed<HashMap<String, Color>> regionColors;
     149
     150    if (regionColors.get().isEmpty()) {
     151        regionColors.get().add("touchstart", Color(191, 191, 63, 80));
     152        regionColors.get().add("touchmove", Color(63, 191, 191, 80));
     153        regionColors.get().add("touchend", Color(191, 63, 127, 80));
     154        regionColors.get().add("touchforcechange", Color(63, 63, 191, 80));
     155        regionColors.get().add("wheel", Color(255, 128, 0, 80));
     156    }
     157   
     158    return regionColors;
     159}
     160
     161static void drawRightAlignedText(const String& text, GraphicsContext& context, const FontCascade& font, const FloatPoint& boxLocation)
     162{
     163    float textGap = 10;
     164    float textBaselineFromTop = 14;
     165
     166    TextRun textRun = TextRun(StringView(text));
     167    context.setFillColor(Color::transparent);
     168    float textWidth = context.drawText(font, textRun, { });
     169    context.setFillColor(Color::black);
     170    context.drawText(font, textRun, boxLocation + FloatSize(-(textWidth + textGap), textBaselineFromTop));
     171}
     172
     173void NonFastScrollableRegionOverlay::drawRect(PageOverlay& pageOverlay, GraphicsContext& context, const IntRect&)
     174{
     175    IntRect bounds = pageOverlay.bounds();
     176   
     177    context.clearRect(bounds);
     178   
     179    FloatRect legendRect = { bounds.maxX() - 30.0f, 10, 20, 20 };
     180   
     181    FontCascadeDescription fontDescription;
     182    fontDescription.setOneFamily("Helvetica");
     183    fontDescription.setSpecifiedSize(12);
     184    fontDescription.setComputedSize(12);
     185    fontDescription.setWeight(FontSelectionValue(500));
     186    FontCascade font(fontDescription, 0, 0);
     187    font.update(nullptr);
     188
     189#if ENABLE(TOUCH_EVENTS)
     190    context.setFillColor(touchEventRegionColors().get("touchstart"));
     191    context.fillRect(legendRect);
     192    drawRightAlignedText("touchstart", context, font, legendRect.location());
     193
     194    legendRect.move(0, 30);
     195    context.setFillColor(touchEventRegionColors().get("touchmove"));
     196    context.fillRect(legendRect);
     197    drawRightAlignedText("touchmove", context, font, legendRect.location());
     198
     199    legendRect.move(0, 30);
     200    context.setFillColor(touchEventRegionColors().get("touchend"));
     201    context.fillRect(legendRect);
     202    drawRightAlignedText("touchend", context, font, legendRect.location());
     203
     204    legendRect.move(0, 30);
     205    context.setFillColor(touchEventRegionColors().get("touchforcechange"));
     206    context.fillRect(legendRect);
     207    drawRightAlignedText("touchforcechange", context, font, legendRect.location());
     208
     209    legendRect.move(0, 30);
     210    context.setFillColor(m_color);
     211    context.fillRect(legendRect);
     212    drawRightAlignedText("passive listeners", context, font, legendRect.location());
     213#else
     214    // On desktop platforms, the "wheel" region includes the non-fast scrollable region.
     215    context.setFillColor(touchEventRegionColors().get("wheel"));
     216    context.fillRect(legendRect);
     217    drawRightAlignedText("non-fast region", context, font, legendRect.location());
     218#endif
     219
     220    for (const auto& synchronousEventRegion : m_eventTrackingRegions.eventSpecificSynchronousDispatchRegions) {
     221        Color regionColor = touchEventRegionColors().get(synchronousEventRegion.key);
     222        drawRegion(context, synchronousEventRegion.value, regionColor, bounds);
     223    }
     224
     225    drawRegion(context, m_eventTrackingRegions.asynchronousDispatchRegion, m_color, bounds);
    139226}
    140227
     
    183270        return;
    184271
     272    drawRegion(context, *m_region, m_color, dirtyRect);
     273}
     274
     275void RegionOverlay::drawRegion(GraphicsContext& context, const Region& region, const Color& color, const IntRect& dirtyRect)
     276{
    185277    GraphicsContextStateSaver saver(context);
    186     context.setFillColor(m_color);
    187     for (auto rect : m_region->rects()) {
     278    context.setFillColor(color);
     279    for (auto rect : region.rects()) {
    188280        if (rect.intersects(dirtyRect))
    189281            context.fillRect(rect);
Note: See TracChangeset for help on using the changeset viewer.