WebKit Bugzilla
Attachment 371785 Details for
Bug 198718
: Add visualization of touch action regions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198718-20190610153931.patch (text/plain), 10.09 KB, created by
Simon Fraser (smfr)
on 2019-06-10 15:39:31 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Simon Fraser (smfr)
Created:
2019-06-10 15:39:31 PDT
Size:
10.09 KB
patch
obsolete
>Subversion Revision: 246278 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 9fe43aea33c596a282c80ec202e15199c425a5e4..643eb8f0818aa0b4b4f2b3f20d39f0a35cc3dea0 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,28 @@ >+2019-06-10 Simon Fraser <simon.fraser@apple.com> >+ >+ Add visualization of touch action regions >+ https://bugs.webkit.org/show_bug.cgi?id=198718 >+ >+ Reviewed by Antoine Quint. >+ >+ Add a way to show which elements of the page have touch-action set on them by >+ painting an overlay with small text that shows the type of action(s). >+ >+ The event regions are painted into GraphicsLayers at paint time in >+ RenderLayerBacking by making a pattern image and filling the region rects >+ with the pattern. >+ >+ * page/DebugPageOverlays.cpp: >+ (WebCore::touchEventRegionColors): >+ * rendering/EventRegion.cpp: >+ (WebCore::EventRegion::regionForTouchAction const): >+ * rendering/EventRegion.h: >+ (WebCore::EventRegion::region const): >+ * rendering/RenderLayerBacking.cpp: >+ (WebCore::RenderLayerBacking::updateEventRegion): >+ (WebCore::patternForTouchAction): >+ (WebCore::RenderLayerBacking::paintContents): >+ > 2019-06-10 Antti Koivisto <antti@apple.com> > > Event region should be set on scrolledContentsLayer if it exists >diff --git a/Source/WebCore/page/DebugPageOverlays.cpp b/Source/WebCore/page/DebugPageOverlays.cpp >index 396b3ebd13ed8cd0b5590aa5dccdb6a7749c15eb..f63daa7f63472558873db3b583bc2512a177527a 100644 >--- a/Source/WebCore/page/DebugPageOverlays.cpp >+++ b/Source/WebCore/page/DebugPageOverlays.cpp >@@ -162,7 +162,7 @@ static const HashMap<String, Color>& touchEventRegionColors() > }; > HashMap<String, Color> map; > for (auto& entry : entries) >- map.add(entry.name, Color { entry.r, entry.g, entry.b, 80 }); >+ map.add(entry.name, Color { entry.r, entry.g, entry.b, 50 }); > return map; > }()); > return regionColors; >diff --git a/Source/WebCore/rendering/EventRegion.cpp b/Source/WebCore/rendering/EventRegion.cpp >index 244ae5b522cb647056e1c0da7325cf97f2775ae4..97b7914b2d385d18171f0875d376223ccc8ab31a 100644 >--- a/Source/WebCore/rendering/EventRegion.cpp >+++ b/Source/WebCore/rendering/EventRegion.cpp >@@ -157,6 +157,15 @@ void EventRegion::uniteTouchActions(const Region& touchRegion, OptionSet<TouchAc > } > } > >+const Region* EventRegion::regionForTouchAction(TouchAction action) const >+{ >+ unsigned actionIndex = toIndex(action); >+ if (actionIndex >= m_touchActionRegions.size()) >+ return nullptr; >+ >+ return &m_touchActionRegions[actionIndex]; >+} >+ > OptionSet<TouchAction> EventRegion::touchActionsForPoint(const IntPoint& point) const > { > OptionSet<TouchAction> actions; >@@ -196,7 +205,7 @@ TextStream& operator<<(TextStream& ts, TouchAction touchAction) > return ts; > } > >-#endif >+#endif // ENABLE(POINTER_EVENTS) > > TextStream& operator<<(TextStream& ts, const EventRegion& eventRegion) > { >diff --git a/Source/WebCore/rendering/EventRegion.h b/Source/WebCore/rendering/EventRegion.h >index c2bac4eccc1f3ee376a7bd09b609f81283418529..1d77beddbdc5f317c4040e4c43a7b0861d8a11e4 100644 >--- a/Source/WebCore/rendering/EventRegion.h >+++ b/Source/WebCore/rendering/EventRegion.h >@@ -67,9 +67,13 @@ public: > bool contains(const IntPoint& point) const { return m_region.contains(point); } > bool contains(const IntRect& rect) const { return m_region.contains(rect); } > >+ const Region& region() const { return m_region; } >+ > #if ENABLE(POINTER_EVENTS) > bool hasTouchActions() const { return !m_touchActionRegions.isEmpty(); } > WEBCORE_EXPORT OptionSet<TouchAction> touchActionsForPoint(const IntPoint&) const; >+ >+ const Region* regionForTouchAction(TouchAction) const; > #endif > > template<class Encoder> void encode(Encoder&) const; >diff --git a/Source/WebCore/rendering/RenderLayerBacking.cpp b/Source/WebCore/rendering/RenderLayerBacking.cpp >index 1ab3486df16d1ed9913243df8b904d2a0e9d3efc..e3b6694820433942ed4c16a8a81b57ac13bf0a8e 100644 >--- a/Source/WebCore/rendering/RenderLayerBacking.cpp >+++ b/Source/WebCore/rendering/RenderLayerBacking.cpp >@@ -2733,6 +2733,123 @@ void RenderLayerBacking::paintIntoLayer(const GraphicsLayer* graphicsLayer, Grap > compositor().didPaintBacking(this); > } > >+#if ENABLE(POINTER_EVENTS) >+static RefPtr<Pattern> patternForTouchAction(TouchAction touchAction, FloatSize contentOffset, GraphicsContext& destContext) >+{ >+ auto toIndex = [](TouchAction touchAction) -> unsigned { >+ switch (touchAction) { >+ case TouchAction::Manipulation: >+ return 1; >+ case TouchAction::PanX: >+ return 2; >+ case TouchAction::PanY: >+ return 3; >+ case TouchAction::PinchZoom: >+ return 4; >+ case TouchAction::None: >+ case TouchAction::Auto: >+ break; >+ } >+ return 0; >+ }; >+ >+ struct TouchActionAndRGB { >+ TouchAction action; >+ ASCIILiteral name; >+ FloatSize phase; >+ }; >+ static const TouchActionAndRGB actionsAndColors[] = { >+ { TouchAction::None, "none"_s, { } }, >+ { TouchAction::Manipulation, "manip"_s, { } }, >+ { TouchAction::PanX, "pan-x"_s, { } }, >+ { TouchAction::PanY, "pan-y"_s, { 0, 9 } }, >+ { TouchAction::PinchZoom, "p-z"_s, { 16, 4.5 } }, >+ }; >+ >+ auto actionIndex = toIndex(touchAction); >+ if (!actionIndex || actionIndex >= ARRAY_SIZE(actionsAndColors)) >+ return nullptr; >+ >+ const FloatSize tileSize { 32, 18 }; >+ >+ auto imageBuffer = ImageBuffer::createCompatibleBuffer(tileSize, ColorSpaceSRGB, destContext); >+ if (!imageBuffer) >+ return nullptr; >+ >+ const auto& touchActionData = actionsAndColors[actionIndex]; >+ { >+ GraphicsContext& imageContext = imageBuffer->context(); >+ >+ FontCascadeDescription fontDescription; >+ fontDescription.setOneFamily("Helvetica"); >+ fontDescription.setSpecifiedSize(10); >+ fontDescription.setComputedSize(10); >+ fontDescription.setWeight(FontSelectionValue(500)); >+ FontCascade font(WTFMove(fontDescription), 0, 0); >+ font.update(nullptr); >+ >+ TextRun textRun = TextRun(touchActionData.name); >+ imageContext.setFillColor(Color(0, 0, 0, 128)); >+ >+ constexpr float textGap = 4; >+ constexpr float yOffset = 12; >+ imageContext.drawText(font, textRun, { textGap, yOffset }, 0); >+ } >+ >+ auto tileImage = ImageBuffer::sinkIntoImage(WTFMove(imageBuffer)); >+ auto fillPattern = Pattern::create(tileImage.releaseNonNull(), true, true); >+ AffineTransform patternOffsetTransform; >+ patternOffsetTransform.translate(contentOffset + touchActionData.phase); >+ patternOffsetTransform.scale(1 / destContext.scaleFactor()); >+ fillPattern->setPatternSpaceTransform(patternOffsetTransform); >+ >+ return fillPattern; >+} >+#endif // ENABLE(POINTER_EVENTS) >+ >+void RenderLayerBacking::paintDebugOverlays(const GraphicsLayer* graphicsLayer, GraphicsContext& context) >+{ >+ if (graphicsLayer->eventRegion().isEmpty()) >+ return; >+ >+ GraphicsContextStateSaver stateSaver(context); >+ >+ // The region is offset by contentOffsetInCompositingLayer() so undo that. >+ auto contentOffset = roundedIntSize(contentOffsetInCompositingLayer()); >+ context.translate(-contentOffset); >+ >+ // The interactive part. >+ auto& eventRegion = graphicsLayer->eventRegion(); >+ Color regionColor(0, 0, 0, 5); >+ context.setFillColor(regionColor); >+ for (auto rect : eventRegion.region().rects()) >+ context.fillRect(rect); >+ >+#if ENABLE(POINTER_EVENTS) >+ const TouchAction touchActionList[] = { >+ TouchAction::None, >+ TouchAction::Manipulation, >+ TouchAction::PanX, >+ TouchAction::PanY, >+ TouchAction::PinchZoom, >+ }; >+ >+ for (auto action : touchActionList) { >+ auto* actionRegion = graphicsLayer->eventRegion().regionForTouchAction(action); >+ if (!actionRegion) >+ continue; >+ >+ auto fillPattern = patternForTouchAction(action, contentOffsetInCompositingLayer(), context); >+ if (!fillPattern) >+ continue; >+ >+ context.setFillPattern(fillPattern.releaseNonNull()); >+ for (auto rect : actionRegion->rects()) >+ context.fillRect(rect); >+ } >+#endif // ENABLE(POINTER_EVENTS) >+} >+ > // Up-call from compositing layer drawing callback. > void RenderLayerBacking::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, OptionSet<GraphicsLayerPaintingPhase> paintingPhase, const FloatRect& clip, GraphicsLayerPaintBehavior layerPaintBehavior) > { >@@ -2771,6 +2888,10 @@ void RenderLayerBacking::paintContents(const GraphicsLayer* graphicsLayer, Graph > behavior.add(PaintBehavior::TileFirstPaint); > > paintIntoLayer(graphicsLayer, context, dirtyRect, behavior, paintingPhase); >+ >+ if (renderer().settings().visibleDebugOverlayRegions() & NonFastScrollableRegion) // Piggy-back off the setting that shows touch handler regions. >+ paintDebugOverlays(graphicsLayer, context); >+ > } else if (graphicsLayer == layerForHorizontalScrollbar()) { > paintScrollbar(m_owningLayer.horizontalScrollbar(), context, dirtyRect); > } else if (graphicsLayer == layerForVerticalScrollbar()) { >diff --git a/Source/WebCore/rendering/RenderLayerBacking.h b/Source/WebCore/rendering/RenderLayerBacking.h >index 412b102827a3da788c08810cd7b8028704d6937b..45bef5012639189503cb669d996aaf852a00091f 100644 >--- a/Source/WebCore/rendering/RenderLayerBacking.h >+++ b/Source/WebCore/rendering/RenderLayerBacking.h >@@ -384,6 +384,8 @@ private: > GraphicsLayer* tileCacheFlatteningLayer() const { return m_isFrameLayerWithTiledBacking ? m_childContainmentLayer.get() : nullptr; } > > void paintIntoLayer(const GraphicsLayer*, GraphicsContext&, const IntRect& paintDirtyRect, OptionSet<PaintBehavior>, OptionSet<GraphicsLayerPaintingPhase>); >+ >+ void paintDebugOverlays(const GraphicsLayer*, GraphicsContext&); > > static CSSPropertyID graphicsLayerToCSSProperty(AnimatedPropertyID); > static AnimatedPropertyID cssToGraphicsLayerProperty(CSSPropertyID);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198718
:
371744
|
371755
| 371785