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

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

Issue 2820633002: [DMC #2] Add DocumentMarkerList interface and GenericDocumentMarkerListImpl (Closed)
Patch Set: Add TODO 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 17 matching lines...) Expand all
28 28
29 #include "core/editing/markers/DocumentMarkerController.h" 29 #include "core/editing/markers/DocumentMarkerController.h"
30 30
31 #include <algorithm> 31 #include <algorithm>
32 #include "core/dom/Node.h" 32 #include "core/dom/Node.h"
33 #include "core/dom/NodeTraversal.h" 33 #include "core/dom/NodeTraversal.h"
34 #include "core/dom/Range.h" 34 #include "core/dom/Range.h"
35 #include "core/dom/Text.h" 35 #include "core/dom/Text.h"
36 #include "core/editing/iterators/TextIterator.h" 36 #include "core/editing/iterators/TextIterator.h"
37 #include "core/editing/markers/DocumentMarkerListEditor.h" 37 #include "core/editing/markers/DocumentMarkerListEditor.h"
38 #include "core/editing/markers/GenericDocumentMarkerListImpl.h"
38 #include "core/editing/markers/RenderedDocumentMarker.h" 39 #include "core/editing/markers/RenderedDocumentMarker.h"
39 #include "core/frame/FrameView.h" 40 #include "core/frame/FrameView.h"
40 #include "core/layout/LayoutObject.h" 41 #include "core/layout/LayoutObject.h"
41 42
42 #ifndef NDEBUG 43 #ifndef NDEBUG
43 #include <stdio.h> 44 #include <stdio.h>
44 #endif 45 #endif
45 46
46 namespace blink { 47 namespace blink {
47 48
(...skipping 11 matching lines...) Expand all
59 case DocumentMarker::kComposition: 60 case DocumentMarker::kComposition:
60 return DocumentMarker::kCompositionMarkerIndex; 61 return DocumentMarker::kCompositionMarkerIndex;
61 } 62 }
62 63
63 NOTREACHED(); 64 NOTREACHED();
64 return DocumentMarker::kSpellingMarkerIndex; 65 return DocumentMarker::kSpellingMarkerIndex;
65 } 66 }
66 67
67 } // namespace 68 } // namespace
68 69
69 Member<DocumentMarkerController::MarkerList>& 70 Member<DocumentMarkerList>& DocumentMarkerController::ListForType(
70 DocumentMarkerController::ListForType(MarkerLists* marker_lists, 71 MarkerLists* marker_lists,
71 DocumentMarker::MarkerType type) { 72 DocumentMarker::MarkerType type) {
72 const size_t marker_list_index = MarkerTypeToMarkerIndex(type); 73 const size_t marker_list_index = MarkerTypeToMarkerIndex(type);
73 return (*marker_lists)[marker_list_index]; 74 return (*marker_lists)[marker_list_index];
74 } 75 }
75 76
76 inline bool DocumentMarkerController::PossiblyHasMarkers( 77 inline bool DocumentMarkerController::PossiblyHasMarkers(
77 DocumentMarker::MarkerTypes types) { 78 DocumentMarker::MarkerTypes types) {
78 return possibly_existing_marker_types_.Intersects(types); 79 return possibly_existing_marker_types_.Intersects(types);
79 } 80 }
80 81
81 DocumentMarkerController::DocumentMarkerController(Document& document) 82 DocumentMarkerController::DocumentMarkerController(Document& document)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 possibly_existing_marker_types_.Add(new_marker->GetType()); 199 possibly_existing_marker_types_.Add(new_marker->GetType());
199 200
200 Member<MarkerLists>& markers = 201 Member<MarkerLists>& markers =
201 markers_.insert(node, nullptr).stored_value->value; 202 markers_.insert(node, nullptr).stored_value->value;
202 if (!markers) { 203 if (!markers) {
203 markers = new MarkerLists; 204 markers = new MarkerLists;
204 markers->Grow(DocumentMarker::kMarkerTypeIndexesCount); 205 markers->Grow(DocumentMarker::kMarkerTypeIndexesCount);
205 } 206 }
206 207
207 const DocumentMarker::MarkerType new_marker_type = new_marker->GetType(); 208 const DocumentMarker::MarkerType new_marker_type = new_marker->GetType();
208 if (!ListForType(markers, new_marker_type)) 209 if (!ListForType(markers, new_marker_type)) {
209 ListForType(markers, new_marker_type) = new MarkerList; 210 // TODO(rlanday): add method for deciding what type of list to create based
211 // on the MarkerType
212 ListForType(markers, new_marker_type) = new GenericDocumentMarkerListImpl;
213 }
210 214
211 Member<MarkerList>& list = ListForType(markers, new_marker_type); 215 DocumentMarkerList* list = ListForType(markers, new_marker_type);
yosin_UTC9 2017/04/25 08:20:58 nit: s/DocumentMarkerList*/DocumentMarkerList* con
212 DocumentMarkerListEditor::AddMarker(list, new_marker); 216 list->Add(new_marker);
213 217
214 // repaint the affected node 218 // repaint the affected node
215 if (node->GetLayoutObject()) { 219 if (node->GetLayoutObject()) {
216 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( 220 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation(
217 kPaintInvalidationDocumentMarkerChange); 221 kPaintInvalidationDocumentMarkerChange);
218 } 222 }
219 } 223 }
220 224
221 // Moves markers from src_node to dst_node. Markers are moved if their start 225 // Moves markers from src_node to dst_node. Markers are moved if their start
222 // offset is less than length. Markers that run past that point are truncated. 226 // offset is less than length. Markers that run past that point are truncated.
(...skipping 12 matching lines...) Expand all
235 return; 239 return;
236 240
237 if (!markers_.Contains(dst_node)) { 241 if (!markers_.Contains(dst_node)) {
238 markers_.insert(dst_node, 242 markers_.insert(dst_node,
239 new MarkerLists(DocumentMarker::kMarkerTypeIndexesCount)); 243 new MarkerLists(DocumentMarker::kMarkerTypeIndexesCount));
240 } 244 }
241 MarkerLists* dst_markers = markers_.at(dst_node); 245 MarkerLists* dst_markers = markers_.at(dst_node);
242 246
243 bool doc_dirty = false; 247 bool doc_dirty = false;
244 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 248 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
245 MarkerList* src_list = ListForType(src_markers, type); 249 DocumentMarkerList* src_list = ListForType(src_markers, type);
yosin_UTC9 2017/04/25 08:20:58 nit: s/DocumentMarkerList*/DocumentMarkerList* con
246 if (!src_list) 250 if (!src_list)
247 continue; 251 continue;
248 252
249 if (!ListForType(dst_markers, type)) 253 if (!ListForType(dst_markers, type)) {
250 ListForType(dst_markers, type) = new MarkerList; 254 // TODO(rlanday): add method for deciding what type of list to create
251 MarkerList* dst_list = ListForType(dst_markers, type); 255 // based on the MarkerType
256 ListForType(dst_markers, type) = new GenericDocumentMarkerListImpl;
257 }
252 258
253 if (DocumentMarkerListEditor::MoveMarkers(src_list, length, dst_list)) 259 DocumentMarkerList* dst_list = ListForType(dst_markers, type);
260 if (src_list->MoveMarkers(length, dst_list))
254 doc_dirty = true; 261 doc_dirty = true;
255 } 262 }
256 263
257 // repaint the affected node 264 // repaint the affected node
258 if (doc_dirty && dst_node->GetLayoutObject()) { 265 if (doc_dirty && dst_node->GetLayoutObject()) {
259 dst_node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( 266 dst_node->GetLayoutObject()->SetShouldDoFullPaintInvalidation(
260 kPaintInvalidationDocumentMarkerChange); 267 kPaintInvalidationDocumentMarkerChange);
261 } 268 }
262 } 269 }
263 270
264 void DocumentMarkerController::RemoveMarkersInternal( 271 void DocumentMarkerController::RemoveMarkersInternal(
265 Node* node, 272 Node* node,
266 unsigned start_offset, 273 unsigned start_offset,
267 int length, 274 int length,
268 DocumentMarker::MarkerTypes marker_types) { 275 DocumentMarker::MarkerTypes marker_types) {
269 if (length <= 0) 276 if (length <= 0)
270 return; 277 return;
271 278
272 if (!PossiblyHasMarkers(marker_types)) 279 if (!PossiblyHasMarkers(marker_types))
273 return; 280 return;
274 DCHECK(!(markers_.IsEmpty())); 281 DCHECK(!(markers_.IsEmpty()));
275 282
276 MarkerLists* markers = markers_.at(node); 283 MarkerLists* markers = markers_.at(node);
277 if (!markers) 284 if (!markers)
278 return; 285 return;
279 286
280 bool doc_dirty = false; 287 bool doc_dirty = false;
281 size_t empty_lists_count = 0; 288 size_t empty_lists_count = 0;
282 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 289 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
283 Member<MarkerList>& list = ListForType(markers, type); 290 DocumentMarkerList* list = ListForType(markers, type);
yosin_UTC9 2017/04/25 08:20:58 nit: s/DocumentMarkerList*/DocumentMarkerList* con
284 if (!list || list->IsEmpty()) { 291 if (!list || list->IsEmpty()) {
285 if (list.Get() && list->IsEmpty()) 292 if (list && list->IsEmpty())
286 list.Clear(); 293 ListForType(markers, type) = nullptr;
287 ++empty_lists_count; 294 ++empty_lists_count;
288 continue; 295 continue;
289 } 296 }
290 if (!marker_types.Contains(type)) 297 if (!marker_types.Contains(type))
291 continue; 298 continue;
292 299
293 if (DocumentMarkerListEditor::RemoveMarkers(list, start_offset, length)) 300 if (list->RemoveMarkers(start_offset, length))
294 doc_dirty = true; 301 doc_dirty = true;
295 302
296 if (list->IsEmpty()) { 303 if (list->IsEmpty()) {
297 list.Clear(); 304 ListForType(markers, type) = nullptr;
298 ++empty_lists_count; 305 ++empty_lists_count;
299 } 306 }
300 } 307 }
301 308
302 if (empty_lists_count == DocumentMarker::kMarkerTypeIndexesCount) { 309 if (empty_lists_count == DocumentMarker::kMarkerTypeIndexesCount) {
303 markers_.erase(node); 310 markers_.erase(node);
304 if (markers_.IsEmpty()) 311 if (markers_.IsEmpty())
305 possibly_existing_marker_types_ = 0; 312 possibly_existing_marker_types_ = 0;
306 } 313 }
307 314
308 // repaint the affected node 315 // repaint the affected node
309 if (doc_dirty && node->GetLayoutObject()) { 316 if (doc_dirty && node->GetLayoutObject()) {
310 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( 317 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation(
311 kPaintInvalidationDocumentMarkerChange); 318 kPaintInvalidationDocumentMarkerChange);
312 } 319 }
313 } 320 }
314 321
315 DocumentMarkerVector DocumentMarkerController::MarkersFor( 322 DocumentMarkerVector DocumentMarkerController::MarkersFor(
316 Node* node, 323 Node* node,
317 DocumentMarker::MarkerTypes marker_types) { 324 DocumentMarker::MarkerTypes marker_types) {
318 DocumentMarkerVector result; 325 DocumentMarkerVector result;
319 326
320 MarkerLists* markers = markers_.at(node); 327 MarkerLists* markers = markers_.at(node);
321 if (!markers) 328 if (!markers)
322 return result; 329 return result;
323 330
324 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 331 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
325 Member<MarkerList>& list = ListForType(markers, type); 332 DocumentMarkerList* list = ListForType(markers, type);
yosin_UTC9 2017/04/25 08:20:58 nit: s/DocumentMarkerList*/DocumentMarkerList* con
326 if (!list || list->IsEmpty() || 333 if (!list || list->IsEmpty() || !marker_types.Contains(type))
327 !marker_types.Contains((*list->begin())->GetType()))
328 continue; 334 continue;
329 335
330 for (size_t i = 0; i < list->size(); ++i) 336 result.AppendVector(list->GetMarkers());
yosin_UTC9 2017/04/25 08:20:58 Wow, AppendVector() is easy.
rlanday 2017/04/25 19:29:52 Except that as far as I'm aware, we haven't solved
331 result.push_back(list->at(i).Get());
332 } 337 }
333 338
334 std::sort(result.begin(), result.end(), 339 std::sort(result.begin(), result.end(),
335 [](const Member<DocumentMarker>& marker1, 340 [](const Member<DocumentMarker>& marker1,
336 const Member<DocumentMarker>& marker2) { 341 const Member<DocumentMarker>& marker2) {
337 return marker1->StartOffset() < marker2->StartOffset(); 342 return marker1->StartOffset() < marker2->StartOffset();
338 }); 343 });
339 return result; 344 return result;
340 } 345 }
341 346
342 DocumentMarkerVector DocumentMarkerController::Markers() { 347 DocumentMarkerVector DocumentMarkerController::Markers() {
343 DocumentMarkerVector result; 348 DocumentMarkerVector result;
344 for (MarkerMap::iterator i = markers_.begin(); i != markers_.end(); ++i) { 349 for (MarkerMap::iterator i = markers_.begin(); i != markers_.end(); ++i) {
345 MarkerLists* markers = i->value.Get(); 350 MarkerLists* markers = i->value.Get();
346 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 351 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
347 Member<MarkerList>& list = ListForType(markers, type); 352 DocumentMarkerList* list = ListForType(markers, type);
348 for (size_t j = 0; list.Get() && j < list->size(); ++j) 353 if (!list)
349 result.push_back(list->at(j).Get()); 354 continue;
355 result.AppendVector(list->GetMarkers());
350 } 356 }
351 } 357 }
352 std::sort(result.begin(), result.end(), 358 std::sort(result.begin(), result.end(),
353 [](const Member<DocumentMarker>& marker1, 359 [](const Member<DocumentMarker>& marker1,
354 const Member<DocumentMarker>& marker2) { 360 const Member<DocumentMarker>& marker2) {
355 return marker1->StartOffset() < marker2->StartOffset(); 361 return marker1->StartOffset() < marker2->StartOffset();
356 }); 362 });
357 return result; 363 return result;
358 } 364 }
359 365
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // outer loop: process each node 405 // outer loop: process each node
400 MarkerMap::iterator end = markers_.end(); 406 MarkerMap::iterator end = markers_.end();
401 for (MarkerMap::iterator node_iterator = markers_.begin(); 407 for (MarkerMap::iterator node_iterator = markers_.begin();
402 node_iterator != end; ++node_iterator) { 408 node_iterator != end; ++node_iterator) {
403 // inner loop; process each marker in this node 409 // inner loop; process each marker in this node
404 const Node& node = *node_iterator->key; 410 const Node& node = *node_iterator->key;
405 if (!node.isConnected()) 411 if (!node.isConnected())
406 continue; 412 continue;
407 MarkerLists* markers = node_iterator->value.Get(); 413 MarkerLists* markers = node_iterator->value.Get();
408 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 414 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
409 Member<MarkerList>& list = ListForType(markers, type); 415 DocumentMarkerList* list = ListForType(markers, type);
yosin_UTC9 2017/04/25 08:20:59 nit: s/DocumentMarkerList*/DocumentMarkerList* con
410 if (!list || list->IsEmpty() || type != marker_type) 416 if (!list || list->IsEmpty() || type != marker_type)
411 continue; 417 continue;
412 for (unsigned marker_index = 0; marker_index < list->size(); 418
413 ++marker_index) { 419 for (RenderedDocumentMarker* rendered_marker : list->GetMarkers()) {
414 RenderedDocumentMarker* marker = list->at(marker_index).Get(); 420 UpdateMarkerRenderedRectIfNeeded(node, *rendered_marker);
415 UpdateMarkerRenderedRectIfNeeded(node, *marker); 421 if (!rendered_marker->IsRendered())
416 if (!marker->IsRendered())
417 continue; 422 continue;
418 result.push_back(marker->RenderedRect()); 423 result.push_back(rendered_marker->RenderedRect());
419 } 424 }
420 } 425 }
421 } 426 }
422 427
423 return result; 428 return result;
424 } 429 }
425 430
426 static void InvalidatePaintForTickmarks(const Node& node) { 431 static void InvalidatePaintForTickmarks(const Node& node) {
427 if (FrameView* frame_view = node.GetDocument().View()) 432 if (FrameView* frame_view = node.GetDocument().View())
428 frame_view->InvalidatePaintForTickmarks(); 433 frame_view->InvalidatePaintForTickmarks();
429 } 434 }
430 435
431 void DocumentMarkerController::UpdateMarkerRenderedRectIfNeeded( 436 void DocumentMarkerController::UpdateMarkerRenderedRectIfNeeded(
432 const Node& node, 437 const Node& node,
433 RenderedDocumentMarker& marker) { 438 RenderedDocumentMarker& marker) {
434 DCHECK(!document_->View() || !document_->View()->NeedsLayout()); 439 DCHECK(!document_->View() || !document_->View()->NeedsLayout());
435 DCHECK(!document_->NeedsLayoutTreeUpdate()); 440 DCHECK(!document_->NeedsLayoutTreeUpdate());
436 if (!marker.IsValid()) 441 if (!marker.IsValid())
437 UpdateMarkerRenderedRect(node, marker); 442 UpdateMarkerRenderedRect(node, marker);
438 } 443 }
439 444
440 void DocumentMarkerController::InvalidateRectsForMarkersInNode( 445 void DocumentMarkerController::InvalidateRectsForMarkersInNode(
441 const Node& node) { 446 const Node& node) {
442 MarkerLists* markers = markers_.at(&node); 447 MarkerLists* markers = markers_.at(&node);
443 448
444 for (auto& marker_list : *markers) { 449 for (auto& marker_list : *markers) {
445 if (!marker_list || marker_list->IsEmpty()) 450 if (!marker_list || marker_list->IsEmpty())
446 continue; 451 continue;
447 452
448 for (auto& marker : *marker_list) 453 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list =
454 marker_list->GetMarkers();
455 for (auto& marker : markers_in_list)
449 marker->Invalidate(); 456 marker->Invalidate();
450 457
451 if (marker_list->front()->GetType() == DocumentMarker::kTextMatch) 458 if (markers_in_list.front()->GetType() == DocumentMarker::kTextMatch)
452 InvalidatePaintForTickmarks(node); 459 InvalidatePaintForTickmarks(node);
453 } 460 }
454 } 461 }
455 462
456 void DocumentMarkerController::InvalidateRectsForAllMarkers() { 463 void DocumentMarkerController::InvalidateRectsForAllMarkers() {
457 for (auto& node_markers : markers_) { 464 for (auto& node_markers : markers_) {
458 const Node& node = *node_markers.key; 465 const Node& node = *node_markers.key;
459 for (auto& marker_list : *node_markers.value) { 466 for (auto& marker_list : *node_markers.value) {
460 if (!marker_list || marker_list->IsEmpty()) 467 if (!marker_list || marker_list->IsEmpty())
461 continue; 468 continue;
462 469
463 for (auto& marker : *marker_list) 470 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list =
464 marker->Invalidate(); 471 marker_list->GetMarkers();
472 for (DocumentMarker* marker : markers_in_list)
473 ToRenderedDocumentMarker(marker)->Invalidate();
465 474
466 if (marker_list->front()->GetType() == DocumentMarker::kTextMatch) 475 if (markers_in_list.front()->GetType() == DocumentMarker::kTextMatch)
467 InvalidatePaintForTickmarks(node); 476 InvalidatePaintForTickmarks(node);
468 } 477 }
469 } 478 }
470 } 479 }
471 480
472 DEFINE_TRACE(DocumentMarkerController) { 481 DEFINE_TRACE(DocumentMarkerController) {
473 visitor->Trace(markers_); 482 visitor->Trace(markers_);
474 visitor->Trace(document_); 483 visitor->Trace(document_);
475 SynchronousMutationObserver::Trace(visitor); 484 SynchronousMutationObserver::Trace(visitor);
476 } 485 }
(...skipping 11 matching lines...) Expand all
488 } 497 }
489 498
490 void DocumentMarkerController::RemoveSpellingMarkersUnderWords( 499 void DocumentMarkerController::RemoveSpellingMarkersUnderWords(
491 const Vector<String>& words) { 500 const Vector<String>& words) {
492 for (auto& node_markers : markers_) { 501 for (auto& node_markers : markers_) {
493 const Node& node = *node_markers.key; 502 const Node& node = *node_markers.key;
494 if (!node.IsTextNode()) // MarkerRemoverPredicate requires a Text node. 503 if (!node.IsTextNode()) // MarkerRemoverPredicate requires a Text node.
495 continue; 504 continue;
496 MarkerLists* markers = node_markers.value; 505 MarkerLists* markers = node_markers.value;
497 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 506 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
498 MarkerList* list = ListForType(markers, type); 507 DocumentMarkerList* list = ListForType(markers, type);
yosin_UTC9 2017/04/25 08:20:58 nit: s/DocumentMarkerList*/DocumentMarkerList* con
499 if (!list) 508 if (!list)
500 continue; 509 continue;
501 bool removed_markers = DocumentMarkerListEditor::RemoveMarkersUnderWords( 510 bool removed_markers =
yosin_UTC9 2017/04/25 08:20:58 nit: s/bool/const bool/
502 list, ToText(node).data(), words); 511 list->RemoveMarkersUnderWords(ToText(node).data(), words);
503 if (removed_markers && type == DocumentMarker::kTextMatch) 512 if (removed_markers && type == DocumentMarker::kTextMatch)
504 InvalidatePaintForTickmarks(node); 513 InvalidatePaintForTickmarks(node);
505 } 514 }
506 } 515 }
507 } 516 }
508 517
509 void DocumentMarkerController::RemoveMarkersOfTypes( 518 void DocumentMarkerController::RemoveMarkersOfTypes(
510 DocumentMarker::MarkerTypes marker_types) { 519 DocumentMarker::MarkerTypes marker_types) {
511 if (!PossiblyHasMarkers(marker_types)) 520 if (!PossiblyHasMarkers(marker_types))
512 return; 521 return;
(...skipping 18 matching lines...) Expand all
531 bool node_can_be_removed; 540 bool node_can_be_removed;
532 541
533 size_t empty_lists_count = 0; 542 size_t empty_lists_count = 0;
534 if (marker_types == DocumentMarker::AllMarkers()) { 543 if (marker_types == DocumentMarker::AllMarkers()) {
535 needs_repainting = true; 544 needs_repainting = true;
536 node_can_be_removed = true; 545 node_can_be_removed = true;
537 } else { 546 } else {
538 MarkerLists* markers = iterator->value.Get(); 547 MarkerLists* markers = iterator->value.Get();
539 548
540 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 549 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
541 Member<MarkerList>& list = ListForType(markers, type); 550 DocumentMarkerList* list = ListForType(markers, type);
yosin_UTC9 2017/04/25 08:20:59 nit: s/DocumentMarkerList*/DocumentMarkerList* con
542 if (!list || list->IsEmpty()) { 551 if (!list || list->IsEmpty()) {
543 if (list.Get() && list->IsEmpty()) 552 if (list && list->IsEmpty())
544 list.Clear(); 553 ListForType(markers, type) = nullptr;
545 ++empty_lists_count; 554 ++empty_lists_count;
546 continue; 555 continue;
547 } 556 }
548 if (marker_types.Contains(type)) { 557 if (marker_types.Contains(type)) {
549 list->clear(); 558 list->Clear();
550 list.Clear(); 559 ListForType(markers, type) = nullptr;
551 ++empty_lists_count; 560 ++empty_lists_count;
552 needs_repainting = true; 561 needs_repainting = true;
553 } 562 }
554 } 563 }
555 564
556 node_can_be_removed = 565 node_can_be_removed =
557 empty_lists_count == DocumentMarker::kMarkerTypeIndexesCount; 566 empty_lists_count == DocumentMarker::kMarkerTypeIndexesCount;
558 } 567 }
559 568
560 if (needs_repainting) { 569 if (needs_repainting) {
(...skipping 19 matching lines...) Expand all
580 DCHECK(!markers_.IsEmpty()); 589 DCHECK(!markers_.IsEmpty());
581 590
582 // outer loop: process each markered node in the document 591 // outer loop: process each markered node in the document
583 MarkerMap::iterator end = markers_.end(); 592 MarkerMap::iterator end = markers_.end();
584 for (MarkerMap::iterator i = markers_.begin(); i != end; ++i) { 593 for (MarkerMap::iterator i = markers_.begin(); i != end; ++i) {
585 const Node* node = i->key; 594 const Node* node = i->key;
586 595
587 // inner loop: process each marker in the current node 596 // inner loop: process each marker in the current node
588 MarkerLists* markers = i->value.Get(); 597 MarkerLists* markers = i->value.Get();
589 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 598 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
590 Member<MarkerList>& list = ListForType(markers, type); 599 DocumentMarkerList* list = ListForType(markers, type);
yosin_UTC9 2017/04/25 08:20:58 nit: s/DocumentMarkerList*/DocumentMarkerList* con
591 if (!list || list->IsEmpty() || !marker_types.Contains(type)) 600 if (!list || list->IsEmpty() || !marker_types.Contains(type))
592 continue; 601 continue;
593 602
594 // cause the node to be redrawn 603 // cause the node to be redrawn
595 if (LayoutObject* layout_object = node->GetLayoutObject()) { 604 if (LayoutObject* layout_object = node->GetLayoutObject()) {
596 layout_object->SetShouldDoFullPaintInvalidation( 605 layout_object->SetShouldDoFullPaintInvalidation(
597 kPaintInvalidationDocumentMarkerChange); 606 kPaintInvalidationDocumentMarkerChange);
598 break; 607 break;
599 } 608 }
600 } 609 }
(...skipping 28 matching lines...) Expand all
629 638
630 bool DocumentMarkerController::SetMarkersActive(Node* node, 639 bool DocumentMarkerController::SetMarkersActive(Node* node,
631 unsigned start_offset, 640 unsigned start_offset,
632 unsigned end_offset, 641 unsigned end_offset,
633 bool active) { 642 bool active) {
634 MarkerLists* markers = markers_.at(node); 643 MarkerLists* markers = markers_.at(node);
635 if (!markers) 644 if (!markers)
636 return false; 645 return false;
637 646
638 bool doc_dirty = false; 647 bool doc_dirty = false;
639 Member<MarkerList>& list = ListForType(markers, DocumentMarker::kTextMatch); 648 DocumentMarkerList* list = ListForType(markers, DocumentMarker::kTextMatch);
yosin_UTC9 2017/04/25 08:20:59 nit: s/DocumentMarkerList*/DocumentMarkerList* con
649
640 if (!list) 650 if (!list)
641 return false; 651 return false;
642 MarkerList::iterator start_pos = std::upper_bound( 652
643 list->begin(), list->end(), start_offset, 653 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list =
644 [](size_t start_offset, const Member<RenderedDocumentMarker>& marker) { 654 list->GetMarkers();
655 // TODO(rlanday): this assumes that the markers are stored in sorted order.
656 // This method should probably eventually be implemented by a
657 // TextMatch-specific marker list
658 const auto start_pos = std::upper_bound(
659 markers_in_list.begin(), markers_in_list.end(), start_offset,
660 [](size_t start_offset, const Member<DocumentMarker>& marker) {
645 return start_offset < marker->EndOffset(); 661 return start_offset < marker->EndOffset();
646 }); 662 });
647 for (MarkerList::iterator marker = start_pos; marker != list->end(); 663 for (auto marker = start_pos; marker != markers_in_list.end(); ++marker) {
648 ++marker) {
649 // Markers are returned in order, so stop if we are now past the specified 664 // Markers are returned in order, so stop if we are now past the specified
650 // range. 665 // range.
651 if ((*marker)->StartOffset() >= end_offset) 666 if ((*marker)->StartOffset() >= end_offset)
652 break; 667 break;
653 668
654 (*marker)->SetIsActiveMatch(active); 669 (*marker)->SetIsActiveMatch(active);
655 doc_dirty = true; 670 doc_dirty = true;
656 } 671 }
657 672
658 // repaint the affected node 673 // repaint the affected node
659 if (doc_dirty && node->GetLayoutObject()) { 674 if (doc_dirty && node->GetLayoutObject()) {
660 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation( 675 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation(
661 kPaintInvalidationDocumentMarkerChange); 676 kPaintInvalidationDocumentMarkerChange);
662 } 677 }
663 return doc_dirty; 678 return doc_dirty;
664 } 679 }
665 680
666 #ifndef NDEBUG 681 #ifndef NDEBUG
667 void DocumentMarkerController::ShowMarkers() const { 682 void DocumentMarkerController::ShowMarkers() const {
668 StringBuilder builder; 683 StringBuilder builder;
669 MarkerMap::const_iterator end = markers_.end(); 684 MarkerMap::const_iterator end = markers_.end();
670 for (MarkerMap::const_iterator node_iterator = markers_.begin(); 685 for (MarkerMap::const_iterator node_iterator = markers_.begin();
671 node_iterator != end; ++node_iterator) { 686 node_iterator != end; ++node_iterator) {
672 const Node* node = node_iterator->key; 687 const Node* node = node_iterator->key;
673 builder.Append(String::Format("%p", node)); 688 builder.Append(String::Format("%p", node));
674 MarkerLists* markers = markers_.at(node); 689 MarkerLists* markers = markers_.at(node);
675 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { 690 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) {
676 Member<MarkerList>& list = ListForType(markers, type); 691 DocumentMarkerList* list = ListForType(markers, type);
677 for (unsigned marker_index = 0; list.Get() && marker_index < list->size(); 692 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list =
678 ++marker_index) { 693 list->GetMarkers();
679 DocumentMarker* marker = list->at(marker_index).Get(); 694 for (const DocumentMarker* marker : markers_in_list) {
680 builder.Append(" "); 695 builder.Append(" ");
681 builder.AppendNumber(marker->GetType()); 696 builder.AppendNumber(marker->GetType());
682 builder.Append(":["); 697 builder.Append(":[");
683 builder.AppendNumber(marker->StartOffset()); 698 builder.AppendNumber(marker->StartOffset());
684 builder.Append(":"); 699 builder.Append(":");
685 builder.AppendNumber(marker->EndOffset()); 700 builder.AppendNumber(marker->EndOffset());
686 builder.Append("]("); 701 builder.Append("](");
687 builder.AppendNumber(marker->IsActiveMatch()); 702 builder.AppendNumber(marker->IsActiveMatch());
688 builder.Append(")"); 703 builder.Append(")");
689 } 704 }
(...skipping 12 matching lines...) Expand all
702 unsigned new_length) { 717 unsigned new_length) {
703 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers())) 718 if (!PossiblyHasMarkers(DocumentMarker::AllMarkers()))
704 return; 719 return;
705 DCHECK(!markers_.IsEmpty()); 720 DCHECK(!markers_.IsEmpty());
706 721
707 MarkerLists* markers = markers_.at(node); 722 MarkerLists* markers = markers_.at(node);
708 if (!markers) 723 if (!markers)
709 return; 724 return;
710 725
711 bool did_shift_marker = false; 726 bool did_shift_marker = false;
712 for (MarkerList* list : *markers) { 727 for (DocumentMarkerList* list : *markers) {
713 if (!list) 728 if (!list)
714 continue; 729 continue;
715 730
716 if (DocumentMarkerListEditor::ShiftMarkers(list, offset, old_length, 731 if (list->ShiftMarkers(offset, old_length, new_length))
717 new_length))
718 did_shift_marker = true; 732 did_shift_marker = true;
719 } 733 }
720 734
721 if (!did_shift_marker) 735 if (!did_shift_marker)
722 return; 736 return;
723 if (!node->GetLayoutObject()) 737 if (!node->GetLayoutObject())
724 return; 738 return;
725 InvalidateRectsForMarkersInNode(*node); 739 InvalidateRectsForMarkersInNode(*node);
726 // repaint the affected node 740 // repaint the affected node
727 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation(); 741 node->GetLayoutObject()->SetShouldDoFullPaintInvalidation();
728 } 742 }
729 743
730 } // namespace blink 744 } // namespace blink
731 745
732 #ifndef NDEBUG 746 #ifndef NDEBUG
733 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { 747 void showDocumentMarkers(const blink::DocumentMarkerController* controller) {
734 if (controller) 748 if (controller)
735 controller->ShowMarkers(); 749 controller->ShowMarkers();
736 } 750 }
737 #endif 751 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698