Consolidate various frame snapshot capabilities.

https://bugs.webkit.org/show_bug.cgi?id=124325

Patch by Brian J. Burg <burg@cs.washington.edu> on 2013-12-04
Reviewed by Darin Adler.

Source/WebCore:

Various snapshot creation methods had duplicated code and were split
between Frame, DragImage, and platform-specific implementationss.
This patch puts WebCore snapshot methods into FrameSnapshotting
and removes platform implementations where possible.

DragImage methods reuse snapshot methods where possible. Inspector
will be able to take snapshots without using drag images.

No new tests, this is a refactoring.

* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.exp.in:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/objc/DOM.mm:
(-[DOMNode renderedImage]):
(-[DOMRange renderedImageForcingBlackText:]):
* dom/Clipboard.cpp:
(WebCore::Clipboard::createDragImage):
* dom/ClipboardMac.mm:
(WebCore::Clipboard::createDragImage):
* page/DragController.cpp:
(WebCore::DragController::startDrag):
* page/Frame.cpp:
* page/Frame.h:
* page/FrameSnapshotting.cpp: Added.
(WebCore::ScopedFramePaintingState::ScopedFramePaintingState):
(WebCore::ScopedFramePaintingState::~ScopedFramePaintingState):
(WebCore::snapshotFrameRect): Move most buffer logic to here.
(WebCore::snapshotSelection): Moved from Frame.
(WebCore::snapshotNode): Moved from Frame.
* page/FrameSnapshotting.h: Added.
* page/mac/FrameMac.mm: Removed.
* page/mac/FrameSnapshottingMac.h: Removed.
* page/mac/FrameSnapshottingMac.mm: Removed.
* page/win/FrameWin.cpp: remove duplicate implementation.
* page/win/FrameWin.h: Fix an incorrect parameter name.
* platform/DragImage.cpp:
(WebCore::ScopedNodeDragState::ScopedNodeDragState):
(WebCore::ScopedNodeDragState::~ScopedNodeDragState):
(WebCore::createDragImageFromSnapshot): Boilerplate buffer conversion.
(WebCore::createDragImageForNode):
(WebCore::createDragImageForSelection):
(WebCore::ScopedFrameSelectionState::ScopedFrameSelectionState):
(WebCore::ScopedFrameSelectionState::~ScopedFrameSelectionState):
(WebCore::createDragImageForRange): Moved from Frame.
(WebCore::createDragImageForImage): Moved from FrameSnapshottingMac.
(WebCore::createDragImageForLink): use nullptr.

Source/WebKit/ios:

* WebCoreSupport/WebFrameIOS.mm: use new header file.

Source/WebKit/mac:

Use new platform-independent methods instead of Mac methods.

* WebView/WebHTMLView.mm:
(-[WebHTMLView _selectionDraggingImage]):
(-[WebHTMLView selectionImageForcingBlackText:]):

Source/WebKit/win:

* DOMCoreClasses.cpp:
(DOMElement::renderedImage): use createDragImageForNode.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160152 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9df78de6
......@@ -1732,6 +1732,7 @@ set(WebCore_SOURCES
page/FocusController.cpp
page/Frame.cpp
page/FrameDestructionObserver.cpp
page/FrameSnapshotting.cpp
page/FrameTree.cpp
page/FrameView.cpp
page/GestureTapHighlighter.cpp
......
2013-12-04 Brian J. Burg <burg@cs.washington.edu>
Consolidate various frame snapshot capabilities.
https://bugs.webkit.org/show_bug.cgi?id=124325
Reviewed by Darin Adler.
Various snapshot creation methods had duplicated code and were split
between Frame, DragImage, and platform-specific implementationss.
This patch puts WebCore snapshot methods into FrameSnapshotting
and removes platform implementations where possible.
DragImage methods reuse snapshot methods where possible. Inspector
will be able to take snapshots without using drag images.
No new tests, this is a refactoring.
* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.exp.in:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/objc/DOM.mm:
(-[DOMNode renderedImage]):
(-[DOMRange renderedImageForcingBlackText:]):
* dom/Clipboard.cpp:
(WebCore::Clipboard::createDragImage):
* dom/ClipboardMac.mm:
(WebCore::Clipboard::createDragImage):
* page/DragController.cpp:
(WebCore::DragController::startDrag):
* page/Frame.cpp:
* page/Frame.h:
* page/FrameSnapshotting.cpp: Added.
(WebCore::ScopedFramePaintingState::ScopedFramePaintingState):
(WebCore::ScopedFramePaintingState::~ScopedFramePaintingState):
(WebCore::snapshotFrameRect): Move most buffer logic to here.
(WebCore::snapshotSelection): Moved from Frame.
(WebCore::snapshotNode): Moved from Frame.
* page/FrameSnapshotting.h: Added.
* page/mac/FrameMac.mm: Removed.
* page/mac/FrameSnapshottingMac.h: Removed.
* page/mac/FrameSnapshottingMac.mm: Removed.
* page/win/FrameWin.cpp: remove duplicate implementation.
* page/win/FrameWin.h: Fix an incorrect parameter name.
* platform/DragImage.cpp:
(WebCore::ScopedNodeDragState::ScopedNodeDragState):
(WebCore::ScopedNodeDragState::~ScopedNodeDragState):
(WebCore::createDragImageFromSnapshot): Boilerplate buffer conversion.
(WebCore::createDragImageForNode):
(WebCore::createDragImageForSelection):
(WebCore::ScopedFrameSelectionState::ScopedFrameSelectionState):
(WebCore::ScopedFrameSelectionState::~ScopedFrameSelectionState):
(WebCore::createDragImageForRange): Moved from Frame.
(WebCore::createDragImageForImage): Moved from FrameSnapshottingMac.
(WebCore::createDragImageForLink): use nullptr.
2013-12-04 Benjamin Poulain <bpoulain@apple.com>
Remove spaces on a blank line to have ResourceHandleCFNet.cpp identical to iOS
......@@ -4131,6 +4131,8 @@ webcore_sources += \
Source/WebCore/page/Frame.h \
Source/WebCore/page/FrameDestructionObserver.cpp \
Source/WebCore/page/FrameDestructionObserver.h \
Source/WebCore/page/FrameSnapshotting.cpp \
Source/WebCore/page/FrameSnapshotting.h \
Source/WebCore/page/FrameTree.cpp \
Source/WebCore/page/FrameTree.h \
Source/WebCore/page/FrameView.cpp \
......
......@@ -428,7 +428,6 @@ __ZN7WebCore14cookiesEnabledERKNS_21NetworkStorageSessionERKNS_3URLES5_
__ZN7WebCore14decodeHostNameEP8NSString
__ZN7WebCore14encodeHostNameEP8NSString
__ZN7WebCore14endOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE
__ZN7WebCore14selectionImageEPNS_5FrameEb
__ZN7WebCore14setMetadataURLERN3WTF6StringERKS1_S4_
__ZN7WebCore15AffineTransform5flipYEv
__ZN7WebCore15AffineTransform5scaleEd
......@@ -890,6 +889,7 @@ __ZN7WebCore27AuthenticationChallengeBaseC2Ev
__ZN7WebCore27CSSComputedStyleDeclarationC1EN3WTF10PassRefPtrINS_4NodeEEEbRKNS1_6StringE
__ZN7WebCore27DeviceOrientationClientMock14setOrientationEN3WTF10PassRefPtrINS_21DeviceOrientationDataEEE
__ZN7WebCore27DeviceOrientationClientMockC1Ev
__ZN7WebCore27createDragImageForSelectionERNS_5FrameEb
__ZN7WebCore27protocolHostAndPortAreEqualERKNS_3URLES2_
__ZN7WebCore27startObservingCookieChangesEPFvvE
__ZN7WebCore28DocumentStyleSheetCollection12addUserSheetEN3WTF7PassRefINS_18StyleSheetContentsEEE
......@@ -2035,7 +2035,6 @@ __ZN7WebCore38contextMenuItemTagWritingDirectionMenuEv
__ZN7WebCore42contextMenuItemTagCheckGrammarWithSpellingEv
__ZN7WebCore42contextMenuItemTagCheckSpellingWhileTypingEv
__ZN7WebCore46contextMenuItemTagCorrectSpellingAutomaticallyEv
__ZN7WebCore5Frame9nodeImageEPNS_4NodeE
__ZN7WebCore6Cursor8fromTypeENS0_4TypeE
__ZN7WebCore6CursorC1EPNS_5ImageERKNS_8IntPointE
__ZN7WebCore6CursorC1ERKS0_
......
......@@ -6998,6 +6998,7 @@
<ClCompile Include="..\page\FocusController.cpp" />
<ClCompile Include="..\page\Frame.cpp" />
<ClCompile Include="..\page\FrameDestructionObserver.cpp" />
<ClCompile Include="..\page\FrameSnapshotting.cpp" />
<ClCompile Include="..\page\FrameTree.cpp" />
<ClCompile Include="..\page\FrameView.cpp" />
<ClCompile Include="..\page\GroupSettings.cpp" />
......@@ -18854,6 +18855,7 @@
<ClInclude Include="..\page\FocusDirection.h" />
<ClInclude Include="..\page\Frame.h" />
<ClInclude Include="..\page\FrameDestructionObserver.h" />
<ClInclude Include="..\page\FrameSnapshotting.h" />
<ClInclude Include="..\page\FrameTree.h" />
<ClInclude Include="..\page\FrameView.h" />
<ClInclude Include="..\page\GroupSettings.h" />
......@@ -720,6 +720,9 @@
<ClCompile Include="..\page\FrameDestructionObserver.cpp">
<Filter>page</Filter>
</ClCompile>
<ClCompile Include="..\page\FrameSnapshotting.cpp">
<Filter>page</Filter>
</ClCompile>
<ClCompile Include="..\page\FrameTree.cpp">
<Filter>page</Filter>
</ClCompile>
......@@ -7641,6 +7644,9 @@
<ClInclude Include="..\page\FrameDestructionObserver.h">
<Filter>page</Filter>
</ClInclude>
<ClInclude Include="..\page\FrameSnapshotting.h">
<Filter>page</Filter>
</ClInclude>
<ClInclude Include="..\page\FrameTree.h">
<Filter>page</Filter>
</ClInclude>
......
......@@ -36,9 +36,9 @@
#import "DOMNodeInternal.h"
#import "DOMPrivate.h"
#import "DOMRangeInternal.h"
#import "DragImage.h"
#import "Font.h"
#import "Frame.h"
#import "FrameSnapshottingMac.h"
#import "HTMLElement.h"
#import "HTMLNames.h"
#import "HTMLParserIdioms.h"
......@@ -289,7 +289,7 @@ id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
WebCore::Frame* frame = node->document().frame();
if (!frame)
return nil;
return frame->nodeImage(node).get();
return [createDragImageForNode(*frame, *node).leakRef() autorelease];
}
- (NSArray *)textRects
......@@ -335,7 +335,7 @@ id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
if (!frame)
return nil;
return WebCore::rangeImage(frame, range, forceBlackText);
return [createDragImageForRange(*frame, *range, forceBlackText).leakRef() autorelease];
}
- (NSArray *)textRects
......
......@@ -277,10 +277,11 @@ DragImageRef Clipboard::createDragImage(IntPoint& location) const
if (m_dragImageElement) {
if (Frame* frame = m_dragImageElement->document().frame())
return frame->nodeImage(m_dragImageElement.get());
return createDragImageForNode(*frame, *m_dragImageElement);
}
return 0; // We do not have enough information to create a drag image, use the default icon.
// We do not have enough information to create a drag image, use the default icon.
return nullptr;
}
#endif
......
......@@ -28,7 +28,7 @@
#import "CachedImage.h"
#import "Element.h"
#import "FrameSnapshottingMac.h"
#import "DragImage.h"
namespace WebCore {
......@@ -37,16 +37,16 @@ namespace WebCore {
// Clipboard::dragImage in Clipboard.cpp does not handle correctly, so must resolve that as well.
DragImageRef Clipboard::createDragImage(IntPoint& location) const
{
NSImage *result = nil;
DragImageRef result = nil;
if (m_dragImageElement) {
if (Frame* frame = m_dragImageElement->document().frame()) {
NSRect imageRect;
NSRect elementRect;
result = snapshotDragImage(frame, m_dragImageElement.get(), &imageRect, &elementRect);
IntRect imageRect;
IntRect elementRect;
result = createDragImageForImage(*frame, *m_dragImageElement, imageRect, elementRect);
// Client specifies point relative to element, not the whole image, which may include child
// layers spread out all over the place.
location.setX(elementRect.origin.x - imageRect.origin.x + m_dragLocation.x());
location.setY(imageRect.size.height - (elementRect.origin.y - imageRect.origin.y + m_dragLocation.y()));
location.setX(elementRect.x() - imageRect.x() + m_dragLocation.x());
location.setY(imageRect.height() - (elementRect.y() - imageRect.y() + m_dragLocation.y()));
}
} else if (m_dragImage) {
result = m_dragImage->image()->getNSImage();
......
......@@ -37,6 +37,7 @@
#include "DragActions.h"
#include "DragClient.h"
#include "DragData.h"
#include "DragImage.h"
#include "DragSession.h"
#include "DragState.h"
#include "Editor.h"
......@@ -779,7 +780,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, DragOperation
}
m_client.willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard);
if (!dragImage) {
dragImage = dissolveDragImageToFraction(src.dragImageForSelection(), DragImageAlpha);
dragImage = dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha);
dragLoc = dragLocForSelectionDrag(src);
m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
}
......
......@@ -966,108 +966,4 @@ bool Frame::isURLAllowed(const URL& url) const
return true;
}
#if !PLATFORM(MAC) && !PLATFORM(WIN)
struct ScopedFramePaintingState {
ScopedFramePaintingState(Frame* frame, Node* node)
: frame(frame)
, node(node)
, paintBehavior(frame->view()->paintBehavior())
, backgroundColor(frame->view()->baseBackgroundColor())
{
ASSERT(!node || node->renderer());
if (node)
node->renderer()->updateDragState(true);
}
~ScopedFramePaintingState()
{
if (node && node->renderer())
node->renderer()->updateDragState(false);
frame->view()->setPaintBehavior(paintBehavior);
frame->view()->setBaseBackgroundColor(backgroundColor);
frame->view()->setNodeToDraw(0);
}
Frame* frame;
Node* node;
PaintBehavior paintBehavior;
Color backgroundColor;
};
DragImageRef Frame::nodeImage(Node* node)
{
if (!node->renderer())
return nullptr;
const ScopedFramePaintingState state(this, node);
m_view->setPaintBehavior(state.paintBehavior | PaintBehaviorFlattenCompositingLayers);
// When generating the drag image for an element, ignore the document background.
m_view->setBaseBackgroundColor(Color::transparent);
m_doc->updateLayout();
m_view->setNodeToDraw(node); // Enable special sub-tree drawing mode.
// Document::updateLayout may have blown away the original renderer.
auto renderer = node->renderer();
if (!renderer)
return nullptr;
LayoutRect topLevelRect;
IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));
float deviceScaleFactor = 1;
if (m_page)
deviceScaleFactor = m_page->deviceScaleFactor();
paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
std::unique_ptr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size(), deviceScaleFactor, ColorSpaceDeviceRGB));
if (!buffer)
return nullptr;
buffer->context()->translate(-paintingRect.x(), -paintingRect.y());
buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));
m_view->paintContents(buffer->context(), paintingRect);
RefPtr<Image> image = buffer->copyImage();
ImageOrientationDescription orientationDescription(renderer->shouldRespectImageOrientation());
#if ENABLE(CSS_IMAGE_ORIENTATION)
orientationDescription.setImageOrientationEnum(renderer->style().imageOrientation());
#endif
return createDragImageFromImage(image.get(), orientationDescription);
}
DragImageRef Frame::dragImageForSelection()
{
if (!selection().isRange())
return 0;
const ScopedFramePaintingState state(this, 0);
m_view->setPaintBehavior(PaintBehaviorSelectionOnly);
m_doc->updateLayout();
IntRect paintingRect = enclosingIntRect(selection().bounds());
float deviceScaleFactor = 1;
if (m_page)
deviceScaleFactor = m_page->deviceScaleFactor();
paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
std::unique_ptr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size(), deviceScaleFactor, ColorSpaceDeviceRGB));
if (!buffer)
return 0;
buffer->context()->translate(-paintingRect.x(), -paintingRect.y());
buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));
m_view->paintContents(buffer->context(), paintingRect);
RefPtr<Image> image = buffer->copyImage();
return createDragImageFromImage(image.get(), ImageOrientationDescription());
}
#endif
} // namespace WebCore
......@@ -29,7 +29,6 @@
#define Frame_h
#include "AdjustViewSizeOrNot.h"
#include "DragImage.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "IntRect.h"
......@@ -58,11 +57,13 @@ namespace WebCore {
class Editor;
class Element;
class EventHandler;
class FloatSize;
class FrameDestructionObserver;
class FrameSelection;
class FrameView;
class HTMLFrameOwnerElement;
class HTMLTableCellElement;
class ImageBuffer;
class IntRect;
class MainFrame;
class Node;
......@@ -177,9 +178,6 @@ namespace WebCore {
String displayStringModifiedByEncoding(const String&) const;
DragImageRef nodeImage(Node*);
DragImageRef dragImageForSelection();
VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
Document* documentAtPoint(const IntPoint& windowPoint);
PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
......
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2013 University of Washington.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "FrameSnapshotting.h"
#include "Document.h"
#include "Frame.h"
#include "FrameSelection.h"
#include "FrameView.h"
#include "ImageBuffer.h"
#include "Page.h"
#include "RenderObject.h"
namespace WebCore {
struct ScopedFramePaintingState {
ScopedFramePaintingState(Frame& frame, Node* node)
: frame(frame)
, node(node)
, paintBehavior(frame.view()->paintBehavior())
, backgroundColor(frame.view()->baseBackgroundColor())
{
ASSERT(!node || node->renderer());
}
~ScopedFramePaintingState()
{
frame.view()->setPaintBehavior(paintBehavior);
frame.view()->setBaseBackgroundColor(backgroundColor);
frame.view()->setNodeToDraw(nullptr);
}
const Frame& frame;
const Node* node;
const PaintBehavior paintBehavior;
const Color backgroundColor;
};
std::unique_ptr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions options)
{
if (!frame.page())
return nullptr;
frame.document()->updateLayout();
FrameView::SelectionInSnapshot shouldIncludeSelection = FrameView::IncludeSelection;
if (options & SnapshotOptionsExcludeSelectionHighlighting)
shouldIncludeSelection = FrameView::ExcludeSelection;
FrameView::CoordinateSpaceForSnapshot coordinateSpace = FrameView::DocumentCoordinates;
if (options & SnapshotOptionsInViewCoordinates)
coordinateSpace = FrameView::ViewCoordinates;
ScopedFramePaintingState state(frame, nullptr);
PaintBehavior paintBehavior = state.paintBehavior;
if (options & SnapshotOptionsForceBlackText)
paintBehavior |= PaintBehaviorForceBlackText;
if (options & SnapshotOptionsPaintSelectionOnly)
paintBehavior |= PaintBehaviorSelectionOnly;
// Other paint behaviors are set by paintContentsForSnapshot.
frame.view()->setPaintBehavior(paintBehavior);
float deviceScaleFactor = frame.page()->deviceScaleFactor();
IntRect usedRect(imageRect);
usedRect.scale(deviceScaleFactor);
std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(usedRect.size(), deviceScaleFactor, ColorSpaceDeviceRGB);
if (!buffer)
return nullptr;
buffer->context()->translate(-usedRect.x(), -usedRect.y());
buffer->context()->clip(FloatRect(0, 0, usedRect.maxX(), usedRect.maxY()));
frame.view()->paintContentsForSnapshot(buffer->context(), usedRect, shouldIncludeSelection, coordinateSpace);
return buffer;
}
std::unique_ptr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions options)
{
if (!frame.selection().isRange())
return nullptr;
options |= SnapshotOptionsPaintSelectionOnly;
return snapshotFrameRect(frame, enclosingIntRect(frame.selection().bounds()), options);
}
std::unique_ptr<ImageBuffer> snapshotNode(Frame& frame, Node& node)
{
if (!node.renderer())
return nullptr;
ScopedFramePaintingState state(frame, &node);
frame.view()->setBaseBackgroundColor(Color::transparent);
frame.view()->setNodeToDraw(&node);
LayoutRect topLevelRect;
return snapshotFrameRect(frame, pixelSnappedIntRect(node.renderer()->paintingRootRect(topLevelRect)));
}
} // namespace WebCore
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2013 University of Washington.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FrameSnapshotting_h
#define FrameSnapshotting_h
#include <memory>
namespace WebCore {
class Frame;
class IntRect;
class ImageBuffer;
class Node;
enum {
SnapshotOptionsNone = 0,
SnapshotOptionsExcludeSelectionHighlighting = 1 << 0,
SnapshotOptionsPaintSelectionOnly = 1 << 1,
SnapshotOptionsInViewCoordinates = 1 << 2,
SnapshotOptionsForceBlackText = 1 << 3,
};
typedef unsigned SnapshotOptions;
std::unique_ptr<ImageBuffer> snapshotFrameRect(Frame&, const IntRect&, SnapshotOptions = SnapshotOptionsNone);
std::unique_ptr<ImageBuffer> snapshotNode(Frame&, Node&);
std::unique_ptr<ImageBuffer> snapshotSelection(Frame&, SnapshotOptions = SnapshotOptionsNone);
} // namespace WebCore
#endif // FrameSnapshotting_h
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "Frame.h"
#import "Document.h"
#import "FrameLoaderClient.h"
#import "FrameSelection.h"
#import "FrameSnapshottingMac.h"
#import "FrameView.h"
#import "RenderObject.h"
namespace WebCore {
DragImageRef Frame::nodeImage(Node* node)
{
m_doc->updateLayout(); // forces style recalc
RenderObject* renderer = node->renderer();
if (!renderer)
return nil;
LayoutRect topLevelRect;
NSRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));
m_view->setNodeToDraw(node); // invoke special sub-tree drawing mode
NSImage* result = imageFromRect(this, paintingRect);
m_view->setNodeToDraw(0);
return result;
}
DragImageRef Frame::dragImageForSelection()
{
if (!selection().isRange())
return nil;
return selectionImage(this);
}
} // namespace WebCore
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FrameSnapshottingMac_h
#define FrameSnapshottingMac_h
OBJC_CLASS NSImage;
namespace WebCore {
class Frame;
class Range;
class Node;
NSImage* selectionImage(Frame*, bool forceBlackText = false);
NSImage* rangeImage(Frame*, Range*, bool forceBlackText = false);