| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> | 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> |
| 3 * 1999 Lars Knoll <knoll@kde.org> | 3 * 1999 Lars Knoll <knoll@kde.org> |
| 4 * 1999 Antti Koivisto <koivisto@kde.org> | 4 * 1999 Antti Koivisto <koivisto@kde.org> |
| 5 * 2000 Simon Hausmann <hausmann@kde.org> | 5 * 2000 Simon Hausmann <hausmann@kde.org> |
| 6 * 2000 Stefan Schimanski <1Stein@gmx.de> | 6 * 2000 Stefan Schimanski <1Stein@gmx.de> |
| 7 * 2001 George Staikos <staikos@kde.org> | 7 * 2001 George Staikos <staikos@kde.org> |
| 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> | 9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> |
| 10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "core/inspector/InstrumentingAgents.h" | 53 #include "core/inspector/InstrumentingAgents.h" |
| 54 #include "core/layout/HitTestResult.h" | 54 #include "core/layout/HitTestResult.h" |
| 55 #include "core/layout/LayoutView.h" | 55 #include "core/layout/LayoutView.h" |
| 56 #include "core/layout/compositing/PaintLayerCompositor.h" | 56 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 57 #include "core/loader/FrameLoadRequest.h" | 57 #include "core/loader/FrameLoadRequest.h" |
| 58 #include "core/loader/FrameLoaderClient.h" | 58 #include "core/loader/FrameLoaderClient.h" |
| 59 #include "core/loader/NavigationScheduler.h" | 59 #include "core/loader/NavigationScheduler.h" |
| 60 #include "core/page/FocusController.h" | 60 #include "core/page/FocusController.h" |
| 61 #include "core/page/Page.h" | 61 #include "core/page/Page.h" |
| 62 #include "core/page/scrolling/ScrollingCoordinator.h" | 62 #include "core/page/scrolling/ScrollingCoordinator.h" |
| 63 #include "core/paint/ObjectPainter.h" | |
| 64 #include "core/paint/PaintInfo.h" | |
| 65 #include "core/paint/PaintLayer.h" | 63 #include "core/paint/PaintLayer.h" |
| 66 #include "core/paint/TransformRecorder.h" | 64 #include "core/paint/TransformRecorder.h" |
| 67 #include "core/svg/SVGDocumentExtensions.h" | 65 #include "core/svg/SVGDocumentExtensions.h" |
| 68 #include "platform/DragImage.h" | 66 #include "platform/DragImage.h" |
| 69 #include "platform/PluginScriptForbiddenScope.h" | 67 #include "platform/PluginScriptForbiddenScope.h" |
| 70 #include "platform/RuntimeEnabledFeatures.h" | 68 #include "platform/RuntimeEnabledFeatures.h" |
| 71 #include "platform/ScriptForbiddenScope.h" | 69 #include "platform/ScriptForbiddenScope.h" |
| 72 #include "platform/graphics/GraphicsContext.h" | 70 #include "platform/graphics/GraphicsContext.h" |
| 73 #include "platform/graphics/StaticBitmapImage.h" | 71 #include "platform/graphics/StaticBitmapImage.h" |
| 74 #include "platform/graphics/paint/ClipRecorder.h" | 72 #include "platform/graphics/paint/ClipRecorder.h" |
| 75 #include "platform/graphics/paint/SkPictureBuilder.h" | 73 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 76 #include "platform/graphics/paint/TransformDisplayItem.h" | |
| 77 #include "platform/text/TextStream.h" | 74 #include "platform/text/TextStream.h" |
| 78 #include "public/platform/WebFrameScheduler.h" | 75 #include "public/platform/WebFrameScheduler.h" |
| 79 #include "public/platform/WebSecurityOrigin.h" | 76 #include "public/platform/WebSecurityOrigin.h" |
| 80 #include "public/platform/WebViewScheduler.h" | 77 #include "public/platform/WebViewScheduler.h" |
| 81 #include "third_party/skia/include/core/SkImage.h" | 78 #include "third_party/skia/include/core/SkImage.h" |
| 82 #include "wtf/PassOwnPtr.h" | 79 #include "wtf/PassOwnPtr.h" |
| 83 #include "wtf/StdLibExtras.h" | 80 #include "wtf/StdLibExtras.h" |
| 84 | 81 |
| 85 namespace blink { | 82 namespace blink { |
| 86 | 83 |
| 87 using namespace HTMLNames; | 84 using namespace HTMLNames; |
| 88 | 85 |
| 89 namespace { | 86 namespace { |
| 90 | 87 |
| 91 // Convenience class for initializing a GraphicsContext to build a DragImage fro
m a specific | 88 struct ScopedFramePaintingState { |
| 92 // region specified by |bounds|. After painting the using context(), the DragIma
ge returned from | |
| 93 // createImage() will only contain the content in |bounds| with the appropriate
device scale | |
| 94 // factor included. | |
| 95 class DragImageBuilder { | |
| 96 STACK_ALLOCATED(); | 89 STACK_ALLOCATED(); |
| 97 public: | 90 public: |
| 98 DragImageBuilder(const LocalFrame& localFrame, const IntRect& bounds, Node*
draggedNode, float opacity = 1) | 91 ScopedFramePaintingState(LocalFrame* frame, Node* node) |
| 99 : m_localFrame(localFrame) | 92 : frame(frame) |
| 100 , m_draggedNode(draggedNode) | 93 , node(node) |
| 101 , m_bounds(bounds) | |
| 102 , m_opacity(opacity) | |
| 103 { | 94 { |
| 104 if (m_draggedNode && m_draggedNode->layoutObject()) | 95 ASSERT(!node || node->layoutObject()); |
| 105 m_draggedNode->layoutObject()->updateDragState(true); | 96 if (node) |
| 106 | 97 node->layoutObject()->updateDragState(true); |
| 107 float deviceScaleFactor = m_localFrame.host()->deviceScaleFactor(); | |
| 108 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor); | |
| 109 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor); | |
| 110 m_pictureBuilder = adoptPtr(new SkPictureBuilder(SkRect::MakeIWH(m_bound
s.width(), m_bounds.height()))); | |
| 111 | |
| 112 AffineTransform transform; | |
| 113 transform.scale(deviceScaleFactor, deviceScaleFactor); | |
| 114 transform.translate(-m_bounds.x(), -m_bounds.y()); | |
| 115 context().paintController().createAndAppend<BeginTransformDisplayItem>(m
_localFrame, transform); | |
| 116 } | 98 } |
| 117 | 99 |
| 118 GraphicsContext& context() { return m_pictureBuilder->context(); } | 100 ~ScopedFramePaintingState() |
| 119 | |
| 120 PassOwnPtr<DragImage> createImage() | |
| 121 { | 101 { |
| 122 if (m_draggedNode && m_draggedNode->layoutObject()) | 102 if (node && node->layoutObject()) |
| 123 m_draggedNode->layoutObject()->updateDragState(false); | 103 node->layoutObject()->updateDragState(false); |
| 124 context().paintController().endItem<EndTransformDisplayItem>(m_localFram
e); | 104 frame->view()->setNodeToDraw(0); |
| 125 RefPtr<const SkPicture> recording = m_pictureBuilder->endRecording(); | |
| 126 RefPtr<SkImage> skImage = adoptRef(SkImage::NewFromPicture(recording.get
(), | |
| 127 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr
)); | |
| 128 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); | |
| 129 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat
ion; | |
| 130 if (m_draggedNode && m_draggedNode->layoutObject()) | |
| 131 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra
ggedNode->layoutObject()); | |
| 132 return DragImage::create(image.get(), imageOrientation, | |
| 133 m_localFrame.host()->deviceScaleFactor(), InterpolationHigh, m_opaci
ty); | |
| 134 } | 105 } |
| 135 | 106 |
| 136 private: | 107 RawPtrWillBeMember<LocalFrame> frame; |
| 137 const LocalFrame& m_localFrame; | 108 RawPtrWillBeMember<Node> node; |
| 138 Node* m_draggedNode; | |
| 139 IntRect m_bounds; | |
| 140 float m_opacity; | |
| 141 OwnPtr<SkPictureBuilder> m_pictureBuilder; | |
| 142 }; | 109 }; |
| 143 | 110 |
| 144 inline float parentPageZoomFactor(LocalFrame* frame) | 111 inline float parentPageZoomFactor(LocalFrame* frame) |
| 145 { | 112 { |
| 146 Frame* parent = frame->tree().parent(); | 113 Frame* parent = frame->tree().parent(); |
| 147 if (!parent || !parent->isLocalFrame()) | 114 if (!parent || !parent->isLocalFrame()) |
| 148 return 1; | 115 return 1; |
| 149 return toLocalFrame(parent)->pageZoomFactor(); | 116 return toLocalFrame(parent)->pageZoomFactor(); |
| 150 } | 117 } |
| 151 | 118 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 double LocalFrame::devicePixelRatio() const | 601 double LocalFrame::devicePixelRatio() const |
| 635 { | 602 { |
| 636 if (!m_host) | 603 if (!m_host) |
| 637 return 0; | 604 return 0; |
| 638 | 605 |
| 639 double ratio = m_host->deviceScaleFactor(); | 606 double ratio = m_host->deviceScaleFactor(); |
| 640 ratio *= pageZoomFactor(); | 607 ratio *= pageZoomFactor(); |
| 641 return ratio; | 608 return ratio; |
| 642 } | 609 } |
| 643 | 610 |
| 644 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage(const GlobalPaintFlags glob
alPaintFlags, | 611 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage( |
| 645 IntRect paintingRect, Node* draggedNode, float opacity) | 612 const DisplayItemClient& displayItemClient, |
| 613 RespectImageOrientationEnum shouldRespectImageOrientation, |
| 614 const GlobalPaintFlags globalPaintFlags, IntRect paintingRect, float opacity
) |
| 646 { | 615 { |
| 647 ASSERT(document()->isActive()); | 616 ASSERT(document()->isActive()); |
| 648 // Not flattening compositing layers will result in a broken image being pai
nted. | 617 // Not flattening compositing layers will result in a broken image being pai
nted. |
| 649 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers); | 618 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers); |
| 650 | 619 |
| 651 DragImageBuilder dragImageBuilder(*this, paintingRect, draggedNode, opacity)
; | 620 float deviceScaleFactor = m_host->deviceScaleFactor(); |
| 652 m_view->paintContents(dragImageBuilder.context(), globalPaintFlags, painting
Rect); | 621 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor); |
| 653 return dragImageBuilder.createImage(); | 622 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor); |
| 623 |
| 624 // The content is shifted to origin, to fit within the image bounds - which
are the same |
| 625 // as the picture bounds. |
| 626 SkRect pictureBounds = SkRect::MakeIWH(paintingRect.width(), paintingRect.he
ight()); |
| 627 SkPictureBuilder pictureBuilder(pictureBounds); |
| 628 { |
| 629 GraphicsContext& paintContext = pictureBuilder.context(); |
| 630 |
| 631 AffineTransform transform; |
| 632 transform.scale(deviceScaleFactor, deviceScaleFactor); |
| 633 transform.translate(-paintingRect.x(), -paintingRect.y()); |
| 634 TransformRecorder transformRecorder(paintContext, displayItemClient, tra
nsform); |
| 635 |
| 636 m_view->paintContents(paintContext, globalPaintFlags, paintingRect); |
| 637 |
| 638 } |
| 639 RefPtr<const SkPicture> recording = pictureBuilder.endRecording(); |
| 640 RefPtr<SkImage> skImage = adoptRef(SkImage::NewFromPicture(recording.get(), |
| 641 SkISize::Make(paintingRect.width(), paintingRect.height()), nullptr, nul
lptr)); |
| 642 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); |
| 643 |
| 644 return DragImage::create(image.get(), shouldRespectImageOrientation, deviceS
caleFactor, |
| 645 InterpolationHigh, opacity); |
| 654 } | 646 } |
| 655 | 647 |
| 656 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) | 648 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) |
| 657 { | 649 { |
| 650 if (!node.layoutObject()) |
| 651 return nullptr; |
| 652 |
| 653 const ScopedFramePaintingState state(this, &node); |
| 654 |
| 658 m_view->updateAllLifecyclePhases(); | 655 m_view->updateAllLifecyclePhases(); |
| 656 |
| 657 m_view->setNodeToDraw(&node); // Enable special sub-tree drawing mode. |
| 658 |
| 659 // Document::updateLayout may have blown away the original LayoutObject. |
| 659 LayoutObject* layoutObject = node.layoutObject(); | 660 LayoutObject* layoutObject = node.layoutObject(); |
| 660 if (!layoutObject) | 661 if (!layoutObject) |
| 661 return nullptr; | 662 return nullptr; |
| 662 | 663 |
| 663 // Directly paint boxes as if they are a stacking context. | 664 IntRect rect; |
| 664 if (layoutObject->isBox() && layoutObject->container()) { | |
| 665 IntRect boundingBox = layoutObject->absoluteBoundingBoxRectIncludingDesc
endants(); | |
| 666 LayoutPoint paintOffset = boundingBox.location() - layoutObject->offsetF
romContainer(layoutObject->container(), LayoutPoint()); | |
| 667 | 665 |
| 668 DragImageBuilder dragImageBuilder(*this, boundingBox, &node); | 666 return paintIntoDragImage(*layoutObject, LayoutObject::shouldRespectImageOri
entation(layoutObject), |
| 669 { | 667 GlobalPaintFlattenCompositingLayers, layoutObject->paintingRootRect(rect
)); |
| 670 PaintInfo paintInfo(dragImageBuilder.context(), boundingBox, PaintPh
ase::PaintPhaseForeground, GlobalPaintFlattenCompositingLayers, 0); | |
| 671 ObjectPainter(*layoutObject).paintAsPseudoStackingContext(paintInfo,
LayoutPoint(paintOffset)); | |
| 672 } | |
| 673 return dragImageBuilder.createImage(); | |
| 674 } | |
| 675 | |
| 676 // TODO(pdr): This will also paint the background if the object contains tra
nsparency. We can | |
| 677 // directly call layoutObject->paint(...) (see: ObjectPainter::paintAsPseudo
StackingContext) but | |
| 678 // painters are inconsistent about which transform space they expect (see: s
vg, inlines, etc.) | |
| 679 // TODO(pdr): SVG and inlines are painted offset (crbug.com/579153, crbug.co
m/579158). | |
| 680 return paintIntoDragImage(GlobalPaintFlattenCompositingLayers, layoutObject-
>absoluteBoundingBoxRectIncludingDescendants(), &node); | |
| 681 } | 668 } |
| 682 | 669 |
| 683 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity) | 670 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity) |
| 684 { | 671 { |
| 685 if (!selection().isRange()) | 672 if (!selection().isRange()) |
| 686 return nullptr; | 673 return nullptr; |
| 687 | 674 |
| 675 const ScopedFramePaintingState state(this, 0); |
| 688 m_view->updateAllLifecyclePhases(); | 676 m_view->updateAllLifecyclePhases(); |
| 689 | 677 |
| 690 return paintIntoDragImage(GlobalPaintSelectionOnly | GlobalPaintFlattenCompo
sitingLayers, | 678 return paintIntoDragImage(*this, DoNotRespectImageOrientation, |
| 691 enclosingIntRect(selection().bounds()), nullptr, opacity); | 679 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers, |
| 680 enclosingIntRect(selection().bounds()), opacity); |
| 692 } | 681 } |
| 693 | 682 |
| 694 String LocalFrame::selectedText() const | 683 String LocalFrame::selectedText() const |
| 695 { | 684 { |
| 696 return selection().selectedText(); | 685 return selection().selectedText(); |
| 697 } | 686 } |
| 698 | 687 |
| 699 String LocalFrame::selectedTextForClipboard() const | 688 String LocalFrame::selectedTextForClipboard() const |
| 700 { | 689 { |
| 701 return selection().selectedTextForClipboard(); | 690 return selection().selectedTextForClipboard(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 { | 888 { |
| 900 m_frame->disableNavigation(); | 889 m_frame->disableNavigation(); |
| 901 } | 890 } |
| 902 | 891 |
| 903 FrameNavigationDisabler::~FrameNavigationDisabler() | 892 FrameNavigationDisabler::~FrameNavigationDisabler() |
| 904 { | 893 { |
| 905 m_frame->enableNavigation(); | 894 m_frame->enableNavigation(); |
| 906 } | 895 } |
| 907 | 896 |
| 908 } // namespace blink | 897 } // namespace blink |
| OLD | NEW |