Title: [276347] trunk
Revision
276347
Author
[email protected]
Date
2021-04-21 00:18:16 -0700 (Wed, 21 Apr 2021)

Log Message

Support scrolling to a selected AppHighlight
https://bugs.webkit.org/show_bug.cgi?id=224773

Reviewed by Tim Horton.

Source/WebCore:

Test: AppHighlights::AppHighlightCreateAndRestoreAndScroll

* Modules/highlight/AppHighlightStorage.cpp:
(WebCore::AppHighlightStorage::restoreAndScrollToAppHighlight):
(WebCore::AppHighlightStorage::attemptToRestoreHighlightAndScroll):
(WebCore::AppHighlightStorage::restoreUnrestoredAppHighlights):
(WebCore::AppHighlightStorage::restoreAppHighlight): Deleted.
* Modules/highlight/AppHighlightStorage.h:
* WebCore.xcodeproj/project.pbxproj:
* editing/Editor.cpp:
(WebCore::TemporarySelectionChange::setSelection):
* page/Page.cpp:
(WebCore::Page::doAfterUpdateRendering):

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(restoreHighlight):
(-[WKWebView _restoreAppHighlights:]):
(-[WKWebView _restoreAndScrollToAppHighlight:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::restoreAppHighlightsAndScrollToIndex):
(WebKit::WebPageProxy::restoreAppHighlights): Deleted.
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::restoreAppHighlightsAndScrollToIndex):
(WebKit::WebPage::restoreAppHighlights): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (276346 => 276347)


--- trunk/Source/WebCore/ChangeLog	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebCore/ChangeLog	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1,3 +1,24 @@
+2021-04-21  Megan Gardner  <[email protected]>
+
+        Support scrolling to a selected AppHighlight
+        https://bugs.webkit.org/show_bug.cgi?id=224773
+
+        Reviewed by Tim Horton.
+
+        Test: AppHighlights::AppHighlightCreateAndRestoreAndScroll
+
+        * Modules/highlight/AppHighlightStorage.cpp:
+        (WebCore::AppHighlightStorage::restoreAndScrollToAppHighlight):
+        (WebCore::AppHighlightStorage::attemptToRestoreHighlightAndScroll):
+        (WebCore::AppHighlightStorage::restoreUnrestoredAppHighlights):
+        (WebCore::AppHighlightStorage::restoreAppHighlight): Deleted.
+        * Modules/highlight/AppHighlightStorage.h:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/Editor.cpp:
+        (WebCore::TemporarySelectionChange::setSelection):
+        * page/Page.cpp:
+        (WebCore::Page::doAfterUpdateRendering):
+
 2021-04-20  Ian Gilbert  <[email protected]>
 
         Crash in CompositeEditCommand::insertNodeAt

Modified: trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp (276346 => 276347)


--- trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-04-21 07:18:16 UTC (rev 276347)
@@ -32,6 +32,7 @@
 #include "Chrome.h"
 #include "Document.h"
 #include "DocumentMarkerController.h"
+#include "Editor.h"
 #include "HTMLBodyElement.h"
 #include "HighlightRegister.h"
 #include "Node.h"
@@ -229,44 +230,57 @@
     m_document->page()->chrome().storeAppHighlight(WTFMove(highlight));
 }
 
-void AppHighlightStorage::restoreAppHighlight(Ref<SharedBuffer>&& buffer)
+void AppHighlightStorage::restoreAndScrollToAppHighlight(Ref<SharedBuffer>&& buffer, ScrollToHighlight scroll)
 {
-    if (!m_document)
-        return;
-    
-    auto strongDocument = makeRefPtr(m_document.get());
-
     auto appHighlightRangeData = AppHighlightRangeData::create(buffer);
     if (!appHighlightRangeData)
         return;
+    
+    if (!attemptToRestoreHighlightAndScroll(appHighlightRangeData.value(), scroll)) {
+        if (scroll == ScrollToHighlight::Yes)
+            m_unrestoredScrollHighlight = appHighlightRangeData;
+        else
+            m_unrestoredHighlights.append(appHighlightRangeData.value());
+    }
+    
+    m_timeAtLastRangeSearch = MonotonicTime::now();
+}
 
-    auto range = findRange(*appHighlightRangeData, *strongDocument);
+bool AppHighlightStorage::attemptToRestoreHighlightAndScroll(AppHighlightRangeData& highlight, ScrollToHighlight scroll)
+{
+    if (!m_document)
+        return false;
     
+    auto strongDocument = makeRefPtr(m_document.get());
+    
+    auto range = findRange(highlight, *strongDocument);
+    
     if (!range)
-        m_unrestoredHighlights.append(appHighlightRangeData.value());
-    else
-        strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
+        return false;
     
-    m_timeAtLastRangeSearch = MonotonicTime::now();
+    strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
+    
+    if (scroll == ScrollToHighlight::Yes) {
+        OptionSet<TemporarySelectionOption> temporarySelectionOptions;
+        temporarySelectionOptions.add(TemporarySelectionOption::RevealSelection);
+        TemporarySelectionChange selectionChange(*strongDocument, { range.value() }, temporarySelectionOptions);
+    }
+    return true;
 }
 
 void AppHighlightStorage::restoreUnrestoredAppHighlights()
 {
     Vector<AppHighlightRangeData> remainingRanges;
-
-    if (!m_document)
-        return;
     
-    auto strongDocument = makeRefPtr(m_document.get());
-    
     for (auto& highlight : m_unrestoredHighlights) {
-        auto range = findRange(highlight, *strongDocument);
-        
-        if (!range)
+        if (!attemptToRestoreHighlightAndScroll(highlight, ScrollToHighlight::No))
             remainingRanges.append(highlight);
-        else
-            strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
     }
+    if (m_unrestoredScrollHighlight) {
+        if (attemptToRestoreHighlightAndScroll(m_unrestoredScrollHighlight.value(), ScrollToHighlight::Yes))
+            m_unrestoredScrollHighlight.reset();
+    }
+        
     m_timeAtLastRangeSearch = MonotonicTime::now();
     m_unrestoredHighlights = WTFMove(remainingRanges);
 }

Modified: trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.h (276346 => 276347)


--- trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.h	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.h	2021-04-21 07:18:16 UTC (rev 276347)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "AppHighlightRangeData.h"
 #include <wtf/Forward.h>
 #include <wtf/MonotonicTime.h>
 #include <wtf/OptionSet.h>
@@ -37,7 +38,6 @@
 
 #if ENABLE(APP_HIGHLIGHTS)
 
-class AppHighlightRangeData;
 class Document;
 class SharedBuffer;
 class StaticRange;
@@ -47,6 +47,8 @@
 
 enum class RestoreWithTextSearch : bool { No, Yes };
 
+enum class ScrollToHighlight : bool { No, Yes };
+
 class AppHighlightStorage final : RefCounted<AppHighlightStorage> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -54,16 +56,19 @@
     ~AppHighlightStorage();
 
     WEBCORE_EXPORT void storeAppHighlight(Ref<StaticRange>&&);
-    WEBCORE_EXPORT void restoreAppHighlight(Ref<SharedBuffer>&&);
+    WEBCORE_EXPORT void restoreAndScrollToAppHighlight(Ref<SharedBuffer>&&, ScrollToHighlight);
     void restoreUnrestoredAppHighlights();
     MonotonicTime lastRangeSearchTime() const { return m_timeAtLastRangeSearch; }
     void resetLastRangeSearchTime() { m_timeAtLastRangeSearch = MonotonicTime::now(); }
-    bool hasUnrestoredHighlights() const { return m_unrestoredHighlights.size(); }
+    bool hasUnrestoredHighlights() const { return m_unrestoredHighlights.size() || m_unrestoredScrollHighlight; }
 
 private:
+    bool attemptToRestoreHighlightAndScroll(AppHighlightRangeData&, ScrollToHighlight);
+    
     WeakPtr<Document> m_document;
     MonotonicTime m_timeAtLastRangeSearch;
     Vector<AppHighlightRangeData> m_unrestoredHighlights;
+    Optional<AppHighlightRangeData> m_unrestoredScrollHighlight;
 };
 
 #endif

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (276346 => 276347)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1261,7 +1261,7 @@
 		44A20DB90F84166C00B3E1FE /* WebCoreURLResponseIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 44A20DB80F84166C00B3E1FE /* WebCoreURLResponseIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		44A28AAC12DFB8AC00AE923B /* MathMLElementFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 44A28AAB12DFB8AC00AE923B /* MathMLElementFactory.h */; };
 		44A28AAF12DFB8BF00AE923B /* MathMLNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 44A28AAE12DFB8BF00AE923B /* MathMLNames.h */; };
-		44AE045C2579CFFB00C42E65 /* AppHighlightRangeData.h in Headers */ = {isa = PBXBuildFile; fileRef = 44AE045A2579CFFB00C42E65 /* AppHighlightRangeData.h */; };
+		44AE045C2579CFFB00C42E65 /* AppHighlightRangeData.h in Headers */ = {isa = PBXBuildFile; fileRef = 44AE045A2579CFFB00C42E65 /* AppHighlightRangeData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		44C991860F3D1EBE00586670 /* ScrollbarThemeIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 44C991850F3D1EBE00586670 /* ScrollbarThemeIOS.h */; };
 		44C9919F0F3D210E00586670 /* ThemeIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 44C9919D0F3D210E00586670 /* ThemeIOS.h */; };
 		44E349F9246F4E190068479C /* LibWebRTCEnumTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 44E349F7246F4DC70068479C /* LibWebRTCEnumTraits.h */; settings = {ATTRIBUTES = (Private, ); }; };

Modified: trunk/Source/WebCore/editing/Editor.cpp (276346 => 276347)


--- trunk/Source/WebCore/editing/Editor.cpp	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebCore/editing/Editor.cpp	2021-04-21 07:18:16 UTC (rev 276347)
@@ -263,6 +263,8 @@
     auto options = FrameSelection::defaultSetSelectionOptions();
     if (m_options & TemporarySelectionOption::DoNotSetFocus)
         options.add(FrameSelection::DoNotSetFocus);
+    if (m_options & TemporarySelectionOption::RevealSelection)
+        options.add(FrameSelection::RevealSelection);
     m_document->selection().setSelection(selection, options);
 }
 

Modified: trunk/Source/WebCore/page/Page.cpp (276346 => 276347)


--- trunk/Source/WebCore/page/Page.cpp	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebCore/page/Page.cpp	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1620,9 +1620,10 @@
     forEachDocument([] (Document& document) {
         document.updateHighlightPositions();
     });
-#if ENABLE(APP_HIGHLIGHT)
+#if ENABLE(APP_HIGHLIGHTS)
     forEachDocument([] (Document& document) {
-        if (!auto appHighlightStorage = document.appHighlightStorageIfExists())
+        auto appHighlightStorage = document.appHighlightStorageIfExists();
+        if (!appHighlightStorage)
             return;
         
         if (appHighlightStorage->hasUnrestoredHighlights() && MonotonicTime::now() - appHighlightStorage->lastRangeSearchTime() > 1_s) {

Modified: trunk/Source/WebKit/ChangeLog (276346 => 276347)


--- trunk/Source/WebKit/ChangeLog	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/ChangeLog	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1,3 +1,25 @@
+2021-04-21  Megan Gardner  <[email protected]>
+
+        Support scrolling to a selected AppHighlight
+        https://bugs.webkit.org/show_bug.cgi?id=224773
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (restoreHighlight):
+        (-[WKWebView _restoreAppHighlights:]):
+        (-[WKWebView _restoreAndScrollToAppHighlight:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::restoreAppHighlightsAndScrollToIndex):
+        (WebKit::WebPageProxy::restoreAppHighlights): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::restoreAppHighlightsAndScrollToIndex):
+        (WebKit::WebPage::restoreAppHighlights): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2021-04-20  Kimmo Kinnunen  <[email protected]>
 
         Connection::m_mainThread is unused

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (276346 => 276347)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-04-21 07:18:16 UTC (rev 276347)
@@ -2153,24 +2153,43 @@
     [self setAllMediaPlaybackSuspended:NO completionHandler:nil];
 }
 
+#if ENABLE(APP_HIGHLIGHTS)
+static void convertAndAddHighlight(Vector<Ref<WebKit::SharedMemory>>& buffers, NSData *highlight)
+{
+    auto sharedMemory = WebKit::SharedMemory::allocate(highlight.length);
+    if (sharedMemory) {
+        [highlight getBytes:sharedMemory->data() length:highlight.length];
+        buffers.append(*sharedMemory);
+    }
+}
+#endif
+
 - (void)_restoreAppHighlights:(NSArray<NSData *> *)highlights
 {
 #if ENABLE(APP_HIGHLIGHTS)
     Vector<Ref<WebKit::SharedMemory>> buffers;
 
-    for (NSData *highlight in highlights) {
-        auto sharedMemory = WebKit::SharedMemory::allocate(highlight.length);
-        if (sharedMemory) {
-            [highlight getBytes:sharedMemory->data() length:highlight.length];
-            buffers.append(*sharedMemory);
-        }
-    }
-    _page->restoreAppHighlights(buffers);
+    for (NSData *highlight in highlights)
+        convertAndAddHighlight(buffers, highlight);
+    
+    _page->restoreAppHighlightsAndScrollToIndex(buffers, WTF::nullopt);
 #else
     UNUSED_PARAM(highlights);
 #endif
 }
 
+- (void)_restoreAndScrollToAppHighlight:(NSData *)highlight
+{
+#if ENABLE(APP_HIGHLIGHTS)
+    Vector<Ref<WebKit::SharedMemory>> buffers;
+    
+    convertAndAddHighlight(buffers, highlight);
+    _page->restoreAppHighlightsAndScrollToIndex(buffers, 0);
+#else
+    UNUSED_PARAM(highlight);
+#endif
+}
+
 - (void)_addAppHighlight
 {
 #if ENABLE(APP_HIGHLIGHTS)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (276346 => 276347)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2021-04-21 07:18:16 UTC (rev 276347)
@@ -367,7 +367,8 @@
 - (void)_didDisableBrowserExtensions:(NSSet<NSString *> *)extensionIDs WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (nonatomic, weak, setter=_setAppHighlightDelegate:) id <_WKAppHighlightDelegate> _appHighlightDelegate WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
-- (void)_restoreAppHighlights:(NSArray<NSData *> *)data WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_restoreAppHighlights:(NSArray<NSData *> *)highlights WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_restoreAndScrollToAppHighlight:(NSData *)highlight WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_addAppHighlight WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 // FIXME: Remove old `-[WKWebView _themeColor]` SPI <rdar://76662644>

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (276346 => 276347)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-04-21 07:18:16 UTC (rev 276347)
@@ -559,7 +559,7 @@
     send(Messages::WebPage::CreateAppHighlightInSelectedRange(createNewGroup, requestOriginatedInApp));
 }
 
-void WebPageProxy::restoreAppHighlights(const Vector<Ref<SharedMemory>>& highlights)
+void WebPageProxy::restoreAppHighlightsAndScrollToIndex(const Vector<Ref<SharedMemory>>& highlights, const Optional<unsigned> index)
 {
     if (!hasRunningProcess())
         return;
@@ -573,7 +573,7 @@
         memoryHandles.append(SharedMemory::IPCHandle { WTFMove(handle), highlight->size() });
     }
 
-    send(Messages::WebPage::RestoreAppHighlights(WTFMove(memoryHandles)));
+    send(Messages::WebPage::RestoreAppHighlightsAndScrollToIndex(WTFMove(memoryHandles), index));
 }
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (276346 => 276347)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1886,7 +1886,7 @@
 #if ENABLE(APP_HIGHLIGHTS)
     void createAppHighlightInSelectedRange(WebCore::CreateNewGroupForHighlight, WebCore::HighlightRequestOriginatedInApp);
     void storeAppHighlight(const WebCore::AppHighlight&);
-    void restoreAppHighlights(const Vector<Ref<WebKit::SharedMemory>>& highlights);
+    void restoreAppHighlightsAndScrollToIndex(const Vector<Ref<WebKit::SharedMemory>>& highlights, const Optional<unsigned> index);
 #endif
 
 #if ENABLE(MEDIA_STREAM)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (276346 => 276347)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-04-21 07:18:16 UTC (rev 276347)
@@ -7485,15 +7485,18 @@
     return true;
 }
 
-void WebPage::restoreAppHighlights(const Vector<SharedMemory::IPCHandle>&& memoryHandles)
+void WebPage::restoreAppHighlightsAndScrollToIndex(const Vector<SharedMemory::IPCHandle>&& memoryHandles, const Optional<unsigned> index)
 {
     auto document = makeRefPtr(m_page->focusController().focusedOrMainFrame().document());
 
+    unsigned i = 0;
     for (const auto& ipcHandle : memoryHandles) {
         auto sharedMemory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
         if (!sharedMemory)
             continue;
-        document->appHighlightStorage().restoreAppHighlight(SharedBuffer::create(static_cast<const char*>(sharedMemory->data()), sharedMemory->size()));
+
+        document->appHighlightStorage().restoreAndScrollToAppHighlight(SharedBuffer::create(static_cast<const char*>(sharedMemory->data()), sharedMemory->size()), i == index ? ScrollToHighlight::Yes : ScrollToHighlight::No);
+        i++;
     }
 }
 #endif

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (276346 => 276347)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1417,7 +1417,7 @@
     WebCore::HighlightRequestOriginatedInApp highlightRequestOriginatedInApp() const { return m_highlightRequestOriginatedInApp; }
 
     bool createAppHighlightInSelectedRange(WebCore::CreateNewGroupForHighlight, WebCore::HighlightRequestOriginatedInApp);
-    void restoreAppHighlights(const Vector<SharedMemory::IPCHandle>&&);
+    void restoreAppHighlightsAndScrollToIndex(const Vector<SharedMemory::IPCHandle>&&, const Optional<unsigned> index);
 #endif
 
     void dispatchWheelEventWithoutScrolling(const WebWheelEvent&, CompletionHandler<void(bool)>&&);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (276346 => 276347)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-04-21 07:18:16 UTC (rev 276347)
@@ -628,7 +628,7 @@
 
 #if ENABLE(APP_HIGHLIGHTS)
     CreateAppHighlightInSelectedRange(enum:bool WebCore::CreateNewGroupForHighlight createNewGroup, enum:bool WebCore::HighlightRequestOriginatedInApp requestOrigin)
-    RestoreAppHighlights(Vector<WebKit::SharedMemory::IPCHandle> memoryHandles)
+    RestoreAppHighlightsAndScrollToIndex(Vector<WebKit::SharedMemory::IPCHandle> memoryHandles, Optional<unsigned> index)
 #endif
 
     DispatchWheelEventWithoutScrolling(WebKit::WebWheelEvent event) -> (bool handled) Async

Modified: trunk/Tools/ChangeLog (276346 => 276347)


--- trunk/Tools/ChangeLog	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Tools/ChangeLog	2021-04-21 07:18:16 UTC (rev 276347)
@@ -1,3 +1,13 @@
+2021-04-21  Megan Gardner  <[email protected]>
+
+        Support scrolling to a selected AppHighlight
+        https://bugs.webkit.org/show_bug.cgi?id=224773
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
+        (TestWebKitAPI::TEST):
+
 2021-04-20  Devin Rousso  <[email protected]>
 
         Parse `theme_color` in web application manifests and pass it along to `-[WKWebView themeColor]`

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm (276346 => 276347)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm	2021-04-21 06:58:19 UTC (rev 276346)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm	2021-04-21 07:18:16 UTC (rev 276347)
@@ -43,14 +43,14 @@
 #endif
 
 @interface AppHighlightDelegate : NSObject <_WKAppHighlightDelegate>
-@property (nonatomic, copy) void (^storeAppHighlightCallback)(WKWebView *, _WKAppHighlight *, BOOL);
+@property (nonatomic, copy) void (^storeAppHighlightCallback)(WKWebView *, _WKAppHighlight *, BOOL, BOOL);
 @end
 
 @implementation AppHighlightDelegate
-- (void)_webView:(WKWebView *)webView storeAppHighlight:(_WKAppHighlight *)highlight inNewGroup:(BOOL)inNewGroup
+- (void)_webView:(WKWebView *)webView storeAppHighlight:(_WKAppHighlight *)highlight inNewGroup:(BOOL)inNewGroup requestOriginatedInApp:(BOOL)requestOriginatedInApp
 {
     if (_storeAppHighlightCallback)
-        _storeAppHighlightCallback(webView, highlight, inNewGroup);
+        _storeAppHighlightCallback(webView, highlight, inNewGroup, requestOriginatedInApp);
 }
 @end
 
@@ -66,7 +66,7 @@
     [webViewCreate synchronouslyLoadHTMLString:@"Test"];
     [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
     __block bool finished = NO;
-    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup) {
+    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) {
         EXPECT_EQ(delegateWebView, webViewCreate.get());
         EXPECT_NOT_NULL(highlight);
         EXPECT_WK_STREQ(highlight.text, @"Test");
@@ -85,6 +85,36 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
+TEST(AppHighlights, AppHighlightCreateAndRestoreAndScroll)
+{
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+    auto delegate = adoptNS([[AppHighlightDelegate alloc] init]);
+    auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
+    auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
+    [webViewCreate _setAppHighlightDelegate:delegate.get()];
+    [webViewCreate synchronouslyLoadHTMLString:@"<div style='height: 1000px'></div>Test"];
+    [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
+    __block bool finished = NO;
+    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) {
+        EXPECT_EQ(delegateWebView, webViewCreate.get());
+        EXPECT_NOT_NULL(highlight);
+        EXPECT_WK_STREQ(highlight.text, @"Test");
+        EXPECT_NOT_NULL(highlight.highlight);
+        
+        [webViewRestore synchronouslyLoadHTMLString:@"<div style='height: 1000px'></div>Test"];
+        [webViewRestore _restoreAndScrollToAppHighlight:highlight.highlight];
+        
+        TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
+            return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
+        }, 2, @"Expected Highlights to be populated.");
+        EXPECT_NE(0, [[webViewRestore objectByEvaluatingJavaScript:@"pageYOffset"] floatValue]);
+        
+        finished = YES;
+    }];
+    [webViewCreate _addAppHighlight];
+    TestWebKitAPI::Util::run(&finished);
+}
+
 TEST(AppHighlights, AppHighlightRestoreFailure)
 {
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
@@ -95,7 +125,7 @@
     [webViewCreate synchronouslyLoadHTMLString:@"Test"];
     [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
     __block bool finished = NO;
-    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup) {
+    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) {
         EXPECT_EQ(delegateWebView, webViewCreate.get());
         EXPECT_NOT_NULL(highlight);
         EXPECT_WK_STREQ(highlight.text, @"Test");
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to