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
Created attachment 307263 [details] Patch
Created attachment 307364 [details] Patch Now that the tests have been imported (bug #170898) this should be ready for review.
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.
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 on attachment 307364 [details] Patch The change still makes the bot to fail.
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 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.
Sorry, it can't return ShadowRoot but it can return Document (and maybe DocumentFragment).
Created attachment 307971 [details] Use parentElementInComposedTree()
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 on attachment 307971 [details] Use parentElementInComposedTree() Clearing flags on attachment: 307971 Committed r215719: <http://trac.webkit.org/changeset/215719>
All reviewed patches have been landed. Closing bug.