<!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>[166208] trunk/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/166208">166208</a></dd>
<dt>Author</dt> <dd>enrica@apple.com</dd>
<dt>Date</dt> <dd>2014-03-24 16:51:58 -0700 (Mon, 24 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS WebKit2] Dictation support.
https://bugs.webkit.org/show_bug.cgi?id=130622
&lt;rdar://problem/15337316&gt;

Reviewed by Benjamin Poulain.

Adding support for dictation on iOS. There are two main types of interactions
with the dictation system:
- initial request for context, which consists in retrieving the selected text
and 5 words before the selection and 5 words after, if available.
- insertion of recognized chunks of text, providing the text
to replace.
    
* UIProcess/AutoCorrectionCallback.h:
(WebKit::DictationContextCallback::create):
(WebKit::DictationContextCallback::~DictationContextCallback):
(WebKit::DictationContextCallback::performCallbackWithReturnValue):
(WebKit::DictationContextCallback::invalidate):
(WebKit::DictationContextCallback::DictationContextCallback):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView replaceDictatedText:withText:]):
(-[WKContentView requestDictationContext:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::dictationContextCallback):
(WebKit::WebPageProxy::replaceDictatedText):
(WebKit::WebPageProxy::requestDictationContext):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestDictationContext):
(WebKit::WebPage::replaceDictatedText):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutoCorrectionCallbackh">trunk/Source/WebKit2/UIProcess/AutoCorrectionCallback.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionh">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm">trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/ChangeLog        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2014-03-24  Enrica Casucci  &lt;enrica@apple.com&gt;
+
+        [iOS WebKit2] Dictation support.
+        https://bugs.webkit.org/show_bug.cgi?id=130622
+        &lt;rdar://problem/15337316&gt;
+
+        Reviewed by Benjamin Poulain.
+
+        Adding support for dictation on iOS. There are two main types of interactions
+        with the dictation system:
+        - initial request for context, which consists in retrieving the selected text
+        and 5 words before the selection and 5 words after, if available.
+        - insertion of recognized chunks of text, providing the text
+        to replace.
+    
+        * UIProcess/AutoCorrectionCallback.h:
+        (WebKit::DictationContextCallback::create):
+        (WebKit::DictationContextCallback::~DictationContextCallback):
+        (WebKit::DictationContextCallback::performCallbackWithReturnValue):
+        (WebKit::DictationContextCallback::invalidate):
+        (WebKit::DictationContextCallback::DictationContextCallback):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView replaceDictatedText:withText:]):
+        (-[WKContentView requestDictationContext:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::dictationContextCallback):
+        (WebKit::WebPageProxy::replaceDictatedText):
+        (WebKit::WebPageProxy::requestDictationContext):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDictationContext):
+        (WebKit::WebPage::replaceDictatedText):
+
</ins><span class="cx"> 2014-03-24  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Yet another iOS build fix, for the 32-bit build this time.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutoCorrectionCallbackh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/AutoCorrectionCallback.h (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/AutoCorrectionCallback.h        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/UIProcess/AutoCorrectionCallback.h        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -119,6 +119,46 @@
</span><span class="cx">     CallbackFunction m_callback;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+class DictationContextCallback : public CallbackBase {
+public:
+    typedef std::function&lt;void (bool, const String&amp;, const String&amp;, const String&amp;)&gt; CallbackFunction;
+
+    static PassRefPtr&lt;DictationContextCallback&gt; create(CallbackFunction callback)
+    {
+        return adoptRef(new DictationContextCallback(callback));
+    }
+
+    virtual ~DictationContextCallback()
+    {
+        ASSERT(!m_callback);
+    }
+
+    void performCallbackWithReturnValue(const String&amp; returnValue1, const String&amp; returnValue2, const String&amp; returnValue3)
+    {
+        ASSERT(m_callback);
+
+        m_callback(false, returnValue1, returnValue2, returnValue3);
+        m_callback = nullptr;
+    }
+
+    void invalidate()
+    {
+        ASSERT(m_callback);
+
+        m_callback(true, String(), String(), String());
+        m_callback = nullptr;
+    }
+    
+private:
+    DictationContextCallback(CallbackFunction callback)
+        : m_callback(callback)
+    {
+        ASSERT(m_callback);
+    }
+    
+    CallbackFunction m_callback;
+};
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // AutoCorrectionCallback_h
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -586,6 +586,8 @@
</span><span class="cx">     bool applyAutocorrection(const String&amp; correction, const String&amp; originalText);
</span><span class="cx">     void requestAutocorrectionContext(PassRefPtr&lt;AutocorrectionContextCallback&gt;);
</span><span class="cx">     void getAutocorrectionContext(String&amp; contextBefore, String&amp; markedText, String&amp; selectedText, String&amp; contextAfter, uint64_t&amp; location, uint64_t&amp; length);
</span><ins>+    void requestDictationContext(PassRefPtr&lt;DictationContextCallback&gt;);
+    void replaceDictatedText(const String&amp; oldText, const String&amp; newText);
</ins><span class="cx">     void didReceivePositionInformation(const InteractionInformationAtPosition&amp;);
</span><span class="cx">     void getPositionInformation(const WebCore::IntPoint&amp;, InteractionInformationAtPosition&amp;);
</span><span class="cx">     void requestPositionInformation(const WebCore::IntPoint&amp;);
</span><span class="lines">@@ -1280,6 +1282,7 @@
</span><span class="cx">     void touchesCallback(const WebCore::IntPoint&amp;, uint32_t, uint64_t);
</span><span class="cx">     void autocorrectionDataCallback(const Vector&lt;WebCore::FloatRect&gt;&amp;, const String&amp;, float, uint64_t, uint64_t);
</span><span class="cx">     void autocorrectionContextCallback(const String&amp;, const String&amp;, const String&amp;, const String&amp;, uint64_t, uint64_t, uint64_t);
</span><ins>+    void dictationContextCallback(const String&amp;, const String&amp;, const String&amp;, uint64_t);
</ins><span class="cx">     void interpretKeyEvent(const EditorState&amp;, bool isCharEvent, bool&amp; handled);
</span><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="lines">@@ -1423,6 +1426,7 @@
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;TouchesCallback&gt;&gt; m_touchesCallbacks;
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;AutocorrectionDataCallback&gt;&gt; m_autocorrectionCallbacks;
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;AutocorrectionContextCallback&gt;&gt; m_autocorrectionContextCallbacks;
</span><ins>+    HashMap&lt;uint64_t, RefPtr&lt;DictationContextCallback&gt;&gt; m_dictationContextCallbacks;
</ins><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;PrintFinishedCallback&gt;&gt; m_printFinishedCallbacks;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -162,6 +162,7 @@
</span><span class="cx">     TouchesCallback(WebCore::IntPoint point, uint32_t touches, uint64_t callbackID)
</span><span class="cx">     AutocorrectionDataCallback(Vector&lt;WebCore::FloatRect&gt; textRects, String fontName, double fontSize, uint64_t traits, uint64_t callbackID)
</span><span class="cx">     AutocorrectionContextCallback(String beforeText, String markedText, String selectedText, String afterText, uint64_t location, uint64_t length, uint64_t callbackID)
</span><ins>+    DictationContextCallback(String selectedText, String beforeText, String afterText, uint64_t callbackID)
</ins><span class="cx">     InterpretKeyEvent(WebKit::EditorState state, bool isCharEvent) -&gt; (bool handled)
</span><span class="cx">     DidReceivePositionInformation(WebKit::InteractionInformationAtPosition information)
</span><span class="cx">     SaveImageToLibrary(WebKit::SharedMemory::Handle handle, uint64_t size)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx"> 
</span><span class="cx"> typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
</span><span class="cx"> typedef void (^UIWKAutocorrectionContextHandler)(UIWKAutocorrectionContext *autocorrectionContext);
</span><ins>+typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText);
</ins><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> struct WKAutoCorrectionData {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -1262,6 +1262,21 @@
</span><span class="cx">     return (_page-&gt;editorState().hasComposition) ? _page-&gt;editorState().lastMarkedRect : _autocorrectionData.textLastRect;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)replaceDictatedText:(NSString*)oldText withText:(NSString *)newText
+{
+    _page-&gt;replaceDictatedText(oldText, newText);
+}
+
+- (void)requestDictationContext:(void (^)(NSString *selectedText, NSString *beforeText, NSString *afterText))completionHandler
+{
+    UIWKDictationContextHandler dictationHandler = [completionHandler copy];
+
+    _page-&gt;requestDictationContext(DictationContextCallback::create([dictationHandler](bool /*error*/, const String&amp; selectedText, const String&amp; beforeText, const String&amp; afterText) {
+        dictationHandler(selectedText, beforeText, afterText);
+        [dictationHandler release];
+    }));
+}
+
</ins><span class="cx"> // The completion handler should pass the rect of the correction text after replacing the input text, or nil if the replacement could not be performed.
</span><span class="cx"> - (void)applyAutocorrection:(NSString *)correction toString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForCorrection))completionHandler
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -160,6 +160,17 @@
</span><span class="cx">     callback-&gt;performCallbackWithReturnValue(rects, fontName, fontSize, fontTraits);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::dictationContextCallback(const String&amp; selectedText, const String&amp; beforeText, const String&amp; afterText, uint64_t callbackID)
+{
+    RefPtr&lt;DictationContextCallback&gt; callback = m_dictationContextCallbacks.take(callbackID);
+    if (!callback) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    callback-&gt;performCallbackWithReturnValue(selectedText, beforeText, afterText);
+}
+
</ins><span class="cx"> void WebPageProxy::autocorrectionContextCallback(const String&amp; beforeText, const String&amp; markedText, const String&amp; selectedText, const String&amp; afterText, uint64_t location, uint64_t length, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;AutocorrectionContextCallback&gt; callback = m_autocorrectionContextCallbacks.take(callbackID);
</span><span class="lines">@@ -216,7 +227,12 @@
</span><span class="cx">     m_touchesCallbacks.set(callbackID, callback);
</span><span class="cx">     m_process-&gt;send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
</span><span class="cx"> }
</span><del>-
</del><ins>+    
+void WebPageProxy::replaceDictatedText(const String&amp; oldText, const String&amp; newText)
+{
+    m_process-&gt;send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
+}
+    
</ins><span class="cx"> void WebPageProxy::requestAutocorrectionData(const String&amp; textForAutocorrection, PassRefPtr&lt;AutocorrectionDataCallback&gt; callback)
</span><span class="cx"> {
</span><span class="cx">     if (!isValid()) {
</span><span class="lines">@@ -248,6 +264,18 @@
</span><span class="cx">     return autocorrectionApplied;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::requestDictationContext(PassRefPtr&lt;DictationContextCallback&gt; callback)
+{
+    if (!isValid()) {
+        callback-&gt;invalidate();
+        return;
+    }
+
+    uint64_t callbackID = callback-&gt;callbackID();
+    m_dictationContextCallbacks.set(callbackID, callback);
+    m_process-&gt;send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
+}
+
</ins><span class="cx"> void WebPageProxy::requestAutocorrectionContext(PassRefPtr&lt;AutocorrectionContextCallback&gt; callback)
</span><span class="cx"> {
</span><span class="cx">     if (!isValid()) {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -452,6 +452,8 @@
</span><span class="cx">     void extendSelection(uint32_t granularity);
</span><span class="cx">     void elementDidFocus(WebCore::Node*);
</span><span class="cx">     void elementDidBlur(WebCore::Node*);
</span><ins>+    void requestDictationContext(uint64_t callbackID);
+    void replaceDictatedText(const String&amp; oldText, const String&amp; newText);
</ins><span class="cx">     void requestAutocorrectionData(const String&amp; textForAutocorrection, uint64_t callbackID);
</span><span class="cx">     void applyAutocorrection(const String&amp; correction, const String&amp; originalText, uint64_t callbackID);
</span><span class="cx">     void syncApplyAutocorrection(const String&amp; correction, const String&amp; originalText, bool&amp; correctionApplied);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -53,6 +53,8 @@
</span><span class="cx">     UpdateBlockSelectionWithTouch(WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)
</span><span class="cx">     SelectWithTwoTouches(WebCore::IntPoint from, WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, uint64_t callbackID)
</span><span class="cx">     ExtendSelection(uint32_t granularity)
</span><ins>+    RequestDictationContext(uint64_t callbackID)
+    ReplaceDictatedText(String oldText, String newText)
</ins><span class="cx">     RequestAutocorrectionData(String textForAutocorrection, uint64_t callbackID)
</span><span class="cx">     ApplyAutocorrection(String correction, String originalText, uint64_t callbackID)
</span><span class="cx">     SyncApplyAutocorrection(String correction, String originalText) -&gt; (bool autocorrectionApplied)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (166207 => 166208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-03-24 23:44:24 UTC (rev 166207)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-03-24 23:51:58 UTC (rev 166208)
</span><span class="lines">@@ -1189,6 +1189,72 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::requestDictationContext(uint64_t callbackID)
+{
+    Frame&amp; frame = m_page-&gt;focusController().focusedOrMainFrame();
+    VisiblePosition startPosition = frame.selection().selection().start();
+    VisiblePosition endPosition = frame.selection().selection().end();
+    const unsigned dictationContextWordCount = 5;
+
+    String selectedText;
+    if (frame.selection().isRange())
+        selectedText = plainText(frame.selection().selection().toNormalizedRange().get());
+
+    String contextBefore;
+    if (startPosition != startOfEditableContent(startPosition)) {
+        VisiblePosition currentPosition = startPosition;
+        VisiblePosition lastPosition = startPosition;
+        for (unsigned i = 0; i &lt; dictationContextWordCount; ++i) {
+            currentPosition = startOfWord(positionOfNextBoundaryOfGranularity(lastPosition, WordGranularity, DirectionBackward));
+            if (currentPosition.isNull())
+                break;
+            lastPosition = currentPosition;
+        }
+        if (lastPosition.isNotNull() &amp;&amp; lastPosition != startPosition)
+            contextBefore = plainText(Range::create(*frame.document(), lastPosition, startPosition).get());
+    }
+
+    String contextAfter;
+    if (endPosition != endOfEditableContent(endPosition)) {
+        VisiblePosition currentPosition = endPosition;
+        VisiblePosition lastPosition = endPosition;
+        for (unsigned i = 0; i &lt; dictationContextWordCount; ++i) {
+            currentPosition = endOfWord(positionOfNextBoundaryOfGranularity(lastPosition, WordGranularity, DirectionForward));
+            if (currentPosition.isNull())
+                break;
+            lastPosition = currentPosition;
+        }
+        if (lastPosition.isNotNull() &amp;&amp; lastPosition != endPosition)
+            contextAfter = plainText(Range::create(*frame.document(), endPosition, lastPosition).get());
+    }
+
+    send(Messages::WebPageProxy::DictationContextCallback(selectedText, contextBefore, contextAfter, callbackID));
+}
+
+void WebPage::replaceDictatedText(const String&amp; oldText, const String&amp; newText)
+{
+    Frame&amp; frame = m_page-&gt;focusController().focusedOrMainFrame();
+    if (frame.selection().isNone())
+        return;
+    
+    if (frame.selection().isRange()) {
+        frame.editor().deleteSelectionWithSmartDelete(false);
+        return;
+    }
+    VisiblePosition position = frame.selection().selection().start();
+    for (size_t i = 0; i &lt; oldText.length(); ++i)
+        position = position.previous();
+    if (position.isNull())
+        position = startOfDocument(static_cast&lt;Node*&gt;(frame.document()-&gt;documentElement()));
+    RefPtr&lt;Range&gt; range = Range::create(*frame.document(), position, frame.selection().selection().start());
+
+    if (plainText(range.get()) != oldText)
+        return;
+
+    frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
+    frame.editor().insertText(newText, 0);
+}
+
</ins><span class="cx"> void WebPage::requestAutocorrectionData(const String&amp; textForAutocorrection, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;Range&gt; range;
</span></span></pre>
</div>
</div>

</body>
</html>