OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 // The forward range starts at the selection end and ends at the document's | 67 // The forward range starts at the selection end and ends at the document's |
68 // end. It will then be updated to only contain the text in the text in the | 68 // end. It will then be updated to only contain the text in the text in the |
69 // right range around the selection. | 69 // right range around the selection. |
70 RefPtrWillBeRawPtr<Range> forwardRange = Range::create(*document, endPositio
n, lastPositionInNode(document->documentElement()).parentAnchoredEquivalent()); | 70 RefPtrWillBeRawPtr<Range> forwardRange = Range::create(*document, endPositio
n, lastPositionInNode(document->documentElement()).parentAnchoredEquivalent()); |
71 CharacterIterator forwardIterator(forwardRange.get(), TextIteratorStopsOnFor
mControls); | 71 CharacterIterator forwardIterator(forwardRange.get(), TextIteratorStopsOnFor
mControls); |
72 // FIXME: why do we stop going trough the text if we were not able to select
something on the right? | 72 // FIXME: why do we stop going trough the text if we were not able to select
something on the right? |
73 if (!forwardIterator.atEnd()) | 73 if (!forwardIterator.atEnd()) |
74 forwardIterator.advance(maxLength - halfMaxLength); | 74 forwardIterator.advance(maxLength - halfMaxLength); |
75 | 75 |
76 forwardRange = forwardIterator.range(); | 76 forwardRange = forwardIterator.createRange(); |
77 if (!forwardRange || !Range::create(*document, endPosition, forwardRange->st
artPosition())->text().length()) { | 77 if (!forwardRange || !Range::create(*document, endPosition, forwardRange->st
artPosition())->text().length()) { |
78 ASSERT(forwardRange); | 78 ASSERT(forwardRange); |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 // Same as with the forward range but with the backward range. The range | 82 // Same as with the forward range but with the backward range. The range |
83 // starts at the document's start and ends at the selection start and will | 83 // starts at the document's start and ends at the selection start and will |
84 // be updated. | 84 // be updated. |
85 RefPtrWillBeRawPtr<Range> backwardsRange = Range::create(*document, firstPos
itionInNode(document->documentElement()).parentAnchoredEquivalent(), startPositi
on); | 85 RefPtrWillBeRawPtr<Range> backwardsRange = Range::create(*document, firstPos
itionInNode(document->documentElement()).parentAnchoredEquivalent(), startPositi
on); |
86 BackwardsCharacterIterator backwardsIterator(backwardsRange.get(), TextItera
torStopsOnFormControls); | 86 BackwardsCharacterIterator backwardsIterator(backwardsRange.get(), TextItera
torStopsOnFormControls); |
87 if (!backwardsIterator.atEnd()) | 87 if (!backwardsIterator.atEnd()) |
88 backwardsIterator.advance(halfMaxLength); | 88 backwardsIterator.advance(halfMaxLength); |
89 | 89 |
90 backwardsRange = backwardsIterator.range(); | 90 m_startOffsetInContent = Range::create(*document, backwardsIterator.endPosit
ion(), startPosition)->text().length(); |
91 if (!backwardsRange) { | 91 m_endOffsetInContent = Range::create(*document, backwardsIterator.endPositio
n(), endPosition)->text().length(); |
92 ASSERT(backwardsRange); | 92 m_contentRange = Range::create(*document, backwardsIterator.endPosition(), f
orwardRange->startPosition()); |
93 return; | |
94 } | |
95 | |
96 m_startOffsetInContent = Range::create(*document, backwardsRange->endPositio
n(), startPosition)->text().length(); | |
97 m_endOffsetInContent = Range::create(*document, backwardsRange->endPosition(
), endPosition)->text().length(); | |
98 m_contentRange = Range::create(*document, backwardsRange->endPosition(), for
wardRange->startPosition()); | |
99 ASSERT(m_contentRange); | 93 ASSERT(m_contentRange); |
100 } | 94 } |
101 | 95 |
102 PassRefPtrWillBeRawPtr<Range> SurroundingText::rangeFromContentOffsets(unsigned
startOffsetInContent, unsigned endOffsetInContent) | 96 PassRefPtrWillBeRawPtr<Range> SurroundingText::rangeFromContentOffsets(unsigned
startOffsetInContent, unsigned endOffsetInContent) |
103 { | 97 { |
104 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte
nt().length()) | 98 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte
nt().length()) |
105 return nullptr; | 99 return nullptr; |
106 | 100 |
107 CharacterIterator iterator(m_contentRange.get()); | 101 CharacterIterator iterator(m_contentRange.get()); |
108 | 102 |
(...skipping 22 matching lines...) Expand all Loading... |
131 { | 125 { |
132 return m_startOffsetInContent; | 126 return m_startOffsetInContent; |
133 } | 127 } |
134 | 128 |
135 unsigned SurroundingText::endOffsetInContent() const | 129 unsigned SurroundingText::endOffsetInContent() const |
136 { | 130 { |
137 return m_endOffsetInContent; | 131 return m_endOffsetInContent; |
138 } | 132 } |
139 | 133 |
140 } // namespace blink | 134 } // namespace blink |
OLD | NEW |