Title: [258133] releases/WebKitGTK/webkit-2.28
Revision
258133
Author
carlo...@webkit.org
Date
2020-03-09 02:50:20 -0700 (Mon, 09 Mar 2020)

Log Message

Merge r258131 - [GTK][WPE] Surrounding text for input methods should not be limited to the current paragraph
https://bugs.webkit.org/show_bug.cgi?id=208706

Reviewed by Žan Doberšek.

Source/WebKit:

It should include all the text around the cursor position.

* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const): Rename paragraphContext* as surroundingContext*.
(WebKit::EditorState::PostLayoutData::decode): Ditto.
* Shared/EditorState.h:
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseUpdateTextInputState): Ditto.
* UIProcess/API/wpe/WPEView.cpp:
(WKWPE::View::selectionDidChange): Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::deleteSurrounding): Use content editable text as context instead of just paragraph.
* WebProcess/WebPage/glib/WebPageGLib.cpp:
(WebKit::WebPage::platformEditorState const): Ditto.

Tools:

Add test case to check surrounding text in multiline context.

* TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp:
(testWebKitInputMethodContextSurrounding):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/ChangeLog (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/ChangeLog	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/ChangeLog	2020-03-09 09:50:20 UTC (rev 258133)
@@ -1,3 +1,25 @@
+2020-03-09  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK][WPE] Surrounding text for input methods should not be limited to the current paragraph
+        https://bugs.webkit.org/show_bug.cgi?id=208706
+
+        Reviewed by Žan Doberšek.
+
+        It should include all the text around the cursor position.
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::PostLayoutData::encode const): Rename paragraphContext* as surroundingContext*.
+        (WebKit::EditorState::PostLayoutData::decode): Ditto.
+        * Shared/EditorState.h:
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseUpdateTextInputState): Ditto.
+        * UIProcess/API/wpe/WPEView.cpp:
+        (WKWPE::View::selectionDidChange): Ditto.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::deleteSurrounding): Use content editable text as context instead of just paragraph.
+        * WebProcess/WebPage/glib/WebPageGLib.cpp:
+        (WebKit::WebPage::platformEditorState const): Ditto.
+
 2020-03-08  Konstantin Tokarev  <annu...@yandex.ru>
 
         [GTK] Fix compilation with disabled OpenGL

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/Shared/EditorState.cpp (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/Shared/EditorState.cpp	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/Shared/EditorState.cpp	2020-03-09 09:50:20 UTC (rev 258133)
@@ -143,9 +143,9 @@
     encoder << stringForCandidateRequest;
 #endif
 #if PLATFORM(GTK) || PLATFORM(WPE)
-    encoder << paragraphContext;
-    encoder << paragraphContextCursorPosition;
-    encoder << paragraphContextSelectionPosition;
+    encoder << surroundingContext;
+    encoder << surroundingContextCursorPosition;
+    encoder << surroundingContextSelectionPosition;
 #endif
     encoder << fontAttributes;
     encoder << canCut;
@@ -220,11 +220,11 @@
         return false;
 #endif
 #if PLATFORM(GTK) || PLATFORM(WPE)
-    if (!decoder.decode(result.paragraphContext))
+    if (!decoder.decode(result.surroundingContext))
         return false;
-    if (!decoder.decode(result.paragraphContextCursorPosition))
+    if (!decoder.decode(result.surroundingContextCursorPosition))
         return false;
-    if (!decoder.decode(result.paragraphContextSelectionPosition))
+    if (!decoder.decode(result.surroundingContextSelectionPosition))
         return false;
 #endif
 

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/Shared/EditorState.h (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/Shared/EditorState.h	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/Shared/EditorState.h	2020-03-09 09:50:20 UTC (rev 258133)
@@ -121,9 +121,9 @@
         String stringForCandidateRequest;
 #endif
 #if PLATFORM(GTK) || PLATFORM(WPE)
-        String paragraphContext;
-        uint64_t paragraphContextCursorPosition { 0 };
-        uint64_t paragraphContextSelectionPosition { 0 };
+        String surroundingContext;
+        uint64_t surroundingContextCursorPosition { 0 };
+        uint64_t surroundingContextSelectionPosition { 0 };
 #endif
 
         Optional<WebCore::FontAttributes> fontAttributes;

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2020-03-09 09:50:20 UTC (rev 258133)
@@ -1679,8 +1679,8 @@
     const auto& editorState = webkitWebViewBase->priv->pageProxy->editorState();
     if (!editorState.isMissingPostLayoutData) {
         webkitWebViewBase->priv->inputMethodFilter.notifyCursorRect(editorState.postLayoutData().caretRectAtStart);
-        webkitWebViewBase->priv->inputMethodFilter.notifySurrounding(editorState.postLayoutData().paragraphContext, editorState.postLayoutData().paragraphContextCursorPosition,
-            editorState.postLayoutData().paragraphContextSelectionPosition);
+        webkitWebViewBase->priv->inputMethodFilter.notifySurrounding(editorState.postLayoutData().surroundingContext, editorState.postLayoutData().surroundingContextCursorPosition,
+            editorState.postLayoutData().surroundingContextSelectionPosition);
     }
 }
 

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/API/wpe/WPEView.cpp (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/API/wpe/WPEView.cpp	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/API/wpe/WPEView.cpp	2020-03-09 09:50:20 UTC (rev 258133)
@@ -258,8 +258,8 @@
     const auto& editorState = m_pageProxy->editorState();
     if (!editorState.isMissingPostLayoutData) {
         m_inputMethodFilter.notifyCursorRect(editorState.postLayoutData().caretRectAtStart);
-        m_inputMethodFilter.notifySurrounding(editorState.postLayoutData().paragraphContext, editorState.postLayoutData().paragraphContextCursorPosition,
-            editorState.postLayoutData().paragraphContextSelectionPosition);
+        m_inputMethodFilter.notifySurrounding(editorState.postLayoutData().surroundingContext, editorState.postLayoutData().surroundingContextCursorPosition,
+            editorState.postLayoutData().surroundingContextSelectionPosition);
     }
 }
 

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/WebProcess/WebPage/WebPage.cpp (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-03-09 09:50:20 UTC (rev 258133)
@@ -5417,9 +5417,9 @@
         return;
 
     auto selectionStart = selection.visibleStart();
-    auto paragraphRange = makeRange(startOfParagraph(selectionStart), selectionStart);
-    auto cursorPosition = TextIterator::rangeLength(paragraphRange.get());
-    auto& rootNode = paragraphRange->startContainer().treeScope().rootNode();
+    auto surroundingRange = makeRange(startOfEditableContent(selectionStart), selectionStart);
+    auto cursorPosition = TextIterator::rangeLength(surroundingRange.get());
+    auto& rootNode = surroundingRange->startContainer().treeScope().rootNode();
     auto selectionRange = TextIterator::rangeFromLocationAndLength(&rootNode, cursorPosition + offset, characterCount);
     if (!selectionRange)
         return;

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp	2020-03-09 09:50:20 UTC (rev 258133)
@@ -107,21 +107,21 @@
 
     if (selection.isContentEditable()) {
         auto selectionStart = selection.visibleStart();
-        auto paragraphStart = startOfParagraph(selectionStart);
-        auto paragraphEnd = endOfParagraph(selectionStart);
-        auto paragraphRange = makeRange(paragraphStart, paragraphEnd);
+        auto surroundingStart = startOfEditableContent(selectionStart);
+        auto surroundingEnd = endOfEditableContent(selectionStart);
+        auto surroundingRange = makeRange(surroundingStart, surroundingEnd);
         auto compositionRange = frame.editor().compositionRange();
-        if (compositionRange && paragraphRange->contains(*compositionRange)) {
-            auto clonedRange = paragraphRange->cloneRange();
-            paragraphRange->setEnd(compositionRange->startPosition());
+        if (compositionRange && surroundingRange->contains(*compositionRange)) {
+            auto clonedRange = surroundingRange->cloneRange();
+            surroundingRange->setEnd(compositionRange->startPosition());
             clonedRange->setStart(compositionRange->endPosition());
-            postLayoutData.paragraphContext = plainText(paragraphRange.get()) + plainText(clonedRange.ptr());
-            postLayoutData.paragraphContextCursorPosition = TextIterator::rangeLength(paragraphRange.get());
-            postLayoutData.paragraphContextSelectionPosition = postLayoutData.paragraphContextCursorPosition;
+            postLayoutData.surroundingContext = plainText(surroundingRange.get()) + plainText(clonedRange.ptr());
+            postLayoutData.surroundingContextCursorPosition = TextIterator::rangeLength(surroundingRange.get());
+            postLayoutData.surroundingContextSelectionPosition = postLayoutData.surroundingContextCursorPosition;
         } else {
-            postLayoutData.paragraphContext = plainText(paragraphRange.get());
-            postLayoutData.paragraphContextCursorPosition = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
-            postLayoutData.paragraphContextSelectionPosition = TextIterator::rangeLength(makeRange(paragraphStart, selection.visibleEnd()).get());
+            postLayoutData.surroundingContext = plainText(surroundingRange.get());
+            postLayoutData.surroundingContextCursorPosition = TextIterator::rangeLength(makeRange(surroundingStart, selectionStart).get());
+            postLayoutData.surroundingContextSelectionPosition = TextIterator::rangeLength(makeRange(surroundingStart, selection.visibleEnd()).get());
         }
     }
 }

Modified: releases/WebKitGTK/webkit-2.28/Tools/ChangeLog (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Tools/ChangeLog	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Tools/ChangeLog	2020-03-09 09:50:20 UTC (rev 258133)
@@ -1,3 +1,15 @@
+2020-03-09  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK][WPE] Surrounding text for input methods should not be limited to the current paragraph
+        https://bugs.webkit.org/show_bug.cgi?id=208706
+
+        Reviewed by Žan Doberšek.
+
+        Add test case to check surrounding text in multiline context.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp:
+        (testWebKitInputMethodContextSurrounding):
+
 2020-03-06  Lauro Moura <lmo...@igalia.com>
 
         [WPE][WebDriver] MiniBrowser should react to close session commands

Modified: releases/WebKitGTK/webkit-2.28/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp (258132 => 258133)


--- releases/WebKitGTK/webkit-2.28/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp	2020-03-09 09:50:12 UTC (rev 258132)
+++ releases/WebKitGTK/webkit-2.28/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp	2020-03-09 09:50:20 UTC (rev 258133)
@@ -52,7 +52,7 @@
 
 G_DEFINE_TYPE(WebKitInputMethodContextMock, webkit_input_method_context_mock, WEBKIT_TYPE_INPUT_METHOD_CONTEXT)
 
-static const char* testHTML = "<html><body><input id='editable' contenteditable _onkeydown_='logKeyDown()' _onkeyup_='logKeyUp()' _onkeypress_='logKeyPress()'></input><script>"
+static const char* testHTML = "<html><body><textarea id='editable' rows='3', cols='50' _onkeydown_='logKeyDown()' _onkeyup_='logKeyUp()' _onkeypress_='logKeyPress()'></textarea><script>"
     "var input = document.getElementById('editable');"
     "input.addEventListener('compositionstart', logCompositionEvent);"
     "input.addEventListener('compositionupdate', logCompositionEvent);"
@@ -860,6 +860,16 @@
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK😀️");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 37);
     g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
+    test->m_events.clear();
+
+    // Check multiline context.
+    test->keyStrokeAndWaitForEvents(KEY(Return), 3);
+    test->keyStrokeAndWaitForEvents(KEY(a), 6);
+    test->waitForSurroundingText("WebKitGTKWPEWebKitabcWebKitGTK😀️\na");
+    g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK😀️\na");
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 39);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
+    test->m_events.clear();
 }
 
 static void testWebKitInputMethodContextReset(InputMethodTest* test, gconstpointer)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to