| 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 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1065 | 1065 | 
| 1066     return newSelection; | 1066     return newSelection; | 
| 1067 } | 1067 } | 
| 1068 | 1068 | 
| 1069 // FIXME: indexForVisiblePosition and visiblePositionForIndex use TextIterators 
      to convert between | 1069 // FIXME: indexForVisiblePosition and visiblePositionForIndex use TextIterators 
      to convert between | 
| 1070 // VisiblePositions and indices. But TextIterator iteration using TextIteratorEm
      itsCharactersBetweenAllVisiblePositions | 1070 // VisiblePositions and indices. But TextIterator iteration using TextIteratorEm
      itsCharactersBetweenAllVisiblePositions | 
| 1071 // does not exactly match VisiblePosition iteration, so using them to preserve a
       selection during an editing | 1071 // does not exactly match VisiblePosition iteration, so using them to preserve a
       selection during an editing | 
| 1072 // opertion is unreliable. TextIterator's TextIteratorEmitsCharactersBetweenAllV
      isiblePositions mode needs to be fixed, | 1072 // opertion is unreliable. TextIterator's TextIteratorEmitsCharactersBetweenAllV
      isiblePositions mode needs to be fixed, | 
| 1073 // or these functions need to be changed to iterate using actual VisiblePosition
      s. | 1073 // or these functions need to be changed to iterate using actual VisiblePosition
      s. | 
| 1074 // FIXME: Deploy these functions everywhere that TextIterators are used to conve
      rt between VisiblePositions and indices. | 1074 // FIXME: Deploy these functions everywhere that TextIterators are used to conve
      rt between VisiblePositions and indices. | 
| 1075 int indexForVisiblePosition(const VisiblePosition& visiblePosition, Element **sc
      ope) | 1075 int indexForVisiblePosition(const VisiblePosition& visiblePosition, RefPtr<Eleme
      nt>& scope) | 
| 1076 { | 1076 { | 
| 1077     if (visiblePosition.isNull()) | 1077     if (visiblePosition.isNull()) | 
| 1078         return 0; | 1078         return 0; | 
| 1079 | 1079 | 
| 1080     Position p(visiblePosition.deepEquivalent()); | 1080     Position p(visiblePosition.deepEquivalent()); | 
| 1081     Document* document = p.anchorNode()->document(); | 1081     Document* document = p.anchorNode()->document(); | 
| 1082 |  | 
| 1083     Element* root; |  | 
| 1084     Node* shadowRoot = p.anchorNode()->shadowTreeRootNode(); | 1082     Node* shadowRoot = p.anchorNode()->shadowTreeRootNode(); | 
| 1085 | 1083 | 
| 1086     if (shadowRoot) { | 1084     if (shadowRoot) { | 
| 1087         // Use the shadow root for form elements, since TextIterators will not e
      nter shadow content. | 1085         // Use the shadow root for form elements, since TextIterators will not e
      nter shadow content. | 
| 1088         ASSERT(shadowRoot->isElementNode()); | 1086         ASSERT(shadowRoot->isElementNode()); | 
| 1089         root = static_cast<Element*>(shadowRoot); | 1087         scope = static_cast<Element*>(shadowRoot); | 
| 1090     } else | 1088     } else | 
| 1091         root = document->documentElement(); | 1089         scope = document->documentElement(); | 
| 1092 | 1090 | 
| 1093     if (scope) { | 1091     RefPtr<Range> range = Range::create(document, firstPositionInNode(scope.get(
      )), p.parentAnchoredEquivalent()); | 
| 1094         ASSERT(!*scope); | 1092 | 
| 1095         *scope = root; |  | 
| 1096     } |  | 
| 1097 |  | 
| 1098     RefPtr<Range> range = Range::create(document, firstPositionInNode(root), p.p
      arentAnchoredEquivalent()); |  | 
| 1099 |  | 
| 1100     return TextIterator::rangeLength(range.get(), true); | 1093     return TextIterator::rangeLength(range.get(), true); | 
| 1101 } | 1094 } | 
| 1102 | 1095 | 
| 1103 VisiblePosition visiblePositionForIndex(int index, Element *scope) | 1096 VisiblePosition visiblePositionForIndex(int index, Element *scope) | 
| 1104 { | 1097 { | 
| 1105     RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, index,
       0, true); | 1098     RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, index,
       0, true); | 
| 1106     // Check for an invalid index. Certain editing operations invalidate indices
       because | 1099     // Check for an invalid index. Certain editing operations invalidate indices
       because | 
| 1107     // of problems with TextIteratorEmitsCharactersBetweenAllVisiblePositions. | 1100     // of problems with TextIteratorEmitsCharactersBetweenAllVisiblePositions. | 
| 1108     if (!range) | 1101     if (!range) | 
| 1109         return VisiblePosition(); | 1102         return VisiblePosition(); | 
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1263     // if the selection starts just before a paragraph break, skip over it | 1256     // if the selection starts just before a paragraph break, skip over it | 
| 1264     if (isEndOfParagraph(visiblePosition)) | 1257     if (isEndOfParagraph(visiblePosition)) | 
| 1265         return visiblePosition.next().deepEquivalent().downstream(); | 1258         return visiblePosition.next().deepEquivalent().downstream(); | 
| 1266 | 1259 | 
| 1267     // otherwise, make sure to be at the start of the first selected node, | 1260     // otherwise, make sure to be at the start of the first selected node, | 
| 1268     // instead of possibly at the end of the last node before the selection | 1261     // instead of possibly at the end of the last node before the selection | 
| 1269     return visiblePosition.deepEquivalent().downstream(); | 1262     return visiblePosition.deepEquivalent().downstream(); | 
| 1270 } | 1263 } | 
| 1271 | 1264 | 
| 1272 } // namespace WebCore | 1265 } // namespace WebCore | 
| OLD | NEW | 
|---|