| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 BackwardsCharacterIterator backwardsIterator(Position::firstPositionInNode(d
ocument->documentElement()).parentAnchoredEquivalent(), startPosition, TextItera
torStopsOnFormControls); | 82 BackwardsCharacterIterator backwardsIterator(Position::firstPositionInNode(d
ocument->documentElement()).parentAnchoredEquivalent(), startPosition, TextItera
torStopsOnFormControls); |
| 83 if (!backwardsIterator.atEnd()) | 83 if (!backwardsIterator.atEnd()) |
| 84 backwardsIterator.advance(halfMaxLength); | 84 backwardsIterator.advance(halfMaxLength); |
| 85 | 85 |
| 86 m_startOffsetInContent = Range::create(*document, backwardsIterator.endPosit
ion(), startPosition)->text().length(); | 86 m_startOffsetInContent = Range::create(*document, backwardsIterator.endPosit
ion(), startPosition)->text().length(); |
| 87 m_endOffsetInContent = Range::create(*document, backwardsIterator.endPositio
n(), endPosition)->text().length(); | 87 m_endOffsetInContent = Range::create(*document, backwardsIterator.endPositio
n(), endPosition)->text().length(); |
| 88 m_contentRange = Range::create(*document, backwardsIterator.endPosition(), f
orwardRange.startPosition()); | 88 m_contentRange = Range::create(*document, backwardsIterator.endPosition(), f
orwardRange.startPosition()); |
| 89 DCHECK(m_contentRange); | 89 DCHECK(m_contentRange); |
| 90 } | 90 } |
| 91 | 91 |
| 92 Range* SurroundingText::rangeFromContentOffsets(unsigned startOffsetInContent, u
nsigned endOffsetInContent) | |
| 93 { | |
| 94 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte
nt().length()) | |
| 95 return nullptr; | |
| 96 | |
| 97 CharacterIterator iterator(m_contentRange->startPosition(), m_contentRange->
endPosition()); | |
| 98 | |
| 99 DCHECK(!iterator.atEnd()); | |
| 100 iterator.advance(startOffsetInContent); | |
| 101 | |
| 102 Position start = iterator.startPosition(); | |
| 103 | |
| 104 DCHECK(!iterator.atEnd()); | |
| 105 iterator.advance(endOffsetInContent - startOffsetInContent); | |
| 106 | |
| 107 Position end = iterator.startPosition(); | |
| 108 | |
| 109 DCHECK(start.document()); | |
| 110 return Range::create(*start.document(), start, end); | |
| 111 } | |
| 112 | |
| 113 String SurroundingText::content() const | 92 String SurroundingText::content() const |
| 114 { | 93 { |
| 115 if (m_contentRange) | 94 if (m_contentRange) |
| 116 return m_contentRange->text(); | 95 return m_contentRange->text(); |
| 117 return String(); | 96 return String(); |
| 118 } | 97 } |
| 119 | 98 |
| 120 unsigned SurroundingText::startOffsetInContent() const | 99 unsigned SurroundingText::startOffsetInContent() const |
| 121 { | 100 { |
| 122 return m_startOffsetInContent; | 101 return m_startOffsetInContent; |
| 123 } | 102 } |
| 124 | 103 |
| 125 unsigned SurroundingText::endOffsetInContent() const | 104 unsigned SurroundingText::endOffsetInContent() const |
| 126 { | 105 { |
| 127 return m_endOffsetInContent; | 106 return m_endOffsetInContent; |
| 128 } | 107 } |
| 129 | 108 |
| 130 } // namespace blink | 109 } // namespace blink |
| OLD | NEW |