Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) kde.org)
      5  *           (C) 2006 Alexey Proskuryakov (ap (at) 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 "core/dom/DocumentMarker.h"
     31 #include "core/platform/graphics/IntRect.h"
     32 #include "wtf/HashMap.h"
     33 #include "wtf/Vector.h"
     34 
     35 namespace WebCore {
     36 
     37 class LayoutPoint;
     38 class LayoutRect;
     39 class Node;
     40 class Range;
     41 class RenderedDocumentMarker;
     42 
     43 class DocumentMarkerController {
     44     WTF_MAKE_NONCOPYABLE(DocumentMarkerController); WTF_MAKE_FAST_ALLOCATED;
     45 public:
     46 
     47     DocumentMarkerController();
     48     ~DocumentMarkerController();
     49 
     50     void detach();
     51     void addMarker(Range*, DocumentMarker::MarkerType);
     52     void addMarker(Range*, DocumentMarker::MarkerType, const String& description);
     53     void addMarker(Range*, DocumentMarker::MarkerType, const String& description, uint32_t hash);
     54     void addMarkerToNode(Node*, unsigned startOffset, unsigned length, DocumentMarker::MarkerType);
     55     void addMarkerToNode(Node*, unsigned startOffset, unsigned length, DocumentMarker::MarkerType, PassRefPtr<DocumentMarkerDetails>);
     56     void addTextMatchMarker(const Range*, bool activeMatch);
     57 
     58     void copyMarkers(Node* srcNode, unsigned startOffset, int length, Node* dstNode, int delta);
     59     bool hasMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
     60 
     61     // When a marker partially overlaps with range, if removePartiallyOverlappingMarkers is true, we completely
     62     // remove the marker. If the argument is false, we will adjust the span of the marker so that it retains
     63     // the portion that is outside of the range.
     64     enum RemovePartiallyOverlappingMarkerOrNot { DoNotRemovePartiallyOverlappingMarker, RemovePartiallyOverlappingMarker };
     65     void removeMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker);
     66     void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(),  RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappingMarker);
     67 
     68     void removeMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
     69     void removeMarkers(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
     70     void repaintMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
     71     void invalidateRenderedRectsForMarkersInRect(const LayoutRect&);
     72     void shiftMarkers(Node*, unsigned startOffset, int delta);
     73     void setMarkersActive(Range*, bool);
     74     void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
     75 
     76     DocumentMarker* markerContainingPoint(const LayoutPoint&, DocumentMarker::MarkerType);
     77     Vector<DocumentMarker*> markersFor(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
     78     Vector<DocumentMarker*> markersInRange(Range*, DocumentMarker::MarkerTypes);
     79     Vector<DocumentMarker> markersForNode(Node*);
     80     Vector<DocumentMarker*> markers();
     81     Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType);
     82 
     83 #ifndef NDEBUG
     84     void showMarkers() const;
     85 #endif
     86 
     87 private:
     88     void addMarker(Node*, const DocumentMarker&);
     89 
     90     typedef Vector<RenderedDocumentMarker> MarkerList;
     91     typedef HashMap<RefPtr<Node>, OwnPtr<MarkerList> > MarkerMap;
     92     bool possiblyHasMarkers(DocumentMarker::MarkerTypes);
     93     void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
     94 
     95     MarkerMap m_markers;
     96     // Provide a quick way to determine whether a particular marker type is absent without going through the map.
     97     DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes;
     98 };
     99 
    100 } // namespace WebCore
    101 
    102 #ifndef NDEBUG
    103 void showDocumentMarkers(const WebCore::DocumentMarkerController*);
    104 #endif
    105 
    106 #endif // DocumentMarkerController_h
    107