Bug 191442 - [iOS] Do not show selection UI for editable elements with opacity near zero
Summary: [iOS] Do not show selection UI for editable elements with opacity near zero
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Local Build
Hardware: iPhone / iPad iOS 12
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar, PlatformOnly
Depends on:
Blocks:
 
Reported: 2018-11-08 16:11 PST by Daniel Bates
Modified: 2018-11-13 15:11 PST (History)
7 users (show)

See Also:


Attachments
Patch (5.71 KB, patch)
2018-11-08 16:23 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Layout Tests (5.54 KB, patch)
2018-11-09 15:45 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
WIP (needs tests) (14.61 KB, patch)
2018-11-11 21:33 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
First pass (50.46 KB, patch)
2018-11-12 21:38 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Add missing layout test. (54.30 KB, patch)
2018-11-12 21:49 PST, Wenson Hsieh
simon.fraser: review+
Details | Formatted Diff | Diff
Patch for EWS (60.33 KB, patch)
2018-11-13 12:25 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch for EWS (60.33 KB, patch)
2018-11-13 12:52 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2018-11-08 16:11:07 PST
Pages on iCloud.com implement their own selection UI that interferes with the native iOS selection UI. Pages uses an editable element with CSS opacity set to value near 0 as a means to opt-out of selection painting on Mac. However, on iOS UIKit is responsible for painting the selection and providing selection assistance (i.e. the lollipops) and does not know about CSS opacity. I propose that we pass information about the editable node's opacity to the UIProcess so that we may opt-out of UIKit selection assistance and selection painting if the opacity is near 0.
Comment 1 Daniel Bates 2018-11-08 16:23:43 PST
Created attachment 354289 [details]
Patch

I am open to ideas on how to fix this bug as well as suggestions on the design in this proposed patch. I was unclear how to write a test for this change.
Comment 2 Simon Fraser (smfr) 2018-11-08 17:03:44 PST
Don't we have UIScriptController stuff to get selection rects?
Comment 3 Daniel Bates 2018-11-08 17:11:43 PST
(In reply to Simon Fraser (smfr) from comment #2)
> Don't we have UIScriptController stuff to get selection rects?

Does this tell us the UIView selection rect? This patch is all about painting. We want UIKit to know what text is selected. We just don’t want UIKit to paint the selection. Show the lollipops or a callout bar.
Comment 4 Wenson Hsieh 2018-11-08 17:13:07 PST
(In reply to Daniel Bates from comment #3)
> (In reply to Simon Fraser (smfr) from comment #2)
> > Don't we have UIScriptController stuff to get selection rects?
> 
> Does this tell us the UIView selection rect? This patch is all about
> painting. We want UIKit to know what text is selected. We just don’t want
> UIKit to paint the selection. Show the lollipops or a callout bar.

See:

UIHelper.getUISelectionRects()
UIHelper.getSelectionStartGrabberViewRect()

etc.

IIRC, there are some examples in editing/selection/ios
Comment 5 Wenson Hsieh 2018-11-08 17:15:14 PST
(In reply to Daniel Bates from comment #1)
> Created attachment 354289 [details]
> Patch
> 
> I am open to ideas on how to fix this bug as well as suggestions on the
> design in this proposed patch. I was unclear how to write a test for this
> change.

I had a patch to fix this not too long ago.

I remember one mildly tricky thing to get right is handling hidden contenteditable subframes. For example, typing and editing in the hidden area in <https://whsieh.github.io/examples/hidden-contenteditable> shouldn't cause native selection UI to pop up.
Comment 6 Wenson Hsieh 2018-11-08 17:31:50 PST
(In reply to Wenson Hsieh from comment #4)
> (In reply to Daniel Bates from comment #3)
> > (In reply to Simon Fraser (smfr) from comment #2)
> > > Don't we have UIScriptController stuff to get selection rects?
> > 
> > Does this tell us the UIView selection rect? This patch is all about
> > painting. We want UIKit to know what text is selected. We just don’t want
> > UIKit to paint the selection. Show the lollipops or a callout bar.
> 
> See:
> 
> UIHelper.getUISelectionRects()
> UIHelper.getSelectionStartGrabberViewRect()
> 
> etc.
> 
> IIRC, there are some examples in editing/selection/ios

Oh, do you mean we want to detect when the view is transparent, even if it has a nonzero frame?

It seems reasonable to add this functionality to UIScriptController, if what we have now doesn't suffice.
Comment 7 Daniel Bates 2018-11-09 15:41:41 PST
(In reply to Wenson Hsieh from comment #5)
> (In reply to Daniel Bates from comment #1)
> > Created attachment 354289 [details]
> > Patch
> > 
> > I am open to ideas on how to fix this bug as well as suggestions on the
> > design in this proposed patch. I was unclear how to write a test for this
> > change.
> 
> I had a patch to fix this not too long ago.
> 

Please post your patch!
Comment 8 Daniel Bates 2018-11-09 15:45:46 PST
Created attachment 354397 [details]
Layout Tests
Comment 9 Daniel Bates 2018-11-09 15:46:48 PST
Wenson is willing to take over this bug since he has an existing patch.

@Wenson: Here are some tests. Feel free to use them or scrap them.
Comment 10 Radar WebKit Bug Importer 2018-11-09 15:47:22 PST
<rdar://problem/45958625>
Comment 11 Wenson Hsieh 2018-11-11 21:33:54 PST
Created attachment 354531 [details]
WIP (needs tests)
Comment 12 Wenson Hsieh 2018-11-12 21:38:24 PST
Created attachment 354648 [details]
First pass
Comment 13 Wenson Hsieh 2018-11-12 21:49:28 PST
Created attachment 354650 [details]
Add missing layout test.
Comment 14 Simon Fraser (smfr) 2018-11-13 10:37:20 PST
Comment on attachment 354650 [details]
Add missing layout test.

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

> Source/WebCore/rendering/RenderObject.cpp:1525
> +        if (layerRenderer.style().opacity() < minimumVisibleOpacity)
> +            return true;

Opacity is multiplicative, so ideally you'd multiply it during your tree walk. For example, try ten nested divs with opacity 0.1.
Comment 15 Wenson Hsieh 2018-11-13 10:38:52 PST
Comment on attachment 354650 [details]
Add missing layout test.

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

>> Source/WebCore/rendering/RenderObject.cpp:1525
>> +            return true;
> 
> Opacity is multiplicative, so ideally you'd multiply it during your tree walk. For example, try ten nested divs with opacity 0.1.

Oh, good point! I'll multiply on the way up, and add another layout test for this scenario as well.
Comment 16 Wenson Hsieh 2018-11-13 12:25:57 PST
Created attachment 354689 [details]
Patch for EWS
Comment 17 Wenson Hsieh 2018-11-13 12:52:41 PST
Created attachment 354691 [details]
Patch for EWS
Comment 18 WebKit Commit Bot 2018-11-13 14:30:36 PST
Comment on attachment 354691 [details]
Patch for EWS

Clearing flags on attachment: 354691

Committed r238146: <https://trac.webkit.org/changeset/238146>