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

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

Issue 1307023005: Move {next,previous}PositionOf() for VisiblePosition to VisibleUnits.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-31T22:28:28 Rebase 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 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after
2330 bool isVisuallyEquivalentCandidate(const Position& position) 2330 bool isVisuallyEquivalentCandidate(const Position& position)
2331 { 2331 {
2332 return isVisuallyEquivalentCandidateAlgorithm<EditingStrategy>(position); 2332 return isVisuallyEquivalentCandidateAlgorithm<EditingStrategy>(position);
2333 } 2333 }
2334 2334
2335 bool isVisuallyEquivalentCandidate(const PositionInComposedTree& position) 2335 bool isVisuallyEquivalentCandidate(const PositionInComposedTree& position)
2336 { 2336 {
2337 return isVisuallyEquivalentCandidateAlgorithm<EditingInComposedTreeStrategy> (position); 2337 return isVisuallyEquivalentCandidateAlgorithm<EditingInComposedTreeStrategy> (position);
2338 } 2338 }
2339 2339
2340 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition& pos, co nst Position& anchor)
2341 {
2342 if (pos.isNull())
2343 return pos;
2344
2345 ContainerNode* highestRoot = highestEditableRoot(anchor);
2346 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent());
2347
2348 // Return |pos| itself if the two are from the very same editable region, or
2349 // both are non-editable.
2350 if (highestRootOfPos == highestRoot)
2351 return pos;
2352
2353 // If this is not editable but |pos| has an editable root, skip to the end
2354 if (!highestRoot && highestRootOfPos)
2355 return VisiblePosition(Position(highestRootOfPos, PositionAnchorType::Af terAnchor).parentAnchoredEquivalent());
2356
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
2359 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
2360 }
2361
2362 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo undaryCrossingRule rule)
2363 {
2364 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv alent()), visiblePosition.affinity());
2365
2366 switch (rule) {
2367 case CanCrossEditingBoundary:
2368 return next;
2369 case CannotCrossEditingBoundary:
2370 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalen t());
2371 case CanSkipOverEditingBoundary:
2372 return skipToEndOfEditingBoundary(next, visiblePosition.deepEquivalent() );
2373 }
2374 ASSERT_NOT_REACHED();
2375 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalent()) ;
2376 }
2377
2378 static VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition& pos, const Position& anchor)
2379 {
2380 if (pos.isNull())
2381 return pos;
2382
2383 ContainerNode* highestRoot = highestEditableRoot(anchor);
2384 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent());
2385
2386 // Return |pos| itself if the two are from the very same editable region, or
2387 // both are non-editable.
2388 if (highestRootOfPos == highestRoot)
2389 return pos;
2390
2391 // If this is not editable but |pos| has an editable root, skip to the start
2392 if (!highestRoot && highestRootOfPos)
2393 return VisiblePosition(previousVisuallyDistinctCandidate(Position(highes tRootOfPos, PositionAnchorType::BeforeAnchor).parentAnchoredEquivalent()));
2394
2395 // That must mean that |pos| is not editable. Return the last position
2396 // before |pos| that is in the same editable region as this position
2397 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot);
2398 }
2399
2400 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi ngBoundaryCrossingRule rule)
2401 {
2402 Position pos = previousVisuallyDistinctCandidate(visiblePosition.deepEquival ent());
2403
2404 // return null visible position if there is no previous visible position
2405 if (pos.atStartOfTree())
2406 return VisiblePosition();
2407
2408 VisiblePosition prev = VisiblePosition(pos);
2409 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent());
2410
2411 #if ENABLE(ASSERT)
2412 // we should always be able to make the affinity |TextAffinity::Downstream|,
2413 // because going previous from an |TextAffinity::Upstream| position can
2414 // never yield another |TextAffinity::Upstream position| (unless line wrap
2415 // length is 0!).
2416 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream ) {
2417 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream)));
2418 }
2419 #endif
2420
2421 switch (rule) {
2422 case CanCrossEditingBoundary:
2423 return prev;
2424 case CannotCrossEditingBoundary:
2425 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale nt());
2426 case CanSkipOverEditingBoundary:
2427 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent ());
2428 }
2429
2430 ASSERT_NOT_REACHED();
2431 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent() );
2432 }
2433
2340 } // namespace blink 2434 } // 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