Use FrameSnapshotting functions in FindController::getFindIndicatorBitmap
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Nov 2014 20:08:22 +0000 (20:08 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Nov 2014 20:08:22 +0000 (20:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138300
<rdar://problem/18855863>

Reviewed by Simon Fraser.

Share more code by using WebCore's FrameSnapshotting::snapshotSelection
in FindController instead of copying it into FindController wholesale.

* WebProcess/WebPage/FindController.cpp:
(WebKit::getFindIndicatorBitmap):
Make getFindIndicatorBitmap static, rename it from getFindIndicatorBitmapAndRect,
and drop the rect argument because only one caller wanted it, and we no longer need
to compute it (this happens in WebCore now).

Use snapshotSelection; all of the removed paint behaviors get added by
code in or underneath snapshotSelection now.

Draw the snapshot into our ShareableBitmap; we could avoid this in a future patch
by refactoring the FrameSnapshotting functions to take GraphicsContexts.

(WebKit::FindController::getImageForFindMatch):
(WebKit::FindController::updateFindIndicator):
Adopt the new getFindIndicatorBitmap.

* WebProcess/WebPage/FindController.h:
Remove getFindIndicatorBitmap(AndRect), which is now static.

* WebCore.exp.in:
* page/FrameSnapshotting.cpp:
(WebCore::snapshotSelection):
Move knowledge that selectionBounds can be empty down to WebCore.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175484 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/page/FrameSnapshotting.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/FindController.cpp
Source/WebKit2/WebProcess/WebPage/FindController.h

index b4f5709..91c5262 100644 (file)
@@ -1,3 +1,16 @@
+2014-11-03  Tim Horton  <timothy_horton@apple.com>
+
+        Use FrameSnapshotting functions in FindController::getFindIndicatorBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=138300
+        <rdar://problem/18855863>
+
+        Reviewed by Simon Fraser.
+
+        * WebCore.exp.in:
+        * page/FrameSnapshotting.cpp:
+        (WebCore::snapshotSelection):
+        Move knowledge that selectionBounds can be empty down to WebCore.
+
 2014-11-03  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Show Selector's Specificity
index 743e23c..563b963 100644 (file)
@@ -176,6 +176,7 @@ __ZN7WebCore11HistoryItemC1ERKN3WTF6StringES4_S4_
 __ZN7WebCore11HistoryItemC1ERKNS_3URLERKN3WTF6StringES7_S7_
 __ZN7WebCore11HistoryItemC1Ev
 __ZN7WebCore11HistoryItemD1Ev
+__ZN7WebCore11ImageBufferD1Ev
 __ZN7WebCore11JSDOMWindow6s_infoE
 __ZN7WebCore11MemoryCache11setDisabledEb
 __ZN7WebCore11MemoryCache13getStatisticsEv
@@ -521,6 +522,7 @@ __ZN7WebCore15GraphicsContext10strokeRectERKNS_9FloatRectEf
 __ZN7WebCore15GraphicsContext11clearShadowEv
 __ZN7WebCore15GraphicsContext12setFillColorERKNS_5ColorENS_10ColorSpaceE
 __ZN7WebCore15GraphicsContext14setStrokeColorERKNS_5ColorENS_10ColorSpaceE
+__ZN7WebCore15GraphicsContext15drawImageBufferEPNS_11ImageBufferENS_10ColorSpaceERKNS_10FloatPointERKNS_20ImagePaintingOptionsE
 __ZN7WebCore15GraphicsContext15drawNativeImageEP7CGImageRKNS_9FloatSizeENS_10ColorSpaceERKNS_9FloatRectES9_NS_17CompositeOperatorENS_9BlendModeENS_16ImageOrientationE
 __ZN7WebCore15GraphicsContext15setFillGradientEN3WTF7PassRefINS_8GradientEEE
 __ZN7WebCore15GraphicsContext18setShouldAntialiasEb
@@ -779,6 +781,7 @@ __ZN7WebCore17languageDidChangeEv
 __ZN7WebCore17openTemporaryFileERKN3WTF6StringERi
 __ZN7WebCore17sRGBColorSpaceRefEv
 __ZN7WebCore17setCookiesFromDOMERKNS_21NetworkStorageSessionERKNS_3URLES5_RKN3WTF6StringE
+__ZN7WebCore17snapshotSelectionERNS_5FrameEj
 __ZN7WebCore17userVisibleStringEP5NSURL
 __ZN7WebCore18DOMWindowExtensionC1EPNS_5FrameERNS_15DOMWrapperWorldE
 __ZN7WebCore18PlatformCALayerMac18setGeometryFlippedEb
index 1f4fda8..4773ffb 100644 (file)
@@ -102,11 +102,19 @@ std::unique_ptr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imag
 
 std::unique_ptr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions options)
 {
-    if (!frame.selection().isRange())
+    auto& selection = frame.selection();
+
+    if (!selection.isRange())
+        return nullptr;
+
+    FloatRect selectionBounds = selection.selectionBounds();
+
+    // It is possible for the selection bounds to be empty; see https://bugs.webkit.org/show_bug.cgi?id=56645.
+    if (selectionBounds.isEmpty())
         return nullptr;
 
     options |= SnapshotOptionsPaintSelectionOnly;
-    return snapshotFrameRect(frame, enclosingIntRect(frame.selection().selectionBounds()), options);
+    return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), options);
 }
 
 std::unique_ptr<ImageBuffer> snapshotNode(Frame& frame, Node& node)
index f406c24..707488c 100644 (file)
@@ -1,3 +1,33 @@
+2014-11-03  Tim Horton  <timothy_horton@apple.com>
+
+        Use FrameSnapshotting functions in FindController::getFindIndicatorBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=138300
+        <rdar://problem/18855863>
+
+        Reviewed by Simon Fraser.
+
+        Share more code by using WebCore's FrameSnapshotting::snapshotSelection
+        in FindController instead of copying it into FindController wholesale.
+
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::getFindIndicatorBitmap):
+        Make getFindIndicatorBitmap static, rename it from getFindIndicatorBitmapAndRect,
+        and drop the rect argument because only one caller wanted it, and we no longer need
+        to compute it (this happens in WebCore now).
+
+        Use snapshotSelection; all of the removed paint behaviors get added by
+        code in or underneath snapshotSelection now.
+
+        Draw the snapshot into our ShareableBitmap; we could avoid this in a future patch
+        by refactoring the FrameSnapshotting functions to take GraphicsContexts.
+
+        (WebKit::FindController::getImageForFindMatch):
+        (WebKit::FindController::updateFindIndicator):
+        Adopt the new getFindIndicatorBitmap.
+
+        * WebProcess/WebPage/FindController.h:
+        Remove getFindIndicatorBitmap(AndRect), which is now static.
+
 2014-11-03  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         URTBF after r175476 to make GTK and EFL build happy.
index c1c8445..a81fed9 100644 (file)
 #include <WebCore/DocumentMarkerController.h>
 #include <WebCore/FloatQuad.h>
 #include <WebCore/FocusController.h>
+#include <WebCore/FrameSnapshotting.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/GraphicsContext.h>
+#include <WebCore/ImageBuffer.h>
 #include <WebCore/MainFrame.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageOverlayController.h>
@@ -257,38 +259,22 @@ void FindController::findStringMatches(const String& string, FindOptions options
     m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection));
 }
 
-bool FindController::getFindIndicatorBitmapAndRect(Frame& frame, ShareableBitmap::Handle& handle, IntRect& selectionRect)
+static bool getFindIndicatorBitmap(Frame& frame, ShareableBitmap::Handle& handle)
 {
-    selectionRect = enclosingIntRect(frame.selection().selectionBounds());
-
-    // Selection rect can be empty for matches that are currently obscured from view.
-    if (selectionRect.isEmpty())
+    std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(frame, WebCore::SnapshotOptionsForceBlackText);
+    if (!snapshot)
         return false;
 
-    IntSize backingStoreSize = selectionRect.size();
-    float deviceScaleFactor = m_webPage->corePage()->deviceScaleFactor();
-    backingStoreSize.scale(deviceScaleFactor);
-
-    // Create a backing store and paint the find indicator text into it.
-    RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
+    RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(snapshot->internalSize(), ShareableBitmap::SupportsAlpha);
     if (!findIndicatorTextBackingStore)
         return false;
 
     // FIXME: We should consider using subpixel antialiasing for the snapshot
     // if we're compositing this image onto a solid color (the modern find indicator style).
     auto graphicsContext = findIndicatorTextBackingStore->createGraphicsContext();
+    float deviceScaleFactor = frame.page()->deviceScaleFactor();
     graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
-
-    IntRect paintRect = selectionRect;
-    paintRect.move(frame.view()->frameRect().x(), frame.view()->frameRect().y());
-    paintRect.move(-frame.view()->scrollOffset());
-
-    graphicsContext->translate(-paintRect.x(), -paintRect.y());
-    frame.view()->setPaintBehavior(PaintBehaviorSelectionOnly | PaintBehaviorForceBlackText | PaintBehaviorFlattenCompositingLayers);
-    frame.document()->updateLayout();
-
-    frame.view()->paint(graphicsContext.get(), paintRect);
-    frame.view()->setPaintBehavior(PaintBehaviorNormal);
+    graphicsContext->drawImageBuffer(snapshot.get(), ColorSpaceDeviceRGB, FloatPoint());
 
     if (!findIndicatorTextBackingStore->createHandle(handle))
         return false;
@@ -306,9 +292,8 @@ void FindController::getImageForFindMatch(uint32_t matchIndex)
     VisibleSelection oldSelection = frame->selection().selection();
     frame->selection().setSelection(VisibleSelection(m_findMatches[matchIndex].get()));
 
-    IntRect selectionRect;
     ShareableBitmap::Handle handle;
-    getFindIndicatorBitmapAndRect(*frame, handle, selectionRect);
+    getFindIndicatorBitmap(*frame, handle);
 
     frame->selection().setSelection(oldSelection);
 
@@ -347,9 +332,9 @@ void FindController::hideFindUI()
 #if !PLATFORM(IOS)
 bool FindController::updateFindIndicator(Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate)
 {
-    IntRect selectionRect;
+    IntRect selectionRect = enclosingIntRect(selectedFrame.selection().selectionBounds());
     ShareableBitmap::Handle handle;
-    if (!getFindIndicatorBitmapAndRect(selectedFrame, handle, selectionRect))
+    if (!getFindIndicatorBitmap(selectedFrame, handle))
         return false;
 
     // We want the selection rect in window coordinates.
index 905ed1f..3d5677d 100644 (file)
@@ -77,7 +77,6 @@ private:
     virtual void drawRect(WebCore::PageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
 
     Vector<WebCore::IntRect> rectsForTextMatches();
-    bool getFindIndicatorBitmapAndRect(WebCore::Frame&, ShareableBitmap::Handle&, WebCore::IntRect& selectionRect);
     bool updateFindIndicator(WebCore::Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
 
     void updateFindUIAfterPageScroll(bool found, const String&, FindOptions, unsigned maxMatchCount);