diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/page/FrameSnapshotting.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/page/FrameSnapshotting.cpp')
-rw-r--r-- | Source/WebCore/page/FrameSnapshotting.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
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 { @@ -66,6 +69,12 @@ struct ScopedFramePaintingState { std::unique_ptr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions options) { + Vector<FloatRect> clipRects; + return snapshotFrameRectWithClip(frame, imageRect, clipRects, options); +} + +std::unique_ptr<ImageBuffer> snapshotFrameRectWithClip(Frame& frame, const IntRect& imageRect, Vector<FloatRect>& clipRects, SnapshotOptions options) +{ if (!frame.page()) return nullptr; @@ -86,14 +95,28 @@ std::unique_ptr<ImageBuffer> 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<ImageBuffer> 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<ImageBuffer> 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<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().bounds()), options); + return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), options); } std::unique_ptr<ImageBuffer> snapshotNode(Frame& frame, Node& node) @@ -119,7 +150,7 @@ std::unique_ptr<ImageBuffer> 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 |