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

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

Issue 1310043003: Introduce previousPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T16:28:03 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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 } 808 }
809 809
810 static HTMLElement* lastInSpecialElement(const Position& pos) 810 static HTMLElement* lastInSpecialElement(const Position& pos)
811 { 811 {
812 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme nt(); 812 Element* rootEditableElement = pos.computeContainerNode()->rootEditableEleme nt();
813 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab leElement; n = n->parentNode()) { 813 for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditab leElement; n = n->parentNode()) {
814 if (isSpecialHTMLElement(*n)) { 814 if (isSpecialHTMLElement(*n)) {
815 HTMLElement* specialElement = toHTMLElement(n); 815 HTMLElement* specialElement = toHTMLElement(n);
816 VisiblePosition vPos = VisiblePosition(pos); 816 VisiblePosition vPos = VisiblePosition(pos);
817 VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfte rNode(specialElement)); 817 VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfte rNode(specialElement));
818 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent() == lastInElement.previous().deepEquivalent()) 818 if (isRenderedTableElement(specialElement) && vPos.deepEquivalent() == previousPositionOf(lastInElement).deepEquivalent())
819 return specialElement; 819 return specialElement;
820 if (vPos.deepEquivalent() == lastInElement.deepEquivalent()) 820 if (vPos.deepEquivalent() == lastInElement.deepEquivalent())
821 return specialElement; 821 return specialElement;
822 } 822 }
823 } 823 }
824 return 0; 824 return 0;
825 } 825 }
826 826
827 Position positionBeforeContainingSpecialElement(const Position& pos, HTMLElement ** containingSpecialElement) 827 Position positionBeforeContainingSpecialElement(const Position& pos, HTMLElement ** containingSpecialElement)
828 { 828 {
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 VisibleSelection newSelection(original); 1464 VisibleSelection newSelection(original);
1465 VisiblePosition startOfSelection(newSelection.visibleStart()); 1465 VisiblePosition startOfSelection(newSelection.visibleStart());
1466 VisiblePosition endOfSelection(newSelection.visibleEnd()); 1466 VisiblePosition endOfSelection(newSelection.visibleEnd());
1467 1467
1468 // If the end of the selection to modify is just after a table, and 1468 // If the end of the selection to modify is just after a table, and
1469 // if the start of the selection is inside that table, then the last paragra ph 1469 // if the start of the selection is inside that table, then the last paragra ph
1470 // that we'll want modify is the last one inside the table, not the table it self 1470 // that we'll want modify is the last one inside the table, not the table it self
1471 // (a table is itself a paragraph). 1471 // (a table is itself a paragraph).
1472 if (Element* table = isFirstPositionAfterTable(endOfSelection)) { 1472 if (Element* table = isFirstPositionAfterTable(endOfSelection)) {
1473 if (startOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table )) 1473 if (startOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table ))
1474 newSelection = VisibleSelection(startOfSelection, endOfSelection.pre vious(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(startOfSelection.next(CannotCrossEdi tingBoundary), endOfSelection);
1484 } 1484 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(visiblePosition.next().deepEquivalent()) ;
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