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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return true; | 288 return true; |
289 } | 289 } |
290 | 290 |
291 bool VisibleSelection::expandUsingGranularityInComposedTree(TextGranularity gran
ularity) | 291 bool VisibleSelection::expandUsingGranularityInComposedTree(TextGranularity gran
ularity) |
292 { | 292 { |
293 m_base = toPositionInDOMTree(baseInComposedTree()); | 293 m_base = toPositionInDOMTree(baseInComposedTree()); |
294 m_extent = toPositionInDOMTree(extentInComposedTree()); | 294 m_extent = toPositionInDOMTree(extentInComposedTree()); |
295 return expandUsingGranularity(granularity); | 295 return expandUsingGranularity(granularity); |
296 } | 296 } |
297 | 297 |
298 static PassRefPtrWillBeRawPtr<Range> makeSearchRange(const Position& pos) | 298 template <typename Strategy> |
| 299 static EphemeralRangeTemplate<Strategy> makeSearchRange(const PositionAlgorithm<
Strategy>& pos) |
299 { | 300 { |
300 Node* node = pos.anchorNode(); | 301 Node* node = pos.anchorNode(); |
301 if (!node) | 302 if (!node) |
302 return nullptr; | 303 return EphemeralRangeTemplate<Strategy>(); |
303 Document& document = node->document(); | 304 Document& document = node->document(); |
304 if (!document.documentElement()) | 305 if (!document.documentElement()) |
305 return nullptr; | 306 return EphemeralRangeTemplate<Strategy>(); |
306 Element* boundary = enclosingBlockFlowElement(*node); | 307 Element* boundary = enclosingBlockFlowElement(*node); |
307 if (!boundary) | 308 if (!boundary) |
308 return nullptr; | 309 return EphemeralRangeTemplate<Strategy>(); |
309 | 310 |
310 RefPtrWillBeRawPtr<Range> searchRange(Range::create(document)); | 311 return EphemeralRangeTemplate<Strategy>(pos, PositionAlgorithm<Strategy>::la
stPositionInNode(boundary)); |
311 TrackExceptionState exceptionState; | |
312 | |
313 Position start(pos.parentAnchoredEquivalent()); | |
314 searchRange->selectNodeContents(boundary, exceptionState); | |
315 searchRange->setStart(start.computeContainerNode(), start.offsetInContainerN
ode(), exceptionState); | |
316 | |
317 ASSERT(!exceptionState.hadException()); | |
318 if (exceptionState.hadException()) | |
319 return nullptr; | |
320 | |
321 return searchRange.release(); | |
322 } | 312 } |
323 | 313 |
324 void VisibleSelection::appendTrailingWhitespace() | 314 void VisibleSelection::appendTrailingWhitespace() |
325 { | 315 { |
326 RefPtrWillBeRawPtr<Range> searchRange = makeSearchRange(m_end); | 316 const EphemeralRange searchRange = makeSearchRange(m_end); |
327 if (!searchRange) | 317 if (searchRange.isNull()) |
328 return; | 318 return; |
329 | 319 |
330 CharacterIterator charIt(searchRange->startPosition(), searchRange->endPosit
ion(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); | 320 CharacterIterator charIt(searchRange.startPosition(), searchRange.endPositio
n(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); |
331 bool changed = false; | 321 bool changed = false; |
332 | 322 |
333 for (; charIt.length(); charIt.advance(1)) { | 323 for (; charIt.length(); charIt.advance(1)) { |
334 UChar c = charIt.characterAt(0); | 324 UChar c = charIt.characterAt(0); |
335 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') | 325 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') |
336 break; | 326 break; |
337 m_end = charIt.endPosition(); | 327 m_end = charIt.endPosition(); |
338 m_endInComposedTree = toPositionInComposedTree(m_end); | 328 m_endInComposedTree = toPositionInComposedTree(m_end); |
339 changed = true; | 329 changed = true; |
340 } | 330 } |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 sel.showTreeForThis(); | 1393 sel.showTreeForThis(); |
1404 } | 1394 } |
1405 | 1395 |
1406 void showTree(const blink::VisibleSelection* sel) | 1396 void showTree(const blink::VisibleSelection* sel) |
1407 { | 1397 { |
1408 if (sel) | 1398 if (sel) |
1409 sel->showTreeForThis(); | 1399 sel->showTreeForThis(); |
1410 } | 1400 } |
1411 | 1401 |
1412 #endif | 1402 #endif |
OLD | NEW |