<!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
<rdar://problem/15337316>
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 <enrica@apple.com>
+
+ [iOS WebKit2] Dictation support.
+ https://bugs.webkit.org/show_bug.cgi?id=130622
+ <rdar://problem/15337316>
+
+ 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 <aestes@apple.com>
</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<void (bool, const String&, const String&, const String&)> CallbackFunction;
+
+ static PassRefPtr<DictationContextCallback> create(CallbackFunction callback)
+ {
+ return adoptRef(new DictationContextCallback(callback));
+ }
+
+ virtual ~DictationContextCallback()
+ {
+ ASSERT(!m_callback);
+ }
+
+ void performCallbackWithReturnValue(const String& returnValue1, const String& returnValue2, const String& 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& correction, const String& originalText);
</span><span class="cx"> void requestAutocorrectionContext(PassRefPtr<AutocorrectionContextCallback>);
</span><span class="cx"> void getAutocorrectionContext(String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length);
</span><ins>+ void requestDictationContext(PassRefPtr<DictationContextCallback>);
+ void replaceDictatedText(const String& oldText, const String& newText);
</ins><span class="cx"> void didReceivePositionInformation(const InteractionInformationAtPosition&);
</span><span class="cx"> void getPositionInformation(const WebCore::IntPoint&, InteractionInformationAtPosition&);
</span><span class="cx"> void requestPositionInformation(const WebCore::IntPoint&);
</span><span class="lines">@@ -1280,6 +1282,7 @@
</span><span class="cx"> void touchesCallback(const WebCore::IntPoint&, uint32_t, uint64_t);
</span><span class="cx"> void autocorrectionDataCallback(const Vector<WebCore::FloatRect>&, const String&, float, uint64_t, uint64_t);
</span><span class="cx"> void autocorrectionContextCallback(const String&, const String&, const String&, const String&, uint64_t, uint64_t, uint64_t);
</span><ins>+ void dictationContextCallback(const String&, const String&, const String&, uint64_t);
</ins><span class="cx"> void interpretKeyEvent(const EditorState&, bool isCharEvent, bool& 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<uint64_t, RefPtr<TouchesCallback>> m_touchesCallbacks;
</span><span class="cx"> HashMap<uint64_t, RefPtr<AutocorrectionDataCallback>> m_autocorrectionCallbacks;
</span><span class="cx"> HashMap<uint64_t, RefPtr<AutocorrectionContextCallback>> m_autocorrectionContextCallbacks;
</span><ins>+ HashMap<uint64_t, RefPtr<DictationContextCallback>> m_dictationContextCallbacks;
</ins><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx"> HashMap<uint64_t, RefPtr<PrintFinishedCallback>> 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<WebCore::FloatRect> 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) -> (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->editorState().hasComposition) ? _page->editorState().lastMarkedRect : _autocorrectionData.textLastRect;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)replaceDictatedText:(NSString*)oldText withText:(NSString *)newText
+{
+ _page->replaceDictatedText(oldText, newText);
+}
+
+- (void)requestDictationContext:(void (^)(NSString *selectedText, NSString *beforeText, NSString *afterText))completionHandler
+{
+ UIWKDictationContextHandler dictationHandler = [completionHandler copy];
+
+ _page->requestDictationContext(DictationContextCallback::create([dictationHandler](bool /*error*/, const String& selectedText, const String& beforeText, const String& 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->performCallbackWithReturnValue(rects, fontName, fontSize, fontTraits);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void WebPageProxy::dictationContextCallback(const String& selectedText, const String& beforeText, const String& afterText, uint64_t callbackID)
+{
+ RefPtr<DictationContextCallback> callback = m_dictationContextCallbacks.take(callbackID);
+ if (!callback) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ callback->performCallbackWithReturnValue(selectedText, beforeText, afterText);
+}
+
</ins><span class="cx"> void WebPageProxy::autocorrectionContextCallback(const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx"> RefPtr<AutocorrectionContextCallback> 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->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
</span><span class="cx"> }
</span><del>-
</del><ins>+
+void WebPageProxy::replaceDictatedText(const String& oldText, const String& newText)
+{
+ m_process->send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
+}
+
</ins><span class="cx"> void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, PassRefPtr<AutocorrectionDataCallback> 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<DictationContextCallback> callback)
+{
+ if (!isValid()) {
+ callback->invalidate();
+ return;
+ }
+
+ uint64_t callbackID = callback->callbackID();
+ m_dictationContextCallbacks.set(callbackID, callback);
+ m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
+}
+
</ins><span class="cx"> void WebPageProxy::requestAutocorrectionContext(PassRefPtr<AutocorrectionContextCallback> 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& oldText, const String& newText);
</ins><span class="cx"> void requestAutocorrectionData(const String& textForAutocorrection, uint64_t callbackID);
</span><span class="cx"> void applyAutocorrection(const String& correction, const String& originalText, uint64_t callbackID);
</span><span class="cx"> void syncApplyAutocorrection(const String& correction, const String& originalText, bool& 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) -> (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& frame = m_page->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 < dictationContextWordCount; ++i) {
+ currentPosition = startOfWord(positionOfNextBoundaryOfGranularity(lastPosition, WordGranularity, DirectionBackward));
+ if (currentPosition.isNull())
+ break;
+ lastPosition = currentPosition;
+ }
+ if (lastPosition.isNotNull() && 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 < dictationContextWordCount; ++i) {
+ currentPosition = endOfWord(positionOfNextBoundaryOfGranularity(lastPosition, WordGranularity, DirectionForward));
+ if (currentPosition.isNull())
+ break;
+ lastPosition = currentPosition;
+ }
+ if (lastPosition.isNotNull() && lastPosition != endPosition)
+ contextAfter = plainText(Range::create(*frame.document(), endPosition, lastPosition).get());
+ }
+
+ send(Messages::WebPageProxy::DictationContextCallback(selectedText, contextBefore, contextAfter, callbackID));
+}
+
+void WebPage::replaceDictatedText(const String& oldText, const String& newText)
+{
+ Frame& frame = m_page->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 < oldText.length(); ++i)
+ position = position.previous();
+ if (position.isNull())
+ position = startOfDocument(static_cast<Node*>(frame.document()->documentElement()));
+ RefPtr<Range> 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& textForAutocorrection, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx"> RefPtr<Range> range;
</span></span></pre>
</div>
</div>
</body>
</html>