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

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

Issue 2927013002: Move "sentence" granularity related functions to VisibleUnitSentence.cpp (Closed)
Patch Set: 2017-06-08T17:39:57 Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
3 * reserved. 3 * 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "core/layout/LayoutTextFragment.h" 56 #include "core/layout/LayoutTextFragment.h"
57 #include "core/layout/LayoutView.h" 57 #include "core/layout/LayoutView.h"
58 #include "core/layout/api/LayoutItem.h" 58 #include "core/layout/api/LayoutItem.h"
59 #include "core/layout/api/LayoutViewItem.h" 59 #include "core/layout/api/LayoutViewItem.h"
60 #include "core/layout/api/LineLayoutAPIShim.h" 60 #include "core/layout/api/LineLayoutAPIShim.h"
61 #include "core/layout/api/LineLayoutItem.h" 61 #include "core/layout/api/LineLayoutItem.h"
62 #include "core/layout/line/InlineIterator.h" 62 #include "core/layout/line/InlineIterator.h"
63 #include "core/layout/line/InlineTextBox.h" 63 #include "core/layout/line/InlineTextBox.h"
64 #include "platform/heap/Handle.h" 64 #include "platform/heap/Handle.h"
65 #include "platform/text/TextBoundaries.h" 65 #include "platform/text/TextBoundaries.h"
66 #include "platform/text/TextBreakIterator.h"
67 66
68 namespace blink { 67 namespace blink {
69 68
70 template <typename PositionType> 69 template <typename PositionType>
71 static PositionType CanonicalizeCandidate(const PositionType& candidate) { 70 static PositionType CanonicalizeCandidate(const PositionType& candidate) {
72 if (candidate.IsNull()) 71 if (candidate.IsNull())
73 return PositionType(); 72 return PositionType();
74 DCHECK(IsVisuallyEquivalentCandidate(candidate)); 73 DCHECK(IsVisuallyEquivalentCandidate(candidate));
75 PositionType upstream = MostBackwardCaretPosition(candidate); 74 PositionType upstream = MostBackwardCaretPosition(candidate);
76 if (IsVisuallyEquivalentCandidate(upstream)) 75 if (IsVisuallyEquivalentCandidate(upstream))
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 533 }
535 534
536 PositionInFlatTree PreviousBoundary( 535 PositionInFlatTree PreviousBoundary(
537 const VisiblePositionInFlatTree& visible_position, 536 const VisiblePositionInFlatTree& visible_position,
538 BoundarySearchFunction search_function) { 537 BoundarySearchFunction search_function) {
539 return PreviousBoundaryAlgorithm(visible_position, search_function); 538 return PreviousBoundaryAlgorithm(visible_position, search_function);
540 } 539 }
541 540
542 // --------- 541 // ---------
543 542
544 static unsigned StartSentenceBoundary(const UChar* characters,
545 unsigned length,
546 unsigned,
547 BoundarySearchContextAvailability,
548 bool&) {
549 TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
550 // FIXME: The following function can return -1; we don't handle that.
551 return iterator->preceding(length);
552 }
553
554 template <typename Strategy>
555 static VisiblePositionTemplate<Strategy> StartOfSentenceAlgorithm(
556 const VisiblePositionTemplate<Strategy>& c) {
557 DCHECK(c.IsValid()) << c;
558 return CreateVisiblePosition(PreviousBoundary(c, StartSentenceBoundary));
559 }
560
561 VisiblePosition StartOfSentence(const VisiblePosition& c) {
562 return StartOfSentenceAlgorithm<EditingStrategy>(c);
563 }
564
565 VisiblePositionInFlatTree StartOfSentence(const VisiblePositionInFlatTree& c) {
566 return StartOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c);
567 }
568
569 static unsigned EndSentenceBoundary(const UChar* characters,
570 unsigned length,
571 unsigned,
572 BoundarySearchContextAvailability,
573 bool&) {
574 TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
575 return iterator->next();
576 }
577
578 // TODO(yosin) This includes the space after the punctuation that marks the end
579 // of the sentence.
580 template <typename Strategy>
581 static VisiblePositionTemplate<Strategy> EndOfSentenceAlgorithm(
582 const VisiblePositionTemplate<Strategy>& c) {
583 DCHECK(c.IsValid()) << c;
584 return CreateVisiblePosition(NextBoundary(c, EndSentenceBoundary),
585 VP_UPSTREAM_IF_POSSIBLE);
586 }
587
588 VisiblePosition EndOfSentence(const VisiblePosition& c) {
589 return EndOfSentenceAlgorithm<EditingStrategy>(c);
590 }
591
592 VisiblePositionInFlatTree EndOfSentence(const VisiblePositionInFlatTree& c) {
593 return EndOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c);
594 }
595
596 static unsigned PreviousSentencePositionBoundary(
597 const UChar* characters,
598 unsigned length,
599 unsigned,
600 BoundarySearchContextAvailability,
601 bool&) {
602 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
603 // not right.
604 TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
605 // FIXME: The following function can return -1; we don't handle that.
606 return iterator->preceding(length);
607 }
608
609 VisiblePosition PreviousSentencePosition(const VisiblePosition& c) {
610 DCHECK(c.IsValid()) << c;
611 VisiblePosition prev = CreateVisiblePosition(
612 PreviousBoundary(c, PreviousSentencePositionBoundary));
613 return HonorEditingBoundaryAtOrBefore(prev, c.DeepEquivalent());
614 }
615
616 static unsigned NextSentencePositionBoundary(const UChar* characters,
617 unsigned length,
618 unsigned,
619 BoundarySearchContextAvailability,
620 bool&) {
621 // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs
622 // to move to the equivlant position in the following sentence.
623 TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
624 return iterator->following(0);
625 }
626
627 VisiblePosition NextSentencePosition(const VisiblePosition& c) {
628 DCHECK(c.IsValid()) << c;
629 VisiblePosition next = CreateVisiblePosition(
630 NextBoundary(c, NextSentencePositionBoundary), VP_UPSTREAM_IF_POSSIBLE);
631 return HonorEditingBoundaryAtOrAfter(next, c.DeepEquivalent());
632 }
633
634 EphemeralRange ExpandEndToSentenceBoundary(const EphemeralRange& range) {
635 DCHECK(range.IsNotNull());
636 const VisiblePosition& visible_end =
637 CreateVisiblePosition(range.EndPosition());
638 DCHECK(visible_end.IsNotNull());
639 const Position& sentence_end = EndOfSentence(visible_end).DeepEquivalent();
640 // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible,
641 // which would trigger a DCHECK in EphemeralRange's constructor if we return
642 // it directly. However, this shouldn't happen and needs to be fixed.
643 return EphemeralRange(
644 range.StartPosition(),
645 sentence_end.IsNotNull() && sentence_end > range.EndPosition()
646 ? sentence_end
647 : range.EndPosition());
648 }
649
650 EphemeralRange ExpandRangeToSentenceBoundary(const EphemeralRange& range) {
651 DCHECK(range.IsNotNull());
652 const VisiblePosition& visible_start =
653 CreateVisiblePosition(range.StartPosition());
654 DCHECK(visible_start.IsNotNull());
655 const Position& sentence_start =
656 StartOfSentence(visible_start).DeepEquivalent();
657 // TODO(xiaochengh): |sentenceStart > range.startPosition()| is possible,
658 // which would trigger a DCHECK in EphemeralRange's constructor if we return
659 // it directly. However, this shouldn't happen and needs to be fixed.
660 return ExpandEndToSentenceBoundary(EphemeralRange(
661 sentence_start.IsNotNull() && sentence_start < range.StartPosition()
662 ? sentence_start
663 : range.StartPosition(),
664 range.EndPosition()));
665 }
666
667 // ---------
668
669 VisiblePosition StartOfBlock(const VisiblePosition& visible_position, 543 VisiblePosition StartOfBlock(const VisiblePosition& visible_position,
670 EditingBoundaryCrossingRule rule) { 544 EditingBoundaryCrossingRule rule) {
671 DCHECK(visible_position.IsValid()) << visible_position; 545 DCHECK(visible_position.IsValid()) << visible_position;
672 Position position = visible_position.DeepEquivalent(); 546 Position position = visible_position.DeepEquivalent();
673 Element* start_block = 547 Element* start_block =
674 position.ComputeContainerNode() 548 position.ComputeContainerNode()
675 ? EnclosingBlock(position.ComputeContainerNode(), rule) 549 ? EnclosingBlock(position.ComputeContainerNode(), rule)
676 : 0; 550 : 0;
677 return start_block ? VisiblePosition::FirstPositionInNode(start_block) 551 return start_block ? VisiblePosition::FirstPositionInNode(start_block)
678 : VisiblePosition(); 552 : VisiblePosition();
(...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after
2620 2494
2621 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { 2495 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) {
2622 return EnclosingIntRect(ComputeTextRectTemplate(range)); 2496 return EnclosingIntRect(ComputeTextRectTemplate(range));
2623 } 2497 }
2624 2498
2625 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { 2499 FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
2626 return ComputeTextRectTemplate(range); 2500 return ComputeTextRectTemplate(range);
2627 } 2501 }
2628 2502
2629 } // namespace blink 2503 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/BUILD.gn ('k') | third_party/WebKit/Source/core/editing/VisibleUnitsSentence.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698