<!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>[175572] branches/safari-600.3-branch/Source/WebKit2</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/175572">175572</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2014-11-04 12:40:41 -0800 (Tue, 04 Nov 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/175474">r175474</a>. rdar://problem/18742323.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6003branchSourceWebKit2ChangeLog">branches/safari-600.3-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari6003branchSourceWebKit2SharedAPIcWKActionMenuItemTypesh">branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h</a></li>
<li><a href="#branchessafari6003branchSourceWebKit2SharedAPIcWKActionMenuTypesh">branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h</a></li>
<li><a href="#branchessafari6003branchSourceWebKit2UIProcessmacWKActionMenuControllermm">branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm</a></li>
<li><a href="#branchessafari6003branchSourceWebKit2WebProcessWebPagemacWebPageMacmm">branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6003branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (175571 => 175572)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog        2014-11-04 20:40:10 UTC (rev 175571)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog        2014-11-04 20:40:41 UTC (rev 175572)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2014-11-03 Beth Dakin <bdakin@apple.com>
+
+ Implement action menus for editable text
+ https://bugs.webkit.org/show_bug.cgi?id=138284
+ -and corresponding-
+ rdar://problem/18742323
+
+ Reviewed by Tim Horton.
+
+ New item type for paste.
+ * Shared/API/c/WKActionMenuItemTypes.h:
+
+ New menu type for editable text.
+ * Shared/API/c/WKActionMenuTypes.h:
+ * UIProcess/mac/WKActionMenuController.mm:
+
+ willOpenMenu should select text for both regular text menus and editable text
+ menus.
+ (-[WKActionMenuController willOpenMenu:withEvent:]):
+
+ Default items for editable text.
+ (-[WKActionMenuController _defaultMenuItemsForEditableText]):
+ (-[WKActionMenuController _paste:]):
+ (-[WKActionMenuController _createActionMenuItemForTag:]):
+
+ New method _hitTestResultForStage:(MenuUpdateStage)stage will figure out whether
+ we can use the WebHitTestResult from the ActionMenuHitTestResult or if we have to
+ use the potentially out-of-date WebHitTestResult that is cached on WebPageProxy.
+ An important difference between these results is that the ActionMenuHitTest
+ result, in addition to being more recent and accurate, also now includes shadow
+ content, which affects some editable regions on important sites such as
+ bugs.webkit.org and nytimes.com.
+ (-[WKActionMenuController _defaultMenuItems:]):
+ (-[WKActionMenuController _updateActionMenuItemsForStage:]):
+ (imageForResource:name::if): Deleted.
+
+ Allow shadow content in action menu hit testing.
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performActionMenuHitTestAtLocation):
+ (WebKit::WebPage::selectLookupTextAtLocation):
+
</ins><span class="cx"> 2014-11-04 Dana Burkart <dburkart@apple.com>
</span><span class="cx">
</span><span class="cx"> Merge r175482. <rdar://problem/18855190>
</span></span></pre></div>
<a id="branchessafari6003branchSourceWebKit2SharedAPIcWKActionMenuItemTypesh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h (175571 => 175572)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h        2014-11-04 20:40:10 UTC (rev 175571)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h        2014-11-04 20:40:41 UTC (rev 175572)
</span><span class="lines">@@ -42,7 +42,8 @@
</span><span class="cx"> kWKContextActionItemTagSaveImageToDownloads,
</span><span class="cx"> kWKContextActionItemTagShareImage,
</span><span class="cx"> kWKContextActionItemTagCopyText,
</span><del>- kWKContextActionItemTagLookupText
</del><ins>+ kWKContextActionItemTagLookupText,
+ kWKContextActionItemTagPaste
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> #ifdef __cplusplus
</span></span></pre></div>
<a id="branchessafari6003branchSourceWebKit2SharedAPIcWKActionMenuTypesh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h (175571 => 175572)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h        2014-11-04 20:40:10 UTC (rev 175571)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h        2014-11-04 20:40:41 UTC (rev 175572)
</span><span class="lines">@@ -37,7 +37,8 @@
</span><span class="cx"> kWKActionMenuLink,
</span><span class="cx"> kWKActionMenuImage,
</span><span class="cx"> kWKActionMenuDataDetectedItem,
</span><del>- kWKActionMenuReadOnlyText
</del><ins>+ kWKActionMenuReadOnlyText,
+ kWKActionMenuEditableText
</ins><span class="cx"> };
</span><span class="cx"> typedef uint32_t _WKActionMenuType;
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari6003branchSourceWebKit2UIProcessmacWKActionMenuControllermm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (175571 => 175572)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm        2014-11-04 20:40:10 UTC (rev 175571)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm        2014-11-04 20:40:41 UTC (rev 175572)
</span><span class="lines">@@ -115,12 +115,12 @@
</span><span class="cx"> if (menu != _wkView.actionMenu)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- if (_type != kWKActionMenuReadOnlyText)
</del><ins>+ if (_type != kWKActionMenuReadOnlyText && _type != kWKActionMenuEditableText)
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> // Action menus for text should highlight the text so that it is clear what the action menu actions
</span><span class="cx"> // will apply to. If the text is already selected, the menu will use the existing selection.
</span><del>- WebHitTestResult* hitTestResult = _page->activeActionMenuHitTestResult();
</del><ins>+ RefPtr<WebHitTestResult> hitTestResult = [self _hitTestResultForStage:MenuUpdateStage::MenuNeedsUpdate];
</ins><span class="cx"> if (!hitTestResult->isSelected())
</span><span class="cx"> _page->selectLookupTextAtLocation([_wkView convertPoint:event.locationInWindow fromView:nil]);
</span><span class="cx"> }
</span><span class="lines">@@ -314,6 +314,17 @@
</span><span class="cx">
</span><span class="cx"> #pragma mark Text actions
</span><span class="cx">
</span><ins>+- (NSArray *)_defaultMenuItemsForDataDetectedText
+{
+ DDActionContext *actionContext = _hitTestResult.actionContext.get();
+ if (!actionContext)
+ return @[ ];
+
+ WKSetDDActionContextIsForActionMenu(actionContext);
+ actionContext.highlightFrame = [_wkView.window convertRectToScreen:[_wkView convertRect:_hitTestResult.actionBoundingBox toView:nil]];
+ return [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_hitTestResult.actionContext mainResult] actionContext:actionContext];
+}
+
</ins><span class="cx"> - (NSArray *)_defaultMenuItemsForText
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<NSMenuItem> copyTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagCopyText];
</span><span class="lines">@@ -322,11 +333,25 @@
</span><span class="cx"> return @[ copyTextItem.get(), lookupTextItem.get() ];
</span><span class="cx"> }
</span><span class="cx">
</span><del>--(void)_copyText:(id)sender
</del><ins>+- (NSArray *)_defaultMenuItemsForEditableText
</ins><span class="cx"> {
</span><ins>+ RetainPtr<NSMenuItem> copyTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagCopyText];
+ RetainPtr<NSMenuItem> lookupTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagLookupText];
+ RetainPtr<NSMenuItem> pasteItem = [self _createActionMenuItemForTag:kWKContextActionItemTagPaste];
+
+ return @[ copyTextItem.get(), lookupTextItem.get(), pasteItem.get() ];
+}
+
+-(void)_copySelection:(id)sender
+{
</ins><span class="cx"> _page->executeEditCommand("copy");
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+-(void)_paste:(id)sender
+{
+ _page->executeEditCommand("paste");
+}
+
</ins><span class="cx"> -(void)_lookupText:(id)sender
</span><span class="cx"> {
</span><span class="cx"> _page->performDictionaryLookupOfCurrentSelection();
</span><span class="lines">@@ -430,7 +455,7 @@
</span><span class="cx"> break;
</span><span class="cx">
</span><span class="cx"> case kWKContextActionItemTagCopyText:
</span><del>- selector = @selector(_copyText:);
</del><ins>+ selector = @selector(_copySelection:);
</ins><span class="cx"> title = @"Copy";
</span><span class="cx"> image = [NSImage imageNamed:@"NSActionMenuCopy"];
</span><span class="cx"> break;
</span><span class="lines">@@ -441,6 +466,12 @@
</span><span class="cx"> image = [NSImage imageNamed:@"NSActionMenuLookup"];
</span><span class="cx"> break;
</span><span class="cx">
</span><ins>+ case kWKContextActionItemTagPaste:
+ selector = @selector(_paste:);
+ title = @"Paste";
+ image = [NSImage imageNamed:@"NSActionMenuPaste"];
+ break;
+
</ins><span class="cx"> default:
</span><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="cx"> return nil;
</span><span class="lines">@@ -458,32 +489,56 @@
</span><span class="cx"> return [[NSBundle bundleForClass:[WKView class]] imageForResource:name];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (NSArray *)_defaultMenuItems
</del><ins>+- (PassRefPtr<WebHitTestResult>)_hitTestResultForStage:(MenuUpdateStage)stage
</ins><span class="cx"> {
</span><del>- if (WebHitTestResult* hitTestResult = _page->activeActionMenuHitTestResult()) {
- if (!hitTestResult->absoluteImageURL().isEmpty() && _hitTestResult.image) {
- _type = kWKActionMenuImage;
- return [self _defaultMenuItemsForImage];
</del><ins>+ RefPtr<WebHitTestResult> hitTestResult;
+ switch (stage) {
+ case MenuUpdateStage::PrepareForMenu:
+ hitTestResult = _page->activeActionMenuHitTestResult();
+ break;
+ case MenuUpdateStage::MenuNeedsUpdate:
+ if (_state == ActionMenuState::Ready)
+ hitTestResult = WebHitTestResult::create(_hitTestResult.hitTestResult);
+ else
+ hitTestResult = _page->activeActionMenuHitTestResult();
+ break;
+ }
+
+ return hitTestResult.release();
+}
+
+- (NSArray *)_defaultMenuItems:(MenuUpdateStage)stage
+{
+ RefPtr<WebHitTestResult> hitTestResult = [self _hitTestResultForStage:stage];
+ if (!hitTestResult) {
+ _type = kWKActionMenuNone;
+ return _state != ActionMenuState::Ready ? @[ [NSMenuItem separatorItem] ] : @[ ];
+ }
+
+ if (!hitTestResult->absoluteImageURL().isEmpty() && _hitTestResult.image) {
+ _type = kWKActionMenuImage;
+ return [self _defaultMenuItemsForImage];
+ }
+
+ if (!hitTestResult->absoluteLinkURL().isEmpty()) {
+ _type = kWKActionMenuLink;
+ return [self _defaultMenuItemsForLink];
+ }
+
+ if (hitTestResult->isTextNode()) {
+ NSArray *dataDetectorMenuItems = [self _defaultMenuItemsForDataDetectedText];
+ if (dataDetectorMenuItems.count) {
+ _type = kWKActionMenuDataDetectedItem;
+ return dataDetectorMenuItems;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- if (!hitTestResult->absoluteLinkURL().isEmpty()) {
- _type = kWKActionMenuLink;
- return [self _defaultMenuItemsForLink];
</del><ins>+ if (hitTestResult->isContentEditable()) {
+ _type = kWKActionMenuEditableText;
+ return [self _defaultMenuItemsForEditableText];
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- if (hitTestResult->isTextNode()) {
- if (DDActionContext *actionContext = _hitTestResult.actionContext.get()) {
- WKSetDDActionContextIsForActionMenu(actionContext);
- actionContext.highlightFrame = [_wkView.window convertRectToScreen:[_wkView convertRect:_hitTestResult.actionBoundingBox toView:nil]];
- NSArray *dataDetectorMenuItems = [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_hitTestResult.actionContext mainResult] actionContext:actionContext];
- if (dataDetectorMenuItems.count) {
- _type = kWKActionMenuDataDetectedItem;
- return dataDetectorMenuItems;
- }
- }
- _type = kWKActionMenuReadOnlyText;
- return [self _defaultMenuItemsForText];
- }
</del><ins>+ _type = kWKActionMenuReadOnlyText;
+ return [self _defaultMenuItemsForText];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> _type = kWKActionMenuNone;
</span><span class="lines">@@ -494,19 +549,8 @@
</span><span class="cx"> {
</span><span class="cx"> [_wkView.actionMenu removeAllItems];
</span><span class="cx">
</span><del>- NSArray *menuItems = [self _defaultMenuItems];
- RefPtr<WebHitTestResult> hitTestResult;
- switch (stage) {
- case MenuUpdateStage::PrepareForMenu:
- hitTestResult = _page->activeActionMenuHitTestResult();
- break;
- case MenuUpdateStage::MenuNeedsUpdate:
- if (_state == ActionMenuState::Ready)
- hitTestResult = WebHitTestResult::create(_hitTestResult.hitTestResult);
- else
- hitTestResult = _page->activeActionMenuHitTestResult();
- break;
- }
</del><ins>+ NSArray *menuItems = [self _defaultMenuItems:stage];
+ RefPtr<WebHitTestResult> hitTestResult = [self _hitTestResultForStage:stage];
</ins><span class="cx">
</span><span class="cx"> if ([_wkView respondsToSelector:@selector(_actionMenuItemsForHitTestResult:defaultActionMenuItems:)])
</span><span class="cx"> menuItems = [_wkView _actionMenuItemsForHitTestResult:toAPI(hitTestResult.get()) defaultActionMenuItems:menuItems];
</span></span></pre></div>
<a id="branchessafari6003branchSourceWebKit2WebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (175571 => 175572)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-11-04 20:40:10 UTC (rev 175571)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-11-04 20:40:41 UTC (rev 175572)
</span><span class="lines">@@ -1137,7 +1137,7 @@
</span><span class="cx">
</span><span class="cx"> RenderView& mainRenderView = *mainFrame.view()->renderView();
</span><span class="cx">
</span><del>- HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AllowChildFrameContent | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent);
</del><ins>+ HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AllowChildFrameContent | HitTestRequest::IgnoreClipping);
</ins><span class="cx">
</span><span class="cx"> IntPoint locationInContentCoordinates = mainFrame.view()->rootViewToContents(roundedIntPoint(locationInViewCooordinates));
</span><span class="cx"> HitTestResult hitTestResult(locationInContentCoordinates);
</span><span class="lines">@@ -1174,7 +1174,7 @@
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> IntPoint point = roundedIntPoint(locationInWindowCooordinates);
</span><del>- HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point));
</del><ins>+ HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AllowChildFrameContent | HitTestRequest::IgnoreClipping);
</ins><span class="cx"> Frame* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
</span><span class="cx"> NSDictionary *options = nil;
</span><span class="cx"> RefPtr<Range> lookupRange = rangeForDictionaryLookupAtHitTestResult(result, &options);
</span></span></pre>
</div>
</div>
</body>
</html>