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

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

Issue 1301023003: Move static member functions next{Previous,Next}Offset() and uncheckedPreviousOffsetForBackwardDelet (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-20T14:28:12 Rebase Created 5 years, 4 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/core/editing/Position.h ('k') | Source/core/editing/PositionIterator.cpp » ('j') | 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, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2009 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 int offsetB = positionB.computeOffsetInContainerNode(); 307 int offsetB = positionB.computeOffsetInContainerNode();
308 return comparePositionsInComposedTree(containerA, offsetA, containerB, offse tB); 308 return comparePositionsInComposedTree(containerA, offsetA, containerB, offse tB);
309 } 309 }
310 310
311 template <typename Strategy> 311 template <typename Strategy>
312 int PositionAlgorithm<Strategy>::compareTo(const PositionAlgorithm<Strategy>& ot her) const 312 int PositionAlgorithm<Strategy>::compareTo(const PositionAlgorithm<Strategy>& ot her) const
313 { 313 {
314 return comparePositions(*this, other); 314 return comparePositions(*this, other);
315 } 315 }
316 316
317 // TODO(yosin) To avoid forward declaration, we should move implementation of
318 // |uncheckedPreviousOffsetForBackwardDeletion()| here.
319 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int current);
320
317 template <typename Strategy> 321 template <typename Strategy>
318 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveTy pe moveType) const 322 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveTy pe moveType) const
319 { 323 {
320 Node* node = anchorNode(); 324 Node* node = anchorNode();
321 if (!node) 325 if (!node)
322 return PositionAlgorithm<Strategy>(*this); 326 return PositionAlgorithm<Strategy>(*this);
323 327
324 int offset = computeEditingOffset(); 328 int offset = computeEditingOffset();
325 329
326 if (offset > 0) { 330 if (offset > 0) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // 2) The new offset is a bogus offset like (<br>, 1), and there is no child. 381 // 2) The new offset is a bogus offset like (<br>, 1), and there is no child.
378 // Going from 0 to 1 is correct. 382 // Going from 0 to 1 is correct.
379 return editingPositionOf(node, (moveType == Character) ? uncheckedNextOf fset(node, offset) : offset + 1); 383 return editingPositionOf(node, (moveType == Character) ? uncheckedNextOf fset(node, offset) : offset + 1);
380 } 384 }
381 385
382 if (ContainerNode* parent = Strategy::parent(*node)) 386 if (ContainerNode* parent = Strategy::parent(*node))
383 return editingPositionOf(parent, Strategy::index(*node) + 1); 387 return editingPositionOf(parent, Strategy::index(*node) + 1);
384 return PositionAlgorithm<Strategy>(*this); 388 return PositionAlgorithm<Strategy>(*this);
385 } 389 }
386 390
387 template <typename Strategy> 391 int uncheckedPreviousOffset(const Node* n, int current)
388 int PositionAlgorithm<Strategy>::uncheckedPreviousOffset(const Node* n, int curr ent)
389 { 392 {
390 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr ent - 1; 393 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr ent - 1;
391 } 394 }
392 395
393 template <typename Strategy> 396 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current )
394 int PositionAlgorithm<Strategy>::uncheckedPreviousOffsetForBackwardDeletion(cons t Node* n, int current)
395 { 397 {
396 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1; 398 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1;
397 } 399 }
398 400
399 template <typename Strategy> 401 int uncheckedNextOffset(const Node* n, int current)
400 int PositionAlgorithm<Strategy>::uncheckedNextOffset(const Node* n, int current)
401 { 402 {
402 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current + 1; 403 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current + 1;
403 } 404 }
404 405
405 template <typename Strategy> 406 template <typename Strategy>
406 bool PositionAlgorithm<Strategy>::atFirstEditingPositionForNode() const 407 bool PositionAlgorithm<Strategy>::atFirstEditingPositionForNode() const
407 { 408 {
408 if (isNull()) 409 if (isNull())
409 return true; 410 return true;
410 // FIXME: Position before anchor shouldn't be considered as at the first edi ting position for node 411 // FIXME: Position before anchor shouldn't be considered as at the first edi ting position for node
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 1361
1361 void showTree(const blink::Position* pos) 1362 void showTree(const blink::Position* pos)
1362 { 1363 {
1363 if (pos) 1364 if (pos)
1364 pos->showTreeForThis(); 1365 pos->showTreeForThis();
1365 else 1366 else
1366 fprintf(stderr, "Cannot showTree for (nil)\n"); 1367 fprintf(stderr, "Cannot showTree for (nil)\n");
1367 } 1368 }
1368 1369
1369 #endif 1370 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/Position.h ('k') | Source/core/editing/PositionIterator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698