| 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 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "core/dom/Position.h" | 36 #include "core/dom/Position.h" |
| 37 #include "core/dom/Text.h" | 37 #include "core/dom/Text.h" |
| 38 #include "core/editing/RenderedPosition.h" | 38 #include "core/editing/RenderedPosition.h" |
| 39 #include "core/editing/TextIterator.h" | 39 #include "core/editing/TextIterator.h" |
| 40 #include "core/editing/VisiblePosition.h" | 40 #include "core/editing/VisiblePosition.h" |
| 41 #include "core/editing/htmlediting.h" | 41 #include "core/editing/htmlediting.h" |
| 42 #include "core/html/HTMLBRElement.h" | 42 #include "core/html/HTMLBRElement.h" |
| 43 #include "core/rendering/InlineTextBox.h" | 43 #include "core/rendering/InlineTextBox.h" |
| 44 #include "core/rendering/RenderBlockFlow.h" | 44 #include "core/rendering/RenderBlockFlow.h" |
| 45 #include "core/rendering/RenderObject.h" | 45 #include "core/rendering/RenderObject.h" |
| 46 #include "platform/heap/Handle.h" |
| 46 #include "platform/text/TextBoundaries.h" | 47 #include "platform/text/TextBoundaries.h" |
| 47 | 48 |
| 48 namespace WebCore { | 49 namespace WebCore { |
| 49 | 50 |
| 50 using namespace HTMLNames; | 51 using namespace HTMLNames; |
| 51 using namespace WTF::Unicode; | 52 using namespace WTF::Unicode; |
| 52 | 53 |
| 53 static Node* previousLeafWithSameEditability(Node* node, EditableType editableTy
pe) | 54 static Node* previousLeafWithSameEditability(Node* node, EditableType editableTy
pe) |
| 54 { | 55 { |
| 55 bool editable = node->rendererIsEditable(editableType); | 56 bool editable = node->rendererIsEditable(editableType); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
Function searchFunction) | 450 static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
Function searchFunction) |
| 450 { | 451 { |
| 451 Position pos = c.deepEquivalent(); | 452 Position pos = c.deepEquivalent(); |
| 452 Node* boundary = pos.parentEditingBoundary(); | 453 Node* boundary = pos.parentEditingBoundary(); |
| 453 if (!boundary) | 454 if (!boundary) |
| 454 return VisiblePosition(); | 455 return VisiblePosition(); |
| 455 | 456 |
| 456 Document& d = boundary->document(); | 457 Document& d = boundary->document(); |
| 457 Position start = createLegacyEditingPosition(boundary, 0).parentAnchoredEqui
valent(); | 458 Position start = createLegacyEditingPosition(boundary, 0).parentAnchoredEqui
valent(); |
| 458 Position end = pos.parentAnchoredEquivalent(); | 459 Position end = pos.parentAnchoredEquivalent(); |
| 459 RefPtr<Range> searchRange = Range::create(d); | 460 RefPtrWillBeRawPtr<Range> searchRange = Range::create(d); |
| 460 | 461 |
| 461 Vector<UChar, 1024> string; | 462 Vector<UChar, 1024> string; |
| 462 unsigned suffixLength = 0; | 463 unsigned suffixLength = 0; |
| 463 | 464 |
| 464 TrackExceptionState exceptionState; | 465 TrackExceptionState exceptionState; |
| 465 if (requiresContextForWordBoundary(c.characterBefore())) { | 466 if (requiresContextForWordBoundary(c.characterBefore())) { |
| 466 RefPtr<Range> forwardsScanRange(d.createRange()); | 467 RefPtrWillBeRawPtr<Range> forwardsScanRange(d.createRange()); |
| 467 forwardsScanRange->setEndAfter(boundary, exceptionState); | 468 forwardsScanRange->setEndAfter(boundary, exceptionState); |
| 468 forwardsScanRange->setStart(end.deprecatedNode(), end.deprecatedEditingO
ffset(), exceptionState); | 469 forwardsScanRange->setStart(end.deprecatedNode(), end.deprecatedEditingO
ffset(), exceptionState); |
| 469 TextIterator forwardsIterator(forwardsScanRange.get()); | 470 TextIterator forwardsIterator(forwardsScanRange.get()); |
| 470 while (!forwardsIterator.atEnd()) { | 471 while (!forwardsIterator.atEnd()) { |
| 471 Vector<UChar, 1024> characters; | 472 Vector<UChar, 1024> characters; |
| 472 forwardsIterator.appendTextTo(characters); | 473 forwardsIterator.appendTextTo(characters); |
| 473 int i = endOfFirstWordBoundaryContext(characters.data(), characters.
size()); | 474 int i = endOfFirstWordBoundaryContext(characters.data(), characters.
size()); |
| 474 string.append(characters.data(), i); | 475 string.append(characters.data(), i); |
| 475 suffixLength += i; | 476 suffixLength += i; |
| 476 if (static_cast<unsigned>(i) < characters.size()) | 477 if (static_cast<unsigned>(i) < characters.size()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 529 } |
| 529 | 530 |
| 530 static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
tion searchFunction) | 531 static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
tion searchFunction) |
| 531 { | 532 { |
| 532 Position pos = c.deepEquivalent(); | 533 Position pos = c.deepEquivalent(); |
| 533 Node* boundary = pos.parentEditingBoundary(); | 534 Node* boundary = pos.parentEditingBoundary(); |
| 534 if (!boundary) | 535 if (!boundary) |
| 535 return VisiblePosition(); | 536 return VisiblePosition(); |
| 536 | 537 |
| 537 Document& d = boundary->document(); | 538 Document& d = boundary->document(); |
| 538 RefPtr<Range> searchRange(d.createRange()); | 539 RefPtrWillBeRawPtr<Range> searchRange(d.createRange()); |
| 539 Position start(pos.parentAnchoredEquivalent()); | 540 Position start(pos.parentAnchoredEquivalent()); |
| 540 | 541 |
| 541 Vector<UChar, 1024> string; | 542 Vector<UChar, 1024> string; |
| 542 unsigned prefixLength = 0; | 543 unsigned prefixLength = 0; |
| 543 | 544 |
| 544 if (requiresContextForWordBoundary(c.characterAfter())) { | 545 if (requiresContextForWordBoundary(c.characterAfter())) { |
| 545 RefPtr<Range> backwardsScanRange(d.createRange()); | 546 RefPtrWillBeRawPtr<Range> backwardsScanRange(d.createRange()); |
| 546 backwardsScanRange->setEnd(start.deprecatedNode(), start.deprecatedEditi
ngOffset(), IGNORE_EXCEPTION); | 547 backwardsScanRange->setEnd(start.deprecatedNode(), start.deprecatedEditi
ngOffset(), IGNORE_EXCEPTION); |
| 547 SimplifiedBackwardsTextIterator backwardsIterator(backwardsScanRange.get
()); | 548 SimplifiedBackwardsTextIterator backwardsIterator(backwardsScanRange.get
()); |
| 548 while (!backwardsIterator.atEnd()) { | 549 while (!backwardsIterator.atEnd()) { |
| 549 Vector<UChar, 1024> characters; | 550 Vector<UChar, 1024> characters; |
| 550 backwardsIterator.prependTextTo(characters); | 551 backwardsIterator.prependTextTo(characters); |
| 551 int length = characters.size(); | 552 int length = characters.size(); |
| 552 int i = startOfLastWordBoundaryContext(characters.data(), length); | 553 int i = startOfLastWordBoundaryContext(characters.data(), length); |
| 553 string.prepend(characters.data() + i, length - i); | 554 string.prepend(characters.data() + i, length - i); |
| 554 prefixLength += length - i; | 555 prefixLength += length - i; |
| 555 if (i > 0) | 556 if (i > 0) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 next = searchFunction(string.data(), string.size(), prefixLength, DontHa
veMoreContext, needMoreContext); | 588 next = searchFunction(string.data(), string.size(), prefixLength, DontHa
veMoreContext, needMoreContext); |
| 588 ASSERT(!needMoreContext); | 589 ASSERT(!needMoreContext); |
| 589 } | 590 } |
| 590 | 591 |
| 591 if (it.atEnd() && next == string.size()) { | 592 if (it.atEnd() && next == string.size()) { |
| 592 pos = it.range()->startPosition(); | 593 pos = it.range()->startPosition(); |
| 593 } else if (next != invalidOffset && next != prefixLength) { | 594 } else if (next != invalidOffset && next != prefixLength) { |
| 594 // Use the character iterator to translate the next value into a DOM pos
ition. | 595 // Use the character iterator to translate the next value into a DOM pos
ition. |
| 595 CharacterIterator charIt(searchRange.get(), TextIteratorEmitsCharactersB
etweenAllVisiblePositions); | 596 CharacterIterator charIt(searchRange.get(), TextIteratorEmitsCharactersB
etweenAllVisiblePositions); |
| 596 charIt.advance(next - prefixLength - 1); | 597 charIt.advance(next - prefixLength - 1); |
| 597 RefPtr<Range> characterRange = charIt.range(); | 598 RefPtrWillBeRawPtr<Range> characterRange = charIt.range(); |
| 598 pos = characterRange->endPosition(); | 599 pos = characterRange->endPosition(); |
| 599 | 600 |
| 600 if (charIt.characterAt(0) == '\n') { | 601 if (charIt.characterAt(0) == '\n') { |
| 601 // FIXME: workaround for collapsed range (where only start position
is correct) emitted for some emitted newlines (see rdar://5192593) | 602 // FIXME: workaround for collapsed range (where only start position
is correct) emitted for some emitted newlines (see rdar://5192593) |
| 602 VisiblePosition visPos = VisiblePosition(pos); | 603 VisiblePosition visPos = VisiblePosition(pos); |
| 603 if (visPos == VisiblePosition(characterRange->startPosition())) { | 604 if (visPos == VisiblePosition(characterRange->startPosition())) { |
| 604 charIt.advance(1); | 605 charIt.advance(1); |
| 605 pos = charIt.range()->startPosition(); | 606 pos = charIt.range()->startPosition(); |
| 606 } | 607 } |
| 607 } | 608 } |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 { | 1386 { |
| 1386 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); | 1387 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); |
| 1387 } | 1388 } |
| 1388 | 1389 |
| 1389 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) | 1390 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) |
| 1390 { | 1391 { |
| 1391 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); | 1392 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); |
| 1392 } | 1393 } |
| 1393 | 1394 |
| 1394 } | 1395 } |
| OLD | NEW |