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 if (startOffset() > offset) { |
| 181 // Deviation from the concept-cd-replace algorithm: < instead of <= in |
| 182 // the next line |
| 183 if (startOffset() < offset + oldLength) { |
| 184 // Marker start was in the replaced text. Move to end of new text |
| 185 // (Deviation from the concept-cd-replace algorithm: that algorithm |
| 186 // would move to the beginning of the new text here) |
| 187 result.newStartOffset = offset + newLength; |
| 188 } else { |
| 189 // Marker start was after the replaced text. Shift by length |
| 190 // difference |
| 191 result.newStartOffset = startOffset() + newLength - oldLength; |
| 192 } |
| 193 } |
| 194 |
| 195 if (endOffset() > offset) { |
| 196 // Deviation from the concept-cd-replace algorithm: < instead of <= in |
| 197 // the next line |
| 198 if (endOffset() < offset + oldLength) { |
| 199 // Marker end was in the replaced text. Move to beginning of new text |
| 200 result.newEndOffset = offset; |
| 201 } else { |
| 202 // Marker end was after the replaced text. Shift by length difference |
| 203 result.newEndOffset = endOffset() + newLength - oldLength; |
| 204 } |
| 205 } |
| 206 |
| 207 if (result.newStartOffset >= result.newEndOffset) |
| 208 result.shouldRemoveMarker = true; |
| 209 |
| 210 return result; |
| 211 } |
| 212 |
169 void DocumentMarker::shiftOffsets(int delta) { | 213 void DocumentMarker::shiftOffsets(int delta) { |
170 m_startOffset += delta; | 214 m_startOffset += delta; |
171 m_endOffset += delta; | 215 m_endOffset += delta; |
172 } | 216 } |
173 | 217 |
174 void DocumentMarker::setActiveMatch(bool active) { | 218 void DocumentMarker::setActiveMatch(bool active) { |
175 m_details = DocumentMarkerTextMatch::create(active); | 219 m_details = DocumentMarkerTextMatch::create(active); |
176 } | 220 } |
177 | 221 |
178 const String& DocumentMarker::description() const { | 222 const String& DocumentMarker::description() const { |
(...skipping 29 matching lines...) Expand all Loading... |
208 toTextCompositionMarkerDetails(m_details.get())) | 252 toTextCompositionMarkerDetails(m_details.get())) |
209 return details->backgroundColor(); | 253 return details->backgroundColor(); |
210 return Color::transparent; | 254 return Color::transparent; |
211 } | 255 } |
212 | 256 |
213 DEFINE_TRACE(DocumentMarker) { | 257 DEFINE_TRACE(DocumentMarker) { |
214 visitor->trace(m_details); | 258 visitor->trace(m_details); |
215 } | 259 } |
216 | 260 |
217 } // namespace blink | 261 } // namespace blink |
OLD | NEW |