Title: [133476] branches/safari-536.28-branch/Source

Diff

Modified: branches/safari-536.28-branch/Source/WebCore/ChangeLog (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebCore/ChangeLog	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebCore/ChangeLog	2012-11-05 15:29:44 UTC (rev 133476)
@@ -1,5 +1,32 @@
 2012-11-05  Lucas Forschler  <[email protected]>
 
+        Merge r125091
+
+    2012-08-08  Beth Dakin  <[email protected]>
+
+            https://bugs.webkit.org/show_bug.cgi?id=92275
+            Need a way to get a snapshot image that does not show the selection
+            -and corresponding-
+            <rdar://problem/11956802>
+
+            Reviewed by Anders Carlsson.
+
+            New function FrameView::paintContentsForSnapshot() has the option to 
+            exclude selection from the snapshot.
+
+            Export new function
+            * WebCore.exp.in:
+
+            Clear the selection from the RenderView when selection is to be excluded. Restore 
+            all of this information via FrameSelection::updateAppearance() after calling 
+            paintContents().
+            * page/FrameView.cpp:
+            (WebCore::FrameView::paintContentsForSnapshot):
+            (WebCore):
+            * page/FrameView.h:
+
+2012-11-05  Lucas Forschler  <[email protected]>
+
         Merge r125052
 
     2012-08-08  Tom Sepez  <[email protected]>
@@ -206416,3 +206443,4 @@
 .
 .
 .
+.

Modified: branches/safari-536.28-branch/Source/WebCore/WebCore.exp.in (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebCore/WebCore.exp.in	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebCore/WebCore.exp.in	2012-11-05 15:29:44 UTC (rev 133476)
@@ -1093,6 +1093,7 @@
 __ZN7WebCore9FrameView22setBaseBackgroundColorERKNS_5ColorE
 __ZN7WebCore9FrameView23updateCanHaveScrollbarsEv
 __ZN7WebCore9FrameView24forceLayoutForPaginationERKNS_9FloatSizeES3_fNS_19AdjustViewSizeOrNotE
+__ZN7WebCore9FrameView24paintContentsForSnapshotEPNS_15GraphicsContextERKNS_7IntRectENS0_18SelectionInSnaphotE
 __ZN7WebCore9FrameView26adjustPageHeightDeprecatedEPffff
 __ZN7WebCore9FrameView29setShouldUpdateWhileOffscreenEb
 __ZN7WebCore9FrameView37updateLayoutAndStyleIfNeededRecursiveEv

Modified: branches/safari-536.28-branch/Source/WebCore/page/FrameView.cpp (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebCore/page/FrameView.cpp	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebCore/page/FrameView.cpp	2012-11-05 15:29:44 UTC (rev 133476)
@@ -3131,6 +3131,36 @@
     m_nodeToDraw = node;
 }
 
+void FrameView::paintContentsForSnapshot(GraphicsContext* context, const IntRect& imageRect, SelectionInSnaphot shouldPaintSelection)
+{
+    updateLayoutAndStyleIfNeededRecursive();
+
+    // Cache paint behavior and set a new behavior appropriate for snapshots.
+    PaintBehavior oldBehavior = paintBehavior();
+    setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
+
+    // If the snapshot should exclude selection, then we'll clear the current selection
+    // in the render tree only. This will allow us to restore the selection from the DOM
+    // after we paint the snapshot.
+    if (shouldPaintSelection == ExcludeSelection) {
+        for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) {
+            if (RenderView* root = frame->contentRenderer())
+                root->clearSelection();
+        }
+    }
+
+    paintContents(context, imageRect);
+
+    // Restore selection.
+    if (shouldPaintSelection == ExcludeSelection) {
+        for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get()))
+            frame->selection()->updateAppearance();
+    }
+
+    // Restore cached paint behavior.
+    setPaintBehavior(oldBehavior);
+}
+
 void FrameView::paintOverhangAreas(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
 {
     if (context->paintingDisabled())

Modified: branches/safari-536.28-branch/Source/WebCore/page/FrameView.h (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebCore/page/FrameView.h	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebCore/page/FrameView.h	2012-11-05 15:29:44 UTC (rev 133476)
@@ -245,6 +245,9 @@
     void setLastPaintTime(double lastPaintTime) { m_lastPaintTime = lastPaintTime; }
     void setNodeToDraw(Node*);
 
+    enum SelectionInSnaphot { IncludeSelection, ExcludeSelection };
+    void paintContentsForSnapshot(GraphicsContext*, const IntRect& imageRect, SelectionInSnaphot shouldPaintSelection);
+
     virtual void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
     virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
     virtual void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&) OVERRIDE;

Modified: branches/safari-536.28-branch/Source/WebKit2/ChangeLog (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/ChangeLog	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/ChangeLog	2012-11-05 15:29:44 UTC (rev 133476)
@@ -1,3 +1,53 @@
+2012-11-05  Lucas Forschler  <[email protected]>
+
+        Merge r125091
+
+    2012-08-08  Beth Dakin  <[email protected]>
+
+            https://bugs.webkit.org/show_bug.cgi?id=92275
+            Need a way to get a snapshot image that does not show the selection
+            -and corresponding-
+            <rdar://problem/11956802>
+
+            Reviewed by Anders Carlsson.
+
+            Added new API WKBundlePageCreateSnapshotWithOptions()
+
+            New enum SnapshotOptions tracks whether snapshots should exclude 
+            selection highlighting in addition to tracking whether the image is 
+            sharable like the original ImageOptions.
+            * Shared/API/c/WKImage.h:
+            * Shared/API/c/WKSharedAPICast.h:
+            (WebKit::snapshotOptionsFromImageOptions):
+            (WebKit):
+            (WebKit::toSnapshotOptions):
+            * Shared/ImageOptions.h:
+
+            New API.
+            * WebProcess/InjectedBundle/API/c/WKBundlePage.h:
+            * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+            (WKBundlePageCreateSnapshotWithOptions):
+
+            These existing APIs all now call 
+            WebPage::scaledSnapshotWithOptions().
+            (WKBundlePageCreateSnapshotInViewCoordinates):
+            (WKBundlePageCreateSnapshotInDocumentCoordinates):
+            (WKBundlePageCreateScaledSnapshotInDocumentCoordinates):
+
+            This patch removes WebPage::snapshotInViewCoordinates(), 
+            WebPage::snapshotInDocumentCoordinates(), and 
+            WebPage::scaledSnapshotInDocumentCoordinates(). All of the logic is 
+            now consolidated into WebPage::scaledSnapshotWithOptions(). It turns 
+            out that we never did anything different for document coordinates 
+            versus view coordinates, so that complexity could just be eliminated 
+            outright.
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::snapshotOptionsToImageOptions):
+            (WebKit::WebPage::scaledSnapshotWithOptions):
+            (WebKit):
+            * WebProcess/WebPage/WebPage.h:
+            (WebPage):
+
 2012-11-02  Lucas Forschler  <[email protected]>
 
         Merge r124724
@@ -47339,3 +47389,4 @@
 .
 .
 .
+.

Modified: branches/safari-536.28-branch/Source/WebKit2/Shared/API/c/WKImage.h (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/Shared/API/c/WKImage.h	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/Shared/API/c/WKImage.h	2012-11-05 15:29:44 UTC (rev 133476)
@@ -38,6 +38,12 @@
 };
 typedef uint32_t WKImageOptions;
 
+enum {
+    kWKSnapshotOptionsShareable = 1 << 0,
+    kWKSnapshotOptionsExcludeSelectionHighlighting = 1 << 1
+};
+typedef uint32_t WKSnapshotOptions;
+
 WK_EXPORT WKTypeID WKImageGetTypeID();
 
 WK_EXPORT WKImageRef WKImageCreate(WKSize size, WKImageOptions options);

Modified: branches/safari-536.28-branch/Source/WebKit2/Shared/API/c/WKSharedAPICast.h (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/Shared/API/c/WKSharedAPICast.h	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/Shared/API/c/WKSharedAPICast.h	2012-11-05 15:29:44 UTC (rev 133476)
@@ -758,6 +758,28 @@
     return static_cast<ImageOptions>(imageOptions);
 }
 
+inline SnapshotOptions snapshotOptionsFromImageOptions(WKImageOptions wkImageOptions)
+{
+    unsigned snapshotOptions = 0;
+
+    if (wkImageOptions & kWKImageOptionsShareable)
+        snapshotOptions |= SnapshotOptionsShareable;
+
+    return snapshotOptions;
+}
+
+inline SnapshotOptions toSnapshotOptions(WKSnapshotOptions wkSnapshotOptions)
+{
+    unsigned snapshotOptions = 0;
+
+    if (wkSnapshotOptions & kWKSnapshotOptionsShareable)
+        snapshotOptions |= SnapshotOptionsShareable;
+    if (wkSnapshotOptions & kWKSnapshotOptionsExcludeSelectionHighlighting)
+        snapshotOptions |= SnapshotOptionsExcludeSelectionHighlighting;
+
+    return snapshotOptions;
+}
+
 } // namespace WebKit
 
 #endif // WKSharedAPICast_h

Modified: branches/safari-536.28-branch/Source/WebKit2/Shared/ImageOptions.h (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/Shared/ImageOptions.h	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/Shared/ImageOptions.h	2012-11-05 15:29:44 UTC (rev 133476)
@@ -32,6 +32,12 @@
     ImageOptionsShareable = 1 << 0,
 };
 
+enum {
+    SnapshotOptionsShareable = 1 << 0,
+    SnapshotOptionsExcludeSelectionHighlighting = 1 << 1
+};
+typedef uint32_t SnapshotOptions;
+
 } // namespace WebKit
 
 #endif // ImageOptions_h

Modified: branches/safari-536.28-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2012-11-05 15:29:44 UTC (rev 133476)
@@ -282,21 +282,27 @@
     return toImpl(pageRef)->findStringFromInjectedBundle(toImpl(target)->string(), toFindOptions(findOptions));
 }
 
+WKImageRef WKBundlePageCreateSnapshotWithOptions(WKBundlePageRef pageRef, WKRect rect, WKSnapshotOptions options)
+{
+    RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, toSnapshotOptions(options));
+    return toAPI(webImage.release().leakRef());
+}
+
 WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options)
 {
-    RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInViewCoordinates(toIntRect(rect), toImageOptions(options));
+    RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, snapshotOptionsFromImageOptions(options));
     return toAPI(webImage.release().leakRef());
 }
 
 WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options)
 {
-    RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInDocumentCoordinates(toIntRect(rect), toImageOptions(options));
+    RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, snapshotOptionsFromImageOptions(options));
     return toAPI(webImage.release().leakRef());
 }
 
 WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, double scaleFactor, WKImageOptions options)
 {
-    RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotInDocumentCoordinates(toIntRect(rect), scaleFactor, toImageOptions(options));
+    RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), scaleFactor, snapshotOptionsFromImageOptions(options));
     return toAPI(webImage.release().leakRef());
 }
 

Modified: branches/safari-536.28-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h	2012-11-05 15:29:44 UTC (rev 133476)
@@ -392,8 +392,14 @@
 
 WK_EXPORT bool WKBundlePageFindString(WKBundlePageRef page, WKStringRef target, WKFindOptions findOptions);
 
+WK_EXPORT WKImageRef WKBundlePageCreateSnapshotWithOptions(WKBundlePageRef page, WKRect rect, WKSnapshotOptions options);
+
+// We should deprecate these functions in favor of just using WKBundlePageCreateSnapshotWithOptions.
 WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options);
 WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options);
+
+// We should keep this function since it allows passing a scale factor, but we should re-name it to
+// WKBundlePageCreateScaledSnapshotWithOptions.
 WK_EXPORT WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, double scaleFactor, WKImageOptions options);
 
 WK_EXPORT double WKBundlePageGetBackingScaleFactor(WKBundlePageRef page);

Modified: branches/safari-536.28-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-11-05 15:29:44 UTC (rev 133476)
@@ -1145,43 +1145,27 @@
 #endif
 }
 
-PassRefPtr<WebImage> WebPage::snapshotInViewCoordinates(const IntRect& rect, ImageOptions options)
+static ImageOptions snapshotOptionsToImageOptions(SnapshotOptions snapshotOptions)
 {
-    FrameView* frameView = m_mainFrame->coreFrame()->view();
-    if (!frameView)
-        return 0;
+    unsigned imageOptions = 0;
 
-    IntSize bitmapSize = rect.size();
-    float deviceScaleFactor = corePage()->deviceScaleFactor();
-    bitmapSize.scale(deviceScaleFactor);
+    if (snapshotOptions & SnapshotOptionsShareable)
+        imageOptions |= ImageOptionsShareable;
 
-    RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, options);
-    if (!snapshot->bitmap())
-        return 0;
-    
-    OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext();
-    graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
-    graphicsContext->translate(-rect.x(), -rect.y());
-
-    frameView->updateLayoutAndStyleIfNeededRecursive();
-
-    PaintBehavior oldBehavior = frameView->paintBehavior();
-    frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
-    frameView->paint(graphicsContext.get(), rect);
-    frameView->setPaintBehavior(oldBehavior);
-
-    return snapshot.release();
+    return static_cast<ImageOptions>(imageOptions);
 }
 
-PassRefPtr<WebImage> WebPage::scaledSnapshotInDocumentCoordinates(const IntRect& rect, double scaleFactor, ImageOptions options)
+PassRefPtr<WebImage> WebPage::scaledSnapshotWithOptions(const IntRect& rect, double scaleFactor, SnapshotOptions options)
 {
     FrameView* frameView = m_mainFrame->coreFrame()->view();
     if (!frameView)
         return 0;
 
+    IntSize bitmapSize = rect.size();
     float combinedScaleFactor = scaleFactor * corePage()->deviceScaleFactor();
-    IntSize size(ceil(rect.width() * combinedScaleFactor), ceil(rect.height() * combinedScaleFactor));
-    RefPtr<WebImage> snapshot = WebImage::create(size, options);
+    bitmapSize.scale(combinedScaleFactor);
+
+    RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options));
     if (!snapshot->bitmap())
         return 0;
 
@@ -1189,21 +1173,15 @@
     graphicsContext->applyDeviceScaleFactor(combinedScaleFactor);
     graphicsContext->translate(-rect.x(), -rect.y());
 
-    frameView->updateLayoutAndStyleIfNeededRecursive();
+    FrameView::SelectionInSnaphot shouldPaintSelection = FrameView::IncludeSelection;
+    if (options & SnapshotOptionsExcludeSelectionHighlighting)
+        shouldPaintSelection = FrameView::ExcludeSelection;
 
-    PaintBehavior oldBehavior = frameView->paintBehavior();
-    frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
-    frameView->paintContents(graphicsContext.get(), rect);
-    frameView->setPaintBehavior(oldBehavior);
+    frameView->paintContentsForSnapshot(graphicsContext.get(), rect, shouldPaintSelection);
 
     return snapshot.release();
 }
 
-PassRefPtr<WebImage> WebPage::snapshotInDocumentCoordinates(const IntRect& rect, ImageOptions options)
-{
-    return scaledSnapshotInDocumentCoordinates(rect, 1, options);
-}
-
 void WebPage::pageDidScroll()
 {
     m_uiClient.pageDidScroll(this);

Modified: branches/safari-536.28-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h (133475 => 133476)


--- branches/safari-536.28-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-11-05 15:25:12 UTC (rev 133475)
+++ branches/safari-536.28-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-11-05 15:29:44 UTC (rev 133476)
@@ -330,9 +330,7 @@
     WebCore::IntPoint screenToWindow(const WebCore::IntPoint&);
     WebCore::IntRect windowToScreen(const WebCore::IntRect&);
 
-    PassRefPtr<WebImage> snapshotInViewCoordinates(const WebCore::IntRect&, ImageOptions);
-    PassRefPtr<WebImage> snapshotInDocumentCoordinates(const WebCore::IntRect&, ImageOptions);
-    PassRefPtr<WebImage> scaledSnapshotInDocumentCoordinates(const WebCore::IntRect&, double scaleFactor, ImageOptions);
+    PassRefPtr<WebImage> scaledSnapshotWithOptions(const WebCore::IntRect&, double scaleFactor, SnapshotOptions);
 
     static const WebEvent* currentEvent();
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to