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

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

Issue 2822963002: [DMC #1.3] Add DocumentMarkerController::ListForType() (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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 case DocumentMarker::kComposition: 70 case DocumentMarker::kComposition:
71 return DocumentMarker::kCompositionMarkerIndex; 71 return DocumentMarker::kCompositionMarkerIndex;
72 } 72 }
73 73
74 NOTREACHED(); 74 NOTREACHED();
75 return DocumentMarker::kSpellingMarkerIndex; 75 return DocumentMarker::kSpellingMarkerIndex;
76 } 76 }
77 77
78 } // namespace 78 } // namespace
79 79
80 Member<DocumentMarkerController::MarkerList>&
81 DocumentMarkerController::ListForType(MarkerLists* marker_lists,
rlanday 2017/04/17 08:19:46 I was confused when writing this why I have to spe
82 DocumentMarker::MarkerType type) {
83 size_t marker_list_index = MarkerTypeToMarkerIndex(type);
yosin_UTC9 2017/04/17 09:13:44 nit: s/size_t/const size_t/
84 return marker_lists->at(marker_list_index);
yosin_UTC9 2017/04/17 09:13:44 nit: It is OK to use |marker_lists[marker_list_ind
rlanday 2017/04/18 01:48:04 Ah, I didn't realize this did bounds checking, I j
85 }
86
80 inline bool DocumentMarkerController::PossiblyHasMarkers( 87 inline bool DocumentMarkerController::PossiblyHasMarkers(
81 DocumentMarker::MarkerTypes types) { 88 DocumentMarker::MarkerTypes types) {
82 return possibly_existing_marker_types_.Intersects(types); 89 return possibly_existing_marker_types_.Intersects(types);
83 } 90 }
84 91
85 DocumentMarkerController::DocumentMarkerController(Document& document) 92 DocumentMarkerController::DocumentMarkerController(Document& document)
86 : possibly_existing_marker_types_(0), document_(&document) { 93 : possibly_existing_marker_types_(0), document_(&document) {
87 SetContext(&document); 94 SetContext(&document);
88 } 95 }
89 96
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 227
221 possibly_existing_marker_types_.Add(new_marker.GetType()); 228 possibly_existing_marker_types_.Add(new_marker.GetType());
222 229
223 Member<MarkerLists>& markers = 230 Member<MarkerLists>& markers =
224 markers_.insert(node, nullptr).stored_value->value; 231 markers_.insert(node, nullptr).stored_value->value;
225 if (!markers) { 232 if (!markers) {
226 markers = new MarkerLists; 233 markers = new MarkerLists;
227 markers->Grow(DocumentMarker::kMarkerTypeIndexesCount); 234 markers->Grow(DocumentMarker::kMarkerTypeIndexesCount);
228 } 235 }
229 236
230 DocumentMarker::MarkerTypeIndex marker_list_index = 237 DocumentMarker::MarkerType new_marker_type = new_marker.GetType();
yosin_UTC9 2017/04/17 09:13:44 nit: s/DocumentMarker::MarkerType/const DocumentMa
231 MarkerTypeToMarkerIndex(new_marker.GetType()); 238 if (!ListForType(markers, new_marker_type))
232 if (!markers->at(marker_list_index)) { 239 ListForType(markers, new_marker_type) = new MarkerList;
233 markers->at(marker_list_index) = new MarkerList;
234 }
235 240
236 Member<MarkerList>& list = markers->at(marker_list_index); 241 Member<MarkerList>& list = ListForType(markers, new_marker_type);
237 DocumentMarkerListEditor::AddMarker(list, &new_marker); 242 DocumentMarkerListEditor::AddMarker(list, &new_marker);
238 243
239 // repaint the affected node 244 // repaint the affected node
240 if (node->GetLayoutObject()) { 245 if (node->GetLayoutObject()) {
241 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( 246 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation(
242 kPaintInvalidationDocumentMarkerChange); 247 kPaintInvalidationDocumentMarkerChange);
243 } 248 }
244 } 249 }
245 250
246 // TODO(rlanday): move DocumentMarkerListEditor into its own .h/.cpp files 251 // TODO(rlanday): move DocumentMarkerListEditor into its own .h/.cpp files
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 772
768 bool DocumentMarkerController::SetMarkersActive(Node* node, 773 bool DocumentMarkerController::SetMarkersActive(Node* node,
769 unsigned start_offset, 774 unsigned start_offset,
770 unsigned end_offset, 775 unsigned end_offset,
771 bool active) { 776 bool active) {
772 MarkerLists* markers = markers_.at(node); 777 MarkerLists* markers = markers_.at(node);
773 if (!markers) 778 if (!markers)
774 return false; 779 return false;
775 780
776 bool doc_dirty = false; 781 bool doc_dirty = false;
777 Member<MarkerList>& list = 782 Member<MarkerList>& list = ListForType(markers, DocumentMarker::kTextMatch);
778 (*markers)[MarkerTypeToMarkerIndex(DocumentMarker::kTextMatch)];
779 if (!list) 783 if (!list)
780 return false; 784 return false;
781 MarkerList::iterator start_pos = 785 MarkerList::iterator start_pos =
782 std::upper_bound(list->begin(), list->end(), start_offset, EndsBefore); 786 std::upper_bound(list->begin(), list->end(), start_offset, EndsBefore);
783 for (MarkerList::iterator marker = start_pos; marker != list->end(); 787 for (MarkerList::iterator marker = start_pos; marker != list->end();
784 ++marker) { 788 ++marker) {
785 // Markers are returned in order, so stop if we are now past the specified 789 // Markers are returned in order, so stop if we are now past the specified
786 // range. 790 // range.
787 if ((*marker)->StartOffset() >= end_offset) 791 if ((*marker)->StartOffset() >= end_offset)
788 break; 792 break;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 } 898 }
895 899
896 } // namespace blink 900 } // namespace blink
897 901
898 #ifndef NDEBUG 902 #ifndef NDEBUG
899 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { 903 void showDocumentMarkers(const blink::DocumentMarkerController* controller) {
900 if (controller) 904 if (controller)
901 controller->ShowMarkers(); 905 controller->ShowMarkers();
902 } 906 }
903 #endif 907 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698