Editing nested RTL-LTR content makes the process unresponsive.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jan 2017 00:02:42 +0000 (00:02 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jan 2017 00:02:42 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167140
rdar://problem/29057611

Reviewed by Ryosuke Niwa.

Source/WebCore:

Break out of the loop if we keep coming back to the same position.
This is a workaround for the underlying editing/position bug -> webkit.org/b/167138.

Test: editing/rtl-to-ltr-editing-word-move-spin.html

* editing/VisibleUnits.cpp:
(WebCore::visualWordPosition):

LayoutTests:

* editing/rtl-to-ltr-editing-word-move-spin-expected.txt: Added.
* editing/rtl-to-ltr-editing-word-move-spin.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210831 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/rtl-to-ltr-editing-word-move-spin-expected.txt [new file with mode: 0644]
LayoutTests/editing/rtl-to-ltr-editing-word-move-spin.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/VisibleUnits.cpp

index 7058cb3..6b3f420 100644 (file)
@@ -1,3 +1,14 @@
+2017-01-17  Zalan Bujtas  <zalan@apple.com>
+
+        Editing nested RTL-LTR content makes the process unresponsive.
+        https://bugs.webkit.org/show_bug.cgi?id=167140
+        rdar://problem/29057611
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/rtl-to-ltr-editing-word-move-spin-expected.txt: Added.
+        * editing/rtl-to-ltr-editing-word-move-spin.html: Added.
+
 2017-01-17  Ryan Haddad  <ryanhaddad@apple.com>
 
         Marking http/tests/media/hls/hls-video-resize.html as flaky on mac.
diff --git a/LayoutTests/editing/rtl-to-ltr-editing-word-move-spin-expected.txt b/LayoutTests/editing/rtl-to-ltr-editing-word-move-spin-expected.txt
new file mode 100644 (file)
index 0000000..cc452c0
--- /dev/null
@@ -0,0 +1,4 @@
+Pass if no hang.
+‫ foobar foobar‫
+
+
diff --git a/LayoutTests/editing/rtl-to-ltr-editing-word-move-spin.html b/LayoutTests/editing/rtl-to-ltr-editing-word-move-spin.html
new file mode 100644 (file)
index 0000000..b2b4943
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This test that we can jump word by word over rtl-ltr content.</title>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8">
+</head>
+<body contenteditable="true";>
+Pass if no hang.
+<div style="direction: rtl;">&#x202B foobar foobar&#x202B</div></br>
+<script>
+    if (window.testRunner)
+        testRunner.dumpAsText();
+    getSelection().setPosition(document.querySelector('div').firstChild, 2);
+    getSelection().modify('move', 'right', 'word');
+    getSelection().modify('move', 'right', 'word');
+</script>
+</body>
+</html>
index 6a66424..f91231a 100644 (file)
@@ -1,3 +1,19 @@
+2017-01-17  Zalan Bujtas  <zalan@apple.com>
+
+        Editing nested RTL-LTR content makes the process unresponsive.
+        https://bugs.webkit.org/show_bug.cgi?id=167140
+        rdar://problem/29057611
+
+        Reviewed by Ryosuke Niwa.
+
+        Break out of the loop if we keep coming back to the same position.
+        This is a workaround for the underlying editing/position bug -> webkit.org/b/167138.
+
+        Test: editing/rtl-to-ltr-editing-word-move-spin.html
+
+        * editing/VisibleUnits.cpp:
+        (WebCore::visualWordPosition):
+
 2017-01-16  Filip Pizlo  <fpizlo@apple.com>
 
         JSCell::classInfo() shouldn't have a bunch of mitigations for being called during destruction
index 153f5ea..4363c1b 100644 (file)
@@ -352,6 +352,7 @@ static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
     TextDirection blockDirection = directionOfEnclosingBlock(visiblePosition.deepEquivalent());
     InlineBox* previouslyVisitedBox = nullptr;
     VisiblePosition current = visiblePosition;
+    std::optional<VisiblePosition> previousPosition;
     UBreakIterator* iter = nullptr;
 
     CachedLogicallyOrderedLeafBoxes leafBoxes;
@@ -361,6 +362,9 @@ static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
         VisiblePosition adjacentCharacterPosition = direction == MoveRight ? current.right(true) : current.left(true); 
         if (adjacentCharacterPosition == current || adjacentCharacterPosition.isNull())
             return VisiblePosition();
+        // FIXME: This is a workaround for webkit.org/b/167138.
+        if (previousPosition && adjacentCharacterPosition == previousPosition.value())
+            return VisiblePosition();
     
         InlineBox* box;
         int offsetInBox;
@@ -409,6 +413,7 @@ static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
         if (isWordBreak)
             return adjacentCharacterPosition;
     
+        previousPosition = current;
         current = adjacentCharacterPosition;
     }
     return VisiblePosition();