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

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2368903002: Ensure valid VisiblePosition input for character{Before,After} (Closed)
Patch Set: Add DCHECK for the correctness of postponing Created 4 years, 2 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 | third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.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, 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 * 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 2966 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 2977
2978 // That must mean that |pos| is not editable. Return the next position after 2978 // That must mean that |pos| is not editable. Return the next position after
2979 // |pos| that is in the same editable region as this position 2979 // |pos| that is in the same editable region as this position
2980 DCHECK(highestRoot); 2980 DCHECK(highestRoot);
2981 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), *highestRoot); 2981 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), *highestRoot);
2982 } 2982 }
2983 2983
2984 template <typename Strategy> 2984 template <typename Strategy>
2985 static UChar32 characterAfterAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition) 2985 static UChar32 characterAfterAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition)
2986 { 2986 {
2987 // TODO(xiaochengh): Ensure that this function is called with a valid 2987 DCHECK(visiblePosition.isValid()) << visiblePosition;
2988 // |visiblePosition|, and add |DCHECK(visiblePosition.isValid())|
2989 // We canonicalize to the first of two equivalent candidates, but the second 2988 // We canonicalize to the first of two equivalent candidates, but the second
2990 // of the two candidates is the one that will be inside the text node 2989 // of the two candidates is the one that will be inside the text node
2991 // containing the character after this visible position. 2990 // containing the character after this visible position.
2992 const PositionTemplate<Strategy> pos = mostForwardCaretPosition(visiblePosit ion.deepEquivalent()); 2991 const PositionTemplate<Strategy> pos = mostForwardCaretPosition(visiblePosit ion.deepEquivalent());
2993 if (!pos.isOffsetInAnchor()) 2992 if (!pos.isOffsetInAnchor())
2994 return 0; 2993 return 0;
2995 Node* containerNode = pos.computeContainerNode(); 2994 Node* containerNode = pos.computeContainerNode();
2996 if (!containerNode || !containerNode->isTextNode()) 2995 if (!containerNode || !containerNode->isTextNode())
2997 return 0; 2996 return 0;
2998 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode()); 2997 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode());
(...skipping 11 matching lines...) Expand all
3010 } 3009 }
3011 3010
3012 UChar32 characterAfter(const VisiblePositionInFlatTree& visiblePosition) 3011 UChar32 characterAfter(const VisiblePositionInFlatTree& visiblePosition)
3013 { 3012 {
3014 return characterAfterAlgorithm<EditingInFlatTreeStrategy>(visiblePosition); 3013 return characterAfterAlgorithm<EditingInFlatTreeStrategy>(visiblePosition);
3015 } 3014 }
3016 3015
3017 template <typename Strategy> 3016 template <typename Strategy>
3018 static UChar32 characterBeforeAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition) 3017 static UChar32 characterBeforeAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition)
3019 { 3018 {
3020 // TODO(xiaochengh): Ensure that this function is called with a valid 3019 DCHECK(visiblePosition.isValid()) << visiblePosition;
3021 // |visiblePosition|, and add |DCHECK(visiblePosition.isValid())|
3022 return characterAfter(previousPositionOf(visiblePosition)); 3020 return characterAfter(previousPositionOf(visiblePosition));
3023 } 3021 }
3024 3022
3025 UChar32 characterBefore(const VisiblePosition& visiblePosition) 3023 UChar32 characterBefore(const VisiblePosition& visiblePosition)
3026 { 3024 {
3027 return characterBeforeAlgorithm<EditingStrategy>(visiblePosition); 3025 return characterBeforeAlgorithm<EditingStrategy>(visiblePosition);
3028 } 3026 }
3029 3027
3030 UChar32 characterBefore(const VisiblePositionInFlatTree& visiblePosition) 3028 UChar32 characterBefore(const VisiblePositionInFlatTree& visiblePosition)
3031 { 3029 {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
3480 { 3478 {
3481 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); 3479 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule);
3482 } 3480 }
3483 3481
3484 VisiblePositionInFlatTree previousPositionOf(const VisiblePositionInFlatTree& vi siblePosition, EditingBoundaryCrossingRule rule) 3482 VisiblePositionInFlatTree previousPositionOf(const VisiblePositionInFlatTree& vi siblePosition, EditingBoundaryCrossingRule rule)
3485 { 3483 {
3486 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePositio n, rule); 3484 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePositio n, rule);
3487 } 3485 }
3488 3486
3489 } // namespace blink 3487 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698