<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175814] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175814">175814</a></dd>
<dt>Author</dt> <dd>bdakin@apple.com</dd>
<dt>Date</dt> <dd>2014-11-10 11:19:52 -0800 (Mon, 10 Nov 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>WK1: Support default actions for read-only text
https://bugs.webkit.org/show_bug.cgi?id=138552
-and corresponding-
rdar://problem/18877483
Reviewed by Tim Horton.
Source/WebCore:
WK1 now needs to do a lot of dictionary lookup operations that it did not
previously have to handle. So this patch takes a lot of that functionality, which
was implemented as static functions in WebPageMac for WK2 and moves it into
WebCore.
* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* editing/DictionaryLookup.h: Added.
* editing/DictionaryLookup.mm: Added.
(WebCore::isPositionInRange):
(WebCore::shouldUseSelection):
(WebCore::rangeExpandedAroundPositionByCharacters):
(WebCore::rangeForDictionaryLookupForSelection):
(WebCore::rangeForDictionaryLookupAtHitTestResult):
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:
Source/WebKit/mac:
New WKSystemInterface functions that WebCore needs to use.
* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
WebActionMenuController now keeps an ivar for the WebCore::HitTestResult. This
makes a lot of things easier.
* WebView/WebActionMenuController.h:
* WebView/WebActionMenuController.mm:
Perform the hit test ourselves instead of calling into WebView so that we can more
easily save the WebCore::HitTestResult for ourselves.
(-[WebActionMenuController performHitTestAtPoint:]):
Clear selection for non-text menus.
(-[WebActionMenuController prepareForMenu:withEvent:]):
Re-set the _type here just to be safe.
(-[WebActionMenuController didCloseMenu:withEvent:]):
Moving this method to be next to the link actions so they can be within a pragma
mark.
(-[WebActionMenuController _defaultMenuItemsForLink:]):
New method for default text actions — lookup and copy.
(-[WebActionMenuController _defaultMenuItemsForText:]):
(-[WebActionMenuController _copySelection:]):
(-[WebActionMenuController _lookupText:]):
If there is not already a selection, invoking the action menu on text should
select the lookup text.
(-[WebActionMenuController _selectLookupText]):
(performDictionaryLookupForSelection):
(performDictionaryLookupForRange):
Handle text now.
(-[WebActionMenuController _createActionMenuItemForTag:withHitTestResult:]):
(-[WebActionMenuController _defaultMenuItemsForHitTestResult:]):
New enum values.
* WebView/WebUIDelegatePrivate.h:
Pass didCloseMenu on to the controller.
* WebView/WebView.mm:
(-[WebView didCloseMenu:withEvent:]):
Source/WebKit2:
WK1 now needs to do a lot of dictionary lookup operations that it did not
previously have to handle. So this patch takes a lot of that functionality, which
was implemented as static functions in WebPageMac for WK2 and moves it into
WebCore.
* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupForRange):
(WebKit::isPositionInRange): Deleted.
(WebKit::shouldUseSelection): Deleted.
(WebKit::rangeExpandedAroundPositionByCharacters): Deleted.
(WebKit::rangeForDictionaryLookupForSelection): Deleted.
(WebKit::rangeForDictionaryLookupAtHitTestResult): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreplatformmacWebCoreSystemInterfaceh">trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacWebCoreSystemInterfacemm">trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebSystemInterfacemm">trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebActionMenuControllerh">trunk/Source/WebKit/mac/WebView/WebActionMenuController.h</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebActionMenuControllermm">trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebUIDelegatePrivateh">trunk/Source/WebKit/mac/WebView/WebUIDelegatePrivate.h</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebViewmm">trunk/Source/WebKit/mac/WebView/WebView.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportmacWebSystemInterfacemm">trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreeditingDictionaryLookuph">trunk/Source/WebCore/editing/DictionaryLookup.h</a></li>
<li><a href="#trunkSourceWebCoreeditingDictionaryLookupmm">trunk/Source/WebCore/editing/DictionaryLookup.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebCore/ChangeLog        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2014-11-10 Beth Dakin <bdakin@apple.com>
+
+ WK1: Support default actions for read-only text
+ https://bugs.webkit.org/show_bug.cgi?id=138552
+ -and corresponding-
+ rdar://problem/18877483
+
+ Reviewed by Tim Horton.
+
+ WK1 now needs to do a lot of dictionary lookup operations that it did not
+ previously have to handle. So this patch takes a lot of that functionality, which
+ was implemented as static functions in WebPageMac for WK2 and moves it into
+ WebCore.
+
+ * WebCore.exp.in:
+ * WebCore.xcodeproj/project.pbxproj:
+ * editing/DictionaryLookup.h: Added.
+ * editing/DictionaryLookup.mm: Added.
+ (WebCore::isPositionInRange):
+ (WebCore::shouldUseSelection):
+ (WebCore::rangeExpandedAroundPositionByCharacters):
+ (WebCore::rangeForDictionaryLookupForSelection):
+ (WebCore::rangeForDictionaryLookupAtHitTestResult):
+ * platform/mac/WebCoreSystemInterface.h:
+ * platform/mac/WebCoreSystemInterface.mm:
+
</ins><span class="cx"> 2014-11-10 Myles C. Maxfield <mmaxfield@apple.com>
</span><span class="cx">
</span><span class="cx"> [OSX] Some words are placed on top of each other in complex text layout
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -316,7 +316,9 @@
</span><span class="cx"> __ZN7WebCore13HitTestResultC1ERKNS_11LayoutPointEjjjj
</span><span class="cx"> __ZN7WebCore13HitTestResultC1ERKNS_15HitTestLocationE
</span><span class="cx"> __ZN7WebCore13HitTestResultC1ERKS0_
</span><ins>+__ZN7WebCore13HitTestResultC1Ev
</ins><span class="cx"> __ZN7WebCore13HitTestResultD1Ev
</span><ins>+__ZN7WebCore13HitTestResultaSERKS0_
</ins><span class="cx"> __ZN7WebCore13IdentifierRep3getEPKc
</span><span class="cx"> __ZN7WebCore13IdentifierRep3getEi
</span><span class="cx"> __ZN7WebCore13JSHTMLElement6s_infoE
</span><span class="lines">@@ -1097,6 +1099,8 @@
</span><span class="cx"> __ZN7WebCore37WidgetHierarchyUpdatesSuspensionScope35s_widgetHierarchyUpdateSuspendCountE
</span><span class="cx"> __ZN7WebCore37computeFreshnessLifetimeForHTTPFamilyERKNS_16ResourceResponseEd
</span><span class="cx"> __ZN7WebCore38updateResponseHeadersAfterRevalidationERNS_16ResourceResponseERKS0_
</span><ins>+__ZN7WebCore39rangeExpandedAroundPositionByCharactersERKNS_15VisiblePositionEi
+__ZN7WebCore39rangeForDictionaryLookupAtHitTestResultERKNS_13HitTestResultEPP12NSDictionary
</ins><span class="cx"> __ZN7WebCore3URL10invalidateEv
</span><span class="cx"> __ZN7WebCore3URL11setProtocolERKN3WTF6StringE
</span><span class="cx"> __ZN7WebCore3URL7setPathERKN3WTF6StringE
</span><span class="lines">@@ -2373,6 +2377,7 @@
</span><span class="cx"> __ZN7WebCore35contextMenuItemTagShowSpellingPanelEb
</span><span class="cx"> __ZN7WebCore35contextMenuItemTagShowSubstitutionsEb
</span><span class="cx"> __ZN7WebCore35contextMenuItemTagSubstitutionsMenuEv
</span><ins>+__ZN7WebCore36rangeForDictionaryLookupForSelectionERKNS_16VisibleSelectionEPP12NSDictionary
</ins><span class="cx"> __ZN7WebCore37contextMenuItemTagTransformationsMenuEv
</span><span class="cx"> __ZN7WebCore38contextMenuItemTagWritingDirectionMenuEv
</span><span class="cx"> __ZN7WebCore42contextMenuItemTagCheckGrammarWithSpellingEv
</span><span class="lines">@@ -2436,6 +2441,7 @@
</span><span class="cx"> _wkDrawMediaSliderTrack
</span><span class="cx"> _wkDrawMediaUIPart
</span><span class="cx"> _wkExecutableWasLinkedOnOrBeforeSnowLeopard
</span><ins>+_wkExtractWordDefinitionTokenRangeFromContextualString
</ins><span class="cx"> _wkGetAXTextMarkerRangeTypeID
</span><span class="cx"> _wkGetAXTextMarkerTypeID
</span><span class="cx"> _wkGetBytesFromAXTextMarker
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -3271,6 +3271,8 @@
</span><span class="cx">                 9362640B0DE1137D009D5A00 /* CSSReflectionDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9362640A0DE1137D009D5A00 /* CSSReflectionDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 9370918D1416D86B00477333 /* textAreaResizeCorner@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9370918C1416D86B00477333 /* textAreaResizeCorner@2x.png */; };
</span><span class="cx">                 9377ABA015DEFEEF0031FD04 /* Pagination.h in Headers */ = {isa = PBXBuildFile; fileRef = 9377AB9F15DEFEEF0031FD04 /* Pagination.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                937FF3D71A10131B008EBA31 /* DictionaryLookup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */; };
</ins><span class="cx">                 9380F47309A11AB4001FDB34 /* Widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47109A11AB4001FDB34 /* Widget.cpp */; };
</span><span class="cx">                 9380F47409A11AB4001FDB34 /* Widget.h in Headers */ = {isa = PBXBuildFile; fileRef = 9380F47209A11AB4001FDB34 /* Widget.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 9380F47809A11ACC001FDB34 /* WidgetMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47709A11ACC001FDB34 /* WidgetMac.mm */; };
</span><span class="lines">@@ -10431,6 +10433,8 @@
</span><span class="cx">                 936DD03A09CEAC270056AE8C /* Range.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Range.idl; sourceTree = "<group>"; };
</span><span class="cx">                 9370918C1416D86B00477333 /* textAreaResizeCorner@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "textAreaResizeCorner@2x.png"; sourceTree = "<group>"; };
</span><span class="cx">                 9377AB9F15DEFEEF0031FD04 /* Pagination.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pagination.h; sourceTree = "<group>"; };
</span><ins>+                937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryLookup.h; sourceTree = "<group>"; };
+                937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DictionaryLookup.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 9380F47109A11AB4001FDB34 /* Widget.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Widget.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 9380F47209A11AB4001FDB34 /* Widget.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Widget.h; sourceTree = "<group>"; };
</span><span class="cx">                 9380F47709A11ACC001FDB34 /* WidgetMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WidgetMac.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -21990,6 +21994,8 @@
</span><span class="cx">                         children = (
</span><span class="cx">                                 CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */,
</span><span class="cx">                                 CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
</span><ins>+                                937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */,
+                                937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
</ins><span class="cx">                                 ED501DC50B249F2900AE18D9 /* EditorMac.mm */,
</span><span class="cx">                                 4A8C96EA0BE69032004EEFF0 /* FrameSelectionMac.mm */,
</span><span class="cx">                                 CE7B2DB11586ABAD0098B3FA /* TextAlternativeWithRange.h */,
</span><span class="lines">@@ -26707,6 +26713,7 @@
</span><span class="cx">                                 9380F47409A11AB4001FDB34 /* Widget.h in Headers */,
</span><span class="cx">                                 51A9D9EA195B931F001B2B5C /* GamepadManager.h in Headers */,
</span><span class="cx">                                 1411DCB1164C39A800D49BC1 /* WidthCache.h in Headers */,
</span><ins>+                                937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */,
</ins><span class="cx">                                 939B02EF0EA2DBC400C54570 /* WidthIterator.h in Headers */,
</span><span class="cx">                                 BC8243E90D0CFD7500460C8F /* WindowFeatures.h in Headers */,
</span><span class="cx">                                 7E99AF530B13846468FB01A5 /* WindowFocusAllowedIndicator.h in Headers */,
</span><span class="lines">@@ -27140,6 +27147,7 @@
</span><span class="cx">                                 49E912AC0EFAC906009D0CAF /* AnimationList.cpp in Sources */,
</span><span class="cx">                                 93309DD6099E64920056E581 /* AppendNodeCommand.cpp in Sources */,
</span><span class="cx">                                 1A8F6BBC0DB55CDC001DB794 /* ApplicationCache.cpp in Sources */,
</span><ins>+                                937FF3D71A10131B008EBA31 /* DictionaryLookup.mm in Sources */,
</ins><span class="cx">                                 1A8F6BBE0DB55CDC001DB794 /* ApplicationCacheGroup.cpp in Sources */,
</span><span class="cx">                                 24F54EAC101FE914000AE741 /* ApplicationCacheHost.cpp in Sources */,
</span><span class="cx">                                 1A8F6BC00DB55CDC001DB794 /* ApplicationCacheResource.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingDictionaryLookuph"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/DictionaryLookup.h (0 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/DictionaryLookup.h         (rev 0)
+++ trunk/Source/WebCore/editing/DictionaryLookup.h        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -0,0 +1,51 @@
</span><ins>+/*
+ * 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
+
+#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 // DictionaryLookup_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreeditingDictionaryLookupmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/DictionaryLookup.mm (0 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/DictionaryLookup.mm         (rev 0)
+++ trunk/Source/WebCore/editing/DictionaryLookup.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -0,0 +1,165 @@
</span><ins>+/*
+ * 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"
+
+#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);
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmacWebCoreSystemInterfaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -103,6 +103,7 @@
</span><span class="cx"> OBJC_CLASS NSCursor;
</span><span class="cx"> OBJC_CLASS NSData;
</span><span class="cx"> OBJC_CLASS NSDate;
</span><ins>+OBJC_CLASS NSDictionary;
</ins><span class="cx"> OBJC_CLASS NSEvent;
</span><span class="cx"> OBJC_CLASS NSFont;
</span><span class="cx"> OBJC_CLASS NSHTTPCookie;
</span><span class="lines">@@ -260,6 +261,8 @@
</span><span class="cx">
</span><span class="cx"> extern bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
</span><span class="cx">
</span><ins>+extern NSRange (*wkExtractWordDefinitionTokenRangeFromContextualString)(NSString *contextString, NSRange range, NSDictionary **options);
+
</ins><span class="cx"> extern CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
</span><span class="cx">
</span><span class="cx"> extern NSCursor *(*wkCursor)(const char*);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacWebCoreSystemInterfacemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -124,6 +124,8 @@
</span><span class="cx">
</span><span class="cx"> bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
</span><span class="cx">
</span><ins>+NSRange (*wkExtractWordDefinitionTokenRangeFromContextualString)(NSString *contextString, NSRange range, NSDictionary **options);
+
</ins><span class="cx"> CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
</span><span class="cx">
</span><span class="cx"> NSCursor *(*wkCursor)(const char*);
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2014-11-10 Beth Dakin <bdakin@apple.com>
+
+ WK1: Support default actions for read-only text
+ https://bugs.webkit.org/show_bug.cgi?id=138552
+ -and corresponding-
+ rdar://problem/18877483
+
+ Reviewed by Tim Horton.
+
+ New WKSystemInterface functions that WebCore needs to use.
+ * WebCoreSupport/WebSystemInterface.mm:
+ (InitWebCoreSystemInterface):
+
+ WebActionMenuController now keeps an ivar for the WebCore::HitTestResult. This
+ makes a lot of things easier.
+ * WebView/WebActionMenuController.h:
+ * WebView/WebActionMenuController.mm:
+
+ Perform the hit test ourselves instead of calling into WebView so that we can more
+ easily save the WebCore::HitTestResult for ourselves.
+ (-[WebActionMenuController performHitTestAtPoint:]):
+
+ Clear selection for non-text menus.
+ (-[WebActionMenuController prepareForMenu:withEvent:]):
+
+ Re-set the _type here just to be safe.
+ (-[WebActionMenuController didCloseMenu:withEvent:]):
+
+ Moving this method to be next to the link actions so they can be within a pragma
+ mark.
+ (-[WebActionMenuController _defaultMenuItemsForLink:]):
+
+ New method for default text actions — lookup and copy.
+ (-[WebActionMenuController _defaultMenuItemsForText:]):
+ (-[WebActionMenuController _copySelection:]):
+ (-[WebActionMenuController _lookupText:]):
+
+ If there is not already a selection, invoking the action menu on text should
+ select the lookup text.
+ (-[WebActionMenuController _selectLookupText]):
+ (performDictionaryLookupForSelection):
+ (performDictionaryLookupForRange):
+
+ Handle text now.
+ (-[WebActionMenuController _createActionMenuItemForTag:withHitTestResult:]):
+ (-[WebActionMenuController _defaultMenuItemsForHitTestResult:]):
+
+ New enum values.
+ * WebView/WebUIDelegatePrivate.h:
+
+ Pass didCloseMenu on to the controller.
+ * WebView/WebView.mm:
+ (-[WebView didCloseMenu:withEvent:]):
+
</ins><span class="cx"> 2014-11-09 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> Add a more correct way to compare floating point numbers and use it
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebSystemInterfacemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -146,6 +146,7 @@
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx"> INIT(RecommendedScrollerStyle);
</span><span class="cx"> INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
</span><ins>+ INIT(ExtractWordDefinitionTokenRangeFromContextualString);
</ins><span class="cx"> INIT(CopyDefaultSearchProviderDisplayName);
</span><span class="cx"> INIT(Cursor);
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebActionMenuControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebActionMenuController.h (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebActionMenuController.h        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit/mac/WebView/WebActionMenuController.h        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -24,6 +24,7 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #import "WebUIDelegatePrivate.h"
</span><ins>+#import <WebCore/HitTestResult.h>
</ins><span class="cx">
</span><span class="cx"> @class WebView;
</span><span class="cx">
</span><span class="lines">@@ -31,10 +32,12 @@
</span><span class="cx"> @private
</span><span class="cx"> WebView *_webView;
</span><span class="cx"> WebActionMenuType _type;
</span><ins>+ WebCore::HitTestResult _hitTestResult;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (id)initWithWebView:(WebView *)webView;
</span><span class="cx"> - (void)webViewClosed;
</span><span class="cx"> - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
</span><ins>+- (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
</ins><span class="cx">
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebActionMenuControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -27,13 +27,26 @@
</span><span class="cx">
</span><span class="cx"> #import "DOMElementInternal.h"
</span><span class="cx"> #import "DOMNodeInternal.h"
</span><ins>+#import "WebDocumentInternal.h"
+#import "WebElementDictionary.h"
+#import "WebFrameInternal.h"
+#import "WebHTMLView.h"
+#import "WebHTMLViewInternal.h"
+#import "WebSystemInterface.h"
</ins><span class="cx"> #import "WebUIDelegatePrivate.h"
</span><span class="cx"> #import "WebViewInternal.h"
</span><ins>+#import <WebCore/DictionaryLookup.h>
</ins><span class="cx"> #import <WebCore/Element.h>
</span><ins>+#import <WebCore/EventHandler.h>
</ins><span class="cx"> #import <WebCore/Frame.h>
</span><span class="cx"> #import <WebCore/FrameView.h>
</span><ins>+#import <WebCore/HTMLConverter.h>
</ins><span class="cx"> #import <WebCore/NSViewSPI.h>
</span><ins>+#import <WebCore/Page.h>
+#import <WebCore/Range.h>
+#import <WebCore/RenderObject.h>
</ins><span class="cx"> #import <WebCore/SoftLinking.h>
</span><ins>+#import <WebKitSystemInterface.h>
</ins><span class="cx"> #import <objc/objc-class.h>
</span><span class="cx"> #import <objc/objc.h>
</span><span class="cx">
</span><span class="lines">@@ -52,6 +65,12 @@
</span><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span><span class="cx">
</span><ins>+struct DictionaryPopupInfo {
+ NSPoint origin;
+ RetainPtr<NSDictionary> options;
+ RetainPtr<NSAttributedString> attributedString;
+};
+
</ins><span class="cx"> @implementation WebActionMenuController
</span><span class="cx">
</span><span class="cx"> - (id)initWithWebView:(WebView *)webView
</span><span class="lines">@@ -70,6 +89,20 @@
</span><span class="cx"> _webView = nil;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (WebElementDictionary *)performHitTestAtPoint:(NSPoint)windowPoint
+{
+ WebHTMLView *documentView = [[[_webView _selectedOrMainFrame] frameView] documentView];
+ NSPoint point = [documentView convertPoint:windowPoint fromView:nil];
+
+ Frame* coreFrame = core([documentView _frame]);
+ if (!coreFrame)
+ return nil;
+ HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
+ _hitTestResult = coreFrame->eventHandler().hitTestResultAtPoint(IntPoint(point), hitType);
+
+ return [[[WebElementDictionary alloc] initWithHitTestResult:_hitTestResult] autorelease];
+}
+
</ins><span class="cx"> - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
</span><span class="cx"> {
</span><span class="cx"> if (!_webView)
</span><span class="lines">@@ -81,10 +114,12 @@
</span><span class="cx">
</span><span class="cx"> [actionMenu removeAllItems];
</span><span class="cx">
</span><del>- NSDictionary *hitTestResult = [_webView elementAtPoint:[_webView convertPoint:event.locationInWindow fromView:nil]];
-
</del><ins>+ WebElementDictionary *hitTestResult = [self performHitTestAtPoint:[_webView convertPoint:event.locationInWindow fromView:nil]];
</ins><span class="cx"> NSArray *menuItems = [self _defaultMenuItemsForHitTestResult:hitTestResult];
</span><span class="cx">
</span><ins>+ if (_type != WebActionMenuReadOnlyText)
+ [[_webView _selectedOrMainFrame] _clearSelection];
+
</ins><span class="cx"> // Allow clients to customize the menu items.
</span><span class="cx"> if ([[_webView UIDelegate] respondsToSelector:@selector(_webView:actionMenuItemsForHitTestResult:withType:defaultActionMenuItems:)])
</span><span class="cx"> menuItems = [[_webView UIDelegate] _webView:_webView actionMenuItemsForHitTestResult:hitTestResult withType:_type defaultActionMenuItems:menuItems];
</span><span class="lines">@@ -93,6 +128,16 @@
</span><span class="cx"> [actionMenu addItem:item];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+ if (menu != _webView.actionMenu)
+ return;
+
+ _type = WebActionMenuNone;
+}
+
+#pragma mark Link actions
+
</ins><span class="cx"> - (void)_openURLFromActionMenu:(id)sender
</span><span class="cx"> {
</span><span class="cx"> if (!_webView)
</span><span class="lines">@@ -174,8 +219,124 @@
</span><span class="cx"> [bubble showPreviewItem:url itemFrame:itemFrame];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (RetainPtr<NSMenuItem>)_createActionMenuItemForTag:(uint32_t)tag withHitTestResult:(NSDictionary *)hitTestResult
</del><ins>+- (NSArray *)_defaultMenuItemsForLink:(WebElementDictionary *)hitTestResult
</ins><span class="cx"> {
</span><ins>+ NSURL *url = [hitTestResult objectForKey:WebElementLinkURLKey];
+ if (!url)
+ return @[ ];
+
+ if (!WebCore::protocolIsInHTTPFamily([url absoluteString]))
+ return @[ ];
+
+ RetainPtr<NSMenuItem> openLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagOpenLinkInDefaultBrowser withHitTestResult:hitTestResult];
+ RetainPtr<NSMenuItem> previewLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagPreviewLink withHitTestResult:hitTestResult];
+ RetainPtr<NSMenuItem> readingListItem = [self _createActionMenuItemForTag:WebActionMenuItemTagAddLinkToSafariReadingList withHitTestResult:hitTestResult];
+
+ return @[ openLinkItem.get(), previewLinkItem.get(), [NSMenuItem separatorItem], readingListItem.get() ];
+}
+
+#pragma mark Text actions
+
+- (NSArray *)_defaultMenuItemsForText:(WebElementDictionary *)hitTestResult
+{
+ RetainPtr<NSMenuItem> copyTextItem = [self _createActionMenuItemForTag:WebActionMenuItemTagCopyText withHitTestResult:hitTestResult];
+ RetainPtr<NSMenuItem> lookupTextItem = [self _createActionMenuItemForTag:WebActionMenuItemTagLookupText withHitTestResult:hitTestResult];
+
+ return @[ copyTextItem.get(), lookupTextItem.get() ];
+}
+
+- (void)_copySelection:(id)sender
+{
+ [_webView _executeCoreCommandByName:@"copy" value:nil];
+}
+
+- (void)_lookupText:(id)sender
+{
+ Frame* frame = core([_webView _selectedOrMainFrame]);
+ if (!frame)
+ return;
+
+ DictionaryPopupInfo popupInfo = performDictionaryLookupForSelection(frame, frame->selection().selection());
+ if (!popupInfo.attributedString)
+ return;
+
+ NSPoint textBaselineOrigin = popupInfo.origin;
+
+ // Convert to screen coordinates.
+ textBaselineOrigin = [_webView convertPoint:textBaselineOrigin toView:nil];
+ textBaselineOrigin = [_webView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
+
+ WKShowWordDefinitionWindow(popupInfo.attributedString.get(), textBaselineOrigin, popupInfo.options.get());
+}
+
+- (BOOL)_selectLookupText
+{
+ NSDictionary *options = nil;
+ RefPtr<Range> lookupRange = rangeForDictionaryLookupAtHitTestResult(_hitTestResult, &options);
+ if (!lookupRange)
+ return false;
+
+ Frame* frame = _hitTestResult.innerNode()->document().frame();
+ if (!frame)
+ return false;
+
+ frame->selection().setSelectedRange(lookupRange.get(), DOWNSTREAM, true);
+ return true;
+}
+
+static DictionaryPopupInfo performDictionaryLookupForSelection(Frame* frame, const VisibleSelection& selection)
+{
+ NSDictionary *options = nil;
+ DictionaryPopupInfo popupInfo;
+ RefPtr<Range> selectedRange = rangeForDictionaryLookupForSelection(selection, &options);
+ if (selectedRange)
+ popupInfo = performDictionaryLookupForRange(frame, *selectedRange, options);
+ return popupInfo;
+}
+
+static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range& range, NSDictionary *options)
+{
+ DictionaryPopupInfo popupInfo;
+ if (range.text().stripWhiteSpace().isEmpty())
+ return popupInfo;
+
+ RenderObject* renderer = range.startContainer()->renderer();
+ const RenderStyle& style = renderer->style();
+
+ Vector<FloatQuad> quads;
+ range.textQuads(quads);
+ if (quads.isEmpty())
+ return popupInfo;
+
+ IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
+
+ popupInfo.origin = NSMakePoint(rangeRect.x(), rangeRect.y() + (style.fontMetrics().descent() * frame->page()->pageScaleFactor()));
+ popupInfo.options = options;
+
+ NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range);
+ RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
+ NSFontManager *fontManager = [NSFontManager sharedFontManager];
+
+ [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
+ RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
+
+ NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
+ if (font) {
+ font = [fontManager convertFont:font toSize:[font pointSize] * frame->page()->pageScaleFactor()];
+ [scaledAttributes setObject:font forKey:NSFontAttributeName];
+ }
+
+ [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
+ }];
+
+ popupInfo.attributedString = scaledNSAttributedString.get();
+ return popupInfo;
+}
+
+#pragma mark Menu Items
+
+- (RetainPtr<NSMenuItem>)_createActionMenuItemForTag:(uint32_t)tag withHitTestResult:(WebElementDictionary *)hitTestResult
+{
</ins><span class="cx"> SEL selector = nullptr;
</span><span class="cx"> NSString *title = nil;
</span><span class="cx"> NSImage *image = nil;
</span><span class="lines">@@ -204,6 +365,18 @@
</span><span class="cx"> representedObject = [hitTestResult objectForKey:WebElementLinkURLKey];
</span><span class="cx"> break;
</span><span class="cx">
</span><ins>+ case WebActionMenuItemTagCopyText:
+ selector = @selector(_copySelection:);
+ title = @"Copy";
+ image = [NSImage imageNamed:@"NSActionMenuCopy"];
+ break;
+
+ case WebActionMenuItemTagLookupText:
+ selector = @selector(_lookupText:);
+ title = @"Look Up";
+ image = [NSImage imageNamed:@"NSActionMenuLookup"];
+ break;
+
</ins><span class="cx"> default:
</span><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="cx"> return nil;
</span><span class="lines">@@ -222,31 +395,24 @@
</span><span class="cx"> return [[NSBundle bundleForClass:NSClassFromString(@"WKView")] imageForResource:name];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (NSArray *)_defaultMenuItemsForLink:(NSDictionary *)hitTestResult
</del><ins>+- (NSArray *)_defaultMenuItemsForHitTestResult:(WebElementDictionary *)hitTestResult
</ins><span class="cx"> {
</span><span class="cx"> NSURL *url = [hitTestResult objectForKey:WebElementLinkURLKey];
</span><del>- if (!url)
- return @[ ];
-
- if (!WebCore::protocolIsInHTTPFamily([url absoluteString]))
- return @[ ];
-
- RetainPtr<NSMenuItem> openLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagOpenLinkInDefaultBrowser withHitTestResult:hitTestResult];
- RetainPtr<NSMenuItem> previewLinkItem = [self _createActionMenuItemForTag:WebActionMenuItemTagPreviewLink withHitTestResult:hitTestResult];
- RetainPtr<NSMenuItem> readingListItem = [self _createActionMenuItemForTag:WebActionMenuItemTagAddLinkToSafariReadingList withHitTestResult:hitTestResult];
-
- return @[ openLinkItem.get(), previewLinkItem.get(), [NSMenuItem separatorItem], readingListItem.get() ];
-}
-
-- (NSArray *)_defaultMenuItemsForHitTestResult:(NSDictionary *)hitTestResult
-{
- NSURL *url = [hitTestResult objectForKey:WebElementLinkURLKey];
-
</del><span class="cx"> if (url) {
</span><span class="cx"> _type = WebActionMenuLink;
</span><span class="cx"> return [self _defaultMenuItemsForLink:hitTestResult];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ Node* node = _hitTestResult.innerNode();
+ if (node && node->isTextNode()) {
+ if (![[hitTestResult objectForKey:WebElementIsSelectedKey] boolValue]) {
+ if (![self _selectLookupText])
+ return @[ ];
+ }
+ _type = WebActionMenuReadOnlyText;
+ return [self _defaultMenuItemsForText:hitTestResult];
+ }
+
</ins><span class="cx"> _type = WebActionMenuNone;
</span><span class="cx"> return @[ ];
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebUIDelegatePrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebUIDelegatePrivate.h (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebUIDelegatePrivate.h        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit/mac/WebView/WebUIDelegatePrivate.h        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -116,12 +116,15 @@
</span><span class="cx"> WebActionMenuItemTagNoAction = 0,
</span><span class="cx"> WebActionMenuItemTagOpenLinkInDefaultBrowser,
</span><span class="cx"> WebActionMenuItemTagPreviewLink,
</span><del>- WebActionMenuItemTagAddLinkToSafariReadingList
</del><ins>+ WebActionMenuItemTagAddLinkToSafariReadingList,
+ WebActionMenuItemTagCopyText,
+ WebActionMenuItemTagLookupText
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> typedef enum {
</span><span class="cx"> WebActionMenuNone = 0,
</span><del>- WebActionMenuLink
</del><ins>+ WebActionMenuLink,
+ WebActionMenuReadOnlyText
</ins><span class="cx"> } WebActionMenuType;
</span><span class="cx">
</span><span class="cx"> // Message Sources.
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebView.mm        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -8543,6 +8543,14 @@
</span><span class="cx">
</span><span class="cx"> [_private->actionMenuController prepareForMenu:menu withEvent:event];
</span><span class="cx"> }
</span><ins>+
+- (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+ if (menu != self.actionMenu)
+ return;
+
+ [_private->actionMenuController didCloseMenu:menu withEvent:event];
+}
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit2/ChangeLog        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-11-10 Beth Dakin <bdakin@apple.com>
+
+ WK1: Support default actions for read-only text
+ https://bugs.webkit.org/show_bug.cgi?id=138552
+ -and corresponding-
+ rdar://problem/18877483
+
+ Reviewed by Tim Horton.
+
+ WK1 now needs to do a lot of dictionary lookup operations that it did not
+ previously have to handle. So this patch takes a lot of that functionality, which
+ was implemented as static functions in WebPageMac for WK2 and moves it into
+ WebCore.
+
+ * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+ (InitWebCoreSystemInterface):
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performDictionaryLookupForRange):
+ (WebKit::isPositionInRange): Deleted.
+ (WebKit::shouldUseSelection): Deleted.
+ (WebKit::rangeExpandedAroundPositionByCharacters): Deleted.
+ (WebKit::rangeForDictionaryLookupForSelection): Deleted.
+ (WebKit::rangeForDictionaryLookupAtHitTestResult): Deleted.
+
</ins><span class="cx"> 2014-11-10 Dan Bernstein <mitz@apple.com>
</span><span class="cx">
</span><span class="cx"> iOS build fix.
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportmacWebSystemInterfacemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -136,6 +136,7 @@
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx"> INIT(RecommendedScrollerStyle);
</span><span class="cx"> INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
</span><ins>+ INIT(ExtractWordDefinitionTokenRangeFromContextualString);
</ins><span class="cx"> INIT(CopyDefaultSearchProviderDisplayName);
</span><span class="cx"> INIT(Cursor);
</span><span class="cx"> INIT(WindowSetScaledFrame);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (175813 => 175814)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-11-10 18:55:08 UTC (rev 175813)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-11-10 19:19:52 UTC (rev 175814)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx"> #import <WebCore/AXObjectCache.h>
</span><span class="cx"> #import <WebCore/BackForwardController.h>
</span><span class="cx"> #import <WebCore/DataDetectorsSPI.h>
</span><ins>+#import <WebCore/DictionaryLookup.h>
</ins><span class="cx"> #import <WebCore/EventHandler.h>
</span><span class="cx"> #import <WebCore/FocusController.h>
</span><span class="cx"> #import <WebCore/FrameLoader.h>
</span><span class="lines">@@ -476,123 +477,6 @@
</span><span class="cx"> send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback(result, EditingRange(editingRange.location, [result.string length]), callbackID));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static 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;
-}
-
-static 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());
-}
-
-static 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);
-}
-
-static 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();
-}
-
-static 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);
-}
-
</del><span class="cx"> void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
</span><span class="cx"> {
</span><span class="cx"> if (PluginView* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
</span><span class="lines">@@ -640,7 +524,7 @@
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
</span><del>-
</del><ins>+
</ins><span class="cx"> DictionaryPopupInfo dictionaryPopupInfo;
</span><span class="cx"> dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + (style.fontMetrics().ascent() * pageScaleFactor()));
</span><span class="cx"> dictionaryPopupInfo.options = (CFDictionaryRef)options;
</span></span></pre>
</div>
</div>
</body>
</html>