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

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

Issue 1245843003: [CodeHealth] Use Position::anchorNode instead of deprecatedNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
« no previous file with comments | « Source/core/editing/VisibleSelection.cpp ('k') | Source/core/editing/htmlediting.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, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 Position start = createLegacyEditingPosition(boundary, 0).parentAnchoredEqui valent(); 466 Position start = createLegacyEditingPosition(boundary, 0).parentAnchoredEqui valent();
467 Position end = pos.parentAnchoredEquivalent(); 467 Position end = pos.parentAnchoredEquivalent();
468 468
469 Vector<UChar, 1024> string; 469 Vector<UChar, 1024> string;
470 unsigned suffixLength = 0; 470 unsigned suffixLength = 0;
471 471
472 TrackExceptionState exceptionState; 472 TrackExceptionState exceptionState;
473 if (requiresContextForWordBoundary(c.characterBefore())) { 473 if (requiresContextForWordBoundary(c.characterBefore())) {
474 RefPtrWillBeRawPtr<Range> forwardsScanRange(d.createRange()); 474 RefPtrWillBeRawPtr<Range> forwardsScanRange(d.createRange());
475 forwardsScanRange->setEndAfter(boundary, exceptionState); 475 forwardsScanRange->setEndAfter(boundary, exceptionState);
476 forwardsScanRange->setStart(end.deprecatedNode(), end.deprecatedEditingO ffset(), exceptionState); 476 forwardsScanRange->setStart(end.anchorNode(), end.deprecatedEditingOffse t(), exceptionState);
477 TextIterator forwardsIterator(forwardsScanRange->startPosition(), forwar dsScanRange->endPosition()); 477 TextIterator forwardsIterator(forwardsScanRange->startPosition(), forwar dsScanRange->endPosition());
478 while (!forwardsIterator.atEnd()) { 478 while (!forwardsIterator.atEnd()) {
479 Vector<UChar, 1024> characters; 479 Vector<UChar, 1024> characters;
480 forwardsIterator.text().appendTextTo(characters); 480 forwardsIterator.text().appendTextTo(characters);
481 int i = endOfFirstWordBoundaryContext(characters.data(), characters. size()); 481 int i = endOfFirstWordBoundaryContext(characters.data(), characters. size());
482 string.append(characters.data(), i); 482 string.append(characters.data(), i);
483 suffixLength += i; 483 suffixLength += i;
484 if (static_cast<unsigned>(i) < characters.size()) 484 if (static_cast<unsigned>(i) < characters.size())
485 break; 485 break;
486 forwardsIterator.advance(); 486 forwardsIterator.advance();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 int length = characters.size(); 554 int length = characters.size();
555 int i = startOfLastWordBoundaryContext(characters.data(), length); 555 int i = startOfLastWordBoundaryContext(characters.data(), length);
556 string.prepend(characters.data() + i, length - i); 556 string.prepend(characters.data() + i, length - i);
557 prefixLength += length - i; 557 prefixLength += length - i;
558 if (i > 0) 558 if (i > 0)
559 break; 559 break;
560 backwardsIterator.advance(); 560 backwardsIterator.advance();
561 } 561 }
562 } 562 }
563 563
564 Position searchStart = createLegacyEditingPosition(start.deprecatedNode(), s tart.deprecatedEditingOffset()); 564 Position searchStart = createLegacyEditingPosition(start.anchorNode(), start .deprecatedEditingOffset());
565 RangeBoundaryPoint searchEndPoint(boundary); 565 RangeBoundaryPoint searchEndPoint(boundary);
566 searchEndPoint.setToEndOfNode(*boundary); 566 searchEndPoint.setToEndOfNode(*boundary);
567 Position searchEnd = searchEndPoint.toPosition(); 567 Position searchEnd = searchEndPoint.toPosition();
568 TextIterator it(searchStart, searchEnd, TextIteratorEmitsCharactersBetweenAl lVisiblePositions); 568 TextIterator it(searchStart, searchEnd, TextIteratorEmitsCharactersBetweenAl lVisiblePositions);
569 const unsigned invalidOffset = static_cast<unsigned>(-1); 569 const unsigned invalidOffset = static_cast<unsigned>(-1);
570 unsigned next = invalidOffset; 570 unsigned next = invalidOffset;
571 bool needMoreContext = false; 571 bool needMoreContext = false;
572 while (!it.atEnd()) { 572 while (!it.atEnd()) {
573 // Keep asking the iterator for chunks until the search function 573 // Keep asking the iterator for chunks until the search function
574 // returns an end value not equal to the length of the string passed to it. 574 // returns an end value not equal to the length of the string passed to it.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 using PositionType = typename PositionWithAffinityType::PositionType; 717 using PositionType = typename PositionWithAffinityType::PositionType;
718 718
719 if (c.isNull()) 719 if (c.isNull())
720 return PositionWithAffinityType(); 720 return PositionWithAffinityType();
721 721
722 RootInlineBox* rootBox = RenderedPosition(c.position(), c.affinity()).rootBo x(); 722 RootInlineBox* rootBox = RenderedPosition(c.position(), c.affinity()).rootBo x();
723 if (!rootBox) { 723 if (!rootBox) {
724 // There are VisiblePositions at offset 0 in blocks without 724 // There are VisiblePositions at offset 0 in blocks without
725 // RootInlineBoxes, like empty editable blocks and bordered blocks. 725 // RootInlineBoxes, like empty editable blocks and bordered blocks.
726 PositionType p = c.position(); 726 PositionType p = c.position();
727 if (p.deprecatedNode()->layoutObject() && p.deprecatedNode()->layoutObje ct()->isLayoutBlock() && !p.deprecatedEditingOffset()) 727 if (p.anchorNode()->layoutObject() && p.anchorNode()->layoutObject()->is LayoutBlock() && !p.deprecatedEditingOffset())
728 return c; 728 return c;
729 729
730 return PositionWithAffinityType(); 730 return PositionWithAffinityType();
731 } 731 }
732 732
733 Node* startNode; 733 Node* startNode;
734 InlineBox* startBox; 734 InlineBox* startBox;
735 if (mode == UseLogicalOrdering) { 735 if (mode == UseLogicalOrdering) {
736 startNode = rootBox->getLogicalStartBoxWithNode(startBox); 736 startNode = rootBox->getLogicalStartBoxWithNode(startBox);
737 if (!startNode) 737 if (!startNode)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint ComputationMode mode) 797 static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint ComputationMode mode)
798 { 798 {
799 if (c.isNull()) 799 if (c.isNull())
800 return VisiblePosition(); 800 return VisiblePosition();
801 801
802 RootInlineBox* rootBox = RenderedPosition(c).rootBox(); 802 RootInlineBox* rootBox = RenderedPosition(c).rootBox();
803 if (!rootBox) { 803 if (!rootBox) {
804 // There are VisiblePositions at offset 0 in blocks without 804 // There are VisiblePositions at offset 0 in blocks without
805 // RootInlineBoxes, like empty editable blocks and bordered blocks. 805 // RootInlineBoxes, like empty editable blocks and bordered blocks.
806 Position p = c.deepEquivalent(); 806 Position p = c.deepEquivalent();
807 if (p.deprecatedNode()->layoutObject() && p.deprecatedNode()->layoutObje ct()->isLayoutBlock() && !p.deprecatedEditingOffset()) 807 if (p.anchorNode()->layoutObject() && p.anchorNode()->layoutObject()->is LayoutBlock() && !p.deprecatedEditingOffset())
808 return c; 808 return c;
809 return VisiblePosition(); 809 return VisiblePosition();
810 } 810 }
811 811
812 Node* endNode; 812 Node* endNode;
813 InlineBox* endBox; 813 InlineBox* endBox;
814 if (mode == UseLogicalOrdering) { 814 if (mode == UseLogicalOrdering) {
815 endNode = rootBox->getLogicalEndBoxWithNode(endBox); 815 endNode = rootBox->getLogicalEndBoxWithNode(endBox);
816 if (!endNode) 816 if (!endNode)
817 return VisiblePosition(); 817 return VisiblePosition();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 956
957 if (root->block().isHorizontalWritingMode()) 957 if (root->block().isHorizontalWritingMode())
958 return LayoutPoint(lineDirectionPoint - absoluteBlockPoint.x(), root->bl ockDirectionPointInLine()); 958 return LayoutPoint(lineDirectionPoint - absoluteBlockPoint.x(), root->bl ockDirectionPointInLine());
959 959
960 return LayoutPoint(root->blockDirectionPointInLine(), lineDirectionPoint - a bsoluteBlockPoint.y()); 960 return LayoutPoint(root->blockDirectionPointInLine(), lineDirectionPoint - a bsoluteBlockPoint.y());
961 } 961 }
962 962
963 VisiblePosition previousLinePosition(const VisiblePosition &visiblePosition, Lay outUnit lineDirectionPoint, EditableType editableType) 963 VisiblePosition previousLinePosition(const VisiblePosition &visiblePosition, Lay outUnit lineDirectionPoint, EditableType editableType)
964 { 964 {
965 Position p = visiblePosition.deepEquivalent(); 965 Position p = visiblePosition.deepEquivalent();
966 Node* node = p.deprecatedNode(); 966 Node* node = p.anchorNode();
967 967
968 if (!node) 968 if (!node)
969 return VisiblePosition(); 969 return VisiblePosition();
970 970
971 node->document().updateLayoutIgnorePendingStylesheets(); 971 node->document().updateLayoutIgnorePendingStylesheets();
972 972
973 LayoutObject* layoutObject = node->layoutObject(); 973 LayoutObject* layoutObject = node->layoutObject();
974 if (!layoutObject) 974 if (!layoutObject)
975 return VisiblePosition(); 975 return VisiblePosition();
976 976
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 // to the start of the line we're on. 1009 // to the start of the line we're on.
1010 Element* rootElement = node->hasEditableStyle(editableType) ? node->rootEdit ableElement(editableType) : node->document().documentElement(); 1010 Element* rootElement = node->hasEditableStyle(editableType) ? node->rootEdit ableElement(editableType) : node->document().documentElement();
1011 if (!rootElement) 1011 if (!rootElement)
1012 return VisiblePosition(); 1012 return VisiblePosition();
1013 return VisiblePosition(firstPositionInNode(rootElement), DOWNSTREAM); 1013 return VisiblePosition(firstPositionInNode(rootElement), DOWNSTREAM);
1014 } 1014 }
1015 1015
1016 VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, LayoutU nit lineDirectionPoint, EditableType editableType) 1016 VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, LayoutU nit lineDirectionPoint, EditableType editableType)
1017 { 1017 {
1018 Position p = visiblePosition.deepEquivalent(); 1018 Position p = visiblePosition.deepEquivalent();
1019 Node* node = p.deprecatedNode(); 1019 Node* node = p.anchorNode();
1020 1020
1021 if (!node) 1021 if (!node)
1022 return VisiblePosition(); 1022 return VisiblePosition();
1023 1023
1024 node->document().updateLayoutIgnorePendingStylesheets(); 1024 node->document().updateLayoutIgnorePendingStylesheets();
1025 1025
1026 LayoutObject* layoutObject = node->layoutObject(); 1026 LayoutObject* layoutObject = node->layoutObject();
1027 if (!layoutObject) 1027 if (!layoutObject)
1028 return VisiblePosition(); 1028 return VisiblePosition();
1029 1029
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1119
1120 VisiblePosition nextSentencePosition(const VisiblePosition &c) 1120 VisiblePosition nextSentencePosition(const VisiblePosition &c)
1121 { 1121 {
1122 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary); 1122 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary);
1123 return c.honorEditingBoundaryAtOrAfter(next); 1123 return c.honorEditingBoundaryAtOrAfter(next);
1124 } 1124 }
1125 1125
1126 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi ngRule boundaryCrossingRule) 1126 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi ngRule boundaryCrossingRule)
1127 { 1127 {
1128 Position p = c.deepEquivalent(); 1128 Position p = c.deepEquivalent();
1129 Node* startNode = p.deprecatedNode(); 1129 Node* startNode = p.anchorNode();
1130 1130
1131 if (!startNode) 1131 if (!startNode)
1132 return VisiblePosition(); 1132 return VisiblePosition();
1133 1133
1134 if (isRenderedAsNonInlineTableImageOrHR(startNode)) 1134 if (isRenderedAsNonInlineTableImageOrHR(startNode))
1135 return VisiblePosition(positionBeforeNode(startNode)); 1135 return VisiblePosition(positionBeforeNode(startNode));
1136 1136
1137 Element* startBlock = enclosingBlock(startNode); 1137 Element* startBlock = enclosingBlock(startNode);
1138 1138
1139 Node* node = startNode; 1139 Node* node = startNode;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 1197
1198 return VisiblePosition(Position(node, type), DOWNSTREAM); 1198 return VisiblePosition(Position(node, type), DOWNSTREAM);
1199 } 1199 }
1200 1200
1201 VisiblePosition endOfParagraph(const VisiblePosition &c, EditingBoundaryCrossing Rule boundaryCrossingRule) 1201 VisiblePosition endOfParagraph(const VisiblePosition &c, EditingBoundaryCrossing Rule boundaryCrossingRule)
1202 { 1202 {
1203 if (c.isNull()) 1203 if (c.isNull())
1204 return VisiblePosition(); 1204 return VisiblePosition();
1205 1205
1206 Position p = c.deepEquivalent(); 1206 Position p = c.deepEquivalent();
1207 Node* startNode = p.deprecatedNode(); 1207 Node* startNode = p.anchorNode();
1208 1208
1209 if (isRenderedAsNonInlineTableImageOrHR(startNode)) 1209 if (isRenderedAsNonInlineTableImageOrHR(startNode))
1210 return VisiblePosition(positionAfterNode(startNode)); 1210 return VisiblePosition(positionAfterNode(startNode));
1211 1211
1212 Element* startBlock = enclosingBlock(startNode); 1212 Element* startBlock = enclosingBlock(startNode);
1213 Element* stayInsideBlock = startBlock; 1213 Element* stayInsideBlock = startBlock;
1214 1214
1215 Node* node = startNode; 1215 Node* node = startNode;
1216 ContainerNode* highestRoot = highestEditableRoot(p); 1216 ContainerNode* highestRoot = highestEditableRoot(p);
1217 int offset = p.deprecatedEditingOffset(); 1217 int offset = p.deprecatedEditingOffset();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 VisiblePosition startOfDocument(const Node* node) 1361 VisiblePosition startOfDocument(const Node* node)
1362 { 1362 {
1363 if (!node || !node->document().documentElement()) 1363 if (!node || !node->document().documentElement())
1364 return VisiblePosition(); 1364 return VisiblePosition();
1365 1365
1366 return VisiblePosition(firstPositionInNode(node->document().documentElement( )), DOWNSTREAM); 1366 return VisiblePosition(firstPositionInNode(node->document().documentElement( )), DOWNSTREAM);
1367 } 1367 }
1368 1368
1369 VisiblePosition startOfDocument(const VisiblePosition &c) 1369 VisiblePosition startOfDocument(const VisiblePosition &c)
1370 { 1370 {
1371 return startOfDocument(c.deepEquivalent().deprecatedNode()); 1371 return startOfDocument(c.deepEquivalent().anchorNode());
1372 } 1372 }
1373 1373
1374 VisiblePosition endOfDocument(const Node* node) 1374 VisiblePosition endOfDocument(const Node* node)
1375 { 1375 {
1376 if (!node || !node->document().documentElement()) 1376 if (!node || !node->document().documentElement())
1377 return VisiblePosition(); 1377 return VisiblePosition();
1378 1378
1379 Element* doc = node->document().documentElement(); 1379 Element* doc = node->document().documentElement();
1380 return VisiblePosition(lastPositionInNode(doc), DOWNSTREAM); 1380 return VisiblePosition(lastPositionInNode(doc), DOWNSTREAM);
1381 } 1381 }
1382 1382
1383 VisiblePosition endOfDocument(const VisiblePosition &c) 1383 VisiblePosition endOfDocument(const VisiblePosition &c)
1384 { 1384 {
1385 return endOfDocument(c.deepEquivalent().deprecatedNode()); 1385 return endOfDocument(c.deepEquivalent().anchorNode());
1386 } 1386 }
1387 1387
1388 bool isStartOfDocument(const VisiblePosition &p) 1388 bool isStartOfDocument(const VisiblePosition &p)
1389 { 1389 {
1390 return p.isNotNull() && p.previous(CanCrossEditingBoundary).isNull(); 1390 return p.isNotNull() && p.previous(CanCrossEditingBoundary).isNull();
1391 } 1391 }
1392 1392
1393 bool isEndOfDocument(const VisiblePosition &p) 1393 bool isEndOfDocument(const VisiblePosition &p)
1394 { 1394 {
1395 return p.isNotNull() && p.next(CanCrossEditingBoundary).isNull(); 1395 return p.isNotNull() && p.next(CanCrossEditingBoundary).isNull();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | H itTestRequest::Active | HitTestRequest::IgnoreClipping; 1455 HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | H itTestRequest::Active | HitTestRequest::IgnoreClipping;
1456 HitTestResult result(request, contentsPoint); 1456 HitTestResult result(request, contentsPoint);
1457 frame->document()->layoutView()->hitTest(result); 1457 frame->document()->layoutView()->hitTest(result);
1458 1458
1459 if (Node* node = result.innerNode()) 1459 if (Node* node = result.innerNode())
1460 return frame->selection().selection().visiblePositionRespectingEditingBo undary(result.localPoint(), node); 1460 return frame->selection().selection().visiblePositionRespectingEditingBo undary(result.localPoint(), node);
1461 return VisiblePosition(); 1461 return VisiblePosition();
1462 } 1462 }
1463 1463
1464 } 1464 }
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.cpp ('k') | Source/core/editing/htmlediting.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698