Title: [274812] trunk
Revision
274812
Author
[email protected]
Date
2021-03-22 15:29:52 -0700 (Mon, 22 Mar 2021)

Log Message

Enable ability to prevent scrolling in Element.focus()
https://bugs.webkit.org/show_bug.cgi?id=178583

Patch by Rob Buis <[email protected]> on 2021-03-22
Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Update improved test result.

* web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements-expected.txt: Added.
* web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html: Added.
* web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt:

Source/WebCore:

Add FocusOptions parameter to the focus method [1] both
to the IDL as the C++ side. Change Element.focus to not
scroll if FocusOptions.preventScroll is true.

Behavior matches Chrome and Firefox.

Tests: imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea.html
       imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html

Test: imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* dom/Element.cpp:
(WebCore::Element::focus):
* dom/Element.h:
(WebCore::Element::focus):
* dom/FocusOptions.h: Copied from Source/WebCore/html/HTMLOrForeignElement.idl.
* dom/FocusOptions.idl: Copied from Source/WebCore/html/HTMLOrForeignElement.idl.
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::didAttachRenderers):
* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::focus):
* html/HTMLLabelElement.h:
* html/HTMLLegendElement.cpp:
(WebCore::HTMLLegendElement::focus):
* html/HTMLLegendElement.h:
* html/HTMLOrForeignElement.idl:
* html/InputType.cpp:
(WebCore::InputType::accessKeyAction):
* page/FocusController.cpp:
(WebCore::FocusController::advanceFocusInDocumentOrder):
(WebCore::FocusController::advanceFocusDirectionallyInContainer):

LayoutTests:

The test preventScroll-textarea.html now passes on all platforms.

* platform/ios-wk2/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Removed.
* platform/mac-wk1/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Removed.

Modified Paths

Added Paths

Removed Paths

  • trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/
  • trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/

Diff

Modified: trunk/LayoutTests/ChangeLog (274811 => 274812)


--- trunk/LayoutTests/ChangeLog	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/LayoutTests/ChangeLog	2021-03-22 22:29:52 UTC (rev 274812)
@@ -1,3 +1,15 @@
+2021-03-22  Rob Buis  <[email protected]>
+
+        Enable ability to prevent scrolling in Element.focus()
+        https://bugs.webkit.org/show_bug.cgi?id=178583
+
+        Reviewed by Simon Fraser.
+
+        The test preventScroll-textarea.html now passes on all platforms.
+
+        * platform/ios-wk2/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Removed.
+        * platform/mac-wk1/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Removed.
+
 2021-03-22  Devin Rousso  <[email protected]>
 
         Remove unused JS and CSS files of media controls

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (274811 => 274812)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-22 22:29:52 UTC (rev 274812)
@@ -1,3 +1,16 @@
+2021-03-22  Rob Buis  <[email protected]>
+
+        Enable ability to prevent scrolling in Element.focus()
+        https://bugs.webkit.org/show_bug.cgi?id=178583
+
+        Reviewed by Simon Fraser.
+
+        Update improved test result.
+
+        * web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements-expected.txt: Added.
+        * web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html: Added.
+        * web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt:
+
 2021-03-22  Chris Dumez  <[email protected]>
 
         imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/nan-param.html is failing

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements-expected.txt (0 => 274812)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements-expected.txt	2021-03-22 22:29:52 UTC (rev 274812)
@@ -0,0 +1,12 @@
+1_1
+1_2
+1_3
+2_1
+2_2
+2_3
+3_1
+3_2
+3_3
+
+PASS focus(options) - preventScroll on nested scroll elements
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html (0 => 274812)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html	2021-03-22 22:29:52 UTC (rev 274812)
@@ -0,0 +1,62 @@
+<!doctype html>
+<title>focus(options) - preventScroll on nested scroll elements</title>
+<script src=""
+<script src=""
+<style>
+  .scrollBox { width: 400px; height: 300px; border: 1px solid }
+  .bigbox { width: 380px; height: 300px; border: 1px solid }
+  .box { width: 380px; height: 150px; border: 1px solid }
+</style>
+<div class="scrollBox" style="overflow-y: scroll;">
+  <div class="bigbox" id="1" style="overflow-y: scroll;" tabindex=1>
+    <div class="box" id="1_1" tabindex=1>1_1</div>
+    <div class="box" id="1_2" tabindex=1>1_2</div>
+    <div class="box" id="1_3" tabindex=1>1_3</div>
+  </div>
+  <div class="bigbox" id="2" style="overflow-y: scroll;" tabindex=1>
+    <div class="box" id="2_1" tabindex=1>2_1</div>
+    <div class="box" id="2_2" tabindex=1>2_2</div>
+    <div class="box" id="2_3" tabindex=1>2_3</div>
+  </div>
+  <div class="bigbox" id="3" style="overflow-y: scroll;" tabindex=1>
+    <div class="box" id="3_1" tabindex=1>3_1</div>
+    <div class="box" id="3_2" tabindex=1>3_2</div>
+    <div class="box" id="3_3" tabindex=1>3_3</div>
+  </div>
+</div>
+<script>
+promise_test(async function(t) {
+  await new Promise(resolve => window.addEventListener("load", resolve));
+  let div2_2 = document.getElementById("2_2");
+  div2_2.focus({ preventScroll: true });
+
+  await new Promise(resolve => {
+    requestAnimationFrame(() => requestAnimationFrame(resolve));
+  });
+
+  assert_equals(document.activeElement, div2_2, `box 2_2: should have been focused`);
+  assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled");
+  assert_equals(div2_2.parentNode.scrollTop, 0, "box 2_2: should not have scrolled ancestor");
+
+  // Reset focus
+  let div1_1 = document.getElementById("1_1");
+  div1_1.focus();
+
+  await new Promise(resolve => {
+    requestAnimationFrame(() => requestAnimationFrame(resolve));
+  });
+  assert_equals(document.activeElement, div1_1, `box 1_1: should have been focused`);
+
+  let div2 = document.getElementById("2");
+  div2.focus({ preventScroll: true });
+
+  await new Promise(resolve => {
+    requestAnimationFrame(() => requestAnimationFrame(resolve));
+  });
+
+  assert_equals(document.activeElement, div2, `box 2: should have been focused`);
+  assert_equals(div2.scrollTop, 0, "box 2: should not have scrolled");
+  assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled");
+  assert_equals(div2.parentNode.scrollTop, 0, "box 2: should not have scrolled ancestor");
+});
+</script>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt (274811 => 274812)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt	2021-03-22 22:29:52 UTC (rev 274812)
@@ -1,4 +1,4 @@
 
 
-FAIL preventScroll: true on a textarea element assert_equals: TEXTAREA: Should not have scrolled after a couple event loop ticks expected 0 but got 920
+PASS preventScroll: true on a textarea element
 

Modified: trunk/Source/WebCore/CMakeLists.txt (274811 => 274812)


--- trunk/Source/WebCore/CMakeLists.txt	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/CMakeLists.txt	2021-03-22 22:29:52 UTC (rev 274812)
@@ -848,6 +848,7 @@
     dom/EventModifierInit.idl
     dom/EventTarget.idl
     dom/FocusEvent.idl
+    dom/FocusOptions.idl
     dom/GlobalEventHandlers+PointerEvents.idl
     dom/GlobalEventHandlers+Selection.idl
     dom/GlobalEventHandlers.idl

Modified: trunk/Source/WebCore/ChangeLog (274811 => 274812)


--- trunk/Source/WebCore/ChangeLog	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/ChangeLog	2021-03-22 22:29:52 UTC (rev 274812)
@@ -1,3 +1,49 @@
+2021-03-22  Rob Buis  <[email protected]>
+
+        Enable ability to prevent scrolling in Element.focus()
+        https://bugs.webkit.org/show_bug.cgi?id=178583
+
+        Reviewed by Simon Fraser.
+
+        Add FocusOptions parameter to the focus method [1] both
+        to the IDL as the C++ side. Change Element.focus to not
+        scroll if FocusOptions.preventScroll is true.
+
+        Behavior matches Chrome and Firefox.
+
+        Tests: imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea.html
+               imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html
+
+        Test: imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/Element.cpp:
+        (WebCore::Element::focus):
+        * dom/Element.h:
+        (WebCore::Element::focus):
+        * dom/FocusOptions.h: Copied from Source/WebCore/html/HTMLOrForeignElement.idl.
+        * dom/FocusOptions.idl: Copied from Source/WebCore/html/HTMLOrForeignElement.idl.
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::didAttachRenderers):
+        * html/HTMLLabelElement.cpp:
+        (WebCore::HTMLLabelElement::focus):
+        * html/HTMLLabelElement.h:
+        * html/HTMLLegendElement.cpp:
+        (WebCore::HTMLLegendElement::focus):
+        * html/HTMLLegendElement.h:
+        * html/HTMLOrForeignElement.idl:
+        * html/InputType.cpp:
+        (WebCore::InputType::accessKeyAction):
+        * page/FocusController.cpp:
+        (WebCore::FocusController::advanceFocusInDocumentOrder):
+        (WebCore::FocusController::advanceFocusDirectionallyInContainer):
+
 2021-03-22  Devin Rousso  <[email protected]>
 
         Remove unused JS and CSS files of media controls

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (274811 => 274812)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2021-03-22 22:29:52 UTC (rev 274812)
@@ -855,6 +855,7 @@
 $(PROJECT_DIR)/dom/EventTarget.idl
 $(PROJECT_DIR)/dom/EventTargetFactory.in
 $(PROJECT_DIR)/dom/FocusEvent.idl
+$(PROJECT_DIR)/dom/FocusOptions.idl
 $(PROJECT_DIR)/dom/GlobalEventHandlers+PointerEvents.idl
 $(PROJECT_DIR)/dom/GlobalEventHandlers+Selection.idl
 $(PROJECT_DIR)/dom/GlobalEventHandlers.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (274811 => 274812)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2021-03-22 22:29:52 UTC (rev 274812)
@@ -830,6 +830,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFillMode.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFocusEvent.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFocusEvent.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFocusOptions.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFocusOptions.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFontFace.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFontFace.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFontFaceSet.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (274811 => 274812)


--- trunk/Source/WebCore/DerivedSources.make	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/DerivedSources.make	2021-03-22 22:29:52 UTC (rev 274812)
@@ -727,6 +727,7 @@
     $(WebCore)/dom/EventModifierInit.idl \
     $(WebCore)/dom/EventTarget.idl \
     $(WebCore)/dom/FocusEvent.idl \
+    $(WebCore)/dom/FocusOptions.idl \
     $(WebCore)/dom/GlobalEventHandlers+PointerEvents.idl \
     $(WebCore)/dom/GlobalEventHandlers+Selection.idl \
     $(WebCore)/dom/GlobalEventHandlers.idl \

Modified: trunk/Source/WebCore/Headers.cmake (274811 => 274812)


--- trunk/Source/WebCore/Headers.cmake	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/Headers.cmake	2021-03-22 22:29:52 UTC (rev 274812)
@@ -467,6 +467,7 @@
     dom/ExceptionCode.h
     dom/ExceptionData.h
     dom/ExceptionOr.h
+    dom/FocusOptions.h
     dom/FragmentScriptingPermission.h
     dom/FullscreenManager.h
     dom/GCReachableRef.h

Modified: trunk/Source/WebCore/Sources.txt (274811 => 274812)


--- trunk/Source/WebCore/Sources.txt	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/Sources.txt	2021-03-22 22:29:52 UTC (rev 274812)
@@ -3024,6 +3024,7 @@
 JSFileSystemFileEntry.cpp
 JSFillMode.cpp
 JSFocusEvent.cpp
+JSFocusOptions.cpp
 JSFontFace.cpp
 JSFontFaceSet.cpp
 JSGPUBindGroupLayoutBinding.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (274811 => 274812)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-22 22:29:52 UTC (rev 274812)
@@ -3607,6 +3607,7 @@
 		AA7FEEAD16A4E74B004C0C33 /* JSSpeechSynthesis.h in Headers */ = {isa = PBXBuildFile; fileRef = AA7FEEAC16A4E74B004C0C33 /* JSSpeechSynthesis.h */; };
 		AAA728F716D1D8BC00D3BBC6 /* WebAccessibilityObjectWrapperIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = AAA728F116D1D8BC00D3BBC6 /* WebAccessibilityObjectWrapperIOS.h */; };
 		AAC08CF315F941FD00F1E188 /* AccessibilitySVGRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = AAC08CF115F941FC00F1E188 /* AccessibilitySVGRoot.h */; };
+		AADEFE4525AF4FD60040DD67 /* FocusOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = AADEFE4325AF4FCB0040DD67 /* FocusOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		AB23A32809BBA7D00067CC53 /* BeforeTextInsertedEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = AB23A32609BBA7D00067CC53 /* BeforeTextInsertedEvent.h */; };
 		AB247A6D0AFD6383003FA5FD /* RenderSlider.h in Headers */ = {isa = PBXBuildFile; fileRef = AB247A6B0AFD6383003FA5FD /* RenderSlider.h */; };
 		AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AB31C91D10AE1B8E000C7B92 /* LineClampValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -13173,6 +13174,7 @@
 		AA2A5AC616A485D500975A25 /* SpeechSynthesisVoice.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SpeechSynthesisVoice.cpp; sourceTree = "<group>"; };
 		AA2A5AC716A485D500975A25 /* SpeechSynthesisVoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpeechSynthesisVoice.h; sourceTree = "<group>"; };
 		AA2A5AC816A485D500975A25 /* SpeechSynthesisVoice.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = SpeechSynthesisVoice.idl; sourceTree = "<group>"; };
+		AA2E0D0925AF5104007693BA /* FocusOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = FocusOptions.idl; sourceTree = "<group>"; };
 		AA478A7D16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAccessibilityObjectWrapperMac.h; sourceTree = "<group>"; };
 		AA478A7E16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebAccessibilityObjectWrapperMac.mm; sourceTree = "<group>"; };
 		AA4C3A740B2B1679002334A2 /* InlineStyleSheetOwner.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InlineStyleSheetOwner.cpp; sourceTree = "<group>"; };
@@ -13197,6 +13199,7 @@
 		AACC83D82316576B00EB6BF5 /* JSHTMLOrForeignElement.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLOrForeignElement.cpp; sourceTree = "<group>"; };
 		AAD9D0B121DFA80C001B11C7 /* LazyLoadImageObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LazyLoadImageObserver.cpp; sourceTree = "<group>"; };
 		AAD9D0B321DFA80E001B11C7 /* LazyLoadImageObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LazyLoadImageObserver.h; sourceTree = "<group>"; };
+		AADEFE4325AF4FCB0040DD67 /* FocusOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FocusOptions.h; sourceTree = "<group>"; };
 		AAE27B7416CBFC0D00623043 /* PlatformSpeechSynthesizerMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformSpeechSynthesizerMock.cpp; sourceTree = "<group>"; };
 		AAE27B7516CBFC0D00623043 /* PlatformSpeechSynthesizerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformSpeechSynthesizerMock.h; sourceTree = "<group>"; };
 		AAE3755D17429BCC006200C2 /* PlatformSpeechSynthesizerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformSpeechSynthesizerIOS.mm; sourceTree = "<group>"; };
@@ -30329,6 +30332,8 @@
 				B6D9D23414EABD260090D75E /* FocusEvent.cpp */,
 				B6D9D23314EABD260090D75E /* FocusEvent.h */,
 				B6D9D27214EABF030090D75E /* FocusEvent.idl */,
+				AADEFE4325AF4FCB0040DD67 /* FocusOptions.h */,
+				AA2E0D0925AF5104007693BA /* FocusOptions.idl */,
 				A853123C11D0471B00D4D077 /* FragmentScriptingPermission.h */,
 				CD92F5172261038200F87BB3 /* FullscreenManager.cpp */,
 				CD92F5162261038200F87BB3 /* FullscreenManager.h */,
@@ -32317,6 +32322,7 @@
 				14993BE60B2F2B1C0050497F /* FocusController.h in Headers */,
 				062287840B4DB322000C34DF /* FocusDirection.h in Headers */,
 				B6D9D23514EABD260090D75E /* FocusEvent.h in Headers */,
+				AADEFE4525AF4FD60040DD67 /* FocusOptions.h in Headers */,
 				B2C3DA650D006CD600EF6F26 /* Font.h in Headers */,
 				1AC2D89D1B1E291F00D52E87 /* FontAntialiasingStateSaver.h in Headers */,
 				F4E57EDC213F3F5F004EA98E /* FontAttributeChanges.h in Headers */,

Modified: trunk/Source/WebCore/dom/Element.cpp (274811 => 274812)


--- trunk/Source/WebCore/dom/Element.cpp	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/dom/Element.cpp	2021-03-22 22:29:52 UTC (rev 274812)
@@ -3040,7 +3040,7 @@
     return nullptr;
 }
 
-void Element::focus(SelectionRestorationMode restorationMode, FocusDirection direction)
+void Element::focus(const FocusOptions& options)
 {
     if (!isConnected())
         return;
@@ -3084,11 +3084,12 @@
         // Focus and change event handlers can cause us to lose our last ref.
         // If a focus event handler changes the focus to a different node it
         // does not make sense to continue and update appearence.
-        if (!page->focusController().setFocusedElement(newTarget.get(), *document->frame(), direction))
+        if (!page->focusController().setFocusedElement(newTarget.get(), *document->frame(), options.direction))
             return;
     }
 
-    newTarget->revealFocusedElement(restorationMode);
+    if (!options.preventScroll)
+        newTarget->revealFocusedElement(options.selectionRestorationMode);
 }
 
 void Element::revealFocusedElement(SelectionRestorationMode selectionMode)

Modified: trunk/Source/WebCore/dom/Element.h (274811 => 274812)


--- trunk/Source/WebCore/dom/Element.h	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/dom/Element.h	2021-03-22 22:29:52 UTC (rev 274812)
@@ -27,6 +27,7 @@
 #include "AXTextStateChangeIntent.h"
 #include "Document.h"
 #include "ElementData.h"
+#include "FocusOptions.h"
 #include "HTMLNames.h"
 #include "ScrollTypes.h"
 #include "ShadowRootInit.h"
@@ -401,7 +402,7 @@
     virtual String target() const { return String(); }
 
     static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); }
-    virtual void focus(SelectionRestorationMode = SelectionRestorationMode::RestoreOrSelectAll, FocusDirection = FocusDirection::None);
+    virtual void focus(const FocusOptions& = { });
     void revealFocusedElement(SelectionRestorationMode);
     virtual RefPtr<Element> focusAppearanceUpdateTarget();
     virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal);

Copied: trunk/Source/WebCore/dom/FocusOptions.h (from rev 274810, trunk/Source/WebCore/html/HTMLOrForeignElement.idl) (0 => 274812)


--- trunk/Source/WebCore/dom/FocusOptions.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/FocusOptions.h	2021-03-22 22:29:52 UTC (rev 274812)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FocusDirection.h"
+
+namespace WebCore {
+
+struct FocusOptions {
+    SelectionRestorationMode selectionRestorationMode { SelectionRestorationMode::RestoreOrSelectAll };
+    FocusDirection direction { FocusDirection::None };
+    bool preventScroll { false };
+};
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/dom/FocusOptions.idl (from rev 274810, trunk/Source/WebCore/html/HTMLOrForeignElement.idl) (0 => 274812)


--- trunk/Source/WebCore/dom/FocusOptions.idl	                        (rev 0)
+++ trunk/Source/WebCore/dom/FocusOptions.idl	2021-03-22 22:29:52 UTC (rev 274812)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2020 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+dictionary FocusOptions {
+   boolean preventScroll = false;
+};

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (274811 => 274812)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2021-03-22 22:29:52 UTC (rev 274812)
@@ -254,11 +254,11 @@
         auto frameView = makeRefPtr(document().view());
         if (frameView && frameView->layoutContext().isInLayout()) {
             frameView->queuePostLayoutCallback([element] {
-                element->focus(SelectionRestorationMode::PlaceCaretAtStart);
+                element->focus({ SelectionRestorationMode::PlaceCaretAtStart });
             });
         } else {
             Style::queuePostResolutionCallback([element] {
-                element->focus(SelectionRestorationMode::PlaceCaretAtStart);
+                element->focus({ SelectionRestorationMode::PlaceCaretAtStart });
             });
         }
     }

Modified: trunk/Source/WebCore/html/HTMLLabelElement.cpp (274811 => 274812)


--- trunk/Source/WebCore/html/HTMLLabelElement.cpp	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/HTMLLabelElement.cpp	2021-03-22 22:29:52 UTC (rev 274812)
@@ -172,7 +172,7 @@
     return (element && element->willRespondToMouseClickEvents()) || HTMLElement::willRespondToMouseClickEvents();
 }
 
-void HTMLLabelElement::focus(SelectionRestorationMode restorationMode, FocusDirection direction)
+void HTMLLabelElement::focus(const FocusOptions& options)
 {
     Ref<HTMLLabelElement> protectedThis(*this);
     if (document().haveStylesheetsLoaded()) {
@@ -179,7 +179,7 @@
         document().updateLayout();
         if (isFocusable()) {
             // The value of restorationMode is not used for label elements as it doesn't override updateFocusAppearance.
-            Element::focus(restorationMode, direction);
+            Element::focus(options);
             return;
         }
     }
@@ -186,7 +186,7 @@
 
     // To match other browsers, always restore previous selection.
     if (auto element = control())
-        element->focus(SelectionRestorationMode::RestoreOrSelectAll, direction);
+        element->focus({ SelectionRestorationMode::RestoreOrSelectAll, options.direction });
 }
 
 bool HTMLLabelElement::accessKeyAction(bool sendMouseEvents)

Modified: trunk/Source/WebCore/html/HTMLLabelElement.h (274811 => 274812)


--- trunk/Source/WebCore/html/HTMLLabelElement.h	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/HTMLLabelElement.h	2021-03-22 22:29:52 UTC (rev 274812)
@@ -51,7 +51,7 @@
     // Overridden to either click() or focus() the corresponding control.
     void defaultEventHandler(Event&) final;
 
-    void focus(SelectionRestorationMode, FocusDirection) final;
+    void focus(const FocusOptions&) final;
 
     bool isInteractiveContent() const final { return true; }
 };

Modified: trunk/Source/WebCore/html/HTMLLegendElement.cpp (274811 => 274812)


--- trunk/Source/WebCore/html/HTMLLegendElement.cpp	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/HTMLLegendElement.cpp	2021-03-22 22:29:52 UTC (rev 274812)
@@ -57,12 +57,12 @@
     return descendantsOfType<HTMLFormControlElement>(*enclosingFieldset).first();
 }
 
-void HTMLLegendElement::focus(SelectionRestorationMode restorationMode, FocusDirection direction)
+void HTMLLegendElement::focus(const FocusOptions& options)
 {
     if (document().haveStylesheetsLoaded()) {
         document().updateLayoutIgnorePendingStylesheets();
         if (isFocusable()) {
-            Element::focus(restorationMode, direction);
+            Element::focus({ options.selectionRestorationMode, options.direction });
             return;
         }
     }
@@ -69,7 +69,7 @@
 
     // To match other browsers' behavior, never restore previous selection.
     if (auto control = associatedControl())
-        control->focus(SelectionRestorationMode::SelectAll, direction);
+        control->focus({ SelectionRestorationMode::SelectAll, options.direction });
 }
 
 bool HTMLLegendElement::accessKeyAction(bool sendMouseEvents)

Modified: trunk/Source/WebCore/html/HTMLLegendElement.h (274811 => 274812)


--- trunk/Source/WebCore/html/HTMLLegendElement.h	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/HTMLLegendElement.h	2021-03-22 22:29:52 UTC (rev 274812)
@@ -43,7 +43,7 @@
     RefPtr<HTMLFormControlElement> associatedControl();
 
     bool accessKeyAction(bool sendMouseEvents) final;
-    void focus(SelectionRestorationMode, FocusDirection) final;
+    void focus(const FocusOptions&) final;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLOrForeignElement.idl (274811 => 274812)


--- trunk/Source/WebCore/html/HTMLOrForeignElement.idl	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/HTMLOrForeignElement.idl	2021-03-22 22:29:52 UTC (rev 274812)
@@ -34,7 +34,7 @@
     // FIXME: Implement 'autofocus'.
     // [CEReactions] attribute boolean autofocus;
     [CEReactions, ImplementedAs=tabIndexForBindings] attribute long tabIndex;
-    // FIMXE: focus() is specified to take an optional FocusOptions. Implement that.
-    undefined focus();
+    undefined focus(optional FocusOptions options);
     undefined blur();
 };
+

Modified: trunk/Source/WebCore/html/InputType.cpp (274811 => 274812)


--- trunk/Source/WebCore/html/InputType.cpp	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/html/InputType.cpp	2021-03-22 22:29:52 UTC (rev 274812)
@@ -638,7 +638,7 @@
 bool InputType::accessKeyAction(bool)
 {
     ASSERT(element());
-    element()->focus(SelectionRestorationMode::SelectAll);
+    element()->focus({ SelectionRestorationMode::SelectAll });
     return false;
 }
 

Modified: trunk/Source/WebCore/page/FocusController.cpp (274811 => 274812)


--- trunk/Source/WebCore/page/FocusController.cpp	2021-03-22 22:19:12 UTC (rev 274811)
+++ trunk/Source/WebCore/page/FocusController.cpp	2021-03-22 22:29:52 UTC (rev 274812)
@@ -534,7 +534,7 @@
     }
 
     element->setHasFocusVisible(true);
-    element->focus(SelectionRestorationMode::SelectAll, direction);
+    element->focus({ SelectionRestorationMode::SelectAll, direction });
     return true;
 }
 
@@ -1108,7 +1108,7 @@
     Element* element = downcast<Element>(focusCandidate.focusableNode);
     ASSERT(element);
 
-    element->focus(SelectionRestorationMode::SelectAll, direction);
+    element->focus({ SelectionRestorationMode::SelectAll, direction });
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to