Changeset 225429 in webkit


Ignore:
Timestamp:
Dec 1, 2017 4:09:02 PM (6 years ago)
Author:
dbates@webkit.org
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.
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r225427 r225429  
     12017-12-01  Daniel Bates  <dabates@apple.com>
     2
     3        Alternative Presentation Button: Provide a way to query for the replaced elements
     4        https://bugs.webkit.org/show_bug.cgi?id=180114
     5        <rdar://problem/35710539>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a test to ensure that Editor::elementsReplacedByAlternativePresentationButton()
     10        returns the same list of elements that were specified to Editor::substituteWithAlternativePresentationButton()
     11        up to ordering.
     12
     13        * fast/forms/alternative-presentation-button/replaced-elements-expected.txt: Added.
     14        * fast/forms/alternative-presentation-button/replaced-elements.html: Added.
     15
    1162017-12-01  Youenn Fablet  <youenn@apple.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r225428 r225429  
     12017-12-01  Daniel Bates  <dabates@apple.com>
     2
     3        Alternative Presentation Button: Provide a way to query for the replaced elements
     4        https://bugs.webkit.org/show_bug.cgi?id=180114
     5        <rdar://problem/35710539>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add SPI to query for the elements that were replaced by an Alternative Presentation Button.
     10
     11        Test: fast/forms/alternative-presentation-button/replaced-elements.html
     12
     13        * editing/Editor.cpp:
     14        (WebCore::Editor::elementsReplacedByAlternativePresentationButton): Added.
     15        * editing/Editor.h:
     16        * editing/cocoa/AlternativePresentationButtonSubstitution.cpp:
     17        (WebCore::AlternativePresentationButtonSubstitution::replacedElements): Added.
     18        * editing/cocoa/AlternativePresentationButtonSubstitution.h:
     19        * testing/Internals.cpp:
     20        (WebCore::Internals::elementsReplacedByAlternativePresentationButton): Added.
     21        * testing/Internals.h:
     22        * testing/Internals.idl: Expose internals function elementsReplacedByAlternativePresentationButton()
     23        so as to test Editor::elementsReplacedByAlternativePresentationButton().
     24
    1252017-12-01  Said Abou-Hallawa  <sabouhallawa@apple.com>
    226
  • trunk/Source/WebCore/editing/Editor.cpp

    r225422 r225429  
    38583858}
    38593859
     3860Vector<Ref<Element>> Editor::elementsReplacedByAlternativePresentationButton(const String& identifier)
     3861{
     3862    if (!m_alternativePresentationButtonIdentifierToElementMap.contains(identifier))
     3863        return { };
     3864    auto* button = m_alternativePresentationButtonIdentifierToElementMap.get(identifier);
     3865    ASSERT(m_alternativePresentationButtonElementToSubstitutionMap.contains(button));
     3866    auto substitution = m_alternativePresentationButtonElementToSubstitutionMap.get(button);
     3867    return substitution->replacedElements();
     3868}
     3869
    38603870void Editor::didInsertAlternativePresentationButtonElement(AlternativePresentationButtonElement& button)
    38613871{
  • trunk/Source/WebCore/editing/Editor.h

    r225311 r225429  
    521521    WEBCORE_EXPORT void removeAlternativePresentationButton(const String&);
    522522
     523    WEBCORE_EXPORT Vector<Ref<Element>> elementsReplacedByAlternativePresentationButton(const String&);
     524
    523525    void didInsertAlternativePresentationButtonElement(AlternativePresentationButtonElement&);
    524526    void didRemoveAlternativePresentationButtonElement(AlternativePresentationButtonElement&);
  • trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.cpp

    r225223 r225429  
    127127}
    128128
     129Vector<Ref<Element>> AlternativePresentationButtonSubstitution::replacedElements()
     130{
     131    Vector<Ref<Element>> result;
     132    result.reserveInitialCapacity(m_savedDisplayStyles.size() + 1);
     133    result.uncheckedAppend(m_shadowHost.copyRef());
     134    for (auto& savedDisplayStyle : m_savedDisplayStyles)
     135        result.uncheckedAppend(savedDisplayStyle.element.copyRef());
     136    return result;
     137}
     138
    129139} // namespace WebCore
    130140
  • trunk/Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.h

    r225223 r225429  
    4747    void unapply();
    4848
     49    Vector<Ref<Element>> replacedElements();
     50
    4951private:
    5052    void initializeSavedDisplayStyles(Vector<Ref<Element>>&&);
  • trunk/Source/WebCore/testing/Internals.cpp

    r225403 r225429  
    43284328    return { };
    43294329}
     4330
     4331ExceptionOr<Vector<Ref<Element>>> Internals::elementsReplacedByAlternativePresentationButton(const String& identifier)
     4332{
     4333    if (!frame())
     4334        return Exception { InvalidAccessError };
     4335    return frame()->editor().elementsReplacedByAlternativePresentationButton(identifier);
     4336}
    43304337#endif
    43314338
  • trunk/Source/WebCore/testing/Internals.h

    r225403 r225429  
    638638    ExceptionOr<void> substituteWithAlternativePresentationButton(Vector<RefPtr<Element>>&&, const String&);
    639639    ExceptionOr<void> removeAlternativePresentationButton(const String&);
     640    ExceptionOr<Vector<Ref<Element>>> elementsReplacedByAlternativePresentationButton(const String&);
    640641#endif
    641642
  • trunk/Source/WebCore/testing/Internals.idl

    r225403 r225429  
    577577    [Conditional=ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT, MayThrowException] void substituteWithAlternativePresentationButton(sequence<Element> elements, DOMString identifier);
    578578    [Conditional=ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT, MayThrowException] void removeAlternativePresentationButton(DOMString identifier);
    579 };
     579    [Conditional=ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT, MayThrowException] sequence<Element> elementsReplacedByAlternativePresentationButton(DOMString identifier);
     580};
  • trunk/Source/WebKit/ChangeLog

    r225427 r225429  
     12017-12-01  Daniel Bates  <dabates@apple.com>
     2
     3        Alternative Presentation Button: Provide a way to query for the replaced elements
     4        https://bugs.webkit.org/show_bug.cgi?id=180114
     5        <rdar://problem/35710539>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add SPI to query for the elements that were replaced by an Alternative Presentation Button.
     10
     11        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm:
     12        (-[WKWebProcessPlugInFrame elementsReplacedByAlternativePresentationButtonWithIdentifier:]): Added.
     13        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h:
     14        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
     15        (WKBundleElementsReplacedByAlternativePresentationButton): Added.
     16        * WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h:
     17
    1182017-12-01  Youenn Fablet  <youenn@apple.com>
    219
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm

    r225223 r225429  
    117117}
    118118
     119- (NSArray<WKWebProcessPlugInNodeHandle *> *)elementsReplacedByAlternativePresentationButtonWithIdentifier:(NSString *)identifier
     120{
     121#if ENABLE(ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT)
     122    auto replacedElements = _frame->coreFrame()->editor().elementsReplacedByAlternativePresentationButton(identifier);
     123    if (replacedElements.isEmpty())
     124        return nil;
     125    auto nodeHandles = adoptNS([NSMutableArray arrayWithCapacity:replacedElements.size()]);
     126    for (auto& element : replacedElements)
     127        [nodeHandles addObject:wrapper(InjectedBundleNodeHandle::getOrCreate(element).get())];
     128    return nodeHandles.autorelease();
     129#else
     130    return nil;
     131#endif
     132}
     133
    119134- (WKWebProcessPlugInBrowserContextController *)_browserContextController
    120135{
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h

    r225223 r225429  
    4545- (void)substituteElements:(NSArray<WKWebProcessPlugInNodeHandle *> *)elements withAlternativePresentationButtonWithIdentifier:(NSString *)identifier;
    4646- (void)removeAlternativePresentationButton:(NSString *)identifier;
     47- (NSArray<WKWebProcessPlugInNodeHandle *> *)elementsReplacedByAlternativePresentationButtonWithIdentifier:(NSString *)identifier;
    4748
    4849@end
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp

    r225223 r225429  
    334334#endif
    335335}
     336
     337WKArrayRef WKBundleElementsReplacedByAlternativePresentationButton(WKBundleFrameRef frame, WKStringRef identifier)
     338{
     339#if ENABLE(ALTERNATIVE_PRESENTATION_BUTTON_ELEMENT)
     340    auto* coreFrame = toImpl(frame)->coreFrame();
     341    if (!coreFrame)
     342        return nullptr;
     343    auto replacedElements = coreFrame->editor().elementsReplacedByAlternativePresentationButton(toWTFString(identifier));
     344    Vector<RefPtr<API::Object>> apiReplacedElements;
     345    apiReplacedElements.reserveInitialCapacity(replacedElements.size());
     346    for (auto& element : replacedElements)
     347        apiReplacedElements.uncheckedAppend(InjectedBundleNodeHandle::getOrCreate(element));
     348    return toAPI(&API::Array::create(WTFMove(apiReplacedElements)).leakRef());
     349#else
     350    UNUSED_PARAM(identifier);
     351    return nullptr;
     352#endif
     353}
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h

    r225223 r225429  
    5959WK_EXPORT void WKBundleSubstituteWithAlternativePresentationButton(WKBundleFrameRef frame, WKArrayRef elements, WKStringRef identifier);
    6060WK_EXPORT void WKBundleRemoveAlternativePresentationButton(WKBundleFrameRef frame, WKStringRef identifier);
     61WK_EXPORT WKArrayRef WKBundleElementsReplacedByAlternativePresentationButton(WKBundleFrameRef frame, WKStringRef identifier);
    6162
    6263#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.