OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 m_details(TextCompositionMarkerDetails::create(underlineColor, | 159 m_details(TextCompositionMarkerDetails::create(underlineColor, |
160 thick, | 160 thick, |
161 backgroundColor)) {} | 161 backgroundColor)) {} |
162 | 162 |
163 DocumentMarker::DocumentMarker(const DocumentMarker& marker) | 163 DocumentMarker::DocumentMarker(const DocumentMarker& marker) |
164 : m_type(marker.type()), | 164 : m_type(marker.type()), |
165 m_startOffset(marker.startOffset()), | 165 m_startOffset(marker.startOffset()), |
166 m_endOffset(marker.endOffset()), | 166 m_endOffset(marker.endOffset()), |
167 m_details(marker.details()) {} | 167 m_details(marker.details()) {} |
168 | 168 |
| 169 DocumentMarker::ShiftMarkerResult DocumentMarker::getShiftedMarkerPosition( |
| 170 unsigned offset, |
| 171 unsigned oldLength, |
| 172 unsigned newLength) const { |
| 173 ShiftMarkerResult result; |
| 174 result.newStartOffset = startOffset(); |
| 175 result.newEndOffset = endOffset(); |
| 176 result.shouldRemoveMarker = false; |
| 177 |
| 178 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace |
| 179 // but with some changes |
| 180 |
| 181 // Deviation from the concept-cd-replace algorithm: second condition in the |
| 182 // next line (don't include text inserted immediately before a marker in the |
| 183 // marked range, but do include the new text if it's replacing text in the |
| 184 // marked range) |
| 185 if (startOffset() > offset || (startOffset() == offset && oldLength == 0)) { |
| 186 if (startOffset() <= offset + oldLength) { |
| 187 // Marker start was in the replaced text. Move to end of new text |
| 188 // (Deviation from the concept-cd-replace algorithm: that algorithm |
| 189 // would move to the beginning of the new text here) |
| 190 result.newStartOffset = offset + newLength; |
| 191 } else { |
| 192 // Marker start was after the replaced text. Shift by length |
| 193 // difference |
| 194 result.newStartOffset = startOffset() + newLength - oldLength; |
| 195 } |
| 196 } |
| 197 |
| 198 if (endOffset() > offset) { |
| 199 // Deviation from the concept-cd-replace algorithm: < instead of <= in |
| 200 // the next line |
| 201 if (endOffset() < offset + oldLength) { |
| 202 // Marker end was in the replaced text. Move to beginning of new text |
| 203 result.newEndOffset = offset; |
| 204 } else { |
| 205 // Marker end was after the replaced text. Shift by length difference |
| 206 result.newEndOffset = endOffset() + newLength - oldLength; |
| 207 } |
| 208 } |
| 209 |
| 210 if (result.newStartOffset >= result.newEndOffset) |
| 211 result.shouldRemoveMarker = true; |
| 212 |
| 213 return result; |
| 214 } |
| 215 |
169 void DocumentMarker::shiftOffsets(int delta) { | 216 void DocumentMarker::shiftOffsets(int delta) { |
170 m_startOffset += delta; | 217 m_startOffset += delta; |
171 m_endOffset += delta; | 218 m_endOffset += delta; |
172 } | 219 } |
173 | 220 |
174 void DocumentMarker::setActiveMatch(bool active) { | 221 void DocumentMarker::setActiveMatch(bool active) { |
175 m_details = DocumentMarkerTextMatch::create(active); | 222 m_details = DocumentMarkerTextMatch::create(active); |
176 } | 223 } |
177 | 224 |
178 const String& DocumentMarker::description() const { | 225 const String& DocumentMarker::description() const { |
(...skipping 29 matching lines...) Expand all Loading... |
208 toTextCompositionMarkerDetails(m_details.get())) | 255 toTextCompositionMarkerDetails(m_details.get())) |
209 return details->backgroundColor(); | 256 return details->backgroundColor(); |
210 return Color::transparent; | 257 return Color::transparent; |
211 } | 258 } |
212 | 259 |
213 DEFINE_TRACE(DocumentMarker) { | 260 DEFINE_TRACE(DocumentMarker) { |
214 visitor->trace(m_details); | 261 visitor->trace(m_details); |
215 } | 262 } |
216 | 263 |
217 } // namespace blink | 264 } // namespace blink |
OLD | NEW |