Title: [192089] trunk/Source
Revision
192089
Author
[email protected]
Date
2015-11-05 16:38:32 -0800 (Thu, 05 Nov 2015)

Log Message

Preview on apple.com/contact with all text selected shows a map
https://bugs.webkit.org/show_bug.cgi?id=150963
<rdar://problem/23421750>

Reviewed by Beth Dakin.

* editing/mac/DictionaryLookup.h:
* editing/mac/DictionaryLookup.mm:
(WebCore::DictionaryLookup::rangeForSelection):
If the range that Lookup decides to use doesn't intersect the hit point,
just ignore Lookup.

(WebCore::DictionaryLookup::rangeAtHitTestResult):
If the selection-based Lookup fails to find a usable result, fall back
to looking around the hit point.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupForSelection):
In this case, we don't know where we hit, so pass a null VisiblePosition.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (192088 => 192089)


--- trunk/Source/WebCore/ChangeLog	2015-11-06 00:13:57 UTC (rev 192088)
+++ trunk/Source/WebCore/ChangeLog	2015-11-06 00:38:32 UTC (rev 192089)
@@ -1,3 +1,21 @@
+2015-11-05  Tim Horton  <[email protected]>
+
+        Preview on apple.com/contact with all text selected shows a map
+        https://bugs.webkit.org/show_bug.cgi?id=150963
+        <rdar://problem/23421750>
+
+        Reviewed by Beth Dakin.
+
+        * editing/mac/DictionaryLookup.h:
+        * editing/mac/DictionaryLookup.mm:
+        (WebCore::DictionaryLookup::rangeForSelection):
+        If the range that Lookup decides to use doesn't intersect the hit point,
+        just ignore Lookup.
+
+        (WebCore::DictionaryLookup::rangeAtHitTestResult):
+        If the selection-based Lookup fails to find a usable result, fall back
+        to looking around the hit point.
+
 2015-11-05  Brady Eidson  <[email protected]>
 
         Modern IDB: Implement IDBIndex get/getKey/count requests.

Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (192088 => 192089)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2015-11-06 00:13:57 UTC (rev 192088)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2015-11-06 00:38:32 UTC (rev 192089)
@@ -48,11 +48,12 @@
 
 class HitTestResult;
 class Range;
+class VisiblePosition;
 class VisibleSelection;
 
 class DictionaryLookup {
 public:
-    WEBCORE_EXPORT static PassRefPtr<Range> rangeForSelection(const VisibleSelection&, NSDictionary **options);
+    WEBCORE_EXPORT static PassRefPtr<Range> rangeForSelection(const VisibleSelection&, const VisiblePosition& hitPosition, NSDictionary **options);
     WEBCORE_EXPORT static PassRefPtr<Range> rangeAtHitTestResult(const HitTestResult&, NSDictionary **options);
     WEBCORE_EXPORT static NSString *stringForPDFSelection(PDFSelection *, NSDictionary **options);
 

Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.mm (192088 => 192089)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2015-11-06 00:13:57 UTC (rev 192088)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2015-11-06 00:38:32 UTC (rev 192089)
@@ -65,7 +65,7 @@
     return selectedRange->contains(position);
 }
 
-PassRefPtr<Range> DictionaryLookup::rangeForSelection(const VisibleSelection& selection, NSDictionary **options)
+PassRefPtr<Range> DictionaryLookup::rangeForSelection(const VisibleSelection& selection, const VisiblePosition& hitPosition, NSDictionary **options)
 {
     RefPtr<Range> selectedRange = selection.toNormalizedRange();
     if (!selectedRange)
@@ -82,12 +82,23 @@
     int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get());
     NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart);
 
-    String fullPlainTextString = plainText(makeRange(paragraphStart, paragraphEnd).get());
+    RefPtr<Range> fullRange = makeRange(paragraphStart, paragraphEnd);
+    if (!fullRange)
+        return nullptr;
 
+    String fullPlainTextString = plainText(fullRange.get());
+
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     // Since we already have the range we want, we just need to grab the returned options.
-    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass())
-        [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
+    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass()) {
+        NSRange extractedRange = [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
+        if (extractedRange.location == NSNotFound)
+            return nullptr;
+
+        RefPtr<Range> lookupRange = TextIterator::subrange(fullRange.get(), extractedRange.location, extractedRange.length);
+        if (!lookupRange || (hitPosition.isNotNull() && !lookupRange->contains(hitPosition)))
+            return nullptr;
+    }
     END_BLOCK_OBJC_EXCEPTIONS;
 
     return selectedRange.release();
@@ -118,8 +129,10 @@
 
     // If we hit the selection, use that instead of letting Lookup decide the range.
     VisibleSelection selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
-    if (selectionContainsPosition(position, selection))
-        return DictionaryLookup::rangeForSelection(selection, options);
+    if (selectionContainsPosition(position, selection)) {
+        if (auto rangeForSelection = DictionaryLookup::rangeForSelection(selection, position, options))
+            return rangeForSelection;
+    }
 
     VisibleSelection selectionAccountingForLineRules = VisibleSelection(position);
     selectionAccountingForLineRules.expandUsingGranularity(WordGranularity);

Modified: trunk/Source/WebKit2/ChangeLog (192088 => 192089)


--- trunk/Source/WebKit2/ChangeLog	2015-11-06 00:13:57 UTC (rev 192088)
+++ trunk/Source/WebKit2/ChangeLog	2015-11-06 00:38:32 UTC (rev 192089)
@@ -1,3 +1,15 @@
+2015-11-05  Tim Horton  <[email protected]>
+
+        Preview on apple.com/contact with all text selected shows a map
+        https://bugs.webkit.org/show_bug.cgi?id=150963
+        <rdar://problem/23421750>
+
+        Reviewed by Beth Dakin.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupForSelection):
+        In this case, we don't know where we hit, so pass a null VisiblePosition.
+
 2015-11-05  Geoffrey Garen  <[email protected]>
 
         _WKObservablePageState's _webProcessIsResponsive property isn't set to YES when an unresponsive page is reloaded

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (192088 => 192089)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-11-06 00:13:57 UTC (rev 192088)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-11-06 00:38:32 UTC (rev 192089)
@@ -519,7 +519,7 @@
 void WebPage::performDictionaryLookupForSelection(Frame* frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
 {
     NSDictionary *options = nil;
-    RefPtr<Range> selectedRange = DictionaryLookup::rangeForSelection(selection, &options);
+    RefPtr<Range> selectedRange = DictionaryLookup::rangeForSelection(selection, { }, &options);
     if (selectedRange)
         performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to