- Revision
- 93221
- Author
- [email protected]
- Date
- 2011-08-17 11:07:33 -0700 (Wed, 17 Aug 2011)
Log Message
An arrow key collapses directionless selection range in the wrong direction in BiDi
https://bugs.webkit.org/show_bug.cgi?id=64626
Reviewed by Darin Adler.
Source/WebCore:
The bug was caused by willBeModified's always using block direction to determine
the direction to which the selection is collapsed. Fixed the bug by calling directionOfSelection
in willBeModified, which will return the text direction of the surrounding context when
the start and the end have the same direction. When the text directions at the start and at the end
of selection do not match, it uses the block's text direction.
Test: editing/selection/collapse-selection-in-bidi.html
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::directionOfSelection): Added.
(WebCore::FrameSelection::willBeModified): Calls directionOfSelection.
(WebCore::FrameSelection::modifyMovingRight): Ditto.
(WebCore::FrameSelection::modifyMovingLeft): Ditto.
* editing/FrameSelection.h:
LayoutTests:
Added a test to ensure collapsing directionless selection respects the direction of text around
the selection's end points.
* editing/selection/collapse-selection-in-bidi-expected.txt: Added.
* editing/selection/collapse-selection-in-bidi.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (93220 => 93221)
--- trunk/LayoutTests/ChangeLog 2011-08-17 18:04:31 UTC (rev 93220)
+++ trunk/LayoutTests/ChangeLog 2011-08-17 18:07:33 UTC (rev 93221)
@@ -1,3 +1,16 @@
+2011-08-17 Ryosuke Niwa <[email protected]>
+
+ An arrow key collapses directionless selection range in the wrong direction in BiDi
+ https://bugs.webkit.org/show_bug.cgi?id=64626
+
+ Reviewed by Darin Adler.
+
+ Added a test to ensure collapsing directionless selection respects the direction of text around
+ the selection's end points.
+
+ * editing/selection/collapse-selection-in-bidi-expected.txt: Added.
+ * editing/selection/collapse-selection-in-bidi.html: Added.
+
2011-08-17 Steve Block <[email protected]>
Unreviewed, rolling out r93204.
Added: trunk/LayoutTests/editing/selection/collapse-selection-in-bidi-expected.txt (0 => 93221)
--- trunk/LayoutTests/editing/selection/collapse-selection-in-bidi-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/selection/collapse-selection-in-bidi-expected.txt 2011-08-17 18:07:33 UTC (rev 93221)
@@ -0,0 +1,10 @@
+This tests collapsing directionless selection on text in a block with the opposite text direction. To manually test, on Mac, select text below by mouse and use arrow keys (without pressing shift) to collapse the selection. The selection should collapse to the left if you pressed the left arrow key and to the right if you pressed the right arrow key.
+
+PASS Selection is [anchorNode: [object Text](אבגדה) anchorOffset: 3 focusNode: [object Text](אבגדה) focusOffset: 3 isCollapsed: true]
+PASS Selection is [anchorNode: [object Text](אבגדה) anchorOffset: 1 focusNode: [object Text](אבגדה) focusOffset: 1 isCollapsed: true]
+PASS Selection is [anchorNode: [object Text](hello) anchorOffset: 1 focusNode: [object Text](hello) focusOffset: 1 isCollapsed: true]
+PASS Selection is [anchorNode: [object Text](hello) anchorOffset: 4 focusNode: [object Text](hello) focusOffset: 4 isCollapsed: true]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/editing/selection/collapse-selection-in-bidi.html (0 => 93221)
--- trunk/LayoutTests/editing/selection/collapse-selection-in-bidi.html (rev 0)
+++ trunk/LayoutTests/editing/selection/collapse-selection-in-bidi.html 2011-08-17 18:07:33 UTC (rev 93221)
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p>This tests collapsing directionless selection on text in a block with the opposite text direction.
+To manually test, on Mac, select text below by mouse and use arrow keys (without pressing shift) to collapse the selection.
+The selection should collapse to the left if you pressed the left arrow key and to the right if you pressed the right arrow key.</p>
+<div id="tests" contenteditable><span dir="ltr">אבגדה</span
+><span dir="rtl">hello</span></div>
+<pre id="console"></pre>
+<script>
+
+if (window.layoutTestController) {
+ layoutTestController.setEditingBehavior('mac');
+
+ function selectTarget(target) {
+ eventSender.mouseMoveTo(target.offsetLeft + target.offsetWidth * 2 / 5, target.offsetTop + 5);
+ eventSender.mouseDown();
+ eventSender.leapForward(200);
+ eventSender.mouseMoveTo(target.offsetLeft + target.offsetWidth * 4 / 5, target.offsetTop + 5);
+ eventSender.leapForward(200);
+ eventSender.mouseUp();
+ }
+
+ var selection = window.getSelection();
+ var tests = document.getElementById('tests').getElementsByTagName('span');
+ for (var i = 0; i < tests.length; i++) {
+ var isLTR = tests[i].dir == 'ltr';
+
+ selectTarget(tests[i]);
+ var expectedOffset = isLTR ? window.getSelection().getRangeAt(0).endOffset : window.getSelection().getRangeAt(0).startOffset;
+ window.getSelection().modify('move', 'left', 'character');
+ assertSelectionAt(tests[i].firstChild, expectedOffset);
+
+ selectTarget(tests[i]);
+ expectedOffset = isLTR ? window.getSelection().getRangeAt(0).startOffset : window.getSelection().getRangeAt(0).endOffset;
+ window.getSelection().modify('move', 'right', 'character');
+ assertSelectionAt(tests[i].firstChild, expectedOffset);
+ }
+
+ document.getElementById('tests').style.display = 'none';
+}
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (93220 => 93221)
--- trunk/Source/WebCore/ChangeLog 2011-08-17 18:04:31 UTC (rev 93220)
+++ trunk/Source/WebCore/ChangeLog 2011-08-17 18:07:33 UTC (rev 93221)
@@ -1,3 +1,25 @@
+2011-08-17 Ryosuke Niwa <[email protected]>
+
+ An arrow key collapses directionless selection range in the wrong direction in BiDi
+ https://bugs.webkit.org/show_bug.cgi?id=64626
+
+ Reviewed by Darin Adler.
+
+ The bug was caused by willBeModified's always using block direction to determine
+ the direction to which the selection is collapsed. Fixed the bug by calling directionOfSelection
+ in willBeModified, which will return the text direction of the surrounding context when
+ the start and the end have the same direction. When the text directions at the start and at the end
+ of selection do not match, it uses the block's text direction.
+
+ Test: editing/selection/collapse-selection-in-bidi.html
+
+ * editing/FrameSelection.cpp:
+ (WebCore::FrameSelection::directionOfSelection): Added.
+ (WebCore::FrameSelection::willBeModified): Calls directionOfSelection.
+ (WebCore::FrameSelection::modifyMovingRight): Ditto.
+ (WebCore::FrameSelection::modifyMovingLeft): Ditto.
+ * editing/FrameSelection.h:
+
2011-08-17 Jeff Miller <[email protected]>
Some AVFoundation source files should be in platform-specific directories
Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (93220 => 93221)
--- trunk/Source/WebCore/editing/FrameSelection.cpp 2011-08-17 18:04:31 UTC (rev 93220)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp 2011-08-17 18:07:33 UTC (rev 93221)
@@ -390,6 +390,21 @@
return WebCore::directionOfEnclosingBlock(m_selection.extent());
}
+TextDirection FrameSelection::directionOfSelection()
+{
+ InlineBox* startBox = 0;
+ InlineBox* endBox = 0;
+ int unusedOffset;
+ if (m_selection.start().isNotNull())
+ m_selection.visibleStart().getInlineBoxAndOffset(startBox, unusedOffset);
+ if (m_selection.end().isNotNull())
+ m_selection.visibleEnd().getInlineBoxAndOffset(endBox, unusedOffset);
+ if (startBox && endBox && startBox->direction() == endBox->direction())
+ return startBox->direction();
+
+ return directionOfEnclosingBlock();
+}
+
void FrameSelection::willBeModified(EAlteration alter, SelectionDirection direction)
{
if (alter != AlterationExtend)
@@ -411,7 +426,7 @@
} else {
switch (direction) {
case DirectionRight:
- if (directionOfEnclosingBlock() == LTR)
+ if (directionOfSelection() == LTR)
baseIsStart = true;
else
baseIsStart = false;
@@ -420,7 +435,7 @@
baseIsStart = true;
break;
case DirectionLeft:
- if (directionOfEnclosingBlock() == LTR)
+ if (directionOfSelection() == LTR)
baseIsStart = false;
else
baseIsStart = true;
@@ -553,7 +568,7 @@
switch (granularity) {
case CharacterGranularity:
if (isRange()) {
- if (directionOfEnclosingBlock() == LTR)
+ if (directionOfSelection() == LTR)
pos = VisiblePosition(m_selection.end(), m_selection.affinity());
else
pos = VisiblePosition(m_selection.start(), m_selection.affinity());
@@ -724,7 +739,7 @@
switch (granularity) {
case CharacterGranularity:
if (isRange())
- if (directionOfEnclosingBlock() == LTR)
+ if (directionOfSelection() == LTR)
pos = VisiblePosition(m_selection.start(), m_selection.affinity());
else
pos = VisiblePosition(m_selection.end(), m_selection.affinity());
Modified: trunk/Source/WebCore/editing/FrameSelection.h (93220 => 93221)
--- trunk/Source/WebCore/editing/FrameSelection.h 2011-08-17 18:04:31 UTC (rev 93220)
+++ trunk/Source/WebCore/editing/FrameSelection.h 2011-08-17 18:07:33 UTC (rev 93221)
@@ -248,6 +248,7 @@
void respondToNodeModification(Node*, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
TextDirection directionOfEnclosingBlock();
+ TextDirection directionOfSelection();
VisiblePosition positionForPlatform(bool isGetStart) const;
VisiblePosition startForPlatform() const;