Chromium Code Reviews| 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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 m_positionStartOffset = textStartOffset; | 1180 m_positionStartOffset = textStartOffset; |
| 1181 m_positionEndOffset = textEndOffset; | 1181 m_positionEndOffset = textEndOffset; |
| 1182 m_singleCharacterBuffer = 0; | 1182 m_singleCharacterBuffer = 0; |
| 1183 m_textLength = textEndOffset - textStartOffset; | 1183 m_textLength = textEndOffset - textStartOffset; |
| 1184 m_lastCharacter = m_text[textEndOffset - 1]; | 1184 m_lastCharacter = m_text[textEndOffset - 1]; |
| 1185 | 1185 |
| 1186 m_lastTextNodeEndedWithCollapsedSpace = false; | 1186 m_lastTextNodeEndedWithCollapsedSpace = false; |
| 1187 m_hasEmitted = true; | 1187 m_hasEmitted = true; |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 PassRefPtrWillBeRawPtr<Range> TextIterator::range() const | 1190 PassRefPtrWillBeRawPtr<Range> TextIterator::createRange() const |
| 1191 { | 1191 { |
| 1192 // use the current run information, if we have it | 1192 // use the current run information, if we have it |
| 1193 if (m_positionNode) { | 1193 if (m_positionNode) { |
| 1194 flushPositionOffsets(); | 1194 flushPositionOffsets(); |
| 1195 return Range::create(m_positionNode->document(), m_positionNode, m_posit ionStartOffset, m_positionNode, m_positionEndOffset); | 1195 return Range::create(m_positionNode->document(), m_positionNode, m_posit ionStartOffset, m_positionNode, m_positionEndOffset); |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 // otherwise, return the end of the overall range we were given | 1198 // otherwise, return the end of the overall range we were given |
| 1199 if (m_endContainer) | 1199 if (m_endContainer) |
| 1200 return Range::create(m_endContainer->document(), m_endContainer, m_endOf fset, m_endContainer, m_endOffset); | 1200 return Range::create(m_endContainer->document(), m_endContainer, m_endOf fset, m_endContainer, m_endOffset); |
| 1201 | 1201 |
| 1202 return nullptr; | 1202 return nullptr; |
| 1203 } | 1203 } |
| 1204 | 1204 |
| 1205 Document* TextIterator::ownerDocument() const | |
| 1206 { | |
| 1207 if (m_positionNode) | |
| 1208 return &m_positionNode->document(); | |
| 1209 if (m_endContainer) | |
| 1210 return &m_endContainer->document(); | |
| 1211 return 0; | |
| 1212 } | |
| 1213 | |
| 1205 Node* TextIterator::node() const | 1214 Node* TextIterator::node() const |
| 1206 { | 1215 { |
| 1207 if (m_positionNode || m_endContainer) { | 1216 if (m_positionNode || m_endContainer) { |
| 1208 Node* node = startContainer(); | 1217 Node* node = startContainer(); |
| 1209 if (node->offsetInCharacters()) | 1218 if (node->offsetInCharacters()) |
| 1210 return node; | 1219 return node; |
| 1211 return NodeTraversal::childAt(*node, startOffset()); | 1220 return NodeTraversal::childAt(*node, startOffset()); |
| 1212 } | 1221 } |
| 1213 return 0; | 1222 return 0; |
| 1214 } | 1223 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1235 | 1244 |
| 1236 Node* TextIterator::startContainer() const | 1245 Node* TextIterator::startContainer() const |
| 1237 { | 1246 { |
| 1238 if (m_positionNode) { | 1247 if (m_positionNode) { |
| 1239 return m_positionNode; | 1248 return m_positionNode; |
| 1240 } | 1249 } |
| 1241 ASSERT(m_endContainer); | 1250 ASSERT(m_endContainer); |
| 1242 return m_endContainer; | 1251 return m_endContainer; |
| 1243 } | 1252 } |
| 1244 | 1253 |
| 1254 Node* TextIterator::endContainer() const | |
| 1255 { | |
| 1256 return startContainer(); | |
| 1257 } | |
| 1258 | |
| 1245 Position TextIterator::startPosition() const | 1259 Position TextIterator::startPosition() const |
| 1246 { | 1260 { |
| 1247 return createLegacyEditingPosition(startContainer(), startOffset()); | 1261 return createLegacyEditingPosition(startContainer(), startOffset()); |
| 1248 } | 1262 } |
| 1249 | 1263 |
| 1250 Position TextIterator::endPosition() const | 1264 Position TextIterator::endPosition() const |
| 1251 { | 1265 { |
| 1252 return createLegacyEditingPosition(startContainer(), endOffset()); | 1266 return createLegacyEditingPosition(endContainer(), endOffset()); |
| 1253 } | 1267 } |
| 1254 | 1268 |
| 1255 // -------- | 1269 // -------- |
| 1256 | 1270 |
| 1257 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r, TextIteratorBehaviorFlags behavior) | 1271 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r, TextIteratorBehaviorFlags behavior) |
| 1258 : m_node(nullptr) | 1272 : m_node(nullptr) |
| 1259 , m_offset(0) | 1273 , m_offset(0) |
| 1260 , m_handledNode(false) | 1274 , m_handledNode(false) |
| 1261 , m_handledChildren(false) | 1275 , m_handledChildren(false) |
| 1262 , m_startNode(nullptr) | 1276 , m_startNode(nullptr) |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1568 { | 1582 { |
| 1569 if (!next) | 1583 if (!next) |
| 1570 return false; | 1584 return false; |
| 1571 m_havePassedStartNode |= m_node == m_startNode; | 1585 m_havePassedStartNode |= m_node == m_startNode; |
| 1572 if (m_havePassedStartNode) | 1586 if (m_havePassedStartNode) |
| 1573 return false; | 1587 return false; |
| 1574 m_node = next; | 1588 m_node = next; |
| 1575 return true; | 1589 return true; |
| 1576 } | 1590 } |
| 1577 | 1591 |
| 1578 PassRefPtrWillBeRawPtr<Range> SimplifiedBackwardsTextIterator::range() const | |
| 1579 { | |
| 1580 if (m_positionNode) | |
| 1581 return Range::create(m_positionNode->document(), m_positionNode, m_posit ionStartOffset, m_positionNode, m_positionEndOffset); | |
| 1582 | |
| 1583 return Range::create(m_startNode->document(), m_startNode, m_startOffset, m_ startNode, m_startOffset); | |
| 1584 } | |
| 1585 | |
| 1586 Node* SimplifiedBackwardsTextIterator::startContainer() const | 1592 Node* SimplifiedBackwardsTextIterator::startContainer() const |
| 1587 { | 1593 { |
| 1588 if (m_positionNode) | 1594 if (m_positionNode) |
| 1589 return m_positionNode; | 1595 return m_positionNode; |
| 1590 return m_startNode; | 1596 return m_startNode; |
| 1591 } | 1597 } |
| 1592 | 1598 |
| 1593 int SimplifiedBackwardsTextIterator::endOffset() const | 1599 int SimplifiedBackwardsTextIterator::endOffset() const |
| 1594 { | 1600 { |
| 1595 if (m_positionNode) | 1601 if (m_positionNode) |
| 1596 return m_positionEndOffset; | 1602 return m_positionEndOffset; |
| 1597 return m_startOffset; | 1603 return m_startOffset; |
| 1598 } | 1604 } |
| 1599 | 1605 |
| 1600 Position SimplifiedBackwardsTextIterator::startPosition() const | 1606 Position SimplifiedBackwardsTextIterator::startPosition() const |
| 1601 { | 1607 { |
| 1602 if (m_positionNode) | 1608 if (m_positionNode) |
| 1603 return createLegacyEditingPosition(m_positionNode, m_positionStartOffset ); | 1609 return createLegacyEditingPosition(m_positionNode, m_positionStartOffset ); |
| 1604 return createLegacyEditingPosition(m_startNode, m_startOffset); | 1610 return createLegacyEditingPosition(m_startNode, m_startOffset); |
| 1605 } | 1611 } |
| 1606 | 1612 |
| 1613 Position SimplifiedBackwardsTextIterator::endPosition() const | |
| 1614 { | |
| 1615 if (m_positionNode) | |
| 1616 return createLegacyEditingPosition(m_positionNode, m_positionEndOffset); | |
| 1617 return createLegacyEditingPosition(m_startNode, m_startOffset); | |
| 1618 } | |
| 1619 | |
| 1607 // -------- | 1620 // -------- |
| 1608 | 1621 |
| 1609 CharacterIterator::CharacterIterator(const Range* range, TextIteratorBehaviorFla gs behavior) | 1622 CharacterIterator::CharacterIterator(const Range* range, TextIteratorBehaviorFla gs behavior) |
| 1610 : m_offset(0) | 1623 : m_offset(0) |
| 1611 , m_runOffset(0) | 1624 , m_runOffset(0) |
| 1612 , m_atBreak(true) | 1625 , m_atBreak(true) |
| 1613 , m_textIterator(range, behavior) | 1626 , m_textIterator(range, behavior) |
| 1614 { | 1627 { |
| 1615 initialize(); | 1628 initialize(); |
| 1616 } | 1629 } |
| 1617 | 1630 |
| 1618 CharacterIterator::CharacterIterator(const Position& start, const Position& end, TextIteratorBehaviorFlags behavior) | 1631 CharacterIterator::CharacterIterator(const Position& start, const Position& end, TextIteratorBehaviorFlags behavior) |
| 1619 : m_offset(0) | 1632 : m_offset(0) |
| 1620 , m_runOffset(0) | 1633 , m_runOffset(0) |
| 1621 , m_atBreak(true) | 1634 , m_atBreak(true) |
| 1622 , m_textIterator(start, end, behavior) | 1635 , m_textIterator(start, end, behavior) |
| 1623 { | 1636 { |
| 1624 initialize(); | 1637 initialize(); |
| 1625 } | 1638 } |
| 1626 | 1639 |
| 1627 void CharacterIterator::initialize() | 1640 void CharacterIterator::initialize() |
| 1628 { | 1641 { |
| 1629 while (!atEnd() && !m_textIterator.length()) | 1642 while (!atEnd() && !m_textIterator.length()) |
| 1630 m_textIterator.advance(); | 1643 m_textIterator.advance(); |
| 1631 } | 1644 } |
| 1632 | 1645 |
| 1633 PassRefPtrWillBeRawPtr<Range> CharacterIterator::range() const | 1646 PassRefPtrWillBeRawPtr<Range> CharacterIterator::createRange() const |
| 1634 { | 1647 { |
| 1635 RefPtrWillBeRawPtr<Range> r = m_textIterator.range(); | 1648 RefPtrWillBeRawPtr<Range> r = m_textIterator.createRange(); |
| 1636 if (!m_textIterator.atEnd()) { | 1649 if (!m_textIterator.atEnd()) { |
| 1637 if (m_textIterator.length() <= 1) { | 1650 if (m_textIterator.length() <= 1) { |
| 1638 ASSERT(!m_runOffset); | 1651 ASSERT(!m_runOffset); |
| 1639 } else { | 1652 } else { |
| 1640 Node* n = r->startContainer(); | 1653 Node* n = r->startContainer(); |
| 1641 ASSERT(n == r->endContainer()); | 1654 ASSERT(n == r->endContainer()); |
| 1642 int offset = r->startOffset() + m_runOffset; | 1655 int offset = r->startOffset() + m_runOffset; |
| 1643 r->setStart(n, offset, ASSERT_NO_EXCEPTION); | 1656 r->setStart(n, offset, ASSERT_NO_EXCEPTION); |
| 1644 r->setEnd(n, offset + 1, ASSERT_NO_EXCEPTION); | 1657 r->setEnd(n, offset + 1, ASSERT_NO_EXCEPTION); |
| 1645 } | 1658 } |
| 1646 } | 1659 } |
| 1647 return r.release(); | 1660 return r.release(); |
| 1648 } | 1661 } |
| 1649 | 1662 |
| 1663 Document* CharacterIterator::ownerDocument() const | |
| 1664 { | |
| 1665 return m_textIterator.ownerDocument(); | |
| 1666 } | |
| 1667 | |
| 1650 Node* CharacterIterator::startContainer() const | 1668 Node* CharacterIterator::startContainer() const |
| 1651 { | 1669 { |
| 1652 return m_textIterator.startContainer(); | 1670 return m_textIterator.startContainer(); |
| 1653 } | 1671 } |
| 1654 | 1672 |
| 1673 Node* CharacterIterator::endContainer() const | |
| 1674 { | |
| 1675 return m_textIterator.endContainer(); | |
| 1676 } | |
| 1677 | |
| 1655 int CharacterIterator::startOffset() const | 1678 int CharacterIterator::startOffset() const |
| 1656 { | 1679 { |
| 1657 if (!m_textIterator.atEnd()) { | 1680 if (!m_textIterator.atEnd()) { |
| 1658 if (m_textIterator.length() > 1) | 1681 if (m_textIterator.length() > 1) |
| 1659 return m_textIterator.startOffset() + m_runOffset; | 1682 return m_textIterator.startOffset() + m_runOffset; |
| 1660 ASSERT(!m_runOffset); | 1683 ASSERT(!m_runOffset); |
| 1661 } | 1684 } |
| 1662 return m_textIterator.startOffset(); | 1685 return m_textIterator.startOffset(); |
| 1663 } | 1686 } |
| 1664 | 1687 |
| 1688 int CharacterIterator::endOffset() const | |
| 1689 { | |
| 1690 if (!m_textIterator.atEnd()) { | |
| 1691 if (m_textIterator.length() > 1) | |
| 1692 return m_textIterator.startOffset() + m_runOffset + 1; | |
| 1693 ASSERT(!m_runOffset); | |
| 1694 } | |
| 1695 return m_textIterator.endOffset(); | |
| 1696 } | |
| 1697 | |
| 1665 Position CharacterIterator::startPosition() const | 1698 Position CharacterIterator::startPosition() const |
| 1666 { | 1699 { |
| 1667 if (!m_textIterator.atEnd()) { | 1700 if (!m_textIterator.atEnd()) { |
| 1668 if (m_textIterator.length() > 1) { | 1701 if (m_textIterator.length() > 1) { |
| 1669 Node* n = m_textIterator.startContainer(); | 1702 Node* n = m_textIterator.startContainer(); |
| 1670 int offset = m_textIterator.startOffset() + m_runOffset; | 1703 int offset = m_textIterator.startOffset() + m_runOffset; |
| 1671 return createLegacyEditingPosition(n, offset); | 1704 return createLegacyEditingPosition(n, offset); |
| 1672 } | 1705 } |
| 1673 ASSERT(!m_runOffset); | 1706 ASSERT(!m_runOffset); |
| 1674 } | 1707 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1756 BackwardsCharacterIterator::BackwardsCharacterIterator(const Position& start, co nst Position& end, TextIteratorBehaviorFlags behavior) | 1789 BackwardsCharacterIterator::BackwardsCharacterIterator(const Position& start, co nst Position& end, TextIteratorBehaviorFlags behavior) |
| 1757 : m_offset(0) | 1790 : m_offset(0) |
| 1758 , m_runOffset(0) | 1791 , m_runOffset(0) |
| 1759 , m_atBreak(true) | 1792 , m_atBreak(true) |
| 1760 , m_textIterator(start, end, behavior) | 1793 , m_textIterator(start, end, behavior) |
| 1761 { | 1794 { |
| 1762 while (!atEnd() && !m_textIterator.length()) | 1795 while (!atEnd() && !m_textIterator.length()) |
| 1763 m_textIterator.advance(); | 1796 m_textIterator.advance(); |
| 1764 } | 1797 } |
| 1765 | 1798 |
| 1766 PassRefPtrWillBeRawPtr<Range> BackwardsCharacterIterator::range() const | |
| 1767 { | |
| 1768 RefPtrWillBeRawPtr<Range> r = m_textIterator.range(); | |
| 1769 if (!m_textIterator.atEnd()) { | |
| 1770 if (m_textIterator.length() <= 1) { | |
| 1771 ASSERT(!m_runOffset); | |
| 1772 } else { | |
| 1773 Node* n = r->startContainer(); | |
| 1774 ASSERT(n == r->endContainer()); | |
| 1775 int offset = r->endOffset() - m_runOffset; | |
| 1776 r->setStart(n, offset - 1, ASSERT_NO_EXCEPTION); | |
| 1777 r->setEnd(n, offset, ASSERT_NO_EXCEPTION); | |
| 1778 } | |
| 1779 } | |
| 1780 return r.release(); | |
| 1781 } | |
| 1782 | |
| 1783 Position BackwardsCharacterIterator::endPosition() const | 1799 Position BackwardsCharacterIterator::endPosition() const |
| 1784 { | 1800 { |
| 1785 Node* n = m_textIterator.startContainer(); | 1801 if (!m_textIterator.atEnd()) { |
|
yosin_UTC9
2014/09/12 01:02:24
ACK: This change is imported from http://crrev.com
Mads Ager (chromium)
2014/09/12 10:52:08
Yes. :)
| |
| 1786 if (m_textIterator.atEnd()) { | 1802 if (m_textIterator.length() > 1) { |
| 1787 if (m_textIterator.length() > 1) | 1803 Node* n = m_textIterator.startContainer(); |
| 1788 return createLegacyEditingPosition(n, m_textIterator.endOffset() - m _runOffset); | 1804 return createLegacyEditingPosition(n, m_textIterator.endOffset() - m _runOffset); |
| 1805 } | |
| 1789 ASSERT(!m_runOffset); | 1806 ASSERT(!m_runOffset); |
| 1790 } | 1807 } |
| 1791 return createLegacyEditingPosition(n, m_textIterator.endOffset()); | 1808 return m_textIterator.endPosition(); |
| 1792 } | 1809 } |
| 1793 | 1810 |
| 1794 void BackwardsCharacterIterator::advance(int count) | 1811 void BackwardsCharacterIterator::advance(int count) |
| 1795 { | 1812 { |
| 1796 if (count <= 0) { | 1813 if (count <= 0) { |
| 1797 ASSERT(!count); | 1814 ASSERT(!count); |
| 1798 return; | 1815 return; |
| 1799 } | 1816 } |
| 1800 | 1817 |
| 1801 m_atBreak = false; | 1818 m_atBreak = false; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2285 { | 2302 { |
| 2286 matchStart = 0; | 2303 matchStart = 0; |
| 2287 size_t matchLength = 0; | 2304 size_t matchLength = 0; |
| 2288 | 2305 |
| 2289 if (!isValidUTF16(target)) | 2306 if (!isValidUTF16(target)) |
| 2290 return 0; | 2307 return 0; |
| 2291 | 2308 |
| 2292 SearchBuffer buffer(target, options); | 2309 SearchBuffer buffer(target, options); |
| 2293 | 2310 |
| 2294 if (buffer.needsMoreContext()) { | 2311 if (buffer.needsMoreContext()) { |
| 2295 RefPtrWillBeRawPtr<Range> startRange = it.range(); | 2312 RefPtrWillBeRawPtr<Range> beforeStartRange = it.ownerDocument()->createR ange(); |
| 2296 RefPtrWillBeRawPtr<Range> beforeStartRange = startRange->ownerDocument() .createRange(); | 2313 beforeStartRange->setEnd(it.startContainer(), it.startOffset(), IGNORE_E XCEPTION); |
| 2297 beforeStartRange->setEnd(startRange->startContainer(), startRange->start Offset(), IGNORE_EXCEPTION); | |
| 2298 for (SimplifiedBackwardsTextIterator backwardsIterator(beforeStartRange. get()); !backwardsIterator.atEnd(); backwardsIterator.advance()) { | 2314 for (SimplifiedBackwardsTextIterator backwardsIterator(beforeStartRange. get()); !backwardsIterator.atEnd(); backwardsIterator.advance()) { |
| 2299 Vector<UChar, 1024> characters; | 2315 Vector<UChar, 1024> characters; |
| 2300 backwardsIterator.prependTextTo(characters); | 2316 backwardsIterator.prependTextTo(characters); |
| 2301 buffer.prependContext(characters.data(), characters.size()); | 2317 buffer.prependContext(characters.data(), characters.size()); |
| 2302 if (!buffer.needsMoreContext()) | 2318 if (!buffer.needsMoreContext()) |
| 2303 break; | 2319 break; |
| 2304 } | 2320 } |
| 2305 } | 2321 } |
| 2306 | 2322 |
| 2307 while (!it.atEnd()) { | 2323 while (!it.atEnd()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2373 resultEnd = collapseTo; | 2389 resultEnd = collapseTo; |
| 2374 return; | 2390 return; |
| 2375 } | 2391 } |
| 2376 } | 2392 } |
| 2377 | 2393 |
| 2378 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo rFindPlainText); | 2394 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo rFindPlainText); |
| 2379 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re sultStart, resultEnd); | 2395 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re sultStart, resultEnd); |
| 2380 } | 2396 } |
| 2381 | 2397 |
| 2382 } | 2398 } |
| OLD | NEW |