Skip to content

Commit 9c00007

Browse files
author
Xiaomei Ji
committed
2011-04-13 Xiaomei Ji <xji@chromium.org>
Reviewed by Ryosuke Niwa. Continue (3rd) experiment with moving caret by word in visual order. https://bugs.webkit.org/show_bug.cgi?id=58294 * editing/selection/move-by-word-visually-expected.txt: * editing/selection/move-by-word-visually.html: 2011-04-13 Xiaomei Ji <xji@chromium.org> Reviewed by Ryosuke Niwa. Continue (3rd) experiment with moving caret by word in visual order. https://bugs.webkit.org/show_bug.cgi?id=58294 This patch along with r82588 and r83483 implements moving caret by word in visual order. The overall algorithm is: 1. First get the InlineBox and offset of the pass-in VisiblePosition. 2. Based on the position (left boundary, middle, right boundary) of the offset and the direction of the movement, look for visually adjacent word breaks. 2.1 If the offset is the minimum offset of the box, return the rightmost word boundary in previous boxes if moving left. return the leftmost word boundary in box and next boxes if moving right. 2.2 Similar for the case when offset is at the maximum offset of the box. 2.3 When offset is inside the box (not at boundaries), first find the previousWordPosition or nextWordPosition based on the directionality of the box. If this word break position is also inside the same box, return it. Otherwise (the nextWordPosition or previousWordPosition is not in the same box or is at the box boundary), collect all the word breaks in the box and search for the one closest to the input "offset" based on box directionality, block directionality, and movement direction. Continue search in adjacent boxes if needed. Notes: 1. Word boundaries are collected one box at a time. Only when a boundary that is closest to the input position (in the moving direction) is not available in current box, word boundaries in adjacent box will be collected. So, there is no need to save InlineBox in word boundaries. Instead, the word boundaries are saved as a pair (VisiblePosition, offset) to avoid recomputing VisiblePosition. 2. We only collect boundaries of the right kind (i.e. left boundary of a word in LTR block and right boundary of a word in RTL block). And word boundaries are collected using previousWordPosition() and nextWordPosition(). So when box directionality is the same as block directionality, word boundaries are collected from right to left visually in a LTR box, and word boundaries are collected from left to right visually in a RTL box. It is the other way around when box directionality is different from block directionality. 3. To find the right kinds of word boundaries, we must move back and forth between words in some situations. For example, if we're moving to the right in a LTR box in LTR block, we cannot simply return nextWordPosition() because it would return the right boundary of a word. Instead, we return nextWordPosition()'s nextWordPosition()'s previousWordPosition(). 4. When collecting word breaks inside a box, it first computes a start position, then collect the right kind of word breaks until it reaches the end of (or beyond) the box. In the meanwhile, it might need special handling on the rightmost or leftmost position based on the directionality of the box and block. These computations do not consider the box's bidi level. * editing/visible_units.cpp: (WebCore::nextWordBreakInBoxInsideBlockWithDifferentDirectionality): (WebCore::collectWordBreaksInBox): (WebCore::previousWordBoundaryInBox): (WebCore::nextWordBoundaryInBox): (WebCore::visuallyLastWordBoundaryInBox): (WebCore::leftWordBoundary): (WebCore::rightWordBoundary): (WebCore::leftWordPosition): (WebCore::rightWordPosition): Canonical link: https://commits.webkit.org/73749@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83996 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 3d680ce commit 9c00007

5 files changed

Lines changed: 482 additions & 83 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2011-04-13 Xiaomei Ji <xji@chromium.org>
2+
3+
Reviewed by Ryosuke Niwa.
4+
5+
Continue (3rd) experiment with moving caret by word in visual order.
6+
https://bugs.webkit.org/show_bug.cgi?id=58294
7+
8+
* editing/selection/move-by-word-visually-expected.txt:
9+
* editing/selection/move-by-word-visually.html:
10+
111
2011-04-15 Simon Fraser <simon.fraser@apple.com>
212

313
Rebaseline Mac pixel results in fast/ on SnowLeopard.

LayoutTests/editing/selection/move-by-word-visually-expected.txt

Lines changed: 168 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,189 @@
22
======== Move By Word ====
33
Test 1, LTR:
44
Move right by one word
5-
"abc def hij opq rst"[0, 8, 12, 16, 16, 19] FAIL expected: [4, 8, 12, 16, 19, 19]
5+
"abc def hij opq rst"[0, 4, 8, 12, 16]
66
Move left by one word
7-
"abc def hij opq rst"[16, 12, 8, 4, 0, 0]
8-
Test 2, RTL:
7+
"abc def hij opq rst"[19, 16, 12, 8, 4, 0]
8+
Test 2, LTR:
9+
Move right by one word
10+
"abc def hij opq rst"[0, 4, 8, 12, 16]
11+
Move left by one word
12+
"abc def hij opq rst"[19, 16, 12, 8, 4, 0]
13+
Test 3, RTL:
14+
Move left by one word
15+
"abc def hij opq rst"[0, 15, 11, 7, 3]
16+
Move right by one word
17+
"abc def hij opq rst"[19, 3, 7, 11, 15, 0]
18+
Test 4, LTR:
19+
Move right by one word
20+
"ZZZ QQQ BBB CCC XXX"[0, 15, 11, 7, 3]
21+
Move left by one word
22+
"ZZZ QQQ BBB CCC XXX"[19, 3, 7, 11, 15, 0]
23+
Test 5, RTL:
24+
Move left by one word
25+
"ZZZ QQQ BBB CCC XXX"[0, 4, 8, 12, 16]
26+
Move right by one word
27+
"ZZZ QQQ BBB CCC XXX"[19, 16, 12, 8, 4, 0]
28+
Test 6, LTR:
29+
Move right by one word
30+
"abc def hij AAA BBB WWW opr uvw xyz"[0, 4, 8, 12, 19, 15, 24, 28, 32]
31+
Move left by one word
32+
"abc def hij AAA BBB WWW opr uvw xyz"[35, 32, 28, 24, 15, 19, 12, 8, 4, 0]
33+
Test 7, RTL:
34+
Move left by one word
35+
"abc def hij AAA BBB WWW opr uvw xyz"[0, 7, 3, 12, 16, 20, 24, 31, 27]
36+
Move right by one word
37+
"abc def hij AAA BBB WWW opr uvw xyz"[35, 27, 31, 24, 20, 16, 12, 3, 7, 0]
38+
Test 8, LTR:
39+
Move right by one word
40+
"abc def ZQB RIG uvw xyz"[0, 4, 8, 11, 16, 20]
41+
Move left by one word
42+
"abc def ZQB RIG uvw xyz"[23, 20, 16, 11, 8, 4, 0]
43+
Test 9, RTL:
44+
Move left by one word
45+
"abc def ZQB RIG uvw xyz"[0, 3, 8, 12, 16, 19]
46+
Move right by one word
47+
"abc def ZQB RIG uvw xyz"[23, 19, 16, 12, 8, 3, 0]
48+
Test 10, LTR:
49+
Move right by one word
50+
"aaa AAA bbb"[0, 4, 8]
51+
Move left by one word
52+
"aaa AAA bbb"[11, 8, 4, 0]
53+
Test 11, RTL:
54+
Move left by one word
55+
"aaa AAA bbb"[0, 4, 8, 11]
56+
Move right by one word
57+
"aaa AAA bbb"[11, 8, 4, 0]
58+
Test 12, LTR:
59+
Move right by one word
60+
"AAA BBB WWW aaa bbb ccc DDD SSS UUU"[0, 7, 3, 12, 16, 20, 24, 31, 27]
61+
Move left by one word
62+
"AAA BBB WWW aaa bbb ccc DDD SSS UUU"[35, 27, 31, 24, 20, 16, 12, 3, 7, 0]
63+
Test 13, RTL:
64+
Move left by one word
65+
"AAA BBB WWW aaa bbb ccc DDD SSS UUU"[0, 4, 8, 12, 19, 15, 24, 28, 32]
66+
Move right by one word
67+
"AAA BBB WWW aaa bbb ccc DDD SSS UUU"[35, 32, 28, 24, 15, 19, 12, 8, 4, 0]
68+
Test 14, LTR:
69+
Move right by one word
70+
"AAA BBB aaa bbb WWW DDD"[0, 3, 8, 12, 16, 19]
71+
Move left by one word
72+
"AAA BBB aaa bbb WWW DDD"[23, 19, 16, 12, 8, 3, 0]
73+
Test 15, RTL:
74+
Move left by one word
75+
"AAA BBB aaa bbb WWW DDD"[0, 4, 8, 11, 16, 20]
76+
Move right by one word
77+
"AAA BBB aaa bbb WWW DDD"[23, 20, 16, 11, 8, 4, 0]
78+
Test 16, LTR:
79+
Move right by one word
80+
"ZQB abc RIG"[0, 4, 8, 11]
981
Move left by one word
10-
"abc def hij opq rst"[0, 11, 7, 3, 3, 19] FAIL expected: [15, 11, 7, 3, 19, 19]
82+
"ZQB abc RIG"[11, 8, 4, 0]
83+
Test 17, RTL:
84+
Move left by one word
85+
"ZQB abc RIG"[0, 4, 8]
86+
Move right by one word
87+
"ZQB abc RIG"[11, 8, 4, 0]
88+
Test 18, LTR:
1189
Move right by one word
12-
"abc def hij opq rst"[19, 7, 11, 15, 0, 0] FAIL expected: [3, 7, 11, 15, 0, 0]
13-
Test 3, LTR:
90+
"abc def hij opq"[0, 4, 15] FAIL expected: [0, 4, 11, 15]
91+
Move left by one word
92+
"abc def hij opq"[18, 15, 4, 0] FAIL expected: [18, 15, 11, 4, 0]
93+
Test 19, LTR:
1494
Move right by one word
15-
"ZZZ QQQ BBB CCC XXX"[0, 11, 7, 3, 3, 19] FAIL expected: [15, 11, 7, 3, 19, 19]
95+
"AAA "[0, 3]
1696
Move left by one word
17-
"ZZZ QQQ BBB CCC XXX"[19, 7, 11, 15, 0, 0] FAIL expected: [3, 7, 11, 15, 0, 0]
18-
Test 4, RTL:
97+
"BB"[2], "AAA "[3, 0]
98+
Test 20, RTL:
1999
Move left by one word
20-
"ZZZ QQQ BBB CCC XXX"[0, 8, 12, 16, 16, 19] FAIL expected: [4, 8, 12, 16, 19, 19]
100+
"AAA "[0, 4]
21101
Move right by one word
22-
"ZZZ QQQ BBB CCC XXX"[16, 12, 8, 4, 0, 0]
23-
Test 5, LTR:
102+
"BB"[2], "AAA "[4, 0]
103+
Test 21, LTR:
24104
Move right by one word
25-
"abc def ZQB RIG uvw xyz"[0, 4, 8, 11, 20, 20, 23] FAIL expected: [4, 8, 11, 16, 20, 23, 23]
105+
"abc def "[0, 4, 8], "hij opq"[4], " rst uvw"[1, 5]
106+
Move left by one word
107+
" rst uvw"[8, 5, 1], "hij opq"[4], "abc def "[8, 4, 0]
108+
Test 22, RTL:
26109
Move left by one word
27-
"abc def ZQB RIG uvw xyz"[20, 16, 4, 8, 4, 0, 0] FAIL expected: [20, 16, 11, 8, 4, 0, 0]
28-
Test 6, RTL:
110+
"abc def "[0], " rst uvw"[4], "hij opq"[3], "abc def "[7, 3] FAIL expected: ["abc def "[ 0, ]" rst uvw"[ 4, 0, ]"hij opq"[ 3, ]"abc def "[ 7, 3]
111+
Move right by one word
112+
" rst uvw"[8], "abc def "[3, 7], "hij opq"[3], " rst uvw"[4], "abc def "[0] FAIL expected: [" rst uvw"[ 8, ]"abc def "[ 3, 7, ]"hij opq"[ 3, ]" rst uvw"[ 0, 4, ]"abc def "[ 0]
113+
Test 23, RTL:
29114
Move left by one word
30-
"abc def ZQB RIG uvw xyz"[0, 3, 12, 12, 16, 19, 23] FAIL expected: [3, 8, 12, 16, 19, 23, 23]
115+
"abc def "[0], " rst uvw"[4], "hij opq"[3], "abc def "[7, 3] FAIL expected: ["abc def "[ 0, ]" rst uvw"[ 4, 0, ]"hij opq"[ 3, ]"abc def "[ 7, 3]
31116
Move right by one word
32-
"abc def ZQB RIG uvw xyz"[12, 16, 12, 8, 8, 0, 0] FAIL expected: [19, 16, 12, 8, 3, 0, 0]
33-
Test 7, LTR:
117+
" rst uvw"[8], "abc def "[3, 7], "hij opq"[3], " rst uvw"[4], "abc def "[0] FAIL expected: [" rst uvw"[ 8, ]"abc def "[ 3, 7, ]"hij opq"[ 3, ]" rst uvw"[ 0, 4, ]"abc def "[ 0]
118+
Test 24, LTR:
34119
Move right by one word
35-
"ZQB abc RIG"[0, 4, 8, 11] FAIL expected: [4, 8, 11, 11]
120+
"abc def "[0, 4, 8], "hij opq"[4], " rst uvw"[1, 5]
36121
Move left by one word
37-
"ZQB abc RIG"[4, 4, 4, 0] FAIL expected: [8, 4, 0, 0]
38-
Test 8, RTL:
122+
" rst uvw"[8, 5, 1], "hij opq"[4], "abc def "[8, 4, 0]
123+
Test 25, RTL:
39124
Move left by one word
40-
"ZQB abc RIG"[0, 4, 8, 11] FAIL expected: [4, 8, 11, 11]
125+
"ABD DSU "[0, 4, 8], "EJH FUX"[4], "FFZ LIG"[4]
126+
Move right by one word
127+
"FFZ LIG"[7, 4], "EJH FUX"[4], "ABD DSU "[8, 4, 0]
128+
Test 26, LTR:
41129
Move right by one word
42-
"ZQB abc RIG"[8, 0, 0, 0] FAIL expected: [8, 4, 0, 0]
130+
"ABD DSU "[0], "FFZ LIG"[3], "EJH FUX"[3], "ABD DSU "[7, 3]
131+
Move left by one word
132+
"FFZ LIG"[7], "ABD DSU "[3, 7], "EJH FUX"[3], "FFZ LIG"[3], "ABD DSU "[0]
133+
Test 27, RTL:
134+
Move left by one word
135+
"ABD DSU "[0, 4, 8], "EJH FUX"[4], "FFZ LIG"[4]
136+
Move right by one word
137+
"FFZ LIG"[7, 4], "EJH FUX"[4], "ABD DSU "[8, 4, 0]
138+
Test 28, LTR:
139+
Move right by one word
140+
"ABD DSU "[0], "FFZ LIG"[3], "EJH FUX"[3], "ABD DSU "[7, 3]
141+
Move left by one word
142+
"FFZ LIG"[7], "ABD DSU "[3, 7], "EJH FUX"[3], "FFZ LIG"[3], "ABD DSU "[0]
143+
Test 29, RTL:
144+
Move left by one word
145+
"ABD DSU "[0, 4, 8], "abc def"[3], "FFZ LIG"[4]
146+
Move right by one word
147+
"FFZ LIG"[7, 4], "abc def"[3], "ABD DSU "[8, 4, 0]
148+
Test 30, LTR:
149+
Move right by one word
150+
"ABD DSU "[0], "FFZ LIG"[3], "ABD DSU "[8], "abc def"[4], "ABD DSU "[7, 3]
151+
Move left by one word
152+
"FFZ LIG"[7], "ABD DSU "[3, 7], "abc def"[4], "ABD DSU "[8], "FFZ LIG"[3] FAIL expected: ["FFZ LIG"[ 7, ]"ABD DSU "[ 3, 7, ]"abc def"[ 4, ]"ABD DSU "[ 8, ]"FFZ LIG"[ 3, ]"ABD DSU "[ 0]
153+
Test 31, RTL:
154+
Move left by one word
155+
"ABD DSU "[0, 4, 8], "abc def"[3], "FFZ LIG"[4]
156+
Move right by one word
157+
"FFZ LIG"[7, 4], "abc def"[3], "ABD DSU "[8, 4, 0]
158+
Test 32, LTR:
159+
Move right by one word
160+
"ABD DSU "[0, 3, 8], "abc def"[4], "FFZ LIG"[3]
161+
Move left by one word
162+
"FFZ LIG"[7, 3], "abc def"[4], "ABD DSU "[8, 4, 0]
163+
Test 33, RTL:
164+
Move left by one word
165+
"ABD opq DSU "[0, 4, 8], "abc AAA def"[8, 4, 3], "FFZ rst LIG"[4, 8] FAIL expected: ["ABD opq DSU "[ 0, 4, 8, 12, ]"abc AAA def"[ 4, 3, ]"FFZ rst LIG"[ 4, 8]
166+
Move right by one word
167+
"FFZ rst LIG"[11, 8, 4], "abc AAA def"[4, 8], "ABD opq DSU "[8, 4, 0] FAIL expected: ["FFZ rst LIG"[ 11, 8, 4, ]"abc AAA def"[ 3, 4, ]"ABD opq DSU "[ 12, 8, 4, 0]
168+
Test 34, LTR:
169+
Move right by one word
170+
"ABD opq DSU "[0, 4], "abc AAA def"[8, 4], "ABD opq DSU "[12, 11], "FFZ rst LIG"[4, 8, 11] FAIL expected: ["ABD opq DSU "[ 0, 4, 8, ]"abc AAA def"[ 8, 7, ]"ABD opq DSU "[ 12, 11, ]"FFZ rst LIG"[ 4, 8, 11]
171+
Move left by one word
172+
"FFZ rst LIG"[11, 8, 4], "ABD opq DSU "[11, 12], "abc AAA def"[7, 8], "ABD opq DSU "[7, 4, 0] FAIL expected: ["FFZ rst LIG"[ 11, 8, 4, ]"ABD opq DSU "[ 11, 12, ]"abc AAA def"[ 7, 8, ]"ABD opq DSU "[ 8, 4, 0]
173+
Test 35, RTL:
174+
Move left by one word
175+
"ABD opq DSU "[0, 4, 8], "abc AAA def"[4, 8], "FFZ rst LIG"[4, 8] FAIL expected: ["ABD opq DSU "[ 0, 4, 8, 12, ]"abc AAA def"[ 4, 8, ]"FFZ rst LIG"[ 4, 8]
176+
Move right by one word
177+
"FFZ rst LIG"[11, 8, 4], "abc AAA def"[8, 4], "ABD opq DSU "[11, 8, 4, 0] FAIL expected: ["FFZ rst LIG"[ 11, 8, 4, ]"abc AAA def"[ 8, 4, ]"ABD opq DSU "[ 12, 8, 4, 0]
178+
Test 36, LTR:
179+
Move right by one word
180+
"ABD opq DSU "[0, 4, 8, 12], "abc AAA def"[4, 8], "FFZ rst LIG"[4, 8, 11]
181+
Move left by one word
182+
"FFZ rst LIG"[11, 8, 4], "abc AAA def"[8, 4], "ABD opq DSU "[12, 8, 4, 0]
183+
Test 37, LTR:
184+
Move right by one word
185+
"aaa "[0, 4], "bbb AAA "[4, 7]
186+
Move left by one word
187+
"FFZ"[3], "bbb AAA "[7, 4], "aaa "[4, 0]
43188

44189
======== Move By Word Specific Test ====
45190
Test 1

0 commit comments

Comments
 (0)