| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2867 if (!pos.node()) | 2867 if (!pos.node()) |
| 2868 return true; | 2868 return true; |
| 2869 | 2869 |
| 2870 if (isAtomicNode(pos.node())) | 2870 if (isAtomicNode(pos.node())) |
| 2871 return true; | 2871 return true; |
| 2872 | 2872 |
| 2873 return pos.atStartOfNode(); | 2873 return pos.atStartOfNode(); |
| 2874 } | 2874 } |
| 2875 | 2875 |
| 2876 template <typename Strategy> | 2876 template <typename Strategy> |
| 2877 static PositionTemplate<Strategy> adjustPositionForBackwardIteration( |
| 2878 const PositionTemplate<Strategy>& position) { |
| 2879 DCHECK(!position.isNull()); |
| 2880 if (!position.isAfterAnchor()) |
| 2881 return position; |
| 2882 if (isUserSelectContain(*position.anchorNode())) |
| 2883 return position.toOffsetInAnchor(); |
| 2884 return PositionTemplate<Strategy>::editingPositionOf( |
| 2885 position.anchorNode(), Strategy::caretMaxOffset(*position.anchorNode())); |
| 2886 } |
| 2887 |
| 2888 template <typename Strategy> |
| 2877 static PositionTemplate<Strategy> mostBackwardCaretPosition( | 2889 static PositionTemplate<Strategy> mostBackwardCaretPosition( |
| 2878 const PositionTemplate<Strategy>& position, | 2890 const PositionTemplate<Strategy>& position, |
| 2879 EditingBoundaryCrossingRule rule) { | 2891 EditingBoundaryCrossingRule rule) { |
| 2880 DCHECK(!needsLayoutTreeUpdate(position)) << position; | 2892 DCHECK(!needsLayoutTreeUpdate(position)) << position; |
| 2881 TRACE_EVENT0("input", "VisibleUnits::mostBackwardCaretPosition"); | 2893 TRACE_EVENT0("input", "VisibleUnits::mostBackwardCaretPosition"); |
| 2882 | 2894 |
| 2883 Node* startNode = position.anchorNode(); | 2895 Node* startNode = position.anchorNode(); |
| 2884 if (!startNode) | 2896 if (!startNode) |
| 2885 return PositionTemplate<Strategy>(); | 2897 return PositionTemplate<Strategy>(); |
| 2886 | 2898 |
| 2887 // iterate backward from there, looking for a qualified position | 2899 // iterate backward from there, looking for a qualified position |
| 2888 Node* boundary = enclosingVisualBoundary<Strategy>(startNode); | 2900 Node* boundary = enclosingVisualBoundary<Strategy>(startNode); |
| 2889 // FIXME: PositionIterator should respect Before and After positions. | 2901 // FIXME: PositionIterator should respect Before and After positions. |
| 2890 PositionIteratorAlgorithm<Strategy> lastVisible( | 2902 PositionIteratorAlgorithm<Strategy> lastVisible( |
| 2891 position.isAfterAnchor() | 2903 adjustPositionForBackwardIteration<Strategy>(position)); |
| 2892 ? PositionTemplate<Strategy>::editingPositionOf( | |
| 2893 position.anchorNode(), | |
| 2894 Strategy::caretMaxOffset(*position.anchorNode())) | |
| 2895 : position); | |
| 2896 PositionIteratorAlgorithm<Strategy> currentPos = lastVisible; | 2904 PositionIteratorAlgorithm<Strategy> currentPos = lastVisible; |
| 2897 bool startEditable = hasEditableStyle(*startNode); | 2905 bool startEditable = hasEditableStyle(*startNode); |
| 2898 Node* lastNode = startNode; | 2906 Node* lastNode = startNode; |
| 2899 bool boundaryCrossed = false; | 2907 bool boundaryCrossed = false; |
| 2900 for (; !currentPos.atStart(); currentPos.decrement()) { | 2908 for (; !currentPos.atStart(); currentPos.decrement()) { |
| 2901 Node* currentNode = currentPos.node(); | 2909 Node* currentNode = currentPos.node(); |
| 2902 // Don't check for an editability change if we haven't moved to a different | 2910 // Don't check for an editability change if we haven't moved to a different |
| 2903 // node, to avoid the expense of computing hasEditableStyle(). | 2911 // node, to avoid the expense of computing hasEditableStyle(). |
| 2904 if (currentNode != lastNode) { | 2912 if (currentNode != lastNode) { |
| 2905 // Don't change editability. | 2913 // Don't change editability. |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3965 | 3973 |
| 3966 VisiblePositionInFlatTree previousPositionOf( | 3974 VisiblePositionInFlatTree previousPositionOf( |
| 3967 const VisiblePositionInFlatTree& visiblePosition, | 3975 const VisiblePositionInFlatTree& visiblePosition, |
| 3968 EditingBoundaryCrossingRule rule) { | 3976 EditingBoundaryCrossingRule rule) { |
| 3969 DCHECK(visiblePosition.isValid()) << visiblePosition; | 3977 DCHECK(visiblePosition.isValid()) << visiblePosition; |
| 3970 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( | 3978 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( |
| 3971 visiblePosition.deepEquivalent(), rule); | 3979 visiblePosition.deepEquivalent(), rule); |
| 3972 } | 3980 } |
| 3973 | 3981 |
| 3974 } // namespace blink | 3982 } // namespace blink |
| OLD | NEW |