From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/page/FrameSnapshotting.cpp | 41 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'Source/WebCore/page/FrameSnapshotting.cpp') diff --git a/Source/WebCore/page/FrameSnapshotting.cpp b/Source/WebCore/page/FrameSnapshotting.cpp index 495406b82..3d34cd929 100644 --- a/Source/WebCore/page/FrameSnapshotting.cpp +++ b/Source/WebCore/page/FrameSnapshotting.cpp @@ -32,12 +32,15 @@ #include "FrameSnapshotting.h" #include "Document.h" +#include "FloatRect.h" #include "Frame.h" #include "FrameSelection.h" #include "FrameView.h" +#include "GraphicsContext.h" #include "ImageBuffer.h" #include "Page.h" #include "RenderObject.h" +#include "Settings.h" namespace WebCore { @@ -65,6 +68,12 @@ struct ScopedFramePaintingState { }; std::unique_ptr snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions options) +{ + Vector clipRects; + return snapshotFrameRectWithClip(frame, imageRect, clipRects, options); +} + +std::unique_ptr snapshotFrameRectWithClip(Frame& frame, const IntRect& imageRect, Vector& clipRects, SnapshotOptions options) { if (!frame.page()) return nullptr; @@ -86,14 +95,28 @@ std::unique_ptr snapshotFrameRect(Frame& frame, const IntRect& imag paintBehavior |= PaintBehaviorForceBlackText; if (options & SnapshotOptionsPaintSelectionOnly) paintBehavior |= PaintBehaviorSelectionOnly; + if (options & SnapshotOptionsPaintSelectionAndBackgroundsOnly) + paintBehavior |= PaintBehaviorSelectionAndBackgroundsOnly; // Other paint behaviors are set by paintContentsForSnapshot. frame.view()->setPaintBehavior(paintBehavior); - std::unique_ptr buffer = ImageBuffer::create(imageRect.size(), frame.page()->deviceScaleFactor(), ColorSpaceDeviceRGB); + float scaleFactor = frame.page()->deviceScaleFactor(); + + if (frame.settings().delegatesPageScaling()) + scaleFactor *= frame.page()->pageScaleFactor(); + + std::unique_ptr buffer = ImageBuffer::create(imageRect.size(), Unaccelerated, scaleFactor); if (!buffer) return nullptr; - buffer->context()->translate(-imageRect.x(), -imageRect.y()); + buffer->context().translate(-imageRect.x(), -imageRect.y()); + + if (!clipRects.isEmpty()) { + Path clipPath; + for (auto& rect : clipRects) + clipPath.addRect(rect); + buffer->context().clipPath(clipPath); + } frame.view()->paintContentsForSnapshot(buffer->context(), imageRect, shouldIncludeSelection, coordinateSpace); return buffer; @@ -101,11 +124,19 @@ std::unique_ptr snapshotFrameRect(Frame& frame, const IntRect& imag std::unique_ptr 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().bounds()), options); + return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), options); } std::unique_ptr snapshotNode(Frame& frame, Node& node) @@ -119,7 +150,7 @@ std::unique_ptr snapshotNode(Frame& frame, Node& node) frame.view()->setNodeToDraw(&node); LayoutRect topLevelRect; - return snapshotFrameRect(frame, pixelSnappedIntRect(node.renderer()->paintingRootRect(topLevelRect))); + return snapshotFrameRect(frame, snappedIntRect(node.renderer()->paintingRootRect(topLevelRect))); } } // namespace WebCore -- cgit v1.2.1