Bug 170899

Summary: [selectors4] :focus-within should use the flat tree
Product: WebKit Reporter: Manuel Rego Casasnovas <rego>
Component: CSSAssignee: Manuel Rego Casasnovas <rego>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, buildbot, cdumez, cmarcelo, commit-queue, dbates, esprehn+autocc, jfernandez, kangil.han, koivisto, rniwa
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 170898    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Archive of layout-test-results from ews114 for mac-elcapitan
none
Use parentElementInComposedTree() none

Description Manuel Rego Casasnovas 2017-04-17 01:26:51 PDT
As discussed in this issue of the CSS WG, ":focus-within" should use the flat tree:
https://github.com/w3c/csswg-drafts/issues/1135

The spec has been updated and now the prose is very clear about this (https://drafts.csswg.org/selectors-4/#the-focus-within-pseudo):
"An element also matches :focus-within if one of its descendants in the flat tree
 (including non-element nodes, such as text nodes) matches the conditions for matching :focus."

Current implementation doesn't follow that, so the following test case fails:
https://github.com/w3c/web-platform-tests/blob/master/css/selectors4/focus-within-shadow-006.html
Comment 1 Manuel Rego Casasnovas 2017-04-17 01:52:44 PDT
Created attachment 307263 [details]
Patch
Comment 2 Manuel Rego Casasnovas 2017-04-18 02:51:06 PDT
Created attachment 307364 [details]
Patch

Now that the tests have been imported (bug #170898) this should be ready for review.
Comment 3 Build Bot 2017-04-18 03:47:28 PDT
Comment on attachment 307364 [details]
Patch

Attachment 307364 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/3556452

Number of test failures exceeded the failure limit.
Comment 4 Build Bot 2017-04-18 03:47:29 PDT
Created attachment 307368 [details]
Archive of layout-test-results from ews114 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 5 Javier Fernandez 2017-04-24 04:34:14 PDT
Comment on attachment 307364 [details]
Patch

The change still makes the bot to fail.
Comment 6 Javier Fernandez 2017-04-24 04:36:44 PDT
Comment on attachment 307364 [details]
Patch

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

> Source/WebCore/dom/Element.cpp:614
> +    for (Element* element = this; element; element = downcast<Element>(element->parentInComposedTree()))

Isn't parentElementInComposedTree what we should use here ?
Comment 7 Antti Koivisto 2017-04-24 04:40:47 PDT
Comment on attachment 307364 [details]
Patch

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

>> Source/WebCore/dom/Element.cpp:614
>> +    for (Element* element = this; element; element = downcast<Element>(element->parentInComposedTree()))
> 
> Isn't parentElementInComposedTree what we should use here ?

Yeah, the cast is not safe. parentInComposedTree can return ShadowRoot which is not Element.
Comment 8 Antti Koivisto 2017-04-24 04:43:01 PDT
Sorry, it can't return ShadowRoot but it can return Document (and maybe DocumentFragment).
Comment 9 Manuel Rego Casasnovas 2017-04-24 07:12:14 PDT
Created attachment 307971 [details]
Use parentElementInComposedTree()
Comment 10 Manuel Rego Casasnovas 2017-04-24 08:21:17 PDT
Thanks for the reviews!

Sorry for the Debug EWS error in the previous version, I thought it was unrelated but probably I got confused with a different patch and not this one.

It seems using parentElementInComposedTree() as suggested has solved the problem.
Comment 11 WebKit Commit Bot 2017-04-24 21:58:59 PDT
Comment on attachment 307971 [details]
Use parentElementInComposedTree()

Clearing flags on attachment: 307971

Committed r215719: <http://trac.webkit.org/changeset/215719>
Comment 12 WebKit Commit Bot 2017-04-24 21:59:01 PDT
All reviewed patches have been landed.  Closing bug.