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

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

Issue 1320233003: Move character{After,Before}() for VisiblePosition to VisibleUnits.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-01T11:25:07 Created 5 years, 3 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/VisibleUnits.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, 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 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 2352
2353 // If this is not editable but |pos| has an editable root, skip to the end 2353 // If this is not editable but |pos| has an editable root, skip to the end
2354 if (!highestRoot && highestRootOfPos) 2354 if (!highestRoot && highestRootOfPos)
2355 return VisiblePosition(Position(highestRootOfPos, PositionAnchorType::Af terAnchor).parentAnchoredEquivalent()); 2355 return VisiblePosition(Position(highestRootOfPos, PositionAnchorType::Af terAnchor).parentAnchoredEquivalent());
2356 2356
2357 // That must mean that |pos| is not editable. Return the next position after 2357 // That must mean that |pos| is not editable. Return the next position after
2358 // |pos| that is in the same editable region as this position 2358 // |pos| that is in the same editable region as this position
2359 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot); 2359 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
2360 } 2360 }
2361 2361
2362 UChar32 characterAfter(const VisiblePosition& visiblePosition)
2363 {
2364 // We canonicalize to the first of two equivalent candidates, but the second
2365 // of the two candidates is the one that will be inside the text node
2366 // containing the character after this visible position.
2367 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent());
2368 if (!pos.isOffsetInAnchor())
2369 return 0;
2370 Node* containerNode = pos.computeContainerNode();
2371 if (!containerNode || !containerNode->isTextNode())
2372 return 0;
2373 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode());
2374 Text* textNode = toText(containerNode);
2375 unsigned length = textNode->length();
2376 if (offset >= length)
2377 return 0;
2378
2379 return textNode->data().characterStartingAt(offset);
2380 }
2381
2382 UChar32 characterBefore(const VisiblePosition& visiblePosition)
2383 {
2384 return characterAfter(previousPositionOf(visiblePosition));
2385 }
2386
2362 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo undaryCrossingRule rule) 2387 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo undaryCrossingRule rule)
2363 { 2388 {
2364 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv alent()), visiblePosition.affinity()); 2389 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv alent()), visiblePosition.affinity());
2365 2390
2366 switch (rule) { 2391 switch (rule) {
2367 case CanCrossEditingBoundary: 2392 case CanCrossEditingBoundary:
2368 return next; 2393 return next;
2369 case CannotCrossEditingBoundary: 2394 case CannotCrossEditingBoundary:
2370 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalen t()); 2395 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalen t());
2371 case CanSkipOverEditingBoundary: 2396 case CanSkipOverEditingBoundary:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale nt()); 2450 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale nt());
2426 case CanSkipOverEditingBoundary: 2451 case CanSkipOverEditingBoundary:
2427 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent ()); 2452 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent ());
2428 } 2453 }
2429 2454
2430 ASSERT_NOT_REACHED(); 2455 ASSERT_NOT_REACHED();
2431 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent() ); 2456 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent() );
2432 } 2457 }
2433 2458
2434 } // namespace blink 2459 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleUnits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698