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

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

Issue 1300303002: Introduce isVisuallyEquivalentCandidate() as replacement of PositionAlgorithm::isCandidate() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-21T01:27:16 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.cpp ('k') | Source/core/editing/VisibleUnits.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 * 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 level = box->bidiLevel(); 246 level = box->bidiLevel();
247 } 247 }
248 layoutObject = &box->layoutObject(); 248 layoutObject = &box->layoutObject();
249 offset = primaryDirection == LTR ? box->caretMinOffset() : box-> caretMaxOffset(); 249 offset = primaryDirection == LTR ? box->caretMinOffset() : box-> caretMaxOffset();
250 } 250 }
251 break; 251 break;
252 } 252 }
253 253
254 p = Position::editingPositionOf(layoutObject->node(), offset); 254 p = Position::editingPositionOf(layoutObject->node(), offset);
255 255
256 if ((p.isCandidate() && p.downstream() != downstreamStart) || p.atStartO fTree() || p.atEndOfTree()) 256 if ((isVisuallyEquivalentCandidate(p) && p.downstream() != downstreamSta rt) || p.atStartOfTree() || p.atEndOfTree())
257 return p; 257 return p;
258 258
259 ASSERT(p != m_deepPosition); 259 ASSERT(p != m_deepPosition);
260 } 260 }
261 } 261 }
262 262
263 VisiblePosition VisiblePosition::left() const 263 VisiblePosition VisiblePosition::left() const
264 { 264 {
265 Position pos = leftVisuallyDistinctCandidate(); 265 Position pos = leftVisuallyDistinctCandidate();
266 // FIXME: Why can't we move left from the last position in a tree? 266 // FIXME: Why can't we move left from the last position in a tree?
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 level = box->bidiLevel(); 408 level = box->bidiLevel();
409 } 409 }
410 layoutObject = &box->layoutObject(); 410 layoutObject = &box->layoutObject();
411 offset = primaryDirection == LTR ? box->caretMaxOffset() : box-> caretMinOffset(); 411 offset = primaryDirection == LTR ? box->caretMaxOffset() : box-> caretMinOffset();
412 } 412 }
413 break; 413 break;
414 } 414 }
415 415
416 p = Position::editingPositionOf(layoutObject->node(), offset); 416 p = Position::editingPositionOf(layoutObject->node(), offset);
417 417
418 if ((p.isCandidate() && p.downstream() != downstreamStart) || p.atStartO fTree() || p.atEndOfTree()) 418 if ((isVisuallyEquivalentCandidate(p) && p.downstream() != downstreamSta rt) || p.atStartOfTree() || p.atEndOfTree())
419 return p; 419 return p;
420 420
421 ASSERT(p != m_deepPosition); 421 ASSERT(p != m_deepPosition);
422 } 422 }
423 } 423 }
424 424
425 VisiblePosition VisiblePosition::right() const 425 VisiblePosition VisiblePosition::right() const
426 { 426 {
427 Position pos = rightVisuallyDistinctCandidate(); 427 Position pos = rightVisuallyDistinctCandidate();
428 // FIXME: Why can't we move left from the last position in a tree? 428 // FIXME: Why can't we move left from the last position in a tree?
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 541
542 // That must mean that |pos| is not editable. Return the next position after pos that is in the same editable region as this position 542 // That must mean that |pos| is not editable. Return the next position after pos that is in the same editable region as this position
543 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot); 543 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
544 } 544 }
545 545
546 template <typename PositionType> 546 template <typename PositionType>
547 static PositionType canonicalizeCandidate(const PositionType& candidate) 547 static PositionType canonicalizeCandidate(const PositionType& candidate)
548 { 548 {
549 if (candidate.isNull()) 549 if (candidate.isNull())
550 return PositionType(); 550 return PositionType();
551 ASSERT(candidate.isCandidate()); 551 ASSERT(isVisuallyEquivalentCandidate(candidate));
552 PositionType upstream = candidate.upstream(); 552 PositionType upstream = candidate.upstream();
553 if (upstream.isCandidate()) 553 if (isVisuallyEquivalentCandidate(upstream))
554 return upstream; 554 return upstream;
555 return candidate; 555 return candidate;
556 } 556 }
557 557
558 template <typename PositionType> 558 template <typename PositionType>
559 static PositionType canonicalPosition(const PositionType& passedPosition) 559 static PositionType canonicalPosition(const PositionType& passedPosition)
560 { 560 {
561 // Sometimes updating selection positions can be extremely expensive and occ ur 561 // Sometimes updating selection positions can be extremely expensive and occ ur
562 // frequently. Often calling preventDefault on mousedown events can avoid 562 // frequently. Often calling preventDefault on mousedown events can avoid
563 // doing unnecessary text selection work. http://crbug.com/472258. 563 // doing unnecessary text selection work. http://crbug.com/472258.
(...skipping 11 matching lines...) Expand all
575 // unless the affinity is upstream. 575 // unless the affinity is upstream.
576 if (position.isNull()) 576 if (position.isNull())
577 return PositionType(); 577 return PositionType();
578 578
579 ASSERT(position.document()); 579 ASSERT(position.document());
580 position.document()->updateLayoutIgnorePendingStylesheets(); 580 position.document()->updateLayoutIgnorePendingStylesheets();
581 581
582 Node* node = position.computeContainerNode(); 582 Node* node = position.computeContainerNode();
583 583
584 PositionType candidate = position.upstream(); 584 PositionType candidate = position.upstream();
585 if (candidate.isCandidate()) 585 if (isVisuallyEquivalentCandidate(candidate))
586 return candidate; 586 return candidate;
587 candidate = position.downstream(); 587 candidate = position.downstream();
588 if (candidate.isCandidate()) 588 if (isVisuallyEquivalentCandidate(candidate))
589 return candidate; 589 return candidate;
590 590
591 // When neither upstream or downstream gets us to a candidate (upstream/down stream won't leave 591 // When neither upstream or downstream gets us to a candidate (upstream/down stream won't leave
592 // blocks or enter new ones), we search forward and backward until we find o ne. 592 // blocks or enter new ones), we search forward and backward until we find o ne.
593 PositionType next = canonicalizeCandidate(nextCandidate(position)); 593 PositionType next = canonicalizeCandidate(nextCandidate(position));
594 PositionType prev = canonicalizeCandidate(previousCandidate(position)); 594 PositionType prev = canonicalizeCandidate(previousCandidate(position));
595 Node* nextNode = next.anchorNode(); 595 Node* nextNode = next.anchorNode();
596 Node* prevNode = prev.anchorNode(); 596 Node* prevNode = prev.anchorNode();
597 597
598 // The new position must be in the same editable element. Enforce that first . 598 // The new position must be in the same editable element. Enforce that first .
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 else 769 else
770 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 770 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
771 } 771 }
772 772
773 void showTree(const blink::VisiblePosition& vpos) 773 void showTree(const blink::VisiblePosition& vpos)
774 { 774 {
775 vpos.showTreeForThis(); 775 vpos.showTreeForThis();
776 } 776 }
777 777
778 #endif 778 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/Position.cpp ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698