Bug 182264

Summary: Make preserve and restore focus more likely to be symmetrical
Product: WebKit Reporter: Megan Gardner <megan_gardner>
Component: New BugsAssignee: Megan Gardner <megan_gardner>
Status: RESOLVED FIXED    
Severity: Normal CC: simon.fraser, thorton, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch thorton: review+

Description Megan Gardner 2018-01-29 15:11:04 PST
Make preserve and restore focus more likely to be symetrical
Comment 1 Megan Gardner 2018-01-29 18:00:36 PST
Created attachment 332612 [details]
Patch
Comment 2 Megan Gardner 2018-01-29 18:01:03 PST
<rdar://problem/36948473>
Comment 3 Tim Horton 2018-01-29 18:03:50 PST
Comment on attachment 332612 [details]
Patch

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

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:174
> +    RetainPtr<NSMutableArray> _focusStateStack;

Vector<bool> is likely a better plan/more efficient/more WebKitty
Comment 4 Tim Horton 2018-01-29 18:06:17 PST
Comment on attachment 332612 [details]
Patch

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

> Source/WebKit/ChangeLog:3
> +        Make preserve and restore focus more likely to be symetrical

Symmetrical
Comment 5 Tim Horton 2018-01-29 18:07:01 PST
Comment on attachment 332612 [details]
Patch

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

> Source/WebKit/ChangeLog:5
> +

There should be a radar here.
Comment 6 Megan Gardner 2018-01-29 18:25:17 PST
Created attachment 332614 [details]
Patch
Comment 7 Wenson Hsieh 2018-01-29 19:24:34 PST
Comment on attachment 332614 [details]
Patch

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

> Source/WebKit/ChangeLog:3
> +        Make preserve and restore focus more likely to be symetrical

symetrical => symmetrical

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4173
> +    BOOL shouldDecrement = _focusStateStack[lastIndex];

Nit - if (_focusStateStack.takeLast()) ... would read a bit more nicely here.

We should also bail early before trying to take the last index (with an assertion, perhaps) if the list is empty, to avoid crashing just in case we get an extra call to _restore.
Comment 8 Wenson Hsieh 2018-01-30 08:36:59 PST
Comment on attachment 332614 [details]
Patch

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

> LayoutTests/fast/forms/ios/ipad/select-form-run-twice.html:38
> +        function getSingleTapUIScript(x, y)

It doesn't look like we use this function anywhere.
Comment 9 Megan Gardner 2018-01-30 10:33:48 PST
Created attachment 332667 [details]
Patch
Comment 10 Simon Fraser (smfr) 2018-01-30 11:09:37 PST
Comment on attachment 332667 [details]
Patch

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

> Source/WebKit/ChangeLog:10
> +        Keep a stack of if we actually increment the focusState, so that
> +        changes to the web content do not result in asymmetric decrements to the focus state. 

Is this actually working around a UIKit bug? If so, can we reference that in a comment so we know if we can remove it in future?

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4175
>          --_webView->_activeFocusedStateRetainCount;

This should also assert that _activeFocusedStateRetainCount isn't going to underflow.
Comment 11 Megan Gardner 2018-01-30 11:23:13 PST
Comment on attachment 332667 [details]
Patch

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

>> Source/WebKit/ChangeLog:10
>> +        changes to the web content do not result in asymmetric decrements to the focus state. 
> 
> Is this actually working around a UIKit bug? If so, can we reference that in a comment so we know if we can remove it in future?

It is, but even if they "fix" it, I don't know if we want to removed this, since it's small, and guards against bad behavior.
Comment 12 Megan Gardner 2018-01-30 11:30:10 PST
Created attachment 332675 [details]
Patch
Comment 13 Tim Horton 2018-01-30 13:58:52 PST
Comment on attachment 332675 [details]
Patch

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

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4176
>          --_webView->_activeFocusedStateRetainCount;

Should we not let this go negative?
Comment 14 Megan Gardner 2018-01-30 14:16:35 PST
https://trac.webkit.org/r227855