OLD | NEW |
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 void VisibleSelection::setExtent(const VisiblePosition& visiblePosition) | 126 void VisibleSelection::setExtent(const VisiblePosition& visiblePosition) |
127 { | 127 { |
128 m_extent = visiblePosition.deepEquivalent(); | 128 m_extent = visiblePosition.deepEquivalent(); |
129 validate(); | 129 validate(); |
130 } | 130 } |
131 | 131 |
132 PassRefPtr<Range> VisibleSelection::firstRange() const | 132 PassRefPtr<Range> VisibleSelection::firstRange() const |
133 { | 133 { |
134 if (isNone()) | 134 if (isNone()) |
135 return 0; | 135 return nullptr; |
136 Position start = m_start.parentAnchoredEquivalent(); | 136 Position start = m_start.parentAnchoredEquivalent(); |
137 Position end = m_end.parentAnchoredEquivalent(); | 137 Position end = m_end.parentAnchoredEquivalent(); |
138 return Range::create(*start.document(), start, end); | 138 return Range::create(*start.document(), start, end); |
139 } | 139 } |
140 | 140 |
141 PassRefPtr<Range> VisibleSelection::toNormalizedRange() const | 141 PassRefPtr<Range> VisibleSelection::toNormalizedRange() const |
142 { | 142 { |
143 if (isNone()) | 143 if (isNone()) |
144 return 0; | 144 return nullptr; |
145 | 145 |
146 // Make sure we have an updated layout since this function is called | 146 // Make sure we have an updated layout since this function is called |
147 // in the course of running edit commands which modify the DOM. | 147 // in the course of running edit commands which modify the DOM. |
148 // Failing to call this can result in equivalentXXXPosition calls returning | 148 // Failing to call this can result in equivalentXXXPosition calls returning |
149 // incorrect results. | 149 // incorrect results. |
150 m_start.document()->updateLayout(); | 150 m_start.document()->updateLayout(); |
151 | 151 |
152 // Check again, because updating layout can clear the selection. | 152 // Check again, because updating layout can clear the selection. |
153 if (isNone()) | 153 if (isNone()) |
154 return 0; | 154 return nullptr; |
155 | 155 |
156 Position s, e; | 156 Position s, e; |
157 if (isCaret()) { | 157 if (isCaret()) { |
158 // If the selection is a caret, move the range start upstream. This help
s us match | 158 // If the selection is a caret, move the range start upstream. This help
s us match |
159 // the conventions of text editors tested, which make style determinatio
ns based | 159 // the conventions of text editors tested, which make style determinatio
ns based |
160 // on the character before the caret, if any. | 160 // on the character before the caret, if any. |
161 s = m_start.upstream().parentAnchoredEquivalent(); | 161 s = m_start.upstream().parentAnchoredEquivalent(); |
162 e = s; | 162 e = s; |
163 } else { | 163 } else { |
164 // If the selection is a range, select the minimum range that encompasse
s the selection. | 164 // If the selection is a range, select the minimum range that encompasse
s the selection. |
(...skipping 15 matching lines...) Expand all Loading... |
180 // The end can wind up before the start if collapsed whitespace is t
he only thing selected. | 180 // The end can wind up before the start if collapsed whitespace is t
he only thing selected. |
181 Position tmp = s; | 181 Position tmp = s; |
182 s = e; | 182 s = e; |
183 e = tmp; | 183 e = tmp; |
184 } | 184 } |
185 s = s.parentAnchoredEquivalent(); | 185 s = s.parentAnchoredEquivalent(); |
186 e = e.parentAnchoredEquivalent(); | 186 e = e.parentAnchoredEquivalent(); |
187 } | 187 } |
188 | 188 |
189 if (!s.containerNode() || !e.containerNode()) | 189 if (!s.containerNode() || !e.containerNode()) |
190 return 0; | 190 return nullptr; |
191 | 191 |
192 // VisibleSelections are supposed to always be valid. This constructor will
ASSERT | 192 // VisibleSelections are supposed to always be valid. This constructor will
ASSERT |
193 // if a valid range could not be created, which is fine for this callsite. | 193 // if a valid range could not be created, which is fine for this callsite. |
194 return Range::create(*s.document(), s, e); | 194 return Range::create(*s.document(), s, e); |
195 } | 195 } |
196 | 196 |
197 bool VisibleSelection::expandUsingGranularity(TextGranularity granularity) | 197 bool VisibleSelection::expandUsingGranularity(TextGranularity granularity) |
198 { | 198 { |
199 if (isNone()) | 199 if (isNone()) |
200 return false; | 200 return false; |
201 | 201 |
202 validate(granularity); | 202 validate(granularity); |
203 return true; | 203 return true; |
204 } | 204 } |
205 | 205 |
206 static PassRefPtr<Range> makeSearchRange(const Position& pos) | 206 static PassRefPtr<Range> makeSearchRange(const Position& pos) |
207 { | 207 { |
208 Node* n = pos.deprecatedNode(); | 208 Node* n = pos.deprecatedNode(); |
209 if (!n) | 209 if (!n) |
210 return 0; | 210 return nullptr; |
211 Document& d = n->document(); | 211 Document& d = n->document(); |
212 Node* de = d.documentElement(); | 212 Node* de = d.documentElement(); |
213 if (!de) | 213 if (!de) |
214 return 0; | 214 return nullptr; |
215 Node* boundary = n->enclosingBlockFlowElement(); | 215 Node* boundary = n->enclosingBlockFlowElement(); |
216 if (!boundary) | 216 if (!boundary) |
217 return 0; | 217 return nullptr; |
218 | 218 |
219 RefPtr<Range> searchRange(Range::create(d)); | 219 RefPtr<Range> searchRange(Range::create(d)); |
220 TrackExceptionState exceptionState; | 220 TrackExceptionState exceptionState; |
221 | 221 |
222 Position start(pos.parentAnchoredEquivalent()); | 222 Position start(pos.parentAnchoredEquivalent()); |
223 searchRange->selectNodeContents(boundary, exceptionState); | 223 searchRange->selectNodeContents(boundary, exceptionState); |
224 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(),
exceptionState); | 224 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(),
exceptionState); |
225 | 225 |
226 ASSERT(!exceptionState.hadException()); | 226 ASSERT(!exceptionState.hadException()); |
227 if (exceptionState.hadException()) | 227 if (exceptionState.hadException()) |
228 return 0; | 228 return nullptr; |
229 | 229 |
230 return searchRange.release(); | 230 return searchRange.release(); |
231 } | 231 } |
232 | 232 |
233 void VisibleSelection::appendTrailingWhitespace() | 233 void VisibleSelection::appendTrailingWhitespace() |
234 { | 234 { |
235 RefPtr<Range> searchRange = makeSearchRange(m_end); | 235 RefPtr<Range> searchRange = makeSearchRange(m_end); |
236 if (!searchRange) | 236 if (!searchRange) |
237 return; | 237 return; |
238 | 238 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 sel.showTreeForThis(); | 734 sel.showTreeForThis(); |
735 } | 735 } |
736 | 736 |
737 void showTree(const WebCore::VisibleSelection* sel) | 737 void showTree(const WebCore::VisibleSelection* sel) |
738 { | 738 { |
739 if (sel) | 739 if (sel) |
740 sel->showTreeForThis(); | 740 sel->showTreeForThis(); |
741 } | 741 } |
742 | 742 |
743 #endif | 743 #endif |
OLD | NEW |