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

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: 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 DocumentMarker::MarkerTypes marker_types) { 479 DocumentMarker::MarkerTypes marker_types) {
492 if (!PossiblyHasMarkers(marker_types)) 480 if (!PossiblyHasMarkers(marker_types))
493 return; 481 return;
494 DCHECK(!markers_.IsEmpty()); 482 DCHECK(!markers_.IsEmpty());
495 483
496 MarkerMap::iterator iterator = markers_.Find(node); 484 MarkerMap::iterator iterator = markers_.Find(node);
497 if (iterator != markers_.end()) 485 if (iterator != markers_.end())
498 RemoveMarkersFromList(iterator, marker_types); 486 RemoveMarkersFromList(iterator, marker_types);
499 } 487 }
500 488
501 void DocumentMarkerController::RemoveMarkers( 489 void DocumentMarkerController::RemoveSpellingMarkersUnderWords(
502 const MarkerRemoverPredicate& should_remove_marker) { 490 const Vector<String>& words) {
503 for (auto& node_markers : markers_) { 491 for (auto& node_markers : markers_) {
504 const Node& node = *node_markers.key; 492 const Node& node = *node_markers.key;
505 if (!node.IsTextNode()) // MarkerRemoverPredicate requires a Text node. 493 if (!node.IsTextNode()) // MarkerRemoverPredicate requires a Text node.
506 continue; 494 continue;
507 MarkerLists* markers = node_markers.value; 495 MarkerLists* markers = node_markers.value;
508 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 496 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
Xiaocheng 2017/04/21 05:40:32 Just noticed that this function is wrong... It rem
509 Member<MarkerList>& list = ListForType(markers, type); 497 Member<MarkerList>& list = ListForType(markers, type);
510 if (!list) 498 if (!list)
511 continue; 499 continue;
512 bool removed_markers = false; 500 bool removed_markers = false;
513 for (size_t j = list->size(); j > 0; --j) { 501 for (size_t j = list->size(); j > 0; --j) {
514 if (should_remove_marker(*list->at(j - 1), 502 const DocumentMarker& marker = *list->at(j - 1);
515 static_cast<const Text&>(node))) { 503
504 unsigned start = marker.StartOffset();
yosin_UTC9 2017/04/21 08:29:33 nit: s/unsigned/const unsigned/
505 unsigned length = marker.EndOffset() - marker.StartOffset();
yosin_UTC9 2017/04/21 08:29:33 nit: s/unsigned/const unsigned/
506
507 String marker_text = ToText(node).data().Substring(start, length);
yosin_UTC9 2017/04/21 08:29:33 nit: s/String/const String&/
508 if (words.Contains(marker_text)) {
516 list->erase(j - 1); 509 list->erase(j - 1);
517 removed_markers = true; 510 removed_markers = true;
518 } 511 }
519 } 512 }
520 if (removed_markers && type == DocumentMarker::kTextMatch) 513 if (removed_markers && type == DocumentMarker::kTextMatch)
521 InvalidatePaintForTickmarks(node); 514 InvalidatePaintForTickmarks(node);
522 } 515 }
523 } 516 }
524 } 517 }
525 518
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } 738 }
746 739
747 } // namespace blink 740 } // namespace blink
748 741
749 #ifndef NDEBUG 742 #ifndef NDEBUG
750 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { 743 void showDocumentMarkers(const blink::DocumentMarkerController* controller) {
751 if (controller) 744 if (controller)
752 controller->ShowMarkers(); 745 controller->ShowMarkers();
753 } 746 }
754 #endif 747 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698