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

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

Issue 1307803003: Introduce nextPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T18:13:02 Created 5 years, 3 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 | « no previous file | Source/core/editing/Editor.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 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 } 791 }
792 792
793 static HTMLElement* firstInSpecialElement(const Position& pos) 793 static HTMLElement* firstInSpecialElement(const Position& pos)
794 { 794 {
795 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme nt(); 795 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme nt();
796 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab leElement; n = n->parentNode()) { 796 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab leElement; n = n->parentNode()) {
797 if (isSpecialHTMLElement(*n)) { 797 if (isSpecialHTMLElement(*n)) {
798 HTMLElement* specialElement = toHTMLElement(n); 798 HTMLElement* specialElement = toHTMLElement(n);
799 VisiblePosition vPos = VisiblePosition(pos); 799 VisiblePosition vPos = VisiblePosition(pos);
800 VisiblePosition firstInElement = VisiblePosition(firstPositionInOrBe foreNode(specialElement)); 800 VisiblePosition firstInElement = VisiblePosition(firstPositionInOrBe foreNode(specialElement));
801 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent() == firstInElement.next().deepEquivalent()) 801 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent() == nextPositionOf(firstInElement).deepEquivalent())
802 return specialElement; 802 return specialElement;
803 if (vPos.deepEquivalent() == firstInElement.deepEquivalent()) 803 if (vPos.deepEquivalent() == firstInElement.deepEquivalent())
804 return specialElement; 804 return specialElement;
805 } 805 }
806 } 806 }
807 return 0; 807 return 0;
808 } 808 }
809 809
810 static HTMLElement* lastInSpecialElement(const Position& pos) 810 static HTMLElement* lastInSpecialElement(const Position& pos)
811 { 811 {
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 Position trailingWhitespacePosition(const Position& position, TextAffinity, Whit espacePositionOption option) 1359 Position trailingWhitespacePosition(const Position& position, TextAffinity, Whit espacePositionOption option)
1360 { 1360 {
1361 ASSERT(isEditablePosition(position, ContentIsEditable, DoNotUpdateStyle)); 1361 ASSERT(isEditablePosition(position, ContentIsEditable, DoNotUpdateStyle));
1362 if (position.isNull()) 1362 if (position.isNull())
1363 return Position(); 1363 return Position();
1364 1364
1365 VisiblePosition visiblePosition(position); 1365 VisiblePosition visiblePosition(position);
1366 UChar characterAfterVisiblePosition = visiblePosition.characterAfter(); 1366 UChar characterAfterVisiblePosition = visiblePosition.characterAfter();
1367 bool isSpace = option == ConsiderNonCollapsibleWhitespace ? (isSpaceOrNewlin e(characterAfterVisiblePosition) || characterAfterVisiblePosition == noBreakSpac eCharacter) : isCollapsibleWhitespace(characterAfterVisiblePosition); 1367 bool isSpace = option == ConsiderNonCollapsibleWhitespace ? (isSpaceOrNewlin e(characterAfterVisiblePosition) || characterAfterVisiblePosition == noBreakSpac eCharacter) : isCollapsibleWhitespace(characterAfterVisiblePosition);
1368 // The space must not be in another paragraph and it must be editable. 1368 // The space must not be in another paragraph and it must be editable.
1369 if (isSpace && !isEndOfParagraph(visiblePosition) && visiblePosition.next(Ca nnotCrossEditingBoundary).isNotNull()) 1369 if (isSpace && !isEndOfParagraph(visiblePosition) && nextPositionOf(visibleP osition, CannotCrossEditingBoundary).isNotNull())
1370 return position; 1370 return position;
1371 return Position(); 1371 return Position();
1372 } 1372 }
1373 1373
1374 unsigned numEnclosingMailBlockquotes(const Position& p) 1374 unsigned numEnclosingMailBlockquotes(const Position& p)
1375 { 1375 {
1376 unsigned num = 0; 1376 unsigned num = 0;
1377 for (Node* n = p.anchorNode(); n; n = n->parentNode()) { 1377 for (Node* n = p.anchorNode(); n; n = n->parentNode()) {
1378 if (isMailHTMLBlockquoteElement(n)) 1378 if (isMailHTMLBlockquoteElement(n))
1379 num++; 1379 num++;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 if (startOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table )) 1473 if (startOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table ))
1474 newSelection = VisibleSelection(startOfSelection, previousPositionOf (endOfSelection, CannotCrossEditingBoundary)); 1474 newSelection = VisibleSelection(startOfSelection, previousPositionOf (endOfSelection, CannotCrossEditingBoundary));
1475 } 1475 }
1476 1476
1477 // If the start of the selection to modify is just before a table, 1477 // If the start of the selection to modify is just before a table,
1478 // and if the end of the selection is inside that table, then the first para graph 1478 // and if the end of the selection is inside that table, then the first para graph
1479 // we'll want to modify is the first one inside the table, not the paragraph 1479 // we'll want to modify is the first one inside the table, not the paragraph
1480 // containing the table itself. 1480 // containing the table itself.
1481 if (Element* table = isLastPositionBeforeTable(startOfSelection)) { 1481 if (Element* table = isLastPositionBeforeTable(startOfSelection)) {
1482 if (endOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table)) 1482 if (endOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table))
1483 newSelection = VisibleSelection(startOfSelection.next(CannotCrossEdi tingBoundary), endOfSelection); 1483 newSelection = VisibleSelection(nextPositionOf(startOfSelection, Can notCrossEditingBoundary), endOfSelection);
1484 } 1484 }
1485 1485
1486 return newSelection; 1486 return newSelection;
1487 } 1487 }
1488 1488
1489 // FIXME: indexForVisiblePosition and visiblePositionForIndex use TextIterators to convert between 1489 // FIXME: indexForVisiblePosition and visiblePositionForIndex use TextIterators to convert between
1490 // VisiblePositions and indices. But TextIterator iteration using TextIteratorEm itsCharactersBetweenAllVisiblePositions 1490 // VisiblePositions and indices. But TextIterator iteration using TextIteratorEm itsCharactersBetweenAllVisiblePositions
1491 // does not exactly match VisiblePosition iteration, so using them to preserve a selection during an editing 1491 // does not exactly match VisiblePosition iteration, so using them to preserve a selection during an editing
1492 // opertion is unreliable. TextIterator's TextIteratorEmitsCharactersBetweenAllV isiblePositions mode needs to be fixed, 1492 // opertion is unreliable. TextIterator's TextIteratorEmitsCharactersBetweenAllV isiblePositions mode needs to be fixed,
1493 // or these functions need to be changed to iterate using actual VisiblePosition s. 1493 // or these functions need to be changed to iterate using actual VisiblePosition s.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 if (visiblePosition.isNull()) 1599 if (visiblePosition.isNull())
1600 return Position(); 1600 return Position();
1601 1601
1602 // if the selection is a caret, just return the position, since the style 1602 // if the selection is a caret, just return the position, since the style
1603 // behind us is relevant 1603 // behind us is relevant
1604 if (selection.isCaret()) 1604 if (selection.isCaret())
1605 return visiblePosition.deepEquivalent(); 1605 return visiblePosition.deepEquivalent();
1606 1606
1607 // if the selection starts just before a paragraph break, skip over it 1607 // if the selection starts just before a paragraph break, skip over it
1608 if (isEndOfParagraph(visiblePosition)) 1608 if (isEndOfParagraph(visiblePosition))
1609 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent()) ; 1609 return mostForwardCaretPosition(nextPositionOf(visiblePosition).deepEqui valent());
1610 1610
1611 // otherwise, make sure to be at the start of the first selected node, 1611 // otherwise, make sure to be at the start of the first selected node,
1612 // instead of possibly at the end of the last node before the selection 1612 // instead of possibly at the end of the last node before the selection
1613 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1613 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1614 } 1614 }
1615 1615
1616 } // namespace blink 1616 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/Editor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698