| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 Position oldStart = m_start; | 259 Position oldStart = m_start; |
| 260 Position oldEnd = m_end; | 260 Position oldEnd = m_end; |
| 261 validate(granularity); | 261 validate(granularity); |
| 262 if (m_base != oldBase || m_extent != oldExtent || m_start != oldStart || m_e
nd != oldEnd) | 262 if (m_base != oldBase || m_extent != oldExtent || m_start != oldStart || m_e
nd != oldEnd) |
| 263 didChange(); | 263 didChange(); |
| 264 return true; | 264 return true; |
| 265 } | 265 } |
| 266 | 266 |
| 267 static PassRefPtrWillBeRawPtr<Range> makeSearchRange(const Position& pos) | 267 static PassRefPtrWillBeRawPtr<Range> makeSearchRange(const Position& pos) |
| 268 { | 268 { |
| 269 Node* n = pos.deprecatedNode(); | 269 Node* node = pos.deprecatedNode(); |
| 270 if (!n) | 270 if (!node) |
| 271 return nullptr; | 271 return nullptr; |
| 272 Document& d = n->document(); | 272 Document& document = node->document(); |
| 273 Node* de = d.documentElement(); | 273 if (!document.documentElement()) |
| 274 if (!de) | |
| 275 return nullptr; | 274 return nullptr; |
| 276 Node* boundary = enclosingBlockFlowElement(*n); | 275 Element* boundary = enclosingBlockFlowElement(*node); |
| 277 if (!boundary) | 276 if (!boundary) |
| 278 return nullptr; | 277 return nullptr; |
| 279 | 278 |
| 280 RefPtrWillBeRawPtr<Range> searchRange(Range::create(d)); | 279 RefPtrWillBeRawPtr<Range> searchRange(Range::create(document)); |
| 281 TrackExceptionState exceptionState; | 280 TrackExceptionState exceptionState; |
| 282 | 281 |
| 283 Position start(pos.parentAnchoredEquivalent()); | 282 Position start(pos.parentAnchoredEquivalent()); |
| 284 searchRange->selectNodeContents(boundary, exceptionState); | 283 searchRange->selectNodeContents(boundary, exceptionState); |
| 285 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(),
exceptionState); | 284 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(),
exceptionState); |
| 286 | 285 |
| 287 ASSERT(!exceptionState.hadException()); | 286 ASSERT(!exceptionState.hadException()); |
| 288 if (exceptionState.hadException()) | 287 if (exceptionState.hadException()) |
| 289 return nullptr; | 288 return nullptr; |
| 290 | 289 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 side = LeftWordIfOnBoundary; | 366 side = LeftWordIfOnBoundary; |
| 368 | 367 |
| 369 VisiblePosition wordEnd(endOfWord(originalEnd, side)); | 368 VisiblePosition wordEnd(endOfWord(originalEnd, side)); |
| 370 VisiblePosition end(wordEnd); | 369 VisiblePosition end(wordEnd); |
| 371 | 370 |
| 372 if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.depre
catedNode())) { | 371 if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.depre
catedNode())) { |
| 373 // Select the paragraph break (the space from the end of a parag
raph to the start of | 372 // Select the paragraph break (the space from the end of a parag
raph to the start of |
| 374 // the next one) to match TextEdit. | 373 // the next one) to match TextEdit. |
| 375 end = wordEnd.next(); | 374 end = wordEnd.next(); |
| 376 | 375 |
| 377 if (Node* table = isFirstPositionAfterTable(end)) { | 376 if (Element* table = isFirstPositionAfterTable(end)) { |
| 378 // The paragraph break after the last paragraph in the last
cell of a block table ends | 377 // The paragraph break after the last paragraph in the last
cell of a block table ends |
| 379 // at the start of the paragraph after the table. | 378 // at the start of the paragraph after the table. |
| 380 if (isBlock(table)) | 379 if (isBlock(table)) |
| 381 end = end.next(CannotCrossEditingBoundary); | 380 end = end.next(CannotCrossEditingBoundary); |
| 382 else | 381 else |
| 383 end = wordEnd; | 382 end = wordEnd; |
| 384 } | 383 } |
| 385 | 384 |
| 386 if (end.isNull()) | 385 if (end.isNull()) |
| 387 end = wordEnd; | 386 end = wordEnd; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 417 VisiblePosition pos(m_start, m_affinity); | 416 VisiblePosition pos(m_start, m_affinity); |
| 418 if (isStartOfLine(pos) && isEndOfEditableOrNonEditableContent(pos)) | 417 if (isStartOfLine(pos) && isEndOfEditableOrNonEditableContent(pos)) |
| 419 pos = pos.previous(); | 418 pos = pos.previous(); |
| 420 m_start = startOfParagraph(pos).deepEquivalent(); | 419 m_start = startOfParagraph(pos).deepEquivalent(); |
| 421 VisiblePosition visibleParagraphEnd = endOfParagraph(VisiblePosition
(m_end, m_affinity)); | 420 VisiblePosition visibleParagraphEnd = endOfParagraph(VisiblePosition
(m_end, m_affinity)); |
| 422 | 421 |
| 423 // Include the "paragraph break" (the space from the end of this par
agraph to the start | 422 // Include the "paragraph break" (the space from the end of this par
agraph to the start |
| 424 // of the next one) in the selection. | 423 // of the next one) in the selection. |
| 425 VisiblePosition end(visibleParagraphEnd.next()); | 424 VisiblePosition end(visibleParagraphEnd.next()); |
| 426 | 425 |
| 427 if (Node* table = isFirstPositionAfterTable(end)) { | 426 if (Element* table = isFirstPositionAfterTable(end)) { |
| 428 // The paragraph break after the last paragraph in the last cell
of a block table ends | 427 // The paragraph break after the last paragraph in the last cell
of a block table ends |
| 429 // at the start of the paragraph after the table, not at the pos
ition just after the table. | 428 // at the start of the paragraph after the table, not at the pos
ition just after the table. |
| 430 if (isBlock(table)) | 429 if (isBlock(table)) |
| 431 end = end.next(CannotCrossEditingBoundary); | 430 end = end.next(CannotCrossEditingBoundary); |
| 432 // There is no parargraph break after the last paragraph in the
last cell of an inline table. | 431 // There is no parargraph break after the last paragraph in the
last cell of an inline table. |
| 433 else | 432 else |
| 434 end = visibleParagraphEnd; | 433 end = visibleParagraphEnd; |
| 435 } | 434 } |
| 436 | 435 |
| 437 if (end.isNull()) | 436 if (end.isNull()) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 } else { | 623 } else { |
| 625 // FIXME: Non-editable pieces inside editable content should be atomic,
in the same way that editable | 624 // FIXME: Non-editable pieces inside editable content should be atomic,
in the same way that editable |
| 626 // pieces in non-editable content are atomic. | 625 // pieces in non-editable content are atomic. |
| 627 | 626 |
| 628 // The selection ends in editable content or non-editable content inside
a different editable ancestor, | 627 // The selection ends in editable content or non-editable content inside
a different editable ancestor, |
| 629 // move backward until non-editable content inside the same lowest edita
ble ancestor is reached. | 628 // move backward until non-editable content inside the same lowest edita
ble ancestor is reached. |
| 630 Element* endEditableAncestor = lowestEditableAncestor(m_end.containerNod
e()); | 629 Element* endEditableAncestor = lowestEditableAncestor(m_end.containerNod
e()); |
| 631 if (endRoot || endEditableAncestor != baseEditableAncestor) { | 630 if (endRoot || endEditableAncestor != baseEditableAncestor) { |
| 632 | 631 |
| 633 Position p = previousVisuallyDistinctCandidate(m_end); | 632 Position p = previousVisuallyDistinctCandidate(m_end); |
| 634 Node* shadowAncestor = endRoot ? endRoot->shadowHost() : 0; | 633 Element* shadowAncestor = endRoot ? endRoot->shadowHost() : 0; |
| 635 if (p.isNull() && shadowAncestor) | 634 if (p.isNull() && shadowAncestor) |
| 636 p = positionAfterNode(shadowAncestor); | 635 p = positionAfterNode(shadowAncestor); |
| 637 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode())
== baseEditableAncestor && !isEditablePosition(p))) { | 636 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode())
== baseEditableAncestor && !isEditablePosition(p))) { |
| 638 Node* root = editableRootForPosition(p); | 637 Element* root = editableRootForPosition(p); |
| 639 shadowAncestor = root ? root->shadowHost() : 0; | 638 shadowAncestor = root ? root->shadowHost() : 0; |
| 640 p = isAtomicNode(p.containerNode()) ? positionInParentBeforeNode
(*p.containerNode()) : previousVisuallyDistinctCandidate(p); | 639 p = isAtomicNode(p.containerNode()) ? positionInParentBeforeNode
(*p.containerNode()) : previousVisuallyDistinctCandidate(p); |
| 641 if (p.isNull() && shadowAncestor) | 640 if (p.isNull() && shadowAncestor) |
| 642 p = positionAfterNode(shadowAncestor); | 641 p = positionAfterNode(shadowAncestor); |
| 643 } | 642 } |
| 644 VisiblePosition previous(p); | 643 VisiblePosition previous(p); |
| 645 | 644 |
| 646 if (previous.isNull()) { | 645 if (previous.isNull()) { |
| 647 // The selection crosses an Editing boundary. This is a | 646 // The selection crosses an Editing boundary. This is a |
| 648 // programmer error in the editing code. Happy debugging! | 647 // programmer error in the editing code. Happy debugging! |
| 649 ASSERT_NOT_REACHED(); | 648 ASSERT_NOT_REACHED(); |
| 650 m_base = Position(); | 649 m_base = Position(); |
| 651 m_extent = Position(); | 650 m_extent = Position(); |
| 652 validate(); | 651 validate(); |
| 653 return; | 652 return; |
| 654 } | 653 } |
| 655 m_end = previous.deepEquivalent(); | 654 m_end = previous.deepEquivalent(); |
| 656 } | 655 } |
| 657 | 656 |
| 658 // The selection starts in editable content or non-editable content insi
de a different editable ancestor, | 657 // The selection starts in editable content or non-editable content insi
de a different editable ancestor, |
| 659 // move forward until non-editable content inside the same lowest editab
le ancestor is reached. | 658 // move forward until non-editable content inside the same lowest editab
le ancestor is reached. |
| 660 Element* startEditableAncestor = lowestEditableAncestor(m_start.containe
rNode()); | 659 Element* startEditableAncestor = lowestEditableAncestor(m_start.containe
rNode()); |
| 661 if (startRoot || startEditableAncestor != baseEditableAncestor) { | 660 if (startRoot || startEditableAncestor != baseEditableAncestor) { |
| 662 Position p = nextVisuallyDistinctCandidate(m_start); | 661 Position p = nextVisuallyDistinctCandidate(m_start); |
| 663 Node* shadowAncestor = startRoot ? startRoot->shadowHost() : 0; | 662 Element* shadowAncestor = startRoot ? startRoot->shadowHost() : 0; |
| 664 if (p.isNull() && shadowAncestor) | 663 if (p.isNull() && shadowAncestor) |
| 665 p = positionBeforeNode(shadowAncestor); | 664 p = positionBeforeNode(shadowAncestor); |
| 666 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode())
== baseEditableAncestor && !isEditablePosition(p))) { | 665 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode())
== baseEditableAncestor && !isEditablePosition(p))) { |
| 667 Node* root = editableRootForPosition(p); | 666 Element* root = editableRootForPosition(p); |
| 668 shadowAncestor = root ? root->shadowHost() : 0; | 667 shadowAncestor = root ? root->shadowHost() : 0; |
| 669 p = isAtomicNode(p.containerNode()) ? positionInParentAfterNode(
*p.containerNode()) : nextVisuallyDistinctCandidate(p); | 668 p = isAtomicNode(p.containerNode()) ? positionInParentAfterNode(
*p.containerNode()) : nextVisuallyDistinctCandidate(p); |
| 670 if (p.isNull() && shadowAncestor) | 669 if (p.isNull() && shadowAncestor) |
| 671 p = positionBeforeNode(shadowAncestor); | 670 p = positionBeforeNode(shadowAncestor); |
| 672 } | 671 } |
| 673 VisiblePosition next(p); | 672 VisiblePosition next(p); |
| 674 | 673 |
| 675 if (next.isNull()) { | 674 if (next.isNull()) { |
| 676 // The selection crosses an Editing boundary. This is a | 675 // The selection crosses an Editing boundary. This is a |
| 677 // programmer error in the editing code. Happy debugging! | 676 // programmer error in the editing code. Happy debugging! |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 sel.showTreeForThis(); | 856 sel.showTreeForThis(); |
| 858 } | 857 } |
| 859 | 858 |
| 860 void showTree(const blink::VisibleSelection* sel) | 859 void showTree(const blink::VisibleSelection* sel) |
| 861 { | 860 { |
| 862 if (sel) | 861 if (sel) |
| 863 sel->showTreeForThis(); | 862 sel->showTreeForThis(); |
| 864 } | 863 } |
| 865 | 864 |
| 866 #endif | 865 #endif |
| OLD | NEW |