Changeset 295291 in webkit
- Timestamp:
- Jun 6, 2022, 10:50:50 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
page/DebugPageOverlays.cpp (modified) (14 diffs)
-
page/DebugPageOverlays.h (modified) (4 diffs)
-
rendering/RenderLayerBacking.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/page/DebugPageOverlays.cpp
r294614 r295291 41 41 #include "PlatformMouseEvent.h" 42 42 #include "Region.h" 43 #include "RenderLayer.h" 44 #include "RenderLayerBacking.h" 45 #include "RenderView.h" 43 46 #include "ScrollingCoordinator.h" 44 47 #include "Settings.h" … … 58 61 59 62 void setRegionChanged() { m_regionChanged = true; } 63 64 virtual bool shouldPaintOverlayIntoLayer() const { return true; } 60 65 61 66 protected: … … 258 263 bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) final; 259 264 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); } 264 272 265 273 struct Setting { … … 279 287 { "regions"_s, "Show Regions"_s, false } 280 288 }; 281 282 Vector<InteractionRegion> m_regions; 289 283 290 IntPoint m_mouseLocationInContentCoordinates; 284 291 }; … … 287 294 { 288 295 m_overlay->setNeedsDisplay(); 289 m_regions = interactionRegions(m_page, { { 0, 0 }, m_page.mainFrame().view()->contentsSize() });290 291 296 return true; 292 297 } … … 302 307 } 303 308 304 std::optional<InteractionRegion> InteractionRegionOverlay::activeRegion() 305 { 309 std::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 328 std::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 306 336 std::optional<InteractionRegion> hitRegion; 307 337 float hitRegionArea = 0; 308 338 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) { 310 344 float area = 0; 311 345 FloatRect boundingRect; … … 318 352 } 319 353 320 if (!boundingRect.contains(m _mouseLocationInContentCoordinates))354 if (!boundingRect.contains(mouseLocationInLayerCoordinates)) 321 355 continue; 322 356 … … 324 358 bool didHitRegion = false; 325 359 for (const auto& path : paths) { 326 if (path.contains(m _mouseLocationInContentCoordinates)) {360 if (path.contains(mouseLocationInLayerCoordinates)) { 327 361 didHitRegion = true; 328 362 break; … … 342 376 } 343 377 378 if (hitRegion) 379 hitRegion->regionInLayerCoordinates.translate(roundedIntSize(offset)); 380 344 381 return hitRegion; 382 #else 383 return std::nullopt; 384 #endif 345 385 } 346 386 … … 370 410 } 371 411 372 FloatRect InteractionRegionOverlay::rectForSettingAtIndex(unsigned index) 412 FloatRect InteractionRegionOverlay::rectForSettingAtIndex(unsigned index) const 373 413 { 374 414 auto viewSize = m_page.mainFrame().view()->layoutSize(); … … 382 422 } 383 423 384 bool InteractionRegionOverlay::valueForSetting(ASCIILiteral name) 424 bool InteractionRegionOverlay::valueForSetting(ASCIILiteral name) const 385 425 { 386 426 for (const auto& setting : m_settings) { … … 428 468 429 469 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 }440 470 441 471 auto region = activeRegion(); … … 537 567 if (event.button() == LeftButton && event.type() == PlatformEvent::MousePressed) { 538 568 m_settings[i].value = !m_settings[i].value; 569 m_page.forceRepaintAllFrames(); 539 570 return true; 540 571 } … … 739 770 } 740 771 741 } 772 bool 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 41 41 static DebugPageOverlays& singleton(); 42 42 43 enum class RegionType {43 enum class RegionType : uint8_t { 44 44 WheelEventHandlers, 45 45 NonFastScrollableRegion, … … 51 51 static void didChangeEventHandlers(Frame&); 52 52 static void doAfterUpdateRendering(Page&); 53 54 static bool shouldPaintOverlayIntoLayerForRegionType(Page&, RegionType); 53 55 54 56 WEBCORE_EXPORT static void settingsChanged(Page&); … … 70 72 71 73 void updateOverlayRegionVisibility(Page&, OptionSet<DebugOverlayRegions>); 74 75 bool shouldPaintOverlayIntoLayer(Page&, RegionType) const; 72 76 73 77 RegionOverlay* regionOverlayForPage(Page&, RegionType) const; … … 117 121 } 118 122 123 inline bool DebugPageOverlays::shouldPaintOverlayIntoLayerForRegionType(Page& page, RegionType regionType) 124 { 125 if (LIKELY(!hasOverlays(page))) 126 return false; 127 return sharedDebugOverlays->shouldPaintOverlayIntoLayer(page, regionType); 128 } 129 119 130 } // namespace WebCore -
trunk/Source/WebCore/rendering/RenderLayerBacking.cpp
r294973 r295291 3477 3477 } 3478 3478 #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 3479 3494 } 3480 3495 … … 3519 3534 3520 3535 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 })) 3522 3537 paintDebugOverlays(graphicsLayer, context); 3523 3538
Note:
See TracChangeset
for help on using the changeset viewer.