Title: [176137] trunk/Source
Revision
176137
Author
timothy_hor...@apple.com
Date
2014-11-14 13:33:03 -0800 (Fri, 14 Nov 2014)

Log Message

Move DataDetectors scanning code to WebCore
https://bugs.webkit.org/show_bug.cgi?id=138731
<rdar://problem/18877535>

Reviewed by Anders Carlsson.

Move DataDetectors scanning code to WebCore, so that both WebKits can use it.

* Shared/TextIndicator.cpp:
(WebKit::TextIndicator::createWithRange):
Move createWithRange in from WebPageMac's textIndicatorForRange.

(WebKit::TextIndicator::createWithSelectionInFrame):
* Shared/TextIndicator.h:
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::createSelectionSnapshot):
* WebProcess/WebPage/WebFrame.h:
Constify some things.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performActionMenuHitTestAtLocation):
Avoid using the DD result if it didn't come with a non-null Range.
Make use of detectItemAroundHitTestResult and TextIndicator::createWithRange.

(WebKit::scanForDataDetectedItems): Deleted.
(WebKit::textIndicatorForRange): Deleted.
Moved these two to other places.

* WebCore.exp.in:
Export our new function.

* WebCore.xcodeproj/project.pbxproj:
Add DataDetection.{mm, h}
Adjust the project so that editing/mac actually points to editing/mac instead of editing/

* editing/mac/DictionaryLookup.h:
* editing/mac/DictionaryLookup.mm:
Swap to PLATFORM(MAC) instead of !PLATFORM(IOS).
Move DictionaryLookup.{mm, h} to editing/mac, where they were in the project but not on disk.

* editing/mac/DataDetection.h: Added.
* editing/mac/DataDetection.mm: Added.
(WebCore::DataDetection::detectItemAroundHitTestResult):
Moved from WebKit2.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176136 => 176137)


--- trunk/Source/WebCore/ChangeLog	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebCore/ChangeLog	2014-11-14 21:33:03 UTC (rev 176137)
@@ -1,3 +1,28 @@
+2014-11-14  Tim Horton  <timothy_hor...@apple.com>
+
+        Move DataDetectors scanning code to WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=138731
+        <rdar://problem/18877535>
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.exp.in:
+        Export our new function.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Add DataDetection.{mm, h}
+        Adjust the project so that editing/mac actually points to editing/mac instead of editing/
+
+        * editing/mac/DictionaryLookup.h:
+        * editing/mac/DictionaryLookup.mm:
+        Swap to PLATFORM(MAC) instead of !PLATFORM(IOS).
+        Move DictionaryLookup.{mm, h} to editing/mac, where they were in the project but not on disk.
+
+        * editing/mac/DataDetection.h: Added.
+        * editing/mac/DataDetection.mm: Added.
+        (WebCore::DataDetection::detectItemAroundHitTestResult):
+        Moved from WebKit2.
+
 2014-11-14  Dan Bernstein  <m...@apple.com>
 
         <rdar://problem/18978497> Wrong (off-by-1) navigation snapshots shown after a mix of gesture and button back/forward navigation

Modified: trunk/Source/WebCore/WebCore.exp.in (176136 => 176137)


--- trunk/Source/WebCore/WebCore.exp.in	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-11-14 21:33:03 UTC (rev 176137)
@@ -288,6 +288,7 @@
 __ZN7WebCore13CharacterData7setDataERKN3WTF6StringERi
 __ZN7WebCore13ContainerNode11appendChildEN3WTF10PassRefPtrINS_4NodeEEERi
 __ZN7WebCore13ContainerNode11removeChildEPNS_4NodeERi
+__ZN7WebCore13DataDetection29detectItemAroundHitTestResultERKNS_13HitTestResultERNS_9FloatRectERN3WTF6RefPtrINS_5RangeEEE
 __ZN7WebCore13GraphicsLayer11setChildrenERKN3WTF6VectorIPS0_Lm0ENS1_15CrashOnOverflowEEE
 __ZN7WebCore13GraphicsLayer12replaceChildEPS0_S1_
 __ZN7WebCore13GraphicsLayer12setZPositionEf
@@ -2404,6 +2405,7 @@
 __ZN7WebCore6Editor34isAutomaticDashSubstitutionEnabledEv
 __ZN7WebCore6Editor35isAutomaticQuoteSubstitutionEnabledEv
 __ZN7WebCore6Editor36isAutomaticSpellingCorrectionEnabledEv
+__ZN7WebCore6Editor9copyImageERKNS_13HitTestResultE
 __ZN7WebCore6Widget17setPlatformWidgetEP6NSView
 __ZN7WebCore6WidgetC2EP6NSView
 __ZN7WebCore7nsColorERKNS_5ColorE
@@ -2507,10 +2509,6 @@
 _wkCreateMemoryStatusPressureCriticalDispatchOnMainQueue
 #endif
 
-#if !PLATFORM(IOS)
-__ZN7WebCore6Editor9copyImageERKNS_13HitTestResultE
-#endif
-
 #if PLATFORM(IOS)
 .objc_class_name_NSCursor
 .objc_class_name_WAKClipView

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (176136 => 176137)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-11-14 21:33:03 UTC (rev 176137)
@@ -1102,6 +1102,8 @@
 		2D481F02146B5C5500AA7834 /* CrossfadeGeneratedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */; };
 		2D481F03146B5C6500AA7834 /* GradientImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D2FC0561460CD6F00263633 /* GradientImage.cpp */; };
 		2D481F04146B5C6B00AA7834 /* GradientImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2FC0571460CD6F00263633 /* GradientImage.h */; };
+		2D58D8551A15F65F00A5F726 /* DataDetection.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D58D8531A15F65F00A5F726 /* DataDetection.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		2D58D8561A15F65F00A5F726 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D58D8541A15F65F00A5F726 /* DataDetection.mm */; };
 		2D59F1BF1A0044C6001F3D29 /* DataDetectorsSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D5A592F152525230036EE51 /* ImageOrientation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8748D7412CC3F89001FBA41 /* ImageOrientation.cpp */; };
 		2D5A5931152525D00036EE51 /* ImageOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = A8748D6612CC3763001FBA41 /* ImageOrientation.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8031,7 +8033,7 @@
 		293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeApplicationChecks.h; sourceTree = "<group>"; };
 		293EAE201356B32E0067ACF9 /* RuntimeApplicationChecks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeApplicationChecks.cpp; sourceTree = "<group>"; };
 		29489FC512C00F0300D83F0F /* AccessibilityScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityScrollView.h; sourceTree = "<group>"; };
-		29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TextUndoInsertionMarkupMac.mm; path = mac/TextUndoInsertionMarkupMac.mm; sourceTree = "<group>"; };
+		29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextUndoInsertionMarkupMac.mm; sourceTree = "<group>"; };
 		297BE3D916C043D8003316BD /* PlatformSpeechSynthesizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformSpeechSynthesizer.cpp; sourceTree = "<group>"; };
 		2981CA9D131822EC00D12F2A /* AccessibilityARIAGrid.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityARIAGrid.cpp; sourceTree = "<group>"; };
 		2981CA9E131822EC00D12F2A /* AccessibilityARIAGridCell.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityARIAGridCell.cpp; sourceTree = "<group>"; };
@@ -8080,7 +8082,7 @@
 		29E04A27BED2F81F98E9022B /* JSBeforeUnloadEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBeforeUnloadEvent.h; sourceTree = "<group>"; };
 		29E4D8DF16B0940F00C84704 /* PlatformSpeechSynthesizer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformSpeechSynthesizer.h; sourceTree = "<group>"; };
 		29E4D8E016B0959800C84704 /* PlatformSpeechSynthesizerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformSpeechSynthesizerMac.mm; sourceTree = "<group>"; };
-		29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextUndoInsertionMarkupMac.h; path = mac/TextUndoInsertionMarkupMac.h; sourceTree = "<group>"; };
+		29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextUndoInsertionMarkupMac.h; sourceTree = "<group>"; };
 		2B42359F15250F6000DBBCD8 /* RenderSVGEllipse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGEllipse.cpp; sourceTree = "<group>"; };
 		2B4235A015250F6000DBBCD8 /* RenderSVGEllipse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGEllipse.h; sourceTree = "<group>"; };
 		2BE8E2C612A589EC00FAD550 /* HTMLMetaCharsetParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLMetaCharsetParser.h; path = parser/HTMLMetaCharsetParser.h; sourceTree = "<group>"; };
@@ -8105,6 +8107,8 @@
 		2D3EF4471917915C00034184 /* WebCoreCALayerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreCALayerExtras.mm; sourceTree = "<group>"; };
 		2D46F04D17B96FBD005647F0 /* IntPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntPoint.cpp; sourceTree = "<group>"; };
 		2D46F04F17B96FD2005647F0 /* IntSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntSize.cpp; sourceTree = "<group>"; };
+		2D58D8531A15F65F00A5F726 /* DataDetection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetection.h; sourceTree = "<group>"; };
+		2D58D8541A15F65F00A5F726 /* DataDetection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetection.mm; sourceTree = "<group>"; };
 		2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsSPI.h; sourceTree = "<group>"; };
 		2D5BC42516F882BE007048D0 /* SecurityPolicyViolationEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecurityPolicyViolationEvent.h; sourceTree = "<group>"; };
 		2D5BC42616F882BE007048D0 /* SecurityPolicyViolationEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SecurityPolicyViolationEvent.idl; sourceTree = "<group>"; };
@@ -8821,7 +8825,7 @@
 		4A6E9FC213C17D1D0046A7F8 /* CSSFontFeatureValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFeatureValue.h; sourceTree = "<group>"; };
 		4A6E9FC513C17D570046A7F8 /* FontFeatureSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFeatureSettings.cpp; sourceTree = "<group>"; };
 		4A6E9FC613C17D570046A7F8 /* FontFeatureSettings.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = FontFeatureSettings.h; sourceTree = "<group>"; };
-		4A8C96EA0BE69032004EEFF0 /* FrameSelectionMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = FrameSelectionMac.mm; path = mac/FrameSelectionMac.mm; sourceTree = "<group>"; };
+		4A8C96EA0BE69032004EEFF0 /* FrameSelectionMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameSelectionMac.mm; sourceTree = "<group>"; };
 		4A9755351858ED9B00BD6D15 /* RTCPeerConnectionErrorCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCPeerConnectionErrorCallback.h; sourceTree = "<group>"; };
 		4A9755361858ED9B00BD6D15 /* RTCPeerConnectionErrorCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCPeerConnectionErrorCallback.idl; sourceTree = "<group>"; };
 		4A9CC81516BB9AC600EC645A /* CSSDefaultStyleSheets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSDefaultStyleSheets.cpp; sourceTree = "<group>"; };
@@ -13227,10 +13231,10 @@
 		CE08C3D0152B599A0021B8C2 /* AlternativeTextController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlternativeTextController.h; sourceTree = "<group>"; };
 		CE5CB1B314EDAB6F00BB2795 /* EventSender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventSender.h; sourceTree = "<group>"; };
 		CE6D89294C7AACE0AD89B3DD /* MathMLMencloseElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLMencloseElement.h; sourceTree = "<group>"; };
-		CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AlternativeTextUIController.h; path = mac/AlternativeTextUIController.h; sourceTree = "<group>"; };
-		CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AlternativeTextUIController.mm; path = mac/AlternativeTextUIController.mm; sourceTree = "<group>"; };
-		CE7B2DB11586ABAD0098B3FA /* TextAlternativeWithRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextAlternativeWithRange.h; path = mac/TextAlternativeWithRange.h; sourceTree = "<group>"; };
-		CE7B2DB21586ABAD0098B3FA /* TextAlternativeWithRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TextAlternativeWithRange.mm; path = mac/TextAlternativeWithRange.mm; sourceTree = "<group>"; };
+		CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlternativeTextUIController.h; sourceTree = "<group>"; };
+		CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AlternativeTextUIController.mm; sourceTree = "<group>"; };
+		CE7B2DB11586ABAD0098B3FA /* TextAlternativeWithRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextAlternativeWithRange.h; sourceTree = "<group>"; };
+		CE7B2DB21586ABAD0098B3FA /* TextAlternativeWithRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextAlternativeWithRange.mm; sourceTree = "<group>"; };
 		CE8245EF19B671BA00AC0122 /* CFNetworkConnectionCacheSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFNetworkConnectionCacheSPI.h; sourceTree = "<group>"; };
 		CE8245F119B671D500AC0122 /* CFURLRequestSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLRequestSPI.h; sourceTree = "<group>"; };
 		CECADFC2153778FF00E37068 /* DictationAlternative.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DictationAlternative.cpp; sourceTree = "<group>"; };
@@ -13728,7 +13732,7 @@
 		EBF5121A1696496C0056BD25 /* JSTypeConversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypeConversions.cpp; sourceTree = "<group>"; };
 		EBF5121B1696496C0056BD25 /* JSTypeConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypeConversions.h; sourceTree = "<group>"; };
 		ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentMarker.h; sourceTree = "<group>"; };
-		ED501DC50B249F2900AE18D9 /* EditorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = EditorMac.mm; path = mac/EditorMac.mm; sourceTree = "<group>"; };
+		ED501DC50B249F2900AE18D9 /* EditorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = EditorMac.mm; sourceTree = "<group>"; };
 		EDE3A4FF0C7A430600956A37 /* ColorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorMac.h; sourceTree = "<group>"; };
 		EDEC98020AED7E170059137F /* WebCorePrefix.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCorePrefix.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
 		F12171F316A8BC63000053CA /* WebVTTElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebVTTElement.cpp; sourceTree = "<group>"; };
@@ -21938,6 +21942,8 @@
 			children = (
 				CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */,
 				CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
+				2D58D8531A15F65F00A5F726 /* DataDetection.h */,
+				2D58D8541A15F65F00A5F726 /* DataDetection.mm */,
 				937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */,
 				937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
 				ED501DC50B249F2900AE18D9 /* EditorMac.mm */,
@@ -21947,7 +21953,7 @@
 				29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */,
 				29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */,
 			);
-			name = mac;
+			path = mac;
 			sourceTree = "<group>";
 		};
 		F523D18402DE42E8018635CA /* css */ = {
@@ -26291,6 +26297,7 @@
 				B2227A880D00BF220071B782 /* SVGPatternElement.h in Headers */,
 				B2227A8C0D00BF220071B782 /* SVGPointList.h in Headers */,
 				B2227A8F0D00BF220071B782 /* SVGPolyElement.h in Headers */,
+				2D58D8551A15F65F00A5F726 /* DataDetection.h in Headers */,
 				B2227A910D00BF220071B782 /* SVGPolygonElement.h in Headers */,
 				B2227A940D00BF220071B782 /* SVGPolylineElement.h in Headers */,
 				B2227A970D00BF220071B782 /* SVGPreserveAspectRatio.h in Headers */,
@@ -29408,6 +29415,7 @@
 				84A81F410FC7E02700955300 /* SourceGraphic.cpp in Sources */,
 				076306D717E149CF005A7C4E /* SourceInfo.cpp in Sources */,
 				536D5A25193F40FC00CE4CAB /* SourceSizeList.cpp in Sources */,
+				2D58D8561A15F65F00A5F726 /* DataDetection.mm in Sources */,
 				D01A27AD10C9BFD800026A42 /* SpaceSplitString.cpp in Sources */,
 				626CDE0E1140424C001E5A68 /* SpatialNavigation.cpp in Sources */,
 				AA2A5AD516A4861400975A25 /* SpeechSynthesis.cpp in Sources */,

Deleted: trunk/Source/WebCore/editing/DictionaryLookup.h (176136 => 176137)


--- trunk/Source/WebCore/editing/DictionaryLookup.h	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebCore/editing/DictionaryLookup.h	2014-11-14 21:33:03 UTC (rev 176137)
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef DictionaryLookup_h
-#define DictionaryLookup_h
-
-#if !PLATFORM(IOS)
-
-#include <wtf/PassRefPtr.h>
-
-@class NSDictionary;
-
-namespace WebCore {
-
-class HitTestResult;
-class Range;
-class VisiblePosition;
-class VisibleSelection;
-
-// FIXME: Some of these functions should probably be in a more generic class.
-// https://bugs.webkit.org/show_bug.cgi?id=138567
-bool isPositionInRange(const VisiblePosition&, Range*);
-bool shouldUseSelection(const VisiblePosition&, const VisibleSelection&);
-
-PassRefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition&, int numberOfCharactersToExpand);
-PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection&, NSDictionary **options);
-PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult&, NSDictionary **options);
-
-} // namespace WebCore
-
-#endif // !PLATFORM(IOS)
-
-#endif // DictionaryLookup_h

Deleted: trunk/Source/WebCore/editing/DictionaryLookup.mm (176136 => 176137)


--- trunk/Source/WebCore/editing/DictionaryLookup.mm	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebCore/editing/DictionaryLookup.mm	2014-11-14 21:33:03 UTC (rev 176137)
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "DictionaryLookup.h"
-
-#if !PLATFORM(IOS)
-
-#import "Document.h"
-#import "FocusController.h"
-#import "Frame.h"
-#import "FrameSelection.h"
-#import "HTMLConverter.h"
-#import "HitTestResult.h"
-#import "Page.h"
-#import "Range.h"
-#import "RenderObject.h"
-#import "TextIterator.h"
-#import "VisiblePosition.h"
-#import "VisibleSelection.h"
-#import "VisibleUnits.h"
-#import "WebCoreSystemInterface.h"
-#import "htmlediting.h"
-#import <wtf/RefPtr.h>
-
-namespace WebCore {
-
-bool isPositionInRange(const VisiblePosition& position, Range* range)
-{
-    RefPtr<Range> positionRange = makeRange(position, position);
-
-    ExceptionCode ec = 0;
-    range->compareBoundaryPoints(Range::START_TO_START, positionRange.get(), ec);
-    if (ec)
-        return false;
-
-    if (!range->isPointInRange(positionRange->startContainer(), positionRange->startOffset(), ec))
-        return false;
-    if (ec)
-        return false;
-
-    return true;
-}
-
-bool shouldUseSelection(const VisiblePosition& position, const VisibleSelection& selection)
-{
-    if (!selection.isRange())
-        return false;
-
-    RefPtr<Range> selectedRange = selection.toNormalizedRange();
-    if (!selectedRange)
-        return false;
-
-    return isPositionInRange(position, selectedRange.get());
-}
-
-PassRefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand)
-{
-    Position start = position.deepEquivalent();
-    Position end = position.deepEquivalent();
-    for (int i = 0; i < numberOfCharactersToExpand; ++i) {
-        if (directionOfEnclosingBlock(start) == LTR)
-            start = start.previous(Character);
-        else
-            start = start.next(Character);
-
-        if (directionOfEnclosingBlock(end) == LTR)
-            end = end.next(Character);
-        else
-            end = end.previous(Character);
-    }
-
-    return makeRange(start, end);
-}
-
-PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection& selection, NSDictionary **options)
-{
-    RefPtr<Range> selectedRange = selection.toNormalizedRange();
-    if (!selectedRange)
-        return nullptr;
-
-    VisiblePosition selectionStart = selection.visibleStart();
-    VisiblePosition selectionEnd = selection.visibleEnd();
-
-    // As context, we are going to use the surrounding paragraphs of text.
-    VisiblePosition paragraphStart = startOfParagraph(selectionStart);
-    VisiblePosition paragraphEnd = endOfParagraph(selectionEnd);
-
-    int lengthToSelectionStart = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
-    int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get());
-    NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart);
-
-    String fullPlainTextString = plainText(makeRange(paragraphStart, paragraphEnd).get());
-
-    // Since we already have the range we want, we just need to grab the returned options.
-    wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
-    
-    return selectedRange.release();
-}
-
-PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult& hitTestResult, NSDictionary **options)
-{
-    Node* node = hitTestResult.innerNonSharedNode();
-    if (!node)
-        return nullptr;
-
-    auto renderer = node->renderer();
-    if (!renderer)
-        return nullptr;
-
-    Frame* frame = node->document().frame();
-    if (!frame)
-        return nullptr;
-
-    // Don't do anything if there is no character at the point.
-    if (!frame->rangeForPoint(hitTestResult.roundedPointInInnerNodeFrame()))
-        return nullptr;
-
-    VisiblePosition position = renderer->positionForPoint(hitTestResult.localPoint(), nullptr);
-    if (position.isNull())
-        position = firstPositionInOrBeforeNode(node);
-
-    VisibleSelection selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
-    if (shouldUseSelection(position, selection))
-        return rangeForDictionaryLookupForSelection(selection, options);
-
-    // As context, we are going to use 250 characters of text before and after the point.
-    RefPtr<Range> fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
-    if (!fullCharacterRange)
-        return nullptr;
-
-    NSRange rangeToPass = NSMakeRange(TextIterator::rangeLength(makeRange(fullCharacterRange->startPosition(), position).get()), 0);
-
-    String fullPlainTextString = plainText(fullCharacterRange.get());
-
-    NSRange extractedRange = wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
-
-    // This function sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
-    if (extractedRange.location == NSNotFound)
-        return nullptr;
-
-    return TextIterator::subrange(fullCharacterRange.get(), extractedRange.location, extractedRange.length);
-}
-
-} // namespace WebCore
-
-#endif // !PLATFORM(IOS)
-

Added: trunk/Source/WebCore/editing/mac/DataDetection.h (0 => 176137)


--- trunk/Source/WebCore/editing/mac/DataDetection.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/mac/DataDetection.h	2014-11-14 21:33:03 UTC (rev 176137)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DataDetection_h
+#define DataDetection_h
+
+#if PLATFORM(MAC)
+
+#import <wtf/RefPtr.h>
+#import <wtf/RetainPtr.h>
+
+OBJC_CLASS DDActionContext;
+
+namespace WebCore {
+
+class FloatRect;
+class HitTestResult;
+class Range;
+
+class DataDetection {
+public:
+    WEBCORE_EXPORT static RetainPtr<DDActionContext> detectItemAroundHitTestResult(const HitTestResult&, FloatRect& detectedDataBoundingBox, RefPtr<Range>& detectedDataRange);
+};
+
+} // namespace WebCore
+
+#endif // PLATFORM(MAC)
+
+#endif // DataDetection_h

Added: trunk/Source/WebCore/editing/mac/DataDetection.mm (0 => 176137)


--- trunk/Source/WebCore/editing/mac/DataDetection.mm	                        (rev 0)
+++ trunk/Source/WebCore/editing/mac/DataDetection.mm	2014-11-14 21:33:03 UTC (rev 176137)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 Apple, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "DataDetection.h"
+
+#import "DataDetectorsSPI.h"
+#import "DictionaryLookup.h"
+#import "FrameView.h"
+#import "HitTestResult.h"
+#import "Node.h"
+#import "Range.h"
+#import "RenderObject.h"
+#import "TextIterator.h"
+#import "VisiblePosition.h"
+#import "htmlediting.h"
+
+namespace WebCore {
+
+RetainPtr<DDActionContext> DataDetection::detectItemAroundHitTestResult(const HitTestResult& hitTestResult, FloatRect& detectedDataBoundingBox, RefPtr<Range>& detectedDataRange)
+{
+    Node* node = hitTestResult.innerNonSharedNode();
+    if (!node)
+        return nullptr;
+    auto renderer = node->renderer();
+    if (!renderer)
+        return nullptr;
+    VisiblePosition position = renderer->positionForPoint(hitTestResult.localPoint(), nullptr);
+    if (position.isNull())
+        position = firstPositionInOrBeforeNode(node);
+
+    RefPtr<Range> contextRange = rangeExpandedAroundPositionByCharacters(position, 250);
+    if (!contextRange)
+        return nullptr;
+
+    String fullPlainTextString = plainText(contextRange.get());
+    int hitLocation = TextIterator::rangeLength(makeRange(contextRange->startPosition(), position).get());
+
+    RetainPtr<DDScannerRef> scanner = adoptCF(DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
+    RetainPtr<DDScanQueryRef> scanQuery = adoptCF(DDScanQueryCreateFromString(kCFAllocatorDefault, fullPlainTextString.createCFString().get(), CFRangeMake(0, fullPlainTextString.length())));
+
+    if (!DDScannerScanQuery(scanner.get(), scanQuery.get()))
+        return nullptr;
+
+    RetainPtr<CFArrayRef> results = adoptCF(DDScannerCopyResultsWithOptions(scanner.get(), DDScannerCopyResultsOptionsNoOverlap));
+
+    // Find the DDResultRef that intersects the hitTestResult's VisiblePosition.
+    DDResultRef mainResult = nullptr;
+    RefPtr<Range> mainResultRange;
+    CFIndex resultCount = CFArrayGetCount(results.get());
+    for (CFIndex i = 0; i < resultCount; i++) {
+        DDResultRef result = (DDResultRef)CFArrayGetValueAtIndex(results.get(), i);
+        CFRange resultRangeInContext = DDResultGetRange(result);
+        if (hitLocation >= resultRangeInContext.location && (hitLocation - resultRangeInContext.location) < resultRangeInContext.length) {
+            mainResult = result;
+            mainResultRange = TextIterator::subrange(contextRange.get(), resultRangeInContext.location, resultRangeInContext.length);
+            break;
+        }
+    }
+
+    if (!mainResult)
+        return nullptr;
+
+    RetainPtr<DDActionContext> actionContext = adoptNS([[getDDActionContextClass() alloc] init]);
+    [actionContext setAllResults:@[ (id)mainResult ]];
+    [actionContext setMainResult:mainResult];
+
+    Vector<FloatQuad> quads;
+    mainResultRange->textQuads(quads);
+    detectedDataBoundingBox = FloatRect();
+    FrameView* frameView = mainResultRange->ownerDocument().view();
+    for (const auto& quad : quads)
+        detectedDataBoundingBox.unite(frameView->contentsToWindow(quad.enclosingBoundingBox()));
+    
+    detectedDataRange = mainResultRange;
+    
+    return actionContext;
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (0 => 176137)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2014-11-14 21:33:03 UTC (rev 176137)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DictionaryLookup_h
+#define DictionaryLookup_h
+
+#if PLATFORM(MAC)
+
+#include <wtf/PassRefPtr.h>
+
+@class NSDictionary;
+
+namespace WebCore {
+
+class HitTestResult;
+class Range;
+class VisiblePosition;
+class VisibleSelection;
+
+// FIXME: Some of these functions should probably be in a more generic class.
+// https://bugs.webkit.org/show_bug.cgi?id=138567
+bool isPositionInRange(const VisiblePosition&, Range*);
+bool shouldUseSelection(const VisiblePosition&, const VisibleSelection&);
+
+PassRefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition&, int numberOfCharactersToExpand);
+PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection&, NSDictionary **options);
+PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult&, NSDictionary **options);
+
+} // namespace WebCore
+
+#endif // PLATFORM(MAC)
+
+#endif // DictionaryLookup_h

Added: trunk/Source/WebCore/editing/mac/DictionaryLookup.mm (0 => 176137)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	                        (rev 0)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2014-11-14 21:33:03 UTC (rev 176137)
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "DictionaryLookup.h"
+
+#if PLATFORM(MAC)
+
+#import "Document.h"
+#import "FocusController.h"
+#import "Frame.h"
+#import "FrameSelection.h"
+#import "HTMLConverter.h"
+#import "HitTestResult.h"
+#import "Page.h"
+#import "Range.h"
+#import "RenderObject.h"
+#import "TextIterator.h"
+#import "VisiblePosition.h"
+#import "VisibleSelection.h"
+#import "VisibleUnits.h"
+#import "WebCoreSystemInterface.h"
+#import "htmlediting.h"
+#import <wtf/RefPtr.h>
+
+namespace WebCore {
+
+bool isPositionInRange(const VisiblePosition& position, Range* range)
+{
+    RefPtr<Range> positionRange = makeRange(position, position);
+
+    ExceptionCode ec = 0;
+    range->compareBoundaryPoints(Range::START_TO_START, positionRange.get(), ec);
+    if (ec)
+        return false;
+
+    if (!range->isPointInRange(positionRange->startContainer(), positionRange->startOffset(), ec))
+        return false;
+    if (ec)
+        return false;
+
+    return true;
+}
+
+bool shouldUseSelection(const VisiblePosition& position, const VisibleSelection& selection)
+{
+    if (!selection.isRange())
+        return false;
+
+    RefPtr<Range> selectedRange = selection.toNormalizedRange();
+    if (!selectedRange)
+        return false;
+
+    return isPositionInRange(position, selectedRange.get());
+}
+
+PassRefPtr<Range> rangeExpandedAroundPositionByCharacters(const VisiblePosition& position, int numberOfCharactersToExpand)
+{
+    Position start = position.deepEquivalent();
+    Position end = position.deepEquivalent();
+    for (int i = 0; i < numberOfCharactersToExpand; ++i) {
+        if (directionOfEnclosingBlock(start) == LTR)
+            start = start.previous(Character);
+        else
+            start = start.next(Character);
+
+        if (directionOfEnclosingBlock(end) == LTR)
+            end = end.next(Character);
+        else
+            end = end.previous(Character);
+    }
+
+    return makeRange(start, end);
+}
+
+PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection& selection, NSDictionary **options)
+{
+    RefPtr<Range> selectedRange = selection.toNormalizedRange();
+    if (!selectedRange)
+        return nullptr;
+
+    VisiblePosition selectionStart = selection.visibleStart();
+    VisiblePosition selectionEnd = selection.visibleEnd();
+
+    // As context, we are going to use the surrounding paragraphs of text.
+    VisiblePosition paragraphStart = startOfParagraph(selectionStart);
+    VisiblePosition paragraphEnd = endOfParagraph(selectionEnd);
+
+    int lengthToSelectionStart = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
+    int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get());
+    NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart);
+
+    String fullPlainTextString = plainText(makeRange(paragraphStart, paragraphEnd).get());
+
+    // Since we already have the range we want, we just need to grab the returned options.
+    wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
+    
+    return selectedRange.release();
+}
+
+PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult& hitTestResult, NSDictionary **options)
+{
+    Node* node = hitTestResult.innerNonSharedNode();
+    if (!node)
+        return nullptr;
+
+    auto renderer = node->renderer();
+    if (!renderer)
+        return nullptr;
+
+    Frame* frame = node->document().frame();
+    if (!frame)
+        return nullptr;
+
+    // Don't do anything if there is no character at the point.
+    if (!frame->rangeForPoint(hitTestResult.roundedPointInInnerNodeFrame()))
+        return nullptr;
+
+    VisiblePosition position = renderer->positionForPoint(hitTestResult.localPoint(), nullptr);
+    if (position.isNull())
+        position = firstPositionInOrBeforeNode(node);
+
+    VisibleSelection selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
+    if (shouldUseSelection(position, selection))
+        return rangeForDictionaryLookupForSelection(selection, options);
+
+    // As context, we are going to use 250 characters of text before and after the point.
+    RefPtr<Range> fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
+    if (!fullCharacterRange)
+        return nullptr;
+
+    NSRange rangeToPass = NSMakeRange(TextIterator::rangeLength(makeRange(fullCharacterRange->startPosition(), position).get()), 0);
+
+    String fullPlainTextString = plainText(fullCharacterRange.get());
+
+    NSRange extractedRange = wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
+
+    // This function sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
+    if (extractedRange.location == NSNotFound)
+        return nullptr;
+
+    return TextIterator::subrange(fullCharacterRange.get(), extractedRange.location, extractedRange.length);
+}
+
+} // namespace WebCore
+
+#endif // PLATFORM(MAC)
+

Modified: trunk/Source/WebKit2/ChangeLog (176136 => 176137)


--- trunk/Source/WebKit2/ChangeLog	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebKit2/ChangeLog	2014-11-14 21:33:03 UTC (rev 176137)
@@ -1,3 +1,33 @@
+2014-11-14  Tim Horton  <timothy_hor...@apple.com>
+
+        Move DataDetectors scanning code to WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=138731
+        <rdar://problem/18877535>
+
+        Reviewed by Anders Carlsson.
+
+        Move DataDetectors scanning code to WebCore, so that both WebKits can use it.
+
+        * Shared/TextIndicator.cpp:
+        (WebKit::TextIndicator::createWithRange):
+        Move createWithRange in from WebPageMac's textIndicatorForRange.
+
+        (WebKit::TextIndicator::createWithSelectionInFrame):
+        * Shared/TextIndicator.h:
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::createSelectionSnapshot):
+        * WebProcess/WebPage/WebFrame.h:
+        Constify some things.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performActionMenuHitTestAtLocation):
+        Avoid using the DD result if it didn't come with a non-null Range.
+        Make use of detectItemAroundHitTestResult and TextIndicator::createWithRange.
+
+        (WebKit::scanForDataDetectedItems): Deleted.
+        (WebKit::textIndicatorForRange): Deleted.
+        Moved these two to other places.
+
 2014-11-14  Dan Bernstein  <m...@apple.com>
 
         <rdar://problem/18978497> Wrong (off-by-1) navigation snapshots shown after a mix of gesture and button back/forward navigation

Modified: trunk/Source/WebKit2/Shared/TextIndicator.cpp (176136 => 176137)


--- trunk/Source/WebKit2/Shared/TextIndicator.cpp	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebKit2/Shared/TextIndicator.cpp	2014-11-14 21:33:03 UTC (rev 176137)
@@ -36,6 +36,7 @@
 #include "WebCoreArgumentCoders.h"
 #include "WebFrame.h"
 #include "WebPage.h"
+#include <WebCore/Document.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameSelection.h>
 #include <WebCore/FrameView.h>
@@ -154,8 +155,25 @@
     return adoptRef(new TextIndicator(data));
 }
 
-PassRefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(WebFrame& frame)
+PassRefPtr<TextIndicator> TextIndicator::createWithRange(const Range& range)
 {
+    Frame* frame = range.startContainer()->document().frame();
+
+    if (!frame)
+        return nullptr;
+
+    VisibleSelection oldSelection = frame->selection().selection();
+    frame->selection().setSelection(&range);
+
+    RefPtr<TextIndicator> indicator = TextIndicator::createWithSelectionInFrame(*WebFrame::fromCoreFrame(*frame));
+
+    frame->selection().setSelection(oldSelection);
+    
+    return indicator.release();
+}
+
+PassRefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(const WebFrame& frame)
+{
     Frame& coreFrame = *frame.coreFrame();
     IntRect selectionRect = enclosingIntRect(coreFrame.selection().selectionBounds());
     RefPtr<ShareableBitmap> indicatorBitmap = frame.createSelectionSnapshot();

Modified: trunk/Source/WebKit2/Shared/TextIndicator.h (176136 => 176137)


--- trunk/Source/WebKit2/Shared/TextIndicator.h	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebKit2/Shared/TextIndicator.h	2014-11-14 21:33:03 UTC (rev 176137)
@@ -34,6 +34,7 @@
 
 namespace WebCore {
 class GraphicsContext;
+class Range;
 }
 
 namespace IPC {
@@ -59,7 +60,8 @@
     };
 
     static PassRefPtr<TextIndicator> create(const TextIndicator::Data&);
-    static PassRefPtr<TextIndicator> createWithSelectionInFrame(WebFrame&);
+    static PassRefPtr<TextIndicator> createWithSelectionInFrame(const WebFrame&);
+    static PassRefPtr<TextIndicator> createWithRange(const WebCore::Range&);
 
     ~TextIndicator();
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp (176136 => 176137)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp	2014-11-14 21:33:03 UTC (rev 176137)
@@ -783,7 +783,7 @@
 }
 #endif
 
-PassRefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot()
+PassRefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const
 {
     std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(*coreFrame(), WebCore::SnapshotOptionsForceBlackText);
     if (!snapshot)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h (176136 => 176137)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h	2014-11-14 21:33:03 UTC (rev 176137)
@@ -150,7 +150,7 @@
     RetainPtr<CFDataRef> webArchiveData(FrameFilterFunction, void* context);
 #endif
 
-    PassRefPtr<ShareableBitmap> createSelectionSnapshot();
+    PassRefPtr<ShareableBitmap> createSelectionSnapshot() const;
 
 private:
     static PassRefPtr<WebFrame> create(std::unique_ptr<WebFrameLoaderClient>);

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


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-11-14 21:28:53 UTC (rev 176136)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-11-14 21:33:03 UTC (rev 176137)
@@ -56,6 +56,7 @@
 #import <QuartzCore/QuartzCore.h>
 #import <WebCore/AXObjectCache.h>
 #import <WebCore/BackForwardController.h>
+#import <WebCore/DataDetection.h>
 #import <WebCore/DataDetectorsSPI.h>
 #import <WebCore/DictionaryLookup.h>
 #import <WebCore/EventHandler.h>
@@ -967,86 +968,6 @@
     return String();
 }
 
-static RetainPtr<DDActionContext> scanForDataDetectedItems(const HitTestResult& hitTestResult, FloatRect& detectedDataBoundingBox, RefPtr<Range>& detectedDataRange)
-{
-    Node* node = hitTestResult.innerNonSharedNode();
-    if (!node)
-        return nullptr;
-    auto renderer = node->renderer();
-    if (!renderer)
-        return nullptr;
-    VisiblePosition position = renderer->positionForPoint(hitTestResult.localPoint(), nullptr);
-    if (position.isNull())
-        position = firstPositionInOrBeforeNode(node);
-
-    RefPtr<Range> contextRange = rangeExpandedAroundPositionByCharacters(position, 250);
-    if (!contextRange)
-        return nullptr;
-
-    String fullPlainTextString = plainText(contextRange.get());
-    int hitLocation = TextIterator::rangeLength(makeRange(contextRange->startPosition(), position).get());
-
-    RetainPtr<DDScannerRef> scanner = adoptCF(DDScannerCreate(DDScannerTypeStandard, 0, nullptr));
-    RetainPtr<DDScanQueryRef> scanQuery = adoptCF(DDScanQueryCreateFromString(kCFAllocatorDefault, fullPlainTextString.createCFString().get(), CFRangeMake(0, fullPlainTextString.length())));
-
-    if (!DDScannerScanQuery(scanner.get(), scanQuery.get()))
-        return nullptr;
-
-    RetainPtr<CFArrayRef> results = adoptCF(DDScannerCopyResultsWithOptions(scanner.get(), DDScannerCopyResultsOptionsNoOverlap));
-
-    // Find the DDResultRef that intersects the hitTestResult's VisiblePosition.
-    DDResultRef mainResult = nullptr;
-    RefPtr<Range> mainResultRange;
-    CFIndex resultCount = CFArrayGetCount(results.get());
-    for (CFIndex i = 0; i < resultCount; i++) {
-        DDResultRef result = (DDResultRef)CFArrayGetValueAtIndex(results.get(), i);
-        CFRange resultRangeInContext = DDResultGetRange(result);
-        if (hitLocation >= resultRangeInContext.location && (hitLocation - resultRangeInContext.location) < resultRangeInContext.length) {
-            mainResult = result;
-            mainResultRange = TextIterator::subrange(contextRange.get(), resultRangeInContext.location, resultRangeInContext.length);
-            break;
-        }
-    }
-
-    if (!mainResult)
-        return nullptr;
-
-    RetainPtr<DDActionContext> actionContext = adoptNS([[getDDActionContextClass() alloc] init]);
-    [actionContext setAllResults:@[ (id)mainResult ]];
-    [actionContext setMainResult:mainResult];
-
-    Vector<FloatQuad> quads;
-    mainResultRange->textQuads(quads);
-    detectedDataBoundingBox = FloatRect();
-    FrameView* frameView = mainResultRange->ownerDocument().view();
-    for (const auto& quad : quads)
-        detectedDataBoundingBox.unite(frameView->contentsToWindow(quad.enclosingBoundingBox()));
-
-    detectedDataRange = mainResultRange;
-
-    return actionContext;
-}
-
-static PassRefPtr<TextIndicator> textIndicatorForRange(Range* range)
-{
-    if (!range)
-        return nullptr;
-
-    Frame* frame = range->startContainer()->document().frame();
-
-    if (!frame)
-        return nullptr;
-
-    VisibleSelection oldSelection = frame->selection().selection();
-    frame->selection().setSelection(range);
-
-    RefPtr<TextIndicator> indicator = TextIndicator::createWithSelectionInFrame(*WebFrame::fromCoreFrame(*frame));
-
-    frame->selection().setSelection(oldSelection);
-
-    return indicator.release();
-}
-
 void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInViewCooordinates)
 {
     m_lastActionMenuHitPageOverlay = nullptr;
@@ -1112,7 +1033,7 @@
             detectedDataBoundingBox.unite(frameView->contentsToWindow(quad.enclosingBoundingBox()));
 
         actionMenuResult.detectedDataBoundingBox = detectedDataBoundingBox;
-        actionMenuResult.detectedDataTextIndicator = textIndicatorForRange(mainResultRange.get());
+        actionMenuResult.detectedDataTextIndicator = TextIndicator::createWithRange(*mainResultRange);
         m_lastActionMenuRangeForSelection = mainResultRange;
         m_lastActionMenuHitPageOverlay = webOverlay;
 
@@ -1123,10 +1044,10 @@
     if (!pageOverlayDidOverrideDataDetectors && hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode()) {
         FloatRect detectedDataBoundingBox;
         RefPtr<Range> detectedDataRange;
-        actionMenuResult.actionContext = scanForDataDetectedItems(hitTestResult, detectedDataBoundingBox, detectedDataRange);
-        if (actionMenuResult.actionContext) {
+        actionMenuResult.actionContext = DataDetection::detectItemAroundHitTestResult(hitTestResult, detectedDataBoundingBox, detectedDataRange);
+        if (actionMenuResult.actionContext && detectedDataRange) {
             actionMenuResult.detectedDataBoundingBox = detectedDataBoundingBox;
-            actionMenuResult.detectedDataTextIndicator = textIndicatorForRange(detectedDataRange.get());
+            actionMenuResult.detectedDataTextIndicator = TextIndicator::createWithRange(*detectedDataRange);
             m_lastActionMenuRangeForSelection = detectedDataRange;
         }
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to