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

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

Issue 1192713002: Introduce honorEditingBoundaryAtOrBeforeOf() to avoid referencing constructing object (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
« no previous file with comments | « no previous file | 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, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 VisiblePosition right = VisiblePosition(pos, DOWNSTREAM); 444 VisiblePosition right = VisiblePosition(pos, DOWNSTREAM);
445 ASSERT(right != *this); 445 ASSERT(right != *this);
446 446
447 if (!stayInEditableContent) 447 if (!stayInEditableContent)
448 return right; 448 return right;
449 449
450 return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditi ngBoundaryAtOrAfter(right) : honorEditingBoundaryAtOrBefore(right); 450 return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditi ngBoundaryAtOrAfter(right) : honorEditingBoundaryAtOrBefore(right);
451 } 451 }
452 452
453 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrBefore(const VisiblePos ition &pos) const 453 VisiblePosition honorEditingBoundaryAtOrBeforeOf(const VisiblePosition& pos, con st Position& anchor)
tkent 2015/06/19 02:15:57 Is this |static|?
yosin_UTC9 2015/06/19 03:38:12 No. This function will be called from |startOfLine
tkent 2015/06/19 03:41:38 So, the function should be declared in a header fi
yosin_UTC9 2015/06/19 04:25:36 You're right. At this time, all call sites, actua
454 { 454 {
455 if (pos.isNull()) 455 if (pos.isNull())
456 return pos; 456 return pos;
457 457
458 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); 458 ContainerNode* highestRoot = highestEditableRoot(anchor);
459 459
460 // Return empty position if pos is not somewhere inside the editable region containing this position 460 // Return empty position if pos is not somewhere inside the editable region containing this position
461 if (highestRoot && !pos.deepEquivalent().deprecatedNode()->isDescendantOf(hi ghestRoot)) 461 if (highestRoot && !pos.deepEquivalent().deprecatedNode()->isDescendantOf(hi ghestRoot))
462 return VisiblePosition(); 462 return VisiblePosition();
463 463
464 // Return pos itself if the two are from the very same editable region, or b oth are non-editable 464 // Return pos itself if the two are from the very same editable region, or b oth are non-editable
465 // FIXME: In the non-editable case, just because the new position is non-edi table doesn't mean movement 465 // FIXME: In the non-editable case, just because the new position is non-edi table doesn't mean movement
466 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr oblem too. 466 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr oblem too.
467 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot) 467 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot)
468 return pos; 468 return pos;
469 469
470 // Return empty position if this position is non-editable, but pos is editab le 470 // Return empty position if this position is non-editable, but pos is editab le
471 // FIXME: Move to the previous non-editable region. 471 // FIXME: Move to the previous non-editable region.
472 if (!highestRoot) 472 if (!highestRoot)
473 return VisiblePosition(); 473 return VisiblePosition();
474 474
475 // Return the last position before pos that is in the same editable region a s this position 475 // Return the last position before pos that is in the same editable region a s this position
476 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot); 476 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot);
477 } 477 }
478 478
479 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrBefore(const VisiblePos ition &pos) const
480 {
481 return honorEditingBoundaryAtOrBeforeOf(pos, deepEquivalent());
482 }
483
479 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi tion &pos) const 484 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi tion &pos) const
480 { 485 {
481 if (pos.isNull()) 486 if (pos.isNull())
482 return pos; 487 return pos;
483 488
484 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); 489 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent());
485 490
486 // Return empty position if pos is not somewhere inside the editable region containing this position 491 // Return empty position if pos is not somewhere inside the editable region containing this position
487 if (highestRoot && !pos.deepEquivalent().deprecatedNode()->isDescendantOf(hi ghestRoot)) 492 if (highestRoot && !pos.deepEquivalent().deprecatedNode()->isDescendantOf(hi ghestRoot))
488 return VisiblePosition(); 493 return VisiblePosition();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 else 797 else
793 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 798 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
794 } 799 }
795 800
796 void showTree(const blink::VisiblePosition& vpos) 801 void showTree(const blink::VisiblePosition& vpos)
797 { 802 {
798 vpos.showTreeForThis(); 803 vpos.showTreeForThis();
799 } 804 }
800 805
801 #endif 806 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698