OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. | 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 Position downstreamStart = p.downstream(); | 128 Position downstreamStart = p.downstream(); |
129 TextDirection primaryDirection = p.primaryDirection(); | 129 TextDirection primaryDirection = p.primaryDirection(); |
130 | 130 |
131 while (true) { | 131 while (true) { |
132 InlineBox* box; | 132 InlineBox* box; |
133 int offset; | 133 int offset; |
134 p.getInlineBoxAndOffset(m_affinity, primaryDirection, box, offset); | 134 p.getInlineBoxAndOffset(m_affinity, primaryDirection, box, offset); |
135 if (!box) | 135 if (!box) |
136 return primaryDirection == LTR ? previousVisuallyDistinctCandidate(m
_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition); | 136 return primaryDirection == LTR ? previousVisuallyDistinctCandidate(m
_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition); |
137 | 137 |
138 RenderObject* renderer = box->renderer(); | 138 RenderObject* renderer = &box->renderer(); |
139 | 139 |
140 while (true) { | 140 while (true) { |
141 if ((renderer->isReplaced() || renderer->isBR()) && offset == box->c
aretRightmostOffset()) | 141 if ((renderer->isReplaced() || renderer->isBR()) && offset == box->c
aretRightmostOffset()) |
142 return box->isLeftToRightDirection() ? previousVisuallyDistinctC
andidate(m_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition); | 142 return box->isLeftToRightDirection() ? previousVisuallyDistinctC
andidate(m_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition); |
143 | 143 |
144 if (!renderer->node()) { | 144 if (!renderer->node()) { |
145 box = box->prevLeafChild(); | 145 box = box->prevLeafChild(); |
146 if (!box) | 146 if (!box) |
147 return primaryDirection == LTR ? previousVisuallyDistinctCan
didate(m_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition); | 147 return primaryDirection == LTR ? previousVisuallyDistinctCan
didate(m_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition); |
148 renderer = box->renderer(); | 148 renderer = &box->renderer(); |
149 offset = box->caretRightmostOffset(); | 149 offset = box->caretRightmostOffset(); |
150 continue; | 150 continue; |
151 } | 151 } |
152 | 152 |
153 offset = box->isLeftToRightDirection() ? renderer->previousOffset(of
fset) : renderer->nextOffset(offset); | 153 offset = box->isLeftToRightDirection() ? renderer->previousOffset(of
fset) : renderer->nextOffset(offset); |
154 | 154 |
155 int caretMinOffset = box->caretMinOffset(); | 155 int caretMinOffset = box->caretMinOffset(); |
156 int caretMaxOffset = box->caretMaxOffset(); | 156 int caretMaxOffset = box->caretMaxOffset(); |
157 | 157 |
158 if (offset > caretMinOffset && offset < caretMaxOffset) | 158 if (offset > caretMinOffset && offset < caretMaxOffset) |
(...skipping 10 matching lines...) Expand all Loading... |
169 InlineBox* boxOnLeft; | 169 InlineBox* boxOnLeft; |
170 int offsetOnLeft; | 170 int offsetOnLeft; |
171 positionOnLeft.getInlineBoxAndOffset(m_affinity, primaryDire
ction, boxOnLeft, offsetOnLeft); | 171 positionOnLeft.getInlineBoxAndOffset(m_affinity, primaryDire
ction, boxOnLeft, offsetOnLeft); |
172 if (boxOnLeft && boxOnLeft->root() == box->root()) | 172 if (boxOnLeft && boxOnLeft->root() == box->root()) |
173 return Position(); | 173 return Position(); |
174 return positionOnLeft; | 174 return positionOnLeft; |
175 } | 175 } |
176 | 176 |
177 // Reposition at the other logical position corresponding to our
edge's visual position and go for another round. | 177 // Reposition at the other logical position corresponding to our
edge's visual position and go for another round. |
178 box = prevBox; | 178 box = prevBox; |
179 renderer = box->renderer(); | 179 renderer = &box->renderer(); |
180 offset = prevBox->caretRightmostOffset(); | 180 offset = prevBox->caretRightmostOffset(); |
181 continue; | 181 continue; |
182 } | 182 } |
183 | 183 |
184 ASSERT(offset == box->caretLeftmostOffset()); | 184 ASSERT(offset == box->caretLeftmostOffset()); |
185 | 185 |
186 unsigned char level = box->bidiLevel(); | 186 unsigned char level = box->bidiLevel(); |
187 InlineBox* prevBox = box->prevLeafChild(); | 187 InlineBox* prevBox = box->prevLeafChild(); |
188 | 188 |
189 if (box->direction() == primaryDirection) { | 189 if (box->direction() == primaryDirection) { |
190 if (!prevBox) { | 190 if (!prevBox) { |
191 InlineBox* logicalStart = 0; | 191 InlineBox* logicalStart = 0; |
192 if (primaryDirection == LTR ? box->root()->getLogicalStartBo
xWithNode(logicalStart) : box->root()->getLogicalEndBoxWithNode(logicalStart)) { | 192 if (primaryDirection == LTR ? box->root()->getLogicalStartBo
xWithNode(logicalStart) : box->root()->getLogicalEndBoxWithNode(logicalStart)) { |
193 box = logicalStart; | 193 box = logicalStart; |
194 renderer = box->renderer(); | 194 renderer = &box->renderer(); |
195 offset = primaryDirection == LTR ? box->caretMinOffset()
: box->caretMaxOffset(); | 195 offset = primaryDirection == LTR ? box->caretMinOffset()
: box->caretMaxOffset(); |
196 } | 196 } |
197 break; | 197 break; |
198 } | 198 } |
199 if (prevBox->bidiLevel() >= level) | 199 if (prevBox->bidiLevel() >= level) |
200 break; | 200 break; |
201 | 201 |
202 level = prevBox->bidiLevel(); | 202 level = prevBox->bidiLevel(); |
203 | 203 |
204 InlineBox* nextBox = box; | 204 InlineBox* nextBox = box; |
205 do { | 205 do { |
206 nextBox = nextBox->nextLeafChild(); | 206 nextBox = nextBox->nextLeafChild(); |
207 } while (nextBox && nextBox->bidiLevel() > level); | 207 } while (nextBox && nextBox->bidiLevel() > level); |
208 | 208 |
209 if (nextBox && nextBox->bidiLevel() == level) | 209 if (nextBox && nextBox->bidiLevel() == level) |
210 break; | 210 break; |
211 | 211 |
212 box = prevBox; | 212 box = prevBox; |
213 renderer = box->renderer(); | 213 renderer = &box->renderer(); |
214 offset = box->caretRightmostOffset(); | 214 offset = box->caretRightmostOffset(); |
215 if (box->direction() == primaryDirection) | 215 if (box->direction() == primaryDirection) |
216 break; | 216 break; |
217 continue; | 217 continue; |
218 } | 218 } |
219 | 219 |
220 while (prevBox && !prevBox->renderer()->node()) | 220 while (prevBox && !prevBox->renderer().node()) |
221 prevBox = prevBox->prevLeafChild(); | 221 prevBox = prevBox->prevLeafChild(); |
222 | 222 |
223 if (prevBox) { | 223 if (prevBox) { |
224 box = prevBox; | 224 box = prevBox; |
225 renderer = box->renderer(); | 225 renderer = &box->renderer(); |
226 offset = box->caretRightmostOffset(); | 226 offset = box->caretRightmostOffset(); |
227 if (box->bidiLevel() > level) { | 227 if (box->bidiLevel() > level) { |
228 do { | 228 do { |
229 prevBox = prevBox->prevLeafChild(); | 229 prevBox = prevBox->prevLeafChild(); |
230 } while (prevBox && prevBox->bidiLevel() > level); | 230 } while (prevBox && prevBox->bidiLevel() > level); |
231 | 231 |
232 if (!prevBox || prevBox->bidiLevel() < level) | 232 if (!prevBox || prevBox->bidiLevel() < level) |
233 continue; | 233 continue; |
234 } | 234 } |
235 } else { | 235 } else { |
236 // Trailing edge of a secondary run. Set to the leading edge of
the entire run. | 236 // Trailing edge of a secondary run. Set to the leading edge of
the entire run. |
237 while (true) { | 237 while (true) { |
238 while (InlineBox* nextBox = box->nextLeafChild()) { | 238 while (InlineBox* nextBox = box->nextLeafChild()) { |
239 if (nextBox->bidiLevel() < level) | 239 if (nextBox->bidiLevel() < level) |
240 break; | 240 break; |
241 box = nextBox; | 241 box = nextBox; |
242 } | 242 } |
243 if (box->bidiLevel() == level) | 243 if (box->bidiLevel() == level) |
244 break; | 244 break; |
245 level = box->bidiLevel(); | 245 level = box->bidiLevel(); |
246 while (InlineBox* prevBox = box->prevLeafChild()) { | 246 while (InlineBox* prevBox = box->prevLeafChild()) { |
247 if (prevBox->bidiLevel() < level) | 247 if (prevBox->bidiLevel() < level) |
248 break; | 248 break; |
249 box = prevBox; | 249 box = prevBox; |
250 } | 250 } |
251 if (box->bidiLevel() == level) | 251 if (box->bidiLevel() == level) |
252 break; | 252 break; |
253 level = box->bidiLevel(); | 253 level = box->bidiLevel(); |
254 } | 254 } |
255 renderer = box->renderer(); | 255 renderer = &box->renderer(); |
256 offset = primaryDirection == LTR ? box->caretMinOffset() : box->
caretMaxOffset(); | 256 offset = primaryDirection == LTR ? box->caretMinOffset() : box->
caretMaxOffset(); |
257 } | 257 } |
258 break; | 258 break; |
259 } | 259 } |
260 | 260 |
261 p = createLegacyEditingPosition(renderer->node(), offset); | 261 p = createLegacyEditingPosition(renderer->node(), offset); |
262 | 262 |
263 if ((p.isCandidate() && p.downstream() != downstreamStart) || p.atStartO
fTree() || p.atEndOfTree()) | 263 if ((p.isCandidate() && p.downstream() != downstreamStart) || p.atStartO
fTree() || p.atEndOfTree()) |
264 return p; | 264 return p; |
265 | 265 |
(...skipping 27 matching lines...) Expand all Loading... |
293 Position downstreamStart = p.downstream(); | 293 Position downstreamStart = p.downstream(); |
294 TextDirection primaryDirection = p.primaryDirection(); | 294 TextDirection primaryDirection = p.primaryDirection(); |
295 | 295 |
296 while (true) { | 296 while (true) { |
297 InlineBox* box; | 297 InlineBox* box; |
298 int offset; | 298 int offset; |
299 p.getInlineBoxAndOffset(m_affinity, primaryDirection, box, offset); | 299 p.getInlineBoxAndOffset(m_affinity, primaryDirection, box, offset); |
300 if (!box) | 300 if (!box) |
301 return primaryDirection == LTR ? nextVisuallyDistinctCandidate(m_dee
pPosition) : previousVisuallyDistinctCandidate(m_deepPosition); | 301 return primaryDirection == LTR ? nextVisuallyDistinctCandidate(m_dee
pPosition) : previousVisuallyDistinctCandidate(m_deepPosition); |
302 | 302 |
303 RenderObject* renderer = box->renderer(); | 303 RenderObject* renderer = &box->renderer(); |
304 | 304 |
305 while (true) { | 305 while (true) { |
306 if ((renderer->isReplaced() || renderer->isBR()) && offset == box->c
aretLeftmostOffset()) | 306 if ((renderer->isReplaced() || renderer->isBR()) && offset == box->c
aretLeftmostOffset()) |
307 return box->isLeftToRightDirection() ? nextVisuallyDistinctCandi
date(m_deepPosition) : previousVisuallyDistinctCandidate(m_deepPosition); | 307 return box->isLeftToRightDirection() ? nextVisuallyDistinctCandi
date(m_deepPosition) : previousVisuallyDistinctCandidate(m_deepPosition); |
308 | 308 |
309 if (!renderer->node()) { | 309 if (!renderer->node()) { |
310 box = box->nextLeafChild(); | 310 box = box->nextLeafChild(); |
311 if (!box) | 311 if (!box) |
312 return primaryDirection == LTR ? nextVisuallyDistinctCandida
te(m_deepPosition) : previousVisuallyDistinctCandidate(m_deepPosition); | 312 return primaryDirection == LTR ? nextVisuallyDistinctCandida
te(m_deepPosition) : previousVisuallyDistinctCandidate(m_deepPosition); |
313 renderer = box->renderer(); | 313 renderer = &box->renderer(); |
314 offset = box->caretLeftmostOffset(); | 314 offset = box->caretLeftmostOffset(); |
315 continue; | 315 continue; |
316 } | 316 } |
317 | 317 |
318 offset = box->isLeftToRightDirection() ? renderer->nextOffset(offset
) : renderer->previousOffset(offset); | 318 offset = box->isLeftToRightDirection() ? renderer->nextOffset(offset
) : renderer->previousOffset(offset); |
319 | 319 |
320 int caretMinOffset = box->caretMinOffset(); | 320 int caretMinOffset = box->caretMinOffset(); |
321 int caretMaxOffset = box->caretMaxOffset(); | 321 int caretMaxOffset = box->caretMaxOffset(); |
322 | 322 |
323 if (offset > caretMinOffset && offset < caretMaxOffset) | 323 if (offset > caretMinOffset && offset < caretMaxOffset) |
(...skipping 10 matching lines...) Expand all Loading... |
334 InlineBox* boxOnRight; | 334 InlineBox* boxOnRight; |
335 int offsetOnRight; | 335 int offsetOnRight; |
336 positionOnRight.getInlineBoxAndOffset(m_affinity, primaryDir
ection, boxOnRight, offsetOnRight); | 336 positionOnRight.getInlineBoxAndOffset(m_affinity, primaryDir
ection, boxOnRight, offsetOnRight); |
337 if (boxOnRight && boxOnRight->root() == box->root()) | 337 if (boxOnRight && boxOnRight->root() == box->root()) |
338 return Position(); | 338 return Position(); |
339 return positionOnRight; | 339 return positionOnRight; |
340 } | 340 } |
341 | 341 |
342 // Reposition at the other logical position corresponding to our
edge's visual position and go for another round. | 342 // Reposition at the other logical position corresponding to our
edge's visual position and go for another round. |
343 box = nextBox; | 343 box = nextBox; |
344 renderer = box->renderer(); | 344 renderer = &box->renderer(); |
345 offset = nextBox->caretLeftmostOffset(); | 345 offset = nextBox->caretLeftmostOffset(); |
346 continue; | 346 continue; |
347 } | 347 } |
348 | 348 |
349 ASSERT(offset == box->caretRightmostOffset()); | 349 ASSERT(offset == box->caretRightmostOffset()); |
350 | 350 |
351 unsigned char level = box->bidiLevel(); | 351 unsigned char level = box->bidiLevel(); |
352 InlineBox* nextBox = box->nextLeafChild(); | 352 InlineBox* nextBox = box->nextLeafChild(); |
353 | 353 |
354 if (box->direction() == primaryDirection) { | 354 if (box->direction() == primaryDirection) { |
355 if (!nextBox) { | 355 if (!nextBox) { |
356 InlineBox* logicalEnd = 0; | 356 InlineBox* logicalEnd = 0; |
357 if (primaryDirection == LTR ? box->root()->getLogicalEndBoxW
ithNode(logicalEnd) : box->root()->getLogicalStartBoxWithNode(logicalEnd)) { | 357 if (primaryDirection == LTR ? box->root()->getLogicalEndBoxW
ithNode(logicalEnd) : box->root()->getLogicalStartBoxWithNode(logicalEnd)) { |
358 box = logicalEnd; | 358 box = logicalEnd; |
359 renderer = box->renderer(); | 359 renderer = &box->renderer(); |
360 offset = primaryDirection == LTR ? box->caretMaxOffset()
: box->caretMinOffset(); | 360 offset = primaryDirection == LTR ? box->caretMaxOffset()
: box->caretMinOffset(); |
361 } | 361 } |
362 break; | 362 break; |
363 } | 363 } |
364 | 364 |
365 if (nextBox->bidiLevel() >= level) | 365 if (nextBox->bidiLevel() >= level) |
366 break; | 366 break; |
367 | 367 |
368 level = nextBox->bidiLevel(); | 368 level = nextBox->bidiLevel(); |
369 | 369 |
370 InlineBox* prevBox = box; | 370 InlineBox* prevBox = box; |
371 do { | 371 do { |
372 prevBox = prevBox->prevLeafChild(); | 372 prevBox = prevBox->prevLeafChild(); |
373 } while (prevBox && prevBox->bidiLevel() > level); | 373 } while (prevBox && prevBox->bidiLevel() > level); |
374 | 374 |
375 if (prevBox && prevBox->bidiLevel() == level) // For example,
abc FED 123 ^ CBA | 375 if (prevBox && prevBox->bidiLevel() == level) // For example,
abc FED 123 ^ CBA |
376 break; | 376 break; |
377 | 377 |
378 // For example, abc 123 ^ CBA or 123 ^ CBA abc | 378 // For example, abc 123 ^ CBA or 123 ^ CBA abc |
379 box = nextBox; | 379 box = nextBox; |
380 renderer = box->renderer(); | 380 renderer = &box->renderer(); |
381 offset = box->caretLeftmostOffset(); | 381 offset = box->caretLeftmostOffset(); |
382 if (box->direction() == primaryDirection) | 382 if (box->direction() == primaryDirection) |
383 break; | 383 break; |
384 continue; | 384 continue; |
385 } | 385 } |
386 | 386 |
387 while (nextBox && !nextBox->renderer()->node()) | 387 while (nextBox && !nextBox->renderer().node()) |
388 nextBox = nextBox->nextLeafChild(); | 388 nextBox = nextBox->nextLeafChild(); |
389 | 389 |
390 if (nextBox) { | 390 if (nextBox) { |
391 box = nextBox; | 391 box = nextBox; |
392 renderer = box->renderer(); | 392 renderer = &box->renderer(); |
393 offset = box->caretLeftmostOffset(); | 393 offset = box->caretLeftmostOffset(); |
394 | 394 |
395 if (box->bidiLevel() > level) { | 395 if (box->bidiLevel() > level) { |
396 do { | 396 do { |
397 nextBox = nextBox->nextLeafChild(); | 397 nextBox = nextBox->nextLeafChild(); |
398 } while (nextBox && nextBox->bidiLevel() > level); | 398 } while (nextBox && nextBox->bidiLevel() > level); |
399 | 399 |
400 if (!nextBox || nextBox->bidiLevel() < level) | 400 if (!nextBox || nextBox->bidiLevel() < level) |
401 continue; | 401 continue; |
402 } | 402 } |
(...skipping 10 matching lines...) Expand all Loading... |
413 level = box->bidiLevel(); | 413 level = box->bidiLevel(); |
414 while (InlineBox* nextBox = box->nextLeafChild()) { | 414 while (InlineBox* nextBox = box->nextLeafChild()) { |
415 if (nextBox->bidiLevel() < level) | 415 if (nextBox->bidiLevel() < level) |
416 break; | 416 break; |
417 box = nextBox; | 417 box = nextBox; |
418 } | 418 } |
419 if (box->bidiLevel() == level) | 419 if (box->bidiLevel() == level) |
420 break; | 420 break; |
421 level = box->bidiLevel(); | 421 level = box->bidiLevel(); |
422 } | 422 } |
423 renderer = box->renderer(); | 423 renderer = &box->renderer(); |
424 offset = primaryDirection == LTR ? box->caretMaxOffset() : box->
caretMinOffset(); | 424 offset = primaryDirection == LTR ? box->caretMaxOffset() : box->
caretMinOffset(); |
425 } | 425 } |
426 break; | 426 break; |
427 } | 427 } |
428 | 428 |
429 p = createLegacyEditingPosition(renderer->node(), offset); | 429 p = createLegacyEditingPosition(renderer->node(), offset); |
430 | 430 |
431 if ((p.isCandidate() && p.downstream() != downstreamStart) || p.atStartO
fTree() || p.atEndOfTree()) | 431 if ((p.isCandidate() && p.downstream() != downstreamStart) || p.atStartO
fTree() || p.atEndOfTree()) |
432 return p; | 432 return p; |
433 | 433 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 | 657 |
658 renderer = node->renderer(); | 658 renderer = node->renderer(); |
659 if (!renderer) | 659 if (!renderer) |
660 return LayoutRect(); | 660 return LayoutRect(); |
661 | 661 |
662 InlineBox* inlineBox; | 662 InlineBox* inlineBox; |
663 int caretOffset; | 663 int caretOffset; |
664 getInlineBoxAndOffset(inlineBox, caretOffset); | 664 getInlineBoxAndOffset(inlineBox, caretOffset); |
665 | 665 |
666 if (inlineBox) | 666 if (inlineBox) |
667 renderer = inlineBox->renderer(); | 667 renderer = &inlineBox->renderer(); |
668 | 668 |
669 return renderer->localCaretRect(inlineBox, caretOffset); | 669 return renderer->localCaretRect(inlineBox, caretOffset); |
670 } | 670 } |
671 | 671 |
672 IntRect VisiblePosition::absoluteCaretBounds() const | 672 IntRect VisiblePosition::absoluteCaretBounds() const |
673 { | 673 { |
674 RenderObject* renderer; | 674 RenderObject* renderer; |
675 LayoutRect localRect = localCaretRect(renderer); | 675 LayoutRect localRect = localCaretRect(renderer); |
676 if (localRect.isEmpty() || !renderer) | 676 if (localRect.isEmpty() || !renderer) |
677 return IntRect(); | 677 return IntRect(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 if (vpos) | 799 if (vpos) |
800 vpos->showTreeForThis(); | 800 vpos->showTreeForThis(); |
801 } | 801 } |
802 | 802 |
803 void showTree(const WebCore::VisiblePosition& vpos) | 803 void showTree(const WebCore::VisiblePosition& vpos) |
804 { | 804 { |
805 vpos.showTreeForThis(); | 805 vpos.showTreeForThis(); |
806 } | 806 } |
807 | 807 |
808 #endif | 808 #endif |
OLD | NEW |