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

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

Issue 1201153002: Introduce composed tree version of canonicalPosition() in VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 Node* node = p.containerNode(); 189 Node* node = p.containerNode();
190 if (!node) 190 if (!node)
191 return 0; 191 return 0;
192 192
193 if (isRenderedHTMLTableElement(node)) 193 if (isRenderedHTMLTableElement(node))
194 node = node->parentNode(); 194 node = node->parentNode();
195 195
196 return node->rootEditableElement(editableType); 196 return node->rootEditableElement(editableType);
197 } 197 }
198 198
199 Element* editableRootForPosition(const PositionInComposedTree& p, EditableType e ditableType)
200 {
201 return editableRootForPosition(toPositionInDOMTree(p), editableType);
202 }
203
199 // Finds the enclosing element until which the tree can be split. 204 // Finds the enclosing element until which the tree can be split.
200 // When a user hits ENTER, he/she won't expect this element to be split into two . 205 // When a user hits ENTER, he/she won't expect this element to be split into two .
201 // You may pass it as the second argument of splitTreeToNode. 206 // You may pass it as the second argument of splitTreeToNode.
202 Element* unsplittableElementForPosition(const Position& p) 207 Element* unsplittableElementForPosition(const Position& p)
203 { 208 {
204 // Since enclosingNodeOfType won't search beyond the highest root editable n ode, 209 // Since enclosingNodeOfType won't search beyond the highest root editable n ode,
205 // this code works even if the closest table cell was outside of the root ed itable node. 210 // this code works even if the closest table cell was outside of the root ed itable node.
206 Element* enclosingCell = toElement(enclosingNodeOfType(p, &isTableCell)); 211 Element* enclosingCell = toElement(enclosingNodeOfType(p, &isTableCell));
207 if (enclosingCell) 212 if (enclosingCell)
208 return enclosingCell; 213 return enclosingCell;
(...skipping 12 matching lines...) Expand all
221 return p; 226 return p;
222 } 227 }
223 return PositionType(); 228 return PositionType();
224 } 229 }
225 230
226 Position nextCandidate(const Position& position) 231 Position nextCandidate(const Position& position)
227 { 232 {
228 return nextCandidateAlgorithm<EditingStrategy>(position); 233 return nextCandidateAlgorithm<EditingStrategy>(position);
229 } 234 }
230 235
236 PositionInComposedTree nextCandidate(const PositionInComposedTree& position)
237 {
238 return nextCandidateAlgorithm<EditingInComposedTreeStrategy>(position);
239 }
240
231 Position nextVisuallyDistinctCandidate(const Position& position) 241 Position nextVisuallyDistinctCandidate(const Position& position)
232 { 242 {
233 Position p = position; 243 Position p = position;
234 Position downstreamStart = p.downstream(); 244 Position downstreamStart = p.downstream();
235 while (!p.atEndOfTree()) { 245 while (!p.atEndOfTree()) {
236 p = p.next(Character); 246 p = p.next(Character);
237 if (p.isCandidate() && p.downstream() != downstreamStart) 247 if (p.isCandidate() && p.downstream() != downstreamStart)
238 return p; 248 return p;
239 } 249 }
240 return Position(); 250 return Position();
(...skipping 10 matching lines...) Expand all
251 return p; 261 return p;
252 } 262 }
253 return PositionType(); 263 return PositionType();
254 } 264 }
255 265
256 Position previousCandidate(const Position& position) 266 Position previousCandidate(const Position& position)
257 { 267 {
258 return previousCandidateAlgorithm<EditingStrategy>(position); 268 return previousCandidateAlgorithm<EditingStrategy>(position);
259 } 269 }
260 270
271 PositionInComposedTree previousCandidate(const PositionInComposedTree& position)
272 {
273 return previousCandidateAlgorithm<EditingInComposedTreeStrategy>(position);
274 }
275
261 template <typename PositionType> 276 template <typename PositionType>
262 PositionType previousVisuallyDistinctCandidateAlgorithm(const PositionType& posi tion) 277 PositionType previousVisuallyDistinctCandidateAlgorithm(const PositionType& posi tion)
263 { 278 {
264 PositionType p = position; 279 PositionType p = position;
265 PositionType downstreamStart = p.downstream(); 280 PositionType downstreamStart = p.downstream();
266 while (!p.atStartOfTree()) { 281 while (!p.atStartOfTree()) {
267 p = p.previous(Character); 282 p = p.previous(Character);
268 if (p.isCandidate() && p.downstream() != downstreamStart) 283 if (p.isCandidate() && p.downstream() != downstreamStart)
269 return p; 284 return p;
270 } 285 }
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 // if the selection starts just before a paragraph break, skip over it 1223 // if the selection starts just before a paragraph break, skip over it
1209 if (isEndOfParagraph(visiblePosition)) 1224 if (isEndOfParagraph(visiblePosition))
1210 return visiblePosition.next().deepEquivalent().downstream(); 1225 return visiblePosition.next().deepEquivalent().downstream();
1211 1226
1212 // otherwise, make sure to be at the start of the first selected node, 1227 // otherwise, make sure to be at the start of the first selected node,
1213 // instead of possibly at the end of the last node before the selection 1228 // instead of possibly at the end of the last node before the selection
1214 return visiblePosition.deepEquivalent().downstream(); 1229 return visiblePosition.deepEquivalent().downstream();
1215 } 1230 }
1216 1231
1217 } // namespace blink 1232 } // namespace blink
OLDNEW
« Source/core/editing/VisiblePositionTest.cpp ('K') | « Source/core/editing/htmlediting.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698