Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 std::sort(result.begin(), result.end(), | 388 std::sort(result.begin(), result.end(), |
| 389 [](const Member<DocumentMarker>& marker1, | 389 [](const Member<DocumentMarker>& marker1, |
| 390 const Member<DocumentMarker>& marker2) { | 390 const Member<DocumentMarker>& marker2) { |
| 391 return marker1->StartOffset() < marker2->StartOffset(); | 391 return marker1->StartOffset() < marker2->StartOffset(); |
| 392 }); | 392 }); |
| 393 return result; | 393 return result; |
| 394 } | 394 } |
| 395 | 395 |
| 396 Vector<IntRect> DocumentMarkerController::RenderedRectsForMarkers( | 396 Vector<IntRect> DocumentMarkerController::RenderedRectsForMarkers( |
| 397 DocumentMarker::MarkerType marker_type) { | 397 DocumentMarker::MarkerType marker_type) { |
| 398 // Only TextMatch markers can have rendered rects | |
| 399 // TODO(rlanday): remove marker_type parameter | |
| 400 DCHECK_EQ(marker_type, DocumentMarker::kTextMatch); | |
| 401 | |
| 398 Vector<IntRect> result; | 402 Vector<IntRect> result; |
| 399 | 403 |
| 400 if (!PossiblyHasMarkers(marker_type)) | 404 if (!PossiblyHasMarkers(marker_type)) |
| 401 return result; | 405 return result; |
| 402 DCHECK(!(markers_.IsEmpty())); | 406 DCHECK(!(markers_.IsEmpty())); |
| 403 | 407 |
| 404 // outer loop: process each node | 408 // outer loop: process each node |
| 405 MarkerMap::iterator end = markers_.end(); | 409 MarkerMap::iterator end = markers_.end(); |
| 406 for (MarkerMap::iterator node_iterator = markers_.begin(); | 410 for (MarkerMap::iterator node_iterator = markers_.begin(); |
| 407 node_iterator != end; ++node_iterator) { | 411 node_iterator != end; ++node_iterator) { |
| 408 // inner loop; process each marker in this node | 412 // inner loop; process each marker in this node |
| 409 const Node& node = *node_iterator->key; | 413 const Node& node = *node_iterator->key; |
| 410 if (!node.isConnected()) | 414 if (!node.isConnected()) |
| 411 continue; | 415 continue; |
| 412 MarkerLists* markers = node_iterator->value.Get(); | 416 MarkerLists* markers = node_iterator->value.Get(); |
| 413 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { | 417 DocumentMarkerList* const list = |
| 414 DocumentMarkerList* const list = ListForType(markers, type); | 418 ListForType(markers, DocumentMarker::kTextMatch); |
| 415 if (!list || list->IsEmpty() || type != marker_type) | 419 if (!list || list->IsEmpty()) |
| 420 continue; | |
| 421 | |
| 422 for (DocumentMarker* marker : list->GetMarkers()) { | |
| 423 RenderedDocumentMarker* const rendered_marker = | |
| 424 ToRenderedDocumentMarker(marker); | |
| 425 UpdateMarkerRenderedRectIfNeeded(node, *rendered_marker); | |
| 426 if (!rendered_marker->IsRendered()) | |
| 416 continue; | 427 continue; |
| 417 | 428 result.push_back(rendered_marker->RenderedRect()); |
| 418 for (RenderedDocumentMarker* rendered_marker : list->GetMarkers()) { | |
| 419 UpdateMarkerRenderedRectIfNeeded(node, *rendered_marker); | |
| 420 if (!rendered_marker->IsRendered()) | |
| 421 continue; | |
| 422 result.push_back(rendered_marker->RenderedRect()); | |
| 423 } | |
| 424 } | 429 } |
| 425 } | 430 } |
| 426 | 431 |
| 427 return result; | 432 return result; |
| 428 } | 433 } |
| 429 | 434 |
| 430 static void InvalidatePaintForTickmarks(const Node& node) { | 435 static void InvalidatePaintForTickmarks(const Node& node) { |
| 431 if (FrameView* frame_view = node.GetDocument().View()) | 436 if (FrameView* frame_view = node.GetDocument().View()) |
| 432 frame_view->InvalidatePaintForTickmarks(); | 437 frame_view->InvalidatePaintForTickmarks(); |
| 433 } | 438 } |
| 434 | 439 |
| 435 void DocumentMarkerController::UpdateMarkerRenderedRectIfNeeded( | 440 void DocumentMarkerController::UpdateMarkerRenderedRectIfNeeded( |
| 436 const Node& node, | 441 const Node& node, |
| 437 RenderedDocumentMarker& marker) { | 442 RenderedDocumentMarker& marker) { |
| 438 DCHECK(!document_->View() || !document_->View()->NeedsLayout()); | 443 DCHECK(!document_->View() || !document_->View()->NeedsLayout()); |
| 439 DCHECK(!document_->NeedsLayoutTreeUpdate()); | 444 DCHECK(!document_->NeedsLayoutTreeUpdate()); |
| 440 if (!marker.IsValid()) | 445 if (!marker.IsValid()) |
| 441 UpdateMarkerRenderedRect(node, marker); | 446 UpdateMarkerRenderedRect(node, marker); |
| 442 } | 447 } |
| 443 | 448 |
| 444 void DocumentMarkerController::InvalidateRectsForMarkersInNode( | 449 void DocumentMarkerController::InvalidateRectsForMarkersInNode( |
| 445 const Node& node) { | 450 const Node& node) { |
| 446 MarkerLists* markers = markers_.at(&node); | 451 MarkerLists* markers = markers_.at(&node); |
| 447 | 452 |
| 448 for (auto& marker_list : *markers) { | 453 const DocumentMarkerList* const marker_list = |
| 449 if (!marker_list || marker_list->IsEmpty()) | 454 ListForType(markers, DocumentMarker::kTextMatch); |
| 450 continue; | 455 if (!marker_list || marker_list->IsEmpty()) |
| 456 return; | |
| 451 | 457 |
| 452 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list = | 458 const HeapVector<Member<DocumentMarker>>& markers_in_list = |
| 453 marker_list->GetMarkers(); | 459 marker_list->GetMarkers(); |
| 454 for (auto& marker : markers_in_list) | 460 for (auto& marker : markers_in_list) |
| 455 marker->Invalidate(); | 461 ToRenderedDocumentMarker(marker)->Invalidate(); |
| 456 | 462 |
| 457 if (markers_in_list.front()->GetType() == DocumentMarker::kTextMatch) | 463 InvalidatePaintForTickmarks(node); |
| 458 InvalidatePaintForTickmarks(node); | |
| 459 } | |
| 460 } | 464 } |
| 461 | 465 |
| 462 void DocumentMarkerController::InvalidateRectsForAllMarkers() { | 466 void DocumentMarkerController::InvalidateRectsForAllMarkers() { |
|
Xiaocheng
2017/05/18 19:15:09
This function should modify only TextMatch marker
| |
| 463 for (auto& node_markers : markers_) { | 467 for (auto& node_markers : markers_) { |
| 464 const Node& node = *node_markers.key; | 468 const Node& node = *node_markers.key; |
| 465 for (auto& marker_list : *node_markers.value) { | 469 for (auto& marker_list : *node_markers.value) { |
| 466 if (!marker_list || marker_list->IsEmpty()) | 470 if (!marker_list || marker_list->IsEmpty()) |
| 467 continue; | 471 continue; |
| 468 | 472 |
| 469 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list = | 473 const HeapVector<Member<DocumentMarker>>& markers_in_list = |
| 470 marker_list->GetMarkers(); | 474 marker_list->GetMarkers(); |
| 471 for (DocumentMarker* marker : markers_in_list) | 475 for (DocumentMarker* marker : markers_in_list) |
| 472 ToRenderedDocumentMarker(marker)->Invalidate(); | 476 ToRenderedDocumentMarker(marker)->Invalidate(); |
|
Xiaocheng
2017/05/18 19:15:09
Otherwise this is a bad cast
| |
| 473 | 477 |
| 474 if (markers_in_list.front()->GetType() == DocumentMarker::kTextMatch) | 478 if (markers_in_list.front()->GetType() == DocumentMarker::kTextMatch) |
| 475 InvalidatePaintForTickmarks(node); | 479 InvalidatePaintForTickmarks(node); |
| 476 } | 480 } |
| 477 } | 481 } |
| 478 } | 482 } |
| 479 | 483 |
| 480 DEFINE_TRACE(DocumentMarkerController) { | 484 DEFINE_TRACE(DocumentMarkerController) { |
| 481 visitor->Trace(markers_); | 485 visitor->Trace(markers_); |
| 482 visitor->Trace(document_); | 486 visitor->Trace(document_); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 if (!markers) | 646 if (!markers) |
| 643 return false; | 647 return false; |
| 644 | 648 |
| 645 bool doc_dirty = false; | 649 bool doc_dirty = false; |
| 646 DocumentMarkerList* const list = | 650 DocumentMarkerList* const list = |
| 647 ListForType(markers, DocumentMarker::kTextMatch); | 651 ListForType(markers, DocumentMarker::kTextMatch); |
| 648 | 652 |
| 649 if (!list) | 653 if (!list) |
| 650 return false; | 654 return false; |
| 651 | 655 |
| 652 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list = | 656 const HeapVector<Member<DocumentMarker>>& markers_in_list = |
| 653 list->GetMarkers(); | 657 list->GetMarkers(); |
| 654 // TODO(rlanday): this assumes that the markers are stored in sorted order. | 658 // TODO(rlanday): this assumes that the markers are stored in sorted order. |
| 655 // This method should probably eventually be implemented by a | 659 // This method should probably eventually be implemented by a |
| 656 // TextMatch-specific marker list | 660 // TextMatch-specific marker list |
| 657 const auto start_pos = std::upper_bound( | 661 const auto start_pos = std::upper_bound( |
| 658 markers_in_list.begin(), markers_in_list.end(), start_offset, | 662 markers_in_list.begin(), markers_in_list.end(), start_offset, |
| 659 [](size_t start_offset, const Member<DocumentMarker>& marker) { | 663 [](size_t start_offset, const Member<DocumentMarker>& marker) { |
| 660 return start_offset < marker->EndOffset(); | 664 return start_offset < marker->EndOffset(); |
| 661 }); | 665 }); |
| 662 for (auto marker = start_pos; marker != markers_in_list.end(); ++marker) { | 666 for (auto marker = start_pos; marker != markers_in_list.end(); ++marker) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 681 void DocumentMarkerController::ShowMarkers() const { | 685 void DocumentMarkerController::ShowMarkers() const { |
| 682 StringBuilder builder; | 686 StringBuilder builder; |
| 683 MarkerMap::const_iterator end = markers_.end(); | 687 MarkerMap::const_iterator end = markers_.end(); |
| 684 for (MarkerMap::const_iterator node_iterator = markers_.begin(); | 688 for (MarkerMap::const_iterator node_iterator = markers_.begin(); |
| 685 node_iterator != end; ++node_iterator) { | 689 node_iterator != end; ++node_iterator) { |
| 686 const Node* node = node_iterator->key; | 690 const Node* node = node_iterator->key; |
| 687 builder.Append(String::Format("%p", node)); | 691 builder.Append(String::Format("%p", node)); |
| 688 MarkerLists* markers = markers_.at(node); | 692 MarkerLists* markers = markers_.at(node); |
| 689 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { | 693 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { |
| 690 DocumentMarkerList* const list = ListForType(markers, type); | 694 DocumentMarkerList* const list = ListForType(markers, type); |
| 691 const HeapVector<Member<RenderedDocumentMarker>>& markers_in_list = | 695 const HeapVector<Member<DocumentMarker>>& markers_in_list = |
| 692 list->GetMarkers(); | 696 list->GetMarkers(); |
| 693 for (const DocumentMarker* marker : markers_in_list) { | 697 for (const DocumentMarker* marker : markers_in_list) { |
| 694 builder.Append(" "); | 698 builder.Append(" "); |
| 695 builder.AppendNumber(marker->GetType()); | 699 builder.AppendNumber(marker->GetType()); |
| 696 builder.Append(":["); | 700 builder.Append(":["); |
| 697 builder.AppendNumber(marker->StartOffset()); | 701 builder.AppendNumber(marker->StartOffset()); |
| 698 builder.Append(":"); | 702 builder.Append(":"); |
| 699 builder.AppendNumber(marker->EndOffset()); | 703 builder.AppendNumber(marker->EndOffset()); |
| 700 builder.Append("]("); | 704 builder.Append("]("); |
| 701 builder.AppendNumber(marker->IsActiveMatch()); | 705 builder.AppendNumber(marker->IsActiveMatch()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 } | 745 } |
| 742 | 746 |
| 743 } // namespace blink | 747 } // namespace blink |
| 744 | 748 |
| 745 #ifndef NDEBUG | 749 #ifndef NDEBUG |
| 746 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { | 750 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { |
| 747 if (controller) | 751 if (controller) |
| 748 controller->ShowMarkers(); | 752 controller->ShowMarkers(); |
| 749 } | 753 } |
| 750 #endif | 754 #endif |
| OLD | NEW |