Title: [167624] trunk/Source
Revision
167624
Author
[email protected]
Date
2014-04-21 14:14:30 -0700 (Mon, 21 Apr 2014)

Log Message

[iOS WebKit2] support replacements for misspelled words.
https://bugs.webkit.org/show_bug.cgi?id=131827
<rdar://problem/16319657>

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167623 => 167624)


--- 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)
@@ -1,3 +1,19 @@
+2014-04-21  Enrica Casucci  <[email protected]>
+
+        [iOS WebKit2] support replacements for misspelled words.
+        https://bugs.webkit.org/show_bug.cgi?id=131827
+        <rdar://problem/16319657>
+
+        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:
+
 2014-04-21  Eric Carlson  <[email protected]>
 
         [iOS] enable plug-in replacement

Modified: trunk/Source/WebCore/WebCore.exp.in (167623 => 167624)


--- 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)
@@ -2570,6 +2570,7 @@
 __ZN7WebCore22startOfEditableContentERKNS_15VisiblePositionE
 __ZN7WebCore23applicationIsMobileMailEv
 __ZN7WebCore23atBoundaryOfGranularityERKNS_15VisiblePositionENS_15TextGranularityENS_18SelectionDirectionE
+__ZN7WebCore23characterBeforePositionERKNS_15VisiblePositionE
 __ZN7WebCore24DocumentMarkerController14markersInRangeEPNS_5RangeENS_14DocumentMarker11MarkerTypesE
 __ZN7WebCore24acquireLineBreakIteratorEN3WTF10StringViewERKNS0_12AtomicStringEPKtj
 __ZN7WebCore24createTemporaryDirectoryEP8NSString

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (167623 => 167624)


--- 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)
@@ -1812,6 +1812,26 @@
 
     return (thisIsStart ? -distance : distance);
 }
+    
+UChar32 characterBeforePosition(const VisiblePosition& 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()->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) && U16_IS_TRAIL(trail))
+            return U16_GET_SUPPLEMENTARY(lead, trail);
+    }
+    return characterString[0] != noBreakSpace ? : ' ';
+}
 
 PassRefPtr<Range> wordRangeFromPosition(const VisiblePosition& position)
 {

Modified: trunk/Source/WebCore/editing/VisibleUnits.h (167623 => 167624)


--- 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)
@@ -104,6 +104,7 @@
 int distanceBetweenPositions(const VisiblePosition&, const VisiblePosition&);
 PassRefPtr<Range> wordRangeFromPosition(const VisiblePosition& position);
 VisiblePosition closestWordBoundaryForPosition(const VisiblePosition& position);
+UChar32 characterBeforePosition(const VisiblePosition&);
 #endif
 } // namespace WebCore
 

Modified: trunk/Source/WebKit2/ChangeLog (167623 => 167624)


--- 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)
@@ -1,3 +1,30 @@
+2014-04-21  Enrica Casucci  <[email protected]>
+
+        [iOS WebKit2] support replacements for misspelled words.
+        https://bugs.webkit.org/show_bug.cgi?id=131827
+        <rdar://problem/16319657>
+
+        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):
+
 2014-04-21  Gavin Barraclough  <[email protected]>
 
         Don't use ProcessAssertion on simulator

Modified: trunk/Source/WebKit2/Shared/EditorState.cpp (167623 => 167624)


--- 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)
@@ -48,6 +48,7 @@
 
 #if PLATFORM(IOS)
     encoder << isReplaceAllowed;
+    encoder << characterBeforeSelection;
     encoder << caretRectAtStart;
     encoder << caretRectAtEnd;
     encoder << selectionRects;
@@ -92,6 +93,8 @@
 #if PLATFORM(IOS)
     if (!decoder.decode(result.isReplaceAllowed))
         return false;
+    if (!decoder.decode(result.characterBeforeSelection))
+        return false;
     if (!decoder.decode(result.caretRectAtStart))
         return false;
     if (!decoder.decode(result.caretRectAtEnd))

Modified: trunk/Source/WebKit2/Shared/EditorState.h (167623 => 167624)


--- 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)
@@ -48,6 +48,7 @@
         , hasComposition(false)
 #if PLATFORM(IOS)
         , isReplaceAllowed(false)
+        , characterBeforeSelection(0)
         , selectedTextLength(0)
 #endif
     {
@@ -65,6 +66,7 @@
 
 #if PLATFORM(IOS)
     bool isReplaceAllowed;
+    UChar32 characterBeforeSelection;
     WebCore::IntRect caretRectAtStart;
     WebCore::IntRect caretRectAtEnd;
     Vector<WebCore::SelectionRect> selectionRects;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (167623 => 167624)


--- 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)
@@ -860,6 +860,11 @@
     return (NSString *)_page->editorState().wordAtSelection;
 }
 
+- (BOOL)isReplaceAllowed
+{
+    return _page->editorState().isReplaceAllowed;
+}
+
 - (void)replaceText:(NSString *)text withText:(NSString *)word
 {
     _page->replaceSelectedText(text, word);
@@ -1331,6 +1336,11 @@
     }));
 }
 
+- (UTF32Char)_characterBeforeCaretSelection
+{
+    return _page->editorState().characterBeforeSelection;
+}
+
 - (CGRect)textFirstRect
 {
     return (_page->editorState().hasComposition) ? _page->editorState().firstMarkedRect : _autocorrectionData.textFirstRect;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (167623 => 167624)


--- 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)
@@ -695,6 +695,7 @@
         // FIXME: The following check should take into account writing direction.
         result.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward);
         result.wordAtSelection = plainText(wordRangeFromPosition(selection.start()).get());
+        result.characterBeforeSelection = characterBeforePosition(selection.start());
     } else if (selection.isRange()) {
         result.caretRectAtStart = view->contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds());
         result.caretRectAtEnd = view->contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds());

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (167623 => 167624)


--- 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)
@@ -1277,13 +1277,14 @@
 void WebPage::replaceSelectedText(const String& oldText, const String& newText)
 {
     Frame& frame = m_page->focusController().focusedOrMainFrame();
-    if (!frame.selection().isRange())
+    RefPtr<Range> wordRange = frame.selection().isCaret() ? wordRangeFromPosition(frame.selection().selection().start()) : frame.selection().toNormalizedRange();
+    if (plainText(wordRange.get()) != oldText)
         return;
-
-    if (plainText(frame.selection().toNormalizedRange().get()) != oldText)
-        return;
-
+    
+    frame.editor().setIgnoreCompositionSelectionChange(true);
+    frame.selection().setSelectedRange(wordRange.get(), UPSTREAM, true);
     frame.editor().insertText(newText, 0);
+    frame.editor().setIgnoreCompositionSelectionChange(false);
 }
 
 void WebPage::replaceDictatedText(const String& oldText, const String& newText)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to