Title: [225429] trunk
Revision
225429
Author
[email protected]
Date
2017-12-01 16:09:02 -0800 (Fri, 01 Dec 2017)

Log Message

Alternative Presentation Button: Provide a way to query for the replaced elements
https://bugs.webkit.org/show_bug.cgi?id=180114
<rdar://problem/35710539>

Reviewed by Tim Horton.

Source/WebCore:

Add SPI to query for the elements that were replaced by an Alternative Presentation Button.

Test: fast/forms/alternative-presentation-button/replaced-elements.html

* editing/Editor.cpp:
(WebCore::Editor::elementsReplacedByAlternativePresentationButton): Added.
* editing/Editor.h:
* editing/cocoa/AlternativePresentationButtonSubstitution.cpp:
(WebCore::AlternativePresentationButtonSubstitution::replacedElements): Added.
* editing/cocoa/AlternativePresentationButtonSubstitution.h:
* testing/Internals.cpp:
(WebCore::Internals::elementsReplacedByAlternativePresentationButton): Added.
* testing/Internals.h:
* testing/Internals.idl: Expose internals function elementsReplacedByAlternativePresentationButton()
so as to test Editor::elementsReplacedByAlternativePresentationButton().

Source/WebKit:

Add SPI to query for the elements that were replaced by an Alternative Presentation Button.

* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm:
(-[WKWebProcessPlugInFrame elementsReplacedByAlternativePresentationButtonWithIdentifier:]): Added.
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h:
* WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
(WKBundleElementsReplacedByAlternativePresentationButton): Added.
* WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h:

LayoutTests:

Add a test to ensure that Editor::elementsReplacedByAlternativePresentationButton()
returns the same list of elements that were specified to Editor::substituteWithAlternativePresentationButton()
up to ordering.

* fast/forms/alternative-presentation-button/replaced-elements-expected.txt: Added.
* fast/forms/alternative-presentation-button/replaced-elements.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225428 => 225429)


--- trunk/LayoutTests/ChangeLog	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/LayoutTests/ChangeLog	2017-12-02 00:09:02 UTC (rev 225429)
@@ -1,3 +1,18 @@
+2017-12-01  Daniel Bates  <[email protected]>
+
+        Alternative Presentation Button: Provide a way to query for the replaced elements
+        https://bugs.webkit.org/show_bug.cgi?id=180114
+        <rdar://problem/35710539>
+
+        Reviewed by Tim Horton.
+
+        Add a test to ensure that Editor::elementsReplacedByAlternativePresentationButton()
+        returns the same list of elements that were specified to Editor::substituteWithAlternativePresentationButton()
+        up to ordering.
+
+        * fast/forms/alternative-presentation-button/replaced-elements-expected.txt: Added.
+        * fast/forms/alternative-presentation-button/replaced-elements.html: Added.
+
 2017-12-01  Youenn Fablet  <[email protected]>
 
         Implement https://w3c.github.io/ServiceWorker/#clients-get

Added: trunk/LayoutTests/fast/forms/alternative-presentation-button/replaced-elements-expected.txt (0 => 225429)


--- trunk/LayoutTests/fast/forms/alternative-presentation-button/replaced-elements-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/alternative-presentation-button/replaced-elements-expected.txt	2017-12-02 00:09:02 UTC (rev 225429)
@@ -0,0 +1,13 @@
+Tests that the elements returned by internals.elementsReplacedByAlternativePresentationButton() are the same as the elements passed to internals.substituteWithAlternativePresentationButton() ignoring order.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS internals.elementsReplacedByAlternativePresentationButton(1).length is 0
+PASS single input element
+PASS multiple elements
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+

Added: trunk/LayoutTests/fast/forms/alternative-presentation-button/replaced-elements.html (0 => 225429)


--- trunk/LayoutTests/fast/forms/alternative-presentation-button/replaced-elements.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/alternative-presentation-button/replaced-elements.html	2017-12-02 00:09:02 UTC (rev 225429)
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="test-container">
+    <div class="test" data-test-name="single input element">
+        <input type="text">
+    </div>
+    <div class="test" data-test-name="multiple elements">
+        <label for="" name</label>
+        <input type="text" id="first-name">
+        <label for="" name</label>
+        <input type="text" id="last-name">
+    </div>
+</div>
+<script>
+function areArraysEqualIgnoringOrder(a, b)
+{
+    if (a.length != b.length)
+        return false;
+    for (let aElement of a) {
+        if (!b.includes(aElement))
+            return false;
+    }
+    return true;
+}
+
+function runTests()
+{
+    if (!window.internals) {
+        testFailed("Must be run in DumpRenderTree or WebKitTestRunner.");
+        return;
+    }
+
+    // Non-existent identifier
+    shouldBeZero("internals.elementsReplacedByAlternativePresentationButton(1).length");
+
+    var id = 0;
+    var testContainer = document.getElementById("test-container");
+    var tests = testContainer.getElementsByClassName("test");
+    for (let test of tests) {
+        var id = ++id;
+        var expectedReplacedElements = Array.prototype.slice.call(test.children);
+        internals.substituteWithAlternativePresentationButton(test.children, id);
+        var actualReplacedElements = internals.elementsReplacedByAlternativePresentationButton(id);
+        if (areArraysEqualIgnoringOrder(actualReplacedElements, expectedReplacedElements))
+            testPassed(test.dataset.testName);
+        else
+            testFailed(test.dataset.testName);
+    }
+}
+
+description("Tests that the elements returned by internals.elementsReplacedByAlternativePresentationButton() are the same as the elements passed to internals.substituteWithAlternativePresentationButton() ignoring order.");
+runTests();
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (225428 => 225429)


--- trunk/Source/WebCore/ChangeLog	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/ChangeLog	2017-12-02 00:09:02 UTC (rev 225429)
@@ -1,3 +1,27 @@
+2017-12-01  Daniel Bates  <[email protected]>
+
+        Alternative Presentation Button: Provide a way to query for the replaced elements
+        https://bugs.webkit.org/show_bug.cgi?id=180114
+        <rdar://problem/35710539>
+
+        Reviewed by Tim Horton.
+
+        Add SPI to query for the elements that were replaced by an Alternative Presentation Button.
+
+        Test: fast/forms/alternative-presentation-button/replaced-elements.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::elementsReplacedByAlternativePresentationButton): Added.
+        * editing/Editor.h:
+        * editing/cocoa/AlternativePresentationButtonSubstitution.cpp:
+        (WebCore::AlternativePresentationButtonSubstitution::replacedElements): Added.
+        * editing/cocoa/AlternativePresentationButtonSubstitution.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::elementsReplacedByAlternativePresentationButton): Added.
+        * testing/Internals.h:
+        * testing/Internals.idl: Expose internals function elementsReplacedByAlternativePresentationButton()
+        so as to test Editor::elementsReplacedByAlternativePresentationButton().
+
 2017-12-01  Said Abou-Hallawa  <[email protected]>
 
         Rename ImageFrameCache to ImageSource

Modified: trunk/Source/WebCore/editing/Editor.cpp (225428 => 225429)


--- trunk/Source/WebCore/editing/Editor.cpp	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/editing/Editor.cpp	2017-12-02 00:09:02 UTC (rev 225429)
@@ -3857,6 +3857,16 @@
     substitution->unapply();
 }
 
+Vector<Ref<Element>> Editor::elementsReplacedByAlternativePresentationButton(const String& identifier)
+{
+    if (!m_alternativePresentationButtonIdentifierToElementMap.contains(identifier))
+        return { };
+    auto* button = m_alternativePresentationButtonIdentifierToElementMap.get(identifier);
+    ASSERT(m_alternativePresentationButtonElementToSubstitutionMap.contains(button));
+    auto substitution = m_alternativePresentationButtonElementToSubstitutionMap.get(button);
+    return substitution->replacedElements();
+}
+
 void Editor::didInsertAlternativePresentationButtonElement(AlternativePresentationButtonElement& button)
 {
     ASSERT(!m_alternativePresentationButtonElementToSubstitutionMap.contains(&button));

Modified: trunk/Source/WebCore/editing/Editor.h (225428 => 225429)


--- trunk/Source/WebCore/editing/Editor.h	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/editing/Editor.h	2017-12-02 00:09:02 UTC (rev 225429)
@@ -520,6 +520,8 @@
     // FIXME: Have this take an AlternativePresentationButtonElement& instead of an identifier.
     WEBCORE_EXPORT void removeAlternativePresentationButton(const String&);
 
+    WEBCORE_EXPORT Vector<Ref<Element>> elementsReplacedByAlternativePresentationButton(const String&);
+
     void didInsertAlternativePresentationButtonElement(AlternativePresentationButtonElement&);
     void didRemoveAlternativePresentationButtonElement(AlternativePresentationButtonElement&);
 #endif

Modified: trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.cpp (225428 => 225429)


--- trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.cpp	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.cpp	2017-12-02 00:09:02 UTC (rev 225429)
@@ -126,6 +126,16 @@
     detachShadowRoot();
 }
 
+Vector<Ref<Element>> AlternativePresentationButtonSubstitution::replacedElements()
+{
+    Vector<Ref<Element>> result;
+    result.reserveInitialCapacity(m_savedDisplayStyles.size() + 1);
+    result.uncheckedAppend(m_shadowHost.copyRef());
+    for (auto& savedDisplayStyle : m_savedDisplayStyles)
+        result.uncheckedAppend(savedDisplayStyle.element.copyRef());
+    return result;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT)

Modified: trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.h (225428 => 225429)


--- trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.h	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.h	2017-12-02 00:09:02 UTC (rev 225429)
@@ -46,6 +46,8 @@
     void apply();
     void unapply();
 
+    Vector<Ref<Element>> replacedElements();
+
 private:
     void initializeSavedDisplayStyles(Vector<Ref<Element>>&&);
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (225428 => 225429)


--- trunk/Source/WebCore/testing/Internals.cpp	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/testing/Internals.cpp	2017-12-02 00:09:02 UTC (rev 225429)
@@ -4327,6 +4327,13 @@
     frame()->editor().removeAlternativePresentationButton(identifier);
     return { };
 }
+
+ExceptionOr<Vector<Ref<Element>>> Internals::elementsReplacedByAlternativePresentationButton(const String& identifier)
+{
+    if (!frame())
+        return Exception { InvalidAccessError };
+    return frame()->editor().elementsReplacedByAlternativePresentationButton(identifier);
+}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (225428 => 225429)


--- trunk/Source/WebCore/testing/Internals.h	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/testing/Internals.h	2017-12-02 00:09:02 UTC (rev 225429)
@@ -637,6 +637,7 @@
 #if ENABLE(ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT)
     ExceptionOr<void> substituteWithAlternativePresentationButton(Vector<RefPtr<Element>>&&, const String&);
     ExceptionOr<void> removeAlternativePresentationButton(const String&);
+    ExceptionOr<Vector<Ref<Element>>> elementsReplacedByAlternativePresentationButton(const String&);
 #endif
 
     String timelineDescription(AnimationTimeline&);

Modified: trunk/Source/WebCore/testing/Internals.idl (225428 => 225429)


--- trunk/Source/WebCore/testing/Internals.idl	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebCore/testing/Internals.idl	2017-12-02 00:09:02 UTC (rev 225429)
@@ -576,4 +576,5 @@
 
     [Conditional=ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT, MayThrowException] void substituteWithAlternativePresentationButton(sequence<Element> elements, DOMString identifier);
     [Conditional=ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT, MayThrowException] void removeAlternativePresentationButton(DOMString identifier);
+    [Conditional=ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT, MayThrowException] sequence<Element> elementsReplacedByAlternativePresentationButton(DOMString identifier);
 };

Modified: trunk/Source/WebKit/ChangeLog (225428 => 225429)


--- trunk/Source/WebKit/ChangeLog	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebKit/ChangeLog	2017-12-02 00:09:02 UTC (rev 225429)
@@ -1,3 +1,20 @@
+2017-12-01  Daniel Bates  <[email protected]>
+
+        Alternative Presentation Button: Provide a way to query for the replaced elements
+        https://bugs.webkit.org/show_bug.cgi?id=180114
+        <rdar://problem/35710539>
+
+        Reviewed by Tim Horton.
+
+        Add SPI to query for the elements that were replaced by an Alternative Presentation Button.
+
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm:
+        (-[WKWebProcessPlugInFrame elementsReplacedByAlternativePresentationButtonWithIdentifier:]): Added.
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h:
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
+        (WKBundleElementsReplacedByAlternativePresentationButton): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h:
+
 2017-12-01  Youenn Fablet  <[email protected]>
 
         Implement https://w3c.github.io/ServiceWorker/#clients-get

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm (225428 => 225429)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm	2017-12-02 00:09:02 UTC (rev 225429)
@@ -116,6 +116,21 @@
 #endif
 }
 
+- (NSArray<WKWebProcessPlugInNodeHandle *> *)elementsReplacedByAlternativePresentationButtonWithIdentifier:(NSString *)identifier
+{
+#if ENABLE(ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT)
+    auto replacedElements = _frame->coreFrame()->editor().elementsReplacedByAlternativePresentationButton(identifier);
+    if (replacedElements.isEmpty())
+        return nil;
+    auto nodeHandles = adoptNS([NSMutableArray arrayWithCapacity:replacedElements.size()]);
+    for (auto& element : replacedElements)
+        [nodeHandles addObject:wrapper(InjectedBundleNodeHandle::getOrCreate(element).get())];
+    return nodeHandles.autorelease();
+#else
+    return nil;
+#endif
+}
+
 - (WKWebProcessPlugInBrowserContextController *)_browserContextController
 {
     return wrapper(*_frame->page());

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h (225428 => 225429)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h	2017-12-02 00:09:02 UTC (rev 225429)
@@ -44,6 +44,7 @@
 
 - (void)substituteElements:(NSArray<WKWebProcessPlugInNodeHandle *> *)elements withAlternativePresentationButtonWithIdentifier:(NSString *)identifier;
 - (void)removeAlternativePresentationButton:(NSString *)identifier;
+- (NSArray<WKWebProcessPlugInNodeHandle *> *)elementsReplacedByAlternativePresentationButtonWithIdentifier:(NSString *)identifier;
 
 @end
 

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp (225428 => 225429)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp	2017-12-02 00:09:02 UTC (rev 225429)
@@ -333,3 +333,21 @@
     UNUSED_PARAM(identifier);
 #endif
 }
+
+WKArrayRef WKBundleElementsReplacedByAlternativePresentationButton(WKBundleFrameRef frame, WKStringRef identifier)
+{
+#if ENABLE(ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT)
+    auto* coreFrame = toImpl(frame)->coreFrame();
+    if (!coreFrame)
+        return nullptr;
+    auto replacedElements = coreFrame->editor().elementsReplacedByAlternativePresentationButton(toWTFString(identifier));
+    Vector<RefPtr<API::Object>> apiReplacedElements;
+    apiReplacedElements.reserveInitialCapacity(replacedElements.size());
+    for (auto& element : replacedElements)
+        apiReplacedElements.uncheckedAppend(InjectedBundleNodeHandle::getOrCreate(element));
+    return toAPI(&API::Array::create(WTFMove(apiReplacedElements)).leakRef());
+#else
+    UNUSED_PARAM(identifier);
+    return nullptr;
+#endif
+}

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h (225428 => 225429)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h	2017-12-02 00:01:54 UTC (rev 225428)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h	2017-12-02 00:09:02 UTC (rev 225429)
@@ -58,6 +58,7 @@
 
 WK_EXPORT void WKBundleSubstituteWithAlternativePresentationButton(WKBundleFrameRef frame, WKArrayRef elements, WKStringRef identifier);
 WK_EXPORT void WKBundleRemoveAlternativePresentationButton(WKBundleFrameRef frame, WKStringRef identifier);
+WK_EXPORT WKArrayRef WKBundleElementsReplacedByAlternativePresentationButton(WKBundleFrameRef frame, WKStringRef identifier);
 
 #ifdef __cplusplus
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to