Bug 225557 - Factor out text indicator bounce layer to be cross-platform
Summary: Factor out text indicator bounce layer to be cross-platform
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Megan Gardner
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-07 23:00 PDT by Megan Gardner
Modified: 2021-05-11 10:47 PDT (History)
5 users (show)

See Also:


Attachments
Patch (45.92 KB, patch)
2021-05-07 23:17 PDT, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (43.93 KB, patch)
2021-05-08 21:07 PDT, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch for landing (45.01 KB, patch)
2021-05-11 09:56 PDT, Megan Gardner
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Megan Gardner 2021-05-07 23:00:52 PDT
Factor out find bounce layer
Comment 1 Megan Gardner 2021-05-07 23:17:05 PDT
Created attachment 428078 [details]
Patch
Comment 2 Wenson Hsieh 2021-05-08 08:47:32 PDT
Comment on attachment 428078 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=428078&action=review

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.h:35
> +    RefPtr<WebCore::TextIndicator> _textIndicator;

Nit - it looks like this could be a Ref<WebCore::TextIndicator> instead?

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:167
> +    RetainPtr<CGColorRef> rimShadowColor = CGColorCreateGenericGray(0, 0.35);
> +    RetainPtr<CGColorRef> dropShadowColor = CGColorCreateGenericGray(0, 0.2);
> +    RetainPtr<CGColorRef> borderColor = CGColorCreateSRGB(0.96, 0.9, 0, 1);

adoptCF() here to fix the leaks.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:171
> +    highlightColor = CGColorCreateSRGB(.99, .89, 0.22, 1.0);

(This leaks too)
Comment 3 Wenson Hsieh 2021-05-08 16:38:57 PDT
(In reply to Wenson Hsieh from comment #2)
> Comment on attachment 428078 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=428078&action=review
> 
> > Source/WebCore/page/cocoa/WebTextIndicatorLayer.h:35
> > +    RefPtr<WebCore::TextIndicator> _textIndicator;
> 
> Nit - it looks like this could be a Ref<WebCore::TextIndicator> instead?

(Never mind — as you discovered, we can't use Ref because ivars in ObjC++ must be default constructible :P)

> 
> > Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:167
> > +    RetainPtr<CGColorRef> rimShadowColor = CGColorCreateGenericGray(0, 0.35);
> > +    RetainPtr<CGColorRef> dropShadowColor = CGColorCreateGenericGray(0, 0.2);
> > +    RetainPtr<CGColorRef> borderColor = CGColorCreateSRGB(0.96, 0.9, 0, 1);
> 
> adoptCF() here to fix the leaks.
> 
> > Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:171
> > +    highlightColor = CGColorCreateSRGB(.99, .89, 0.22, 1.0);
> 
> (This leaks too)
Comment 4 Megan Gardner 2021-05-08 21:07:41 PDT
Created attachment 428110 [details]
Patch
Comment 5 Tim Horton 2021-05-08 21:38:42 PDT
Comment on attachment 428110 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=428110&action=review

> Source/WebCore/ChangeLog:3
> +        Factor out find bounce layer

This really undersells the change. It's not just "factor it out" but really "reimplement it in terms of CALayer to make it cross-platform"

> Source/WebCore/ChangeLog:9
> +        compatable with iOS. 

sp: Compatible

> Source/WebCore/ChangeLog:11
> +        No behavior change. 

Please make sure you test find in both modern WebKit and WebKitLegacy, since there are precisely 0 automated tests for TextIndicatorWindow+friends.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:163
> +    

Weird extraneous newline

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:165
> +    RetainPtr<CGColorRef> rimShadowColor =adoptCF(CGColorCreateGenericGray(0, 0.35));

Missing a space after the =

> Source/WebCore/page/mac/TextIndicatorWindow.mm:119
> +    [m_textIndicatorView setWantsLayer:YES];
> +    [m_textIndicatorView setLayer:m_textIndicatorLayer.get()];

IIRC the order of these is important. The documentation says that you want them in the opposite order to make a layer-hosting view, which I think is the mode you want? Take a gander at the discussion section in https://developer.apple.com/documentation/appkit/nsview/1483695-wantslayer?language=objc
Comment 6 Tim Horton 2021-05-08 21:39:45 PDT
(In reply to Tim Horton from comment #5)
> Comment on attachment 428110 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=428110&action=review
> 
> > Source/WebCore/ChangeLog:3
> > +        Factor out find bounce layer
> 
> This really undersells the change. It's not just "factor it out" but really
> "reimplement it in terms of CALayer to make it cross-platform"
> 
> > Source/WebCore/ChangeLog:9
> > +        compatable with iOS. 
> 
> sp: Compatible
> 
> > Source/WebCore/ChangeLog:11
> > +        No behavior change. 
> 
> Please make sure you test find in both modern WebKit and WebKitLegacy, since
> there are precisely 0 automated tests for TextIndicatorWindow+friends.

Not just find: test Lookup! (with force-touch trackpad, or three-finger tap, or right-click on a selection; they all use different animations)
Comment 7 Darin Adler 2021-05-08 21:49:19 PDT
Comment on attachment 428110 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=428110&action=review

Some style tweaks you could consider: not required

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:57
> +const CFTimeInterval bounceAnimationDuration = 0.12;
> +const CFTimeInterval bounceWithCrossfadeAnimationDuration = 0.3;
> +const CFTimeInterval fadeInAnimationDuration = 0.15;
> +const CFTimeInterval timeBeforeFadeStarts = bounceAnimationDuration + 0.2;
> +const CFTimeInterval fadeOutAnimationDuration = 0.3;
> +
> +const CGFloat midBounceScale = 1.25;
> +const CGFloat borderWidth = 0;
> +const CGFloat cornerRadius = 0;
> +const CGFloat dropShadowOffsetX = 0;
> +const CGFloat dropShadowOffsetY = 1;
> +const CGFloat dropShadowBlurRadius = 2;
> +const CGFloat rimShadowBlurRadius = 1;
> +
> +NSString *textLayerKey = @"TextLayer";
> +NSString *dropShadowLayerKey = @"DropShadowLayer";
> +NSString *rimShadowLayerKey = @"RimShadowLayer";

We should use constexpr for all of these.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:59
> +using namespace WebCore;

We should avoid this, and instead write the WebCore:: prefix where needed.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:65
> +#if PLATFORM(MAC)
> +OBJC_CLASS NSColor;
> +using CocoaColor = NSColor;
> +#endif

Should get this from the CocoaColor.h header. Since we need this in WebCore, should move that header from WebKit to WebCore.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:161
> +    RetainPtr<NSMutableArray> bounceLayers = adoptNS([[NSMutableArray alloc] init]);

We should use auto here.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:167
> +    RetainPtr<CGColorRef> rimShadowColor =adoptCF(CGColorCreateGenericGray(0, 0.35));
> +    RetainPtr<CGColorRef> dropShadowColor = adoptCF(CGColorCreateGenericGray(0, 0.2));
> +    RetainPtr<CGColorRef> borderColor = adoptCF(CGColorCreateSRGB(0.96, 0.9, 0, 1));

We should use auto for these. Also there is a missing space after the "=" in the rimShadowColor line.

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:174
> +    Vector<FloatRect> textRectsInBoundingRectCoordinates = _textIndicator->textRectsInBoundingRectCoordinates();

auto

> Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:176
> +    Vector<Path> paths = PathUtilities::pathsWithShrinkWrappedRects(textRectsInBoundingRectCoordinates, cornerRadius);

auto
Comment 8 Megan Gardner 2021-05-11 09:56:31 PDT
Created attachment 428287 [details]
Patch for landing
Comment 9 EWS 2021-05-11 10:46:48 PDT
Committed r277330 (237589@main): <https://commits.webkit.org/237589@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 428287 [details].
Comment 10 Radar WebKit Bug Importer 2021-05-11 10:47:19 PDT
<rdar://problem/77853815>