Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp

Issue 2891843003: Fix bug causing DCHECKs to be hit in DocumentMarkerController (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void DocumentMarkerController::PrepareForDestruction() { 157 void DocumentMarkerController::PrepareForDestruction() {
158 Clear(); 158 Clear();
159 } 159 }
160 160
161 void DocumentMarkerController::RemoveMarkers( 161 void DocumentMarkerController::RemoveMarkers(
162 TextIterator& marked_text, 162 TextIterator& marked_text,
163 DocumentMarker::MarkerTypes marker_types) { 163 DocumentMarker::MarkerTypes marker_types) {
164 for (; !marked_text.AtEnd(); marked_text.Advance()) { 164 for (; !marked_text.AtEnd(); marked_text.Advance()) {
165 if (!PossiblyHasMarkers(marker_types)) 165 if (!PossiblyHasMarkers(marker_types))
166 return; 166 return;
167 DCHECK(!markers_.IsEmpty());
yosin_UTC9 2017/05/18 04:29:08 Rather than removing DCHECK, how about changing Po
168 167
169 int start_offset = marked_text.StartOffsetInCurrentContainer(); 168 int start_offset = marked_text.StartOffsetInCurrentContainer();
170 int end_offset = marked_text.EndOffsetInCurrentContainer(); 169 int end_offset = marked_text.EndOffsetInCurrentContainer();
171 RemoveMarkersInternal(marked_text.CurrentContainer(), start_offset, 170 RemoveMarkersInternal(marked_text.CurrentContainer(), start_offset,
172 end_offset - start_offset, marker_types); 171 end_offset - start_offset, marker_types);
173 } 172 }
174 } 173 }
175 174
176 void DocumentMarkerController::RemoveMarkersInRange( 175 void DocumentMarkerController::RemoveMarkersInRange(
177 const EphemeralRange& range, 176 const EphemeralRange& range,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Moves markers from src_node to dst_node. Markers are moved if their start 237 // Moves markers from src_node to dst_node. Markers are moved if their start
239 // offset is less than length. Markers that run past that point are truncated. 238 // offset is less than length. Markers that run past that point are truncated.
240 void DocumentMarkerController::MoveMarkers(Node* src_node, 239 void DocumentMarkerController::MoveMarkers(Node* src_node,
241 int length, 240 int length,
242 Node* dst_node) { 241 Node* dst_node) {
243 if (length <= 0) 242 if (length <= 0)
244 return; 243 return;
245 244
246 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers())) 245 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers()))
247 return; 246 return;
248 DCHECK(!markers_.IsEmpty());
249 247
250 MarkerLists* src_markers = markers_.at(src_node); 248 MarkerLists* src_markers = markers_.at(src_node);
251 if (!src_markers) 249 if (!src_markers)
252 return; 250 return;
253 251
254 if (!markers_.Contains(dst_node)) { 252 if (!markers_.Contains(dst_node)) {
255 markers_.insert(dst_node, 253 markers_.insert(dst_node,
256 new MarkerLists(DocumentMarker::kMarkerTypeIndexesCount)); 254 new MarkerLists(DocumentMarker::kMarkerTypeIndexesCount));
257 } 255 }
258 MarkerLists* dst_markers = markers_.at(dst_node); 256 MarkerLists* dst_markers = markers_.at(dst_node);
(...skipping 22 matching lines...) Expand all
281 void DocumentMarkerController::RemoveMarkersInternal( 279 void DocumentMarkerController::RemoveMarkersInternal(
282 Node* node, 280 Node* node,
283 unsigned start_offset, 281 unsigned start_offset,
284 int length, 282 int length,
285 DocumentMarker::MarkerTypes marker_types) { 283 DocumentMarker::MarkerTypes marker_types) {
286 if (length <= 0) 284 if (length <= 0)
287 return; 285 return;
288 286
289 if (!PossiblyHasMarkers(marker_types)) 287 if (!PossiblyHasMarkers(marker_types))
290 return; 288 return;
291 DCHECK(!(markers_.IsEmpty()));
292 289
293 MarkerLists* markers = markers_.at(node); 290 MarkerLists* markers = markers_.at(node);
294 if (!markers) 291 if (!markers)
295 return; 292 return;
296 293
297 bool doc_dirty = false; 294 bool doc_dirty = false;
298 size_t empty_lists_count = 0; 295 size_t empty_lists_count = 0;
299 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 296 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
300 DocumentMarkerList* const list = ListForType(markers, type); 297 DocumentMarkerList* const list = ListForType(markers, type);
301 if (!list || list->IsEmpty()) { 298 if (!list || list->IsEmpty()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 }); 386 });
390 return result; 387 return result;
391 } 388 }
392 389
393 Vector<IntRect> DocumentMarkerController::RenderedRectsForMarkers( 390 Vector<IntRect> DocumentMarkerController::RenderedRectsForMarkers(
394 DocumentMarker::MarkerType marker_type) { 391 DocumentMarker::MarkerType marker_type) {
395 Vector<IntRect> result; 392 Vector<IntRect> result;
396 393
397 if (!PossiblyHasMarkers(marker_type)) 394 if (!PossiblyHasMarkers(marker_type))
398 return result; 395 return result;
399 DCHECK(!(markers_.IsEmpty()));
400 396
401 // outer loop: process each node 397 // outer loop: process each node
402 MarkerMap::iterator end = markers_.end(); 398 MarkerMap::iterator end = markers_.end();
403 for (MarkerMap::iterator node_iterator = markers_.begin(); 399 for (MarkerMap::iterator node_iterator = markers_.begin();
404 node_iterator != end; ++node_iterator) { 400 node_iterator != end; ++node_iterator) {
405 // inner loop; process each marker in this node 401 // inner loop; process each marker in this node
406 const Node& node = *node_iterator->key; 402 const Node& node = *node_iterator->key;
407 if (!node.isConnected()) 403 if (!node.isConnected())
408 continue; 404 continue;
409 MarkerLists* markers = node_iterator->value.Get(); 405 MarkerLists* markers = node_iterator->value.Get();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 visitor->Trace(markers_); 474 visitor->Trace(markers_);
479 visitor->Trace(document_); 475 visitor->Trace(document_);
480 SynchronousMutationObserver::Trace(visitor); 476 SynchronousMutationObserver::Trace(visitor);
481 } 477 }
482 478
483 void DocumentMarkerController::RemoveMarkersForNode( 479 void DocumentMarkerController::RemoveMarkersForNode(
484 Node* node, 480 Node* node,
485 DocumentMarker::MarkerTypes marker_types) { 481 DocumentMarker::MarkerTypes marker_types) {
486 if (!PossiblyHasMarkers(marker_types)) 482 if (!PossiblyHasMarkers(marker_types))
487 return; 483 return;
488 DCHECK(!markers_.IsEmpty());
489 484
490 MarkerMap::iterator iterator = markers_.find(node); 485 MarkerMap::iterator iterator = markers_.find(node);
491 if (iterator != markers_.end()) 486 if (iterator != markers_.end())
492 RemoveMarkersFromList(iterator, marker_types); 487 RemoveMarkersFromList(iterator, marker_types);
493 } 488 }
494 489
495 void DocumentMarkerController::RemoveSpellingMarkersUnderWords( 490 void DocumentMarkerController::RemoveSpellingMarkersUnderWords(
496 const Vector<String>& words) { 491 const Vector<String>& words) {
497 for (auto& node_markers : markers_) { 492 for (auto& node_markers : markers_) {
498 const Node& node = *node_markers.key; 493 const Node& node = *node_markers.key;
499 if (!node.IsTextNode()) 494 if (!node.IsTextNode())
500 continue; 495 continue;
501 MarkerLists* markers = node_markers.value; 496 MarkerLists* markers = node_markers.value;
502 for (DocumentMarker::MarkerType type : 497 for (DocumentMarker::MarkerType type :
503 DocumentMarker::MisspellingMarkers()) { 498 DocumentMarker::MisspellingMarkers()) {
504 DocumentMarkerList* const list = ListForType(markers, type); 499 DocumentMarkerList* const list = ListForType(markers, type);
505 if (!list) 500 if (!list)
506 continue; 501 continue;
507 ToSpellCheckMarkerListImpl(list)->RemoveMarkersUnderWords( 502 ToSpellCheckMarkerListImpl(list)->RemoveMarkersUnderWords(
508 ToText(node).data(), words); 503 ToText(node).data(), words);
509 } 504 }
510 } 505 }
511 } 506 }
512 507
513 void DocumentMarkerController::RemoveMarkersOfTypes( 508 void DocumentMarkerController::RemoveMarkersOfTypes(
514 DocumentMarker::MarkerTypes marker_types) { 509 DocumentMarker::MarkerTypes marker_types) {
515 if (!PossiblyHasMarkers(marker_types)) 510 if (!PossiblyHasMarkers(marker_types))
516 return; 511 return;
517 DCHECK(!markers_.IsEmpty());
518 512
519 HeapVector<Member<const Node>> nodes_with_markers; 513 HeapVector<Member<const Node>> nodes_with_markers;
520 CopyKeysToVector(markers_, nodes_with_markers); 514 CopyKeysToVector(markers_, nodes_with_markers);
521 unsigned size = nodes_with_markers.size(); 515 unsigned size = nodes_with_markers.size();
522 for (unsigned i = 0; i < size; ++i) { 516 for (unsigned i = 0; i < size; ++i) {
523 MarkerMap::iterator iterator = markers_.find(nodes_with_markers[i]); 517 MarkerMap::iterator iterator = markers_.find(nodes_with_markers[i]);
524 if (iterator != markers_.end()) 518 if (iterator != markers_.end())
525 RemoveMarkersFromList(iterator, marker_types); 519 RemoveMarkersFromList(iterator, marker_types);
526 } 520 }
527 521
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 markers_.erase(iterator); 568 markers_.erase(iterator);
575 if (markers_.IsEmpty()) 569 if (markers_.IsEmpty())
576 possibly_existing_marker_types_ = 0; 570 possibly_existing_marker_types_ = 0;
577 } 571 }
578 } 572 }
579 573
580 void DocumentMarkerController::RepaintMarkers( 574 void DocumentMarkerController::RepaintMarkers(
581 DocumentMarker::MarkerTypes marker_types) { 575 DocumentMarker::MarkerTypes marker_types) {
582 if (!PossiblyHasMarkers(marker_types)) 576 if (!PossiblyHasMarkers(marker_types))
583 return; 577 return;
584 DCHECK(!markers_.IsEmpty());
585 578
586 // outer loop: process each markered node in the document 579 // outer loop: process each markered node in the document
587 MarkerMap::iterator end = markers_.end(); 580 MarkerMap::iterator end = markers_.end();
588 for (MarkerMap::iterator i = markers_.begin(); i != end; ++i) { 581 for (MarkerMap::iterator i = markers_.begin(); i != end; ++i) {
589 const Node* node = i->key; 582 const Node* node = i->key;
590 583
591 // inner loop: process each marker in the current node 584 // inner loop: process each marker in the current node
592 MarkerLists* markers = i->value.Get(); 585 MarkerLists* markers = i->value.Get();
593 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 586 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
594 DocumentMarkerList* const list = ListForType(markers, type); 587 DocumentMarkerList* const list = ListForType(markers, type);
595 if (!list || list->IsEmpty() || !marker_types.Contains(type)) 588 if (!list || list->IsEmpty() || !marker_types.Contains(type))
596 continue; 589 continue;
597 590
598 // cause the node to be redrawn 591 // cause the node to be redrawn
599 if (LayoutObject* layout_object = node->GetLayoutObject()) { 592 if (LayoutObject* layout_object = node->GetLayoutObject()) {
600 layout_object->SetShouldDoFullPaintInvalidation( 593 layout_object->SetShouldDoFullPaintInvalidation(
601 PaintInvalidationReason::kDocumentMarker); 594 PaintInvalidationReason::kDocumentMarker);
602 break; 595 break;
603 } 596 }
604 } 597 }
605 } 598 }
606 } 599 }
607 600
608 bool DocumentMarkerController::SetMarkersActive(const EphemeralRange& range, 601 bool DocumentMarkerController::SetMarkersActive(const EphemeralRange& range,
609 bool active) { 602 bool active) {
610 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers())) 603 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers()))
611 return false; 604 return false;
612 605
613 DCHECK(!markers_.IsEmpty());
614
615 Node* const start_container = range.StartPosition().ComputeContainerNode(); 606 Node* const start_container = range.StartPosition().ComputeContainerNode();
616 DCHECK(start_container); 607 DCHECK(start_container);
617 Node* const end_container = range.EndPosition().ComputeContainerNode(); 608 Node* const end_container = range.EndPosition().ComputeContainerNode();
618 DCHECK(end_container); 609 DCHECK(end_container);
619 610
620 const unsigned container_start_offset = 611 const unsigned container_start_offset =
621 range.StartPosition().ComputeOffsetInContainerNode(); 612 range.StartPosition().ComputeOffsetInContainerNode();
622 const unsigned container_end_offset = 613 const unsigned container_end_offset =
623 range.EndPosition().ComputeOffsetInContainerNode(); 614 range.EndPosition().ComputeOffsetInContainerNode();
624 615
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } 697 }
707 #endif 698 #endif
708 699
709 // SynchronousMutationObserver 700 // SynchronousMutationObserver
710 void DocumentMarkerController::DidUpdateCharacterData(CharacterData* node, 701 void DocumentMarkerController::DidUpdateCharacterData(CharacterData* node,
711 unsigned offset, 702 unsigned offset,
712 unsigned old_length, 703 unsigned old_length,
713 unsigned new_length) { 704 unsigned new_length) {
714 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers())) 705 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers()))
715 return; 706 return;
716 DCHECK(!markers_.IsEmpty());
717 707
718 MarkerLists* markers = markers_.at(node); 708 MarkerLists* markers = markers_.at(node);
719 if (!markers) 709 if (!markers)
720 return; 710 return;
721 711
722 bool did_shift_marker = false; 712 bool did_shift_marker = false;
723 for (DocumentMarkerList* const list : *markers) { 713 for (DocumentMarkerList* const list : *markers) {
724 if (!list) 714 if (!list)
725 continue; 715 continue;
726 716
(...skipping 11 matching lines...) Expand all
738 } 728 }
739 729
740 } // namespace blink 730 } // namespace blink
741 731
742 #ifndef NDEBUG 732 #ifndef NDEBUG
743 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { 733 void showDocumentMarkers(const blink::DocumentMarkerController* controller) {
744 if (controller) 734 if (controller)
745 controller->ShowMarkers(); 735 controller->ShowMarkers();
746 } 736 }
747 #endif 737 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698