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

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

Issue 23467007: Have Range constructor take a Document reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 m_extent = visiblePosition.deepEquivalent(); 126 m_extent = visiblePosition.deepEquivalent();
127 validate(); 127 validate();
128 } 128 }
129 129
130 PassRefPtr<Range> VisibleSelection::firstRange() const 130 PassRefPtr<Range> VisibleSelection::firstRange() const
131 { 131 {
132 if (isNone()) 132 if (isNone())
133 return 0; 133 return 0;
134 Position start = m_start.parentAnchoredEquivalent(); 134 Position start = m_start.parentAnchoredEquivalent();
135 Position end = m_end.parentAnchoredEquivalent(); 135 Position end = m_end.parentAnchoredEquivalent();
136 return Range::create(&start.anchorNode()->document(), start, end); 136 return Range::create(start.anchorNode()->document(), start, end);
137 } 137 }
138 138
139 PassRefPtr<Range> VisibleSelection::toNormalizedRange() const 139 PassRefPtr<Range> VisibleSelection::toNormalizedRange() const
140 { 140 {
141 if (isNone()) 141 if (isNone())
142 return 0; 142 return 0;
143 143
144 // Make sure we have an updated layout since this function is called 144 // Make sure we have an updated layout since this function is called
145 // in the course of running edit commands which modify the DOM. 145 // in the course of running edit commands which modify the DOM.
146 // Failing to call this can result in equivalentXXXPosition calls returning 146 // Failing to call this can result in equivalentXXXPosition calls returning
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 s = s.parentAnchoredEquivalent(); 183 s = s.parentAnchoredEquivalent();
184 e = e.parentAnchoredEquivalent(); 184 e = e.parentAnchoredEquivalent();
185 } 185 }
186 186
187 if (!s.containerNode() || !e.containerNode()) 187 if (!s.containerNode() || !e.containerNode())
188 return 0; 188 return 0;
189 189
190 // VisibleSelections are supposed to always be valid. This constructor will ASSERT 190 // VisibleSelections are supposed to always be valid. This constructor will ASSERT
191 // if a valid range could not be created, which is fine for this callsite. 191 // if a valid range could not be created, which is fine for this callsite.
192 return Range::create(&s.anchorNode()->document(), s, e); 192 return Range::create(s.anchorNode()->document(), s, e);
193 } 193 }
194 194
195 bool VisibleSelection::expandUsingGranularity(TextGranularity granularity) 195 bool VisibleSelection::expandUsingGranularity(TextGranularity granularity)
196 { 196 {
197 if (isNone()) 197 if (isNone())
198 return false; 198 return false;
199 199
200 validate(granularity); 200 validate(granularity);
201 return true; 201 return true;
202 } 202 }
203 203
204 static PassRefPtr<Range> makeSearchRange(const Position& pos) 204 static PassRefPtr<Range> makeSearchRange(const Position& pos)
205 { 205 {
206 Node* n = pos.deprecatedNode(); 206 Node* n = pos.deprecatedNode();
207 if (!n) 207 if (!n)
208 return 0; 208 return 0;
209 Document& d = n->document(); 209 Document& d = n->document();
210 Node* de = d.documentElement(); 210 Node* de = d.documentElement();
211 if (!de) 211 if (!de)
212 return 0; 212 return 0;
213 Node* boundary = n->enclosingBlockFlowElement(); 213 Node* boundary = n->enclosingBlockFlowElement();
214 if (!boundary) 214 if (!boundary)
215 return 0; 215 return 0;
216 216
217 RefPtr<Range> searchRange(Range::create(&d)); 217 RefPtr<Range> searchRange(Range::create(d));
218 TrackExceptionState es; 218 TrackExceptionState es;
219 219
220 Position start(pos.parentAnchoredEquivalent()); 220 Position start(pos.parentAnchoredEquivalent());
221 searchRange->selectNodeContents(boundary, es); 221 searchRange->selectNodeContents(boundary, es);
222 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(), es); 222 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(), es);
223 223
224 ASSERT(!es.hadException()); 224 ASSERT(!es.hadException());
225 if (es.hadException()) 225 if (es.hadException())
226 return 0; 226 return 0;
227 227
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 sel.showTreeForThis(); 737 sel.showTreeForThis();
738 } 738 }
739 739
740 void showTree(const WebCore::VisibleSelection* sel) 740 void showTree(const WebCore::VisibleSelection* sel)
741 { 741 {
742 if (sel) 742 if (sel)
743 sel->showTreeForThis(); 743 sel->showTreeForThis();
744 } 744 }
745 745
746 #endif 746 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698