Changeset 91788 in webkit


Ignore:
Timestamp:
Jul 26, 2011 2:51:17 PM (13 years ago)
Author:
xji@chromium.org
Message:

--webkit-visual-word does not work in multi-line
https://bugs.webkit.org/show_bug.cgi?id=61344

Reviewed by Ryosuke Niwa.

Source/WebCore:

Replace Position(node, offset, PositionIsOffsetInAnchor) with
createPositionAvoidingIgnoredNode(node, offset) which takes care of creating position
before/after <br/> etc. editingIgnoresContent node.

When iterate InlineBox, replace prevLeafChild and nextLeafChild (which only returns
InlineBox within the same line) with leftInlineBox and rightInlineBox (which returns
InlineBox across multiple lines).

  • editing/htmlediting.cpp:

(WebCore::createPositionAvoidingIgnoredNode):

  • editing/htmlediting.h:
  • editing/visible_units.cpp:

(WebCore::previousWordBreakInBoxInsideBlockWithSameDirectionality): Replace Position() with
createPositionAvoidingIgnoredNode().
(WebCore::leftmostPositionInRTLBoxInLTRBlock): Ditto.
(WebCore::rightmostPositionInLTRBoxInRTLBlock): Ditto.
(WebCore::nextWordBreakInBoxInsideBlockWithDifferentDirectionality): Ditto.
(WebCore::blockWithPreviousLineBox): Added.
(WebCore::previousRootInlineBox): Added.
(WebCore::blockWithNextLineBox): Added.
(WebCore::nextRootInlineBox): Added.
(WebCore::leftInlineBox): Added.
(WebCore::rightInlineBox): Added.
(WebCore::leftWordBoundary): Replace prevLeafChild/nextLeafChild with leftInlineBox()
and rightInlineBox().
(WebCore::rightWordBoundary): Ditto.
(WebCore::leftWordPositionAcrossBoundary): Ditto.
(WebCore::rightWordPositionAcrossBoundary): Ditto.

LayoutTests:

Add test for multiple-line.

  • editing/selection/move-by-word-visually-null-box.html:
  • editing/selection/move-by-word-visually-others-expected.txt:
  • editing/selection/move-by-word-visually-others.html: Add tests for multi-line. Shorten

test id.

  • editing/selection/move-by-word-visually-single-space-sigle-line.html: Shorten test id.
  • editing/selection/resources/move-by-word-visually.js:

(moveByWordForEveryPosition):
(setWidth):
(runMoveLeftRight):

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91781 r91788  
     12011-07-26  Xiaomei Ji  <xji@chromium.org>
     2
     3        --webkit-visual-word does not work in multi-line
     4        https://bugs.webkit.org/show_bug.cgi?id=61344
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Add test for multiple-line.
     9
     10        * editing/selection/move-by-word-visually-null-box.html:
     11        * editing/selection/move-by-word-visually-others-expected.txt:
     12        * editing/selection/move-by-word-visually-others.html: Add tests for multi-line. Shorten
     13        test id.
     14        * editing/selection/move-by-word-visually-single-space-sigle-line.html: Shorten test id.
     15        * editing/selection/resources/move-by-word-visually.js:
     16        (moveByWordForEveryPosition):
     17        (setWidth):
     18        (runMoveLeftRight):
     19
    1202011-07-26  David Hyatt  <hyatt@apple.com>
    221
  • trunk/LayoutTests/editing/selection/move-by-word-visually-null-box.html

    r91077 r91788  
    1919    layoutTestController.dumpAsText();
    2020</script>
     21<div id="console"></div>
    2122<div id="testMoveByWord">
    2223<output><div dir=ltr title="0|0" class="test_move_by_word">
     24<div class="test_move_by_word" dir=ltr contenteditable title="0|0"></div>
     2500<base dir=ltr class="test_move_by_word" title="3|3 1">
    2326</div>
    24 <div id="console"></div>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-others-expected.txt

    r91077 r91788  
    224224Test 44, LTR:
    225225Move right by one word
     226"abc def ghi jkl mn "[0, 4, 8, 12, 16], "opq rst uvw xyz"[0, 4, 8, 12]
     227Move left by one word
     228"opq rst uvw xyz"[15, 12, 8, 4, 0], "abc def ghi jkl mn "[16, 12, 8, 4, 0]
     229Test 45, LTR:
     230Move right by one word
     231"abc def ghi jkl mn "[0, 4, 8, 12, 16], "opq rst uvw xyz"[0, 4, 8, 12]
     232Move left by one word
     233"opq rst uvw xyz"[15, 12, 8, 4, 0], "abc def ghi jkl mn "[16, 12, 8, 4, 0]
     234Test 46, LTR:
     235Move right by one word
     236"AAA AAA AAA AAA "[0, 3, 8, 11], "AAA AAA AAA AAA"[0, 3, 8, 11]
     237Move left by one word
     238"AAA AAA AAA AAA"[15, 11, 8, 3, 0], "AAA AAA AAA AAA "[11, 8, 3, 0]
     239Test 47, LTR:
     240Move right by one word
     241"AAA AAA AAA AAA "[0, 3, 8, 11], "AAA AAA AAA AAA"[0, 3, 8, 11]
     242Move left by one word
     243"AAA AAA AAA AAA"[15, 11, 8, 3, 0], "AAA AAA AAA AAA "[11, 8, 3, 0]
     244Test 48, LTR:
     245Move right by one word
     246" abc def AAA AAA hij AAA AAA uvw xyz "[1, 5, 9, 12, 17, 21, 25, 29, 33], "AAA kj AAA mn opq AAA AAA"[0, 4, 7, 11, 14, 18, 22, 25]
     247Move left by one word
     248"AAA kj AAA mn opq AAA AAA"[25, 22, 18, 14, 11, 7, 4, 0], " abc def AAA AAA hij AAA AAA uvw xyz "[33, 29, 25, 21, 17, 12, 9, 5, 1]
     249Test 49, LTR:
     250Move right by one word
     251" abc def AAA AAA hij AAA AAA uvw xyz "[1, 5, 9, 12, 17, 21, 25, 29, 33], "AAA kj AAA mn opq AAA AAA"[0, 4, 7, 11, 14, 18, 22, 25]
     252Move left by one word
     253"AAA kj AAA mn opq AAA AAA"[25, 22, 18, 14, 11, 7, 4, 0], " abc def AAA AAA hij AAA AAA uvw xyz "[33, 29, 25, 21, 17, 12, 9, 5, 1]
     254Test 50, RTL:
     255Move left by one word
     256"abc def ghi jkl mn "[0, 3, 8, 11, 16], "opq rst uvw xyz"[0, 3, 8, 11]
     257Move right by one word
     258"opq rst uvw xyz"[15, 11, 8, 3, 0], "abc def ghi jkl mn "[16, 11, 8, 3, 0]
     259Test 51, RTL:
     260Move left by one word
     261"abc def ghi jkl mn "[0, 3, 8, 11, 16, 18], "opq rst uvw xyz"[0, 3, 8, 11]
     262Move right by one word
     263"opq rst uvw xyz"[15, 11, 8, 3, 0], "abc def ghi jkl mn "[18, 16, 11, 8, 3, 0]
     264Test 52, RTL:
     265Move left by one word
     266"AAA AAA AAA AAA "[0, 4, 8, 12], "AAA AAA AAA AAA"[0, 4, 8, 12]
     267Move right by one word
     268"AAA AAA AAA AAA"[15, 12, 8, 4, 0], "AAA AAA AAA AAA "[12, 8, 4, 0]
     269Test 53, RTL:
     270Move left by one word
     271"AAA AAA AAA AAA "[0, 4, 8, 12], "AAA AAA AAA AAA"[0, 4, 8, 12]
     272Move right by one word
     273"AAA AAA AAA AAA"[15, 12, 8, 4, 0], "AAA AAA AAA AAA "[12, 8, 4, 0]
     274Test 54, RTL:
     275Move left by one word
     276" abc def AAA AAA hij AAA AAA uvw xyz "[1, 4, 9, 13, 17, 21, 25, 29, 33], "AAA kj AAA mn opq AAA AAA"[0, 4, 7, 11, 14, 18, 22]
     277Move right by one word
     278"AAA kj AAA mn opq AAA AAA"[25, 22, 18, 14, 11, 7, 4, 0], " abc def AAA AAA hij AAA AAA uvw xyz "[33, 29, 25, 21, 17, 13, 9, 4, 1]
     279Test 55, RTL:
     280Move left by one word
     281" abc def AAA AAA hij AAA AAA uvw xyz "[1, 4, 9, 13, 17, 21, 25, 29, 33, 36], "AAA kj AAA mn opq AAA AAA"[0, 4, 7, 11, 14, 18, 22]
     282Move right by one word
     283"AAA kj AAA mn opq AAA AAA"[25, 22, 18, 14, 11, 7, 4, 0], " abc def AAA AAA hij AAA AAA uvw xyz "[36, 33, 29, 25, 21, 17, 13, 9, 4, 1]
     284Test 56, LTR:
     285Move right by one word
    226286"abc def "[0, 4]
    227287Move left by one word
    228288" hij opq"[8, 5, 1]
    229 Test 45, LTR:
     289Test 57, LTR:
     290Move right by one word
     291<DIV>[0]
     292Move left by one word
     293<DIV>[0]
     294Test 58, LTR:
    230295Move right by one word
    231296"\n00"[3]
  • trunk/LayoutTests/editing/selection/move-by-word-visually-others.html

    r91077 r91788  
    55<link rel="stylesheet" type="text/css" href="resources/extend-selection.css" />
    66<style>
    7 test_move_by_word {display: none;}
     7.fix_width {font-size: 10px; font-family: sans-serif;}
    88</style>
    99<script src="resources/move-by-word-visually.js"></script>
     
    8989<div style="white-space:pre" contenteditable dir=ltr class="test_move_by_word" title="0 1 2 3 4 9 10 11 17 21|24 21 17 11 10 9 4 3 2 1 0">人一氧喝大    笑抬的     abc def</div>
    9090
     91<!-- test multi-line -->
     92<div><span class="fix_width" id="span_size">אאא אאא</span></div>
     93<div contenteditable dir=ltr id="ml_1" class="test_move_by_word fix_width" title="[ml_1, 0][ml_1, 4][ml_1, 8][ml_1, 12][ml_1, 16][ml_1, 0, 5][ml_1, 4, 5][ml_1, 8, 5][ml_1, 12, 5]|[ml_1, 15, 5][ml_1, 12, 5][ml_1, 8, 5][ml_1, 4, 5][ml_1, 0, 5][ml_1, 16][ml_1, 12][ml_1, 8][ml_1, 4][ml_1, 0]">abc def ghi jkl mn <br/><br/><br/>opq rst uvw xyz</div>
     94
     95<div contenteditable dir=ltr id="ml_2" class="test_move_by_word fix_width" title="[ml_2, 0][ml_2, 4][ml_2, 8][ml_2, 12][ml_2, 16][ml_2, 0, 5][ml_2, 4, 5][ml_2, 8, 5][ml_2, 12, 5]|[ml_2, 15, 5][ml_2, 12, 5][ml_2, 8, 5][ml_2, 4, 5][ml_2, 0, 5][ml_2, 16][ml_2, 12][ml_2, 8][ml_2, 4][ml_2, 0]">abc def ghi jkl mn <div><br/></div><div><br/></div><div><br/></div>opq rst uvw xyz</div>
     96
     97<div contenteditable dir=ltr id="ml_3" class="test_move_by_word fix_width" title="[ml_3, 0][ml_3, 3][ml_3, 8][ml_3, 11]][ml_3, 0, 5][ml_3, 3, 5][ml_3, 8, 5][ml_3, 11, 5]|[ml_3, 15, 5][ml_3, 11, 5][ml_3, 8, 5][ml_3, 3, 5][ml_3, 0, 5][ml_3, 11][ml_3, 8][ml_3, 3][ml_3, 0]">אאא אאא אאא אאא <br/><br/><br/>אאא אאא אאא אאא</div>
     98
     99<div contenteditable dir=ltr id="ml_4" class="test_move_by_word fix_width" title="[ml_4, 0][ml_4, 3][ml_4, 8][ml_4, 11][ml_4, 0, 5][ml_4, 3, 5][ml_4, 8, 5][ml_4, 11, 5]|[ml_4, 15, 5][ml_4, 11, 5][ml_4, 8, 5][ml_4, 3, 5][ml_4, 0, 5][ml_4, 11][ml_4, 8][ml_4, 3][ml_4, 0]">אאא אאא אאא אאא <div><br/></div><div><br/></div><div><br/></div>אאא אאא אאא אאא</div>
     100
     101<div contenteditable dir=ltr id="ml_5" class="test_move_by_word fix_width" title="[ml_5, 1][ml_5, 5][ml_5, 9][ml_5, 12][ml_5, 17][ml_5, 21][ml_5, 25][ml_5, 29][ml_5, 33][ml_5, 0, 5][ml_5, 4, 5][ml_5, 7, 5][ml_5, 11, 5][ml_5, 14, 5][ml_5, 18, 5][ml_5, 22, 5][ml_5, 25, 5]|[ml_5, 25, 5][ml_5, 22, 5][ml_5, 18, 5][ml_5, 14, 5][ml_5, 11, 5][ml_5, 7, 5][ml_5, 4, 5][ml_5, 0, 5][ml_5, 33][ml_5, 29][ml_5, 25][ml_5, 21][ml_5, 17][ml_5, 12][ml_5, 9][ml_5, 5][ml_5, 1]"> abc def אאא אאא hij אאא אאא uvw xyz <br/><br/><br/>אאא kj אאא mn opq אאא אאא</div>
     102
     103<div contenteditable dir=ltr id="ml_6" class="test_move_by_word fix_width" title="[ml_6, 1][ml_6, 5][ml_6, 9][ml_6, 12][ml_6, 17][ml_6, 21][ml_6, 25][ml_6, 29][ml_6, 33][ml_6, 0, 5][ml_6, 4, 5][ml_6, 7, 5][ml_6, 11, 5][ml_6, 14, 5][ml_6, 18, 5][ml_6, 22, 5][ml_6, 25, 5]|[ml_6, 25, 5][ml_6, 22, 5][ml_6, 18, 5][ml_6, 14, 5][ml_6, 11, 5][ml_6, 7, 5][ml_6, 4, 5][ml_6, 0, 5][ml_6, 33][ml_6, 29][ml_6, 25][ml_6, 21][ml_6, 17][ml_6, 12][ml_6, 9][ml_6, 5][ml_6, 1]"> abc def אאא אאא hij אאא אאא uvw xyz <div><br/></div><div><br/></div><div><br/></div>אאא kj אאא mn opq אאא אאא</div>
     104
     105
     106<div contenteditable dir=rtl id="ml_7" class="test_move_by_word fix_width" title="[ml_7, 15, 5][ml_7, 11, 5][ml_7, 8, 5][ml_7, 3, 5][ml_7, 0, 5][ml_7, 16][ml_7, 11][ml_7, 8][ml_7, 3][ml_7, 0]|[ml_7, 0][ml_7, 3][ml_7, 8][ml_7, 11][ml_7, 16][ml_7, 0, 5][ml_7, 3, 5][ml_7, 8, 5][ml_7, 11, 5]">abc def ghi jkl mn <br/><br/><br/>opq rst uvw xyz</div>
     107
     108<div contenteditable dir=rtl id="ml_8" class="test_move_by_word fix_width" title="[ml_8, 15, 5][ml_8, 11, 5][ml_8, 8, 5][ml_8, 3, 5][ml_8, 0, 5][ml_8, 18][ml_8, 16][ml_8, 11][ml_8, 8][ml_8, 3][ml_8, 0]|[ml_8, 0][ml_8, 3][ml_8, 8][ml_8, 11][ml_8, 16][ml_8, 18][ml_8, 0, 5][ml_8, 3, 5][ml_8, 8, 5][ml_8, 11, 5]">abc def ghi jkl mn <div><br/></div><div><br/></div><div><br/></div>opq rst uvw xyz</div>
     109
     110<div contenteditable dir=rtl id="ml_9" class="test_move_by_word fix_width" title="[ml_9, 15, 5][ml_9, 12, 5][ml_9, 8, 5][ml_9, 4, 5][ml_9, 0, 5][ml_9, 12][ml_9, 8][ml_9, 4][ml_9, 0]|[ml_9, 0][ml_9, 4][ml_9, 8][ml_9, 12][ml_9, 0, 5][ml_9, 4, 5][ml_9, 8, 5][ml_9, 12, 5]">אאא אאא אאא אאא <br/><br/><br/>אאא אאא אאא אאא</div>
     111
     112<div contenteditable dir=rtl id="ml_10" class="test_move_by_word fix_width" title="[ml_10, 15, 5][ml_10, 12, 5][ml_10, 8, 5][ml_10, 4, 5][ml_10, 0, 5][ml_10, 12][ml_10, 8][ml_10, 4][ml_10, 0]|[ml_10, 0][ml_10, 4][ml_10, 8][ml_10, 12][ml_10, 0, 5][ml_10, 4, 5][ml_10, 8, 5][ml_10, 12, 5]">אאא אאא אאא אאא <div><br/></div><div><br/></div><div><br/></div>אאא אאא אאא אאא</div>
     113
     114<div contenteditable dir=rtl id="ml_11" class="test_move_by_word fix_width" title="
     115[ml_11, 25, 5][ml_11, 22, 5][ml_11, 18, 5][ml_11, 14, 5][ml_11, 11, 5][ml_11, 7, 5][ml_11, 4, 5][ml_11, 0, 5][ml_11, 33][ml_11, 29][ml_11, 25][ml_11, 21][ml_11, 17][ml_11, 13][ml_11, 9][ml_11, 4][ml_11, 1]|[ml_11, 1][ml_11, 4][ml_11, 9][ml_11, 13][ml_11, 17][ml_11, 21][ml_11, 25][ml_11, 29][ml_11, 33][ml_11, 0, 5][ml_11, 4, 5][ml_11, 7, 5][ml_11, 11, 5][ml_11, 14, 5][ml_11, 18, 5][ml_11, 22, 5]
     116"> abc def אאא אאא hij אאא אאא uvw xyz <br/><br/><br/>אאא kj אאא mn opq אאא אאא</div>
     117
     118<div contenteditable dir=rtl id="ml_12" class="test_move_by_word fix_width" title="
     119[ml_12, 25, 5][ml_12, 22, 5][ml_12, 18, 5][ml_12, 14, 5][ml_12, 11, 5][ml_12, 7, 5][ml_12, 4, 5][ml_12, 0, 5][ml_12, 36][ml_12, 33][ml_12, 29][ml_12, 25][ml_12, 21][ml_12, 17][ml_12, 13][ml_12, 9][ml_12, 4][ml_12, 1]|[ml_12, 1][ml_12, 4][ml_12, 9][ml_12, 13][ml_12, 17][ml_12, 21][ml_12, 25][ml_12, 29][ml_12, 33][ml_12, 36][ml_12, 0, 5][ml_12, 4, 5][ml_12, 7, 5][ml_12, 11, 5][ml_12, 14, 5][ml_12, 18, 5][ml_12, 22, 5]
     120"> abc def אאא אאא hij אאא אאא uvw xyz <div><br/></div><div><br/></div><div><br/></div>אאא kj אאא mn opq אאא אאא</div>
     121
    91122<!-- mixed editability -->
    92123<div dir=ltr class="test_move_by_word" title="0 4|8 5 1">abc def <span contenteditable> inside span </span> hij opq</div>
    93124
    94 <div dir=ltr contenteditable></div>
     125<div class="test_move_by_word" contenteditable dir=ltr title="0|0"></div>
     126
     127<div contenteditable>
    9512800<base dir=ltr class="test_move_by_word" title="3|3 1">
     129</div>
    96130
    97131</div>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-single-space-sigle-line.html

    r88393 r91788  
    6565
    6666<!-- Inline element -->
    67 <div dir=ltr id="div_1" class="test_move_by_word" title="[div_1, 0][div_1, 3]|[span_1, 2][div_1, 3][div_1,0]" contenteditable>אאא <span id="span_1">בב</span></div>
    68 <div dir=rtl id="div_2" class="test_move_by_word" title="[span_2, 2][div_2, 4][div_2, 0]|[div_2, 0][div_2, 4]" contenteditable>אאא <span id="span_2">בב</span></div>
     67<div dir=ltr id="d_1" class="test_move_by_word" title="[d_1, 0][d_1, 3]|[s_1, 2][d_1, 3][d_1,0]" contenteditable>אאא <span id="s_1">בב</span></div>
     68<div dir=rtl id="d_2" class="test_move_by_word" title="[s_2, 2][d_2, 4][d_2, 0]|[d_2, 0][d_2, 4]" contenteditable>אאא <span id="s_2">בב</span></div>
    6969
    7070<!-- pure English in inline element with same or different directionality from its parent -->
    71 <div dir=ltr id="div_3" class="test_move_by_word" title="[div_3, 0][div_3, 4][div_3, 8][span_3, 4][div_3, 1, 3][div_3, 5, 3]|[div_3, 8, 3][div_3, 5, 3][div_3, 1, 3][span_3, 4][div_3, 8][div_3, 4][div_3, 0]" contenteditable>abc def <span id="span_3">hij opq</span> rst uvw</div>
     71<div dir=ltr id="d_3" class="test_move_by_word" title="[d_3, 0][d_3, 4][d_3, 8][s_3, 4][d_3, 1, 3][d_3, 5, 3]|[d_3, 8, 3][d_3, 5, 3][d_3, 1, 3][s_3, 4][d_3, 8][d_3, 4][d_3, 0]" contenteditable>abc def <span id="s_3">hij opq</span> rst uvw</div>
    7272
    7373<!-- FAILED -->
    74 <div dir=rtl id="div_4" class="test_move_by_word" title="[div_4, 8, 3][div_4, 3, 1][div_4, 7, 1][span_4, 3, 1][span_4, 7, 1][div_4, 4, 3][div_4, 0, 1]|[div_4, 0, 1][div_4, 4, 3][span_4, 7, 1][span_4, 3, 1][div_4, 7, 1][div_4, 3, 1]" contenteditable>abc def <span id="span_4">hij opq</span> rst uvw</div>
     74<div dir=rtl id="d_4" class="test_move_by_word" title="[d_4, 8, 3][d_4, 3, 1][d_4, 7, 1][s_4, 3, 1][s_4, 7, 1][d_4, 4, 3][d_4, 0, 1]|[d_4, 0, 1][d_4, 4, 3][s_4, 7, 1][s_4, 3, 1][d_4, 7, 1][d_4, 3, 1]" contenteditable>abc def <span id="s_4">hij opq</span> rst uvw</div>
    7575
    76 <!-- FAILED. The render result is the same as div_4. -->
    77 <div id="div_5" dir=rtl class="test_move_by_word" title="[div_5, 8, 3][div_5, 3, 1][div_5, 7, 1][span_5, 3, 1][span_5, 7, 1][div_5, 4, 3][div_5, 0, 1]|[div_5, 0, 1][div_5, 4, 3][span_5, 7, 1][span_5, 3, 1][div_5, 7, 1][div_5, 3, 1]"contenteditable>abc def <span dir=ltr id="span_5">hij opq</span> rst uvw</div>
     76<!-- FAILED. The render result is the same as d_4. -->
     77<div id="d_5" dir=rtl class="test_move_by_word" title="[d_5, 8, 3][d_5, 3, 1][d_5, 7, 1][s_5, 3, 1][s_5, 7, 1][d_5, 4, 3][d_5, 0, 1]|[d_5, 0, 1][d_5, 4, 3][s_5, 7, 1][s_5, 3, 1][d_5, 7, 1][d_5, 3, 1]"contenteditable>abc def <span dir=ltr id="s_5">hij opq</span> rst uvw</div>
    7878
    79 <div id="div_6" dir=ltr class="test_move_by_word" title="[div_6, 0, 1][div_6, 4, 1][div_6, 8, 1][span_6, 4, 1][div_6, 1, 3][div_6, 5, 3]|[div_6, 8, 3][div_6, 5, 3][div_6, 1, 3][span_6, 4, 1][div_6, 8, 1][div_6, 4, 1][div_6, 0, 1]" contenteditable>abc def <span dir=rtl id="span_6">hij opq</span> rst uvw</div>
     79<div id="d_6" dir=ltr class="test_move_by_word" title="[d_6, 0, 1][d_6, 4, 1][d_6, 8, 1][s_6, 4, 1][d_6, 1, 3][d_6, 5, 3]|[d_6, 8, 3][d_6, 5, 3][d_6, 1, 3][s_6, 4, 1][d_6, 8, 1][d_6, 4, 1][d_6, 0, 1]" contenteditable>abc def <span dir=rtl id="s_6">hij opq</span> rst uvw</div>
    8080
    8181<!-- pure Hebrew in inline element with same or different directionality from its parent -->
    8282
    83 <div id="div_7" dir=rtl class="test_move_by_word" title="[div_7, 7, 3][div_7, 4, 3][span_7, 4, 1][div_7, 8, 1][div_7, 4, 1][div_7, 0, 1]|[div_7, 0, 1][div_7, 4, 1][div_7, 8, 1][span_7, 4, 1][div_7, 4, 3]" contenteditable>אבד דעפ <span dir=ltr id="span_7">היח ופק</span>ווש כטז</div>
     83<div id="d_7" dir=rtl class="test_move_by_word" title="[d_7, 7, 3][d_7, 4, 3][s_7, 4, 1][d_7, 8, 1][d_7, 4, 1][d_7, 0, 1]|[d_7, 0, 1][d_7, 4, 1][d_7, 8, 1][s_7, 4, 1][d_7, 4, 3]" contenteditable>אבד דעפ <span dir=ltr id="s_7">היח ופק</span>ווש כטז</div>
    8484
    85 <div id="div_8" dir=ltr class="test_move_by_word" title="[div_8, 0, 1][div_8, 3, 3][span_8, 3, 1][div_8, 7, 1][div_8, 3, 1]|[div_8, 7, 3][div_8, 3, 1][div_8, 7, 1][span_8, 3, 1][div_8, 3, 3][div_8, 0, 1]" contenteditable>אבד דעפ <span dir=rtl id="span_8">היח ופק</span>ווש כטז</div>
     85<div id="d_8" dir=ltr class="test_move_by_word" title="[d_8, 0, 1][d_8, 3, 3][s_8, 3, 1][d_8, 7, 1][d_8, 3, 1]|[d_8, 7, 3][d_8, 3, 1][d_8, 7, 1][s_8, 3, 1][d_8, 3, 3][d_8, 0, 1]" contenteditable>אבד דעפ <span dir=rtl id="s_8">היח ופק</span>ווש כטז</div>
    8686
    87 <div id="div_9" dir=rtl class="test_move_by_word" title="[div_9, 7, 3][div_9, 4, 3][span_9, 4, 1][div_9, 8, 1][div_9, 4, 1][div_9, 0, 1]|[div_9, 0, 1][div_9, 4, 1][div_9, 8, 1][span_9, 4, 1][div_9, 4, 3]" contenteditable>אבד דעפ <span id="span_9">היח ופק</span>ווש כטז</div>
     87<div id="d_9" dir=rtl class="test_move_by_word" title="[d_9, 7, 3][d_9, 4, 3][s_9, 4, 1][d_9, 8, 1][d_9, 4, 1][d_9, 0, 1]|[d_9, 0, 1][d_9, 4, 1][d_9, 8, 1][s_9, 4, 1][d_9, 4, 3]" contenteditable>אבד דעפ <span id="s_9">היח ופק</span>ווש כטז</div>
    8888
    89 <div id="div_10" dir=ltr class="test_move_by_word" title="[div_10, 0, 1][div_10, 3, 3][span_10, 3, 1][div_10, 7, 1][div_10, 3, 1]|[div_10, 7, 3][div_10, 3, 1][div_10, 7, 1][span_10, 3, 1][div_10, 3, 3][div_10, 0, 1]" contenteditable>אבד דעפ <span id="span_10">היח ופק</span>ווש כטז</div>
     89<div id="d_10" dir=ltr class="test_move_by_word" title="[d_10, 0, 1][d_10, 3, 3][s_10, 3, 1][d_10, 7, 1][d_10, 3, 1]|[d_10, 7, 3][d_10, 3, 1][d_10, 7, 1][s_10, 3, 1][d_10, 3, 3][d_10, 0, 1]" contenteditable>אבד דעפ <span id="s_10">היח ופק</span>ווש כטז</div>
    9090
    9191<!-- bidi in inline element with same or different directionality from its parent -->
    92 <div id="div_11" dir=rtl class="test_move_by_word" title="[div_11, 7, 3][div_11, 4, 3][span_11, 3, 1][div_11, 8, 1][div_11, 4, 1][div_11, 0, 1]|[div_11, 0, 1][div_11, 4, 1][div_11, 8, 1][span_11, 3, 1][div_11, 4, 3]" contenteditable>אבד דעפ <span dir=ltr id="span_11">abc def</span>ווש כטז</div>
     92<div id="d_11" dir=rtl class="test_move_by_word" title="[d_11, 7, 3][d_11, 4, 3][s_11, 3, 1][d_11, 8, 1][d_11, 4, 1][d_11, 0, 1]|[d_11, 0, 1][d_11, 4, 1][d_11, 8, 1][s_11, 3, 1][d_11, 4, 3]" contenteditable>אבד דעפ <span dir=ltr id="s_11">abc def</span>ווש כטז</div>
    9393
    9494<!-- FAIL -->
    95 <div id="div_12" dir=ltr class="test_move_by_word" title="[div_12, 0, 1][div_12, 3, 3][div_12, 8, 1][span_12, 4, 1][div_12, 7, 1][div_12, 3, 1]|[div_12, 7, 3][div_12, 3, 1][div_12, 7, 1][span_12, 4, 1][div_12, 8, 1][div_12, 3, 3][div_12, 0]" contenteditable>אבד דעפ <span dir=rtl id="span_12">abc def</span>ווש כטז</div>
     95<div id="d_12" dir=ltr class="test_move_by_word" title="[d_12, 0, 1][d_12, 3, 3][d_12, 8, 1][s_12, 4, 1][d_12, 7, 1][d_12, 3, 1]|[d_12, 7, 3][d_12, 3, 1][d_12, 7, 1][s_12, 4, 1][d_12, 8, 1][d_12, 3, 3][d_12, 0]" contenteditable>אבד דעפ <span dir=rtl id="s_12">abc def</span>ווש כטז</div>
    9696
    97 <div id="div_13" dir=rtl class="test_move_by_word" title="[div_13, 7, 3][div_13, 4, 3][span_13, 3, 1][div_13, 8, 1][div_13, 4, 1][div_13, 0, 1]|[div_13, 0, 1][div_13, 4, 1][div_13, 8, 1][span_13, 3, 1][div_13, 4, 3]" contenteditable>אבד דעפ <span id="span_13">abc def</span>ווש כטז</div>
     97<div id="d_13" dir=rtl class="test_move_by_word" title="[d_13, 7, 3][d_13, 4, 3][s_13, 3, 1][d_13, 8, 1][d_13, 4, 1][d_13, 0, 1]|[d_13, 0, 1][d_13, 4, 1][d_13, 8, 1][s_13, 3, 1][d_13, 4, 3]" contenteditable>אבד דעפ <span id="s_13">abc def</span>ווש כטז</div>
    9898
    99 <div id="div_14" dir=ltr class="test_move_by_word" title="[div_14, 0, 1][div_14, 3, 1][div_14, 8, 1][span_14, 4, 1][div_14, 3, 3]|[div_14, 7, 3][div_14, 3, 3][span_14, 4, 1][div_14, 8, 1][div_14, 3, 1][div_14, 0, 1]" contenteditable>אבד דעפ <span id="span_14">abc def</span>ווש כטז</div>
     99<div id="d_14" dir=ltr class="test_move_by_word" title="[d_14, 0, 1][d_14, 3, 1][d_14, 8, 1][s_14, 4, 1][d_14, 3, 3]|[d_14, 7, 3][d_14, 3, 3][s_14, 4, 1][d_14, 8, 1][d_14, 3, 1][d_14, 0, 1]" contenteditable>אבד דעפ <span id="s_14">abc def</span>ווש כטז</div>
    100100
    101101<!-- FAILED -->
    102 <div id="div_15" dir=rtl class="test_move_by_word" title="[div_15, 11, 3][div_15, 8, 3][div_15, 4, 3][span_15, 3, 1][span_15, 4, 1][div_15, 12, 1][div_15, 8, 1][div_15, 4, 1][div_15, 0, 1]|[div_15, 0, 1][div_15, 4, 1][div_15, 8, 1][div_15, 12, 1][span_15, 4, 1][span_15, 3, 1][div_15, 4, 3][div_15, 8, 3]" contenteditable>אבד opq דעפ <span dir=ltr id="span_15">abc אאא def</span>ווש rst כטז</div>
     102<div id="d_15" dir=rtl class="test_move_by_word" title="[d_15, 11, 3][d_15, 8, 3][d_15, 4, 3][s_15, 3, 1][s_15, 4, 1][d_15, 12, 1][d_15, 8, 1][d_15, 4, 1][d_15, 0, 1]|[d_15, 0, 1][d_15, 4, 1][d_15, 8, 1][d_15, 12, 1][s_15, 4, 1][s_15, 3, 1][d_15, 4, 3][d_15, 8, 3]" contenteditable>אבד opq דעפ <span dir=ltr id="s_15">abc אאא def</span>ווש rst כטז</div>
    103103
    104104<!-- FAILED, and wrong printing result -->
    105 <div id="div_16" dir=ltr class="test_move_by_word" title="[div_16, 0, 1][div_16, 4, 1][div_16, 8, 1][span_16, 8, 1][span_16, 7, 1][div_16, 12, 1][div_16, 11, 1][div_16, 4, 3][div_16, 8, 3][div_16, 11, 3]|[div_16, 11, 3][div_16, 8, 3][div_16, 4, 3][div_16, 11, 1][div_16, 12, 1][span_16, 7, 1][span_16, 8, 1][div_16, 8, 1][div_16, 4, 1][div_16, 0, 1]" contenteditable>אבד opq דעפ <span dir=rtl id="span_16">abc אאא def</span>ווש rst כטז</div>
     105<div id="d_16" dir=ltr class="test_move_by_word" title="[d_16, 0, 1][d_16, 4, 1][d_16, 8, 1][s_16, 8, 1][s_16, 7, 1][d_16, 12, 1][d_16, 11, 1][d_16, 4, 3][d_16, 8, 3][d_16, 11, 3]|[d_16, 11, 3][d_16, 8, 3][d_16, 4, 3][d_16, 11, 1][d_16, 12, 1][s_16, 7, 1][s_16, 8, 1][d_16, 8, 1][d_16, 4, 1][d_16, 0, 1]" contenteditable>אבד opq דעפ <span dir=rtl id="s_16">abc אאא def</span>ווש rst כטז</div>
    106106
    107107<!-- FAILED -->
    108 <div id="div_17" dir=rtl class="test_move_by_word" title="[div_17, 11, 3][div_17, 8, 3][div_17, 4, 3][span_17, 8, 1][span_17, 4, 1][div_17, 12, 1][div_17, 8, 1][div_17, 4, 1][div_17, 0, 1]|[div_17, 0, 1][div_17, 4, 1][div_17, 8, 1][div_17, 12, 1][span_17, 4, 1][span_17, 8, 1][div_17, 4, 3][div_17, 8, 3]" contenteditable>אבד opq דעפ <span id="span_17">abc אאא def</span>ווש rst כטז</div>
     108<div id="d_17" dir=rtl class="test_move_by_word" title="[d_17, 11, 3][d_17, 8, 3][d_17, 4, 3][s_17, 8, 1][s_17, 4, 1][d_17, 12, 1][d_17, 8, 1][d_17, 4, 1][d_17, 0, 1]|[d_17, 0, 1][d_17, 4, 1][d_17, 8, 1][d_17, 12, 1][s_17, 4, 1][s_17, 8, 1][d_17, 4, 3][d_17, 8, 3]" contenteditable>אבד opq דעפ <span id="s_17">abc אאא def</span>ווש rst כטז</div>
    109109
    110 <div id="div_18" dir=ltr class="test_move_by_word" title="[div_18, 0, 1][div_18, 4, 1][div_18, 8, 1][div_18, 12, 1][span_18, 4, 1][span_18, 8, 1][div_18, 4, 3][div_18, 8, 3][div_18, 11, 3]|[div_18, 11, 3][div_18, 8, 3][div_18, 4, 3][span_18, 8, 1][span_18, 4, 1][div_18, 12, 1][div_18, 8, 1][div_18, 4, 1][div_18, 0, 1]" contenteditable>אבד opq דעפ <span id="span_18">abc אאא def</span>ווש rst כטז</div>
     110<div id="d_18" dir=ltr class="test_move_by_word" title="[d_18, 0, 1][d_18, 4, 1][d_18, 8, 1][d_18, 12, 1][s_18, 4, 1][s_18, 8, 1][d_18, 4, 3][d_18, 8, 3][d_18, 11, 3]|[d_18, 11, 3][d_18, 8, 3][d_18, 4, 3][s_18, 8, 1][s_18, 4, 1][d_18, 12, 1][d_18, 8, 1][d_18, 4, 1][d_18, 0, 1]" contenteditable>אבד opq דעפ <span id="s_18">abc אאא def</span>ווש rst כטז</div>
    111111
    112 <div id="div_19" dir=ltr class="test_move_by_word" title="[div_19, 0, 1][div_19, 4, 1][span_19, 4, 1][span_19, 7, 1]|[div_19, 3, 3][span_19, 7, 1][span_19, 4, 1][div_19, 4, 1][div_19, 0, 1]" contenteditable>aaa <span id="span_19">bbb אאא </span>ווש</div>
     112<div id="d_19" dir=ltr class="test_move_by_word" title="[d_19, 0, 1][d_19, 4, 1][s_19, 4, 1][s_19, 7, 1]|[d_19, 3, 3][s_19, 7, 1][s_19, 4, 1][d_19, 4, 1][d_19, 0, 1]" contenteditable>aaa <span id="s_19">bbb אאא </span>ווש</div>
    113113
    114 <div id="div_20" dir=rtl class="test_move_by_word" title="[div_20, 15, 3][div_20, 12, 3][div_20, 7, 3][div_20, 4, 3][span_20, 3, 1][span_20, 7, 1][span_20, 8, 1][span_20, 15, 1][div_20, 16, 1][div_20, 12, 1][div_20, 7, 1][div_20, 4, 1][div_20, 0, 1]|[div_20, 0, 1][div_20, 4, 1][div_20, 7, 1][div_20, 12, 1][div_20, 16, 1][span_20, 15, 1][span_20, 8, 1][span_20, 7, 1][span_20, 3, 1][div_20, 4, 3][div_20, 7, 3][div_20, 12, 3]" contenteditable>אבד opq rst דעפ <span dir=ltr id="span_20">abc uvw אאא def lmn</span>אבצ hij xyz וקק</div>
     114<div id="d_20" dir=rtl class="test_move_by_word" title="[d_20, 15, 3][d_20, 12, 3][d_20, 7, 3][d_20, 4, 3][s_20, 3, 1][s_20, 7, 1][s_20, 8, 1][s_20, 15, 1][d_20, 16, 1][d_20, 12, 1][d_20, 7, 1][d_20, 4, 1][d_20, 0, 1]|[d_20, 0, 1][d_20, 4, 1][d_20, 7, 1][d_20, 12, 1][d_20, 16, 1][s_20, 15, 1][s_20, 8, 1][s_20, 7, 1][s_20, 3, 1][d_20, 4, 3][d_20, 7, 3][d_20, 12, 3]" contenteditable>אבד opq rst דעפ <span dir=ltr id="s_20">abc uvw אאא def lmn</span>אבצ hij xyz וקק</div>
    115115
    116116</div>
  • trunk/LayoutTests/editing/selection/resources/move-by-word-visually.js

    r88393 r91788  
    227227
    228228    sel.modify("move", "forward", "lineBoundary");
     229    var position = { node: sel.anchorNode, offset: sel.anchorOffset };
     230
    229231    // Check ctrl-left-arrow works for every position.
    230232    if (dir == "ltr")
     
    233235        direction = "right";   
    234236    moveByWord(sel, test, direction, dir);   
    235     sel.modify("move", "forward", "lineBoundary");
     237
     238    sel.setPosition(position.node, position.offset);
    236239    moveByWordOnEveryChar(sel, test, direction, dir);
     240}
     241
     242function setWidth(test)
     243{
     244    if (test.className.search("fix_width") != -1) {
     245        var span = document.getElementById("span_size");
     246        var length = span.offsetWidth;
     247        test.style.width = length + "px";
     248    }
    237249}
    238250
     
    243255        var positionsMovingRight;
    244256        var positionsMovingLeft;
     257
     258        setWidth(tests[i]);
    245259
    246260        if (tests[i].getAttribute("dir") == 'ltr')
  • trunk/Source/WebCore/ChangeLog

    r91781 r91788  
     12011-07-26  Xiaomei Ji  <xji@chromium.org>
     2
     3        --webkit-visual-word does not work in multi-line
     4        https://bugs.webkit.org/show_bug.cgi?id=61344
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Replace Position(node, offset, PositionIsOffsetInAnchor) with
     9        createPositionAvoidingIgnoredNode(node, offset) which takes care of creating position
     10        before/after <br/> etc. editingIgnoresContent node.
     11
     12        When iterate InlineBox, replace prevLeafChild and nextLeafChild (which only returns
     13        InlineBox within the same line) with leftInlineBox and rightInlineBox (which returns
     14        InlineBox across multiple lines).
     15
     16        * editing/htmlediting.cpp:
     17        (WebCore::createPositionAvoidingIgnoredNode):
     18        * editing/htmlediting.h:
     19        * editing/visible_units.cpp:
     20        (WebCore::previousWordBreakInBoxInsideBlockWithSameDirectionality): Replace Position() with
     21        createPositionAvoidingIgnoredNode().
     22        (WebCore::leftmostPositionInRTLBoxInLTRBlock): Ditto.
     23        (WebCore::rightmostPositionInLTRBoxInRTLBlock): Ditto.
     24        (WebCore::nextWordBreakInBoxInsideBlockWithDifferentDirectionality): Ditto.
     25        (WebCore::blockWithPreviousLineBox): Added.
     26        (WebCore::previousRootInlineBox): Added.
     27        (WebCore::blockWithNextLineBox): Added.
     28        (WebCore::nextRootInlineBox): Added.
     29        (WebCore::leftInlineBox): Added.
     30        (WebCore::rightInlineBox): Added.
     31        (WebCore::leftWordBoundary): Replace prevLeafChild/nextLeafChild with leftInlineBox()
     32        and rightInlineBox().
     33        (WebCore::rightWordBoundary): Ditto.
     34        (WebCore::leftWordPositionAcrossBoundary): Ditto.
     35        (WebCore::rightWordPositionAcrossBoundary): Ditto.
     36
    1372011-07-26  David Hyatt  <hyatt@apple.com>
    238
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r90885 r91788  
    11381138}
    11391139
     1140Position createPositionAvoidingIgnoredNode(Node* node, int offset)
     1141{
     1142    if (!node)
     1143        return Position();
     1144    if (!node->isTextNode()) {
     1145        // FIXME: the pass-in offset is the caretMinOffset() or caretMaxOffset() of box.
     1146        // caretMaxOffset could be 1 for replacedElement, br, and hr.
     1147        // We should get rid of this offset checking code after we get rid of legacy editing
     1148        // position in rendering code.
     1149        if (!offset)
     1150            return positionBeforeNode(node);
     1151        ASSERT(offset == 1);
     1152        return positionAfterNode(node);
     1153    }
     1154    return Position(static_cast<Text*>(node), offset);
     1155}
     1156
    11401157} // namespace WebCore
  • trunk/Source/WebCore/editing/htmlediting.h

    r90885 r91788  
    142142}
    143143
     144Position createPositionAvoidingIgnoredNode(Node*, int offset);
     145
    144146// comparision functions on Position
    145147   
  • trunk/Source/WebCore/editing/visible_units.cpp

    r91395 r91788  
    11991199        wordBreak = previousWordBreak;
    12001200    else {
    1201         wordBreak = Position(box->renderer()->node(), box->caretMaxOffset(), Position::PositionIsOffsetInAnchor);
     1201        wordBreak = createPositionAvoidingIgnoredNode(box->renderer()->node(), box->caretMaxOffset());
     1202
    12021203        // Return the rightmost word boundary of LTR box or leftmost word boundary of RTL box if
    12031204        // it is not in the previously visited boxes. For example, given a logical text
     
    12111212        if ((box->isLeftToRightDirection() && box->nextLeafChild())
    12121213            || (!box->isLeftToRightDirection() && box->prevLeafChild())) {
    1213    
     1214
    12141215            VisiblePosition positionAfterWord = nextBoundary(wordBreak, nextWordPositionBoundary);
    12151216            if (positionAfterWord.isNotNull()) {
     
    12371238   
    12381239    if (previousLeaf && !previousLeaf->isLeftToRightDirection())
    1239         return Position(node, box->caretMaxOffset(), Position::PositionIsOffsetInAnchor);
     1240        return createPositionAvoidingIgnoredNode(node, box->caretMaxOffset());
    12401241
    12411242    if (nextLeaf && !nextLeaf->isLeftToRightDirection()) {
    12421243        if (previousLeaf)
    1243             return Position(previousLeaf->renderer()->node(), previousLeaf->caretMaxOffset(), Position::PositionIsOffsetInAnchor);
     1244            return createPositionAvoidingIgnoredNode(previousLeaf->renderer()->node(), previousLeaf->caretMaxOffset());
    12441245
    12451246        InlineBox* lastRTLLeaf;
     
    12481249            nextLeaf = nextLeaf->nextLeafChild();
    12491250        } while (nextLeaf && !nextLeaf->isLeftToRightDirection());
    1250         return Position(lastRTLLeaf->renderer()->node(), lastRTLLeaf->caretMinOffset(), Position::PositionIsOffsetInAnchor);
    1251     }
    1252 
    1253     return Position(node, box->caretMinOffset(), Position::PositionIsOffsetInAnchor);
     1251        return createPositionAvoidingIgnoredNode(lastRTLLeaf->renderer()->node(), lastRTLLeaf->caretMinOffset());
     1252    }
     1253
     1254    return createPositionAvoidingIgnoredNode(node, box->caretMinOffset());
    12541255}
    12551256
     
    12621263   
    12631264    if (nextLeaf && nextLeaf->isLeftToRightDirection())   
    1264         return Position(node, box->caretMaxOffset(), Position::PositionIsOffsetInAnchor);
     1265        return createPositionAvoidingIgnoredNode(node, box->caretMaxOffset());
    12651266
    12661267    if (previousLeaf && previousLeaf->isLeftToRightDirection()) {
    12671268        if (nextLeaf)
    1268             return Position(nextLeaf->renderer()->node(), nextLeaf->caretMaxOffset(), Position::PositionIsOffsetInAnchor);
     1269            return createPositionAvoidingIgnoredNode(nextLeaf->renderer()->node(), nextLeaf->caretMaxOffset());
    12691270
    12701271        InlineBox* firstLTRLeaf;
     
    12731274            previousLeaf = previousLeaf->prevLeafChild();
    12741275        } while (previousLeaf && previousLeaf->isLeftToRightDirection());
    1275         return Position(firstLTRLeaf->renderer()->node(), firstLTRLeaf->caretMinOffset(), Position::PositionIsOffsetInAnchor);
    1276     }
    1277 
    1278     return Position(node, box->caretMinOffset(), Position::PositionIsOffsetInAnchor);
     1276        return createPositionAvoidingIgnoredNode(firstLTRLeaf->renderer()->node(), firstLTRLeaf->caretMinOffset());
     1277    }
     1278
     1279    return createPositionAvoidingIgnoredNode(node, box->caretMinOffset());
    12791280}
    12801281   
     
    13211322   
    13221323    bool hasSeenWordBreakInThisBox = previousWordBreak.isNotNull();
    1323     VisiblePosition wordBreak = hasSeenWordBreakInThisBox ? previousWordBreak : Position(box->renderer()->node(), box->caretMinOffset(), Position::PositionIsOffsetInAnchor);
     1324    VisiblePosition wordBreak = hasSeenWordBreakInThisBox ? previousWordBreak :
     1325        createPositionAvoidingIgnoredNode(box->renderer()->node(), box->caretMinOffset());
     1326
    13241327    wordBreak = nextBoundary(wordBreak, nextWordPositionBoundary);
    13251328 
     
    14761479}
    14771480
     1481static const RenderBlock* blockWithPreviousLineBox(const RenderBlock* startingBlock)
     1482{
     1483    for (const RenderBlock* block = startingBlock; block; block = toRenderBlock(block->previousSibling())) {
     1484        if (block->childrenInline()) {
     1485            if (block->firstRootBox())
     1486                return block;
     1487        } else if (const RenderBlock* renderBlock = blockWithPreviousLineBox(toRenderBlock(block->lastChild())))
     1488            return renderBlock;
     1489    }
     1490    return 0;
     1491}
     1492
     1493static const RootInlineBox* previousRootInlineBox(const InlineBox* box)
     1494{
     1495    Node* node = box->renderer()->node();
     1496
     1497    for (RenderObject* renderer = node->renderer(); renderer; renderer = renderer->parent()) {
     1498        if (renderer->isRenderBlock()) {
     1499            if (const RenderBlock* blockWithLineBoxes = blockWithPreviousLineBox(toRenderBlock(renderer->previousSibling())))
     1500                return blockWithLineBoxes->lastRootBox();
     1501        }
     1502    }
     1503
     1504    return 0;
     1505}
     1506
     1507static const RenderBlock* blockWithNextLineBox(const RenderBlock* startingBlock)
     1508{
     1509    for (const RenderBlock* block = startingBlock; block; block = toRenderBlock(block->nextSibling())) {
     1510        if (block->childrenInline()) {
     1511            if (block->firstRootBox())
     1512                return block;
     1513        } else if (const RenderBlock* renderBlock = blockWithNextLineBox(toRenderBlock(block->firstChild())))
     1514            return renderBlock;
     1515    }
     1516    return 0;
     1517}
     1518
     1519static const RootInlineBox* nextRootInlineBox(const InlineBox* box)
     1520{
     1521    Node* node = box->renderer()->node();
     1522
     1523    for (RenderObject* renderer = node->renderer(); renderer; renderer = renderer->parent()) {
     1524        if (renderer->isRenderBlock()) {
     1525            if (const RenderBlock* blockWithLineBoxes = blockWithNextLineBox(toRenderBlock(renderer->nextSibling())))
     1526                return blockWithLineBoxes->firstRootBox();
     1527        }
     1528    }
     1529
     1530    return 0;
     1531}
     1532
     1533static const InlineBox* leftInlineBox(const InlineBox* box, TextDirection blockDirection)
     1534{
     1535    if (box->prevLeafChild())
     1536        return box->prevLeafChild();
     1537   
     1538    const RootInlineBox* rootBox = box->root();
     1539    const bool isBlockLTR = blockDirection == LTR;
     1540    const InlineFlowBox* leftLineBox = isBlockLTR ? rootBox->prevLineBox() : rootBox->nextLineBox();
     1541    if (leftLineBox)
     1542        return leftLineBox->lastLeafChild();
     1543
     1544    const RootInlineBox* leftRootInlineBox = isBlockLTR ? previousRootInlineBox(box) : nextRootInlineBox(box);
     1545    return leftRootInlineBox ? leftRootInlineBox->lastLeafChild() : 0;
     1546}
     1547
     1548static const InlineBox* rightInlineBox(const InlineBox* box, TextDirection blockDirection)
     1549{
     1550    if (box->nextLeafChild())
     1551        return box->nextLeafChild();
     1552   
     1553    const RootInlineBox* rootBox = box->root();
     1554    const bool isBlockLTR = blockDirection == LTR;
     1555    const InlineFlowBox* rightLineBox = isBlockLTR ? rootBox->nextLineBox() : rootBox->prevLineBox();
     1556    if (rightLineBox)
     1557        return rightLineBox->firstLeafChild();
     1558
     1559    const RootInlineBox* rightRootInlineBox = isBlockLTR ? nextRootInlineBox(box) : previousRootInlineBox(box);
     1560    return rightRootInlineBox ? rightRootInlineBox->firstLeafChild() : 0;
     1561}
     1562
    14781563static VisiblePosition leftWordBoundary(const InlineBox* box, int offset, TextDirection blockDirection)
    14791564{
    14801565    VisiblePosition wordBreak;
    1481     for  (const InlineBox* adjacentBox = box; adjacentBox; adjacentBox = adjacentBox->prevLeafChild()) {
     1566    for  (const InlineBox* adjacentBox = box; adjacentBox; adjacentBox = leftInlineBox(adjacentBox, blockDirection)) {
    14821567        if (blockDirection == LTR) {
    14831568            if (adjacentBox->isLeftToRightDirection())
     
    14971582   
    14981583    VisiblePosition wordBreak;
    1499     for (const InlineBox* adjacentBox = box; adjacentBox; adjacentBox = adjacentBox->nextLeafChild()) {
     1584    for (const InlineBox* adjacentBox = box; adjacentBox; adjacentBox = rightInlineBox(adjacentBox, blockDirection)) {
    15001585        if (blockDirection == RTL) {
    15011586            if (adjacentBox->isLeftToRightDirection())
     
    15281613
    15291614    TextDirection blockDirection = directionOfEnclosingBlock(visiblePosition.deepEquivalent());
    1530    
     1615
    15311616    // FIXME: If the box's directionality is the same as that of the enclosing block, when the offset is at the box boundary
    15321617    // and the direction is towards inside the box, do I still need to make it a special case? For example, a LTR box inside a LTR block,
    15331618    // when offset is at box's caretMinOffset and the direction is DirectionRight, should it be taken care as a general case?
    15341619    if (offset == box->caretLeftmostOffset())
    1535         return leftWordBoundary(box->prevLeafChild(), invalidOffset, blockDirection);
     1620        return leftWordBoundary(leftInlineBox(box, blockDirection), invalidOffset, blockDirection);
    15361621    if (offset == box->caretRightmostOffset())
    15371622        return leftWordBoundary(box, offset, blockDirection);
     
    15561641        return orderedWordBoundaries[index].visiblePosition;
    15571642   
    1558     return leftWordBoundary(box->prevLeafChild(), invalidOffset, blockDirection);
     1643    return leftWordBoundary(leftInlineBox(box, blockDirection), invalidOffset, blockDirection);
    15591644}
    15601645
     
    15731658        return rightWordBoundary(box, offset, blockDirection);
    15741659    if (offset == box->caretRightmostOffset())
    1575         return rightWordBoundary(box->nextLeafChild(), invalidOffset, blockDirection);
     1660        return rightWordBoundary(rightInlineBox(box, blockDirection), invalidOffset, blockDirection);
    15761661 
    15771662    VisiblePosition wordBreak;
     
    15931678        return orderedWordBoundaries[index].visiblePosition;
    15941679   
    1595     return rightWordBoundary(box->nextLeafChild(), invalidOffset, blockDirection);
     1680    return rightWordBoundary(rightInlineBox(box, blockDirection), invalidOffset, blockDirection);
    15961681}
    15971682
Note: See TracChangeset for help on using the changeset viewer.