Title: [197916] trunk/Source
Revision
197916
Author
[email protected]
Date
2016-03-09 18:05:49 -0800 (Wed, 09 Mar 2016)

Log Message

Retrieve additional context for some data detector link for preview and action menu.
https://bugs.webkit.org/show_bug.cgi?id=155278
rdar://problem/24884951

Reviewed by Tim Horton.

Source/WebCore:

Adding helper function to compute a range by moving by a number of characters
from a given position and direction.
Adding function to check if the given data detector link element requires
an extended context.

* editing/VisibleUnits.cpp:
(WebCore::rangeExpandedByCharactersInDirectionAtWordBoundary):
* editing/VisibleUnits.h:
* editing/cocoa/DataDetection.h:
* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::requiresExtendedContext):

Source/WebKit2:

Data detector results for items like calendar events, can be augmented
retrieving the text surrounding the link.

* Platform/spi/ios/DataDetectorsUISPI.h:
* Shared/ios/InteractionInformationAtPosition.h:
* Shared/ios/InteractionInformationAtPosition.mm:
(WebKit::InteractionInformationAtPosition::encode):
(WebKit::InteractionInformationAtPosition::decode):
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant showDataDetectorsSheet]):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _dataForPreviewItemController:atPosition:type:]):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPositionInformation):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197915 => 197916)


--- trunk/Source/WebCore/ChangeLog	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebCore/ChangeLog	2016-03-10 02:05:49 UTC (rev 197916)
@@ -1,3 +1,23 @@
+2016-03-09  Enrica Casucci  <[email protected]>
+
+        Retrieve additional context for some data detector link for preview and action menu.
+        https://bugs.webkit.org/show_bug.cgi?id=155278
+        rdar://problem/24884951
+
+        Reviewed by Tim Horton.
+
+        Adding helper function to compute a range by moving by a number of characters
+        from a given position and direction.
+        Adding function to check if the given data detector link element requires
+        an extended context.
+
+        * editing/VisibleUnits.cpp:
+        (WebCore::rangeExpandedByCharactersInDirectionAtWordBoundary):
+        * editing/VisibleUnits.h:
+        * editing/cocoa/DataDetection.h:
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::DataDetection::requiresExtendedContext):
+
 2016-03-09  Daniel Bates  <[email protected]>
 
         Fix the Windows build after <https://trac.webkit.org/changeset/197905>

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (197915 => 197916)


--- trunk/Source/WebCore/editing/VisibleUnits.cpp	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp	2016-03-10 02:05:49 UTC (rev 197916)
@@ -1983,6 +1983,25 @@
     return result;
 }
 
+PassRefPtr<Range> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition& position, int numberOfCharactersToExpand, SelectionDirection direction)
+{
+    Position start = position.deepEquivalent();
+    Position end = position.deepEquivalent();
+    for (int i = 0; i < numberOfCharactersToExpand; ++i) {
+        if (direction == DirectionBackward)
+            start = start.previous(Character);
+        else
+            end = end.next(Character);
+    }
+    
+    if (direction == DirectionBackward && !atBoundaryOfGranularity(start, WordGranularity, DirectionBackward))
+        start = startOfWord(start).deepEquivalent();
+    if (direction == DirectionForward && !atBoundaryOfGranularity(end, WordGranularity, DirectionForward))
+        end = endOfWord(end).deepEquivalent();
+
+    return makeRange(start, end);
+}    
+
 PassRefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand)
 {
     Position start = position.deepEquivalent();

Modified: trunk/Source/WebCore/editing/VisibleUnits.h (197915 => 197916)


--- trunk/Source/WebCore/editing/VisibleUnits.h	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebCore/editing/VisibleUnits.h	2016-03-10 02:05:49 UTC (rev 197916)
@@ -108,6 +108,7 @@
 WEBCORE_EXPORT VisiblePosition closestWordBoundaryForPosition(const VisiblePosition& position);
 WEBCORE_EXPORT void charactersAroundPosition(const VisiblePosition&, UChar32& oneAfter, UChar32& oneBefore, UChar32& twoBefore);
 WEBCORE_EXPORT PassRefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition&, int numberOfCharactersToExpand);
+WEBCORE_EXPORT PassRefPtr<Range> rangeExpandedByCharactersInDirectionAtWordBoundary(const VisiblePosition&, int numberOfCharactersToExpand, SelectionDirection);
 
 // helper function
 enum BoundarySearchContextAvailability { DontHaveMoreContext, MayHaveMoreContext };

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.h (197915 => 197916)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.h	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.h	2016-03-10 02:05:49 UTC (rev 197916)
@@ -60,6 +60,7 @@
     WEBCORE_EXPORT static bool isDataDetectorLink(Element*);
     WEBCORE_EXPORT static String dataDetectorIdentifier(Element*);
     WEBCORE_EXPORT static bool shouldCancelDefaultAction(Element*);
+    WEBCORE_EXPORT static bool requiresExtendedContext(Element*);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (197915 => 197916)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2016-03-10 02:05:49 UTC (rev 197916)
@@ -56,6 +56,11 @@
     return element->getAttribute(dataDetectorsURLScheme) == "true";
 }
 
+bool DataDetection::requiresExtendedContext(Element* element)
+{
+    return element->getAttribute(dataDetectorsAttributeTypeKey) == "calendar-event";
+}
+
 String DataDetection::dataDetectorIdentifier(Element* element)
 {
     return element->getAttribute(dataDetectorsAttributeResultKey);

Modified: trunk/Source/WebKit2/ChangeLog (197915 => 197916)


--- trunk/Source/WebKit2/ChangeLog	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-10 02:05:49 UTC (rev 197916)
@@ -1,3 +1,26 @@
+2016-03-09  Enrica Casucci  <[email protected]>
+
+        Retrieve additional context for some data detector link for preview and action menu.
+        https://bugs.webkit.org/show_bug.cgi?id=155278
+        rdar://problem/24884951
+
+        Reviewed by Tim Horton.
+
+        Data detector results for items like calendar events, can be augmented
+        retrieving the text surrounding the link.
+
+        * Platform/spi/ios/DataDetectorsUISPI.h:
+        * Shared/ios/InteractionInformationAtPosition.h:
+        * Shared/ios/InteractionInformationAtPosition.mm:
+        (WebKit::InteractionInformationAtPosition::encode):
+        (WebKit::InteractionInformationAtPosition::decode):
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant showDataDetectorsSheet]):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _dataForPreviewItemController:atPosition:type:]):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::getPositionInformation):
+
 2016-03-09  Gavin Barraclough  <[email protected]>
 
         Last opened tab does not receive SetHiddenPageTimerThrottlingIncreaseLimit message

Modified: trunk/Source/WebKit2/Platform/spi/ios/DataDetectorsUISPI.h (197915 => 197916)


--- trunk/Source/WebKit2/Platform/spi/ios/DataDetectorsUISPI.h	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/Platform/spi/ios/DataDetectorsUISPI.h	2016-03-10 02:05:49 UTC (rev 197916)
@@ -63,3 +63,5 @@
 
 SOFT_LINK_PRIVATE_FRAMEWORK(DataDetectorsUI)
 SOFT_LINK_CLASS(DataDetectorsUI, DDDetectionController)
+SOFT_LINK_CONSTANT(DataDetectorsUI, kDataDetectorsLeadingText, const NSString *)
+SOFT_LINK_CONSTANT(DataDetectorsUI, kDataDetectorsTrailingText, const NSString *)

Modified: trunk/Source/WebKit2/Shared/ios/InteractionInformationAtPosition.h (197915 => 197916)


--- trunk/Source/WebKit2/Shared/ios/InteractionInformationAtPosition.h	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/Shared/ios/InteractionInformationAtPosition.h	2016-03-10 02:05:49 UTC (rev 197916)
@@ -56,6 +56,8 @@
     String title;
     WebCore::IntRect bounds;
     RefPtr<ShareableBitmap> image;
+    String textBefore;
+    String textAfter;
 
     WebCore::TextIndicatorData linkIndicator;
 #if ENABLE(DATA_DETECTION)

Modified: trunk/Source/WebKit2/Shared/ios/InteractionInformationAtPosition.mm (197915 => 197916)


--- trunk/Source/WebKit2/Shared/ios/InteractionInformationAtPosition.mm	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/Shared/ios/InteractionInformationAtPosition.mm	2016-03-10 02:05:49 UTC (rev 197916)
@@ -55,6 +55,8 @@
     encoder << imageURL;
     encoder << title;
     encoder << bounds;
+    encoder << textBefore;
+    encoder << textAfter;
     encoder << linkIndicator;
 
     ShareableBitmap::Handle handle;
@@ -120,6 +122,12 @@
     if (!decoder.decode(result.bounds))
         return false;
 
+    if (!decoder.decode(result.textBefore))
+        return false;
+    
+    if (!decoder.decode(result.textAfter))
+        return false;
+    
     if (!decoder.decode(result.linkIndicator))
         return false;
 

Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (197915 => 197916)


--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm	2016-03-10 02:05:49 UTC (rev 197916)
@@ -436,11 +436,22 @@
     if ([controller respondsToSelector:@selector(actionsForURL:identifier:selectedText:results:context:)]) {
         NSDictionary *context = nil;
         NSString *textAtSelection = nil;
+        RetainPtr<NSMutableDictionary> extendedContext;
 
         if ([delegate respondsToSelector:@selector(dataDetectionContextForActionSheetAssistant:)])
             context = [delegate dataDetectionContextForActionSheetAssistant:self];
         if ([delegate respondsToSelector:@selector(selectedTextForActionSheetAssistant:)])
             textAtSelection = [delegate selectedTextForActionSheetAssistant:self];
+        if (!positionInformation.textBefore.isEmpty() || !positionInformation.textAfter.isEmpty()) {
+            extendedContext = adoptNS([@{
+                getkDataDetectorsLeadingText() : positionInformation.textBefore,
+                getkDataDetectorsTrailingText() : positionInformation.textAfter,
+            } mutableCopy]);
+            
+            if (context)
+                [extendedContext addEntriesFromDictionary:context];
+            context = extendedContext.get();
+        }
         dataDetectorsActions = [controller actionsForURL:targetURL identifier:positionInformation.dataDetectorIdentifier selectedText:textAtSelection results:positionInformation.dataDetectorResults.get() context:context];
     } else
         dataDetectorsActions = [controller actionsForAnchor:nil url:targetURL forFrame:nil];

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (197915 => 197916)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2016-03-10 02:05:49 UTC (rev 197916)
@@ -3829,9 +3829,20 @@
             DDDetectionController *controller = [getDDDetectionControllerClass() sharedController];
             if ([controller respondsToSelector:@selector(resultForURL:identifier:selectedText:results:context:extendedContext:)]) {
                 NSDictionary *newContext = nil;
+                RetainPtr<NSMutableDictionary> extendedContext;
                 DDResultRef ddResult = [controller resultForURL:dataForPreview[UIPreviewDataLink] identifier:_positionInformation.dataDetectorIdentifier selectedText:[self selectedText] results:_positionInformation.dataDetectorResults.get() context:context extendedContext:&newContext];
                 if (ddResult)
                     dataForPreview[UIPreviewDataDDResult] = (__bridge id)ddResult;
+                if (!_positionInformation.textBefore.isEmpty() || !_positionInformation.textAfter.isEmpty()) {
+                    extendedContext = adoptNS([@{
+                        getkDataDetectorsLeadingText() : _positionInformation.textBefore,
+                        getkDataDetectorsTrailingText() : _positionInformation.textAfter,
+                    } mutableCopy]);
+                    
+                    if (newContext)
+                        [extendedContext addEntriesFromDictionary:newContext];
+                    newContext = extendedContext.get();
+                }
                 if (newContext)
                     dataForPreview[UIPreviewDataDDContext] = newContext;
             }

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (197915 => 197916)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-03-10 02:04:20 UTC (rev 197915)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-03-10 02:05:49 UTC (rev 197916)
@@ -2200,8 +2200,15 @@
 #if ENABLE(DATA_DETECTION)
                     info.isDataDetectorLink = DataDetection::isDataDetectorLink(element);
                     if (info.isDataDetectorLink) {
+                        const int dataDetectionExtendedContextLength = 350;
                         info.dataDetectorIdentifier = DataDetection::dataDetectorIdentifier(element);
                         info.dataDetectorResults = element->document().frame()->dataDetectionResults();
+                        if (DataDetection::requiresExtendedContext(element)) {
+                            RefPtr<Range> linkRange = Range::create(element->document());
+                            linkRange->selectNodeContents(element, ASSERT_NO_EXCEPTION);
+                            info.textBefore = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->startPosition(), dataDetectionExtendedContextLength, DirectionBackward).get(), TextIteratorDefaultBehavior, true);
+                            info.textAfter = plainTextReplacingNoBreakSpace(rangeExpandedByCharactersInDirectionAtWordBoundary(linkRange->endPosition(), dataDetectionExtendedContextLength, DirectionForward).get(), TextIteratorDefaultBehavior, true);
+                        }
                     }
 #endif
                 } else if (element->renderer() && element->renderer()->isRenderImage()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to