| OLD | NEW |
| 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 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1524 return EphemeralRange(); | 1524 return EphemeralRange(); |
| 1525 | 1525 |
| 1526 Position s = start.deepEquivalent().parentAnchoredEquivalent(); | 1526 Position s = start.deepEquivalent().parentAnchoredEquivalent(); |
| 1527 Position e = end.deepEquivalent().parentAnchoredEquivalent(); | 1527 Position e = end.deepEquivalent().parentAnchoredEquivalent(); |
| 1528 if (s.isNull() || e.isNull()) | 1528 if (s.isNull() || e.isNull()) |
| 1529 return EphemeralRange(); | 1529 return EphemeralRange(); |
| 1530 | 1530 |
| 1531 return EphemeralRange(s, e); | 1531 return EphemeralRange(s, e); |
| 1532 } | 1532 } |
| 1533 | 1533 |
| 1534 template <typename Strategy> |
| 1535 static EphemeralRangeTemplate<Strategy> normalizeRangeAlgorithm(const EphemeralR
angeTemplate<Strategy>& range) |
| 1536 { |
| 1537 ASSERT(range.isNotNull()); |
| 1538 range.document().updateLayoutIgnorePendingStylesheets(); |
| 1539 |
| 1540 // TODO(yosin) We should not call |parentAnchoredEquivalent()|, it is |
| 1541 // redundant. |
| 1542 const PositionAlgorithm<Strategy> normalizedStart = mostForwardCaretPosition
(range.startPosition()).parentAnchoredEquivalent(); |
| 1543 const PositionAlgorithm<Strategy> normalizedEnd = mostBackwardCaretPosition(
range.endPosition()).parentAnchoredEquivalent(); |
| 1544 // The order of the positions of |start| and |end| can be swapped after |
| 1545 // upstream/downstream. e.g. editing/pasteboard/copy-display-none.html |
| 1546 if (normalizedStart.compareTo(normalizedEnd) > 0) |
| 1547 return EphemeralRangeTemplate<Strategy>(normalizedEnd, normalizedStart); |
| 1548 return EphemeralRangeTemplate<Strategy>(normalizedStart, normalizedEnd); |
| 1549 } |
| 1550 |
| 1551 EphemeralRange normalizeRange(const EphemeralRange& range) |
| 1552 { |
| 1553 return normalizeRangeAlgorithm<EditingStrategy>(range); |
| 1554 } |
| 1555 |
| 1556 EphemeralRangeInComposedTree normalizeRange(const EphemeralRangeInComposedTree&
range) |
| 1557 { |
| 1558 return normalizeRangeAlgorithm<EditingInComposedTreeStrategy>(range); |
| 1559 } |
| 1560 |
| 1534 VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope) | 1561 VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope) |
| 1535 { | 1562 { |
| 1536 if (!scope) | 1563 if (!scope) |
| 1537 return VisiblePosition(); | 1564 return VisiblePosition(); |
| 1538 EphemeralRange range = PlainTextRange(index).createRangeForSelection(*scope)
; | 1565 EphemeralRange range = PlainTextRange(index).createRangeForSelection(*scope)
; |
| 1539 // Check for an invalid index. Certain editing operations invalidate indices | 1566 // Check for an invalid index. Certain editing operations invalidate indices |
| 1540 // because of problems with | 1567 // because of problems with |
| 1541 // TextIteratorEmitsCharactersBetweenAllVisiblePositions. | 1568 // TextIteratorEmitsCharactersBetweenAllVisiblePositions. |
| 1542 if (range.isNull()) | 1569 if (range.isNull()) |
| 1543 return VisiblePosition(); | 1570 return VisiblePosition(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 // if the selection starts just before a paragraph break, skip over it | 1654 // if the selection starts just before a paragraph break, skip over it |
| 1628 if (isEndOfParagraph(visiblePosition)) | 1655 if (isEndOfParagraph(visiblePosition)) |
| 1629 return mostForwardCaretPosition(nextPositionOf(visiblePosition).deepEqui
valent()); | 1656 return mostForwardCaretPosition(nextPositionOf(visiblePosition).deepEqui
valent()); |
| 1630 | 1657 |
| 1631 // otherwise, make sure to be at the start of the first selected node, | 1658 // otherwise, make sure to be at the start of the first selected node, |
| 1632 // instead of possibly at the end of the last node before the selection | 1659 // instead of possibly at the end of the last node before the selection |
| 1633 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1660 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1634 } | 1661 } |
| 1635 | 1662 |
| 1636 } // namespace blink | 1663 } // namespace blink |
| OLD | NEW |