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

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

Issue 2149893003: Rename Node::inShadowIncludingDocument() to Node::isConnected() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed Created 4 years, 5 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 244
245 template <typename Strategy> 245 template <typename Strategy>
246 void FrameSelection::setNonDirectionalSelectionIfNeededAlgorithm(const VisibleSe lectionTemplate<Strategy>& passedNewSelection, TextGranularity granularity, 246 void FrameSelection::setNonDirectionalSelectionIfNeededAlgorithm(const VisibleSe lectionTemplate<Strategy>& passedNewSelection, TextGranularity granularity,
247 EndPointsAdjustmentMode endpointsAdjustmentMode) 247 EndPointsAdjustmentMode endpointsAdjustmentMode)
248 { 248 {
249 VisibleSelectionTemplate<Strategy> newSelection = passedNewSelection; 249 VisibleSelectionTemplate<Strategy> newSelection = passedNewSelection;
250 bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSele ction.isDirectional(); 250 bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSele ction.isDirectional();
251 251
252 const PositionTemplate<Strategy> basePosition = this->originalBase<Strategy> ().deepEquivalent(); 252 const PositionTemplate<Strategy> basePosition = this->originalBase<Strategy> ().deepEquivalent();
253 const VisiblePositionTemplate<Strategy> originalBase = basePosition.inShadow IncludingDocument() ? createVisiblePosition(basePosition) : VisiblePositionTempl ate<Strategy>(); 253 const VisiblePositionTemplate<Strategy> originalBase = basePosition.isConnec ted() ? createVisiblePosition(basePosition) : VisiblePositionTemplate<Strategy>( );
254 const VisiblePositionTemplate<Strategy> base = originalBase.isNotNull() ? or iginalBase : createVisiblePosition(newSelection.base()); 254 const VisiblePositionTemplate<Strategy> base = originalBase.isNotNull() ? or iginalBase : createVisiblePosition(newSelection.base());
255 VisiblePositionTemplate<Strategy> newBase = base; 255 VisiblePositionTemplate<Strategy> newBase = base;
256 const VisiblePositionTemplate<Strategy> extent = createVisiblePosition(newSe lection.extent()); 256 const VisiblePositionTemplate<Strategy> extent = createVisiblePosition(newSe lection.extent());
257 VisiblePositionTemplate<Strategy> newExtent = extent; 257 VisiblePositionTemplate<Strategy> newExtent = extent;
258 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary) 258 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary)
259 adjustEndpointsAtBidiBoundary(newBase, newExtent); 259 adjustEndpointsAtBidiBoundary(newBase, newExtent);
260 260
261 if (newBase.deepEquivalent() != base.deepEquivalent() || newExtent.deepEquiv alent() != extent.deepEquivalent()) { 261 if (newBase.deepEquivalent() != base.deepEquivalent() || newExtent.deepEquiv alent() != extent.deepEquivalent()) {
262 setOriginalBase(base); 262 setOriginalBase(base);
263 newSelection.setBase(newBase); 263 newSelection.setBase(newBase);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 positionOffset = node->length(); 518 positionOffset = node->length();
519 519
520 // CharacterNode in VisibleSelection must be Text node, because Comment 520 // CharacterNode in VisibleSelection must be Text node, because Comment
521 // and ProcessingInstruction node aren't visible. 521 // and ProcessingInstruction node aren't visible.
522 return Position(toText(node), positionOffset); 522 return Position(toText(node), positionOffset);
523 } 523 }
524 524
525 void FrameSelection::didUpdateCharacterData(CharacterData* node, unsigned offset , unsigned oldLength, unsigned newLength) 525 void FrameSelection::didUpdateCharacterData(CharacterData* node, unsigned offset , unsigned oldLength, unsigned newLength)
526 { 526 {
527 // The fragment check is a performance optimization. See http://trac.webkit. org/changeset/30062. 527 // The fragment check is a performance optimization. See http://trac.webkit. org/changeset/30062.
528 if (isNone() || !node || !node->inShadowIncludingDocument()) 528 if (isNone() || !node || !node->isConnected())
529 return; 529 return;
530 530
531 Position base = updatePositionAfterAdoptingTextReplacement(selection().base( ), node, offset, oldLength, newLength); 531 Position base = updatePositionAfterAdoptingTextReplacement(selection().base( ), node, offset, oldLength, newLength);
532 Position extent = updatePositionAfterAdoptingTextReplacement(selection().ext ent(), node, offset, oldLength, newLength); 532 Position extent = updatePositionAfterAdoptingTextReplacement(selection().ext ent(), node, offset, oldLength, newLength);
533 Position start = updatePositionAfterAdoptingTextReplacement(selection().star t(), node, offset, oldLength, newLength); 533 Position start = updatePositionAfterAdoptingTextReplacement(selection().star t(), node, offset, oldLength, newLength);
534 Position end = updatePositionAfterAdoptingTextReplacement(selection().end(), node, offset, oldLength, newLength); 534 Position end = updatePositionAfterAdoptingTextReplacement(selection().end(), node, offset, oldLength, newLength);
535 updateSelectionIfNeeded(base, extent, start, end); 535 updateSelectionIfNeeded(base, extent, start, end);
536 } 536 }
537 537
538 static Position updatePostionAfterAdoptingTextNodesMerged(const Position& positi on, const Text& oldNode, unsigned offset) 538 static Position updatePostionAfterAdoptingTextNodesMerged(const Position& positi on, const Text& oldNode, unsigned offset)
539 { 539 {
540 if (!position.anchorNode() || !position.isOffsetInAnchor()) 540 if (!position.anchorNode() || !position.isOffsetInAnchor())
541 return position; 541 return position;
542 542
543 DCHECK_GE(position.offsetInContainerNode(), 0); 543 DCHECK_GE(position.offsetInContainerNode(), 0);
544 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de()); 544 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de());
545 545
546 if (position.anchorNode() == &oldNode) 546 if (position.anchorNode() == &oldNode)
547 return Position(toText(oldNode.previousSibling()), positionOffset + offs et); 547 return Position(toText(oldNode.previousSibling()), positionOffset + offs et);
548 548
549 if (position.anchorNode() == oldNode.parentNode() && positionOffset == offse t) 549 if (position.anchorNode() == oldNode.parentNode() && positionOffset == offse t)
550 return Position(toText(oldNode.previousSibling()), offset); 550 return Position(toText(oldNode.previousSibling()), offset);
551 551
552 return position; 552 return position;
553 } 553 }
554 554
555 void FrameSelection::didMergeTextNodes(const Text& oldNode, unsigned offset) 555 void FrameSelection::didMergeTextNodes(const Text& oldNode, unsigned offset)
556 { 556 {
557 if (isNone() || !oldNode.inShadowIncludingDocument()) 557 if (isNone() || !oldNode.isConnected())
558 return; 558 return;
559 Position base = updatePostionAfterAdoptingTextNodesMerged(selection().base() , oldNode, offset); 559 Position base = updatePostionAfterAdoptingTextNodesMerged(selection().base() , oldNode, offset);
560 Position extent = updatePostionAfterAdoptingTextNodesMerged(selection().exte nt(), oldNode, offset); 560 Position extent = updatePostionAfterAdoptingTextNodesMerged(selection().exte nt(), oldNode, offset);
561 Position start = updatePostionAfterAdoptingTextNodesMerged(selection().start (), oldNode, offset); 561 Position start = updatePostionAfterAdoptingTextNodesMerged(selection().start (), oldNode, offset);
562 Position end = updatePostionAfterAdoptingTextNodesMerged(selection().end(), oldNode, offset); 562 Position end = updatePostionAfterAdoptingTextNodesMerged(selection().end(), oldNode, offset);
563 updateSelectionIfNeeded(base, extent, start, end); 563 updateSelectionIfNeeded(base, extent, start, end);
564 } 564 }
565 565
566 static Position updatePostionAfterAdoptingTextNodeSplit(const Position& position , const Text& oldNode) 566 static Position updatePostionAfterAdoptingTextNodeSplit(const Position& position , const Text& oldNode)
567 { 567 {
568 if (!position.anchorNode() || position.anchorNode() != &oldNode || !position .isOffsetInAnchor()) 568 if (!position.anchorNode() || position.anchorNode() != &oldNode || !position .isOffsetInAnchor())
569 return position; 569 return position;
570 // See: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2 -Range-Mutation 570 // See: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2 -Range-Mutation
571 DCHECK_GE(position.offsetInContainerNode(), 0); 571 DCHECK_GE(position.offsetInContainerNode(), 0);
572 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de()); 572 unsigned positionOffset = static_cast<unsigned>(position.offsetInContainerNo de());
573 unsigned oldLength = oldNode.length(); 573 unsigned oldLength = oldNode.length();
574 if (positionOffset <= oldLength) 574 if (positionOffset <= oldLength)
575 return position; 575 return position;
576 return Position(toText(oldNode.nextSibling()), positionOffset - oldLength); 576 return Position(toText(oldNode.nextSibling()), positionOffset - oldLength);
577 } 577 }
578 578
579 void FrameSelection::didSplitTextNode(const Text& oldNode) 579 void FrameSelection::didSplitTextNode(const Text& oldNode)
580 { 580 {
581 if (isNone() || !oldNode.inShadowIncludingDocument()) 581 if (isNone() || !oldNode.isConnected())
582 return; 582 return;
583 Position base = updatePostionAfterAdoptingTextNodeSplit(selection().base(), oldNode); 583 Position base = updatePostionAfterAdoptingTextNodeSplit(selection().base(), oldNode);
584 Position extent = updatePostionAfterAdoptingTextNodeSplit(selection().extent (), oldNode); 584 Position extent = updatePostionAfterAdoptingTextNodeSplit(selection().extent (), oldNode);
585 Position start = updatePostionAfterAdoptingTextNodeSplit(selection().start() , oldNode); 585 Position start = updatePostionAfterAdoptingTextNodeSplit(selection().start() , oldNode);
586 Position end = updatePostionAfterAdoptingTextNodeSplit(selection().end(), ol dNode); 586 Position end = updatePostionAfterAdoptingTextNodeSplit(selection().end(), ol dNode);
587 updateSelectionIfNeeded(base, extent, start, end); 587 updateSelectionIfNeeded(base, extent, start, end);
588 } 588 }
589 589
590 void FrameSelection::updateSelectionIfNeeded(const Position& base, const Positio n& extent, const Position& start, const Position& end) 590 void FrameSelection::updateSelectionIfNeeded(const Position& base, const Positio n& extent, const Position& start, const Position& end)
591 { 591 {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 } 847 }
848 } 848 }
849 if (!root || editingIgnoresContent(root)) 849 if (!root || editingIgnoresContent(root))
850 return; 850 return;
851 851
852 if (selectStartTarget) { 852 if (selectStartTarget) {
853 const Document& expectedDocument = document(); 853 const Document& expectedDocument = document();
854 if (selectStartTarget->dispatchEvent(Event::createCancelableBubble(Event TypeNames::selectstart)) != DispatchEventResult::NotCanceled) 854 if (selectStartTarget->dispatchEvent(Event::createCancelableBubble(Event TypeNames::selectstart)) != DispatchEventResult::NotCanceled)
855 return; 855 return;
856 // |root| may be detached due to selectstart event. 856 // |root| may be detached due to selectstart event.
857 if (!root->inShadowIncludingDocument() || expectedDocument != root->docu ment()) 857 if (!root->isConnected() || expectedDocument != root->document())
858 return; 858 return;
859 } 859 }
860 860
861 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode( root)); 861 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode( root));
862 setSelection(newSelection); 862 setSelection(newSelection);
863 selectFrameElementInParentIfFullySelected(); 863 selectFrameElementInParentIfFullySelected();
864 notifyLayoutObjectOfSelectionChange(UserTriggered); 864 notifyLayoutObjectOfSelectionChange(UserTriggered);
865 } 865 }
866 866
867 bool FrameSelection::setSelectedRange(Range* range, TextAffinity affinity, Selec tionDirectionalMode directional, SetSelectionOptions options) 867 bool FrameSelection::setSelectedRange(Range* range, TextAffinity affinity, Selec tionDirectionalMode directional, SetSelectionOptions options)
868 { 868 {
869 if (!range || !range->inShadowIncludingDocument()) 869 if (!range || !range->isConnected())
870 return false; 870 return false;
871 DCHECK_EQ(range->startContainer()->document(), range->endContainer()->docume nt()); 871 DCHECK_EQ(range->startContainer()->document(), range->endContainer()->docume nt());
872 return setSelectedRange(EphemeralRange(range), affinity, directional, option s); 872 return setSelectedRange(EphemeralRange(range), affinity, directional, option s);
873 } 873 }
874 874
875 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, SetSelectionOptions options) 875 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, SetSelectionOptions options)
876 { 876 {
877 if (range.isNull()) 877 if (range.isNull())
878 return false; 878 return false;
879 m_selectionEditor->resetLogicalRange(); 879 m_selectionEditor->resetLogicalRange();
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1381
1382 void showTree(const blink::FrameSelection* sel) 1382 void showTree(const blink::FrameSelection* sel)
1383 { 1383 {
1384 if (sel) 1384 if (sel)
1385 sel->showTreeForThis(); 1385 sel->showTreeForThis();
1386 else 1386 else
1387 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1387 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1388 } 1388 }
1389 1389
1390 #endif 1390 #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