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

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

Issue 2271603002: Force expandToParagraphBoundary to return a valid EphemeralRange (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use position comparison Created 4 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 | « no previous file | 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) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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 19 matching lines...) Expand all
30 #include "core/editing/VisiblePosition.h" 30 #include "core/editing/VisiblePosition.h"
31 #include "core/editing/VisibleUnits.h" 31 #include "core/editing/VisibleUnits.h"
32 #include "core/editing/iterators/CharacterIterator.h" 32 #include "core/editing/iterators/CharacterIterator.h"
33 33
34 namespace blink { 34 namespace blink {
35 35
36 static EphemeralRange expandToParagraphBoundary(const EphemeralRange& range) 36 static EphemeralRange expandToParagraphBoundary(const EphemeralRange& range)
37 { 37 {
38 const VisiblePosition& start = createVisiblePosition(range.startPosition()); 38 const VisiblePosition& start = createVisiblePosition(range.startPosition());
39 DCHECK(start.isNotNull()) << range.startPosition(); 39 DCHECK(start.isNotNull()) << range.startPosition();
40 const VisiblePosition& paragraphStart = startOfParagraph(start); 40 const Position& paragraphStart = startOfParagraph(start).deepEquivalent();
41 DCHECK(paragraphStart.isNotNull()) << range.startPosition(); 41 DCHECK(paragraphStart.isNotNull()) << range.startPosition();
42 42
43 const VisiblePosition& end = createVisiblePosition(range.endPosition()); 43 const VisiblePosition& end = createVisiblePosition(range.endPosition());
44 DCHECK(end.isNotNull()) << range.endPosition(); 44 DCHECK(end.isNotNull()) << range.endPosition();
45 const VisiblePosition& paragraphEnd = endOfParagraph(end); 45 const Position& paragraphEnd = endOfParagraph(end).deepEquivalent();
46 DCHECK(paragraphEnd.isNotNull()) << range.endPosition(); 46 DCHECK(paragraphEnd.isNotNull()) << range.endPosition();
47 47
48 return EphemeralRange(paragraphStart.deepEquivalent(), paragraphEnd.deepEqui valent()); 48 // TODO(xiaochengh): There are some cases (crbug.com/640112) where we get
49 // |paragraphStart > paragraphEnd|, which is the reason we cannot directly
50 // return |EphemeralRange(paragraphStart, paragraphEnd)|. This is not
51 // desired, though. We should do more investigation to ensure that why
52 // |paragraphStart <= paragraphEnd| is violated.
53 const Position& resultStart = paragraphStart.isNotNull() && paragraphStart < = range.startPosition() ? paragraphStart : range.startPosition();
54 const Position& resultEnd = paragraphEnd.isNotNull() && paragraphEnd >= rang e.endPosition() ? paragraphEnd : range.endPosition();
55 return EphemeralRange(resultStart, resultEnd);
49 } 56 }
50 57
51 TextCheckingParagraph::TextCheckingParagraph(const EphemeralRange& checkingRange ) 58 TextCheckingParagraph::TextCheckingParagraph(const EphemeralRange& checkingRange )
52 : m_checkingRange(checkingRange) 59 : m_checkingRange(checkingRange)
53 , m_checkingStart(-1) 60 , m_checkingStart(-1)
54 , m_checkingEnd(-1) 61 , m_checkingEnd(-1)
55 , m_checkingLength(-1) 62 , m_checkingLength(-1)
56 { 63 {
57 } 64 }
58 65
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 179
173 int TextCheckingParagraph::checkingLength() const 180 int TextCheckingParagraph::checkingLength() const
174 { 181 {
175 DCHECK(m_checkingRange.isNotNull()); 182 DCHECK(m_checkingRange.isNotNull());
176 if (-1 == m_checkingLength) 183 if (-1 == m_checkingLength)
177 m_checkingLength = TextIterator::rangeLength(checkingRange().startPositi on(), checkingRange().endPosition()); 184 m_checkingLength = TextIterator::rangeLength(checkingRange().startPositi on(), checkingRange().endPosition());
178 return m_checkingLength; 185 return m_checkingLength;
179 } 186 }
180 187
181 } // namespace blink 188 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698