Title: [286588] trunk/Source
Revision
286588
Author
[email protected]
Date
2021-12-06 22:20:45 -0800 (Mon, 06 Dec 2021)

Log Message

[Cocoa] Web Inspector: Unify Grid overlay drawing code
https://bugs.webkit.org/show_bug.cgi?id=233773

Reviewed by Devin Rousso.

Source/WebCore:

Expose InspectorOverlay::drawGridOverlay as a static method so that it can be used for iOS overlay drawing and
clean up other related drawing methods to be private static instead of instance methods or public static methods.

* inspector/InspectorOverlay.cpp:
(WebCore::drawLayoutHatching):
(WebCore::fontForLayoutLabel):
(WebCore::backgroundPathForLayoutLabel):
(WebCore::expectedSizeForLayoutLabel):
(WebCore::drawLayoutLabel):
(WebCore::InspectorOverlay::drawLayoutHatching): Deleted.
(WebCore::InspectorOverlay::fontForLayoutLabel): Deleted.
(WebCore::InspectorOverlay::backgroundPathForLayoutLabel): Deleted.
(WebCore::InspectorOverlay::drawLayoutLabel): Deleted.
* inspector/InspectorOverlay.h:

Source/WebKit:

Remove the (almost) 1-to-1 duplicated logic currently being used to turn Grid Overlays into a layer hierarchy
and instead use a graphics context to draw the overlays straight into the view to take advantage of the existing
drawing code we use for macOS in WebCore::InspectorOverlay. To accommodate this, we now correctly set the
content scale factor of the view itself (so that our drawing does not appear blurry) and set the frame of the
view equal to the current visible portion of the parent scroll view, which helps us to avoid having an
incredibly large graphics context to draw into (which we would if the view's frame was just set to match the
frame of the webpage's view). This frame will not always be the same size, such as when zooming in where less of
the frame is visible. Combined with the current content scale, this actually means that on zoom the effective
number of pixels that need to be drawn is consistent.

* UIProcess/Inspector/ios/WKInspectorHighlightView.h:
* UIProcess/Inspector/ios/WKInspectorHighlightView.mm:
(-[WKInspectorHighlightView initWithFrame:]):
- Explicitly set this view to be non-opaque so that page content can be seen below this view. This wasn't
previously necessary because the bounds of this view were a zero-rect, which meant the background was never
painted.

(-[WKInspectorHighlightView _removeAllLayers]):
(-[WKInspectorHighlightView _createLayers:]):
- Because the view's frame origin is now offset, we need to create the node highlight layers offset by the
negation of the frame's origin so that they still line up correctly with page content.

(-[WKInspectorHighlightView drawRect:]):
(-[WKInspectorHighlightView update:scale:frame:]):
(-[WKInspectorHighlightView _createGridOverlayLayers:scale:]): Deleted.
(createLayoutHatchingLayer): Deleted.
(createLayoutLabelLayer): Deleted.
(-[WKInspectorHighlightView _createGridOverlayLayer:scale:]): Deleted.
(-[WKInspectorHighlightView update:scale:]): Deleted.
* UIProcess/ios/WKContentView.mm:
(-[WKContentView _showInspectorHighlight:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286587 => 286588)


--- trunk/Source/WebCore/ChangeLog	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebCore/ChangeLog	2021-12-07 06:20:45 UTC (rev 286588)
@@ -1,3 +1,25 @@
+2021-12-06  Patrick Angle  <[email protected]>
+
+        [Cocoa] Web Inspector: Unify Grid overlay drawing code
+        https://bugs.webkit.org/show_bug.cgi?id=233773
+
+        Reviewed by Devin Rousso.
+
+        Expose InspectorOverlay::drawGridOverlay as a static method so that it can be used for iOS overlay drawing and
+        clean up other related drawing methods to be private static instead of instance methods or public static methods.
+
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::drawLayoutHatching):
+        (WebCore::fontForLayoutLabel):
+        (WebCore::backgroundPathForLayoutLabel):
+        (WebCore::expectedSizeForLayoutLabel):
+        (WebCore::drawLayoutLabel):
+        (WebCore::InspectorOverlay::drawLayoutHatching): Deleted.
+        (WebCore::InspectorOverlay::fontForLayoutLabel): Deleted.
+        (WebCore::InspectorOverlay::backgroundPathForLayoutLabel): Deleted.
+        (WebCore::InspectorOverlay::drawLayoutLabel): Deleted.
+        * inspector/InspectorOverlay.h:
+
 2021-12-06  Chris Dumez  <[email protected]>
 
         <input type="time">'s range should be reversible

Modified: trunk/Source/WebCore/inspector/InspectorOverlay.cpp (286587 => 286588)


--- trunk/Source/WebCore/inspector/InspectorOverlay.cpp	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebCore/inspector/InspectorOverlay.cpp	2021-12-07 06:20:45 UTC (rev 286588)
@@ -1170,7 +1170,7 @@
     return path;
 }
 
-void InspectorOverlay::drawLayoutHatching(GraphicsContext& context, FloatQuad quad)
+static void drawLayoutHatching(GraphicsContext& context, FloatQuad quad)
 {
     GraphicsContextStateSaver saver(context);
     context.clipPath(quadToPath(quad));
@@ -1204,7 +1204,7 @@
     context.strokePath(hatchPath);
 }
 
-FontCascade InspectorOverlay::fontForLayoutLabel()
+static FontCascade fontForLayoutLabel()
 {
     FontCascadeDescription fontDescription;
     fontDescription.setFamilies({ "system-ui" });
@@ -1216,7 +1216,7 @@
     return font;
 }
 
-Path InspectorOverlay::backgroundPathForLayoutLabel(float width, float height, InspectorOverlay::LabelArrowDirection arrowDirection, InspectorOverlay::LabelArrowEdgePosition arrowEdgePosition, float arrowSize)
+static Path backgroundPathForLayoutLabel(float width, float height, InspectorOverlay::LabelArrowDirection arrowDirection, InspectorOverlay::LabelArrowEdgePosition arrowEdgePosition, float arrowSize)
 {
     Path path;
     FloatSize offsetForArrowEdgePosition;
@@ -1346,7 +1346,7 @@
 
 static FloatSize expectedSizeForLayoutLabel(String label, InspectorOverlay::LabelArrowDirection direction, float maximumWidth = 0)
 {
-    auto font = InspectorOverlay::fontForLayoutLabel();
+    auto font = fontForLayoutLabel();
 
     float textHeight = font.fontMetrics().floatHeight();
     float textWidth = font.width(TextRun(label));
@@ -1367,9 +1367,9 @@
     RELEASE_ASSERT_NOT_REACHED();
 }
 
-void InspectorOverlay::drawLayoutLabel(GraphicsContext& context, String label, FloatPoint point, InspectorOverlay::LabelArrowDirection arrowDirection, InspectorOverlay::LabelArrowEdgePosition arrowEdgePosition, Color backgroundColor, float maximumWidth)
+static void drawLayoutLabel(GraphicsContext& context, String label, FloatPoint point, InspectorOverlay::LabelArrowDirection arrowDirection, InspectorOverlay::LabelArrowEdgePosition arrowEdgePosition, Color backgroundColor, float maximumWidth = 0)
 {
-    ASSERT(arrowEdgePosition != LabelArrowEdgePosition::None || arrowDirection == LabelArrowDirection::None);
+    ASSERT(arrowEdgePosition != InspectorOverlay::LabelArrowEdgePosition::None || arrowDirection == InspectorOverlay::LabelArrowDirection::None);
 
     GraphicsContextStateSaver saver(context);
     

Modified: trunk/Source/WebCore/inspector/InspectorOverlay.h (286587 => 286588)


--- trunk/Source/WebCore/inspector/InspectorOverlay.h	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebCore/inspector/InspectorOverlay.h	2021-12-07 06:20:45 UTC (rev 286588)
@@ -218,8 +218,7 @@
     Inspector::ErrorStringOr<void> clearGridOverlayForNode(Node&);
     void clearAllGridOverlays();
 
-    WEBCORE_EXPORT static FontCascade fontForLayoutLabel();
-    WEBCORE_EXPORT static Path backgroundPathForLayoutLabel(float, float, InspectorOverlay::LabelArrowDirection, InspectorOverlay::LabelArrowEdgePosition, float arrowSize);
+    WEBCORE_EXPORT static void drawGridOverlay(GraphicsContext&, const InspectorOverlay::Highlight::GridHighlightOverlay&);
 private:
     using TimeRectPair = std::pair<MonotonicTime, FloatRect>;
 
@@ -236,10 +235,6 @@
 
     Path drawElementTitle(GraphicsContext&, Node&, const Highlight::Bounds&);
     
-    void drawLayoutHatching(GraphicsContext&, FloatQuad);
-    void drawLayoutLabel(GraphicsContext&, String, FloatPoint, LabelArrowDirection, InspectorOverlay::LabelArrowEdgePosition, Color backgroundColor = Color::white, float maximumWidth = 0);
-
-    void drawGridOverlay(GraphicsContext&, const InspectorOverlay::Highlight::GridHighlightOverlay&);
     std::optional<InspectorOverlay::Highlight::GridHighlightOverlay> buildGridOverlay(const InspectorOverlay::Grid&, bool offsetBoundsByScroll = false);
 
     void updatePaintRectsTimerFired();

Modified: trunk/Source/WebKit/ChangeLog (286587 => 286588)


--- trunk/Source/WebKit/ChangeLog	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebKit/ChangeLog	2021-12-07 06:20:45 UTC (rev 286588)
@@ -1,3 +1,43 @@
+2021-12-06  Patrick Angle  <[email protected]>
+
+        [Cocoa] Web Inspector: Unify Grid overlay drawing code
+        https://bugs.webkit.org/show_bug.cgi?id=233773
+
+        Reviewed by Devin Rousso.
+
+        Remove the (almost) 1-to-1 duplicated logic currently being used to turn Grid Overlays into a layer hierarchy
+        and instead use a graphics context to draw the overlays straight into the view to take advantage of the existing
+        drawing code we use for macOS in WebCore::InspectorOverlay. To accommodate this, we now correctly set the
+        content scale factor of the view itself (so that our drawing does not appear blurry) and set the frame of the
+        view equal to the current visible portion of the parent scroll view, which helps us to avoid having an
+        incredibly large graphics context to draw into (which we would if the view's frame was just set to match the
+        frame of the webpage's view). This frame will not always be the same size, such as when zooming in where less of
+        the frame is visible. Combined with the current content scale, this actually means that on zoom the effective
+        number of pixels that need to be drawn is consistent.
+
+        * UIProcess/Inspector/ios/WKInspectorHighlightView.h:
+        * UIProcess/Inspector/ios/WKInspectorHighlightView.mm:
+        (-[WKInspectorHighlightView initWithFrame:]):
+        - Explicitly set this view to be non-opaque so that page content can be seen below this view. This wasn't
+        previously necessary because the bounds of this view were a zero-rect, which meant the background was never
+        painted.
+
+        (-[WKInspectorHighlightView _removeAllLayers]):
+        (-[WKInspectorHighlightView _createLayers:]):
+        - Because the view's frame origin is now offset, we need to create the node highlight layers offset by the
+        negation of the frame's origin so that they still line up correctly with page content.
+
+        (-[WKInspectorHighlightView drawRect:]):
+        (-[WKInspectorHighlightView update:scale:frame:]):
+        (-[WKInspectorHighlightView _createGridOverlayLayers:scale:]): Deleted.
+        (createLayoutHatchingLayer): Deleted.
+        (createLayoutLabelLayer): Deleted.
+        (-[WKInspectorHighlightView _createGridOverlayLayer:scale:]): Deleted.
+        (-[WKInspectorHighlightView update:scale:]): Deleted.
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _showInspectorHighlight:]):
+
+
 2021-12-06  Lauro Moura  <[email protected]>
 
         REGRESSION(r286535) [GTK] Fix clean builds after DerivedSources/WebKit2 move

Modified: trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.h (286587 => 286588)


--- trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.h	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.h	2021-12-07 06:20:45 UTC (rev 286588)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014, 2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,11 +28,15 @@
 #import <UIKit/UIKit.h>
 #import <WebCore/InspectorOverlay.h>
 
+namespace WebCore {
+class FloatRect;
+}
+
 @interface WKInspectorHighlightView : UIView {
     RetainPtr<NSMutableArray<CAShapeLayer *>> _layers;
-    RetainPtr<NSMutableArray<CALayer *>> _gridOverlayLayers;
+    std::optional<WebCore::InspectorOverlay::Highlight> _highlight;
 }
-- (void)update:(const WebCore::InspectorOverlay::Highlight&)highlight scale:(double)scale;
+- (void)update:(const WebCore::InspectorOverlay::Highlight&)highlight scale:(double)scale frame:(const WebCore::FloatRect&)frame;
 @end
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.mm (286587 => 286588)


--- trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.mm	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.mm	2021-12-07 06:20:45 UTC (rev 286588)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014, 2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,12 +28,10 @@
 
 #if PLATFORM(IOS_FAMILY)
 
-#import <WebCore/FloatLine.h>
 #import <WebCore/FloatQuad.h>
-#import <WebCore/FontCascade.h>
-#import <WebCore/FontCascadeDescription.h>
+#import <WebCore/FloatRect.h>
 #import <WebCore/GeometryUtilities.h>
-#import <WebCore/TextRun.h>
+#import <WebCore/GraphicsContextCG.h>
 
 @implementation WKInspectorHighlightView
 
@@ -42,7 +40,7 @@
     if (!(self = [super initWithFrame:frame]))
         return nil;
     _layers = adoptNS([[NSMutableArray alloc] init]);
-    _gridOverlayLayers = adoptNS([[NSMutableArray alloc] init]);
+    self.opaque = NO;
     return self;
 }
 
@@ -57,9 +55,6 @@
     for (CAShapeLayer *layer in _layers.get())
         [layer removeFromSuperlayer];
     [_layers removeAllObjects];
-    for (CALayer *layer in _gridOverlayLayers.get())
-        [layer removeFromSuperlayer];
-    [_gridOverlayLayers removeAllObjects];
 }
 
 - (void)_createLayers:(NSUInteger)numLayers
@@ -69,6 +64,7 @@
 
     for (NSUInteger i = 0; i < numLayers; ++i) {
         auto layer = adoptNS([[CAShapeLayer alloc] init]);
+        layer.get().position = CGPointMake(-self.frame.origin.x, -self.frame.origin.y);
         [_layers addObject:layer.get()];
         [self.layer addSublayer:layer.get()];
     }
@@ -268,220 +264,36 @@
     }
 }
 
-- (void)_createGridOverlayLayers:(const WebCore::InspectorOverlay::Highlight&)highlight scale:(double)scale
+- (void)drawRect:(CGRect)dirtyRect
 {
-    for (auto gridOverlay : highlight.gridHighlightOverlays) {
-        auto layer = [self _createGridOverlayLayer:gridOverlay scale:scale];
-        [_gridOverlayLayers addObject:layer];
-        [self.layer addSublayer:layer];
-    }
-}
+    [super drawRect:dirtyRect];
 
-static CALayer * createLayoutHatchingLayer(WebCore::FloatQuad quad, WebCore::Color strokeColor)
-{
-    CAShapeLayer *layer = [CAShapeLayer layer];
+    if (!_highlight)
+        return;
 
-    constexpr auto hatchSpacing = 12;
-    auto hatchPath = adoptCF(CGPathCreateMutable());
+    auto context = WebCore::GraphicsContextCG(UIGraphicsGetCurrentContext());
+    context.clip({ dirtyRect });
+    context.translate(-self.frame.origin.x, -self.frame.origin.y);
 
-    WebCore::FloatLine topSide = { quad.p1(), quad.p2() };
-    WebCore::FloatLine leftSide = { quad.p1(), quad.p4() };
-
-    // The opposite axis' length is used to determine how far to draw a hatch line in both dimensions, which keeps the lines at a 45deg angle.
-    if (topSide.length() > leftSide.length()) {
-        WebCore::FloatLine bottomSide = { quad.p4(), quad.p3() };
-        // Move across the relative top of the quad, starting left of `0, 0` to ensure that the tail of the previous hatch line is drawn while scrolling.
-        for (float x = -leftSide.length(); x < topSide.length(); x += hatchSpacing) {
-            auto startPoint = topSide.pointAtAbsoluteDistance(x);
-            auto endPoint = bottomSide.pointAtAbsoluteDistance(x + leftSide.length());
-            CGPathMoveToPoint(hatchPath.get(), 0, startPoint.x(), startPoint.y());
-            CGPathAddLineToPoint(hatchPath.get(), 0, endPoint.x(), endPoint.y());
-        }
-    } else {
-        WebCore::FloatLine rightSide = { quad.p2(), quad.p3() };
-        // Move down the relative left side of the quad, starting above `0, 0` to ensure that the tail of the previous hatch line is drawn while scrolling.
-        for (float y = -topSide.length(); y < leftSide.length(); y += hatchSpacing) {
-            auto startPoint = leftSide.pointAtAbsoluteDistance(y);
-            auto endPoint = rightSide.pointAtAbsoluteDistance(y + topSide.length());
-            CGPathMoveToPoint(hatchPath.get(), 0, startPoint.x(), startPoint.y());
-            CGPathAddLineToPoint(hatchPath.get(), 0, endPoint.x(), endPoint.y());
-        }
-    }
-    layer.path = hatchPath.get();
-    layer.strokeColor = cachedCGColor(strokeColor).get();
-    layer.lineWidth = 0.5;
-    layer.lineDashPattern = @[[NSNumber numberWithInt:2], [NSNumber numberWithInt:2]];
-
-    CAShapeLayer *maskLayer = [CAShapeLayer layer];
-    layerPath(maskLayer, quad);
-    layer.mask = maskLayer;
-    return layer;
+    for (auto gridHighlightOverlay : _highlight->gridHighlightOverlays)
+        WebCore::InspectorOverlay::drawGridOverlay(context, gridHighlightOverlay);
 }
 
-static CALayer * createLayoutLabelLayer(String label, WebCore::FloatPoint point, WebCore::InspectorOverlay::LabelArrowDirection arrowDirection, WebCore::InspectorOverlay::LabelArrowEdgePosition arrowEdgePosition, WebCore::Color backgroundColor, WebCore::Color strokeColor, double scale, float maximumWidth = 0)
+- (void)update:(const WebCore::InspectorOverlay::Highlight&)highlight scale:(double)scale frame:(const WebCore::FloatRect&)frame
 {
-    auto font = WebCore::InspectorOverlay::fontForLayoutLabel();
+    [self _removeAllLayers];
 
-    constexpr auto padding = 4;
-    constexpr auto arrowSize = 6;
-    float textHeight = font.fontMetrics().floatHeight();
+    _highlight = highlight;
+    self.contentScaleFactor = UIScreen.mainScreen.scale * scale;
+    self.frame = frame;
 
-    float textWidth = font.width(WebCore::TextRun(label));
-    if (maximumWidth && textWidth + (padding * 2) > maximumWidth) {
-        label.append("..."_s);
-        while (textWidth + (padding * 2) > maximumWidth && label.length() >= 4) {
-            // Remove the fourth from last character (the character before the ellipsis) and remeasure.
-            label.remove(label.length() - 4);
-            textWidth = font.width(WebCore::TextRun(label));
-        }
-    }
-
-    // Note: Implementation Difference - The textPosition is the center of text, unlike WebCore::InspectorOverlay, where the textPosition is leftmost point on the baseline of the text.
-    WebCore::FloatPoint textPosition;
-    switch (arrowDirection) {
-    case WebCore::InspectorOverlay::LabelArrowDirection::Down:
-        switch (arrowEdgePosition) {
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Leading:
-            textPosition = WebCore::FloatPoint((textWidth / 2) + padding, -(textHeight / 2) - arrowSize - padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Middle:
-            textPosition = WebCore::FloatPoint(0, -(textHeight / 2) - arrowSize - padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Trailing:
-            textPosition = WebCore::FloatPoint(-(textWidth / 2) - padding, -(textHeight / 2) - arrowSize - padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::None:
-            break;
-        }
-        break;
-    case WebCore::InspectorOverlay::LabelArrowDirection::Up:
-        switch (arrowEdgePosition) {
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Leading:
-            textPosition = WebCore::FloatPoint((textWidth / 2) + padding, (textHeight / 2) + arrowSize + padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Middle:
-            textPosition = WebCore::FloatPoint(0, (textHeight / 2) + arrowSize + padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Trailing:
-            textPosition = WebCore::FloatPoint(-(textWidth / 2) - padding, (textHeight / 2) + arrowSize + padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::None:
-            break;
-        }
-        break;
-    case WebCore::InspectorOverlay::LabelArrowDirection::Right:
-        switch (arrowEdgePosition) {
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Leading:
-            textPosition = WebCore::FloatPoint(-(textWidth / 2) - arrowSize - padding, (textHeight / 2) + padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Middle:
-            textPosition = WebCore::FloatPoint(-(textWidth / 2) - arrowSize - padding, 0);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Trailing:
-            textPosition = WebCore::FloatPoint(-(textWidth / 2) - arrowSize - padding, -(textHeight / 2) - padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::None:
-            break;
-        }
-        break;
-    case WebCore::InspectorOverlay::LabelArrowDirection::Left:
-        switch (arrowEdgePosition) {
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Leading:
-            textPosition = WebCore::FloatPoint((textWidth / 2) + arrowSize + padding, (textHeight / 2) + padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Middle:
-            textPosition = WebCore::FloatPoint((textWidth / 2) + arrowSize + padding, 0);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::Trailing:
-            textPosition = WebCore::FloatPoint((textWidth / 2) + arrowSize + padding, -(textHeight / 2) - padding);
-            break;
-        case WebCore::InspectorOverlay::LabelArrowEdgePosition::None:
-            break;
-        }
-        break;
-    case WebCore::InspectorOverlay::LabelArrowDirection::None:
-        // Text position will remain (0, 0).
-        break;
-    }
-
-    CALayer *layer = [CALayer layer];
-
-#if USE(CG)
-    // WebCore::Path::PlatformPathPtr is only a CGPath* when `USE(CG)` is true.
-    auto labelPath = WebCore::InspectorOverlay::backgroundPathForLayoutLabel(textWidth + (padding * 2), textHeight + (padding * 2), arrowDirection, arrowEdgePosition, arrowSize);
-    CGPath* platformLabelPath = labelPath.ensurePlatformPath();
-
-    CAShapeLayer *labelPathLayer = [CAShapeLayer layer];
-    labelPathLayer.path = platformLabelPath;
-    labelPathLayer.fillColor = cachedCGColor(backgroundColor).get();
-    labelPathLayer.strokeColor = cachedCGColor(strokeColor).get();
-    labelPathLayer.position = CGPointMake(point.x(), point.y());
-    [layer addSublayer:labelPathLayer];
-#endif
-
-    CATextLayer *textLayer = [CATextLayer layer];
-    textLayer.frame = CGRectMake(0, 0, textWidth, textHeight);
-    textLayer.string = label;
-    textLayer.font = font.primaryFont().getCTFont();
-    textLayer.fontSize = 12;
-    textLayer.alignmentMode = kCAAlignmentLeft;
-    textLayer.foregroundColor = CGColorGetConstantColor(kCGColorBlack);
-    textLayer.position = CGPointMake(textPosition.x() + point.x(), textPosition.y() + point.y());
-    textLayer.contentsScale = [[UIScreen mainScreen] scale] * scale;
-    [layer addSublayer:textLayer];
-
-    return layer;
-}
-
-- (CALayer *)_createGridOverlayLayer:(const WebCore::InspectorOverlay::Highlight::GridHighlightOverlay&)overlay scale:(double)scale
-{
-    // Keep implementation roughly equivalent to `WebCore::InspectorOverlay::drawGridOverlay`.
-    CALayer *layer = [CALayer layer];
-
-    auto gridLinesPath = adoptCF(CGPathCreateMutable());
-    for (auto gridLine : overlay.gridLines) {
-        CGPathMoveToPoint(gridLinesPath.get(), 0, gridLine.start().x(), gridLine.start().y());
-        CGPathAddLineToPoint(gridLinesPath.get(), 0, gridLine.end().x(), gridLine.end().y());
-    }
-    CAShapeLayer *gridLinesLayer = [CAShapeLayer layer];
-    gridLinesLayer.path = gridLinesPath.get();
-    gridLinesLayer.lineWidth = 1;
-    gridLinesLayer.strokeColor = cachedCGColor(overlay.color).get();
-    [layer addSublayer:gridLinesLayer];
-
-    for (auto gapQuad : overlay.gaps)
-        [layer addSublayer:createLayoutHatchingLayer(gapQuad, overlay.color)];
-
-    for (auto area : overlay.areas) {
-        CAShapeLayer *areaLayer = [CAShapeLayer layer];
-        layerPath(areaLayer, area.quad);
-        areaLayer.lineWidth = 3;
-        areaLayer.fillColor = CGColorGetConstantColor(kCGColorClear);
-        areaLayer.strokeColor = cachedCGColor(overlay.color).get();
-        [layer addSublayer:areaLayer];
-    }
-
-    constexpr auto translucentLabelBackgroundColor = WebCore::Color::white.colorWithAlphaByte(230);
-
-    for (auto area : overlay.areas)
-        [layer addSublayer:createLayoutLabelLayer(area.name, area.quad.center(), WebCore::InspectorOverlay::LabelArrowDirection::None, WebCore::InspectorOverlay::LabelArrowEdgePosition::None, translucentLabelBackgroundColor, overlay.color, scale, area.quad.boundingBox().width())];
-
-    for (auto label : overlay.labels)
-        [layer addSublayer:createLayoutLabelLayer(label.text, label.location, label.arrowDirection, label.arrowEdgePosition, label.backgroundColor, overlay.color, scale)];
-
-    return layer;
-}
-
-- (void)update:(const WebCore::InspectorOverlay::Highlight&)highlight scale:(double)scale
-{
-    [self _removeAllLayers];
-
     if (highlight.type == WebCore::InspectorOverlay::Highlight::Type::Node || highlight.type == WebCore::InspectorOverlay::Highlight::Type::NodeList)
         [self _layoutForNodeListHighlight:highlight];
     else if (highlight.type == WebCore::InspectorOverlay::Highlight::Type::Rects)
         [self _layoutForRectsHighlight:highlight];
 
-    [self _createGridOverlayLayers:highlight scale:scale];
+    
+    [self setNeedsDisplay];
 }
 
 @end

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (286587 => 286588)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2021-12-07 05:52:22 UTC (rev 286587)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2021-12-07 06:20:45 UTC (rev 286588)
@@ -412,8 +412,7 @@
         _inspectorHighlightView = adoptNS([[WKInspectorHighlightView alloc] initWithFrame:CGRectZero]);
         [self insertSubview:_inspectorHighlightView.get() aboveSubview:_rootContentView.get()];
     }
-
-    [_inspectorHighlightView update:highlight scale:[self _contentZoomScale]];
+    [_inspectorHighlightView update:highlight scale:[self _contentZoomScale] frame:_page->unobscuredContentRect()];
 }
 
 - (void)_hideInspectorHighlight
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to