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

Side by Side Diff: Source/core/dom/DocumentMarkerController.cpp

Issue 289323003: Move markerlists to Oilpan heap and remove finalizer from DocumentMarkerController (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 inline bool DocumentMarkerController::possiblyHasMarkers(DocumentMarker::MarkerT ypes types) 64 inline bool DocumentMarkerController::possiblyHasMarkers(DocumentMarker::MarkerT ypes types)
65 { 65 {
66 return m_possiblyExistingMarkerTypes.intersects(types); 66 return m_possiblyExistingMarkerTypes.intersects(types);
67 } 67 }
68 68
69 DocumentMarkerController::DocumentMarkerController() 69 DocumentMarkerController::DocumentMarkerController()
70 : m_possiblyExistingMarkerTypes(0) 70 : m_possiblyExistingMarkerTypes(0)
71 { 71 {
72 } 72 }
73 73
74 DocumentMarkerController::~DocumentMarkerController()
75 {
76 }
77
78 void DocumentMarkerController::clear() 74 void DocumentMarkerController::clear()
79 { 75 {
80 m_markers.clear(); 76 m_markers.clear();
81 m_possiblyExistingMarkerTypes = 0; 77 m_possiblyExistingMarkerTypes = 0;
82 } 78 }
83 79
84 void DocumentMarkerController::addMarker(Range* range, DocumentMarker::MarkerTyp e type, const String& description, uint32_t hash) 80 void DocumentMarkerController::addMarker(Range* range, DocumentMarker::MarkerTyp e type, const String& description, uint32_t hash)
85 { 81 {
86 // Use a TextIterator to visit the potentially multiple nodes the range cove rs. 82 // Use a TextIterator to visit the potentially multiple nodes the range cove rs.
87 for (TextIterator markedText(range); !markedText.atEnd(); markedText.advance ()) { 83 for (TextIterator markedText(range); !markedText.atEnd(); markedText.advance ()) {
(...skipping 28 matching lines...) Expand all
116 RefPtrWillBeRawPtr<Range> textPiece = markedText.range(); 112 RefPtrWillBeRawPtr<Range> textPiece = markedText.range();
117 unsigned startOffset = textPiece->startOffset(); 113 unsigned startOffset = textPiece->startOffset();
118 unsigned endOffset = textPiece->endOffset(); 114 unsigned endOffset = textPiece->endOffset();
119 addMarker(textPiece->startContainer(), DocumentMarker(startOffset, endOf fset, activeMatch)); 115 addMarker(textPiece->startContainer(), DocumentMarker(startOffset, endOf fset, activeMatch));
120 if (endOffset > startOffset) { 116 if (endOffset > startOffset) {
121 // Rendered rects for markers in WebKit are not populated until each time 117 // Rendered rects for markers in WebKit are not populated until each time
122 // the markers are painted. However, we need it to happen sooner, be cause 118 // the markers are painted. However, we need it to happen sooner, be cause
123 // the whole purpose of tickmarks on the scrollbar is to show where 119 // the whole purpose of tickmarks on the scrollbar is to show where
124 // matches off-screen are (that haven't been painted yet). 120 // matches off-screen are (that haven't been painted yet).
125 Node* node = textPiece->startContainer(); 121 Node* node = textPiece->startContainer();
126 Vector<DocumentMarker*> markers = markersFor(node); 122 WillBeHeapVector<DocumentMarker*> markers = markersFor(node);
127 toRenderedDocumentMarker(markers[markers.size() - 1])->setRenderedRe ct(range->boundingBox()); 123 toRenderedDocumentMarker(markers[markers.size() - 1])->setRenderedRe ct(range->boundingBox());
128 } 124 }
129 } 125 }
130 } 126 }
131 127
132 void DocumentMarkerController::prepareForDestruction() 128 void DocumentMarkerController::prepareForDestruction()
133 { 129 {
134 clear(); 130 clear();
135 } 131 }
136 132
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Markers of the same type do not overlap each other. 178 // Markers of the same type do not overlap each other.
183 179
184 void DocumentMarkerController::addMarker(Node* node, const DocumentMarker& newMa rker) 180 void DocumentMarkerController::addMarker(Node* node, const DocumentMarker& newMa rker)
185 { 181 {
186 ASSERT(newMarker.endOffset() >= newMarker.startOffset()); 182 ASSERT(newMarker.endOffset() >= newMarker.startOffset());
187 if (newMarker.endOffset() == newMarker.startOffset()) 183 if (newMarker.endOffset() == newMarker.startOffset())
188 return; 184 return;
189 185
190 m_possiblyExistingMarkerTypes.add(newMarker.type()); 186 m_possiblyExistingMarkerTypes.add(newMarker.type());
191 187
192 OwnPtr<MarkerLists>& markers = m_markers.add(node, nullptr).storedValue->val ue; 188 OwnPtrWillBeMember<MarkerLists>& markers = m_markers.add(node, nullptr).stor edValue->value;
193 if (!markers) { 189 if (!markers) {
194 markers = adoptPtr(new MarkerLists); 190 markers = adoptPtrWillBeNoop(new MarkerLists);
195 markers->grow(DocumentMarker::MarkerTypeIndexesCount); 191 markers->grow(DocumentMarker::MarkerTypeIndexesCount);
196 } 192 }
197 193
198 DocumentMarker::MarkerTypeIndex markerListIndex = MarkerTypeToMarkerIndex(ne wMarker.type()); 194 DocumentMarker::MarkerTypeIndex markerListIndex = MarkerTypeToMarkerIndex(ne wMarker.type());
199 if (!markers->at(markerListIndex)) { 195 if (!markers->at(markerListIndex)) {
200 markers->insert(markerListIndex, adoptPtr(new MarkerList)); 196 markers->insert(markerListIndex, adoptPtrWillBeNoop(new MarkerList));
201 } 197 }
202 198
203 OwnPtr<MarkerList>& list = markers->at(markerListIndex); 199 OwnPtrWillBeMember<MarkerList>& list = markers->at(markerListIndex);
204 if (list->isEmpty() || list->last().endOffset() < newMarker.startOffset()) { 200 if (list->isEmpty() || list->last().endOffset() < newMarker.startOffset()) {
205 list->append(RenderedDocumentMarker(newMarker)); 201 list->append(RenderedDocumentMarker(newMarker));
206 } else { 202 } else {
207 RenderedDocumentMarker toInsert(newMarker); 203 RenderedDocumentMarker toInsert(newMarker);
208 if (toInsert.type() != DocumentMarker::TextMatch) { 204 if (toInsert.type() != DocumentMarker::TextMatch) {
209 mergeOverlapping(list.get(), toInsert); 205 mergeOverlapping(list.get(), toInsert);
210 } else { 206 } else {
211 MarkerList::iterator pos = std::lower_bound(list->begin(), list->end (), toInsert, startsFurther); 207 MarkerList::iterator pos = std::lower_bound(list->begin(), list->end (), toInsert, startsFurther);
212 list->insert(pos - list->begin(), RenderedDocumentMarker(toInsert)); 208 list->insert(pos - list->begin(), RenderedDocumentMarker(toInsert));
213 } 209 }
(...skipping 28 matching lines...) Expand all
242 if (!possiblyHasMarkers(DocumentMarker::AllMarkers())) 238 if (!possiblyHasMarkers(DocumentMarker::AllMarkers()))
243 return; 239 return;
244 ASSERT(!m_markers.isEmpty()); 240 ASSERT(!m_markers.isEmpty());
245 241
246 MarkerLists* markers = m_markers.get(srcNode); 242 MarkerLists* markers = m_markers.get(srcNode);
247 if (!markers) 243 if (!markers)
248 return; 244 return;
249 245
250 bool docDirty = false; 246 bool docDirty = false;
251 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) { 247 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) {
252 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 248 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
253 if (!list) 249 if (!list)
254 continue; 250 continue;
255 251
256 unsigned endOffset = startOffset + length - 1; 252 unsigned endOffset = startOffset + length - 1;
257 MarkerList::iterator startPos = std::lower_bound(list->begin(), list->en d(), startOffset, doesNotInclude); 253 MarkerList::iterator startPos = std::lower_bound(list->begin(), list->en d(), startOffset, doesNotInclude);
258 for (MarkerList::iterator i = startPos; i != list->end(); ++i) { 254 for (MarkerList::iterator i = startPos; i != list->end(); ++i) {
259 DocumentMarker marker = *i; 255 DocumentMarker marker = *i;
260 256
261 // stop if we are now past the specified range 257 // stop if we are now past the specified range
262 if (marker.startOffset() > endOffset) 258 if (marker.startOffset() > endOffset)
(...skipping 25 matching lines...) Expand all
288 return; 284 return;
289 ASSERT(!(m_markers.isEmpty())); 285 ASSERT(!(m_markers.isEmpty()));
290 286
291 MarkerLists* markers = m_markers.get(node); 287 MarkerLists* markers = m_markers.get(node);
292 if (!markers) 288 if (!markers)
293 return; 289 return;
294 290
295 bool docDirty = false; 291 bool docDirty = false;
296 size_t emptyListsCount = 0; 292 size_t emptyListsCount = 0;
297 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) { 293 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) {
298 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 294 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
299 if (!list || list->isEmpty()) { 295 if (!list || list->isEmpty()) {
300 if (list.get() && list->isEmpty()) 296 if (list.get() && list->isEmpty())
301 list.clear(); 297 list.clear();
302 ++emptyListsCount; 298 ++emptyListsCount;
303 continue; 299 continue;
304 } 300 }
305 if (!markerTypes.contains(list->begin()->type())) 301 if (!markerTypes.contains(list->begin()->type()))
306 continue; 302 continue;
307 unsigned endOffset = startOffset + length; 303 unsigned endOffset = startOffset + length;
308 MarkerList::iterator startPos = std::upper_bound(list->begin(), list->en d(), startOffset, endsBefore); 304 MarkerList::iterator startPos = std::upper_bound(list->begin(), list->en d(), startOffset, endsBefore);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 { 360 {
365 if (!possiblyHasMarkers(markerType)) 361 if (!possiblyHasMarkers(markerType))
366 return 0; 362 return 0;
367 ASSERT(!(m_markers.isEmpty())); 363 ASSERT(!(m_markers.isEmpty()));
368 364
369 // outer loop: process each node that contains any markers 365 // outer loop: process each node that contains any markers
370 MarkerMap::iterator end = m_markers.end(); 366 MarkerMap::iterator end = m_markers.end();
371 for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != e nd; ++nodeIterator) { 367 for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != e nd; ++nodeIterator) {
372 // inner loop; process each marker in this node 368 // inner loop; process each marker in this node
373 MarkerLists* markers = nodeIterator->value.get(); 369 MarkerLists* markers = nodeIterator->value.get();
374 OwnPtr<MarkerList>& list = (*markers)[MarkerTypeToMarkerIndex(markerType )]; 370 OwnPtrWillBeMember<MarkerList>& list = (*markers)[MarkerTypeToMarkerInde x(markerType)];
375 unsigned markerCount = list.get() ? list->size() : 0; 371 unsigned markerCount = list.get() ? list->size() : 0;
376 for (unsigned markerIndex = 0; markerIndex < markerCount; ++markerIndex) { 372 for (unsigned markerIndex = 0; markerIndex < markerCount; ++markerIndex) {
377 RenderedDocumentMarker& marker = list->at(markerIndex); 373 RenderedDocumentMarker& marker = list->at(markerIndex);
378 374
379 if (marker.contains(point)) 375 if (marker.contains(point))
380 return &marker; 376 return &marker;
381 } 377 }
382 } 378 }
383 379
384 return 0; 380 return 0;
385 } 381 }
386 382
387 Vector<DocumentMarker*> DocumentMarkerController::markersFor(Node* node, Documen tMarker::MarkerTypes markerTypes) 383 WillBeHeapVector<DocumentMarker*> DocumentMarkerController::markersFor(Node* nod e, DocumentMarker::MarkerTypes markerTypes)
388 { 384 {
389 Vector<DocumentMarker*> result; 385 WillBeHeapVector<DocumentMarker*> result;
390 386
391 MarkerLists* markers = m_markers.get(node); 387 MarkerLists* markers = m_markers.get(node);
392 if (!markers) 388 if (!markers)
393 return result; 389 return result;
394 390
395 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) { 391 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) {
396 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 392 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
397 if (!list || list->isEmpty() || !markerTypes.contains(list->begin()->typ e())) 393 if (!list || list->isEmpty() || !markerTypes.contains(list->begin()->typ e()))
398 continue; 394 continue;
399 395
400 for (size_t i = 0; i < list->size(); ++i) 396 for (size_t i = 0; i < list->size(); ++i)
401 result.append(&(list->at(i))); 397 result.append(&(list->at(i)));
402 } 398 }
403 399
404 std::sort(result.begin(), result.end(), compareByStart); 400 std::sort(result.begin(), result.end(), compareByStart);
405 return result; 401 return result;
406 } 402 }
407 403
408 Vector<DocumentMarker*> DocumentMarkerController::markers() 404 WillBeHeapVector<DocumentMarker*> DocumentMarkerController::markers()
409 { 405 {
410 Vector<DocumentMarker*> result; 406 WillBeHeapVector<DocumentMarker*> result;
411 for (MarkerMap::iterator i = m_markers.begin(); i != m_markers.end(); ++i) { 407 for (MarkerMap::iterator i = m_markers.begin(); i != m_markers.end(); ++i) {
412 MarkerLists* markers = i->value.get(); 408 MarkerLists* markers = i->value.get();
413 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) { 409 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) {
414 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 410 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
415 for (size_t j = 0; list.get() && j < list->size(); ++j) 411 for (size_t j = 0; list.get() && j < list->size(); ++j)
416 result.append(&(list->at(j))); 412 result.append(&(list->at(j)));
417 } 413 }
418 } 414 }
419 std::sort(result.begin(), result.end(), compareByStart); 415 std::sort(result.begin(), result.end(), compareByStart);
420 return result; 416 return result;
421 } 417 }
422 418
423 Vector<DocumentMarker*> DocumentMarkerController::markersInRange(Range* range, D ocumentMarker::MarkerTypes markerTypes) 419 WillBeHeapVector<DocumentMarker*> DocumentMarkerController::markersInRange(Range * range, DocumentMarker::MarkerTypes markerTypes)
424 { 420 {
425 if (!possiblyHasMarkers(markerTypes)) 421 if (!possiblyHasMarkers(markerTypes))
426 return Vector<DocumentMarker*>(); 422 return WillBeHeapVector<DocumentMarker*>();
427 423
428 Vector<DocumentMarker*> foundMarkers; 424 WillBeHeapVector<DocumentMarker*> foundMarkers;
429 425
430 Node* startContainer = range->startContainer(); 426 Node* startContainer = range->startContainer();
431 ASSERT(startContainer); 427 ASSERT(startContainer);
432 Node* endContainer = range->endContainer(); 428 Node* endContainer = range->endContainer();
433 ASSERT(endContainer); 429 ASSERT(endContainer);
434 430
435 Node* pastLastNode = range->pastLastNode(); 431 Node* pastLastNode = range->pastLastNode();
436 for (Node* node = range->firstNode(); node != pastLastNode; node = NodeTrave rsal::next(*node)) { 432 for (Node* node = range->firstNode(); node != pastLastNode; node = NodeTrave rsal::next(*node)) {
437 Vector<DocumentMarker*> markers = markersFor(node); 433 WillBeHeapVector<DocumentMarker*> markers = markersFor(node);
438 Vector<DocumentMarker*>::const_iterator end = markers.end(); 434 WillBeHeapVector<DocumentMarker*>::const_iterator end = markers.end();
439 for (Vector<DocumentMarker*>::const_iterator it = markers.begin(); it != end; ++it) { 435 for (WillBeHeapVector<DocumentMarker*>::const_iterator it = markers.begi n(); it != end; ++it) {
440 DocumentMarker* marker = *it; 436 DocumentMarker* marker = *it;
441 if (!markerTypes.contains(marker->type())) 437 if (!markerTypes.contains(marker->type()))
442 continue; 438 continue;
443 if (node == startContainer && marker->endOffset() <= static_cast<uns igned>(range->startOffset())) 439 if (node == startContainer && marker->endOffset() <= static_cast<uns igned>(range->startOffset()))
444 continue; 440 continue;
445 if (node == endContainer && marker->startOffset() >= static_cast<uns igned>(range->endOffset())) 441 if (node == endContainer && marker->startOffset() >= static_cast<uns igned>(range->endOffset()))
446 continue; 442 continue;
447 foundMarkers.append(marker); 443 foundMarkers.append(marker);
448 } 444 }
449 } 445 }
450 return foundMarkers; 446 return foundMarkers;
451 } 447 }
452 448
453 Vector<IntRect> DocumentMarkerController::renderedRectsForMarkers(DocumentMarker ::MarkerType markerType) 449 Vector<IntRect> DocumentMarkerController::renderedRectsForMarkers(DocumentMarker ::MarkerType markerType)
454 { 450 {
455 Vector<IntRect> result; 451 Vector<IntRect> result;
456 452
457 if (!possiblyHasMarkers(markerType)) 453 if (!possiblyHasMarkers(markerType))
458 return result; 454 return result;
459 ASSERT(!(m_markers.isEmpty())); 455 ASSERT(!(m_markers.isEmpty()));
460 456
461 // outer loop: process each node 457 // outer loop: process each node
462 MarkerMap::iterator end = m_markers.end(); 458 MarkerMap::iterator end = m_markers.end();
463 for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != e nd; ++nodeIterator) { 459 for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != e nd; ++nodeIterator) {
464 // inner loop; process each marker in this node 460 // inner loop; process each marker in this node
465 MarkerLists* markers = nodeIterator->value.get(); 461 MarkerLists* markers = nodeIterator->value.get();
466 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) { 462 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) {
467 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 463 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
468 if (!list || list->isEmpty() || list->begin()->type() != markerType) 464 if (!list || list->isEmpty() || list->begin()->type() != markerType)
469 continue; 465 continue;
470 for (unsigned markerIndex = 0; markerIndex < list->size(); ++markerI ndex) { 466 for (unsigned markerIndex = 0; markerIndex < list->size(); ++markerI ndex) {
471 const RenderedDocumentMarker& marker = list->at(markerIndex); 467 const RenderedDocumentMarker& marker = list->at(markerIndex);
472 468
473 if (!marker.isRendered()) 469 if (!marker.isRendered())
474 continue; 470 continue;
475 471
476 result.append(marker.renderedRect()); 472 result.append(marker.renderedRect());
477 } 473 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 bool nodeCanBeRemoved; 517 bool nodeCanBeRemoved;
522 518
523 size_t emptyListsCount = 0; 519 size_t emptyListsCount = 0;
524 if (markerTypes == DocumentMarker::AllMarkers()) { 520 if (markerTypes == DocumentMarker::AllMarkers()) {
525 needsRepainting = true; 521 needsRepainting = true;
526 nodeCanBeRemoved = true; 522 nodeCanBeRemoved = true;
527 } else { 523 } else {
528 MarkerLists* markers = iterator->value.get(); 524 MarkerLists* markers = iterator->value.get();
529 525
530 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) { 526 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) {
531 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 527 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
532 if (!list || list->isEmpty()) { 528 if (!list || list->isEmpty()) {
533 if (list.get() && list->isEmpty()) 529 if (list.get() && list->isEmpty())
534 list.clear(); 530 list.clear();
535 ++emptyListsCount; 531 ++emptyListsCount;
536 continue; 532 continue;
537 } 533 }
538 if (markerTypes.contains(list->begin()->type())) { 534 if (markerTypes.contains(list->begin()->type())) {
539 list->clear(); 535 list->clear();
540 list.clear(); 536 list.clear();
541 ++emptyListsCount; 537 ++emptyListsCount;
(...skipping 23 matching lines...) Expand all
565 ASSERT(!m_markers.isEmpty()); 561 ASSERT(!m_markers.isEmpty());
566 562
567 // outer loop: process each markered node in the document 563 // outer loop: process each markered node in the document
568 MarkerMap::iterator end = m_markers.end(); 564 MarkerMap::iterator end = m_markers.end();
569 for (MarkerMap::iterator i = m_markers.begin(); i != end; ++i) { 565 for (MarkerMap::iterator i = m_markers.begin(); i != end; ++i) {
570 const Node* node = i->key; 566 const Node* node = i->key;
571 567
572 // inner loop: process each marker in the current node 568 // inner loop: process each marker in the current node
573 MarkerLists* markers = i->value.get(); 569 MarkerLists* markers = i->value.get();
574 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) { 570 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) {
575 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 571 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
576 if (!list || list->isEmpty() || !markerTypes.contains(list->begin()- >type())) 572 if (!list || list->isEmpty() || !markerTypes.contains(list->begin()- >type()))
577 continue; 573 continue;
578 574
579 // cause the node to be redrawn 575 // cause the node to be redrawn
580 if (RenderObject* renderer = node->renderer()) { 576 if (RenderObject* renderer = node->renderer()) {
581 renderer->repaint(); 577 renderer->repaint();
582 break; 578 break;
583 } 579 }
584 } 580 }
585 } 581 }
586 } 582 }
587 583
588 void DocumentMarkerController::invalidateRenderedRectsForMarkersInRect(const Lay outRect& r) 584 void DocumentMarkerController::invalidateRenderedRectsForMarkersInRect(const Lay outRect& r)
589 { 585 {
590 // outer loop: process each markered node in the document 586 // outer loop: process each markered node in the document
591 MarkerMap::iterator end = m_markers.end(); 587 MarkerMap::iterator end = m_markers.end();
592 for (MarkerMap::iterator i = m_markers.begin(); i != end; ++i) { 588 for (MarkerMap::iterator i = m_markers.begin(); i != end; ++i) {
593 589
594 // inner loop: process each rect in the current node 590 // inner loop: process each rect in the current node
595 MarkerLists* markers = i->value.get(); 591 MarkerLists* markers = i->value.get();
596 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) { 592 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) {
597 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 593 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
598 for (size_t markerIndex = 0; list.get() && markerIndex < list->size( ); ++markerIndex) 594 for (size_t markerIndex = 0; list.get() && markerIndex < list->size( ); ++markerIndex)
599 list->at(markerIndex).invalidate(r); 595 list->at(markerIndex).invalidate(r);
600 } 596 }
601 } 597 }
602 } 598 }
603 599
604 void DocumentMarkerController::shiftMarkers(Node* node, unsigned startOffset, in t delta) 600 void DocumentMarkerController::shiftMarkers(Node* node, unsigned startOffset, in t delta)
605 { 601 {
606 if (!possiblyHasMarkers(DocumentMarker::AllMarkers())) 602 if (!possiblyHasMarkers(DocumentMarker::AllMarkers()))
607 return; 603 return;
608 ASSERT(!m_markers.isEmpty()); 604 ASSERT(!m_markers.isEmpty());
609 605
610 MarkerLists* markers = m_markers.get(node); 606 MarkerLists* markers = m_markers.get(node);
611 if (!markers) 607 if (!markers)
612 return; 608 return;
613 609
614 bool docDirty = false; 610 bool docDirty = false;
615 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) { 611 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::MarkerTyp eIndexesCount; ++markerListIndex) {
616 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 612 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
617 if (!list) 613 if (!list)
618 continue; 614 continue;
619 MarkerList::iterator startPos = std::lower_bound(list->begin(), list->en d(), startOffset, startsAfter); 615 MarkerList::iterator startPos = std::lower_bound(list->begin(), list->en d(), startOffset, startsAfter);
620 for (MarkerList::iterator marker = startPos; marker != list->end(); ++ma rker) { 616 for (MarkerList::iterator marker = startPos; marker != list->end(); ++ma rker) {
621 ASSERT((int)marker->startOffset() + delta >= 0); 617 ASSERT((int)marker->startOffset() + delta >= 0);
622 marker->shiftOffsets(delta); 618 marker->shiftOffsets(delta);
623 docDirty = true; 619 docDirty = true;
624 620
625 // Marker moved, so previously-computed rendered rectangle is now in valid 621 // Marker moved, so previously-computed rendered rectangle is now in valid
626 marker->invalidate(); 622 marker->invalidate();
(...skipping 23 matching lines...) Expand all
650 } 646 }
651 } 647 }
652 648
653 void DocumentMarkerController::setMarkersActive(Node* node, unsigned startOffset , unsigned endOffset, bool active) 649 void DocumentMarkerController::setMarkersActive(Node* node, unsigned startOffset , unsigned endOffset, bool active)
654 { 650 {
655 MarkerLists* markers = m_markers.get(node); 651 MarkerLists* markers = m_markers.get(node);
656 if (!markers) 652 if (!markers)
657 return; 653 return;
658 654
659 bool docDirty = false; 655 bool docDirty = false;
660 OwnPtr<MarkerList>& list = (*markers)[MarkerTypeToMarkerIndex(DocumentMarker ::TextMatch)]; 656 OwnPtrWillBeMember<MarkerList>& list = (*markers)[MarkerTypeToMarkerIndex(Do cumentMarker::TextMatch)];
661 if (!list) 657 if (!list)
662 return; 658 return;
663 MarkerList::iterator startPos = std::upper_bound(list->begin(), list->end(), startOffset, endsBefore); 659 MarkerList::iterator startPos = std::upper_bound(list->begin(), list->end(), startOffset, endsBefore);
664 for (MarkerList::iterator marker = startPos; marker != list->end(); ++marker ) { 660 for (MarkerList::iterator marker = startPos; marker != list->end(); ++marker ) {
665 661
666 // Markers are returned in order, so stop if we are now past the specifi ed range. 662 // Markers are returned in order, so stop if we are now past the specifi ed range.
667 if (marker->startOffset() >= endOffset) 663 if (marker->startOffset() >= endOffset)
668 break; 664 break;
669 665
670 marker->setActiveMatch(active); 666 marker->setActiveMatch(active);
(...skipping 11 matching lines...) Expand all
682 return false; 678 return false;
683 ASSERT(!m_markers.isEmpty()); 679 ASSERT(!m_markers.isEmpty());
684 680
685 Node* startContainer = range->startContainer(); 681 Node* startContainer = range->startContainer();
686 ASSERT(startContainer); 682 ASSERT(startContainer);
687 Node* endContainer = range->endContainer(); 683 Node* endContainer = range->endContainer();
688 ASSERT(endContainer); 684 ASSERT(endContainer);
689 685
690 Node* pastLastNode = range->pastLastNode(); 686 Node* pastLastNode = range->pastLastNode();
691 for (Node* node = range->firstNode(); node != pastLastNode; node = NodeTrave rsal::next(*node)) { 687 for (Node* node = range->firstNode(); node != pastLastNode; node = NodeTrave rsal::next(*node)) {
692 Vector<DocumentMarker*> markers = markersFor(node); 688 WillBeHeapVector<DocumentMarker*> markers = markersFor(node);
693 Vector<DocumentMarker*>::const_iterator end = markers.end(); 689 WillBeHeapVector<DocumentMarker*>::const_iterator end = markers.end();
694 for (Vector<DocumentMarker*>::const_iterator it = markers.begin(); it != end; ++it) { 690 for (WillBeHeapVector<DocumentMarker*>::const_iterator it = markers.begi n(); it != end; ++it) {
695 DocumentMarker* marker = *it; 691 DocumentMarker* marker = *it;
696 if (!markerTypes.contains(marker->type())) 692 if (!markerTypes.contains(marker->type()))
697 continue; 693 continue;
698 if (node == startContainer && marker->endOffset() <= static_cast<uns igned>(range->startOffset())) 694 if (node == startContainer && marker->endOffset() <= static_cast<uns igned>(range->startOffset()))
699 continue; 695 continue;
700 if (node == endContainer && marker->startOffset() >= static_cast<uns igned>(range->endOffset())) 696 if (node == endContainer && marker->startOffset() >= static_cast<uns igned>(range->endOffset()))
701 continue; 697 continue;
702 return true; 698 return true;
703 } 699 }
704 } 700 }
705 return false; 701 return false;
706 } 702 }
707 703
708 #ifndef NDEBUG 704 #ifndef NDEBUG
709 void DocumentMarkerController::showMarkers() const 705 void DocumentMarkerController::showMarkers() const
710 { 706 {
711 fprintf(stderr, "%d nodes have markers:\n", m_markers.size()); 707 fprintf(stderr, "%d nodes have markers:\n", m_markers.size());
712 MarkerMap::const_iterator end = m_markers.end(); 708 MarkerMap::const_iterator end = m_markers.end();
713 for (MarkerMap::const_iterator nodeIterator = m_markers.begin(); nodeIterato r != end; ++nodeIterator) { 709 for (MarkerMap::const_iterator nodeIterator = m_markers.begin(); nodeIterato r != end; ++nodeIterator) {
714 const Node* node = nodeIterator->key; 710 const Node* node = nodeIterator->key;
715 fprintf(stderr, "%p", node); 711 fprintf(stderr, "%p", node);
716 MarkerLists* markers = m_markers.get(node); 712 MarkerLists* markers = m_markers.get(node);
717 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) { 713 for (size_t markerListIndex = 0; markerListIndex < DocumentMarker::Marke rTypeIndexesCount; ++markerListIndex) {
718 OwnPtr<MarkerList>& list = (*markers)[markerListIndex]; 714 OwnPtrWillBeMember<MarkerList>& list = (*markers)[markerListIndex];
719 for (unsigned markerIndex = 0; list.get() && markerIndex < list->siz e(); ++markerIndex) { 715 for (unsigned markerIndex = 0; list.get() && markerIndex < list->siz e(); ++markerIndex) {
720 const DocumentMarker& marker = list->at(markerIndex); 716 const DocumentMarker& marker = list->at(markerIndex);
721 fprintf(stderr, " %d:[%d:%d](%d)", marker.type(), marker.startOf fset(), marker.endOffset(), marker.activeMatch()); 717 fprintf(stderr, " %d:[%d:%d](%d)", marker.type(), marker.startOf fset(), marker.endOffset(), marker.activeMatch());
722 } 718 }
723 } 719 }
724 720
725 fprintf(stderr, "\n"); 721 fprintf(stderr, "\n");
726 } 722 }
727 } 723 }
728 #endif 724 #endif
729 725
730 } // namespace WebCore 726 } // namespace WebCore
731 727
732 #ifndef NDEBUG 728 #ifndef NDEBUG
733 void showDocumentMarkers(const WebCore::DocumentMarkerController* controller) 729 void showDocumentMarkers(const WebCore::DocumentMarkerController* controller)
734 { 730 {
735 if (controller) 731 if (controller)
736 controller->showMarkers(); 732 controller->showMarkers();
737 } 733 }
738 #endif 734 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698