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

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 1858163002: Rename inDocument() to inShadowIncludingDocument() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 positionOffset = node->length(); 508 positionOffset = node->length();
509 509
510 // CharacterNode in VisibleSelection must be Text node, because Comment 510 // CharacterNode in VisibleSelection must be Text node, because Comment
511 // and ProcessingInstruction node aren't visible. 511 // and ProcessingInstruction node aren't visible.
512 return Position(toText(node), positionOffset); 512 return Position(toText(node), positionOffset);
513 } 513 }
514 514
515 void FrameSelection::didUpdateCharacterData(CharacterData* node, unsigned offset , unsigned oldLength, unsigned newLength) 515 void FrameSelection::didUpdateCharacterData(CharacterData* node, unsigned offset , unsigned oldLength, unsigned newLength)
516 { 516 {
517 // The fragment check is a performance optimization. See http://trac.webkit. org/changeset/30062. 517 // The fragment check is a performance optimization. See http://trac.webkit. org/changeset/30062.
518 if (isNone() || !node || !node->inDocument()) 518 if (isNone() || !node || !node->inShadowIncludingDocument())
519 return; 519 return;
520 520
521 Position base = updatePositionAfterAdoptingTextReplacement(selection().base( ), node, offset, oldLength, newLength); 521 Position base = updatePositionAfterAdoptingTextReplacement(selection().base( ), node, offset, oldLength, newLength);
522 Position extent = updatePositionAfterAdoptingTextReplacement(selection().ext ent(), node, offset, oldLength, newLength); 522 Position extent = updatePositionAfterAdoptingTextReplacement(selection().ext ent(), node, offset, oldLength, newLength);
523 Position start = updatePositionAfterAdoptingTextReplacement(selection().star t(), node, offset, oldLength, newLength); 523 Position start = updatePositionAfterAdoptingTextReplacement(selection().star t(), node, offset, oldLength, newLength);
524 Position end = updatePositionAfterAdoptingTextReplacement(selection().end(), node, offset, oldLength, newLength); 524 Position end = updatePositionAfterAdoptingTextReplacement(selection().end(), node, offset, oldLength, newLength);
525 updateSelectionIfNeeded(base, extent, start, end); 525 updateSelectionIfNeeded(base, extent, start, end);
526 } 526 }
527 527
528 static Position updatePostionAfterAdoptingTextNodesMerged(const Position& positi on, const Text& oldNode, unsigned offset) 528 static Position updatePostionAfterAdoptingTextNodesMerged(const Position& positi on, const Text& oldNode, unsigned offset)
529 { 529 {
530 if (!position.anchorNode() || !position.isOffsetInAnchor()) 530 if (!position.anchorNode() || !position.isOffsetInAnchor())
531 return position; 531 return position;
532 532
533 ASSERT(position.offsetInContainerNode() >= 0); 533 ASSERT(position.offsetInContainerNode() >= 0);
534 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de()); 534 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de());
535 535
536 if (position.anchorNode() == &oldNode) 536 if (position.anchorNode() == &oldNode)
537 return Position(toText(oldNode.previousSibling()), positionOffset + offs et); 537 return Position(toText(oldNode.previousSibling()), positionOffset + offs et);
538 538
539 if (position.anchorNode() == oldNode.parentNode() && positionOffset == offse t) 539 if (position.anchorNode() == oldNode.parentNode() && positionOffset == offse t)
540 return Position(toText(oldNode.previousSibling()), offset); 540 return Position(toText(oldNode.previousSibling()), offset);
541 541
542 return position; 542 return position;
543 } 543 }
544 544
545 void FrameSelection::didMergeTextNodes(const Text& oldNode, unsigned offset) 545 void FrameSelection::didMergeTextNodes(const Text& oldNode, unsigned offset)
546 { 546 {
547 if (isNone() || !oldNode.inDocument()) 547 if (isNone() || !oldNode.inShadowIncludingDocument())
548 return; 548 return;
549 Position base = updatePostionAfterAdoptingTextNodesMerged(selection().base() , oldNode, offset); 549 Position base = updatePostionAfterAdoptingTextNodesMerged(selection().base() , oldNode, offset);
550 Position extent = updatePostionAfterAdoptingTextNodesMerged(selection().exte nt(), oldNode, offset); 550 Position extent = updatePostionAfterAdoptingTextNodesMerged(selection().exte nt(), oldNode, offset);
551 Position start = updatePostionAfterAdoptingTextNodesMerged(selection().start (), oldNode, offset); 551 Position start = updatePostionAfterAdoptingTextNodesMerged(selection().start (), oldNode, offset);
552 Position end = updatePostionAfterAdoptingTextNodesMerged(selection().end(), oldNode, offset); 552 Position end = updatePostionAfterAdoptingTextNodesMerged(selection().end(), oldNode, offset);
553 updateSelectionIfNeeded(base, extent, start, end); 553 updateSelectionIfNeeded(base, extent, start, end);
554 } 554 }
555 555
556 static Position updatePostionAfterAdoptingTextNodeSplit(const Position& position , const Text& oldNode) 556 static Position updatePostionAfterAdoptingTextNodeSplit(const Position& position , const Text& oldNode)
557 { 557 {
558 if (!position.anchorNode() || position.anchorNode() != &oldNode || !position .isOffsetInAnchor()) 558 if (!position.anchorNode() || position.anchorNode() != &oldNode || !position .isOffsetInAnchor())
559 return position; 559 return position;
560 // See: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2 -Range-Mutation 560 // See: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2 -Range-Mutation
561 ASSERT(position.offsetInContainerNode() >= 0); 561 ASSERT(position.offsetInContainerNode() >= 0);
562 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de()); 562 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de());
563 unsigned oldLength = oldNode.length(); 563 unsigned oldLength = oldNode.length();
564 if (positionOffset <= oldLength) 564 if (positionOffset <= oldLength)
565 return position; 565 return position;
566 return Position(toText(oldNode.nextSibling()), positionOffset - oldLength); 566 return Position(toText(oldNode.nextSibling()), positionOffset - oldLength);
567 } 567 }
568 568
569 void FrameSelection::didSplitTextNode(const Text& oldNode) 569 void FrameSelection::didSplitTextNode(const Text& oldNode)
570 { 570 {
571 if (isNone() || !oldNode.inDocument()) 571 if (isNone() || !oldNode.inShadowIncludingDocument())
572 return; 572 return;
573 Position base = updatePostionAfterAdoptingTextNodeSplit(selection().base(), oldNode); 573 Position base = updatePostionAfterAdoptingTextNodeSplit(selection().base(), oldNode);
574 Position extent = updatePostionAfterAdoptingTextNodeSplit(selection().extent (), oldNode); 574 Position extent = updatePostionAfterAdoptingTextNodeSplit(selection().extent (), oldNode);
575 Position start = updatePostionAfterAdoptingTextNodeSplit(selection().start() , oldNode); 575 Position start = updatePostionAfterAdoptingTextNodeSplit(selection().start() , oldNode);
576 Position end = updatePostionAfterAdoptingTextNodeSplit(selection().end(), ol dNode); 576 Position end = updatePostionAfterAdoptingTextNodeSplit(selection().end(), ol dNode);
577 updateSelectionIfNeeded(base, extent, start, end); 577 updateSelectionIfNeeded(base, extent, start, end);
578 } 578 }
579 579
580 void FrameSelection::updateSelectionIfNeeded(const Position& base, const Positio n& extent, const Position& start, const Position& end) 580 void FrameSelection::updateSelectionIfNeeded(const Position& base, const Positio n& extent, const Position& start, const Position& end)
581 { 581 {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 selectStartTarget = document->body(); 857 selectStartTarget = document->body();
858 } 858 }
859 } 859 }
860 if (!root || editingIgnoresContent(root.get())) 860 if (!root || editingIgnoresContent(root.get()))
861 return; 861 return;
862 862
863 if (selectStartTarget) { 863 if (selectStartTarget) {
864 if (selectStartTarget->dispatchEvent(Event::createCancelableBubble(Event TypeNames::selectstart)) != DispatchEventResult::NotCanceled) 864 if (selectStartTarget->dispatchEvent(Event::createCancelableBubble(Event TypeNames::selectstart)) != DispatchEventResult::NotCanceled)
865 return; 865 return;
866 // |root| may be detached due to selectstart event. 866 // |root| may be detached due to selectstart event.
867 if (!root->inDocument() || root->document() != document) 867 if (!root->inShadowIncludingDocument() || root->document() != document)
868 return; 868 return;
869 } 869 }
870 870
871 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode( root.get())); 871 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode( root.get()));
872 setSelection(newSelection); 872 setSelection(newSelection);
873 selectFrameElementInParentIfFullySelected(); 873 selectFrameElementInParentIfFullySelected();
874 notifyLayoutObjectOfSelectionChange(UserTriggered); 874 notifyLayoutObjectOfSelectionChange(UserTriggered);
875 } 875 }
876 876
877 bool FrameSelection::setSelectedRange(Range* range, TextAffinity affinity, Selec tionDirectionalMode directional, SetSelectionOptions options) 877 bool FrameSelection::setSelectedRange(Range* range, TextAffinity affinity, Selec tionDirectionalMode directional, SetSelectionOptions options)
878 { 878 {
879 if (!range || !range->inDocument()) 879 if (!range || !range->inShadowIncludingDocument())
880 return false; 880 return false;
881 ASSERT(range->startContainer()->document() == range->endContainer()->documen t()); 881 ASSERT(range->startContainer()->document() == range->endContainer()->documen t());
882 return setSelectedRange(EphemeralRange(range), affinity, directional, option s); 882 return setSelectedRange(EphemeralRange(range), affinity, directional, option s);
883 } 883 }
884 884
885 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, SetSelectionOptions options) 885 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, SetSelectionOptions options)
886 { 886 {
887 return m_selectionEditor->setSelectedRange(range, affinity, directional, opt ions); 887 return m_selectionEditor->setSelectedRange(range, affinity, directional, opt ions);
888 } 888 }
889 889
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 1421
1422 void showTree(const blink::FrameSelection* sel) 1422 void showTree(const blink::FrameSelection* sel)
1423 { 1423 {
1424 if (sel) 1424 if (sel)
1425 sel->showTreeForThis(); 1425 sel->showTreeForThis();
1426 else 1426 else
1427 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1427 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1428 } 1428 }
1429 1429
1430 #endif 1430 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EphemeralRange.cpp ('k') | third_party/WebKit/Source/core/editing/PendingSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698