Compute document marker rects at use time instead of paint time
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Sep 2015 19:36:37 +0000 (19:36 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Sep 2015 19:36:37 +0000 (19:36 +0000)
commit9ed553cdb7d4c40505091a62bd5c29df5b212559
treef7f57613f957da943e9c094fcb3134bdde37160a
parent4ea65276c6c00734db3407375ec0aa650911e4a1
Compute document marker rects at use time instead of paint time
https://bugs.webkit.org/show_bug.cgi?id=149643

Reviewed by Darin Adler.

* dom/DocumentMarkerController.cpp:
(WebCore::DocumentMarkerController::DocumentMarkerController):
(WebCore::DocumentMarkerController::detach):
Store and zero the Document backpointer.

(WebCore::DocumentMarkerController::addMarker):
(WebCore::DocumentMarkerController::addTextMatchMarker):
(WebCore::DocumentMarkerController::addDictationPhraseWithAlternativesMarker):
(WebCore::DocumentMarkerController::addDictationResultMarker):
(WebCore::DocumentMarkerController::copyMarkers):
Remove some useless comments.

(WebCore::updateRenderedRectsForMarker):
Use Range to compute the (unclipped, absolute) text rects, and store them
on the RenderedDocumentMarker.

(WebCore::DocumentMarkerController::invalidateRectsForAllMarkers):
(WebCore::DocumentMarkerController::invalidateRectsForMarkersInNode):
Mark the relevant markers' rects as invalid, and notify the ChromeClient.

(WebCore::DocumentMarkerController::updateRectsForInvalidatedMarkersOfType):
Run through all markers, computing rects for ones that don't have valid rects.
We will do layout (once) if necessary. However, this is most commonly
called from a place where layout should already be up to date, so this
should not happen often. updateRenderedRectsForMarker also asserts
that layout is up to date.

(WebCore::DocumentMarkerController::renderedRectsForMarkers):
Retrieve all markers of the given type, clip them by overflow clip and
frame clip, and return them to the caller.

(WebCore::DocumentMarkerController::addMarker):
(WebCore::DocumentMarkerController::markerContainingPoint):
(WebCore::DocumentMarkerController::markersFor):
(WebCore::DocumentMarkerController::repaintMarkers):
(WebCore::DocumentMarkerController::shiftMarkers):
(DocumentMarkerController::setMarkersActive):
(DocumentMarkerController::hasMarkers):
Modern iteration.

(WebCore::DocumentMarkerController::invalidateRenderedRectsForMarkersInRect): Deleted.
* dom/DocumentMarkerController.h:

* dom/Document.cpp:
(WebCore::Document::Document):
Pass the Document to the DocumentMarkerController.

* dom/RenderedDocumentMarker.h:
(WebCore::RenderedDocumentMarker::contains):
(WebCore::RenderedDocumentMarker::setUnclippedAbsoluteRects):
(WebCore::RenderedDocumentMarker::unclippedAbsoluteRects):
(WebCore::RenderedDocumentMarker::invalidate):
(WebCore::RenderedDocumentMarker::isValid):
(WebCore::RenderedDocumentMarker::addRenderedRect): Deleted.
(WebCore::RenderedDocumentMarker::renderedRects): Deleted.
Instead of keeping "rendered" rects, keep unclipped rects in absolute
document coordinates. Invalidation will happen wholesale instead of
based on dirty rects, because computation no longer happens at paint
time, so it's safe to throw all of the rects away.
Keep track of whether we have valid rects or not.

* editing/Editor.cpp:
(WebCore::Editor::countMatchesForText):
We don't need to do a fake whole-document paint just to compute the
document marker rects. They are computed on demand, using layout information
instead of paint-time information.

* page/ChromeClient.h:
Remove an unnecessary semicolon.
Add didInvalidateDocumentMarkerRects, which DocumentMarkerController
will call whenever document marker rects are invalidated (and when e.g.
the find holes PageOverlay should repaint itself).

* page/FrameView.cpp:
(WebCore::FrameView::layout):
Invalidate document marker's layout-computed rects after layout is complete.
They'll be lazily recomputed when next requested.

(WebCore::FrameView::willPaintContents):
Remove the pre-painting invalidation of document marker rects.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paintTextMatchMarker):
(WebCore::InlineTextBox::paintDocumentMarker): Deleted.
(WebCore::InlineTextBox::computeRectForReplacementMarker): Deleted.
(WebCore::InlineTextBox::paintDocumentMarkers): Deleted.
Don't bother computing rendered rects for document markers at paint time.
Just do the actual painting work (which, for replacement markers, is
nothing at all).

* rendering/InlineTextBox.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateLayerPositions):
(WebCore::RenderLayer::updateLayerPositionsAfterScroll):
When RenderLayers move, invalidate document marker rects.

* rendering/svg/SVGInlineFlowBox.cpp:
(WebCore::SVGInlineFlowBox::paint):
(WebCore::SVGInlineFlowBox::computeTextMatchMarkerRectForRenderer): Deleted.
* rendering/svg/SVGInlineFlowBox.h:
* rendering/svg/SVGRootInlineBox.cpp:
(WebCore::SVGRootInlineBox::paint):
Don't bother computing rendered rects for document markers at paint time.

* testing/Internals.cpp:
(WebCore::markerTypeFrom):
(WebCore::markerTypesFrom):
Add markerTypeFrom, which returns MarkerType enum values for the input string
instead of a MarkerTypes class.

(WebCore::Internals::dumpMarkerRects):
Dump all markers for the given type, and request them from DocumentMarkerController
instead of from the RenderedDocumentMarker, because we want fully clipped
rects, which can only be obtained from DocumentMarkerController.

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::getTextRectangles):
Avoid enclosing unnecessarily, to avoid inflating zero-width text rects
to have a non-zero width. Callers appear to be OK with non-integral positions.

* testing/Internals.h:
* testing/Internals.idl:

* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::didInvalidateDocumentMarkerRects):
* WebProcess/WebCoreSupport/WebChromeClient.h:
Plumb the notification about invalidated document marker rects through to FindController.

* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::updateFindUIAfterPageScroll):
Make a document-relative PageOverlay, so that we get fast scrolling.

(WebKit::FindController::rectsForTextMatchesInRect):
Return find hole rects in main-FrameView content coordinates, to
match the document-relative page overlay.
We'll only return rects that intersect the passed-in rect, which
comes from the dirty rect passed to drawRect.

(WebKit::FindController::drawRect):
Inflate the dirty rect by the border width so that we hit all relevant
markers in each tile. Otherwise, we would end up missing the border of a marker
that touched the edge of a tile.

(WebKit::FindController::didInvalidateDocumentMarkerRects):
Repaint (for now, the entire overlay) when document marker rects change.

* WebProcess/WebPage/FindController.h:

* WebView/WebHTMLView.mm:
(-[WebHTMLView rectsForTextMatches]):

* WebView.cpp:
(WebView::rectsForTextMatches):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190363 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/DocumentMarkerController.cpp
Source/WebCore/dom/DocumentMarkerController.h
Source/WebCore/dom/RenderedDocumentMarker.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/page/ChromeClient.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/rendering/InlineTextBox.h
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/svg/SVGInlineFlowBox.cpp
Source/WebCore/rendering/svg/SVGInlineFlowBox.h
Source/WebCore/rendering/svg/SVGRootInlineBox.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebHTMLView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit2/WebProcess/WebPage/FindController.cpp
Source/WebKit2/WebProcess/WebPage/FindController.h