Skip to content

Commit f67e8bf

Browse files
committed
Implement focus fixup rule
https://bugs.webkit.org/show_bug.cgi?id=237273 rdar://89902824 Reviewed by NOBODY (OOPS!). It's currently specced at whatwg/html#8392 as a rendering step after requestAnimationFrame callbacks. * LayoutTests/imported/w3c/web-platform-tests/inert/dynamic-inert-on-focused-element-expected.txt: * Source/WebCore/page/Page.cpp: (WebCore::Page::updateRendering): (WebCore::operator<<): * Source/WebCore/page/Page.h:
1 parent 7df587c commit f67e8bf

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

LayoutTests/imported/w3c/web-platform-tests/inert/dynamic-inert-on-focused-element-expected.txt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11

2-
FAIL <input> that gets 'inert' attribute assert_equals: The element stops being focused expected Element node <body><div id="log"></div>
3-
4-
<div class="test-wrapper" dat... but got Element node <input class="becomes-inert check-focus" inert=""></input>
5-
FAIL <input> whose parent gets 'inert' attribute assert_equals: The element stops being focused expected Element node <body><div id="log"></div>
6-
7-
<div class="test-wrapper" dat... but got Element node <input class="check-focus"></input>
8-
FAIL <button> that gets 'inert' attribute assert_equals: The element stops being focused expected Element node <body><div id="log"></div>
9-
10-
<div class="test-wrapper" dat... but got Element node <button class="becomes-inert check-focus" inert="">foo</b...
11-
FAIL <div> that gets 'inert' attribute assert_equals: The element stops being focused expected Element node <body><div id="log"></div>
12-
13-
<div class="test-wrapper" dat... but got Element node <div class="becomes-inert check-focus" tabindex="-1" iner...
14-
FAIL <div> whose parent gets 'inert' attribute assert_equals: The element stops being focused expected Element node <body><div id="log"></div>
15-
16-
<div class="test-wrapper" dat... but got Element node <div class="check-focus" tabindex="-1">bar</div>
17-
FAIL <div> whose grandparent gets 'inert' attribute assert_equals: The element stops being focused expected Element node <body><div id="log"></div>
18-
19-
<div class="test-wrapper" dat... but got Element node <span class="check-focus" tabindex="-1">baz</span>
2+
PASS <input> that gets 'inert' attribute
3+
PASS <input> whose parent gets 'inert' attribute
4+
PASS <button> that gets 'inert' attribute
5+
PASS <div> that gets 'inert' attribute
6+
PASS <div> whose parent gets 'inert' attribute
7+
PASS <div> whose grandparent gets 'inert' attribute
208

219

2210
foo

Source/WebCore/page/Page.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "Editing.h"
6060
#include "Editor.h"
6161
#include "EditorClient.h"
62+
#include "ElementRareData.h"
6263
#include "EmptyClients.h"
6364
#include "Event.h"
6465
#include "EventHandler.h"
@@ -138,6 +139,7 @@
138139
#include "ScrollingCoordinator.h"
139140
#include "ServiceWorkerGlobalScope.h"
140141
#include "Settings.h"
142+
#include "ShadowRoot.h"
141143
#include "SharedBuffer.h"
142144
#include "SocketProvider.h"
143145
#include "SpeechRecognitionProvider.h"
@@ -1730,6 +1732,15 @@ void Page::updateRendering()
17301732
document.serviceRequestAnimationFrameCallbacks();
17311733
});
17321734

1735+
runProcessingStep(RenderingUpdateStep::FocusFixupRule, [] (Document& document) {
1736+
if (auto* activeElement = document.activeElement()) {
1737+
if (auto* root = activeElement->shadowRoot(); root && root->activeElement())
1738+
activeElement = root->activeElement();
1739+
if (!activeElement->isFocusable())
1740+
document.setFocusedElement(nullptr);
1741+
}
1742+
});
1743+
17331744
layoutIfNeeded();
17341745

17351746
runProcessingStep(RenderingUpdateStep::ResizeObservations, [&] (Document& document) {
@@ -3930,6 +3941,7 @@ WTF::TextStream& operator<<(WTF::TextStream& ts, RenderingUpdateStep step)
39303941
#endif
39313942
case RenderingUpdateStep::VideoFrameCallbacks: ts << "VideoFrameCallbacks"; break;
39323943
case RenderingUpdateStep::PrepareCanvasesForDisplay: ts << "PrepareCanvasesForDisplay"; break;
3944+
case RenderingUpdateStep::FocusFixupRule: ts << "FocusFixupRule"; break;
39333945
}
39343946
return ts;
39353947
}

Source/WebCore/page/Page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ enum class RenderingUpdateStep : uint32_t {
233233
FlushAutofocusCandidates = 1 << 14,
234234
VideoFrameCallbacks = 1 << 15,
235235
PrepareCanvasesForDisplay = 1 << 16,
236+
FocusFixupRule = 1 << 17,
236237
};
237238

238239
constexpr OptionSet<RenderingUpdateStep> updateRenderingSteps = {

0 commit comments

Comments
 (0)