Skip to content

:focus pseudo class fails to repaint on a shadow host when focus moves from outside the page inside a shadow tree - #2047

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

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

Conversation

@rniwa

@rniwa rniwa commented Jul 4, 2022 •

Copy link
Copy Markdown
Member

e92078a

:focus pseudo class fails to repaint on a shadow host when focus moves from outside the page inside a shadow tree
https://bugs.webkit.org/show_bug.cgi?id=205531

Reviewed by Simon Fraser, Darin Adler and Wenson Hsieh.

The bug was caused by FrameSelection::focusedOrActiveStateChanged only invalidating the style of the focused element.
Invalidate each outer shadow host when the focus status changes to fix the bug.

* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::FrameSelection::focusedOrActiveStateChanged): Fixed the bug.
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h:
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
(WTR::UIScriptControllerCocoa::becomeFirstResponder): Moved to UIScriptControllerIOS.
(WTR::UIScriptControllerCocoa::resignFirstResponder): Ditto.
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h:
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::becomeFirstResponder): Moved from UIScriptControllerCocoa.
(WTR::UIScriptControllerIOS::resignFirstResponder): Ditto.
* Tools/WebKitTestRunner/mac/UIScriptControllerMac.h:
* Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::becomeFirstResponder): Added.
(WTR::UIScriptControllerMac::resignFirstResponder): Added.

* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-expected.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host.html: Added.
* LayoutTests/resources/ui-helper.js:
(window.UIHelper.resignFirstResponder): Added the support for WebKit1.
(window.UIHelper.becomeFirstResponder): Ditto.
* LayoutTests/platform/gtk/TestExpectations: Skip the test as resignFirstResponder is not implemented on GTK+.
* LayoutTests/platform/win/TestExpectations: Ditto on Windows.

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

@rniwa rniwa self-assigned this Jul 4, 2022
@rniwa rniwa added CSS Cascading Style Sheets implementation Safari Technology Preview labels Jul 4, 2022
@rniwa
rniwa requested review from anttijk and smfr July 4, 2022 02:14

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.

Not new, but we’re null checking renderer twice. I suggest:

if (auto* renderer = element->renderer(); renderer && renderer->style().hasEffectiveAppearance())

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.

Sure, fixed.

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.

Would it be better to call containingShadowRoot and null check it rather than checking isInShadowTree and relying on the relationship between these two checks?

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.

Also seems like a helper function for walking up to the containing shadow root's host could make this code a lot easier to read. That idiom must have come up elsewhere.

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.

Oh, actually we have such a function: Node::shadowHost. Will use that instead.

@rniwa
rniwa requested a review from JonWBedard as a code owner July 7, 2022 20:04
@rniwa
rniwa requested review from darinadler and smfr July 7, 2022 20:13
@whsieh
whsieh self-requested a review July 7, 2022 20:14
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 7, 2022
@rniwa rniwa added merge-queue Applied to send a pull request to merge-queue unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged merge-queue Applied to send a pull request to merge-queue labels Jul 8, 2022
@webkit-early-warning-system webkit-early-warning-system added merging-blocked Applied to prevent a change from being merged and removed unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing labels Jul 8, 2022
@rniwa rniwa added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Jul 8, 2022
…s from outside the page inside a shadow tree

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

Reviewed by Simon Fraser, Darin Adler and Wenson Hsieh.

The bug was caused by FrameSelection::focusedOrActiveStateChanged only invalidating the style of the focused element.
Invalidate each outer shadow host when the focus status changes to fix the bug.

* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::FrameSelection::focusedOrActiveStateChanged): Fixed the bug.
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h:
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
(WTR::UIScriptControllerCocoa::becomeFirstResponder): Moved to UIScriptControllerIOS.
(WTR::UIScriptControllerCocoa::resignFirstResponder): Ditto.
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h:
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::becomeFirstResponder): Moved from UIScriptControllerCocoa.
(WTR::UIScriptControllerIOS::resignFirstResponder): Ditto.
* Tools/WebKitTestRunner/mac/UIScriptControllerMac.h:
* Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::becomeFirstResponder): Added.
(WTR::UIScriptControllerMac::resignFirstResponder): Added.

* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host-expected.html: Added.
* LayoutTests/fast/shadow-dom/focus-ring-on-shadow-host.html: Added.
* LayoutTests/resources/ui-helper.js:
(window.UIHelper.resignFirstResponder): Added the support for WebKit1.
(window.UIHelper.becomeFirstResponder): Ditto.
* LayoutTests/platform/gtk/TestExpectations: Skip the test as resignFirstResponder is not implemented on GTK+.
* LayoutTests/platform/win/TestExpectations: Ditto on Windows.

Canonical link: https://commits.webkit.org/252261@main
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 252261@main (e92078a): https://commits.webkit.org/252261@main

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

@webkit-early-warning-system
webkit-early-warning-system merged commit e92078a into WebKit:main Jul 8, 2022
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 8, 2022
Comment on lines 2149 to 2156

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.

I don't think is the right place to do this (and we generally should not need to call invalidateStyleForSubtree at all, ever). There is already a shadow host loop in Element::setFocus. Why does that not cover this case?

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.

The focused element isn't changing here. It's the frame / window gaining or losing the focus.

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.

focus pseudo-class is flipping. We still need to invalidate correctly and preferably efficiently whatever the reason for flipping is.

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’m convinced!

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.

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.

Or this PR: #2259

@rniwa
rniwa deleted the fix205531 branch July 17, 2022 20:42
webkit-commit-queue pushed a commit to kmiller68/WebKit that referenced this pull request Apr 17, 2026
https://bugs.webkit.org/show_bug.cgi?id=312485
rdar://174932570

Reviewed by Yusuke Suzuki.

Use value - trunc(value) == 0.0 for isInteger, which rejects NaN and
Infinity without an explicit isFinite check since NaN - NaN and
Inf - Inf both produce NaN.

Add MacroAssembler::isDoubleInteger helper and use it in the DFG
NumberIsInteger path, removing the manual exponent-bit extraction
branch. Simplify the FTL NumberIsInteger path similarly using B3 IR.

Remove redundant isFinite checks from DFG and FTL NumberIsSafeInteger,
since the range check against maxSafeInteger already rejects Infinity.

On ARM64 the difference in codegen is roughly:

isIntegerOld(double):
        frintz  d1, d0
        fmov    x8, d0
        mov     w9, WebKit#2047
        ubfx    x8, x8, WebKit#52, WebKit#11
        fcmp    d1, d0
        ccmp    x8, x9, WebKit#2, eq
        cset    w0, lo
        ret

isIntegerNew(double):
        frintz  d1, d0
        fsub    d0, d0, d1
        fcmp    d0, #0.0
        cset    w0, eq
        ret

No new tests, no behavior change. Covered by existing tests.

Canonical link: https://commits.webkit.org/311413@main
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.

7 participants