<!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>[167830] 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/167830">167830</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-04-25 15:22:14 -0700 (Fri, 25 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add a selection overlay.
<rdar://problem/16727797> and https://bugs.webkit.org/show_bug.cgi?id=132200
Reviewed by David Hyatt.
Source/WebCore:
No new tests (WK2 feature in development).
* WebCore.xcodeproj/project.pbxproj:
Add a SelectionRectGathterer class.
It creates a Notifier (given a RenderView) then accepts Rects from the RenderView.
When the Notifier is destroyed, the appropriate EditorClient is notified of the gathered rects.
* editing/SelectionRectGatherer.cpp: Added.
(WebCore::SelectionRectGatherer::SelectionRectGatherer):
(WebCore::SelectionRectGatherer::addRect):
(WebCore::SelectionRectGatherer::addRects):
(WebCore::SelectionRectGatherer::Notifier::Notifier):
(WebCore::SelectionRectGatherer::Notifier::~Notifier):
(WebCore::SelectionRectGatherer::clearAndCreateNotifier):
* editing/SelectionRectGatherer.h: Added.
* page/EditorClient.h:
(WebCore::EditorClient::selectionRectsDidChange):
* rendering/RenderView.cpp:
(WebCore::RenderView::RenderView):
(WebCore::RenderView::setSelection): Clear the gatherer’s rects then create a Notifier.
(WebCore::RenderView::setSubtreeSelection): Give all the selection rects to be painted to
the SelectionRectGatherer.
* rendering/RenderView.h:
Source/WebKit2:
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::selectionRectsDidChange): Pass the new selection rects on
to the selection overlay controller.
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebPage/SelectionOverlayController.cpp: Added.
(WebKit::SelectionOverlayController::SelectionOverlayController):
(WebKit::SelectionOverlayController::createOverlayIfNeeded):
(WebKit::SelectionOverlayController::destroyOverlay):
(WebKit::SelectionOverlayController::pageOverlayDestroyed):
(WebKit::SelectionOverlayController::willMoveToWebPage):
(WebKit::SelectionOverlayController::didMoveToWebPage):
(WebKit::SelectionOverlayController::selectionRectsDidChange):
(WebKit::SelectionOverlayController::drawRect):
(WebKit::SelectionOverlayController::mouseEvent):
* WebProcess/WebPage/SelectionOverlayController.h: Added.
(WebKit::SelectionOverlayController::create):
* WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm: Added.
(WebKit::SelectionOverlayController::drawRect):
(WebKit::SelectionOverlayController::mouseEvent):
(WebKit::SelectionOverlayController::handleClick):
(WebKit::SelectionOverlayController::clearHighlight):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::selectionOverlayController):
* WebProcess/WebPage/WebPage.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorepageEditorClienth">trunk/Source/WebCore/page/EditorClient.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderViewcpp">trunk/Source/WebCore/rendering/RenderView.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderViewh">trunk/Source/WebCore/rendering/RenderView.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebEditorClientcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebEditorClienth">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreeditingSelectionRectGatherercpp">trunk/Source/WebCore/editing/SelectionRectGatherer.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingSelectionRectGathererh">trunk/Source/WebCore/editing/SelectionRectGatherer.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllercpp">trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllerh">trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacSelectionOverlayControllerMacmm">trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebCore/ChangeLog        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2014-04-25 Brady Eidson <beidson@apple.com>
+
+ Add a selection overlay.
+ <rdar://problem/16727797> and https://bugs.webkit.org/show_bug.cgi?id=132200
+
+ Reviewed by David Hyatt.
+
+ No new tests (WK2 feature in development).
+
+ * WebCore.xcodeproj/project.pbxproj:
+
+ Add a SelectionRectGathterer class.
+ It creates a Notifier (given a RenderView) then accepts Rects from the RenderView.
+ When the Notifier is destroyed, the appropriate EditorClient is notified of the gathered rects.
+ * editing/SelectionRectGatherer.cpp: Added.
+ (WebCore::SelectionRectGatherer::SelectionRectGatherer):
+ (WebCore::SelectionRectGatherer::addRect):
+ (WebCore::SelectionRectGatherer::addRects):
+ (WebCore::SelectionRectGatherer::Notifier::Notifier):
+ (WebCore::SelectionRectGatherer::Notifier::~Notifier):
+ (WebCore::SelectionRectGatherer::clearAndCreateNotifier):
+ * editing/SelectionRectGatherer.h: Added.
+
+ * page/EditorClient.h:
+ (WebCore::EditorClient::selectionRectsDidChange):
+
+ * rendering/RenderView.cpp:
+ (WebCore::RenderView::RenderView):
+ (WebCore::RenderView::setSelection): Clear the gatherer’s rects then create a Notifier.
+ (WebCore::RenderView::setSubtreeSelection): Give all the selection rects to be painted to
+ the SelectionRectGatherer.
+ * rendering/RenderView.h:
+
</ins><span class="cx"> 2014-04-08 Jer Noble <jer.noble@apple.com>
</span><span class="cx">
</span><span class="cx"> Support "Live" streams in media controls.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -1817,6 +1817,8 @@
</span><span class="cx">                 51327D6111A33A2B004F9D65 /* SinkDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51327D5F11A33A2B004F9D65 /* SinkDocument.cpp */; };
</span><span class="cx">                 513F14530AB634C400094DDF /* IconLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513F14510AB634C400094DDF /* IconLoader.cpp */; };
</span><span class="cx">                 513F14540AB634C400094DDF /* IconLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 513F14520AB634C400094DDF /* IconLoader.h */; };
</span><ins>+                51405C88190B014400754F94 /* SelectionRectGatherer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51405C86190B014400754F94 /* SelectionRectGatherer.cpp */; };
+                51405C89190B014400754F94 /* SelectionRectGatherer.h in Headers */ = {isa = PBXBuildFile; fileRef = 51405C87190B014400754F94 /* SelectionRectGatherer.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 514B3F730C722047000530DF /* FileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 514B3F720C722047000530DF /* FileSystem.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 514B3F760C722055000530DF /* FileSystemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514B3F750C722055000530DF /* FileSystemMac.mm */; };
</span><span class="cx">                 514BC83F161CF04A004D52F4 /* ResourceBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514BC83D161CF043004D52F4 /* ResourceBuffer.mm */; };
</span><span class="lines">@@ -8808,6 +8810,8 @@
</span><span class="cx">                 51327D5F11A33A2B004F9D65 /* SinkDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SinkDocument.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 513F14510AB634C400094DDF /* IconLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IconLoader.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 513F14520AB634C400094DDF /* IconLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IconLoader.h; sourceTree = "<group>"; };
</span><ins>+                51405C86190B014400754F94 /* SelectionRectGatherer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionRectGatherer.cpp; sourceTree = "<group>"; };
+                51405C87190B014400754F94 /* SelectionRectGatherer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionRectGatherer.h; sourceTree = "<group>"; };
</ins><span class="cx">                 514B3F720C722047000530DF /* FileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystem.h; sourceTree = "<group>"; };
</span><span class="cx">                 514B3F750C722055000530DF /* FileSystemMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSystemMac.mm; sourceTree = "<group>"; };
</span><span class="cx">                 514BC83D161CF043004D52F4 /* ResourceBuffer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceBuffer.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -17190,6 +17194,8 @@
</span><span class="cx">                                 A89CCC510F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h */,
</span><span class="cx">                                 93309DBA099E64910056E581 /* ReplaceSelectionCommand.cpp */,
</span><span class="cx">                                 93309DBB099E64910056E581 /* ReplaceSelectionCommand.h */,
</span><ins>+                                51405C86190B014400754F94 /* SelectionRectGatherer.cpp */,
+                                51405C87190B014400754F94 /* SelectionRectGatherer.h */,
</ins><span class="cx">                                 93309DC0099E64910056E581 /* SetNodeAttributeCommand.cpp */,
</span><span class="cx">                                 93309DC1099E64910056E581 /* SetNodeAttributeCommand.h */,
</span><span class="cx">                                 B8DBDB47130B0F8A00F5CDB1 /* SetSelectionCommand.cpp */,
</span><span class="lines">@@ -23642,6 +23648,7 @@
</span><span class="cx">                                 85E711C60AC5D5350053270F /* DOMHTMLSelectElementInternal.h in Headers */,
</span><span class="cx">                                 859A9C4F0AA5E3BD00B694B2 /* DOMHTMLStyleElement.h in Headers */,
</span><span class="cx">                                 85E711C70AC5D5350053270F /* DOMHTMLStyleElementInternal.h in Headers */,
</span><ins>+                                51405C89190B014400754F94 /* SelectionRectGatherer.h in Headers */,
</ins><span class="cx">                                 85DF821D0AA7849E00486AD7 /* DOMHTMLTableCaptionElement.h in Headers */,
</span><span class="cx">                                 85E711C80AC5D5350053270F /* DOMHTMLTableCaptionElementInternal.h in Headers */,
</span><span class="cx">                                 85DF821F0AA7849E00486AD7 /* DOMHTMLTableCellElement.h in Headers */,
</span><span class="lines">@@ -28520,6 +28527,7 @@
</span><span class="cx">                                 FDB1700514A2BAB200A2B5D9 /* MultiChannelResampler.cpp in Sources */,
</span><span class="cx">                                 85031B490A44EFC700F992E0 /* MutationEvent.cpp in Sources */,
</span><span class="cx">                                 C6F0900E14327B6100685849 /* MutationObserver.cpp in Sources */,
</span><ins>+                                51405C88190B014400754F94 /* SelectionRectGatherer.cpp in Sources */,
</ins><span class="cx">                                 D6E528A3149A926D00EFE1F3 /* MutationObserverInterestGroup.cpp in Sources */,
</span><span class="cx">                                 D6E276AF14637455001D280A /* MutationObserverRegistration.cpp in Sources */,
</span><span class="cx">                                 C6F08FBC1430FE8F00685849 /* MutationRecord.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingSelectionRectGatherercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/SelectionRectGatherer.cpp (0 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/SelectionRectGatherer.cpp         (rev 0)
+++ trunk/Source/WebCore/editing/SelectionRectGatherer.cpp        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -0,0 +1,79 @@
</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.
+ */
+
+#include "config.h"
+#include "SelectionRectGatherer.h"
+
+#include "Editor.h"
+#include "EditorClient.h"
+#include "Frame.h"
+#include "RenderView.h"
+
+#if ENABLE(SERVICE_CONTROLS)
+
+namespace WebCore {
+
+SelectionRectGatherer::SelectionRectGatherer(RenderView& renderView)
+ : m_renderView(renderView)
+{
+}
+
+void SelectionRectGatherer::addRect(const LayoutRect& rect)
+{
+ if (!rect.isEmpty())
+ m_rects.append(rect);
+}
+
+void SelectionRectGatherer::addRects(const GapRects& rects)
+{
+ if (!rects.left().isEmpty())
+ m_rects.append(rects.left());
+ if (!rects.right().isEmpty())
+ m_rects.append(rects.right());
+ if (!rects.center().isEmpty())
+ m_rects.append(rects.center());
+}
+
+SelectionRectGatherer::Notifier::Notifier(SelectionRectGatherer& gatherer)
+ : m_gatherer(gatherer)
+{
+}
+
+SelectionRectGatherer::Notifier::~Notifier()
+{
+ if (EditorClient* client = m_gatherer.m_renderView.view().frame().editor().client())
+ client->selectionRectsDidChange(m_gatherer.m_rects);
+}
+
+std::unique_ptr<SelectionRectGatherer::Notifier> SelectionRectGatherer::clearAndCreateNotifier()
+{
+ m_rects.clear();
+
+ return std::make_unique<Notifier>(*this);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_CONTROLS)
</ins></span></pre></div>
<a id="trunkSourceWebCoreeditingSelectionRectGathererh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/SelectionRectGatherer.h (0 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/SelectionRectGatherer.h         (rev 0)
+++ trunk/Source/WebCore/editing/SelectionRectGatherer.h        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -0,0 +1,70 @@
</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 SelectionRectGatherer_h
+#define SelectionRectGatherer_h
+
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+
+#if ENABLE(SERVICE_CONTROLS)
+
+namespace WebCore {
+
+class LayoutRect;
+class RenderView;
+
+struct GapRects;
+
+class SelectionRectGatherer {
+ WTF_MAKE_NONCOPYABLE(SelectionRectGatherer);
+
+public:
+ SelectionRectGatherer(RenderView&);
+
+ void addRect(const LayoutRect&);
+ void addRects(const GapRects&);
+
+ class Notifier {
+ WTF_MAKE_NONCOPYABLE(Notifier);
+ public:
+ Notifier(SelectionRectGatherer&);
+ ~Notifier();
+
+ private:
+ SelectionRectGatherer& m_gatherer;
+ };
+
+ std::unique_ptr<Notifier> clearAndCreateNotifier();
+
+private:
+ RenderView& m_renderView;
+ Vector<LayoutRect> m_rects;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_CONTROLS)
+#endif // SelectionRectGatherer_h
</ins></span></pre></div>
<a id="trunkSourceWebCorepageEditorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EditorClient.h (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EditorClient.h        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebCore/page/EditorClient.h        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -55,6 +55,7 @@
</span><span class="cx"> class Frame;
</span><span class="cx"> class HTMLElement;
</span><span class="cx"> class KeyboardEvent;
</span><ins>+class LayoutRect;
</ins><span class="cx"> class Node;
</span><span class="cx"> class Range;
</span><span class="cx"> class SharedBuffer;
</span><span class="lines">@@ -182,6 +183,10 @@
</span><span class="cx"> virtual void selectedTelephoneNumberRangesChanged(const Vector<RefPtr<Range>>&) { }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ virtual void selectionRectsDidChange(const Vector<LayoutRect>&) { }
+#endif
+
</ins><span class="cx"> // Support for global selections, used on platforms like the X Window System that treat
</span><span class="cx"> // selection as a type of clipboard.
</span><span class="cx"> virtual bool supportsGlobalSelection() { return false; }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderView.cpp (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderView.cpp        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebCore/rendering/RenderView.cpp        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -72,6 +72,9 @@
</span><span class="cx"> #if ENABLE(CSS_FILTERS)
</span><span class="cx"> , m_hasSoftwareFilters(false)
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ , m_selectionRectGatherer(*this)
+#endif
</ins><span class="cx"> {
</span><span class="cx"> setIsRenderView();
</span><span class="cx">
</span><span class="lines">@@ -760,6 +763,12 @@
</span><span class="cx">
</span><span class="cx"> void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
</span><span class="cx"> {
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ // Clear the current rects and create a notifier for the new rects we are about to gather.
+ // The Notifier updates the Editor when it goes out of scope and is destroyed.
+ std::unique_ptr<SelectionRectGatherer::Notifier> rectNotifier = m_selectionRectGatherer.clearAndCreateNotifier();
+#endif // ENABLE(SERVICE_CONTROLS)
+
</ins><span class="cx"> // Make sure both our start and end objects are defined.
</span><span class="cx"> // Check www.msnbc.com and try clicking around to find the case where this happened.
</span><span class="cx"> if ((start && !end) || (end && !start))
</span><span class="lines">@@ -933,7 +942,14 @@
</span><span class="cx"> o = start;
</span><span class="cx"> while (o && o != stop) {
</span><span class="cx"> if ((o->canBeSelectionLeaf() || o == start || o == end) && o->selectionState() != SelectionNone) {
</span><del>- newSelectedObjects.set(o, std::make_unique<RenderSelectionInfo>(o, true));
</del><ins>+ std::unique_ptr<RenderSelectionInfo> selectionInfo = std::make_unique<RenderSelectionInfo>(o, true);
+
+#if ENABLE(SERVICE_CONTROLS)
+ m_selectionRectGatherer.addRect(selectionInfo->rect());
+#endif
+
+ newSelectedObjects.set(o, std::move(selectionInfo));
+
</ins><span class="cx"> RenderBlock* cb = o->containingBlock();
</span><span class="cx"> while (cb && !cb->isRenderView()) {
</span><span class="cx"> std::unique_ptr<RenderBlockSelectionInfo>& blockInfo = newSelectedBlocks.add(cb, nullptr).iterator->value;
</span><span class="lines">@@ -941,6 +957,10 @@
</span><span class="cx"> break;
</span><span class="cx"> blockInfo = std::make_unique<RenderBlockSelectionInfo>(cb);
</span><span class="cx"> cb = cb->containingBlock();
</span><ins>+
+#if ENABLE(SERVICE_CONTROLS)
+ m_selectionRectGatherer.addRects(blockInfo->rects());
+#endif
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderView.h (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderView.h        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebCore/rendering/RenderView.h        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -32,6 +32,10 @@
</span><span class="cx"> #include <wtf/HashSet.h>
</span><span class="cx"> #include <wtf/OwnPtr.h>
</span><span class="cx">
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+#include "SelectionRectGatherer.h"
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> class FlowThreadController;
</span><span class="lines">@@ -354,6 +358,10 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> HashSet<RenderElement*> m_renderersWithPausedImageAnimation;
</span><ins>+
+#if ENABLE(SERVICE_CONTROLS)
+ SelectionRectGatherer m_selectionRectGatherer;
+#endif
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView())
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebKit2/ChangeLog        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2014-04-25 Brady Eidson <beidson@apple.com>
+
+ Add a selection overlay.
+ <rdar://problem/16727797> and https://bugs.webkit.org/show_bug.cgi?id=132200
+
+ Reviewed by David Hyatt.
+
+ * WebKit2.xcodeproj/project.pbxproj:
+
+ * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+ (WebKit::WebEditorClient::selectionRectsDidChange): Pass the new selection rects on
+ to the selection overlay controller.
+ * WebProcess/WebCoreSupport/WebEditorClient.h:
+
+ * WebProcess/WebPage/SelectionOverlayController.cpp: Added.
+ (WebKit::SelectionOverlayController::SelectionOverlayController):
+ (WebKit::SelectionOverlayController::createOverlayIfNeeded):
+ (WebKit::SelectionOverlayController::destroyOverlay):
+ (WebKit::SelectionOverlayController::pageOverlayDestroyed):
+ (WebKit::SelectionOverlayController::willMoveToWebPage):
+ (WebKit::SelectionOverlayController::didMoveToWebPage):
+ (WebKit::SelectionOverlayController::selectionRectsDidChange):
+ (WebKit::SelectionOverlayController::drawRect):
+ (WebKit::SelectionOverlayController::mouseEvent):
+ * WebProcess/WebPage/SelectionOverlayController.h: Added.
+ (WebKit::SelectionOverlayController::create):
+ * WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm: Added.
+ (WebKit::SelectionOverlayController::drawRect):
+ (WebKit::SelectionOverlayController::mouseEvent):
+ (WebKit::SelectionOverlayController::handleClick):
+ (WebKit::SelectionOverlayController::clearHighlight):
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::selectionOverlayController):
+ * WebProcess/WebPage/WebPage.h:
+
</ins><span class="cx"> 2014-04-25 Enrica Casucci <enrica@apple.com>
</span><span class="cx">
</span><span class="cx"> Remove duplicate member variable in WKAutocorrectionRects and WKAutocorrectionContext.
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -905,6 +905,9 @@
</span><span class="cx">                 51E35205180F5D4F00E53BE9 /* DatabaseProcessMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35203180F5D4B00E53BE9 /* DatabaseProcessMain.mm */; };
</span><span class="cx">                 51E35209180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */; };
</span><span class="cx">                 51E3B67F16F266B3009968DC /* NetworkResourceLoaderMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E3B67E16F266B3009968DC /* NetworkResourceLoaderMac.mm */; };
</span><ins>+                51EF124E19098522008A6532 /* SelectionOverlayController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51EF124C19098522008A6532 /* SelectionOverlayController.cpp */; };
+                51EF124F19098523008A6532 /* SelectionOverlayController.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EF124D19098522008A6532 /* SelectionOverlayController.h */; };
+                51EF125119098531008A6532 /* SelectionOverlayControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51EF125019098531008A6532 /* SelectionOverlayControllerMac.mm */; };
</ins><span class="cx">                 51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FA2D541521118600C1BA0B /* WKBundleDOMWindowExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */; };
</span><span class="cx">                 51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */; };
</span><span class="lines">@@ -2757,6 +2760,9 @@
</span><span class="cx">                 51E35207180F5D6100E53BE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
</span><span class="cx">                 51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseServiceEntryPoint.mm; sourceTree = "<group>"; };
</span><span class="cx">                 51E3B67E16F266B3009968DC /* NetworkResourceLoaderMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkResourceLoaderMac.mm; sourceTree = "<group>"; };
</span><ins>+                51EF124C19098522008A6532 /* SelectionOverlayController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionOverlayController.cpp; sourceTree = "<group>"; };
+                51EF124D19098522008A6532 /* SelectionOverlayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionOverlayController.h; sourceTree = "<group>"; };
+                51EF125019098531008A6532 /* SelectionOverlayControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SelectionOverlayControllerMac.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoaderMessageReceiver.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebResourceLoaderMessages.h; sourceTree = "<group>"; };
</span><span class="cx">                 51F7DC4A180CC93600212CA3 /* com.apple.WebKit.Databases.xpc */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = com.apple.WebKit.Databases.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="lines">@@ -5316,6 +5322,8 @@
</span><span class="cx">                                 1A90C23512650717003E44D4 /* PageOverlay.h */,
</span><span class="cx">                                 2D140EAD18F37BE0005E75A0 /* PageOverlayController.cpp */,
</span><span class="cx">                                 2D140EAE18F37BE0005E75A0 /* PageOverlayController.h */,
</span><ins>+                                51EF124C19098522008A6532 /* SelectionOverlayController.cpp */,
+                                51EF124D19098522008A6532 /* SelectionOverlayController.h */,
</ins><span class="cx">                                 519EF58F18EF77210003B7F4 /* TelephoneNumberOverlayController.cpp */,
</span><span class="cx">                                 519EF59018EF77210003B7F4 /* TelephoneNumberOverlayController.h */,
</span><span class="cx">                                 2D819B99186275B3001F03D1 /* ViewGestureGeometryCollector.cpp */,
</span><span class="lines">@@ -6071,6 +6079,7 @@
</span><span class="cx">                                 1AB16AE7164B3A8800290D62 /* RemoteLayerTreeContext.mm */,
</span><span class="cx">                                 1AB16ADC1648598400290D62 /* RemoteLayerTreeDrawingArea.h */,
</span><span class="cx">                                 1AB16ADB1648598400290D62 /* RemoteLayerTreeDrawingArea.mm */,
</span><ins>+                                51EF125019098531008A6532 /* SelectionOverlayControllerMac.mm */,
</ins><span class="cx">                                 519EF58D18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm */,
</span><span class="cx">                                 1AAF263714687C39004A1E8A /* TiledCoreAnimationDrawingArea.h */,
</span><span class="cx">                                 1AAF263614687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm */,
</span><span class="lines">@@ -7346,6 +7355,7 @@
</span><span class="cx">                                 29501724162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h in Headers */,
</span><span class="cx">                                 1F7506B61859165700EC0FF7 /* WKWebProcessPlugInNodeHandleInternal.h in Headers */,
</span><span class="cx">                                 1F7506B51859165400EC0FF7 /* WKWebProcessPlugInScriptWorldInternal.h in Headers */,
</span><ins>+                                51EF124F19098523008A6532 /* SelectionOverlayController.h in Headers */,
</ins><span class="cx">                                 373CEAD6185417AE008C363D /* WKNSData.h in Headers */,
</span><span class="cx">                                 1AB8A1F018400B0000E9AE69 /* WKPageFormClient.h in Headers */,
</span><span class="cx">                                 BC989D85161A9890000D46D3 /* WKWebProcessPlugInInternal.h in Headers */,
</span><span class="lines">@@ -8447,6 +8457,7 @@
</span><span class="cx">                                 BCAC112012C92C1F00B08EEE /* WebDatabaseManagerProxyClient.cpp in Sources */,
</span><span class="cx">                                 F62A76B812B1B25F0005F1B6 /* WebDatabaseManagerProxyMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 517DD5C5180DC3E10081660B /* DatabaseProcessProxyMac.mm in Sources */,
</span><ins>+                                51EF125119098531008A6532 /* SelectionOverlayControllerMac.mm in Sources */,
</ins><span class="cx">                                 BC111A5D112F4FBB00337BAB /* WebDragClient.cpp in Sources */,
</span><span class="cx">                                 C574A37712E6099D002DFE98 /* WebDragClientMac.mm in Sources */,
</span><span class="cx">                                 BCA0EFA012332642007D3CFB /* WebEditCommandProxy.cpp in Sources */,
</span><span class="lines">@@ -8589,6 +8600,7 @@
</span><span class="cx">                                 3336762F130C9998006C9DE2 /* WebResourceCacheManager.cpp in Sources */,
</span><span class="cx">                                 33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */,
</span><span class="cx">                                 33367655130C9ECA006C9DE2 /* WebResourceCacheManagerMessageReceiver.cpp in Sources */,
</span><ins>+                                51EF124E19098522008A6532 /* SelectionOverlayController.cpp in Sources */,
</ins><span class="cx">                                 33367635130C99B2006C9DE2 /* WebResourceCacheManagerProxy.cpp in Sources */,
</span><span class="cx">                                 33367657130C9ECA006C9DE2 /* WebResourceCacheManagerProxyMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 1A8E7D3C18C15149005A702A /* VisitedLinkTableControllerMessageReceiver.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebEditorClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include "WebEditorClient.h"
</span><span class="cx">
</span><span class="cx"> #include "EditorState.h"
</span><ins>+#include "SelectionOverlayController.h"
</ins><span class="cx"> #include "TelephoneNumberOverlayController.h"
</span><span class="cx"> #include "WebCoreArgumentCoders.h"
</span><span class="cx"> #include "WebFrame.h"
</span><span class="lines">@@ -531,4 +532,11 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+void WebEditorClient::selectionRectsDidChange(const Vector<LayoutRect>& rects)
+{
+ m_page->selectionOverlayController().selectionRectsDidChange(rects);
+}
+#endif // ENABLE(SERVICE_CONTROLS)
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebEditorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -170,6 +170,9 @@
</span><span class="cx"> #if ENABLE(TELEPHONE_NUMBER_DETECTION)
</span><span class="cx"> virtual void selectedTelephoneNumberRangesChanged(const Vector<RefPtr<WebCore::Range>>&) override;
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ virtual void selectionRectsDidChange(const Vector<WebCore::LayoutRect>&) override;
+#endif
</ins><span class="cx">
</span><span class="cx"> WebPage* m_page;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp (0 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp         (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -0,0 +1,118 @@
</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.
+ */
+
+#include "config.h"
+#include "SelectionOverlayController.h"
+
+#if ENABLE(SERVICE_CONTROLS)
+
+#include "WebPage.h"
+#include <WebCore/NotImplemented.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+SelectionOverlayController::SelectionOverlayController(WebPage* webPage)
+ : m_webPage(webPage)
+ , m_selectionOverlay(nullptr)
+ , m_mouseIsDownOnButton(false)
+ , m_mouseIsOverHighlight(false)
+{
+}
+
+void SelectionOverlayController::createOverlayIfNeeded()
+{
+ if (m_selectionOverlay) {
+ m_selectionOverlay->setNeedsDisplay();
+ return;
+ }
+
+ RefPtr<PageOverlay> overlay = PageOverlay::create(this, PageOverlay::OverlayType::Document);
+ m_selectionOverlay = overlay.get();
+ m_webPage->installPageOverlay(overlay.release(), PageOverlay::FadeMode::Fade);
+ m_selectionOverlay->setNeedsDisplay();
+}
+
+void SelectionOverlayController::destroyOverlay()
+{
+ if (!m_selectionOverlay)
+ return;
+
+ m_webPage->uninstallPageOverlay(m_selectionOverlay, PageOverlay::FadeMode::DoNotFade);
+}
+
+void SelectionOverlayController::pageOverlayDestroyed(PageOverlay*)
+{
+ // Before the overlay is destroyed, it should have moved out of the WebPage,
+ // at which point we already cleared our back pointer.
+ ASSERT(!m_selectionOverlay);
+}
+
+void SelectionOverlayController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
+{
+ if (webPage)
+ return;
+
+ ASSERT(m_selectionOverlay);
+ m_selectionOverlay = nullptr;
+}
+
+void SelectionOverlayController::didMoveToWebPage(PageOverlay*, WebPage*)
+{
+}
+
+void SelectionOverlayController::selectionRectsDidChange(const Vector<LayoutRect>& rects)
+{
+#if __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
+ clearHighlight();
+
+ m_currentSelectionRects = rects;
+
+ if (m_currentSelectionRects.isEmpty())
+ destroyOverlay();
+ else
+ createOverlayIfNeeded();
+#else
+ UNUSED_PARAM(rects);
+#endif
+}
+
+#if !PLATFORM(MAC)
+void SelectionOverlayController::drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect&)
+{
+ notImplemented();
+}
+
+bool SelectionOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent&)
+{
+ notImplemented();
+ return false;
+}
+#endif
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_CONTROLS)
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllerh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h (0 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h         (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -0,0 +1,89 @@
</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 SelectionOverlayController_h
+
+#if ENABLE(SERVICE_CONTROLS)
+
+#include "PageOverlay.h"
+#include "WebPage.h"
+#include <wtf/RefCounted.h>
+
+#if PLATFORM(MAC)
+typedef void* DDHighlightRef;
+#endif
+
+namespace WebCore {
+class LayoutRect;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class SelectionOverlayController : public RefCounted<SelectionOverlayController>, private PageOverlay::Client {
+public:
+
+ static PassRefPtr<SelectionOverlayController> create(WebPage* webPage)
+ {
+ return adoptRef(new SelectionOverlayController(webPage));
+ }
+
+ void selectionRectsDidChange(const Vector<WebCore::LayoutRect>&);
+ void handleClick(const WebCore::IntPoint&);
+
+private:
+ SelectionOverlayController(WebPage*);
+
+ void createOverlayIfNeeded();
+ void destroyOverlay();
+
+ void handleSelectionOverlayClick(const WebCore::IntPoint&);
+
+ virtual void pageOverlayDestroyed(PageOverlay*) override;
+ virtual void willMoveToWebPage(PageOverlay*, WebPage*) override;
+ virtual void didMoveToWebPage(PageOverlay*, WebPage*) override;
+ virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override;
+ virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&) override;
+
+ void clearHighlight();
+
+ RefPtr<WebPage> m_webPage;
+ PageOverlay* m_selectionOverlay;
+ Vector<WebCore::LayoutRect> m_currentSelectionRects;
+
+ WebCore::IntPoint m_mousePosition;
+ bool m_mouseIsDownOnButton;
+ bool m_mouseIsOverHighlight;
+
+#if PLATFORM(MAC)
+ RetainPtr<DDHighlightRef> m_currentHighlight;
+#endif
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_CONTROLS)
+#endif // SelectionOverlayController_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx"> #include "PluginProxy.h"
</span><span class="cx"> #include "PluginView.h"
</span><span class="cx"> #include "PrintInfo.h"
</span><ins>+#include "SelectionOverlayController.h"
</ins><span class="cx"> #include "SessionState.h"
</span><span class="cx"> #include "SessionTracker.h"
</span><span class="cx"> #include "ShareableBitmap.h"
</span><span class="lines">@@ -4570,6 +4571,16 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+SelectionOverlayController& WebPage::selectionOverlayController()
+{
+ if (!m_selectionOverlayController)
+ m_selectionOverlayController = SelectionOverlayController::create(this);
+
+ return *m_selectionOverlayController;
+}
+#endif
+
</ins><span class="cx"> void WebPage::didChangeScrollOffsetForFrame(Frame* frame)
</span><span class="cx"> {
</span><span class="cx"> m_pageOverlayController.didScrollFrame(frame);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (167829 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-04-25 22:18:36 UTC (rev 167829)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -140,6 +140,7 @@
</span><span class="cx"> class PageBanner;
</span><span class="cx"> class PageOverlay;
</span><span class="cx"> class PluginView;
</span><ins>+class SelectionOverlayController;
</ins><span class="cx"> class SessionState;
</span><span class="cx"> class VisibleContentRectUpdateInfo;
</span><span class="cx"> class WebColorChooser;
</span><span class="lines">@@ -783,6 +784,9 @@
</span><span class="cx"> TelephoneNumberOverlayController& telephoneNumberOverlayController();
</span><span class="cx"> void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&);
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ SelectionOverlayController& selectionOverlayController();
+#endif
</ins><span class="cx">
</span><span class="cx"> void didChangeScrollOffsetForFrame(WebCore::Frame*);
</span><span class="cx">
</span><span class="lines">@@ -1200,6 +1204,9 @@
</span><span class="cx"> #if ENABLE(TELEPHONE_NUMBER_DETECTION)
</span><span class="cx"> RefPtr<TelephoneNumberOverlayController> m_telephoneNumberOverlayController;
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ RefPtr<SelectionOverlayController> m_selectionOverlayController;
+#endif
</ins><span class="cx">
</span><span class="cx"> PageOverlayController m_pageOverlayController;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacSelectionOverlayControllerMacmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm (0 => 167830)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm         (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm        2014-04-25 22:22:14 UTC (rev 167830)
</span><span class="lines">@@ -0,0 +1,174 @@
</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 "SelectionOverlayController.h"
+
+#if ENABLE(SERVICE_CONTROLS)
+
+#import <WebCore/FrameView.h>
+#import <WebCore/GraphicsContext.h>
+#import <WebCore/MainFrame.h>
+#import <WebCore/SoftLinking.h>
+
+#if __has_include(<DataDetectors/DDHighlightDrawing.h>)
+#import <DataDetectors/DDHighlightDrawing.h>
+#else
+typedef void* DDHighlightRef;
+#endif
+
+#if __has_include(<DataDetectors/DDHighlightDrawing_Private.h>)
+#import <DataDetectors/DDHighlightDrawing_Private.h>
+#endif
+
+SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectors)
+SOFT_LINK(DataDetectors, DDHighlightCreateWithRectsInVisibleRect, DDHighlightRef, (CFAllocatorRef allocator, CGRect * rects, CFIndex count, CGRect globalVisibleRect, Boolean withArrow), (allocator, rects, count, globalVisibleRect, withArrow))
+SOFT_LINK(DataDetectors, DDHighlightGetLayerWithContext, CGLayerRef, (DDHighlightRef highlight, CGContextRef context), (highlight, context))
+SOFT_LINK(DataDetectors, DDHighlightGetBoundingRect, CGRect, (DDHighlightRef highlight), (highlight))
+SOFT_LINK(DataDetectors, DDHighlightPointIsOnHighlight, Boolean, (DDHighlightRef highlight, CGPoint point, Boolean* onButton), (highlight, point, onButton))
+SOFT_LINK(DataDetectors, DDHighlightSetButtonPressed, void, (DDHighlightRef highlight, Boolean buttonPressed), (highlight, buttonPressed))
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void SelectionOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
+{
+ if (m_currentSelectionRects.isEmpty())
+ return;
+
+ if (!m_currentHighlight) {
+ Vector<CGRect> cgRects;
+ cgRects.reserveCapacity(m_currentSelectionRects.size());
+
+ for (auto& rect : m_currentSelectionRects)
+ cgRects.append((CGRect)pixelSnappedIntRect(rect));
+
+ m_currentHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRect(nullptr, cgRects.begin(), cgRects.size(), (CGRect)dirtyRect, true));
+
+ Boolean onButton;
+ m_mouseIsOverHighlight = DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &onButton);
+ }
+
+ // If the mouse is not over the DDHighlight we have no drawing to do.
+ if (!m_mouseIsOverHighlight)
+ return;
+
+ CGContextRef cgContext = graphicsContext.platformContext();
+
+ CGLayerRef highlightLayer = DDHighlightGetLayerWithContext(m_currentHighlight.get(), cgContext);
+ CGRect highlightBoundingRect = DDHighlightGetBoundingRect(m_currentHighlight.get());
+
+ GraphicsContextStateSaver stateSaver(graphicsContext);
+
+ graphicsContext.translate(toFloatSize(highlightBoundingRect.origin));
+ graphicsContext.scale(FloatSize(1, -1));
+ graphicsContext.translate(FloatSize(0, -highlightBoundingRect.size.height));
+
+ CGRect highlightDrawRect = highlightBoundingRect;
+ highlightDrawRect.origin.x = 0;
+ highlightDrawRect.origin.y = 0;
+
+ CGContextDrawLayerInRect(cgContext, highlightDrawRect, highlightLayer);
+}
+
+bool SelectionOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& event)
+{
+ m_mousePosition = m_webPage->corePage()->mainFrame().view()->rootViewToContents(event.position());
+
+ bool mouseWasOverHighlight = m_mouseIsOverHighlight;
+ Boolean onButton = false;
+ m_mouseIsOverHighlight = m_currentHighlight ? DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &onButton) : false;
+
+ if (mouseWasOverHighlight != m_mouseIsOverHighlight)
+ m_selectionOverlay->setNeedsDisplay();
+
+ // If this event has nothing to do with the left button, it clears the current mouse down tracking and we're done processing it.
+ if (event.button() != WebMouseEvent::LeftButton) {
+ m_mouseIsDownOnButton = false;
+ return false;
+ }
+
+ if (!m_currentHighlight)
+ return false;
+
+ // Check and see if the mouse went up and we have a current mouse down highlight button.
+ if (event.type() == WebEvent::MouseUp) {
+ bool mouseWasDownOnButton = m_mouseIsDownOnButton;
+ m_mouseIsDownOnButton = false;
+
+ // If the mouse lifted while still over the highlight button that it went down on, then that is a click.
+ if (m_mouseIsOverHighlight && onButton && mouseWasDownOnButton) {
+ handleClick(m_mousePosition);
+ return true;
+ }
+
+ return false;
+ }
+
+ // Check and see if the mouse moved within the confines of the DD highlight button.
+ if (event.type() == WebEvent::MouseMove) {
+ // Moving with the mouse button down is okay as long as the mouse never leaves the highlight button.
+ if (m_mouseIsOverHighlight && onButton)
+ return true;
+
+ m_mouseIsDownOnButton = false;
+
+ return false;
+ }
+
+ // Check and see if the mouse went down over a DD highlight button.
+ if (event.type() == WebEvent::MouseDown) {
+ if (m_mouseIsOverHighlight && onButton) {
+ m_mouseIsDownOnButton = true;
+
+ // FIXME: We need to do the following, but SOFT_LINK isn't working for this method.
+ // DDHighlightSetButtonPressed(m_currentHighlight.get(), true);
+
+ m_selectionOverlay->setNeedsDisplay();
+ return true;
+ }
+
+ return false;
+ }
+
+ return false;
+}
+
+void SelectionOverlayController::handleClick(const WebCore::IntPoint& point)
+{
+ // FIXME: Handle the click here.
+}
+
+void SelectionOverlayController::clearHighlight()
+{
+ m_currentHighlight.clear();
+ m_mouseIsOverHighlight = false;
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_CONTROLS)
+
</ins></span></pre>
</div>
</div>
</body>
</html>