Preview on apple.com/contact with all text selected shows a map
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Nov 2015 00:38:32 +0000 (00:38 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Nov 2015 00:38:32 +0000 (00:38 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192089 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/mac/DictionaryLookup.h
Source/WebCore/editing/mac/DictionaryLookup.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index dd45784..4e304fa 100644 (file)
@@ -1,3 +1,21 @@
+2015-11-05  Tim Horton  <timothy_horton@apple.com>
+
+        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  <beidson@apple.com>
 
         Modern IDB: Implement IDBIndex get/getKey/count requests.
index 11ada16..861417a 100644 (file)
@@ -48,11 +48,12 @@ namespace WebCore {
 
 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);
 
index 01760ab..b7166aa 100644 (file)
@@ -65,7 +65,7 @@ static bool selectionContainsPosition(const VisiblePosition& position, const Vis
     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 @@ PassRefPtr<Range> DictionaryLookup::rangeForSelection(const VisibleSelection& se
     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 @@ PassRefPtr<Range> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hi
 
     // 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);
index 85c57d0..7a0ddd4 100644 (file)
@@ -1,3 +1,15 @@
+2015-11-05  Tim Horton  <timothy_horton@apple.com>
+
+        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  <ggaren@apple.com>
 
         _WKObservablePageState's _webProcessIsResponsive property isn't set to YES when an unresponsive page is reloaded
index 0542f91..f3af922 100644 (file)
@@ -519,7 +519,7 @@ void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
 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);
 }