OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights |
7 * reserved. | 7 * reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 static bool CompareByStart(const Member<DocumentMarker>& lhv, | 187 static bool CompareByStart(const Member<DocumentMarker>& lhv, |
188 const Member<DocumentMarker>& rhv) { | 188 const Member<DocumentMarker>& rhv) { |
189 return lhv->StartOffset() < rhv->StartOffset(); | 189 return lhv->StartOffset() < rhv->StartOffset(); |
190 } | 190 } |
191 | 191 |
192 static bool DoesNotOverlap(const Member<RenderedDocumentMarker>& lhv, | 192 static bool DoesNotOverlap(const Member<RenderedDocumentMarker>& lhv, |
193 const DocumentMarker* rhv) { | 193 const DocumentMarker* rhv) { |
194 return lhv->EndOffset() < rhv->StartOffset(); | 194 return lhv->EndOffset() < rhv->StartOffset(); |
195 } | 195 } |
196 | 196 |
197 static bool DoesNotInclude(const Member<RenderedDocumentMarker>& marker, | |
198 size_t start_offset) { | |
199 return marker->EndOffset() < start_offset; | |
200 } | |
201 | |
202 static void UpdateMarkerRenderedRect(const Node& node, | 197 static void UpdateMarkerRenderedRect(const Node& node, |
203 RenderedDocumentMarker& marker) { | 198 RenderedDocumentMarker& marker) { |
204 Range* range = Range::Create(node.GetDocument()); | 199 Range* range = Range::Create(node.GetDocument()); |
205 // The offsets of the marker may be out-dated, so check for exceptions. | 200 // The offsets of the marker may be out-dated, so check for exceptions. |
206 DummyExceptionStateForTesting exception_state; | 201 DummyExceptionStateForTesting exception_state; |
207 range->setStart(&const_cast<Node&>(node), marker.StartOffset(), | 202 range->setStart(&const_cast<Node&>(node), marker.StartOffset(), |
208 exception_state); | 203 exception_state); |
209 if (!exception_state.HadException()) { | 204 if (!exception_state.HadException()) { |
210 range->setEnd(&const_cast<Node&>(node), marker.EndOffset(), | 205 range->setEnd(&const_cast<Node&>(node), marker.EndOffset(), |
211 IGNORE_EXCEPTION_FOR_TESTING); | 206 IGNORE_EXCEPTION_FOR_TESTING); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 for (MarkerList::iterator i = first_overlapping; | 274 for (MarkerList::iterator i = first_overlapping; |
280 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { | 275 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { |
281 (*inserted)->SetStartOffset( | 276 (*inserted)->SetStartOffset( |
282 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); | 277 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); |
283 (*inserted)->SetEndOffset( | 278 (*inserted)->SetEndOffset( |
284 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); | 279 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); |
285 list->erase(i - list->begin()); | 280 list->erase(i - list->begin()); |
286 } | 281 } |
287 } | 282 } |
288 | 283 |
289 // copies markers from srcNode to dstNode, applying the specified shift delta to | 284 // Moves markers from src_node to dst_node. Markers are moved if their start |
290 // the copies. The shift is useful if, e.g., the caller has created the dstNode | 285 // offset is less than length. Markers that run past that point are truncated. |
291 // from a non-prefix substring of the srcNode. | 286 void DocumentMarkerController::MoveMarkers(Node* src_node, |
292 void DocumentMarkerController::CopyMarkers(Node* src_node, | |
293 unsigned start_offset, | |
294 int length, | 287 int length, |
295 Node* dst_node, | 288 Node* dst_node) { |
296 int delta) { | |
297 if (length <= 0) | 289 if (length <= 0) |
298 return; | 290 return; |
299 | 291 |
300 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers())) | 292 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers())) |
301 return; | 293 return; |
302 DCHECK(!markers_.IsEmpty()); | 294 DCHECK(!markers_.IsEmpty()); |
303 | 295 |
304 MarkerLists* markers = markers_.at(src_node); | 296 MarkerLists* markers = markers_.at(src_node); |
305 if (!markers) | 297 if (!markers) |
306 return; | 298 return; |
307 | 299 |
308 bool doc_dirty = false; | 300 bool doc_dirty = false; |
309 for (Member<MarkerList> list : *markers) { | 301 for (Member<MarkerList> list : *markers) { |
310 if (!list) | 302 if (!list) |
311 continue; | 303 continue; |
312 | 304 |
313 unsigned end_offset = start_offset + length - 1; | 305 unsigned end_offset = length - 1; |
314 MarkerList::iterator start_pos = std::lower_bound( | 306 MarkerList::iterator it; |
315 list->begin(), list->end(), start_offset, DoesNotInclude); | 307 for (it = list->begin(); it != list->end(); ++it) { |
316 for (MarkerList::iterator i = start_pos; i != list->end(); ++i) { | 308 DocumentMarker* marker = it->Get(); |
317 DocumentMarker* marker = i->Get(); | |
318 | 309 |
319 // stop if we are now past the specified range | 310 // stop if we are now past the specified range |
320 if (marker->StartOffset() > end_offset) | 311 if (marker->StartOffset() > end_offset) |
321 break; | 312 break; |
322 | 313 |
323 // pin the marker to the specified range and apply the shift delta | 314 // pin the marker to the specified range |
324 doc_dirty = true; | 315 doc_dirty = true; |
325 if (marker->StartOffset() < start_offset) | |
326 marker->SetStartOffset(start_offset); | |
327 if (marker->EndOffset() > end_offset) | 316 if (marker->EndOffset() > end_offset) |
328 marker->SetEndOffset(end_offset); | 317 marker->SetEndOffset(end_offset); |
329 marker->ShiftOffsets(delta); | |
330 | 318 |
331 AddMarker(dst_node, *marker); | 319 AddMarker(dst_node, *marker); |
332 } | 320 } |
| 321 |
| 322 // Remove the range of markers that were moved to dstNode |
| 323 list->erase(0, it - list->begin()); |
333 } | 324 } |
334 | 325 |
335 // repaint the affected node | 326 // repaint the affected node |
336 if (doc_dirty && dst_node->GetLayoutObject()) { | 327 if (doc_dirty && dst_node->GetLayoutObject()) { |
337 dst_node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( | 328 dst_node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( |
338 kPaintInvalidationDocumentMarkerChange); | 329 kPaintInvalidationDocumentMarkerChange); |
339 } | 330 } |
340 } | 331 } |
341 | 332 |
342 void DocumentMarkerController::RemoveMarkers( | 333 void DocumentMarkerController::RemoveMarkers( |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 } | 864 } |
874 | 865 |
875 } // namespace blink | 866 } // namespace blink |
876 | 867 |
877 #ifndef NDEBUG | 868 #ifndef NDEBUG |
878 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { | 869 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { |
879 if (controller) | 870 if (controller) |
880 controller->ShowMarkers(); | 871 controller->ShowMarkers(); |
881 } | 872 } |
882 #endif | 873 #endif |
OLD | NEW |