Title: [214483] trunk/Source/WebCore
Revision
214483
Author
[email protected]
Date
2017-03-28 11:29:40 -0700 (Tue, 28 Mar 2017)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (214482 => 214483)


--- trunk/Source/WebCore/ChangeLog	2017-03-28 18:29:37 UTC (rev 214482)
+++ trunk/Source/WebCore/ChangeLog	2017-03-28 18:29:40 UTC (rev 214483)
@@ -1,5 +1,26 @@
 2017-03-27  Simon Fraser  <[email protected]>
 
+        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):
+
+2017-03-27  Simon Fraser  <[email protected]>
+
         Make sure the non-fast scrolling debug overlay is correctly updated
         https://bugs.webkit.org/show_bug.cgi?id=170142
 

Modified: trunk/Source/WebCore/page/DebugPageOverlays.cpp (214482 => 214483)


--- trunk/Source/WebCore/page/DebugPageOverlays.cpp	2017-03-28 18:29:37 UTC (rev 214482)
+++ trunk/Source/WebCore/page/DebugPageOverlays.cpp	2017-03-28 18:29:40 UTC (rev 214483)
@@ -55,7 +55,7 @@
 private:
     void willMoveToPage(PageOverlay&, Page*) final;
     void didMoveToPage(PageOverlay&, Page*) final;
-    void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) final;
+    void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) override;
     bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) final;
     void didScrollFrame(PageOverlay&, Frame&) final;
 
@@ -62,6 +62,7 @@
 protected:
     // Returns true if the region changed.
     virtual bool updateRegion() = 0;
+    void drawRegion(GraphicsContext&, const Region&, const Color&, const IntRect& dirtyRect);
     
     MainFrame& m_frame;
     RefPtr<PageOverlay> m_overlay;
@@ -119,25 +120,111 @@
     }
 
     bool updateRegion() override;
+    void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) final;
+    
+    EventTrackingRegions m_eventTrackingRegions;
 };
 
 bool NonFastScrollableRegionOverlay::updateRegion()
 {
-    auto region = std::make_unique<Region>();
+    bool regionChanged = false;
 
     if (Page* page = m_frame.page()) {
         if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) {
             EventTrackingRegions eventTrackingRegions = scrollingCoordinator->absoluteEventTrackingRegions();
-            for (const auto& synchronousEventRegion : eventTrackingRegions.eventSpecificSynchronousDispatchRegions)
-                region->unite(synchronousEventRegion.value);
+
+            if (eventTrackingRegions != m_eventTrackingRegions) {
+                m_eventTrackingRegions = eventTrackingRegions;
+                regionChanged = true;
+            }
         }
     }
 
-    bool regionChanged = !m_region || !(*m_region == *region);
-    m_region = WTFMove(region);
     return regionChanged;
 }
 
+static HashMap<String, Color>& touchEventRegionColors()
+{
+    static NeverDestroyed<HashMap<String, Color>> regionColors;
+
+    if (regionColors.get().isEmpty()) {
+        regionColors.get().add("touchstart", Color(191, 191, 63, 80));
+        regionColors.get().add("touchmove", Color(63, 191, 191, 80));
+        regionColors.get().add("touchend", Color(191, 63, 127, 80));
+        regionColors.get().add("touchforcechange", Color(63, 63, 191, 80));
+        regionColors.get().add("wheel", Color(255, 128, 0, 80));
+    }
+    
+    return regionColors;
+}
+
+static void drawRightAlignedText(const String& text, GraphicsContext& context, const FontCascade& font, const FloatPoint& boxLocation)
+{
+    float textGap = 10;
+    float textBaselineFromTop = 14;
+
+    TextRun textRun = TextRun(StringView(text));
+    context.setFillColor(Color::transparent);
+    float textWidth = context.drawText(font, textRun, { });
+    context.setFillColor(Color::black);
+    context.drawText(font, textRun, boxLocation + FloatSize(-(textWidth + textGap), textBaselineFromTop));
+}
+
+void NonFastScrollableRegionOverlay::drawRect(PageOverlay& pageOverlay, GraphicsContext& context, const IntRect&)
+{
+    IntRect bounds = pageOverlay.bounds();
+    
+    context.clearRect(bounds);
+    
+    FloatRect legendRect = { bounds.maxX() - 30.0f, 10, 20, 20 };
+    
+    FontCascadeDescription fontDescription;
+    fontDescription.setOneFamily("Helvetica");
+    fontDescription.setSpecifiedSize(12);
+    fontDescription.setComputedSize(12);
+    fontDescription.setWeight(FontSelectionValue(500));
+    FontCascade font(fontDescription, 0, 0);
+    font.update(nullptr);
+
+#if ENABLE(TOUCH_EVENTS)
+    context.setFillColor(touchEventRegionColors().get("touchstart"));
+    context.fillRect(legendRect);
+    drawRightAlignedText("touchstart", context, font, legendRect.location());
+
+    legendRect.move(0, 30);
+    context.setFillColor(touchEventRegionColors().get("touchmove"));
+    context.fillRect(legendRect);
+    drawRightAlignedText("touchmove", context, font, legendRect.location());
+
+    legendRect.move(0, 30);
+    context.setFillColor(touchEventRegionColors().get("touchend"));
+    context.fillRect(legendRect);
+    drawRightAlignedText("touchend", context, font, legendRect.location());
+
+    legendRect.move(0, 30);
+    context.setFillColor(touchEventRegionColors().get("touchforcechange"));
+    context.fillRect(legendRect);
+    drawRightAlignedText("touchforcechange", context, font, legendRect.location());
+
+    legendRect.move(0, 30);
+    context.setFillColor(m_color);
+    context.fillRect(legendRect);
+    drawRightAlignedText("passive listeners", context, font, legendRect.location());
+#else
+    // On desktop platforms, the "wheel" region includes the non-fast scrollable region.
+    context.setFillColor(touchEventRegionColors().get("wheel"));
+    context.fillRect(legendRect);
+    drawRightAlignedText("non-fast region", context, font, legendRect.location());
+#endif
+
+    for (const auto& synchronousEventRegion : m_eventTrackingRegions.eventSpecificSynchronousDispatchRegions) {
+        Color regionColor = touchEventRegionColors().get(synchronousEventRegion.key);
+        drawRegion(context, synchronousEventRegion.value, regionColor, bounds);
+    }
+
+    drawRegion(context, m_eventTrackingRegions.asynchronousDispatchRegion, m_color, bounds);
+}
+
 Ref<RegionOverlay> RegionOverlay::create(MainFrame& frame, DebugPageOverlays::RegionType regionType)
 {
     switch (regionType) {
@@ -182,9 +269,14 @@
     if (!m_region)
         return;
 
+    drawRegion(context, *m_region, m_color, dirtyRect);
+}
+
+void RegionOverlay::drawRegion(GraphicsContext& context, const Region& region, const Color& color, const IntRect& dirtyRect)
+{
     GraphicsContextStateSaver saver(context);
-    context.setFillColor(m_color);
-    for (auto rect : m_region->rects()) {
+    context.setFillColor(color);
+    for (auto rect : region.rects()) {
         if (rect.intersects(dirtyRect))
             context.fillRect(rect);
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to