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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 m_end = extent; | 463 m_end = extent; |
464 } else { | 464 } else { |
465 m_start = extent; | 465 m_start = extent; |
466 m_end = base; | 466 m_end = base; |
467 } | 467 } |
468 m_selectionType = base == extent ? CaretSelection : RangeSelection; | 468 m_selectionType = base == extent ? CaretSelection : RangeSelection; |
469 } | 469 } |
470 | 470 |
471 static Position adjustPositionForEnd(const Position& currentPosition, Node* star
tContainerNode) | 471 static Position adjustPositionForEnd(const Position& currentPosition, Node* star
tContainerNode) |
472 { | 472 { |
473 TreeScope& treeScope = startContainerNode->treeScope(); | 473 NonNullPtr<TreeScope> treeScope = startContainerNode->treeScope(); |
474 | 474 |
475 ASSERT(¤tPosition.containerNode()->treeScope() != &treeScope); | 475 ASSERT(currentPosition.containerNode()->treeScope() != treeScope); |
476 | 476 |
477 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.container
Node())) { | 477 if (Node* ancestor = treeScope->ancestorInThisScope(currentPosition.containe
rNode())) { |
478 if (ancestor->contains(startContainerNode)) | 478 if (ancestor->contains(startContainerNode)) |
479 return positionAfterNode(ancestor); | 479 return positionAfterNode(ancestor); |
480 return positionBeforeNode(ancestor); | 480 return positionBeforeNode(ancestor); |
481 } | 481 } |
482 | 482 |
483 if (Node* lastChild = treeScope.rootNode()->lastChild()) | 483 if (Node* lastChild = treeScope->rootNode()->lastChild()) |
484 return positionAfterNode(lastChild); | 484 return positionAfterNode(lastChild); |
485 | 485 |
486 return Position(); | 486 return Position(); |
487 } | 487 } |
488 | 488 |
489 static Position adjustPositionForStart(const Position& currentPosition, Node* en
dContainerNode) | 489 static Position adjustPositionForStart(const Position& currentPosition, Node* en
dContainerNode) |
490 { | 490 { |
491 TreeScope& treeScope = endContainerNode->treeScope(); | 491 NonNullPtr<TreeScope> treeScope = endContainerNode->treeScope(); |
492 | 492 |
493 ASSERT(¤tPosition.containerNode()->treeScope() != &treeScope); | 493 ASSERT(currentPosition.containerNode()->treeScope() != treeScope); |
494 | 494 |
495 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.container
Node())) { | 495 if (Node* ancestor = treeScope->ancestorInThisScope(currentPosition.containe
rNode())) { |
496 if (ancestor->contains(endContainerNode)) | 496 if (ancestor->contains(endContainerNode)) |
497 return positionBeforeNode(ancestor); | 497 return positionBeforeNode(ancestor); |
498 return positionAfterNode(ancestor); | 498 return positionAfterNode(ancestor); |
499 } | 499 } |
500 | 500 |
501 if (Node* firstChild = treeScope.rootNode()->firstChild()) | 501 if (Node* firstChild = treeScope->rootNode()->firstChild()) |
502 return positionBeforeNode(firstChild); | 502 return positionBeforeNode(firstChild); |
503 | 503 |
504 return Position(); | 504 return Position(); |
505 } | 505 } |
506 | 506 |
507 void VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries() | 507 void VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries() |
508 { | 508 { |
509 if (m_base.isNull() || m_start.isNull() || m_end.isNull()) | 509 if (m_base.isNull() || m_start.isNull() || m_end.isNull()) |
510 return; | 510 return; |
511 | 511 |
512 if (&m_start.anchorNode()->treeScope() == &m_end.anchorNode()->treeScope()) | 512 if (m_start.anchorNode()->treeScope() == m_end.anchorNode()->treeScope()) |
513 return; | 513 return; |
514 | 514 |
515 if (m_baseIsFirst) { | 515 if (m_baseIsFirst) { |
516 m_extent = adjustPositionForEnd(m_end, m_start.containerNode()); | 516 m_extent = adjustPositionForEnd(m_end, m_start.containerNode()); |
517 m_end = m_extent; | 517 m_end = m_extent; |
518 } else { | 518 } else { |
519 m_extent = adjustPositionForStart(m_start, m_end.containerNode()); | 519 m_extent = adjustPositionForStart(m_start, m_end.containerNode()); |
520 m_start = m_extent; | 520 m_start = m_extent; |
521 } | 521 } |
522 | 522 |
523 ASSERT(&m_start.anchorNode()->treeScope() == &m_end.anchorNode()->treeScope(
)); | 523 ASSERT(m_start.anchorNode()->treeScope() == m_end.anchorNode()->treeScope())
; |
524 } | 524 } |
525 | 525 |
526 void VisibleSelection::adjustSelectionToAvoidCrossingEditingBoundaries() | 526 void VisibleSelection::adjustSelectionToAvoidCrossingEditingBoundaries() |
527 { | 527 { |
528 if (m_base.isNull() || m_start.isNull() || m_end.isNull()) | 528 if (m_base.isNull() || m_start.isNull() || m_end.isNull()) |
529 return; | 529 return; |
530 | 530 |
531 Node* baseRoot = highestEditableRoot(m_base); | 531 Node* baseRoot = highestEditableRoot(m_base); |
532 Node* startRoot = highestEditableRoot(m_start); | 532 Node* startRoot = highestEditableRoot(m_start); |
533 Node* endRoot = highestEditableRoot(m_end); | 533 Node* endRoot = highestEditableRoot(m_end); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 sel.showTreeForThis(); | 740 sel.showTreeForThis(); |
741 } | 741 } |
742 | 742 |
743 void showTree(const WebCore::VisibleSelection* sel) | 743 void showTree(const WebCore::VisibleSelection* sel) |
744 { | 744 { |
745 if (sel) | 745 if (sel) |
746 sel->showTreeForThis(); | 746 sel->showTreeForThis(); |
747 } | 747 } |
748 | 748 |
749 #endif | 749 #endif |
OLD | NEW |