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

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

Issue 224113002: Oilpan: move Range object to the oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use STACK_ALLOCATED() + incorporate ager's overview of macros in this area. Created 6 years, 8 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
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 PlainTextRange::PlainTextRange(int start, int end) 51 PlainTextRange::PlainTextRange(int start, int end)
52 : m_start(start) 52 : m_start(start)
53 , m_end(end) 53 , m_end(end)
54 { 54 {
55 ASSERT(start >= 0); 55 ASSERT(start >= 0);
56 ASSERT(end >= 0); 56 ASSERT(end >= 0);
57 ASSERT(start <= end); 57 ASSERT(start <= end);
58 } 58 }
59 59
60 PassRefPtr<Range> PlainTextRange::createRange(const ContainerNode& scope) const 60 PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRange(const ContainerNode& s cope) const
61 { 61 {
62 return createRangeFor(scope, ForGeneric); 62 return createRangeFor(scope, ForGeneric);
63 } 63 }
64 64
65 PassRefPtr<Range> PlainTextRange::createRangeForSelection(const ContainerNode& s cope) const 65 PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRangeForSelection(const Cont ainerNode& scope) const
66 { 66 {
67 return createRangeFor(scope, ForSelection); 67 return createRangeFor(scope, ForSelection);
68 } 68 }
69 69
70 PassRefPtr<Range> PlainTextRange::createRangeFor(const ContainerNode& scope, Get RangeFor getRangeFor) const 70 PassRefPtrWillBeRawPtr<Range> PlainTextRange::createRangeFor(const ContainerNode & scope, GetRangeFor getRangeFor) const
71 { 71 {
72 ASSERT(isNotNull()); 72 ASSERT(isNotNull());
73 73
74 RefPtr<Range> resultRange = scope.document().createRange(); 74 RefPtrWillBeRawPtr<Range> resultRange = scope.document().createRange();
75 75
76 size_t docTextPosition = 0; 76 size_t docTextPosition = 0;
77 bool startRangeFound = false; 77 bool startRangeFound = false;
78 78
79 RefPtr<Range> textRunRange; 79 RefPtrWillBeRawPtr<Range> textRunRange = nullptr;
80 80
81 TextIterator it(rangeOfContents(const_cast<ContainerNode*>(&scope)).get(), g etRangeFor == ForSelection ? TextIteratorEmitsCharactersBetweenAllVisiblePositio ns : TextIteratorDefaultBehavior); 81 TextIterator it(rangeOfContents(const_cast<ContainerNode*>(&scope)).get(), g etRangeFor == ForSelection ? TextIteratorEmitsCharactersBetweenAllVisiblePositio ns : TextIteratorDefaultBehavior);
82 82
83 // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://b ugs.webkit.org/show_bug.cgi?id=6289>. 83 // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://b ugs.webkit.org/show_bug.cgi?id=6289>.
84 if (!start() && !length() && it.atEnd()) { 84 if (!start() && !length() && it.atEnd()) {
85 textRunRange = it.range(); 85 textRunRange = it.range();
86 86
87 resultRange->setStart(textRunRange->startContainer(), 0, ASSERT_NO_EXCEP TION); 87 resultRange->setStart(textRunRange->startContainer(), 0, ASSERT_NO_EXCEP TION);
88 resultRange->setEnd(textRunRange->startContainer(), 0, ASSERT_NO_EXCEPTI ON); 88 resultRange->setEnd(textRunRange->startContainer(), 0, ASSERT_NO_EXCEPTI ON);
89 89
90 return resultRange.release(); 90 return resultRange.release();
91 } 91 }
92 92
93 for (; !it.atEnd(); it.advance()) { 93 for (; !it.atEnd(); it.advance()) {
94 int len = it.length(); 94 int len = it.length();
95 textRunRange = it.range(); 95 textRunRange = it.range();
96 96
97 bool foundStart = start() >= docTextPosition && start() <= docTextPositi on + len; 97 bool foundStart = start() >= docTextPosition && start() <= docTextPositi on + len;
98 bool foundEnd = end() >= docTextPosition && end() <= docTextPosition + l en; 98 bool foundEnd = end() >= docTextPosition && end() <= docTextPosition + l en;
99 99
100 // Fix textRunRange->endPosition(), but only if foundStart || foundEnd, because it is only 100 // Fix textRunRange->endPosition(), but only if foundStart || foundEnd, because it is only
101 // in those cases that textRunRange is used. 101 // in those cases that textRunRange is used.
102 if (foundEnd) { 102 if (foundEnd) {
103 // FIXME: This is a workaround for the fact that the end of a run is often at the wrong 103 // FIXME: This is a workaround for the fact that the end of a run is often at the wrong
104 // position for emitted '\n's. 104 // position for emitted '\n's.
105 if (len == 1 && it.characterAt(0) == '\n') { 105 if (len == 1 && it.characterAt(0) == '\n') {
106 scope.document().updateLayoutIgnorePendingStylesheets(); 106 scope.document().updateLayoutIgnorePendingStylesheets();
107 it.advance(); 107 it.advance();
108 if (!it.atEnd()) { 108 if (!it.atEnd()) {
109 RefPtr<Range> range = it.range(); 109 RefPtrWillBeRawPtr<Range> range = it.range();
110 textRunRange->setEnd(range->startContainer(), range->startOf fset(), ASSERT_NO_EXCEPTION); 110 textRunRange->setEnd(range->startContainer(), range->startOf fset(), ASSERT_NO_EXCEPTION);
111 } else { 111 } else {
112 Position runStart = textRunRange->startPosition(); 112 Position runStart = textRunRange->startPosition();
113 Position runEnd = VisiblePosition(runStart).next().deepEquiv alent(); 113 Position runEnd = VisiblePosition(runStart).next().deepEquiv alent();
114 if (runEnd.isNotNull()) 114 if (runEnd.isNotNull())
115 textRunRange->setEnd(runEnd.containerNode(), runEnd.comp uteOffsetInContainerNode(), ASSERT_NO_EXCEPTION); 115 textRunRange->setEnd(runEnd.containerNode(), runEnd.comp uteOffsetInContainerNode(), ASSERT_NO_EXCEPTION);
116 } 116 }
117 } 117 }
118 } 118 }
119 119
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // The critical assumption is that this only gets called with ranges that 164 // The critical assumption is that this only gets called with ranges that
165 // concentrate on a given area containing the selection root. This is done 165 // concentrate on a given area containing the selection root. This is done
166 // because of text fields and textareas. The DOM for those is not 166 // because of text fields and textareas. The DOM for those is not
167 // directly in the document DOM, so ensure that the range does not cross a 167 // directly in the document DOM, so ensure that the range does not cross a
168 // boundary of one of those. 168 // boundary of one of those.
169 if (range.startContainer() != &scope && !range.startContainer()->isDescendan tOf(&scope)) 169 if (range.startContainer() != &scope && !range.startContainer()->isDescendan tOf(&scope))
170 return PlainTextRange(); 170 return PlainTextRange();
171 if (range.endContainer() != scope && !range.endContainer()->isDescendantOf(& scope)) 171 if (range.endContainer() != scope && !range.endContainer()->isDescendantOf(& scope))
172 return PlainTextRange(); 172 return PlainTextRange();
173 173
174 RefPtr<Range> testRange = Range::create(scope.document(), const_cast<Node*>( &scope), 0, range.startContainer(), range.startOffset()); 174 RefPtrWillBeRawPtr<Range> testRange = Range::create(scope.document(), const_ cast<Node*>(&scope), 0, range.startContainer(), range.startOffset());
175 ASSERT(testRange->startContainer() == &scope); 175 ASSERT(testRange->startContainer() == &scope);
176 size_t start = TextIterator::rangeLength(testRange.get()); 176 size_t start = TextIterator::rangeLength(testRange.get());
177 177
178 testRange->setEnd(range.endContainer(), range.endOffset(), IGNORE_EXCEPTION) ; 178 testRange->setEnd(range.endContainer(), range.endOffset(), IGNORE_EXCEPTION) ;
179 ASSERT(testRange->startContainer() == &scope); 179 ASSERT(testRange->startContainer() == &scope);
180 size_t end = TextIterator::rangeLength(testRange.get()); 180 size_t end = TextIterator::rangeLength(testRange.get());
181 181
182 return PlainTextRange(start, end); 182 return PlainTextRange(start, end);
183 } 183 }
184 184
185 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698