WebKit Bugzilla
Attachment 371744 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-20190610080924.patch (text/plain), 9.47 KB, created by
Simon Fraser (smfr)
on 2019-06-10 08:09:25 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Simon Fraser (smfr)
Created:
2019-06-10 08:09:25 PDT
Size:
9.47 KB
patch
obsolete
>Subversion Revision: 246143 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 3f26b0dc77ef72c420d3a6144ca65bd57e045c7b..e17374dc4a43fb558b0db241a56b9a36fa677a05 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 NOBODY (OOPS!). >+ >+ 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 the primary GraphicsLayer 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-05 Takashi Komori <Takashi.Komori@sony.com> > > [Curl] Report all request headers to web inspector. >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..99f0fe6622c972ccf5db8eab2666295e6b4981d0 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; >diff --git a/Source/WebCore/rendering/EventRegion.h b/Source/WebCore/rendering/EventRegion.h >index c2bac4eccc1f3ee376a7bd09b609f81283418529..3d195eda512fcb76236c3d671e294eaa1c8ff728 100644 >--- a/Source/WebCore/rendering/EventRegion.h >+++ b/Source/WebCore/rendering/EventRegion.h >@@ -67,6 +67,9 @@ 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; } >+ const Region* regionForTouchAction(TouchAction) const; >+ > #if ENABLE(POINTER_EVENTS) > bool hasTouchActions() const { return !m_touchActionRegions.isEmpty(); } > WEBCORE_EXPORT OptionSet<TouchAction> touchActionsForPoint(const IntPoint&) const; >diff --git a/Source/WebCore/rendering/RenderLayerBacking.cpp b/Source/WebCore/rendering/RenderLayerBacking.cpp >index 59bb7607704e7f5735b7bdacaa6b3fc5adeb8f9d..614d54d02ecfee0b0ba647015b50ef0ccbfbff8d 100644 >--- a/Source/WebCore/rendering/RenderLayerBacking.cpp >+++ b/Source/WebCore/rendering/RenderLayerBacking.cpp >@@ -1529,7 +1529,6 @@ void RenderLayerBacking::updateEventRegion() > auto contentOffset = roundedIntSize(contentOffsetInCompositingLayer()); > eventRegion.translate(contentOffset); > m_graphicsLayer->setEventRegion(WTFMove(eventRegion)); >- > #endif > } > >@@ -2733,6 +2732,85 @@ void RenderLayerBacking::paintIntoLayer(const GraphicsLayer* graphicsLayer, Grap > compositor().didPaintBacking(this); > } > >+static RefPtr<Pattern> patternForTouchAction(TouchAction touchAction, FloatSize contentOffset, GraphicsContext& destContext) >+{ >+ auto toIndex = [](TouchAction touchAction) -> unsigned { >+ switch (touchAction) { >+ case TouchAction::None: >+ return 0; >+ case TouchAction::Manipulation: >+ return 1; >+ case TouchAction::PanX: >+ return 2; >+ case TouchAction::PanY: >+ return 3; >+ case TouchAction::PinchZoom: >+ return 4; >+ case TouchAction::Auto: >+ break; >+ } >+ ASSERT_NOT_REACHED(); >+ return 0; >+ }; >+ >+ struct TouchActionAndRGB { >+ TouchAction action; >+ ASCIILiteral name; >+ FloatSize phase; >+ int r; >+ int g; >+ int b; >+ }; >+ TouchActionAndRGB actionsAndColors[] = { >+ { TouchAction::None, "none"_s, { }, 0, 0, 0 }, >+ { TouchAction::Manipulation, "manip"_s, { }, 14, 230, 71 }, >+ { TouchAction::PanX, "pan-x"_s, { }, 58, 148, 102 }, >+ { TouchAction::PanY, "pan-y"_s, { 0, 9 }, 118, 31, 223 }, >+ { TouchAction::PinchZoom, "p-z"_s, { 16, 4.5 }, 249, 171, 80 }, >+ }; >+ >+ 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(touchActionData.r, touchActionData.g, touchActionData.b, 128)); >+ imageContext.setFillColor(Color(0, 0, 0, 128)); >+// imageContext.setShadow({ }, 2, Color(255, 255, 255, 200)); >+ >+ float textGap = 4; >+ imageContext.drawText(font, textRun, { textGap, 12 }, 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; >+} >+ > // 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 +2849,45 @@ void RenderLayerBacking::paintContents(const GraphicsLayer* graphicsLayer, Graph > behavior.add(PaintBehavior::TileFirstPaint); > > paintIntoLayer(graphicsLayer, context, dirtyRect, behavior, paintingPhase); >+ >+ bool showTouchActionRegions = renderer().settings().visibleDebugOverlayRegions() & NonFastScrollableRegion; >+ if (showTouchActionRegions && graphicsLayer == m_graphicsLayer.get() && !m_graphicsLayer->eventRegion().isEmpty()) { >+ GraphicsContextStateSaver stateSaver(context); >+ >+ // The region is offset by contentOffsetInCompositingLayer() so undo that. >+ auto contentOffset = roundedIntSize(contentOffsetInCompositingLayer()); >+ context.translate(-contentOffset); >+ >+ // The interactive part. >+ auto& eventRegion = m_graphicsLayer->eventRegion(); >+ Color regionColor(0, 0, 0, 5); >+ context.setFillColor(regionColor); >+ for (auto rect : eventRegion.region().rects()) >+ context.fillRect(rect); >+ >+ const TouchAction touchActionList[] = { >+ TouchAction::None, >+ TouchAction::Manipulation, >+ TouchAction::PanX, >+ TouchAction::PanY, >+ TouchAction::PinchZoom, >+ }; >+ >+ for (auto action : touchActionList) { >+ auto* actionRegion = m_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); >+ } >+ } >+ > } else if (graphicsLayer == layerForHorizontalScrollbar()) { > paintScrollbar(m_owningLayer.horizontalScrollbar(), context, dirtyRect); > } else if (graphicsLayer == layerForVerticalScrollbar()) {
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
Flags:
graouts
:
review+
ews-watchlist
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198718
: 371744 |
371755
|
371785