Title: [254822] trunk
Revision
254822
Author
[email protected]
Date
2020-01-20 06:46:32 -0800 (Mon, 20 Jan 2020)

Log Message

[GTK][WPE] Also include the selection index in webkit_input_method_context_notify_surrounding()
https://bugs.webkit.org/show_bug.cgi?id=206497

Reviewed by Adrian Perez de Castro.

Source/WebKit:

Input methods also want to know the selection.

* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const): Encode paragraphContextSelectionPosition.
(WebKit::EditorState::PostLayoutData::decode): Decode paragraphContextSelectionPosition.
* Shared/EditorState.h: Add paragraphContextSelectionPosition.
* UIProcess/API/glib/InputMethodFilter.cpp:
(WebKit::InputMethodFilter::notifySurrounding): Also include the selection index.
* UIProcess/API/glib/InputMethodFilter.h:
* UIProcess/API/glib/WebKitInputMethodContext.cpp:
(webkit_input_method_context_notify_surrounding):
* UIProcess/API/gtk/WebKitInputMethodContext.h:
* UIProcess/API/gtk/WebKitInputMethodContextImplGtk.cpp:
(webkitInputMethodContextImplGtkNotifySurrounding): Ignore the selection index, since GtkIMContext doesn't
support it.
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseUpdateTextInputState): Pass paragraphContextSelectionPosition to InputMethodFilter::notifySurrounding().
* UIProcess/API/wpe/WPEView.cpp:
(WKWPE::View::selectionDidChange): Ditto.
* UIProcess/API/wpe/WebKitInputMethodContext.h:
* WebProcess/WebPage/glib/WebPageGLib.cpp:
(WebKit::WebPage::platformEditorState const): Get the selection index too.

Tools:

Add new test case to check the selection index when there's a selection.

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (254821 => 254822)


--- trunk/Source/WebKit/ChangeLog	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/ChangeLog	2020-01-20 14:46:32 UTC (rev 254822)
@@ -1,3 +1,33 @@
+2020-01-20  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Also include the selection index in webkit_input_method_context_notify_surrounding()
+        https://bugs.webkit.org/show_bug.cgi?id=206497
+
+        Reviewed by Adrian Perez de Castro.
+
+        Input methods also want to know the selection.
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::PostLayoutData::encode const): Encode paragraphContextSelectionPosition.
+        (WebKit::EditorState::PostLayoutData::decode): Decode paragraphContextSelectionPosition.
+        * Shared/EditorState.h: Add paragraphContextSelectionPosition.
+        * UIProcess/API/glib/InputMethodFilter.cpp:
+        (WebKit::InputMethodFilter::notifySurrounding): Also include the selection index.
+        * UIProcess/API/glib/InputMethodFilter.h:
+        * UIProcess/API/glib/WebKitInputMethodContext.cpp:
+        (webkit_input_method_context_notify_surrounding):
+        * UIProcess/API/gtk/WebKitInputMethodContext.h:
+        * UIProcess/API/gtk/WebKitInputMethodContextImplGtk.cpp:
+        (webkitInputMethodContextImplGtkNotifySurrounding): Ignore the selection index, since GtkIMContext doesn't
+        support it.
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseUpdateTextInputState): Pass paragraphContextSelectionPosition to InputMethodFilter::notifySurrounding().
+        * UIProcess/API/wpe/WPEView.cpp:
+        (WKWPE::View::selectionDidChange): Ditto.
+        * UIProcess/API/wpe/WebKitInputMethodContext.h:
+        * WebProcess/WebPage/glib/WebPageGLib.cpp:
+        (WebKit::WebPage::platformEditorState const): Get the selection index too.
+
 2020-01-20  Zan Dobersek  <[email protected]>
 
         [WPE] Expose the WebKitOptionMenu APIs

Modified: trunk/Source/WebKit/Shared/EditorState.cpp (254821 => 254822)


--- trunk/Source/WebKit/Shared/EditorState.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/Shared/EditorState.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -145,6 +145,7 @@
 #if PLATFORM(GTK) || PLATFORM(WPE)
     encoder << paragraphContext;
     encoder << paragraphContextCursorPosition;
+    encoder << paragraphContextSelectionPosition;
 #endif
     encoder << fontAttributes;
     encoder << canCut;
@@ -223,6 +224,8 @@
         return false;
     if (!decoder.decode(result.paragraphContextCursorPosition))
         return false;
+    if (!decoder.decode(result.paragraphContextSelectionPosition))
+        return false;
 #endif
 
     Optional<Optional<FontAttributes>> optionalFontAttributes;

Modified: trunk/Source/WebKit/Shared/EditorState.h (254821 => 254822)


--- trunk/Source/WebKit/Shared/EditorState.h	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/Shared/EditorState.h	2020-01-20 14:46:32 UTC (rev 254822)
@@ -123,6 +123,7 @@
 #if PLATFORM(GTK) || PLATFORM(WPE)
         String paragraphContext;
         uint64_t paragraphContextCursorPosition { 0 };
+        uint64_t paragraphContextSelectionPosition { 0 };
 #endif
 
         Optional<WebCore::FontAttributes> fontAttributes;

Modified: trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.cpp (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -210,20 +210,24 @@
     webkit_input_method_context_notify_cursor_area(m_context.get(), translatedRect.x(), translatedRect.y(), translatedRect.width(), translatedRect.height());
 }
 
-void InputMethodFilter::notifySurrounding(const String& text, uint64_t cursorPosition)
+void InputMethodFilter::notifySurrounding(const String& text, uint64_t cursorPosition, uint64_t selectionPosition)
 {
     if (!isEnabled() || !m_context)
         return;
 
-    if (m_surrounding.text == text && m_surrounding.cursorPosition == cursorPosition)
+    if (m_surrounding.text == text && m_surrounding.cursorPosition == cursorPosition && m_surrounding.selectionPosition == selectionPosition)
         return;
 
     m_surrounding.text = text;
     m_surrounding.cursorPosition = cursorPosition;
+    m_surrounding.selectionPosition = selectionPosition;
 
     auto textUTF8 = m_surrounding.text.utf8();
     auto cursorPositionUTF8 = cursorPosition != text.length() ? text.substring(0, cursorPosition).utf8().length() : textUTF8.length();
-    webkit_input_method_context_notify_surrounding(m_context.get(), textUTF8.data(), textUTF8.length(), cursorPositionUTF8);
+    auto selectionPositionUTF8 = cursorPositionUTF8;
+    if (cursorPosition != selectionPosition)
+        selectionPositionUTF8 = selectionPosition != text.length() ? text.substring(0, selectionPosition).utf8().length() : textUTF8.length();
+    webkit_input_method_context_notify_surrounding(m_context.get(), textUTF8.data(), textUTF8.length(), cursorPositionUTF8, selectionPositionUTF8);
 }
 
 void InputMethodFilter::preeditStarted()

Modified: trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.h (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.h	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.h	2020-01-20 14:46:32 UTC (rev 254822)
@@ -67,7 +67,7 @@
     void notifyFocusedOut();
     void notifyMouseButtonPress();
     void notifyCursorRect(const WebCore::IntRect&);
-    void notifySurrounding(const String&, uint64_t);
+    void notifySurrounding(const String&, uint64_t, uint64_t);
 
     void cancelComposition();
 
@@ -110,6 +110,7 @@
     struct {
         String text;
         uint64_t cursorPosition;
+        uint64_t selectionPosition;
     } m_surrounding;
 };
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitInputMethodContext.cpp (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitInputMethodContext.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitInputMethodContext.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -459,12 +459,14 @@
  * @text: text surrounding the insertion point
  * @length: the length of @text, or -1 if @text is nul-terminated
  * @cursor_index: the byte index of the insertion cursor within @text.
+ * @selection_index: the byte index of the selection cursor within @text.
  *
  * Notify @context that the context surrounding the cursor has changed.
+ * If there's no selection @selection_index is the same as @cursor_index.
  *
  * Since: 2.28
  */
-void webkit_input_method_context_notify_surrounding(WebKitInputMethodContext* context, const char* text, int length, unsigned cursorIndex)
+void webkit_input_method_context_notify_surrounding(WebKitInputMethodContext* context, const char* text, int length, unsigned cursorIndex, unsigned selectionIndex)
 {
     g_return_if_fail(WEBKIT_IS_INPUT_METHOD_CONTEXT(context));
     g_return_if_fail(text || !length);
@@ -477,7 +479,7 @@
 
     auto* imClass = WEBKIT_INPUT_METHOD_CONTEXT_GET_CLASS(context);
     if (imClass->notify_surrounding)
-        imClass->notify_surrounding(context, text, length, cursorIndex);
+        imClass->notify_surrounding(context, text, length, cursorIndex, selectionIndex);
 }
 
 /**

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitInputMethodContext.h (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitInputMethodContext.h	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitInputMethodContext.h	2020-01-20 14:46:32 UTC (rev 254822)
@@ -131,7 +131,8 @@
     void     (* notify_surrounding) (WebKitInputMethodContext *context,
                                      const gchar              *text,
                                      guint                     length,
-                                     guint                     cursor_index);
+                                     guint                     cursor_index,
+                                     guint                     selection_index);
     void     (* reset)              (WebKitInputMethodContext *context);
 
     void (*_webkit_reserved0) (void);
@@ -178,7 +179,8 @@
 webkit_input_method_context_notify_surrounding (WebKitInputMethodContext   *context,
                                                 const gchar                *text,
                                                 int                         length,
-                                                guint                       cursor_index);
+                                                guint                       cursor_index,
+                                                guint                       selection_index);
 
 WEBKIT_API void
 webkit_input_method_context_reset              (WebKitInputMethodContext   *context);

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitInputMethodContextImplGtk.cpp (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitInputMethodContextImplGtk.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitInputMethodContextImplGtk.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -193,7 +193,7 @@
     gtk_im_context_set_cursor_location(priv->context.get(), &cursorRect);
 }
 
-static void webkitInputMethodContextImplGtkNotifySurrounding(WebKitInputMethodContext* context, const gchar* text, unsigned length, unsigned cursorIndex)
+static void webkitInputMethodContextImplGtkNotifySurrounding(WebKitInputMethodContext* context, const gchar* text, unsigned length, unsigned cursorIndex, unsigned)
 {
     auto* priv = WEBKIT_INPUT_METHOD_CONTEXT_IMPL_GTK(context)->priv;
     priv->surroundingText = { text, length };

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -1674,7 +1674,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);
+        webkitWebViewBase->priv->inputMethodFilter.notifySurrounding(editorState.postLayoutData().paragraphContext, editorState.postLayoutData().paragraphContextCursorPosition,
+            editorState.postLayoutData().paragraphContextSelectionPosition);
     }
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -241,7 +241,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);
+        m_inputMethodFilter.notifySurrounding(editorState.postLayoutData().paragraphContext, editorState.postLayoutData().paragraphContextCursorPosition,
+            editorState.postLayoutData().paragraphContextSelectionPosition);
     }
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitInputMethodContext.h (254821 => 254822)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitInputMethodContext.h	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitInputMethodContext.h	2020-01-20 14:46:32 UTC (rev 254822)
@@ -132,7 +132,8 @@
     void     (* notify_surrounding) (WebKitInputMethodContext        *context,
                                      const gchar                     *text,
                                      guint                            length,
-                                     guint                            cursor_index);
+                                     guint                            cursor_index,
+                                     guint                            selection_index);
     void     (* reset)              (WebKitInputMethodContext        *context);
 
     void (*_webkit_reserved0) (void);
@@ -179,7 +180,8 @@
 webkit_input_method_context_notify_surrounding (WebKitInputMethodContext        *context,
                                                 const gchar                     *text,
                                                 int                              length,
-                                                guint                            cursor_index);
+                                                guint                            cursor_index,
+                                                guint                            selection_index);
 
 WEBKIT_API void
 webkit_input_method_context_reset              (WebKitInputMethodContext        *context);

Modified: trunk/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp (254821 => 254822)


--- trunk/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Source/WebKit/WebProcess/WebPage/glib/WebPageGLib.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -117,9 +117,11 @@
             clonedRange->setStart(compositionRange->endPosition());
             postLayoutData.paragraphContext = plainText(paragraphRange.get()) + plainText(clonedRange.ptr());
             postLayoutData.paragraphContextCursorPosition = TextIterator::rangeLength(paragraphRange.get());
+            postLayoutData.paragraphContextSelectionPosition = postLayoutData.paragraphContextCursorPosition;
         } else {
             postLayoutData.paragraphContext = plainText(paragraphRange.get());
             postLayoutData.paragraphContextCursorPosition = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
+            postLayoutData.paragraphContextSelectionPosition = TextIterator::rangeLength(makeRange(paragraphStart, selection.visibleEnd()).get());
         }
     }
 }

Modified: trunk/Tools/ChangeLog (254821 => 254822)


--- trunk/Tools/ChangeLog	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Tools/ChangeLog	2020-01-20 14:46:32 UTC (rev 254822)
@@ -1,3 +1,17 @@
+2020-01-20  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Also include the selection index in webkit_input_method_context_notify_surrounding()
+        https://bugs.webkit.org/show_bug.cgi?id=206497
+
+        Reviewed by Adrian Perez de Castro.
+
+        Add new test case to check the selection index when there's a selection.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp:
+        (webkitInputMethodContextMockNotifySurrounding):
+        (webkitInputMethodContextMockReset):
+        (testWebKitInputMethodContextSurrounding):
+
 2020-01-20  Zan Dobersek  <[email protected]>
 
         [WPE] Expose the WebKitOptionMenu APIs

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp (254821 => 254822)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp	2020-01-20 14:43:44 UTC (rev 254821)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp	2020-01-20 14:46:32 UTC (rev 254822)
@@ -43,6 +43,7 @@
     bool commitNextCharacter;
     char* surroundingText;
     unsigned surroundingCursorIndex;
+    unsigned surroundingSelectionIndex;
 } WebKitInputMethodContextMock;
 
 typedef struct _WebKitInputMethodContextMockClass {
@@ -174,7 +175,7 @@
     reinterpret_cast<WebKitInputMethodContextMock*>(context)->enabled = false;
 }
 
-static void webkitInputMethodContextMockNotifySurrounding(WebKitInputMethodContext* context, const gchar *text, unsigned length, unsigned cursorIndex)
+static void webkitInputMethodContextMockNotifySurrounding(WebKitInputMethodContext* context, const gchar *text, unsigned length, unsigned cursorIndex, unsigned selectionIndex)
 {
     auto* mock = reinterpret_cast<WebKitInputMethodContextMock*>(context);
     g_clear_pointer(&mock->surroundingText, g_free);
@@ -185,6 +186,7 @@
     }
     mock->surroundingText = g_strndup(text, length);
     mock->surroundingCursorIndex = cursorIndex;
+    mock->surroundingSelectionIndex = selectionIndex;
 }
 
 static void webkitInputMethodContextMockReset(WebKitInputMethodContext* context)
@@ -197,6 +199,7 @@
     mock->preedit = nullptr;
     g_clear_pointer(&mock->surroundingText, g_free);
     mock->surroundingCursorIndex = 0;
+    mock->surroundingSelectionIndex = 0;
 
     g_signal_emit_by_name(context, "preedit-changed", nullptr);
     g_signal_emit_by_name(context, "preedit-finished", nullptr);
@@ -432,6 +435,11 @@
         return m_context->surroundingCursorIndex;
     }
 
+    unsigned surroundingSelectionIndex() const
+    {
+        return m_context->surroundingSelectionIndex;
+    }
+
     void waitForSurroundingText(const char* text)
     {
         m_expectedSurroundingText = text;
@@ -745,6 +753,7 @@
 
     g_assert_null(test->surroundingText());
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
 
     test->keyStrokeAndWaitForEvents(KEY(a), 3);
     test->keyStrokeAndWaitForEvents(KEY(b), 6);
@@ -751,6 +760,7 @@
     test->keyStrokeAndWaitForEvents(KEY(c), 9);
     g_assert_cmpstr(test->surroundingText(), ==, "abc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 3);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->m_events.clear();
 
     // Check preedit string is not included in surrounding.
@@ -760,31 +770,38 @@
     test->keyStrokeAndWaitForEvents(KEY(Left), 6);
     g_assert_cmpstr(test->surroundingText(), ==, "abc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->m_events.clear();
     test->keyStrokeAndWaitForEvents(KEY(w), 4, CONTROL_MASK | SHIFT_MASK);
     g_assert_cmpstr(test->surroundingText(), ==, "abc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->keyStrokeAndWaitForEvents(KEY(g), 7);
     test->keyStrokeAndWaitForEvents(KEY(t), 10);
     test->keyStrokeAndWaitForEvents(KEY(k), 13);
     g_assert_cmpstr(test->surroundingText(), ==, "abc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->keyStrokeAndWaitForEvents(KEY(ISO_Enter), 16);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 9);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->m_events.clear();
     // 2. Preedit string in the middle of context.
     test->keyStrokeAndWaitForEvents(KEY(w), 4, CONTROL_MASK | SHIFT_MASK);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 9);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->keyStrokeAndWaitForEvents(KEY(w), 7);
     test->keyStrokeAndWaitForEvents(KEY(p), 10);
     test->keyStrokeAndWaitForEvents(KEY(e), 13);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 9);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->keyStrokeAndWaitForEvents(KEY(space), 16);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 18);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->m_events.clear();
     // 3. Preedit string at the end of context.
     test->keyStrokeAndWaitForEvents(KEY(Right), 2);
@@ -792,20 +809,49 @@
     test->keyStrokeAndWaitForEvents(KEY(Right), 6);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 21);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->m_events.clear();
     test->keyStrokeAndWaitForEvents(KEY(w), 4, CONTROL_MASK | SHIFT_MASK);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 21);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->keyStrokeAndWaitForEvents(KEY(g), 7);
     test->keyStrokeAndWaitForEvents(KEY(t), 10);
     test->keyStrokeAndWaitForEvents(KEY(k), 13);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabc");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 21);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->keyStrokeAndWaitForEvents(KEY(ISO_Enter), 16);
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 30);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
     test->m_events.clear();
 
+    // Check selection cursor.
+    test->keyStrokeAndWaitForEvents(KEY(Left), 2, SHIFT_MASK);
+    g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK");
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 29);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, 30);
+    test->keyStrokeAndWaitForEvents(KEY(Home), 4, SHIFT_MASK);
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, 30);
+    test->keyStrokeAndWaitForEvents(KEY(Left), 6);
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
+    test->m_events.clear();
+    test->keyStrokeAndWaitForEvents(KEY(Right), 2, SHIFT_MASK);
+    g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK");
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, 1);
+    test->keyStrokeAndWaitForEvents(KEY(End), 4, SHIFT_MASK);
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 0);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, 30);
+    test->keyStrokeAndWaitForEvents(KEY(Right), 6);
+    g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK");
+    g_assert_cmpuint(test->surroundingCursorIndex(), ==, 30);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
+    test->m_events.clear();
+
     // Check text replacements (get surrounding + delete surrounding).
     test->keyStrokeAndWaitForEvents(KEY(colon), 3);
     test->keyStrokeAndWaitForEvents(KEY(minus), 6);
@@ -813,6 +859,7 @@
     test->waitForSurroundingText("WebKitGTKWPEWebKitabcWebKitGTK😀️");
     g_assert_cmpstr(test->surroundingText(), ==, "WebKitGTKWPEWebKitabcWebKitGTK😀️");
     g_assert_cmpuint(test->surroundingCursorIndex(), ==, 37);
+    g_assert_cmpuint(test->surroundingSelectionIndex(), ==, test->surroundingCursorIndex());
 }
 
 static void testWebKitInputMethodContextReset(InputMethodTest* test, gconstpointer)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to