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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 marked_text.EndOffsetInCurrentContainer(), | 139 marked_text.EndOffsetInCurrentContainer(), |
140 underline_color, thick, background_color)); | 140 underline_color, thick, background_color)); |
141 } | 141 } |
142 | 142 |
143 void DocumentMarkerController::PrepareForDestruction() { | 143 void DocumentMarkerController::PrepareForDestruction() { |
144 Clear(); | 144 Clear(); |
145 } | 145 } |
146 | 146 |
147 void DocumentMarkerController::RemoveMarkers( | 147 void DocumentMarkerController::RemoveMarkers( |
148 TextIterator& marked_text, | 148 TextIterator& marked_text, |
149 DocumentMarker::MarkerTypes marker_types, | 149 DocumentMarker::MarkerTypes marker_types) { |
150 RemovePartiallyOverlappingMarkerOrNot | |
151 should_remove_partially_overlapping_marker) { | |
152 for (; !marked_text.AtEnd(); marked_text.Advance()) { | 150 for (; !marked_text.AtEnd(); marked_text.Advance()) { |
153 if (!PossiblyHasMarkers(marker_types)) | 151 if (!PossiblyHasMarkers(marker_types)) |
154 return; | 152 return; |
155 DCHECK(!markers_.IsEmpty()); | 153 DCHECK(!markers_.IsEmpty()); |
156 | 154 |
157 int start_offset = marked_text.StartOffsetInCurrentContainer(); | 155 int start_offset = marked_text.StartOffsetInCurrentContainer(); |
158 int end_offset = marked_text.EndOffsetInCurrentContainer(); | 156 int end_offset = marked_text.EndOffsetInCurrentContainer(); |
159 RemoveMarkers(marked_text.CurrentContainer(), start_offset, | 157 RemoveMarkers(marked_text.CurrentContainer(), start_offset, |
160 end_offset - start_offset, marker_types, | 158 end_offset - start_offset, marker_types); |
161 should_remove_partially_overlapping_marker); | |
162 } | 159 } |
163 } | 160 } |
164 | 161 |
165 void DocumentMarkerController::RemoveMarkers( | 162 void DocumentMarkerController::RemoveMarkers( |
166 const EphemeralRange& range, | 163 const EphemeralRange& range, |
167 DocumentMarker::MarkerTypes marker_types, | 164 DocumentMarker::MarkerTypes marker_types) { |
168 RemovePartiallyOverlappingMarkerOrNot | |
169 should_remove_partially_overlapping_marker) { | |
170 DCHECK(!document_->NeedsLayoutTreeUpdate()); | 165 DCHECK(!document_->NeedsLayoutTreeUpdate()); |
171 | 166 |
172 TextIterator marked_text(range.StartPosition(), range.EndPosition()); | 167 TextIterator marked_text(range.StartPosition(), range.EndPosition()); |
173 DocumentMarkerController::RemoveMarkers( | 168 DocumentMarkerController::RemoveMarkers(marked_text, marker_types); |
174 marked_text, marker_types, should_remove_partially_overlapping_marker); | |
175 } | 169 } |
176 | 170 |
177 static bool StartsFurther(const Member<RenderedDocumentMarker>& lhv, | 171 static bool StartsFurther(const Member<RenderedDocumentMarker>& lhv, |
178 const DocumentMarker* rhv) { | 172 const DocumentMarker* rhv) { |
179 return lhv->StartOffset() < rhv->StartOffset(); | 173 return lhv->StartOffset() < rhv->StartOffset(); |
180 } | 174 } |
181 | 175 |
182 static bool EndsBefore(size_t start_offset, | 176 static bool EndsBefore(size_t start_offset, |
183 const Member<RenderedDocumentMarker>& rhv) { | 177 const Member<RenderedDocumentMarker>& rhv) { |
184 return start_offset < rhv->EndOffset(); | 178 return start_offset < rhv->EndOffset(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (doc_dirty && dst_node->GetLayoutObject()) { | 321 if (doc_dirty && dst_node->GetLayoutObject()) { |
328 dst_node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( | 322 dst_node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( |
329 kPaintInvalidationDocumentMarkerChange); | 323 kPaintInvalidationDocumentMarkerChange); |
330 } | 324 } |
331 } | 325 } |
332 | 326 |
333 void DocumentMarkerController::RemoveMarkers( | 327 void DocumentMarkerController::RemoveMarkers( |
334 Node* node, | 328 Node* node, |
335 unsigned start_offset, | 329 unsigned start_offset, |
336 int length, | 330 int length, |
337 DocumentMarker::MarkerTypes marker_types, | 331 DocumentMarker::MarkerTypes marker_types) { |
338 RemovePartiallyOverlappingMarkerOrNot | |
339 should_remove_partially_overlapping_marker) { | |
340 if (length <= 0) | 332 if (length <= 0) |
341 return; | 333 return; |
342 | 334 |
343 if (!PossiblyHasMarkers(marker_types)) | 335 if (!PossiblyHasMarkers(marker_types)) |
344 return; | 336 return; |
345 DCHECK(!(markers_.IsEmpty())); | 337 DCHECK(!(markers_.IsEmpty())); |
346 | 338 |
347 MarkerLists* markers = markers_.at(node); | 339 MarkerLists* markers = markers_.at(node); |
348 if (!markers) | 340 if (!markers) |
349 return; | 341 return; |
(...skipping 16 matching lines...) Expand all Loading... |
366 MarkerList::iterator start_pos = | 358 MarkerList::iterator start_pos = |
367 std::upper_bound(list->begin(), list->end(), start_offset, EndsBefore); | 359 std::upper_bound(list->begin(), list->end(), start_offset, EndsBefore); |
368 for (MarkerList::iterator i = start_pos; i != list->end();) { | 360 for (MarkerList::iterator i = start_pos; i != list->end();) { |
369 DocumentMarker marker(*i->Get()); | 361 DocumentMarker marker(*i->Get()); |
370 | 362 |
371 // markers are returned in order, so stop if we are now past the specified | 363 // markers are returned in order, so stop if we are now past the specified |
372 // range | 364 // range |
373 if (marker.StartOffset() >= end_offset) | 365 if (marker.StartOffset() >= end_offset) |
374 break; | 366 break; |
375 | 367 |
376 // at this point we know that marker and target intersect in some way | 368 list->erase(i - list->begin()); |
377 doc_dirty = true; | 369 doc_dirty = true; |
378 | |
379 // pitch the old marker | |
380 list->erase(i - list->begin()); | |
381 | |
382 if (should_remove_partially_overlapping_marker) { | |
383 // Stop here. Don't add resulting slices back. | |
384 continue; | |
385 } | |
386 | |
387 // add either of the resulting slices that are left after removing target | |
388 if (start_offset > marker.StartOffset()) { | |
389 DocumentMarker new_left = marker; | |
390 new_left.SetEndOffset(start_offset); | |
391 size_t insert_index = i - list->begin(); | |
392 list->insert(insert_index, RenderedDocumentMarker::Create(new_left)); | |
393 // Move to the marker after the inserted one. | |
394 i = list->begin() + insert_index + 1; | |
395 } | |
396 if (marker.EndOffset() > end_offset) { | |
397 DocumentMarker new_right = marker; | |
398 new_right.SetStartOffset(end_offset); | |
399 size_t insert_index = i - list->begin(); | |
400 list->insert(insert_index, RenderedDocumentMarker::Create(new_right)); | |
401 // Move to the marker after the inserted one. | |
402 i = list->begin() + insert_index + 1; | |
403 } | |
404 } | 370 } |
405 | 371 |
406 if (list->IsEmpty()) { | 372 if (list->IsEmpty()) { |
407 list.Clear(); | 373 list.Clear(); |
408 ++empty_lists_count; | 374 ++empty_lists_count; |
409 } | 375 } |
410 } | 376 } |
411 | 377 |
412 if (empty_lists_count == DocumentMarker::kMarkerTypeIndexesCount) { | 378 if (empty_lists_count == DocumentMarker::kMarkerTypeIndexesCount) { |
413 markers_.erase(node); | 379 markers_.erase(node); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 832 } |
867 | 833 |
868 } // namespace blink | 834 } // namespace blink |
869 | 835 |
870 #ifndef NDEBUG | 836 #ifndef NDEBUG |
871 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { | 837 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { |
872 if (controller) | 838 if (controller) |
873 controller->ShowMarkers(); | 839 controller->ShowMarkers(); |
874 } | 840 } |
875 #endif | 841 #endif |
OLD | NEW |