OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. |
3 * Copyright (C) 2005 Alexey Proskuryakov. | 3 * Copyright (C) 2005 Alexey Proskuryakov. |
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 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 if (!r) | 1282 if (!r) |
1283 return; | 1283 return; |
1284 | 1284 |
1285 Node* startNode = r->startContainer(); | 1285 Node* startNode = r->startContainer(); |
1286 if (!startNode) | 1286 if (!startNode) |
1287 return; | 1287 return; |
1288 Node* endNode = r->endContainer(); | 1288 Node* endNode = r->endContainer(); |
1289 int startOffset = r->startOffset(); | 1289 int startOffset = r->startOffset(); |
1290 int endOffset = r->endOffset(); | 1290 int endOffset = r->endOffset(); |
1291 | 1291 |
| 1292 init(startNode, endNode, startOffset, endOffset); |
| 1293 } |
| 1294 |
| 1295 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Position&
start, const Position& end, TextIteratorBehaviorFlags behavior) |
| 1296 : m_node(nullptr) |
| 1297 , m_offset(0) |
| 1298 , m_handledNode(false) |
| 1299 , m_handledChildren(false) |
| 1300 , m_startNode(nullptr) |
| 1301 , m_startOffset(0) |
| 1302 , m_endNode(nullptr) |
| 1303 , m_endOffset(0) |
| 1304 , m_positionNode(nullptr) |
| 1305 , m_positionStartOffset(0) |
| 1306 , m_positionEndOffset(0) |
| 1307 , m_textOffset(0) |
| 1308 , m_textLength(0) |
| 1309 , m_lastTextNode(nullptr) |
| 1310 , m_lastCharacter(0) |
| 1311 , m_singleCharacterBuffer(0) |
| 1312 , m_havePassedStartNode(false) |
| 1313 , m_shouldHandleFirstLetter(false) |
| 1314 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) |
| 1315 , m_shouldStop(false) |
| 1316 , m_emitsOriginalText(false) |
| 1317 { |
| 1318 ASSERT(behavior == TextIteratorDefaultBehavior || behavior == TextIteratorSt
opsOnFormControls); |
| 1319 |
| 1320 Node* startNode = start.deprecatedNode(); |
| 1321 if (!startNode) |
| 1322 return; |
| 1323 Node* endNode = end.deprecatedNode(); |
| 1324 int startOffset = start.deprecatedEditingOffset(); |
| 1325 int endOffset = end.deprecatedEditingOffset(); |
| 1326 |
| 1327 init(startNode, endNode, startOffset, endOffset); |
| 1328 } |
| 1329 |
| 1330 void SimplifiedBackwardsTextIterator::init(Node* startNode, Node* endNode, int s
tartOffset, int endOffset) |
| 1331 { |
1292 if (!startNode->offsetInCharacters() && startOffset >= 0) { | 1332 if (!startNode->offsetInCharacters() && startOffset >= 0) { |
1293 // NodeTraversal::childAt() will return 0 if the offset is out of range.
We rely on this behavior | 1333 // NodeTraversal::childAt() will return 0 if the offset is out of range.
We rely on this behavior |
1294 // instead of calling countChildren() to avoid traversing the children t
wice. | 1334 // instead of calling countChildren() to avoid traversing the children t
wice. |
1295 if (Node* childAtOffset = NodeTraversal::childAt(*startNode, startOffset
)) { | 1335 if (Node* childAtOffset = NodeTraversal::childAt(*startNode, startOffset
)) { |
1296 startNode = childAtOffset; | 1336 startNode = childAtOffset; |
1297 startOffset = 0; | 1337 startOffset = 0; |
1298 } | 1338 } |
1299 } | 1339 } |
1300 if (!endNode->offsetInCharacters() && endOffset > 0) { | 1340 if (!endNode->offsetInCharacters() && endOffset > 0) { |
1301 // NodeTraversal::childAt() will return 0 if the offset is out of range.
We rely on this behavior | 1341 // NodeTraversal::childAt() will return 0 if the offset is out of range.
We rely on this behavior |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range* range, TextI
teratorBehaviorFlags behavior) | 1746 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range* range, TextI
teratorBehaviorFlags behavior) |
1707 : m_offset(0) | 1747 : m_offset(0) |
1708 , m_runOffset(0) | 1748 , m_runOffset(0) |
1709 , m_atBreak(true) | 1749 , m_atBreak(true) |
1710 , m_textIterator(range, behavior) | 1750 , m_textIterator(range, behavior) |
1711 { | 1751 { |
1712 while (!atEnd() && !m_textIterator.length()) | 1752 while (!atEnd() && !m_textIterator.length()) |
1713 m_textIterator.advance(); | 1753 m_textIterator.advance(); |
1714 } | 1754 } |
1715 | 1755 |
| 1756 BackwardsCharacterIterator::BackwardsCharacterIterator(const Position& start, co
nst Position& end, TextIteratorBehaviorFlags behavior) |
| 1757 : m_offset(0) |
| 1758 , m_runOffset(0) |
| 1759 , m_atBreak(true) |
| 1760 , m_textIterator(start, end, behavior) |
| 1761 { |
| 1762 while (!atEnd() && !m_textIterator.length()) |
| 1763 m_textIterator.advance(); |
| 1764 } |
| 1765 |
1716 PassRefPtrWillBeRawPtr<Range> BackwardsCharacterIterator::range() const | 1766 PassRefPtrWillBeRawPtr<Range> BackwardsCharacterIterator::range() const |
1717 { | 1767 { |
1718 RefPtrWillBeRawPtr<Range> r = m_textIterator.range(); | 1768 RefPtrWillBeRawPtr<Range> r = m_textIterator.range(); |
1719 if (!m_textIterator.atEnd()) { | 1769 if (!m_textIterator.atEnd()) { |
1720 if (m_textIterator.length() <= 1) { | 1770 if (m_textIterator.length() <= 1) { |
1721 ASSERT(!m_runOffset); | 1771 ASSERT(!m_runOffset); |
1722 } else { | 1772 } else { |
1723 Node* n = r->startContainer(); | 1773 Node* n = r->startContainer(); |
1724 ASSERT(n == r->endContainer()); | 1774 ASSERT(n == r->endContainer()); |
1725 int offset = r->endOffset() - m_runOffset; | 1775 int offset = r->endOffset() - m_runOffset; |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 resultEnd = collapseTo; | 2373 resultEnd = collapseTo; |
2324 return; | 2374 return; |
2325 } | 2375 } |
2326 } | 2376 } |
2327 | 2377 |
2328 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); | 2378 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); |
2329 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); | 2379 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); |
2330 } | 2380 } |
2331 | 2381 |
2332 } | 2382 } |
OLD | NEW |