<!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>[167624] 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/167624">167624</a></dd>
<dt>Author</dt> <dd>enrica@apple.com</dd>
<dt>Date</dt> <dd>2014-04-21 14:14:30 -0700 (Mon, 21 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS WebKit2] support replacements for misspelled words.
https://bugs.webkit.org/show_bug.cgi?id=131827
&lt;rdar://problem/16319657&gt;

Reviewed by Darin Adler.


Source/WebCore: 
Adds utility function to return the character before the current selection
and converts the nbsp to the space character.

* WebCore.exp.in:
* editing/VisibleUnits.cpp:
(WebCore::characterBeforePosition):
* editing/VisibleUnits.h:

Source/WebKit2: 
This is the second a final piece to support replacements.
It adds some entrypoints used by the keyboard code to perform
replacement when reaching the edge of a word using backspace.
I've modified the behavior of replaceSelectedText to work both
with caret or range selections.

* Shared/EditorState.cpp:
(WebKit::EditorState::encode):
(WebKit::EditorState::decode):
* Shared/EditorState.h:
(WebKit::EditorState::EditorState):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView isReplaceAllowed]):
(-[WKContentView _characterBeforeCaretSelection]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::replaceSelectedText):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreeditingVisibleUnitscpp">trunk/Source/WebCore/editing/VisibleUnits.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingVisibleUnitsh">trunk/Source/WebCore/editing/VisibleUnits.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedEditorStatecpp">trunk/Source/WebKit2/Shared/EditorState.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedEditorStateh">trunk/Source/WebKit2/Shared/EditorState.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</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="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebCore/ChangeLog        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-04-21  Enrica Casucci  &lt;enrica@apple.com&gt;
+
+        [iOS WebKit2] support replacements for misspelled words.
+        https://bugs.webkit.org/show_bug.cgi?id=131827
+        &lt;rdar://problem/16319657&gt;
+
+        Reviewed by Darin Adler.
+
+        Adds utility function to return the character before the current selection
+        and converts the nbsp to the space character.
+
+        * WebCore.exp.in:
+        * editing/VisibleUnits.cpp:
+        (WebCore::characterBeforePosition):
+        * editing/VisibleUnits.h:
+
</ins><span class="cx"> 2014-04-21  Eric Carlson  &lt;eric.carlson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] enable plug-in replacement
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -2570,6 +2570,7 @@
</span><span class="cx"> __ZN7WebCore22startOfEditableContentERKNS_15VisiblePositionE
</span><span class="cx"> __ZN7WebCore23applicationIsMobileMailEv
</span><span class="cx"> __ZN7WebCore23atBoundaryOfGranularityERKNS_15VisiblePositionENS_15TextGranularityENS_18SelectionDirectionE
</span><ins>+__ZN7WebCore23characterBeforePositionERKNS_15VisiblePositionE
</ins><span class="cx"> __ZN7WebCore24DocumentMarkerController14markersInRangeEPNS_5RangeENS_14DocumentMarker11MarkerTypesE
</span><span class="cx"> __ZN7WebCore24acquireLineBreakIteratorEN3WTF10StringViewERKNS0_12AtomicStringEPKtj
</span><span class="cx"> __ZN7WebCore24createTemporaryDirectoryEP8NSString
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingVisibleUnitscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/VisibleUnits.cpp        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -1812,6 +1812,26 @@
</span><span class="cx"> 
</span><span class="cx">     return (thisIsStart ? -distance : distance);
</span><span class="cx"> }
</span><ins>+    
+UChar32 characterBeforePosition(const VisiblePosition&amp; position)
+{
+    if (position.isNull() || isStartOfDocument(position))
+        return 0;
+    VisiblePosition previousPosition = nextCharacterBoundaryInDirection(position, DirectionBackward);
+    if (previousPosition.isNull())
+        return 0;
+    String characterString = plainText(Range::create(position.deepEquivalent().anchorNode()-&gt;document(), previousPosition, position).get(), TextIteratorDefaultBehavior, true);
+    if (characterString.isEmpty())
+        return 0;
+    
+    if (characterString.length() == 2) {
+        UTF32Char lead = characterString[0];
+        UTF32Char trail = characterString[1];
+        if (U16_IS_LEAD(lead) &amp;&amp; U16_IS_TRAIL(trail))
+            return U16_GET_SUPPLEMENTARY(lead, trail);
+    }
+    return characterString[0] != noBreakSpace ? : ' ';
+}
</ins><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;Range&gt; wordRangeFromPosition(const VisiblePosition&amp; position)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingVisibleUnitsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/VisibleUnits.h (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/VisibleUnits.h        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebCore/editing/VisibleUnits.h        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -104,6 +104,7 @@
</span><span class="cx"> int distanceBetweenPositions(const VisiblePosition&amp;, const VisiblePosition&amp;);
</span><span class="cx"> PassRefPtr&lt;Range&gt; wordRangeFromPosition(const VisiblePosition&amp; position);
</span><span class="cx"> VisiblePosition closestWordBoundaryForPosition(const VisiblePosition&amp; position);
</span><ins>+UChar32 characterBeforePosition(const VisiblePosition&amp;);
</ins><span class="cx"> #endif
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebKit2/ChangeLog        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-04-21  Enrica Casucci  &lt;enrica@apple.com&gt;
+
+        [iOS WebKit2] support replacements for misspelled words.
+        https://bugs.webkit.org/show_bug.cgi?id=131827
+        &lt;rdar://problem/16319657&gt;
+
+        Reviewed by Darin Adler.
+
+        This is the second a final piece to support replacements.
+        It adds some entrypoints used by the keyboard code to perform
+        replacement when reaching the edge of a word using backspace.
+        I've modified the behavior of replaceSelectedText to work both
+        with caret or range selections.
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::encode):
+        (WebKit::EditorState::decode):
+        * Shared/EditorState.h:
+        (WebKit::EditorState::EditorState):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView isReplaceAllowed]):
+        (-[WKContentView _characterBeforeCaretSelection]):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::editorState):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::replaceSelectedText):
+
</ins><span class="cx"> 2014-04-21  Gavin Barraclough  &lt;baraclough@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Don't use ProcessAssertion on simulator
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedEditorStatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/EditorState.cpp (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/EditorState.cpp        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebKit2/Shared/EditorState.cpp        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     encoder &lt;&lt; isReplaceAllowed;
</span><ins>+    encoder &lt;&lt; characterBeforeSelection;
</ins><span class="cx">     encoder &lt;&lt; caretRectAtStart;
</span><span class="cx">     encoder &lt;&lt; caretRectAtEnd;
</span><span class="cx">     encoder &lt;&lt; selectionRects;
</span><span class="lines">@@ -92,6 +93,8 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     if (!decoder.decode(result.isReplaceAllowed))
</span><span class="cx">         return false;
</span><ins>+    if (!decoder.decode(result.characterBeforeSelection))
+        return false;
</ins><span class="cx">     if (!decoder.decode(result.caretRectAtStart))
</span><span class="cx">         return false;
</span><span class="cx">     if (!decoder.decode(result.caretRectAtEnd))
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedEditorStateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/EditorState.h (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/EditorState.h        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebKit2/Shared/EditorState.h        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx">         , hasComposition(false)
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">         , isReplaceAllowed(false)
</span><ins>+        , characterBeforeSelection(0)
</ins><span class="cx">         , selectedTextLength(0)
</span><span class="cx"> #endif
</span><span class="cx">     {
</span><span class="lines">@@ -65,6 +66,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     bool isReplaceAllowed;
</span><ins>+    UChar32 characterBeforeSelection;
</ins><span class="cx">     WebCore::IntRect caretRectAtStart;
</span><span class="cx">     WebCore::IntRect caretRectAtEnd;
</span><span class="cx">     Vector&lt;WebCore::SelectionRect&gt; selectionRects;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -860,6 +860,11 @@
</span><span class="cx">     return (NSString *)_page-&gt;editorState().wordAtSelection;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (BOOL)isReplaceAllowed
+{
+    return _page-&gt;editorState().isReplaceAllowed;
+}
+
</ins><span class="cx"> - (void)replaceText:(NSString *)text withText:(NSString *)word
</span><span class="cx"> {
</span><span class="cx">     _page-&gt;replaceSelectedText(text, word);
</span><span class="lines">@@ -1331,6 +1336,11 @@
</span><span class="cx">     }));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (UTF32Char)_characterBeforeCaretSelection
+{
+    return _page-&gt;editorState().characterBeforeSelection;
+}
+
</ins><span class="cx"> - (CGRect)textFirstRect
</span><span class="cx"> {
</span><span class="cx">     return (_page-&gt;editorState().hasComposition) ? _page-&gt;editorState().firstMarkedRect : _autocorrectionData.textFirstRect;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -695,6 +695,7 @@
</span><span class="cx">         // FIXME: The following check should take into account writing direction.
</span><span class="cx">         result.isReplaceAllowed = result.isContentEditable &amp;&amp; atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward);
</span><span class="cx">         result.wordAtSelection = plainText(wordRangeFromPosition(selection.start()).get());
</span><ins>+        result.characterBeforeSelection = characterBeforePosition(selection.start());
</ins><span class="cx">     } else if (selection.isRange()) {
</span><span class="cx">         result.caretRectAtStart = view-&gt;contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds());
</span><span class="cx">         result.caretRectAtEnd = view-&gt;contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds());
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (167623 => 167624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-04-21 21:06:57 UTC (rev 167623)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-04-21 21:14:30 UTC (rev 167624)
</span><span class="lines">@@ -1277,13 +1277,14 @@
</span><span class="cx"> void WebPage::replaceSelectedText(const String&amp; oldText, const String&amp; newText)
</span><span class="cx"> {
</span><span class="cx">     Frame&amp; frame = m_page-&gt;focusController().focusedOrMainFrame();
</span><del>-    if (!frame.selection().isRange())
</del><ins>+    RefPtr&lt;Range&gt; wordRange = frame.selection().isCaret() ? wordRangeFromPosition(frame.selection().selection().start()) : frame.selection().toNormalizedRange();
+    if (plainText(wordRange.get()) != oldText)
</ins><span class="cx">         return;
</span><del>-
-    if (plainText(frame.selection().toNormalizedRange().get()) != oldText)
-        return;
-
</del><ins>+    
+    frame.editor().setIgnoreCompositionSelectionChange(true);
+    frame.selection().setSelectedRange(wordRange.get(), UPSTREAM, true);
</ins><span class="cx">     frame.editor().insertText(newText, 0);
</span><ins>+    frame.editor().setIgnoreCompositionSelectionChange(false);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPage::replaceDictatedText(const String&amp; oldText, const String&amp; newText)
</span></span></pre>
</div>
</div>

</body>
</html>