| Differences between
and this patch
- Source/WebCore/ChangeLog +21 lines
Lines 1-3 Source/WebCore/ChangeLog_sec1
1
2012-03-16  Xiaomei Ji  <xji@chromium.org>
2
3
        visual word movement: using cache to decrease the number of collectLeafBoxesInLogicalOrder on RootInlineBox
4
        https://bugs.webkit.org/show_bug.cgi?id=81408
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * editing/visible_units.cpp:
9
        (CachedRootAndLeafBoxesInLogicalOrder): Added class to cache the RootInlineBox and its leaf boxes in logical order.
10
        (WebCore::CachedRootAndLeafBoxesInLogicalOrder::leafBoxesInLogicalOrder):
11
        (WebCore):
12
        (WebCore::CachedRootAndLeafBoxesInLogicalOrder::CachedRootAndLeafBoxesInLogicalOrder):
13
        (WebCore::CachedRootAndLeafBoxesInLogicalOrder::collectLeafBoxesInLogicalOrder):
14
        (WebCore::previousBoxInLine): Passing in CachedRootAndLeafBoxesInLogicalOrder object around.
15
        (WebCore::logicallyPreviousBox):
16
        (WebCore::nextBoxInLine):
17
        (WebCore::logicallyNextBox):
18
        (WebCore::wordBreakIteratorForMinOffsetBoundary):
19
        (WebCore::wordBreakIteratorForMaxOffsetBoundary):
20
        (WebCore::visualWordPosition):
21
1
2012-03-16  Emil A Eklund  <eae@chromium.org>
22
2012-03-16  Emil A Eklund  <eae@chromium.org>
2
23
3
        Fix rounding and usage of LayoutUnits in RenderBoxModelObject
24
        Fix rounding and usage of LayoutUnits in RenderBoxModelObject
- Source/WebCore/editing/visible_units.cpp -26 / +47 lines
Lines 166-178 static int boxIndexInVector(const Inline Source/WebCore/editing/visible_units.cpp_sec1
166
    return 0;
166
    return 0;
167
}
167
}
168
168
169
static const InlineTextBox* previousBoxInLine(const RootInlineBox* root, const InlineTextBox* box, Vector<InlineBox*>& leafBoxesInLogicalOrder)
169
class CachedRootAndLeafBoxesInLogicalOrder {
170
public:
171
    CachedRootAndLeafBoxesInLogicalOrder();
172
    const Vector<InlineBox*>& collectLeafBoxesInLogicalOrder(const RootInlineBox*);
173
    const Vector<InlineBox*>& leafBoxesInLogicalOrder() const { return m_leafBoxes; }
174
    
175
private:
176
    const RootInlineBox* m_rootInlineBox;
177
    Vector<InlineBox*> m_leafBoxes;
178
};
179
180
CachedRootAndLeafBoxesInLogicalOrder::CachedRootAndLeafBoxesInLogicalOrder() : m_rootInlineBox(0) { };
181
182
const Vector<InlineBox*>& CachedRootAndLeafBoxesInLogicalOrder::collectLeafBoxesInLogicalOrder(const RootInlineBox* root)
183
{
184
    if (m_rootInlineBox != root) {
185
        m_rootInlineBox = root;
186
        m_leafBoxes.clear();
187
        root->collectLeafBoxesInLogicalOrder(m_leafBoxes);
188
    }
189
    return m_leafBoxes;
190
}
191
192
static const InlineTextBox* previousBoxInLine(const RootInlineBox* root, const InlineTextBox* box, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes)
170
{
193
{
171
    if (!root)
194
    if (!root)
172
        return 0;
195
        return 0;
173
196
174
    leafBoxesInLogicalOrder.clear();
197
    const Vector<InlineBox*>&  leafBoxesInLogicalOrder = rootAndLeafBoxes.collectLeafBoxesInLogicalOrder(root);
175
    root->collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder);
176
198
177
    // If box is null, root is box's previous RootInlineBox, and previousBox is the last logical box in root.
199
    // If box is null, root is box's previous RootInlineBox, and previousBox is the last logical box in root.
178
    int boxIndex = leafBoxesInLogicalOrder.size() - 1;
200
    int boxIndex = leafBoxesInLogicalOrder.size() - 1;
Lines 187-202 static const InlineTextBox* previousBoxI Source/WebCore/editing/visible_units.cpp_sec2
187
    return 0;
209
    return 0;
188
}
210
}
189
211
190
static const InlineTextBox* logicallyPreviousBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& previousBoxInDifferentBlock)
212
static const InlineTextBox* logicallyPreviousBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& previousBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes)
191
{
213
{
192
    const InlineBox* startBox = textBox;
214
    const InlineBox* startBox = textBox;
193
    Vector<InlineBox*> leafBoxesInLogicalOrder;
194
215
195
    const InlineTextBox* previousBox = previousBoxInLine(startBox->root(), textBox, leafBoxesInLogicalOrder);
216
    const InlineTextBox* previousBox = previousBoxInLine(startBox->root(), textBox, rootAndLeafBoxes);
196
    if (previousBox)
217
    if (previousBox)
197
        return previousBox;
218
        return previousBox;
198
219
199
    previousBox = previousBoxInLine(startBox->root()->prevRootBox(), 0, leafBoxesInLogicalOrder);
220
    previousBox = previousBoxInLine(startBox->root()->prevRootBox(), 0, rootAndLeafBoxes);
200
    if (previousBox)
221
    if (previousBox)
201
        return previousBox;
222
        return previousBox;
202
223
Lines 205-230 static const InlineTextBox* logicallyPre Source/WebCore/editing/visible_units.cpp_sec3
205
        if (!previousRoot)
226
        if (!previousRoot)
206
            break;
227
            break;
207
228
208
        previousBox = previousBoxInLine(previousRoot, 0, leafBoxesInLogicalOrder);
229
        previousBox = previousBoxInLine(previousRoot, 0, rootAndLeafBoxes);
209
        if (previousBox) {
230
        if (previousBox) {
210
            previousBoxInDifferentBlock = true;
231
            previousBoxInDifferentBlock = true;
211
            return previousBox;
232
            return previousBox;
212
        }
233
        }
213
234
214
        if (!leafBoxesInLogicalOrder.size())
235
        if (!rootAndLeafBoxes.leafBoxesInLogicalOrder().size())
215
            break;
236
            break;
216
        startBox = leafBoxesInLogicalOrder[0];
237
        startBox = rootAndLeafBoxes.leafBoxesInLogicalOrder()[0];
217
    }
238
    }
218
    return 0;
239
    return 0;
219
}
240
}
220
241
221
static const InlineTextBox* nextBoxInLine(const RootInlineBox* root, const InlineTextBox* box, Vector<InlineBox*>& leafBoxesInLogicalOrder)
242
static const InlineTextBox* nextBoxInLine(const RootInlineBox* root, const InlineTextBox* box, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes)
222
{
243
{
223
    if (!root)
244
    if (!root)
224
        return 0;
245
        return 0;
225
246
226
    leafBoxesInLogicalOrder.clear();
247
    const Vector<InlineBox*>&  leafBoxesInLogicalOrder = rootAndLeafBoxes.collectLeafBoxesInLogicalOrder(root);
227
    root->collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder);
228
248
229
    // If box is null, root is box's next RootInlineBox, and nextBox is the first logical box in root.
249
    // If box is null, root is box's next RootInlineBox, and nextBox is the first logical box in root.
230
    // Otherwise, root is box's RootInlineBox, and nextBox is the next logical box in the same line.
250
    // Otherwise, root is box's RootInlineBox, and nextBox is the next logical box in the same line.
Lines 240-255 static const InlineTextBox* nextBoxInLin Source/WebCore/editing/visible_units.cpp_sec4
240
    return 0;
260
    return 0;
241
}
261
}
242
262
243
static const InlineTextBox* logicallyNextBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock)
263
static const InlineTextBox* logicallyNextBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes)
244
{
264
{
245
    const InlineBox* startBox = textBox;
265
    const InlineBox* startBox = textBox;
246
    Vector<InlineBox*> leafBoxesInLogicalOrder;
247
266
248
    const InlineTextBox* nextBox = nextBoxInLine(startBox->root(), textBox, leafBoxesInLogicalOrder);
267
    const InlineTextBox* nextBox = nextBoxInLine(startBox->root(), textBox, rootAndLeafBoxes);
249
    if (nextBox)
268
    if (nextBox)
250
        return nextBox;
269
        return nextBox;
251
270
252
    nextBox = nextBoxInLine(startBox->root()->nextRootBox(), 0, leafBoxesInLogicalOrder);
271
    nextBox = nextBoxInLine(startBox->root()->nextRootBox(), 0, rootAndLeafBoxes);
253
    if (nextBox)
272
    if (nextBox)
254
        return nextBox;
273
        return nextBox;
255
274
Lines 258-283 static const InlineTextBox* logicallyNex Source/WebCore/editing/visible_units.cpp_sec5
258
        if (!nextRoot)
277
        if (!nextRoot)
259
            break;
278
            break;
260
279
261
        nextBox = nextBoxInLine(nextRoot, 0, leafBoxesInLogicalOrder);
280
        nextBox = nextBoxInLine(nextRoot, 0, rootAndLeafBoxes);
262
        if (nextBox) {
281
        if (nextBox) {
263
            nextBoxInDifferentBlock = true;
282
            nextBoxInDifferentBlock = true;
264
            return nextBox;
283
            return nextBox;
265
        }
284
        }
266
285
267
        if (!leafBoxesInLogicalOrder.size())
286
        if (!rootAndLeafBoxes.leafBoxesInLogicalOrder().size())
268
            break;
287
            break;
269
        startBox = leafBoxesInLogicalOrder[0];
288
        startBox = rootAndLeafBoxes.leafBoxesInLogicalOrder()[0];
270
    }
289
    }
271
    return 0;
290
    return 0;
272
}
291
}
273
292
274
static TextBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
293
static TextBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
275
     int& previousBoxLength, bool& previousBoxInDifferentBlock)
294
     int& previousBoxLength, bool& previousBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes)
276
{
295
{
277
    previousBoxInDifferentBlock = false;
296
    previousBoxInDifferentBlock = false;
278
297
279
    // FIXME: Handle the case when we don't have an inline text box.
298
    // FIXME: Handle the case when we don't have an inline text box.
280
    const InlineTextBox* previousBox = logicallyPreviousBox(visiblePosition, textBox, previousBoxInDifferentBlock);
299
    const InlineTextBox* previousBox = logicallyPreviousBox(visiblePosition, textBox, previousBoxInDifferentBlock, rootAndLeafBoxes);
281
300
282
    int len = 0;
301
    int len = 0;
283
    Vector<UChar, 1024> string;
302
    Vector<UChar, 1024> string;
Lines 292-303 static TextBreakIterator* wordBreakItera Source/WebCore/editing/visible_units.cpp_sec6
292
    return wordBreakIterator(string.data(), len);
311
    return wordBreakIterator(string.data(), len);
293
} 
312
} 
294
313
295
static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock)
314
static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes)
296
{
315
{
297
    nextBoxInDifferentBlock = false;
316
    nextBoxInDifferentBlock = false;
298
317
299
    // FIXME: Handle the case when we don't have an inline text box.
318
    // FIXME: Handle the case when we don't have an inline text box.
300
    const InlineTextBox* nextBox = logicallyNextBox(visiblePosition, textBox, nextBoxInDifferentBlock);
319
    const InlineTextBox* nextBox = logicallyNextBox(visiblePosition, textBox, nextBoxInDifferentBlock, rootAndLeafBoxes);
301
320
302
    int len = 0;
321
    int len = 0;
303
    Vector<UChar, 1024> string;
322
    Vector<UChar, 1024> string;
Lines 340-345 static VisiblePosition visualWordPositio Source/WebCore/editing/visible_units.cpp_sec7
340
    VisiblePosition current = visiblePosition;
359
    VisiblePosition current = visiblePosition;
341
    TextBreakIterator* iter = 0;
360
    TextBreakIterator* iter = 0;
342
361
362
    CachedRootAndLeafBoxesInLogicalOrder rootAndLeafBoxes;
363
343
    while (1) {
364
    while (1) {
344
        VisiblePosition adjacentCharacterPosition = direction == MoveRight ? current.right(true) : current.left(true); 
365
        VisiblePosition adjacentCharacterPosition = direction == MoveRight ? current.right(true) : current.left(true); 
345
        if (adjacentCharacterPosition == current || adjacentCharacterPosition.isNull())
366
        if (adjacentCharacterPosition == current || adjacentCharacterPosition.isNull())
Lines 363-371 static VisiblePosition visualWordPositio Source/WebCore/editing/visible_units.cpp_sec8
363
        bool movingIntoNewBox = previouslyVisitedBox != box;
384
        bool movingIntoNewBox = previouslyVisitedBox != box;
364
385
365
        if (offsetInBox == box->caretMinOffset())
386
        if (offsetInBox == box->caretMinOffset())
366
            iter = wordBreakIteratorForMinOffsetBoundary(visiblePosition, textBox, previousBoxLength, previousBoxInDifferentBlock);
387
            iter = wordBreakIteratorForMinOffsetBoundary(visiblePosition, textBox, previousBoxLength, previousBoxInDifferentBlock, rootAndLeafBoxes);
367
        else if (offsetInBox == box->caretMaxOffset())
388
        else if (offsetInBox == box->caretMaxOffset())
368
            iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBox, nextBoxInDifferentBlock);
389
            iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBox, nextBoxInDifferentBlock, rootAndLeafBoxes);
369
        else if (movingIntoNewBox) {
390
        else if (movingIntoNewBox) {
370
            iter = wordBreakIterator(textBox->textRenderer()->text()->characters() + textBox->start(), textBox->len());
391
            iter = wordBreakIterator(textBox->textRenderer()->text()->characters() + textBox->start(), textBox->len());
371
            previouslyVisitedBox = box;
392
            previouslyVisitedBox = box;
- LayoutTests/ChangeLog +11 lines
Lines 1-3 LayoutTests/ChangeLog_sec1
1
2012-03-16  Xiaomei Ji  <xji@chromium.org>
2
3
        visual word movement: using cache to decrease the number of collectLeafBoxesInLogicalOrder on RootInlineBox
4
        https://bugs.webkit.org/show_bug.cgi?id=81408
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * editing/selection/move-by-word-visually-single-space-one-element-expected.txt:
9
        * editing/selection/move-by-word-visually-single-space-one-element.html:
10
          Add a test case that a word is spreading across multiple inline boxes.
11
1
2012-03-16  Tim Horton  <timothy_horton@apple.com>
12
2012-03-16  Tim Horton  <timothy_horton@apple.com>
2
13
3
        Unreviewed new mac baselines after http://trac.webkit.org/changeset/108185
14
        Unreviewed new mac baselines after http://trac.webkit.org/changeset/108185
- LayoutTests/editing/selection/move-by-word-visually-single-space-one-element-expected.txt +5 lines
Lines 97-102 Move left by one word LayoutTests/editing/selection/move-by-word-visually-single-space-one-element-expected.txt_sec1
97
" opq rst "[8, 5, 1], "abc def hij "[8, 4, 0]
97
" opq rst "[8, 5, 1], "abc def hij "[8, 4, 0]
98
Test 19, LTR:
98
Test 19, LTR:
99
Move right by one word
99
Move right by one word
100
"abc def this"[0, 4, 8], "end opq rst "[4, 8, 11]
101
Move left by one word
102
"end opq rst "[11, 8, 4], "abc def this"[8, 4, 0]
103
Test 20, LTR:
104
Move right by one word
100
<DIV>[0]
105
<DIV>[0]
101
Move left by one word
106
Move left by one word
102
<DIV>[0]
107
<DIV>[0]
- LayoutTests/editing/selection/move-by-word-visually-single-space-one-element.html +2 lines
Lines 71-76 where child_node_index is optional, defa LayoutTests/editing/selection/move-by-word-visually-single-space-one-element.html_sec1
71
<!-- Test with image -- non-inline-text-box -->
71
<!-- Test with image -- non-inline-text-box -->
72
<div id="d_1" dir=ltr class="test_move_by_word" contenteditable title="[d_1, 0, 1][d_1, 4, 1][d_1, 8, 1][d_1, 1, 3][d_1, 5, 3][d_1, 8, 3]|[d_1, 8, 3][d_1, 5, 3][d_1, 1, 3][d_1, 8, 1][d_1, 4, 1][d_1, 0, 1]">abc def hij <img src=../../accessibility/resources/cake.png> opq rst </div>
72
<div id="d_1" dir=ltr class="test_move_by_word" contenteditable title="[d_1, 0, 1][d_1, 4, 1][d_1, 8, 1][d_1, 1, 3][d_1, 5, 3][d_1, 8, 3]|[d_1, 8, 3][d_1, 5, 3][d_1, 1, 3][d_1, 8, 1][d_1, 4, 1][d_1, 0, 1]">abc def hij <img src=../../accessibility/resources/cake.png> opq rst </div>
73
73
74
<div id="d_2" dir=ltr class="test_move_by_word" contenteditable title="[d_2, 0, 1][d_2, 4, 1][d_2, 8, 1][d_2, 4, 5][d_2, 8, 5][d_2, 11, 5]|[d_2, 11, 5][d_2, 8, 5][d_2, 4, 5][d_2, 8, 1][d_2, 4, 1][d_2, 0, 1]">abc def this<span>is</span><span>one</span><span>word</span>end opq rst </div>
75
74
<!-- empty div -->
76
<!-- empty div -->
75
<div dir=ltr class="test_move_by_word" title="0|0" contenteditable></div>
77
<div dir=ltr class="test_move_by_word" title="0|0" contenteditable></div>
76
78

Return to Bug 81408