Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: Source/core/editing/SurroundingText.cpp

Issue 560333002: Avoid more temporary ranges in connection with various TextIterators. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix mac build. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/PlainTextRange.cpp ('k') | Source/core/editing/TextIterator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « Source/core/editing/PlainTextRange.cpp ('k') | Source/core/editing/TextIterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698