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

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

Issue 2833753004: [DMC #1.915] Refactor DocumentMarkerController::RemoveMarkers(const MarkerRemoverPredicate&) (Closed)
Patch Set: Use const Created 3 years, 8 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
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 27 matching lines...) Expand all
38 #include "core/editing/markers/RenderedDocumentMarker.h" 38 #include "core/editing/markers/RenderedDocumentMarker.h"
39 #include "core/frame/FrameView.h" 39 #include "core/frame/FrameView.h"
40 #include "core/layout/LayoutObject.h" 40 #include "core/layout/LayoutObject.h"
41 41
42 #ifndef NDEBUG 42 #ifndef NDEBUG
43 #include <stdio.h> 43 #include <stdio.h>
44 #endif 44 #endif
45 45
46 namespace blink { 46 namespace blink {
47 47
48 MarkerRemoverPredicate::MarkerRemoverPredicate(const Vector<String>& words)
49 : words_(words) {}
50
51 bool MarkerRemoverPredicate::operator()(const DocumentMarker& document_marker,
52 const Text& text_node) const {
53 unsigned start = document_marker.StartOffset();
54 unsigned length = document_marker.EndOffset() - document_marker.StartOffset();
55
56 String marker_text = text_node.data().Substring(start, length);
57 return words_.Contains(marker_text);
58 }
59
60 namespace { 48 namespace {
61 49
62 DocumentMarker::MarkerTypeIndex MarkerTypeToMarkerIndex( 50 DocumentMarker::MarkerTypeIndex MarkerTypeToMarkerIndex(
63 DocumentMarker::MarkerType type) { 51 DocumentMarker::MarkerType type) {
64 switch (type) { 52 switch (type) {
65 case DocumentMarker::kSpelling: 53 case DocumentMarker::kSpelling:
66 return DocumentMarker::kSpellingMarkerIndex; 54 return DocumentMarker::kSpellingMarkerIndex;
67 case DocumentMarker::kGrammar: 55 case DocumentMarker::kGrammar:
68 return DocumentMarker::kGrammarMarkerIndex; 56 return DocumentMarker::kGrammarMarkerIndex;
69 case DocumentMarker::kTextMatch: 57 case DocumentMarker::kTextMatch:
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 DocumentMarker::MarkerTypes marker_types) { 489 DocumentMarker::MarkerTypes marker_types) {
502 if (!PossiblyHasMarkers(marker_types)) 490 if (!PossiblyHasMarkers(marker_types))
503 return; 491 return;
504 DCHECK(!markers_.IsEmpty()); 492 DCHECK(!markers_.IsEmpty());
505 493
506 MarkerMap::iterator iterator = markers_.Find(node); 494 MarkerMap::iterator iterator = markers_.Find(node);
507 if (iterator != markers_.end()) 495 if (iterator != markers_.end())
508 RemoveMarkersFromList(iterator, marker_types); 496 RemoveMarkersFromList(iterator, marker_types);
509 } 497 }
510 498
511 void DocumentMarkerController::RemoveMarkers( 499 void DocumentMarkerController::RemoveSpellingMarkersUnderWords(
512 const MarkerRemoverPredicate& should_remove_marker) { 500 const Vector<String>& words) {
513 for (auto& node_markers : markers_) { 501 for (auto& node_markers : markers_) {
514 const Node& node = *node_markers.key; 502 const Node& node = *node_markers.key;
515 if (!node.IsTextNode()) // MarkerRemoverPredicate requires a Text node. 503 if (!node.IsTextNode()) // MarkerRemoverPredicate requires a Text node.
516 continue; 504 continue;
517 MarkerLists& markers = *node_markers.value; 505 MarkerLists& markers = *node_markers.value;
518 for (size_t marker_list_index = 0; 506 for (size_t marker_list_index = 0;
519 marker_list_index < DocumentMarker::kMarkerTypeIndexesCount; 507 marker_list_index < DocumentMarker::kMarkerTypeIndexesCount;
520 ++marker_list_index) { 508 ++marker_list_index) {
521 Member<MarkerList>& list = markers[marker_list_index]; 509 Member<MarkerList>& list = markers[marker_list_index];
522 if (!list) 510 if (!list)
523 continue; 511 continue;
524 bool removed_markers = false; 512 bool removed_markers = false;
525 for (size_t j = list->size(); j > 0; --j) { 513 for (size_t j = list->size(); j > 0; --j) {
526 if (should_remove_marker(*list->at(j - 1), 514 const DocumentMarker& marker = *list->at(j - 1);
527 static_cast<const Text&>(node))) { 515
516 const unsigned start = marker.StartOffset();
517 const unsigned length = marker.EndOffset() - marker.StartOffset();
518
519 const String marker_text = ToText(node).data().Substring(start, length);
rlanday 2017/04/22 10:03:23 oops, missed making this a reference here, I'm mov
520 if (words.Contains(marker_text)) {
528 list->erase(j - 1); 521 list->erase(j - 1);
529 removed_markers = true; 522 removed_markers = true;
530 } 523 }
531 } 524 }
532 if (removed_markers && 525 if (removed_markers &&
533 marker_list_index == DocumentMarker::kTextMatchMarkerIndex) 526 marker_list_index == DocumentMarker::kTextMatchMarkerIndex)
534 InvalidatePaintForTickmarks(node); 527 InvalidatePaintForTickmarks(node);
535 } 528 }
536 } 529 }
537 } 530 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } 758 }
766 759
767 } // namespace blink 760 } // namespace blink
768 761
769 #ifndef NDEBUG 762 #ifndef NDEBUG
770 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { 763 void showDocumentMarkers(const blink::DocumentMarkerController* controller) {
771 if (controller) 764 if (controller)
772 controller->ShowMarkers(); 765 controller->ShowMarkers();
773 } 766 }
774 #endif 767 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698