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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master 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
« no previous file with comments | « Source/core/editing/VisiblePosition.cpp ('k') | Source/core/editing/VisibleUnits.cpp » ('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) 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
147 // incorrect results. 147 // incorrect results.
148 m_start.anchorNode()->document()->updateLayout(); 148 m_start.anchorNode()->document().updateLayout();
149 149
150 // Check again, because updating layout can clear the selection. 150 // Check again, because updating layout can clear the selection.
151 if (isNone()) 151 if (isNone())
152 return 0; 152 return 0;
153 153
154 Position s, e; 154 Position s, e;
155 if (isCaret()) { 155 if (isCaret()) {
156 // If the selection is a caret, move the range start upstream. This help s us match 156 // If the selection is a caret, move the range start upstream. This help s us match
157 // the conventions of text editors tested, which make style determinatio ns based 157 // the conventions of text editors tested, which make style determinatio ns based
158 // on the character before the caret, if any. 158 // on the character before the caret, if any.
(...skipping 23 matching lines...) Expand all
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
« no previous file with comments | « Source/core/editing/VisiblePosition.cpp ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698