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
reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
8 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 8 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 13 matching lines...) Expand all Loading... |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/dom/DocumentMarkerController.h" | 28 #include "core/dom/DocumentMarkerController.h" |
29 | 29 |
30 #include "core/dom/Node.h" | 30 #include "core/dom/Node.h" |
31 #include "core/dom/NodeTraversal.h" | 31 #include "core/dom/NodeTraversal.h" |
32 #include "core/dom/Range.h" | 32 #include "core/dom/Range.h" |
33 #include "core/dom/RenderedDocumentMarker.h" | 33 #include "core/dom/RenderedDocumentMarker.h" |
| 34 #include "core/dom/Text.h" |
34 #include "core/editing/TextIterator.h" | 35 #include "core/editing/TextIterator.h" |
35 #include "core/rendering/RenderObject.h" | 36 #include "core/rendering/RenderObject.h" |
36 | 37 |
37 #ifndef NDEBUG | 38 #ifndef NDEBUG |
38 #include <stdio.h> | 39 #include <stdio.h> |
39 #endif | 40 #endif |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
| 44 MarkerRemoverPredicate::MarkerRemoverPredicate(const Vector<String>& words) |
| 45 : m_words(words) |
| 46 { |
| 47 } |
| 48 |
| 49 bool MarkerRemoverPredicate::operator()(const DocumentMarker& documentMarker, |
| 50 const Text* textNode) const { |
| 51 unsigned start = documentMarker.startOffset(); |
| 52 unsigned length = documentMarker.endOffset() - documentMarker.startOffset(); |
| 53 |
| 54 String markerText = textNode->data().substring(start, length); |
| 55 return m_words.contains(markerText); |
| 56 } |
| 57 |
43 namespace { | 58 namespace { |
44 | 59 |
45 DocumentMarker::MarkerTypeIndex MarkerTypeToMarkerIndex(DocumentMarker::MarkerTy
pe type) | 60 DocumentMarker::MarkerTypeIndex MarkerTypeToMarkerIndex(DocumentMarker::MarkerTy
pe type) |
46 { | 61 { |
47 switch (type) { | 62 switch (type) { |
48 case DocumentMarker::Spelling: | 63 case DocumentMarker::Spelling: |
49 return DocumentMarker::SpellingMarkerIndex; | 64 return DocumentMarker::SpellingMarkerIndex; |
50 case DocumentMarker::Grammar: | 65 case DocumentMarker::Grammar: |
51 return DocumentMarker::GramarMarkerIndex; | 66 return DocumentMarker::GramarMarkerIndex; |
52 case DocumentMarker::TextMatch: | 67 case DocumentMarker::TextMatch: |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 { | 502 { |
488 if (!possiblyHasMarkers(markerTypes)) | 503 if (!possiblyHasMarkers(markerTypes)) |
489 return; | 504 return; |
490 ASSERT(!m_markers.isEmpty()); | 505 ASSERT(!m_markers.isEmpty()); |
491 | 506 |
492 MarkerMap::iterator iterator = m_markers.find(node); | 507 MarkerMap::iterator iterator = m_markers.find(node); |
493 if (iterator != m_markers.end()) | 508 if (iterator != m_markers.end()) |
494 removeMarkersFromList(iterator, markerTypes); | 509 removeMarkersFromList(iterator, markerTypes); |
495 } | 510 } |
496 | 511 |
| 512 void DocumentMarkerController::removeMarkers(const MarkerRemoverPredicate& shoul
dRemoveMarker) |
| 513 { |
| 514 for (MarkerMap::iterator i = m_markers.begin(); i != m_markers.end(); ++i) { |
| 515 MarkerLists* markers = i->value.get(); |
| 516 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke
rTypeIndexesCount; ++markerListIndex) { |
| 517 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex]; |
| 518 |
| 519 Vector<RenderedDocumentMarker *> markersToBeRemoved; |
| 520 for (size_t j = 0; list.get() && j < list->size(); ++j) { |
| 521 if (i->key->isTextNode() && shouldRemoveMarker(*list->at(j).get(
), static_cast<const Text*>(i->key))) |
| 522 markersToBeRemoved.append(list->at(j).get()); |
| 523 } |
| 524 |
| 525 for (size_t j = 0; j < markersToBeRemoved.size(); ++j) |
| 526 list->remove(list->find(markersToBeRemoved[j])); |
| 527 } |
| 528 } |
| 529 } |
| 530 |
497 void DocumentMarkerController::removeMarkers(DocumentMarker::MarkerTypes markerT
ypes) | 531 void DocumentMarkerController::removeMarkers(DocumentMarker::MarkerTypes markerT
ypes) |
498 { | 532 { |
499 if (!possiblyHasMarkers(markerTypes)) | 533 if (!possiblyHasMarkers(markerTypes)) |
500 return; | 534 return; |
501 ASSERT(!m_markers.isEmpty()); | 535 ASSERT(!m_markers.isEmpty()); |
502 | 536 |
503 Vector<const Node*> nodesWithMarkers; | 537 Vector<const Node*> nodesWithMarkers; |
504 copyKeysToVector(m_markers, nodesWithMarkers); | 538 copyKeysToVector(m_markers, nodesWithMarkers); |
505 unsigned size = nodesWithMarkers.size(); | 539 unsigned size = nodesWithMarkers.size(); |
506 for (unsigned i = 0; i < size; ++i) { | 540 for (unsigned i = 0; i < size; ++i) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 763 |
730 } // namespace blink | 764 } // namespace blink |
731 | 765 |
732 #ifndef NDEBUG | 766 #ifndef NDEBUG |
733 void showDocumentMarkers(const blink::DocumentMarkerController* controller) | 767 void showDocumentMarkers(const blink::DocumentMarkerController* controller) |
734 { | 768 { |
735 if (controller) | 769 if (controller) |
736 controller->showMarkers(); | 770 controller->showMarkers(); |
737 } | 771 } |
738 #endif | 772 #endif |
OLD | NEW |