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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/VisibleUnits.cpp
diff --git a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
index cd0758efdd148523400c75f7f8cc862df5b68544..fbaddd4d51e114fdde666240de68987def97aaea 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -63,7 +63,6 @@
#include "core/layout/line/InlineTextBox.h"
#include "platform/heap/Handle.h"
#include "platform/text/TextBoundaries.h"
-#include "platform/text/TextBreakIterator.h"
namespace blink {
@@ -541,131 +540,6 @@ PositionInFlatTree PreviousBoundary(
// ---------
-static unsigned StartSentenceBoundary(const UChar* characters,
- unsigned length,
- unsigned,
- BoundarySearchContextAvailability,
- bool&) {
- TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
- // FIXME: The following function can return -1; we don't handle that.
- return iterator->preceding(length);
-}
-
-template <typename Strategy>
-static VisiblePositionTemplate<Strategy> StartOfSentenceAlgorithm(
- const VisiblePositionTemplate<Strategy>& c) {
- DCHECK(c.IsValid()) << c;
- return CreateVisiblePosition(PreviousBoundary(c, StartSentenceBoundary));
-}
-
-VisiblePosition StartOfSentence(const VisiblePosition& c) {
- return StartOfSentenceAlgorithm<EditingStrategy>(c);
-}
-
-VisiblePositionInFlatTree StartOfSentence(const VisiblePositionInFlatTree& c) {
- return StartOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c);
-}
-
-static unsigned EndSentenceBoundary(const UChar* characters,
- unsigned length,
- unsigned,
- BoundarySearchContextAvailability,
- bool&) {
- TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
- return iterator->next();
-}
-
-// TODO(yosin) This includes the space after the punctuation that marks the end
-// of the sentence.
-template <typename Strategy>
-static VisiblePositionTemplate<Strategy> EndOfSentenceAlgorithm(
- const VisiblePositionTemplate<Strategy>& c) {
- DCHECK(c.IsValid()) << c;
- return CreateVisiblePosition(NextBoundary(c, EndSentenceBoundary),
- VP_UPSTREAM_IF_POSSIBLE);
-}
-
-VisiblePosition EndOfSentence(const VisiblePosition& c) {
- return EndOfSentenceAlgorithm<EditingStrategy>(c);
-}
-
-VisiblePositionInFlatTree EndOfSentence(const VisiblePositionInFlatTree& c) {
- return EndOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c);
-}
-
-static unsigned PreviousSentencePositionBoundary(
- const UChar* characters,
- unsigned length,
- unsigned,
- BoundarySearchContextAvailability,
- bool&) {
- // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
- // not right.
- TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
- // FIXME: The following function can return -1; we don't handle that.
- return iterator->preceding(length);
-}
-
-VisiblePosition PreviousSentencePosition(const VisiblePosition& c) {
- DCHECK(c.IsValid()) << c;
- VisiblePosition prev = CreateVisiblePosition(
- PreviousBoundary(c, PreviousSentencePositionBoundary));
- return HonorEditingBoundaryAtOrBefore(prev, c.DeepEquivalent());
-}
-
-static unsigned NextSentencePositionBoundary(const UChar* characters,
- unsigned length,
- unsigned,
- BoundarySearchContextAvailability,
- bool&) {
- // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs
- // to move to the equivlant position in the following sentence.
- TextBreakIterator* iterator = SentenceBreakIterator(characters, length);
- return iterator->following(0);
-}
-
-VisiblePosition NextSentencePosition(const VisiblePosition& c) {
- DCHECK(c.IsValid()) << c;
- VisiblePosition next = CreateVisiblePosition(
- NextBoundary(c, NextSentencePositionBoundary), VP_UPSTREAM_IF_POSSIBLE);
- return HonorEditingBoundaryAtOrAfter(next, c.DeepEquivalent());
-}
-
-EphemeralRange ExpandEndToSentenceBoundary(const EphemeralRange& range) {
- DCHECK(range.IsNotNull());
- const VisiblePosition& visible_end =
- CreateVisiblePosition(range.EndPosition());
- DCHECK(visible_end.IsNotNull());
- const Position& sentence_end = EndOfSentence(visible_end).DeepEquivalent();
- // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible,
- // which would trigger a DCHECK in EphemeralRange's constructor if we return
- // it directly. However, this shouldn't happen and needs to be fixed.
- return EphemeralRange(
- range.StartPosition(),
- sentence_end.IsNotNull() && sentence_end > range.EndPosition()
- ? sentence_end
- : range.EndPosition());
-}
-
-EphemeralRange ExpandRangeToSentenceBoundary(const EphemeralRange& range) {
- DCHECK(range.IsNotNull());
- const VisiblePosition& visible_start =
- CreateVisiblePosition(range.StartPosition());
- DCHECK(visible_start.IsNotNull());
- const Position& sentence_start =
- StartOfSentence(visible_start).DeepEquivalent();
- // TODO(xiaochengh): |sentenceStart > range.startPosition()| is possible,
- // which would trigger a DCHECK in EphemeralRange's constructor if we return
- // it directly. However, this shouldn't happen and needs to be fixed.
- return ExpandEndToSentenceBoundary(EphemeralRange(
- sentence_start.IsNotNull() && sentence_start < range.StartPosition()
- ? sentence_start
- : range.StartPosition(),
- range.EndPosition()));
-}
-
-// ---------
-
VisiblePosition StartOfBlock(const VisiblePosition& visible_position,
EditingBoundaryCrossingRule rule) {
DCHECK(visible_position.IsValid()) << visible_position;
« 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