static PassRefPtr<WebImage> imageForRect(FrameView* frameView, const IntRect& rect, SnapshotOptions options) { IntSize bitmapSize = rect.size(); float scaleFactor = frameView->frame().page()->deviceScaleFactor(); bitmapSize.scale(scaleFactor); auto snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options)); if (!snapshot->bitmap()) return 0; auto graphicsContext = snapshot->bitmap()->createGraphicsContext(); graphicsContext->clearRect(IntRect(IntPoint(), bitmapSize)); graphicsContext->applyDeviceScaleFactor(scaleFactor); graphicsContext->translate(-rect.x(), -rect.y()); FrameView::SelectionInSnapshot shouldPaintSelection = FrameView::IncludeSelection; if (options & SnapshotOptionsExcludeSelectionHighlighting) shouldPaintSelection = FrameView::ExcludeSelection; PaintBehavior paintBehavior = frameView->paintBehavior() | PaintBehaviorFlattenCompositingLayers; if (options & SnapshotOptionsForceBlackText) paintBehavior |= PaintBehaviorForceBlackText; if (options & SnapshotOptionsForceWhiteText) paintBehavior |= PaintBehaviorForceWhiteText; PaintBehavior oldPaintBehavior = frameView->paintBehavior(); frameView->setPaintBehavior(paintBehavior); frameView->paintContentsForSnapshot(*graphicsContext.get(), rect, shouldPaintSelection, FrameView::DocumentCoordinates); frameView->setPaintBehavior(oldPaintBehavior); return snapshot; }
static PassRefPtr<WebImage> imageForRect(FrameView* frameView, const IntRect& rect, SnapshotOptions options) { IntSize bitmapSize = rect.size(); float scaleFactor = frameView->frame().page()->deviceScaleFactor(); bitmapSize.scale(scaleFactor); RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options)); if (!snapshot->bitmap()) return 0; auto graphicsContext = snapshot->bitmap()->createGraphicsContext(); graphicsContext->clearRect(IntRect(IntPoint(), bitmapSize)); graphicsContext->applyDeviceScaleFactor(scaleFactor); graphicsContext->translate(-rect.x(), -rect.y()); FrameView::SelectionInSnapshot shouldPaintSelection = FrameView::IncludeSelection; if (options & SnapshotOptionsExcludeSelectionHighlighting) shouldPaintSelection = FrameView::ExcludeSelection; frameView->paintContentsForSnapshot(graphicsContext.get(), rect, shouldPaintSelection, FrameView::DocumentCoordinates); return snapshot.release(); }