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

Side by Side Diff: Source/WebCore/editing/htmlediting.cpp

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

Powered by Google App Engine
This is Rietveld 408576698