Changeset 160152 in webkit
- Timestamp:
- Dec 4, 2013 7:08:40 PM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 2 added
- 3 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r160135 r160152 1733 1733 page/Frame.cpp 1734 1734 page/FrameDestructionObserver.cpp 1735 page/FrameSnapshotting.cpp 1735 1736 page/FrameTree.cpp 1736 1737 page/FrameView.cpp -
trunk/Source/WebCore/ChangeLog
r160147 r160152 1 2013-12-04 Brian J. Burg <burg@cs.washington.edu> 2 3 Consolidate various frame snapshot capabilities. 4 https://bugs.webkit.org/show_bug.cgi?id=124325 5 6 Reviewed by Darin Adler. 7 8 Various snapshot creation methods had duplicated code and were split 9 between Frame, DragImage, and platform-specific implementationss. 10 This patch puts WebCore snapshot methods into FrameSnapshotting 11 and removes platform implementations where possible. 12 13 DragImage methods reuse snapshot methods where possible. Inspector 14 will be able to take snapshots without using drag images. 15 16 No new tests, this is a refactoring. 17 18 * CMakeLists.txt: 19 * GNUmakefile.list.am: 20 * WebCore.exp.in: 21 * WebCore.vcxproj/WebCore.vcxproj: 22 * WebCore.vcxproj/WebCore.vcxproj.filters: 23 * WebCore.xcodeproj/project.pbxproj: 24 * bindings/objc/DOM.mm: 25 (-[DOMNode renderedImage]): 26 (-[DOMRange renderedImageForcingBlackText:]): 27 * dom/Clipboard.cpp: 28 (WebCore::Clipboard::createDragImage): 29 * dom/ClipboardMac.mm: 30 (WebCore::Clipboard::createDragImage): 31 * page/DragController.cpp: 32 (WebCore::DragController::startDrag): 33 * page/Frame.cpp: 34 * page/Frame.h: 35 * page/FrameSnapshotting.cpp: Added. 36 (WebCore::ScopedFramePaintingState::ScopedFramePaintingState): 37 (WebCore::ScopedFramePaintingState::~ScopedFramePaintingState): 38 (WebCore::snapshotFrameRect): Move most buffer logic to here. 39 (WebCore::snapshotSelection): Moved from Frame. 40 (WebCore::snapshotNode): Moved from Frame. 41 * page/FrameSnapshotting.h: Added. 42 * page/mac/FrameMac.mm: Removed. 43 * page/mac/FrameSnapshottingMac.h: Removed. 44 * page/mac/FrameSnapshottingMac.mm: Removed. 45 * page/win/FrameWin.cpp: remove duplicate implementation. 46 * page/win/FrameWin.h: Fix an incorrect parameter name. 47 * platform/DragImage.cpp: 48 (WebCore::ScopedNodeDragState::ScopedNodeDragState): 49 (WebCore::ScopedNodeDragState::~ScopedNodeDragState): 50 (WebCore::createDragImageFromSnapshot): Boilerplate buffer conversion. 51 (WebCore::createDragImageForNode): 52 (WebCore::createDragImageForSelection): 53 (WebCore::ScopedFrameSelectionState::ScopedFrameSelectionState): 54 (WebCore::ScopedFrameSelectionState::~ScopedFrameSelectionState): 55 (WebCore::createDragImageForRange): Moved from Frame. 56 (WebCore::createDragImageForImage): Moved from FrameSnapshottingMac. 57 (WebCore::createDragImageForLink): use nullptr. 58 1 59 2013-12-04 Benjamin Poulain <bpoulain@apple.com> 2 60 -
trunk/Source/WebCore/GNUmakefile.list.am
r160135 r160152 4132 4132 Source/WebCore/page/FrameDestructionObserver.cpp \ 4133 4133 Source/WebCore/page/FrameDestructionObserver.h \ 4134 Source/WebCore/page/FrameSnapshotting.cpp \ 4135 Source/WebCore/page/FrameSnapshotting.h \ 4134 4136 Source/WebCore/page/FrameTree.cpp \ 4135 4137 Source/WebCore/page/FrameTree.h \ -
trunk/Source/WebCore/WebCore.exp.in
r160099 r160152 429 429 __ZN7WebCore14encodeHostNameEP8NSString 430 430 __ZN7WebCore14endOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE 431 __ZN7WebCore14selectionImageEPNS_5FrameEb432 431 __ZN7WebCore14setMetadataURLERN3WTF6StringERKS1_S4_ 433 432 __ZN7WebCore15AffineTransform5flipYEv … … 891 890 __ZN7WebCore27DeviceOrientationClientMock14setOrientationEN3WTF10PassRefPtrINS_21DeviceOrientationDataEEE 892 891 __ZN7WebCore27DeviceOrientationClientMockC1Ev 892 __ZN7WebCore27createDragImageForSelectionERNS_5FrameEb 893 893 __ZN7WebCore27protocolHostAndPortAreEqualERKNS_3URLES2_ 894 894 __ZN7WebCore27startObservingCookieChangesEPFvvE … … 2036 2036 __ZN7WebCore42contextMenuItemTagCheckSpellingWhileTypingEv 2037 2037 __ZN7WebCore46contextMenuItemTagCorrectSpellingAutomaticallyEv 2038 __ZN7WebCore5Frame9nodeImageEPNS_4NodeE2039 2038 __ZN7WebCore6Cursor8fromTypeENS0_4TypeE 2040 2039 __ZN7WebCore6CursorC1EPNS_5ImageERKNS_8IntPointE -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r160135 r160152 6999 6999 <ClCompile Include="..\page\Frame.cpp" /> 7000 7000 <ClCompile Include="..\page\FrameDestructionObserver.cpp" /> 7001 <ClCompile Include="..\page\FrameSnapshotting.cpp" /> 7001 7002 <ClCompile Include="..\page\FrameTree.cpp" /> 7002 7003 <ClCompile Include="..\page\FrameView.cpp" /> … … 18855 18856 <ClInclude Include="..\page\Frame.h" /> 18856 18857 <ClInclude Include="..\page\FrameDestructionObserver.h" /> 18858 <ClInclude Include="..\page\FrameSnapshotting.h" /> 18857 18859 <ClInclude Include="..\page\FrameTree.h" /> 18858 18860 <ClInclude Include="..\page\FrameView.h" /> -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
r160102 r160152 721 721 <Filter>page</Filter> 722 722 </ClCompile> 723 <ClCompile Include="..\page\FrameSnapshotting.cpp"> 724 <Filter>page</Filter> 725 </ClCompile> 723 726 <ClCompile Include="..\page\FrameTree.cpp"> 724 727 <Filter>page</Filter> … … 7640 7643 </ClInclude> 7641 7644 <ClInclude Include="..\page\FrameDestructionObserver.h"> 7645 <Filter>page</Filter> 7646 </ClInclude> 7647 <ClInclude Include="..\page\FrameSnapshotting.h"> 7642 7648 <Filter>page</Filter> 7643 7649 </ClInclude> -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r160135 r160152 2014 2014 65BF022E0974816300C43196 /* Frame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65BF02290974816300C43196 /* Frame.cpp */; }; 2015 2015 65BF022F0974816300C43196 /* Frame.h in Headers */ = {isa = PBXBuildFile; fileRef = 65BF022A0974816300C43196 /* Frame.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2016 65BF02450974819000C43196 /* FrameMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65BF023C0974819000C43196 /* FrameMac.mm */; };2017 2016 65C97AF308EA908800ACD273 /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 65C97AF208EA908800ACD273 /* config.h */; }; 2018 2017 65CBFEF90974F607001DAC25 /* FrameView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65CBFEF70974F607001DAC25 /* FrameView.cpp */; }; … … 2219 2218 7C5343FD17B74B63004232F0 /* JSMediaQueryListListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C5343FB17B74B63004232F0 /* JSMediaQueryListListener.h */; }; 2220 2219 7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; }; 2221 7CE30DA9171B63D200EC33E1 /* FrameSnapshottingMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CE30DA7171B63D200EC33E1 /* FrameSnapshottingMac.mm */; };2222 7CE30DAA171B63D200EC33E1 /* FrameSnapshottingMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE30DA8171B63D200EC33E1 /* FrameSnapshottingMac.h */; settings = {ATTRIBUTES = (Private, ); }; };2223 2220 7D741BDA177226AA00859170 /* CSSValueKeywords.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 6565814809D13043000E61D7 /* CSSValueKeywords.h */; }; 2224 2221 7E12E90F15FA5D3A005E4126 /* CustomFilterMeshGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E12E90D15FA5D3A005E4126 /* CustomFilterMeshGenerator.h */; }; … … 5256 5253 C3CF17A615B0063F00276D39 /* IdTargetObserverRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C3CF17A215B0063F00276D39 /* IdTargetObserverRegistry.cpp */; }; 5257 5254 C3CF17A715B0063F00276D39 /* IdTargetObserverRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C3CF17A315B0063F00276D39 /* IdTargetObserverRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; }; 5255 C4CD629A18383766007EBAF1 /* FrameSnapshotting.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C4CD629818383766007EBAF1 /* FrameSnapshotting.cpp */; }; 5256 C4CD629B18383766007EBAF1 /* FrameSnapshotting.h in Headers */ = {isa = PBXBuildFile; fileRef = C4CD629918383766007EBAF1 /* FrameSnapshotting.h */; settings = {ATTRIBUTES = (Private, ); }; }; 5258 5257 C50B561612119D23008B46E0 /* GroupSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50B561412119D23008B46E0 /* GroupSettings.cpp */; }; 5259 5258 C50B561712119D23008B46E0 /* GroupSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = C50B561512119D23008B46E0 /* GroupSettings.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 8782 8781 65BF02290974816300C43196 /* Frame.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Frame.cpp; sourceTree = "<group>"; }; 8783 8782 65BF022A0974816300C43196 /* Frame.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Frame.h; sourceTree = "<group>"; }; 8784 65BF023C0974819000C43196 /* FrameMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameMac.mm; sourceTree = "<group>"; };8785 8783 65C97AF208EA908800ACD273 /* config.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; }; 8786 8784 65CBFEF70974F607001DAC25 /* FrameView.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FrameView.cpp; sourceTree = "<group>"; }; … … 9014 9012 7C6136F91710C35200FF4A57 /* StaticString.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = StaticString.pm; path = scripts/StaticString.pm; sourceTree = "<group>"; }; 9015 9013 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDNScriptWhiteList.txt; sourceTree = "<group>"; }; 9016 7CE30DA7171B63D200EC33E1 /* FrameSnapshottingMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameSnapshottingMac.mm; sourceTree = "<group>"; };9017 7CE30DA8171B63D200EC33E1 /* FrameSnapshottingMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FrameSnapshottingMac.h; sourceTree = "<group>"; };9018 9014 7E12E90D15FA5D3A005E4126 /* CustomFilterMeshGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterMeshGenerator.h; path = filters/CustomFilterMeshGenerator.h; sourceTree = "<group>"; }; 9019 9015 7E12E90E15FA5D3A005E4126 /* CustomFilterMeshGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomFilterMeshGenerator.cpp; path = filters/CustomFilterMeshGenerator.cpp; sourceTree = "<group>"; }; … … 12322 12318 C3CF17A215B0063F00276D39 /* IdTargetObserverRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IdTargetObserverRegistry.cpp; sourceTree = "<group>"; }; 12323 12319 C3CF17A315B0063F00276D39 /* IdTargetObserverRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdTargetObserverRegistry.h; sourceTree = "<group>"; }; 12320 C4CD629818383766007EBAF1 /* FrameSnapshotting.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FrameSnapshotting.cpp; sourceTree = "<group>"; }; 12321 C4CD629918383766007EBAF1 /* FrameSnapshotting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FrameSnapshotting.h; sourceTree = "<group>"; }; 12324 12322 C50B561412119D23008B46E0 /* GroupSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GroupSettings.cpp; sourceTree = "<group>"; }; 12325 12323 C50B561512119D23008B46E0 /* GroupSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupSettings.h; sourceTree = "<group>"; }; … … 15696 15694 974A862014B7ADBB003FDC76 /* FrameDestructionObserver.cpp */, 15697 15695 974A862114B7ADBB003FDC76 /* FrameDestructionObserver.h */, 15696 C4CD629818383766007EBAF1 /* FrameSnapshotting.cpp */, 15697 C4CD629918383766007EBAF1 /* FrameSnapshotting.h */, 15698 15698 65A21482097A3F5300B9050A /* FrameTree.cpp */, 15699 15699 65A21483097A3F5300B9050A /* FrameTree.h */, … … 16612 16612 A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */, 16613 16613 93C09A7E0B064EEF005ABD4D /* EventHandlerMac.mm */, 16614 65BF023C0974819000C43196 /* FrameMac.mm */,16615 7CE30DA8171B63D200EC33E1 /* FrameSnapshottingMac.h */,16616 7CE30DA7171B63D200EC33E1 /* FrameSnapshottingMac.mm */,16617 16614 1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */, 16618 16615 E1C2F2481533A2120083F974 /* SettingsMac.mm */, … … 22234 22231 1A569CFA0D7E2B82007C3983 /* c_instance.h in Headers */, 22235 22232 1A569CFC0D7E2B82007C3983 /* c_runtime.h in Headers */, 22233 C4CD629B18383766007EBAF1 /* FrameSnapshotting.h in Headers */, 22236 22234 1A569CFE0D7E2B82007C3983 /* c_utility.h in Headers */, 22237 22235 BCB16C1A0979C3BD00467741 /* CachedCSSStyleSheet.h in Headers */, … … 23096 23094 E172AF70180F289500FBADB9 /* CryptoKeyUsage.h in Headers */, 23097 23095 93309E0E099E64920056E581 /* FrameSelection.h in Headers */, 23098 7CE30DAA171B63D200EC33E1 /* FrameSnapshottingMac.h in Headers */,23099 23096 65A21485097A3F5300B9050A /* FrameTree.h in Headers */, 23100 23097 65CBFEFA0974F607001DAC25 /* FrameView.h in Headers */, … … 26386 26383 D000EBA211BDAFD400C47726 /* FrameLoaderStateMachine.cpp in Sources */, 26387 26384 86BA766E166427A8005BE5D1 /* FrameLoadRequest.cpp in Sources */, 26388 65BF02450974819000C43196 /* FrameMac.mm in Sources */,26389 26385 93309E0D099E64920056E581 /* FrameSelection.cpp in Sources */, 26390 26386 4A8C96EB0BE69032004EEFF0 /* FrameSelectionMac.mm in Sources */, 26391 7CE30DA9171B63D200EC33E1 /* FrameSnapshottingMac.mm in Sources */,26392 26387 07969DAD17D14151007FF842 /* JSRTCDataChannelEvent.cpp in Sources */, 26393 26388 65A21484097A3F5300B9050A /* FrameTree.cpp in Sources */, … … 27901 27896 07277E5217D018CC0015534D /* JSMediaStreamTrack.cpp in Sources */, 27902 27897 C50D0E820FF4272900AC2644 /* StorageNamespace.cpp in Sources */, 27898 C4CD629A18383766007EBAF1 /* FrameSnapshotting.cpp in Sources */, 27903 27899 C55E38C010040D5D00A56BDB /* StorageNamespaceImpl.cpp in Sources */, 27904 27900 1AB09DB416AF5F6C008538E7 /* StorageStrategy.cpp in Sources */, -
trunk/Source/WebCore/bindings/objc/DOM.mm
r159487 r160152 37 37 #import "DOMPrivate.h" 38 38 #import "DOMRangeInternal.h" 39 #import "DragImage.h" 39 40 #import "Font.h" 40 41 #import "Frame.h" 41 #import "FrameSnapshottingMac.h"42 42 #import "HTMLElement.h" 43 43 #import "HTMLNames.h" … … 290 290 if (!frame) 291 291 return nil; 292 return frame->nodeImage(node).get();292 return [createDragImageForNode(*frame, *node).leakRef() autorelease]; 293 293 } 294 294 … … 336 336 return nil; 337 337 338 return WebCore::rangeImage(frame, range, forceBlackText);338 return [createDragImageForRange(*frame, *range, forceBlackText).leakRef() autorelease]; 339 339 } 340 340 -
trunk/Source/WebCore/dom/Clipboard.cpp
r159487 r160152 278 278 if (m_dragImageElement) { 279 279 if (Frame* frame = m_dragImageElement->document().frame()) 280 return frame->nodeImage(m_dragImageElement.get());280 return createDragImageForNode(*frame, *m_dragImageElement); 281 281 } 282 282 283 return 0; // We do not have enough information to create a drag image, use the default icon. 283 // We do not have enough information to create a drag image, use the default icon. 284 return nullptr; 284 285 } 285 286 -
trunk/Source/WebCore/dom/ClipboardMac.mm
r159487 r160152 29 29 #import "CachedImage.h" 30 30 #import "Element.h" 31 #import " FrameSnapshottingMac.h"31 #import "DragImage.h" 32 32 33 33 namespace WebCore { … … 38 38 DragImageRef Clipboard::createDragImage(IntPoint& location) const 39 39 { 40 NSImage *result = nil;40 DragImageRef result = nil; 41 41 if (m_dragImageElement) { 42 42 if (Frame* frame = m_dragImageElement->document().frame()) { 43 NSRect imageRect;44 NSRect elementRect;45 result = snapshotDragImage(frame, m_dragImageElement.get(), &imageRect, &elementRect);43 IntRect imageRect; 44 IntRect elementRect; 45 result = createDragImageForImage(*frame, *m_dragImageElement, imageRect, elementRect); 46 46 // Client specifies point relative to element, not the whole image, which may include child 47 47 // layers spread out all over the place. 48 location.setX(elementRect. origin.x - imageRect.origin.x+ m_dragLocation.x());49 location.setY(imageRect. size.height - (elementRect.origin.y - imageRect.origin.y+ m_dragLocation.y()));48 location.setX(elementRect.x() - imageRect.x() + m_dragLocation.x()); 49 location.setY(imageRect.height() - (elementRect.y() - imageRect.y() + m_dragLocation.y())); 50 50 } 51 51 } else if (m_dragImage) { -
trunk/Source/WebCore/page/DragController.cpp
r159856 r160152 38 38 #include "DragClient.h" 39 39 #include "DragData.h" 40 #include "DragImage.h" 40 41 #include "DragSession.h" 41 42 #include "DragState.h" … … 780 781 m_client.willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard); 781 782 if (!dragImage) { 782 dragImage = dissolveDragImageToFraction( src.dragImageForSelection(), DragImageAlpha);783 dragImage = dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha); 783 784 dragLoc = dragLocForSelectionDrag(src); 784 785 m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y()); -
trunk/Source/WebCore/page/Frame.cpp
r159856 r160152 967 967 } 968 968 969 #if !PLATFORM(MAC) && !PLATFORM(WIN)970 struct ScopedFramePaintingState {971 ScopedFramePaintingState(Frame* frame, Node* node)972 : frame(frame)973 , node(node)974 , paintBehavior(frame->view()->paintBehavior())975 , backgroundColor(frame->view()->baseBackgroundColor())976 {977 ASSERT(!node || node->renderer());978 if (node)979 node->renderer()->updateDragState(true);980 }981 982 ~ScopedFramePaintingState()983 {984 if (node && node->renderer())985 node->renderer()->updateDragState(false);986 frame->view()->setPaintBehavior(paintBehavior);987 frame->view()->setBaseBackgroundColor(backgroundColor);988 frame->view()->setNodeToDraw(0);989 }990 991 Frame* frame;992 Node* node;993 PaintBehavior paintBehavior;994 Color backgroundColor;995 };996 997 DragImageRef Frame::nodeImage(Node* node)998 {999 if (!node->renderer())1000 return nullptr;1001 1002 const ScopedFramePaintingState state(this, node);1003 1004 m_view->setPaintBehavior(state.paintBehavior | PaintBehaviorFlattenCompositingLayers);1005 1006 // When generating the drag image for an element, ignore the document background.1007 m_view->setBaseBackgroundColor(Color::transparent);1008 m_doc->updateLayout();1009 m_view->setNodeToDraw(node); // Enable special sub-tree drawing mode.1010 1011 // Document::updateLayout may have blown away the original renderer.1012 auto renderer = node->renderer();1013 if (!renderer)1014 return nullptr;1015 1016 LayoutRect topLevelRect;1017 IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));1018 1019 float deviceScaleFactor = 1;1020 if (m_page)1021 deviceScaleFactor = m_page->deviceScaleFactor();1022 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);1023 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);1024 1025 std::unique_ptr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size(), deviceScaleFactor, ColorSpaceDeviceRGB));1026 if (!buffer)1027 return nullptr;1028 buffer->context()->translate(-paintingRect.x(), -paintingRect.y());1029 buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));1030 1031 m_view->paintContents(buffer->context(), paintingRect);1032 1033 RefPtr<Image> image = buffer->copyImage();1034 1035 ImageOrientationDescription orientationDescription(renderer->shouldRespectImageOrientation());1036 #if ENABLE(CSS_IMAGE_ORIENTATION)1037 orientationDescription.setImageOrientationEnum(renderer->style().imageOrientation());1038 #endif1039 return createDragImageFromImage(image.get(), orientationDescription);1040 }1041 1042 DragImageRef Frame::dragImageForSelection()1043 {1044 if (!selection().isRange())1045 return 0;1046 1047 const ScopedFramePaintingState state(this, 0);1048 m_view->setPaintBehavior(PaintBehaviorSelectionOnly);1049 m_doc->updateLayout();1050 1051 IntRect paintingRect = enclosingIntRect(selection().bounds());1052 1053 float deviceScaleFactor = 1;1054 if (m_page)1055 deviceScaleFactor = m_page->deviceScaleFactor();1056 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);1057 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);1058 1059 std::unique_ptr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size(), deviceScaleFactor, ColorSpaceDeviceRGB));1060 if (!buffer)1061 return 0;1062 buffer->context()->translate(-paintingRect.x(), -paintingRect.y());1063 buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));1064 1065 m_view->paintContents(buffer->context(), paintingRect);1066 1067 RefPtr<Image> image = buffer->copyImage();1068 return createDragImageFromImage(image.get(), ImageOrientationDescription());1069 }1070 1071 #endif1072 1073 969 } // namespace WebCore -
trunk/Source/WebCore/page/Frame.h
r159487 r160152 30 30 31 31 #include "AdjustViewSizeOrNot.h" 32 #include "DragImage.h"33 32 #include "FrameLoader.h" 34 33 #include "FrameTree.h" … … 59 58 class Element; 60 59 class EventHandler; 60 class FloatSize; 61 61 class FrameDestructionObserver; 62 62 class FrameSelection; … … 64 64 class HTMLFrameOwnerElement; 65 65 class HTMLTableCellElement; 66 class ImageBuffer; 66 67 class IntRect; 67 68 class MainFrame; … … 178 179 String displayStringModifiedByEncoding(const String&) const; 179 180 180 DragImageRef nodeImage(Node*);181 DragImageRef dragImageForSelection();182 183 181 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint); 184 182 Document* documentAtPoint(const IntPoint& windowPoint); -
trunk/Source/WebCore/page/win/FrameWin.cpp
r159487 r160152 58 58 } 59 59 60 DragImageRef Frame::dragImageForSelection()61 {62 if (selection().isRange())63 return imageFromSelection(this, false).leak();64 65 return 0;66 }67 68 DragImageRef Frame::nodeImage(Node* node)69 {70 document()->updateLayout();71 72 RenderObject* renderer = node->renderer();73 if (!renderer)74 return 0;75 76 LayoutRect topLevelRect;77 IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));78 79 m_view->setNodeToDraw(node); // invoke special sub-tree drawing mode80 GDIObject<HBITMAP> result = imageFromRect(this, paintingRect);81 m_view->setNodeToDraw(0);82 83 return result.leak();84 }85 86 60 } // namespace WebCore -
trunk/Source/WebCore/page/win/FrameWin.h
r159487 r160152 36 36 37 37 GDIObject<HBITMAP> imageFromRect(const Frame*, IntRect&); 38 GDIObject<HBITMAP> imageFromSelection(Frame*, bool force WhiteText);38 GDIObject<HBITMAP> imageFromSelection(Frame*, bool forceBlackText); 39 39 void computePageRectsForFrame(Frame*, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, Vector<IntRect>& outPages, int& outPageHeight); 40 40 -
trunk/Source/WebCore/platform/DragImage.cpp
r159487 r160152 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 … … 29 29 #if ENABLE(DRAG_SUPPORT) 30 30 31 #include "Frame.h" 32 #include "FrameSnapshotting.h" 33 #include "FrameView.h" 34 #include "ImageBuffer.h" 35 #include "Range.h" 36 #include "RenderObject.h" 37 #include "RenderView.h" 38 31 39 namespace WebCore { 32 40 33 41 DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& srcSize, const IntSize& size) 34 42 { … … 37 45 float resizeRatio = -1.0f; 38 46 IntSize originalSize = dragImageSize(image); 39 47 40 48 if (srcSize.width() > size.width()) { 41 49 widthResizeRatio = size.width() / (float)srcSize.width(); 42 50 resizeRatio = widthResizeRatio; 43 51 } 44 52 45 53 if (srcSize.height() > size.height()) { 46 54 heightResizeRatio = size.height() / (float)srcSize.height(); … … 48 56 resizeRatio = heightResizeRatio; 49 57 } 50 58 51 59 if (srcSize == originalSize) 52 60 return resizeRatio > 0.0f ? scaleDragImage(image, FloatSize(resizeRatio, resizeRatio)) : image; 53 61 54 62 // The image was scaled in the webpage so at minimum we must account for that scaling 55 63 float scalex = srcSize.width() / (float)originalSize.width(); … … 59 67 scaley *= resizeRatio; 60 68 } 61 69 62 70 return scaleDragImage(image, FloatSize(scalex, scaley)); 71 } 72 73 struct ScopedNodeDragEnabler { 74 ScopedNodeDragEnabler(Frame& frame, Node& node) 75 : frame(frame) 76 , node(node) 77 { 78 if (node.renderer()) 79 node.renderer()->updateDragState(true); 80 frame.document()->updateLayout(); 81 } 82 83 ~ScopedNodeDragEnabler() 84 { 85 if (node.renderer()) 86 node.renderer()->updateDragState(false); 87 } 88 89 const Frame& frame; 90 const Node& node; 91 }; 92 93 static DragImageRef createDragImageFromSnapshot(std::unique_ptr<ImageBuffer> snapshot, Node* node) 94 { 95 if (!snapshot) 96 return nullptr; 97 98 ImageOrientationDescription orientation; 99 #if ENABLE(CSS_IMAGE_ORIENTATION) 100 if (node) { 101 RenderObject* renderer = node->renderer(); 102 if (!renderer) 103 return nullptr; 104 105 orientation.setRespectImageOrientation(renderer->shouldRespectImageOrientation()); 106 orientation.setImageOrientationEnum(renderer->style().imageOrientation()); 107 } 108 #else 109 UNUSED_PARAM(node); 110 #endif 111 RefPtr<Image> image = snapshot->copyImage(ImageBuffer::fastCopyImageMode()); 112 if (!image) 113 return nullptr; 114 return createDragImageFromImage(image.get(), orientation); 115 } 116 117 DragImageRef createDragImageForNode(Frame& frame, Node& node) 118 { 119 ScopedNodeDragEnabler enableDrag(frame, node); 120 return createDragImageFromSnapshot(snapshotNode(frame, node), &node); 121 } 122 123 DragImageRef createDragImageForSelection(Frame& frame, bool forceBlackText) 124 { 125 SnapshotOptions options = forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone; 126 return createDragImageFromSnapshot(snapshotSelection(frame, options), nullptr); 127 } 128 129 struct ScopedFrameSelectionState { 130 ScopedFrameSelectionState(Frame& frame) 131 : frame(frame) 132 { 133 if (RenderView* root = frame.contentRenderer()) 134 root->getSelection(startRenderer, startOffset, endRenderer, endOffset); 135 } 136 137 ~ScopedFrameSelectionState() 138 { 139 if (RenderView* root = frame.contentRenderer()) 140 root->setSelection(startRenderer, startOffset, endRenderer, endOffset, RenderView::RepaintNothing); 141 } 142 143 const Frame& frame; 144 RenderObject* startRenderer; 145 RenderObject* endRenderer; 146 int startOffset; 147 int endOffset; 148 }; 149 150 DragImageRef createDragImageForRange(Frame& frame, Range& range, bool forceBlackText) 151 { 152 frame.document()->updateLayout(); 153 RenderView* view = frame.contentRenderer(); 154 if (!view) 155 return nullptr; 156 157 // To snapshot the range, temporarily select it and take selection snapshot. 158 Position start = range.startPosition(); 159 Position candidate = start.downstream(); 160 if (candidate.deprecatedNode() && candidate.deprecatedNode()->renderer()) 161 start = candidate; 162 163 Position end = range.endPosition(); 164 candidate = end.upstream(); 165 if (candidate.deprecatedNode() && candidate.deprecatedNode()->renderer()) 166 end = candidate; 167 168 if (start.isNull() || end.isNull() || start == end) 169 return nullptr; 170 171 const ScopedFrameSelectionState selectionState(frame); 172 173 RenderObject* startRenderer = start.deprecatedNode()->renderer(); 174 RenderObject* endRenderer = end.deprecatedNode()->renderer(); 175 if (!startRenderer || !endRenderer) 176 return nullptr; 177 178 SnapshotOptions options = SnapshotOptionsPaintSelectionOnly | (forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone); 179 view->setSelection(startRenderer, start.deprecatedEditingOffset(), endRenderer, end.deprecatedEditingOffset(), RenderView::RepaintNothing); 180 // We capture using snapshotFrameRect() because we fake up the selection using 181 // FrameView but snapshotSelection() uses the selection from the Frame itself. 182 return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selectionBounds(), options), nullptr); 183 } 184 185 DragImageRef createDragImageForImage(Frame& frame, Node& node, IntRect& imageRect, IntRect& elementRect) 186 { 187 ScopedNodeDragEnabler enableDrag(frame, node); 188 189 RenderObject* renderer = node.renderer(); 190 if (!renderer) 191 return nullptr; 192 193 // Calculate image and element metrics for the client, then create drag image. 194 LayoutRect topLevelRect; 195 IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect)); 196 197 if (paintingRect.isEmpty()) 198 return nullptr; 199 200 elementRect = pixelSnappedIntRect(topLevelRect); 201 imageRect = paintingRect; 202 203 return createDragImageFromSnapshot(snapshotNode(frame, node), &node); 63 204 } 64 205 … … 66 207 DragImageRef createDragImageForLink(URL&, const String&, FontRenderingMode) 67 208 { 68 return 0;209 return nullptr; 69 210 } 70 211 #endif -
trunk/Source/WebCore/platform/DragImage.h
r159487 r160152 27 27 #define DragImage_h 28 28 29 #include "FloatSize.h" 29 30 #include "FontRenderingMode.h" 31 #include "FrameSnapshotting.h" 30 32 #include "ImageOrientation.h" 31 33 #include "IntSize.h" 32 #include "FloatSize.h"33 34 #include <wtf/Forward.h> 34 35 … … 42 43 #endif 43 44 44 // We need to #define YOffset as it needs to be shared with WebKit45 // We need to #define YOffset as it needs to be shared with WebKit 45 46 #define DragLabelBorderYOffset 2 46 47 47 48 namespace WebCore { 48 49 49 class Image; 50 class URL; 50 class Frame; 51 class Image; 52 class IntRect; 53 class Node; 54 class Range; 55 class URL; 51 56 52 57 #if PLATFORM(MAC) 53 58 typedef RetainPtr<NSImage> DragImageRef; 54 59 #elif PLATFORM(WIN) 55 60 typedef HBITMAP DragImageRef; 56 61 #elif PLATFORM(GTK) || PLATFORM(NIX) 57 62 typedef cairo_surface_t* DragImageRef; 58 63 #elif PLATFORM(EFL) || PLATFORM(BLACKBERRY) 59 64 typedef void* DragImageRef; 60 65 #endif 61 62 IntSize dragImageSize(DragImageRef); 63 64 //These functions should be memory neutral, eg. if they return a newly allocated image, 65 //they should release the input image. As a corollary these methods don't guarantee 66 //the input image ref will still be valid after they have been called 67 DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& srcSize, const IntSize& size); 68 DragImageRef scaleDragImage(DragImageRef, FloatSize scale); 69 DragImageRef dissolveDragImageToFraction(DragImageRef image, float delta); 70 71 DragImageRef createDragImageFromImage(Image*, ImageOrientationDescription); 72 DragImageRef createDragImageIconForCachedImageFilename(const String&); 73 DragImageRef createDragImageForLink(URL&, const String& label, FontRenderingMode); 74 void deleteDragImage(DragImageRef); 66 67 IntSize dragImageSize(DragImageRef); 68 69 // These functions should be memory neutral, eg. if they return a newly allocated image, 70 // they should release the input image. As a corollary these methods don't guarantee 71 // the input image ref will still be valid after they have been called. 72 DragImageRef fitDragImageToMaxSize(DragImageRef, const IntSize& srcSize, const IntSize& dstSize); 73 DragImageRef scaleDragImage(DragImageRef, FloatSize scale); 74 DragImageRef dissolveDragImageToFraction(DragImageRef, float delta); 75 76 DragImageRef createDragImageFromImage(Image*, ImageOrientationDescription); 77 DragImageRef createDragImageIconForCachedImageFilename(const String&); 78 79 DragImageRef createDragImageForNode(Frame&, Node&); 80 DragImageRef createDragImageForSelection(Frame&, bool forceBlackText = false); 81 DragImageRef createDragImageForRange(Frame&, Range&, bool forceBlackText = false); 82 DragImageRef createDragImageForImage(Frame&, Node&, IntRect& imageRect, IntRect& elementRect); 83 DragImageRef createDragImageForLink(URL&, const String& label, FontRenderingMode); 84 void deleteDragImage(DragImageRef); 75 85 } 76 86 77 78 #endif //!DragImage_h 87 #endif // DragImage_h -
trunk/Source/WebKit/ios/ChangeLog
r160106 r160152 1 2013-12-04 Brian J. Burg <burg@cs.washington.edu> 2 3 Consolidate various frame snapshot capabilities. 4 https://bugs.webkit.org/show_bug.cgi?id=124325 5 6 Reviewed by Darin Adler. 7 8 * WebCoreSupport/WebFrameIOS.mm: use new header file. 9 1 10 2013-12-04 Andy Estes <aestes@apple.com> 2 11 -
trunk/Source/WebKit/ios/WebCoreSupport/WebFrameIOS.mm
r160106 r160152 34 34 #import <WebCore/Frame.h> 35 35 #import <WebCore/FrameSelection.h> 36 #import <WebCore/FrameSnapshotting Mac.h>36 #import <WebCore/FrameSnapshotting.h> 37 37 #import <WebCore/FrameView.h> 38 38 #import <WebCore/HitTestResult.h> -
trunk/Source/WebKit/mac/ChangeLog
r160111 r160152 1 2013-12-04 Brian J. Burg <burg@cs.washington.edu> 2 3 Consolidate various frame snapshot capabilities. 4 https://bugs.webkit.org/show_bug.cgi?id=124325 5 6 Reviewed by Darin Adler. 7 8 Use new platform-independent methods instead of Mac methods. 9 10 * WebView/WebHTMLView.mm: 11 (-[WebHTMLView _selectionDraggingImage]): 12 (-[WebHTMLView selectionImageForcingBlackText:]): 13 1 14 2013-12-04 Andy Estes <aestes@apple.com> 2 15 -
trunk/Source/WebKit/mac/WebView/WebHTMLView.mm
r159856 r160152 86 86 #import <WebCore/DocumentMarkerController.h> 87 87 #import <WebCore/DragController.h> 88 #import <WebCore/DragImage.h> 88 89 #import <WebCore/Editor.h> 89 90 #import <WebCore/EditorDeleteAction.h> … … 96 97 #import <WebCore/FrameLoader.h> 97 98 #import <WebCore/FrameSelection.h> 98 #import <WebCore/FrameSnapshottingMac.h>99 99 #import <WebCore/FrameView.h> 100 100 #import <WebCore/HTMLConverter.h> … … 1821 1821 if (![self _hasSelection]) 1822 1822 return nil; 1823 NSImage *dragImage = selectionImage(core([self _frame])); 1823 1824 Frame* coreFrame = core([self _frame]); 1825 if (!coreFrame) 1826 return nil; 1827 1828 NSImage *dragImage = [createDragImageForSelection(*coreFrame).leakRef() autorelease]; 1824 1829 [dragImage _web_dissolveToFraction:WebDragImageAlpha]; 1825 1830 return dragImage; … … 5966 5971 if (![self _hasSelection]) 5967 5972 return nil; 5968 return selectionImage(core([self _frame]), forceBlackText); 5973 5974 Frame* coreFrame = core([self _frame]); 5975 if (!coreFrame) 5976 return nil; 5977 return [createDragImageForSelection(*coreFrame, forceBlackText).leakRef() autorelease]; 5969 5978 } 5970 5979 -
trunk/Source/WebKit/win/ChangeLog
r160099 r160152 1 2013-12-04 Brian J. Burg <burg@cs.washington.edu> 2 3 Consolidate various frame snapshot capabilities. 4 https://bugs.webkit.org/show_bug.cgi?id=124325 5 6 Reviewed by Darin Adler. 7 8 * DOMCoreClasses.cpp: 9 (DOMElement::renderedImage): use createDragImageForNode. 10 1 11 2013-12-03 Joseph Pecoraro <pecoraro@apple.com> 2 12 -
trunk/Source/WebKit/win/DOMCoreClasses.cpp
r159487 r160152 37 37 #include <WebCore/DOMWindow.h> 38 38 #include <WebCore/Document.h> 39 #include <WebCore/DragImage.h> 39 40 #include <WebCore/Element.h> 40 41 #include <WebCore/Font.h> 41 42 #include <WebCore/Frame.h> 42 #include <WebCore/SimpleFontData.h>43 43 #include <WebCore/HTMLFormElement.h> 44 44 #include <WebCore/HTMLInputElement.h> … … 50 50 #include <WebCore/RenderElement.h> 51 51 #include <WebCore/RenderTreeAsText.h> 52 #include <WebCore/SimpleFontData.h> 52 53 53 54 #include <initguid.h> … … 1280 1281 return E_FAIL; 1281 1282 1282 *image = frame->nodeImage(m_element);1283 *image = createDragImageForNode(*frame, *m_element); 1283 1284 if (!*image) 1284 1285 return E_FAIL;
Note: See TracChangeset
for help on using the changeset viewer.