1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 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.torchmobile.com/) 8 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Library General Public 12 * License as published by the Free Software Foundation; either 13 * version 2 of the License, or (at your option) any later version. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Library General Public License for more details. 19 * 20 * You should have received a copy of the GNU Library General Public License 21 * along with this library; see the file COPYING.LIB. If not, write to 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 * Boston, MA 02110-1301, USA. 24 * 25 */ 26 27 #ifndef DocumentMarkerController_h 28 #define DocumentMarkerController_h 29 30 #include "DocumentMarker.h" 31 #include <wtf/HashMap.h> 32 #include <wtf/Vector.h> 33 34 namespace WebCore { 35 36 class IntPoint; 37 class IntRect; 38 class Node; 39 class Range; 40 41 class DocumentMarkerController { 42 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); WTF_MAKE_FAST_ALLOCATED; 43 public: 44 DocumentMarkerController(); ~DocumentMarkerController()45 ~DocumentMarkerController() { detach(); } 46 47 void detach(); 48 void addMarker(Range*, DocumentMarker::MarkerType, String description = String()); 49 void addMarker(Node*, DocumentMarker); 50 void copyMarkers(Node* srcNode, unsigned startOffset, int length, Node* dstNode, int delta); 51 bool hasMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 52 53 // When a marker partially overlaps with range, if removePartiallyOverlappingMarkers is true, we completely 54 // remove the marker. If the argument is false, we will adjust the span of the marker so that it retains 55 // the portion that is outside of the range. 56 enum RemovePartiallyOverlappingMarkerOrNot { DoNotRemovePartiallyOverlappingMarker, RemovePartiallyOverlappingMarker }; 57 void removeMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker); 58 void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker); 59 60 void removeMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 61 void removeMarkers(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 62 void repaintMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 63 void setRenderedRectForMarker(Node*, const DocumentMarker&, const IntRect&); 64 void invalidateRenderedRectsForMarkersInRect(const IntRect&); 65 void shiftMarkers(Node*, unsigned startOffset, int delta); 66 void setMarkersActive(Range*, bool); 67 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); 68 69 DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::MarkerType); 70 Vector<DocumentMarker> markersForNode(Node*); 71 Vector<DocumentMarker> markersInRange(Range*, DocumentMarker::MarkerType); 72 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); 73 void clearDescriptionOnMarkersIntersectingRange(Range*, DocumentMarker::MarkerTypes); 74 75 #ifndef NDEBUG 76 void showMarkers() const; 77 #endif 78 79 private: 80 typedef std::pair<Vector<DocumentMarker>, Vector<IntRect> > MarkerMapVectorPair; 81 typedef HashMap<RefPtr<Node>, MarkerMapVectorPair*> MarkerMap; 82 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); 83 void removeMarkersFromMarkerMapVectorPair(Node*, MarkerMapVectorPair*, DocumentMarker::MarkerTypes); 84 85 MarkerMap m_markers; 86 // Provide a quick way to determine whether a particular marker type is absent without going through the map. 87 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; 88 }; 89 90 } // namespace WebCore 91 92 #ifndef NDEBUG 93 void showDocumentMarkers(const WebCore::DocumentMarkerController*); 94 #endif 95 96 #endif // DocumentMarkerController_h 97