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

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

Issue 189773005: Revert of Have Position deal with more references (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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/TypingCommand.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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 463 }
464 464
465 static Position adjustPositionForEnd(const Position& currentPosition, Node* star tContainerNode) 465 static Position adjustPositionForEnd(const Position& currentPosition, Node* star tContainerNode)
466 { 466 {
467 TreeScope& treeScope = startContainerNode->treeScope(); 467 TreeScope& treeScope = startContainerNode->treeScope();
468 468
469 ASSERT(currentPosition.containerNode()->treeScope() != treeScope); 469 ASSERT(currentPosition.containerNode()->treeScope() != treeScope);
470 470
471 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.container Node())) { 471 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.container Node())) {
472 if (ancestor->contains(startContainerNode)) 472 if (ancestor->contains(startContainerNode))
473 return positionAfterNode(*ancestor); 473 return positionAfterNode(ancestor);
474 return positionBeforeNode(*ancestor); 474 return positionBeforeNode(ancestor);
475 } 475 }
476 476
477 if (Node* lastChild = treeScope.rootNode().lastChild()) 477 if (Node* lastChild = treeScope.rootNode().lastChild())
478 return positionAfterNode(*lastChild); 478 return positionAfterNode(lastChild);
479 479
480 return Position(); 480 return Position();
481 } 481 }
482 482
483 static Position adjustPositionForStart(const Position& currentPosition, Node* en dContainerNode) 483 static Position adjustPositionForStart(const Position& currentPosition, Node* en dContainerNode)
484 { 484 {
485 TreeScope& treeScope = endContainerNode->treeScope(); 485 TreeScope& treeScope = endContainerNode->treeScope();
486 486
487 ASSERT(currentPosition.containerNode()->treeScope() != treeScope); 487 ASSERT(currentPosition.containerNode()->treeScope() != treeScope);
488 488
489 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.container Node())) { 489 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.container Node())) {
490 if (ancestor->contains(endContainerNode)) 490 if (ancestor->contains(endContainerNode))
491 return positionBeforeNode(*ancestor); 491 return positionBeforeNode(ancestor);
492 return positionAfterNode(*ancestor); 492 return positionAfterNode(ancestor);
493 } 493 }
494 494
495 if (Node* firstChild = treeScope.rootNode().firstChild()) 495 if (Node* firstChild = treeScope.rootNode().firstChild())
496 return positionBeforeNode(*firstChild); 496 return positionBeforeNode(firstChild);
497 497
498 return Position(); 498 return Position();
499 } 499 }
500 500
501 void VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries() 501 void VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries()
502 { 502 {
503 if (m_base.isNull() || m_start.isNull() || m_end.isNull()) 503 if (m_base.isNull() || m_start.isNull() || m_end.isNull())
504 return; 504 return;
505 505
506 if (m_start.anchorNode()->treeScope() == m_end.anchorNode()->treeScope()) 506 if (m_start.anchorNode()->treeScope() == m_end.anchorNode()->treeScope())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // pieces in non-editable content are atomic. 560 // pieces in non-editable content are atomic.
561 561
562 // The selection ends in editable content or non-editable content inside a different editable ancestor, 562 // The selection ends in editable content or non-editable content inside a different editable ancestor,
563 // move backward until non-editable content inside the same lowest edita ble ancestor is reached. 563 // move backward until non-editable content inside the same lowest edita ble ancestor is reached.
564 Node* endEditableAncestor = lowestEditableAncestor(m_end.containerNode() ); 564 Node* endEditableAncestor = lowestEditableAncestor(m_end.containerNode() );
565 if (endRoot || endEditableAncestor != baseEditableAncestor) { 565 if (endRoot || endEditableAncestor != baseEditableAncestor) {
566 566
567 Position p = previousVisuallyDistinctCandidate(m_end); 567 Position p = previousVisuallyDistinctCandidate(m_end);
568 Node* shadowAncestor = endRoot ? endRoot->shadowHost() : 0; 568 Node* shadowAncestor = endRoot ? endRoot->shadowHost() : 0;
569 if (p.isNull() && shadowAncestor) 569 if (p.isNull() && shadowAncestor)
570 p = positionAfterNode(*shadowAncestor); 570 p = positionAfterNode(shadowAncestor);
571 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode()) == baseEditableAncestor && !isEditablePosition(p))) { 571 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode()) == baseEditableAncestor && !isEditablePosition(p))) {
572 Node* root = editableRootForPosition(p); 572 Node* root = editableRootForPosition(p);
573 shadowAncestor = root ? root->shadowHost() : 0; 573 shadowAncestor = root ? root->shadowHost() : 0;
574 p = isAtomicNode(p.containerNode()) ? positionInParentBeforeNode (*p.containerNode()) : previousVisuallyDistinctCandidate(p); 574 p = isAtomicNode(p.containerNode()) ? positionInParentBeforeNode (*p.containerNode()) : previousVisuallyDistinctCandidate(p);
575 if (p.isNull() && shadowAncestor) 575 if (p.isNull() && shadowAncestor)
576 p = positionAfterNode(*shadowAncestor); 576 p = positionAfterNode(shadowAncestor);
577 } 577 }
578 VisiblePosition previous(p); 578 VisiblePosition previous(p);
579 579
580 if (previous.isNull()) { 580 if (previous.isNull()) {
581 // The selection crosses an Editing boundary. This is a 581 // The selection crosses an Editing boundary. This is a
582 // programmer error in the editing code. Happy debugging! 582 // programmer error in the editing code. Happy debugging!
583 ASSERT_NOT_REACHED(); 583 ASSERT_NOT_REACHED();
584 m_base = Position(); 584 m_base = Position();
585 m_extent = Position(); 585 m_extent = Position();
586 validate(); 586 validate();
587 return; 587 return;
588 } 588 }
589 m_end = previous.deepEquivalent(); 589 m_end = previous.deepEquivalent();
590 } 590 }
591 591
592 // The selection starts in editable content or non-editable content insi de a different editable ancestor, 592 // The selection starts in editable content or non-editable content insi de a different editable ancestor,
593 // move forward until non-editable content inside the same lowest editab le ancestor is reached. 593 // move forward until non-editable content inside the same lowest editab le ancestor is reached.
594 Node* startEditableAncestor = lowestEditableAncestor(m_start.containerNo de()); 594 Node* startEditableAncestor = lowestEditableAncestor(m_start.containerNo de());
595 if (startRoot || startEditableAncestor != baseEditableAncestor) { 595 if (startRoot || startEditableAncestor != baseEditableAncestor) {
596 Position p = nextVisuallyDistinctCandidate(m_start); 596 Position p = nextVisuallyDistinctCandidate(m_start);
597 Node* shadowAncestor = startRoot ? startRoot->shadowHost() : 0; 597 Node* shadowAncestor = startRoot ? startRoot->shadowHost() : 0;
598 if (p.isNull() && shadowAncestor) 598 if (p.isNull() && shadowAncestor)
599 p = positionBeforeNode(*shadowAncestor); 599 p = positionBeforeNode(shadowAncestor);
600 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode()) == baseEditableAncestor && !isEditablePosition(p))) { 600 while (p.isNotNull() && !(lowestEditableAncestor(p.containerNode()) == baseEditableAncestor && !isEditablePosition(p))) {
601 Node* root = editableRootForPosition(p); 601 Node* root = editableRootForPosition(p);
602 shadowAncestor = root ? root->shadowHost() : 0; 602 shadowAncestor = root ? root->shadowHost() : 0;
603 p = isAtomicNode(p.containerNode()) ? positionInParentAfterNode( *p.containerNode()) : nextVisuallyDistinctCandidate(p); 603 p = isAtomicNode(p.containerNode()) ? positionInParentAfterNode( *p.containerNode()) : nextVisuallyDistinctCandidate(p);
604 if (p.isNull() && shadowAncestor) 604 if (p.isNull() && shadowAncestor)
605 p = positionBeforeNode(*shadowAncestor); 605 p = positionBeforeNode(shadowAncestor);
606 } 606 }
607 VisiblePosition next(p); 607 VisiblePosition next(p);
608 608
609 if (next.isNull()) { 609 if (next.isNull()) {
610 // The selection crosses an Editing boundary. This is a 610 // The selection crosses an Editing boundary. This is a
611 // programmer error in the editing code. Happy debugging! 611 // programmer error in the editing code. Happy debugging!
612 ASSERT_NOT_REACHED(); 612 ASSERT_NOT_REACHED();
613 m_base = Position(); 613 m_base = Position();
614 m_extent = Position(); 614 m_extent = Position();
615 validate(); 615 validate();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « Source/core/editing/TypingCommand.cpp ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698