| 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" |
| 63 #include "core/paint/PaintLayer.h" | 65 #include "core/paint/PaintLayer.h" |
| 64 #include "core/paint/TransformRecorder.h" | 66 #include "core/paint/TransformRecorder.h" |
| 65 #include "core/svg/SVGDocumentExtensions.h" | 67 #include "core/svg/SVGDocumentExtensions.h" |
| 66 #include "platform/DragImage.h" | 68 #include "platform/DragImage.h" |
| 67 #include "platform/PluginScriptForbiddenScope.h" | 69 #include "platform/PluginScriptForbiddenScope.h" |
| 68 #include "platform/RuntimeEnabledFeatures.h" | 70 #include "platform/RuntimeEnabledFeatures.h" |
| 69 #include "platform/ScriptForbiddenScope.h" | 71 #include "platform/ScriptForbiddenScope.h" |
| 70 #include "platform/graphics/GraphicsContext.h" | 72 #include "platform/graphics/GraphicsContext.h" |
| 71 #include "platform/graphics/StaticBitmapImage.h" | 73 #include "platform/graphics/StaticBitmapImage.h" |
| 72 #include "platform/graphics/paint/ClipRecorder.h" | 74 #include "platform/graphics/paint/ClipRecorder.h" |
| 73 #include "platform/graphics/paint/SkPictureBuilder.h" | 75 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 76 #include "platform/graphics/paint/TransformDisplayItem.h" |
| 74 #include "platform/text/TextStream.h" | 77 #include "platform/text/TextStream.h" |
| 75 #include "public/platform/WebFrameScheduler.h" | 78 #include "public/platform/WebFrameScheduler.h" |
| 76 #include "public/platform/WebSecurityOrigin.h" | 79 #include "public/platform/WebSecurityOrigin.h" |
| 77 #include "public/platform/WebViewScheduler.h" | 80 #include "public/platform/WebViewScheduler.h" |
| 78 #include "third_party/skia/include/core/SkImage.h" | 81 #include "third_party/skia/include/core/SkImage.h" |
| 79 #include "wtf/PassOwnPtr.h" | 82 #include "wtf/PassOwnPtr.h" |
| 80 #include "wtf/StdLibExtras.h" | 83 #include "wtf/StdLibExtras.h" |
| 81 | 84 |
| 82 namespace blink { | 85 namespace blink { |
| 83 | 86 |
| 84 using namespace HTMLNames; | 87 using namespace HTMLNames; |
| 85 | 88 |
| 86 namespace { | 89 namespace { |
| 87 | 90 |
| 88 struct ScopedFramePaintingState { | 91 // Convenience class for initializing a GraphicsContext to build a DragImage fro
m a specific |
| 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 { |
| 89 STACK_ALLOCATED(); | 96 STACK_ALLOCATED(); |
| 90 public: | 97 public: |
| 91 ScopedFramePaintingState(LocalFrame* frame, Node* node) | 98 DragImageBuilder(const LocalFrame* localFrame, const IntRect& bounds, Node*
draggedNode, float opacity = 1) |
| 92 : frame(frame) | 99 : m_localFrame(localFrame) |
| 93 , node(node) | 100 , m_draggedNode(draggedNode) |
| 101 , m_bounds(bounds) |
| 102 , m_opacity(opacity) |
| 94 { | 103 { |
| 95 ASSERT(!node || node->layoutObject()); | 104 if (m_draggedNode && m_draggedNode->layoutObject()) |
| 96 if (node) | 105 m_draggedNode->layoutObject()->updateDragState(true); |
| 97 node->layoutObject()->updateDragState(true); | 106 |
| 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); |
| 98 } | 116 } |
| 99 | 117 |
| 100 ~ScopedFramePaintingState() | 118 GraphicsContext& context() { return m_pictureBuilder->context(); } |
| 119 |
| 120 PassOwnPtr<DragImage> createImage() |
| 101 { | 121 { |
| 102 if (node && node->layoutObject()) | 122 if (m_draggedNode && m_draggedNode->layoutObject()) |
| 103 node->layoutObject()->updateDragState(false); | 123 m_draggedNode->layoutObject()->updateDragState(false); |
| 104 frame->view()->setNodeToDraw(0); | 124 context().paintController().endItem<EndTransformDisplayItem>(*m_localFra
me); |
| 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_opac
ity); |
| 105 } | 134 } |
| 106 | 135 |
| 107 RawPtrWillBeMember<LocalFrame> frame; | 136 private: |
| 108 RawPtrWillBeMember<Node> node; | 137 RawPtrWillBeMember<const LocalFrame> m_localFrame; |
| 138 RawPtrWillBeMember<Node> m_draggedNode; |
| 139 IntRect m_bounds; |
| 140 float m_opacity; |
| 141 OwnPtr<SkPictureBuilder> m_pictureBuilder; |
| 109 }; | 142 }; |
| 110 | 143 |
| 111 inline float parentPageZoomFactor(LocalFrame* frame) | 144 inline float parentPageZoomFactor(LocalFrame* frame) |
| 112 { | 145 { |
| 113 Frame* parent = frame->tree().parent(); | 146 Frame* parent = frame->tree().parent(); |
| 114 if (!parent || !parent->isLocalFrame()) | 147 if (!parent || !parent->isLocalFrame()) |
| 115 return 1; | 148 return 1; |
| 116 return toLocalFrame(parent)->pageZoomFactor(); | 149 return toLocalFrame(parent)->pageZoomFactor(); |
| 117 } | 150 } |
| 118 | 151 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 double LocalFrame::devicePixelRatio() const | 634 double LocalFrame::devicePixelRatio() const |
| 602 { | 635 { |
| 603 if (!m_host) | 636 if (!m_host) |
| 604 return 0; | 637 return 0; |
| 605 | 638 |
| 606 double ratio = m_host->deviceScaleFactor(); | 639 double ratio = m_host->deviceScaleFactor(); |
| 607 ratio *= pageZoomFactor(); | 640 ratio *= pageZoomFactor(); |
| 608 return ratio; | 641 return ratio; |
| 609 } | 642 } |
| 610 | 643 |
| 611 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage( | 644 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage(const GlobalPaintFlags glob
alPaintFlags, |
| 612 const DisplayItemClient& displayItemClient, | 645 IntRect paintingRect, Node* draggedNode, float opacity) |
| 613 RespectImageOrientationEnum shouldRespectImageOrientation, | |
| 614 const GlobalPaintFlags globalPaintFlags, IntRect paintingRect, float opacity
) | |
| 615 { | 646 { |
| 616 ASSERT(document()->isActive()); | 647 ASSERT(document()->isActive()); |
| 617 // Not flattening compositing layers will result in a broken image being pai
nted. | 648 // Not flattening compositing layers will result in a broken image being pai
nted. |
| 618 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers); | 649 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers); |
| 619 | 650 |
| 620 float deviceScaleFactor = m_host->deviceScaleFactor(); | 651 DragImageBuilder dragImageBuilder(this, paintingRect, draggedNode, opacity); |
| 621 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor); | 652 m_view->paintContents(dragImageBuilder.context(), globalPaintFlags, painting
Rect); |
| 622 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor); | 653 return dragImageBuilder.createImage(); |
| 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); | |
| 646 } | 654 } |
| 647 | 655 |
| 648 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) | 656 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) |
| 649 { | 657 { |
| 650 if (!node.layoutObject()) | |
| 651 return nullptr; | |
| 652 | |
| 653 const ScopedFramePaintingState state(this, &node); | |
| 654 | |
| 655 m_view->updateAllLifecyclePhases(); | 658 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. | |
| 660 LayoutObject* layoutObject = node.layoutObject(); | 659 LayoutObject* layoutObject = node.layoutObject(); |
| 661 if (!layoutObject) | 660 if (!layoutObject) |
| 662 return nullptr; | 661 return nullptr; |
| 663 | 662 |
| 664 IntRect rect; | 663 // Directly paint boxes as if they are a stacking context. |
| 664 if (layoutObject->isBox() && layoutObject->container()) { |
| 665 IntRect boundingBox = layoutObject->absoluteBoundingBoxRectIncludingDesc
endants(); |
| 666 LayoutPoint paintOffset = boundingBox.location() - layoutObject->offsetF
romContainer(layoutObject->container(), LayoutPoint()); |
| 665 | 667 |
| 666 return paintIntoDragImage(*layoutObject, LayoutObject::shouldRespectImageOri
entation(layoutObject), | 668 DragImageBuilder dragImageBuilder(this, boundingBox, &node); |
| 667 GlobalPaintFlattenCompositingLayers, layoutObject->paintingRootRect(rect
)); | 669 { |
| 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); |
| 668 } | 681 } |
| 669 | 682 |
| 670 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity) | 683 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity) |
| 671 { | 684 { |
| 672 if (!selection().isRange()) | 685 if (!selection().isRange()) |
| 673 return nullptr; | 686 return nullptr; |
| 674 | 687 |
| 675 const ScopedFramePaintingState state(this, 0); | |
| 676 m_view->updateAllLifecyclePhases(); | 688 m_view->updateAllLifecyclePhases(); |
| 677 | 689 |
| 678 return paintIntoDragImage(*this, DoNotRespectImageOrientation, | 690 return paintIntoDragImage(GlobalPaintSelectionOnly | GlobalPaintFlattenCompo
sitingLayers, |
| 679 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers, | 691 enclosingIntRect(selection().bounds()), nullptr, opacity); |
| 680 enclosingIntRect(selection().bounds()), opacity); | |
| 681 } | 692 } |
| 682 | 693 |
| 683 String LocalFrame::selectedText() const | 694 String LocalFrame::selectedText() const |
| 684 { | 695 { |
| 685 return selection().selectedText(); | 696 return selection().selectedText(); |
| 686 } | 697 } |
| 687 | 698 |
| 688 String LocalFrame::selectedTextForClipboard() const | 699 String LocalFrame::selectedTextForClipboard() const |
| 689 { | 700 { |
| 690 return selection().selectedTextForClipboard(); | 701 return selection().selectedTextForClipboard(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 { | 899 { |
| 889 m_frame->disableNavigation(); | 900 m_frame->disableNavigation(); |
| 890 } | 901 } |
| 891 | 902 |
| 892 FrameNavigationDisabler::~FrameNavigationDisabler() | 903 FrameNavigationDisabler::~FrameNavigationDisabler() |
| 893 { | 904 { |
| 894 m_frame->enableNavigation(); | 905 m_frame->enableNavigation(); |
| 895 } | 906 } |
| 896 | 907 |
| 897 } // namespace blink | 908 } // namespace blink |
| OLD | NEW |