| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 return; | 46 return; |
| 47 | 47 |
| 48 const unsigned halfMaxLength = maxLength / 2; | 48 const unsigned halfMaxLength = maxLength / 2; |
| 49 CharacterIterator forwardIterator(makeRange(visiblePosition, endOfDocument(v
isiblePosition)).get(), TextIteratorStopsOnFormControls); | 49 CharacterIterator forwardIterator(makeRange(visiblePosition, endOfDocument(v
isiblePosition)).get(), TextIteratorStopsOnFormControls); |
| 50 if (!forwardIterator.atEnd()) | 50 if (!forwardIterator.atEnd()) |
| 51 forwardIterator.advance(maxLength - halfMaxLength); | 51 forwardIterator.advance(maxLength - halfMaxLength); |
| 52 | 52 |
| 53 Position position = visiblePosition.deepEquivalent().parentAnchoredEquivalen
t(); | 53 Position position = visiblePosition.deepEquivalent().parentAnchoredEquivalen
t(); |
| 54 Document* document = position.document(); | 54 Document* document = position.document(); |
| 55 ASSERT(document); | 55 ASSERT(document); |
| 56 RefPtr<Range> forwardRange = forwardIterator.range(); | 56 RefPtrWillBeRawPtr<Range> forwardRange = forwardIterator.range(); |
| 57 if (!forwardRange || !Range::create(*document, position, forwardRange->start
Position())->text().length()) { | 57 if (!forwardRange || !Range::create(*document, position, forwardRange->start
Position())->text().length()) { |
| 58 ASSERT(forwardRange); | 58 ASSERT(forwardRange); |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 | 61 |
| 62 BackwardsCharacterIterator backwardsIterator(makeRange(startOfDocument(visib
lePosition), visiblePosition).get(), TextIteratorStopsOnFormControls); | 62 BackwardsCharacterIterator backwardsIterator(makeRange(startOfDocument(visib
lePosition), visiblePosition).get(), TextIteratorStopsOnFormControls); |
| 63 if (!backwardsIterator.atEnd()) | 63 if (!backwardsIterator.atEnd()) |
| 64 backwardsIterator.advance(halfMaxLength); | 64 backwardsIterator.advance(halfMaxLength); |
| 65 | 65 |
| 66 RefPtr<Range> backwardsRange = backwardsIterator.range(); | 66 RefPtrWillBeRawPtr<Range> backwardsRange = backwardsIterator.range(); |
| 67 if (!backwardsRange) { | 67 if (!backwardsRange) { |
| 68 ASSERT(backwardsRange); | 68 ASSERT(backwardsRange); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 | 71 |
| 72 m_positionOffsetInContent = Range::create(*document, backwardsRange->endPosi
tion(), position)->text().length(); | 72 m_positionOffsetInContent = Range::create(*document, backwardsRange->endPosi
tion(), position)->text().length(); |
| 73 m_contentRange = Range::create(*document, backwardsRange->endPosition(), for
wardRange->startPosition()); | 73 m_contentRange = Range::create(*document, backwardsRange->endPosition(), for
wardRange->startPosition()); |
| 74 ASSERT(m_contentRange); | 74 ASSERT(m_contentRange); |
| 75 } | 75 } |
| 76 | 76 |
| 77 PassRefPtr<Range> SurroundingText::rangeFromContentOffsets(unsigned startOffsetI
nContent, unsigned endOffsetInContent) | 77 PassRefPtrWillBeRawPtr<Range> SurroundingText::rangeFromContentOffsets(unsigned
startOffsetInContent, unsigned endOffsetInContent) |
| 78 { | 78 { |
| 79 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte
nt().length()) | 79 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte
nt().length()) |
| 80 return nullptr; | 80 return nullptr; |
| 81 | 81 |
| 82 CharacterIterator iterator(m_contentRange.get()); | 82 CharacterIterator iterator(m_contentRange.get()); |
| 83 | 83 |
| 84 ASSERT(!iterator.atEnd()); | 84 ASSERT(!iterator.atEnd()); |
| 85 iterator.advance(startOffsetInContent); | 85 iterator.advance(startOffsetInContent); |
| 86 | 86 |
| 87 ASSERT(iterator.range()); | 87 ASSERT(iterator.range()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 return m_contentRange->text(); | 103 return m_contentRange->text(); |
| 104 return String(); | 104 return String(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 unsigned SurroundingText::positionOffsetInContent() const | 107 unsigned SurroundingText::positionOffsetInContent() const |
| 108 { | 108 { |
| 109 return m_positionOffsetInContent; | 109 return m_positionOffsetInContent; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace WebCore | 112 } // namespace WebCore |
| OLD | NEW |