OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #include "core/editing/spellcheck/TextCheckingParagraph.h" | 27 #include "core/editing/spellcheck/TextCheckingParagraph.h" |
28 | 28 |
29 #include "core/dom/Range.h" | 29 #include "core/dom/Range.h" |
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) { | |
37 const VisiblePosition& start = CreateVisiblePosition(range.StartPosition()); | |
38 DCHECK(start.IsNotNull()) << range.StartPosition(); | |
39 const Position& paragraph_start = StartOfParagraph(start).DeepEquivalent(); | |
40 DCHECK(paragraph_start.IsNotNull()) << range.StartPosition(); | |
41 | |
42 const VisiblePosition& end = CreateVisiblePosition(range.EndPosition()); | |
43 DCHECK(end.IsNotNull()) << range.EndPosition(); | |
44 const Position& paragraph_end = EndOfParagraph(end).DeepEquivalent(); | |
45 DCHECK(paragraph_end.IsNotNull()) << range.EndPosition(); | |
46 | |
47 // TODO(xiaochengh): There are some cases (crbug.com/640112) where we get | |
48 // |paragraphStart > paragraphEnd|, which is the reason we cannot directly | |
49 // return |EphemeralRange(paragraphStart, paragraphEnd)|. This is not | |
50 // desired, though. We should do more investigation to ensure that why | |
51 // |paragraphStart <= paragraphEnd| is violated. | |
52 const Position& result_start = | |
53 paragraph_start.IsNotNull() && paragraph_start <= range.StartPosition() | |
54 ? paragraph_start | |
55 : range.StartPosition(); | |
56 const Position& result_end = | |
57 paragraph_end.IsNotNull() && paragraph_end >= range.EndPosition() | |
58 ? paragraph_end | |
59 : range.EndPosition(); | |
60 return EphemeralRange(result_start, result_end); | |
61 } | |
62 | |
63 TextCheckingParagraph::TextCheckingParagraph( | 36 TextCheckingParagraph::TextCheckingParagraph( |
64 const EphemeralRange& checking_range) | 37 const EphemeralRange& checking_range) |
65 : checking_range_(checking_range), | 38 : checking_range_(checking_range), |
66 checking_start_(-1), | 39 checking_start_(-1), |
67 checking_end_(-1), | 40 checking_end_(-1), |
68 checking_length_(-1) {} | 41 checking_length_(-1) {} |
69 | 42 |
70 TextCheckingParagraph::TextCheckingParagraph( | 43 TextCheckingParagraph::TextCheckingParagraph( |
71 const EphemeralRange& checking_range, | 44 const EphemeralRange& checking_range, |
72 const EphemeralRange& paragraph_range) | 45 const EphemeralRange& paragraph_range) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 151 |
179 int TextCheckingParagraph::CheckingLength() const { | 152 int TextCheckingParagraph::CheckingLength() const { |
180 DCHECK(checking_range_.IsNotNull()); | 153 DCHECK(checking_range_.IsNotNull()); |
181 if (-1 == checking_length_) | 154 if (-1 == checking_length_) |
182 checking_length_ = TextIterator::RangeLength( | 155 checking_length_ = TextIterator::RangeLength( |
183 CheckingRange().StartPosition(), CheckingRange().EndPosition()); | 156 CheckingRange().StartPosition(), CheckingRange().EndPosition()); |
184 return checking_length_; | 157 return checking_length_; |
185 } | 158 } |
186 | 159 |
187 } // namespace blink | 160 } // namespace blink |
OLD | NEW |