Skip to content

:focus-within pseudo class doesn't get invalidated when frame loses focus - #2259

Merged
webkit-early-warning-system merged 1 commit into
WebKit:mainfrom
rniwa:fix242526
Jul 10, 2022
Merged

webkit-early-warning-system merged 1 commit into
WebKit:mainfrom
rniwa:fix242526

Conversation

@rniwa

@rniwa rniwa commented Jul 9, 2022 •

Copy link
Copy Markdown
Member

ac8282f

:focus-within pseudo class doesn't get invalidated when frame loses focus
https://bugs.webkit.org/show_bug.cgi?id=242526

Reviewed by Antti Koivisto and Darin Adler.

This patch fixes the bug that :focus-within pseudo fails to start applying or stop applying upon frame
gaining or losing focus, and makes pseudo class invalidation more precise.

A new boolean flag FrameSelection::m_isActive, which mirrors the value of FocusController::isActive()
while the frame associated with FrameSelection is focused, is introduced and used in FrameSelection's
isFocusedAndActive on behalf of FocusController::isActive(). It's used to compute the value of :focus,
:focus-visible, :focus-within and pseudo classes. Most notably, FrameSelection::pageActivationChanged
and FrameSelection::setFocused use it to flip the flag with Style::PseudoClassChangeInvalidation.

Note that the value of FrameSelection::m_isActive could be stale when the frame associated with
FrameSelection is no longer focused. This isn't an issue in practice since it means isFocusedAndActive
would always return false in such cases (since m_focused check fails).

* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-focuswithin-expected.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-focuswithin.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-sibling-expected.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-sibling.html: Added.
* LayoutTests/platform/gtk/TestExpectations:
* LayoutTests/platform/win/TestExpectations:
* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const): Fixed a bug that this was checking hasFocusWithin
without isFrameFocused.
* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::isPageActive): Added.
(WebCore::FrameSelection::FrameSelection): Initialize newly introduced m_isActive.
(WebCore::FrameSelection::focusedOrActiveStateChanged): Moved the logic to invalidate elements to
callers of this function: FrameSelection::pageActivationChanged and FrameSelection::setFocused.
(WebCore::invalidateFocusedElementAndShadowIncludingAncestors): Added.
(WebCore::FrameSelection::pageActivationChanged):
(WebCore::FrameSelection::setFocused):
(WebCore::FrameSelection::isFocusedAndActive const):
* Source/WebCore/editing/FrameSelection.h:

Canonical link: https://commits.webkit.org/252324@main

@rniwa rniwa self-assigned this Jul 9, 2022
@rniwa rniwa added CSS Cascading Style Sheets implementation WebKit Nightly Build labels Jul 9, 2022
@rniwa
rniwa requested a review from anttijk July 9, 2022 08:02
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 9, 2022

@darinadler darinadler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is excellent and correct now; of course, @anttijk should still look it over, since he’s the one who spotted it was wrong last time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a function that’s shared for this expression? I know this is not a lot of code, but I think it would be nice to have a named function to emphasize that it’s the same all three times.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added isPageActive.

@anttijk anttijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@darinadler

Copy link
Copy Markdown
Member

Have to figure out what’s causing the test failures.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I need to update the flags even when focused element is nullptr here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@rniwa rniwa removed the merging-blocked Applied to prevent a change from being merged label Jul 9, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 9, 2022
@rniwa rniwa removed the merging-blocked Applied to prevent a change from being merged label Jul 9, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@rniwa rniwa removed the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@rniwa rniwa removed the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@rniwa rniwa removed the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@rniwa rniwa removed the merging-blocked Applied to prevent a change from being merged label Jul 10, 2022
@rniwa

rniwa commented Jul 10, 2022

Copy link
Copy Markdown
Member Author

Sigh... EWS test failures are nothing to do with this patch. Not sure why it thinks this patch caused it.

@rniwa rniwa added the merge-queue Applied to send a pull request to merge-queue label Jul 10, 2022
…ocus

https://bugs.webkit.org/show_bug.cgi?id=242526

Reviewed by Antti Koivisto and Darin Adler.

This patch fixes the bug that :focus-within pseudo fails to start applying or stop applying upon frame
gaining or losing focus, and makes pseudo class invalidation more precise.

A new boolean flag FrameSelection::m_isActive, which mirrors the value of FocusController::isActive()
while the frame associated with FrameSelection is focused, is introduced and used in FrameSelection's
isFocusedAndActive on behalf of FocusController::isActive(). It's used to compute the value of :focus,
:focus-visible, :focus-within and pseudo classes. Most notably, FrameSelection::pageActivationChanged
and FrameSelection::setFocused use it to flip the flag with Style::PseudoClassChangeInvalidation.

Note that the value of FrameSelection::m_isActive could be stale when the frame associated with
FrameSelection is no longer focused. This isn't an issue in practice since it means isFocusedAndActive
would always return false in such cases (since m_focused check fails).

* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-focuswithin-expected.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-focuswithin.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-sibling-expected.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-sibling.html: Added.
* LayoutTests/platform/gtk/TestExpectations:
* LayoutTests/platform/win/TestExpectations:
* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const): Fixed a bug that this was checking hasFocusWithin
without isFrameFocused.
* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::isPageActive): Added.
(WebCore::FrameSelection::FrameSelection): Initialize newly introduced m_isActive.
(WebCore::FrameSelection::focusedOrActiveStateChanged): Moved the logic to invalidate elements to
callers of this function: FrameSelection::pageActivationChanged and FrameSelection::setFocused.
(WebCore::invalidateFocusedElementAndShadowIncludingAncestors): Added.
(WebCore::FrameSelection::pageActivationChanged):
(WebCore::FrameSelection::setFocused):
(WebCore::FrameSelection::isFocusedAndActive const):
* Source/WebCore/editing/FrameSelection.h:

Canonical link: https://commits.webkit.org/252324@main
@webkit-early-warning-system
webkit-early-warning-system merged commit ac8282f into WebKit:main Jul 10, 2022
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 252324@main (ac8282f): https://commits.webkit.org/252324@main

Reviewed commits have been landed. Closing PR #2259 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jul 10, 2022
@rniwa
rniwa deleted the fix242526 branch July 17, 2022 20:41
clopez added a commit to clopez/WebKit that referenced this pull request Feb 12, 2026
Conflicts:
	Source/WebCore/loader/FrameLoader.cpp
	Source/WebCore/page/LocalFrame.cpp
	Source/WebCore/page/LocalFrame.h
	Source/WebKit/SourcesGTK.txt
	Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
	Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp
	Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp
	Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h
	Source/WebKit/UIProcess/WebFrameProxy.cpp
	Source/WebKit/UIProcess/WebPageProxy.cpp
	Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp
	Source/WebKit/UIProcess/mac/PageClientImplMac.mm
	Source/WebKit/WebKit.xcodeproj/project.pbxproj
clopez added a commit to clopez/WebKit that referenced this pull request Feb 12, 2026
Conflicts:
	Source/WebCore/loader/FrameLoader.cpp
	Source/WebCore/page/LocalFrame.cpp
	Source/WebCore/page/LocalFrame.h
	Source/WebKit/SourcesGTK.txt
	Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
	Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp
	Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp
	Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h
	Source/WebKit/UIProcess/WebFrameProxy.cpp
	Source/WebKit/UIProcess/WebPageProxy.cpp
	Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp
	Source/WebKit/UIProcess/mac/PageClientImplMac.mm
	Source/WebKit/WebKit.xcodeproj/project.pbxproj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CSS Cascading Style Sheets implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants