| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 #include "platform/graphics/paint/PaintController.h" | 79 #include "platform/graphics/paint/PaintController.h" |
| 80 #include "platform/graphics/paint/SkPictureBuilder.h" | 80 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 81 #include "platform/graphics/paint/TransformDisplayItem.h" | 81 #include "platform/graphics/paint/TransformDisplayItem.h" |
| 82 #include "platform/plugins/PluginData.h" | 82 #include "platform/plugins/PluginData.h" |
| 83 #include "platform/text/TextStream.h" | 83 #include "platform/text/TextStream.h" |
| 84 #include "public/platform/ServiceRegistry.h" | 84 #include "public/platform/ServiceRegistry.h" |
| 85 #include "public/platform/WebFrameScheduler.h" | 85 #include "public/platform/WebFrameScheduler.h" |
| 86 #include "public/platform/WebScreenInfo.h" | 86 #include "public/platform/WebScreenInfo.h" |
| 87 #include "public/platform/WebViewScheduler.h" | 87 #include "public/platform/WebViewScheduler.h" |
| 88 #include "third_party/skia/include/core/SkImage.h" | 88 #include "third_party/skia/include/core/SkImage.h" |
| 89 #include "wtf/PtrUtil.h" | 89 #include "wtf/PassOwnPtr.h" |
| 90 #include "wtf/StdLibExtras.h" | 90 #include "wtf/StdLibExtras.h" |
| 91 #include <memory> | |
| 92 | 91 |
| 93 namespace blink { | 92 namespace blink { |
| 94 | 93 |
| 95 using namespace HTMLNames; | 94 using namespace HTMLNames; |
| 96 | 95 |
| 97 namespace { | 96 namespace { |
| 98 | 97 |
| 99 // Convenience class for initializing a GraphicsContext to build a DragImage fro
m a specific | 98 // Convenience class for initializing a GraphicsContext to build a DragImage fro
m a specific |
| 100 // region specified by |bounds|. After painting the using context(), the DragIma
ge returned from | 99 // region specified by |bounds|. After painting the using context(), the DragIma
ge returned from |
| 101 // createImage() will only contain the content in |bounds| with the appropriate
device scale | 100 // createImage() will only contain the content in |bounds| with the appropriate
device scale |
| 102 // factor included. | 101 // factor included. |
| 103 class DragImageBuilder { | 102 class DragImageBuilder { |
| 104 STACK_ALLOCATED(); | 103 STACK_ALLOCATED(); |
| 105 public: | 104 public: |
| 106 DragImageBuilder(const LocalFrame* localFrame, const FloatRect& bounds, Node
* draggedNode, float opacity = 1) | 105 DragImageBuilder(const LocalFrame* localFrame, const FloatRect& bounds, Node
* draggedNode, float opacity = 1) |
| 107 : m_localFrame(localFrame) | 106 : m_localFrame(localFrame) |
| 108 , m_draggedNode(draggedNode) | 107 , m_draggedNode(draggedNode) |
| 109 , m_bounds(bounds) | 108 , m_bounds(bounds) |
| 110 , m_opacity(opacity) | 109 , m_opacity(opacity) |
| 111 { | 110 { |
| 112 if (m_draggedNode && m_draggedNode->layoutObject()) | 111 if (m_draggedNode && m_draggedNode->layoutObject()) |
| 113 m_draggedNode->layoutObject()->updateDragState(true); | 112 m_draggedNode->layoutObject()->updateDragState(true); |
| 114 float deviceScaleFactor = m_localFrame->host()->chromeClient().screenInf
o().deviceScaleFactor; | 113 float deviceScaleFactor = m_localFrame->host()->chromeClient().screenInf
o().deviceScaleFactor; |
| 115 | 114 |
| 116 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor); | 115 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor); |
| 117 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor); | 116 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor); |
| 118 m_pictureBuilder = wrapUnique(new SkPictureBuilder(SkRect::MakeIWH(m_bou
nds.width(), m_bounds.height()))); | 117 m_pictureBuilder = adoptPtr(new SkPictureBuilder(SkRect::MakeIWH(m_bound
s.width(), m_bounds.height()))); |
| 119 | 118 |
| 120 AffineTransform transform; | 119 AffineTransform transform; |
| 121 transform.scale(deviceScaleFactor, deviceScaleFactor); | 120 transform.scale(deviceScaleFactor, deviceScaleFactor); |
| 122 transform.translate(-m_bounds.x(), -m_bounds.y()); | 121 transform.translate(-m_bounds.x(), -m_bounds.y()); |
| 123 context().getPaintController().createAndAppend<BeginTransformDisplayItem
>(*m_pictureBuilder, transform); | 122 context().getPaintController().createAndAppend<BeginTransformDisplayItem
>(*m_pictureBuilder, transform); |
| 124 } | 123 } |
| 125 | 124 |
| 126 GraphicsContext& context() { return m_pictureBuilder->context(); } | 125 GraphicsContext& context() { return m_pictureBuilder->context(); } |
| 127 | 126 |
| 128 std::unique_ptr<DragImage> createImage() | 127 PassOwnPtr<DragImage> createImage() |
| 129 { | 128 { |
| 130 if (m_draggedNode && m_draggedNode->layoutObject()) | 129 if (m_draggedNode && m_draggedNode->layoutObject()) |
| 131 m_draggedNode->layoutObject()->updateDragState(false); | 130 m_draggedNode->layoutObject()->updateDragState(false); |
| 132 context().getPaintController().endItem<EndTransformDisplayItem>(*m_pictu
reBuilder); | 131 context().getPaintController().endItem<EndTransformDisplayItem>(*m_pictu
reBuilder); |
| 133 // TODO(fmalita): endRecording() should return a non-const SKP. | 132 // TODO(fmalita): endRecording() should return a non-const SKP. |
| 134 sk_sp<SkPicture> recording(const_cast<SkPicture*>(m_pictureBuilder->endR
ecording().leakRef())); | 133 sk_sp<SkPicture> recording(const_cast<SkPicture*>(m_pictureBuilder->endR
ecording().leakRef())); |
| 135 RefPtr<SkImage> skImage = fromSkSp(SkImage::MakeFromPicture(std::move(re
cording), | 134 RefPtr<SkImage> skImage = fromSkSp(SkImage::MakeFromPicture(std::move(re
cording), |
| 136 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr
)); | 135 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr
)); |
| 137 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); | 136 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); |
| 138 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat
ion; | 137 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat
ion; |
| 139 if (m_draggedNode && m_draggedNode->layoutObject()) | 138 if (m_draggedNode && m_draggedNode->layoutObject()) |
| 140 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra
ggedNode->layoutObject()); | 139 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra
ggedNode->layoutObject()); |
| 141 | 140 |
| 142 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr
eenInfo().deviceScaleFactor; | 141 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr
eenInfo().deviceScaleFactor; |
| 143 | 142 |
| 144 return DragImage::create(image.get(), imageOrientation, screenDeviceScal
eFactor, InterpolationHigh, m_opacity); | 143 return DragImage::create(image.get(), imageOrientation, screenDeviceScal
eFactor, InterpolationHigh, m_opacity); |
| 145 } | 144 } |
| 146 | 145 |
| 147 private: | 146 private: |
| 148 Member<const LocalFrame> m_localFrame; | 147 Member<const LocalFrame> m_localFrame; |
| 149 Member<Node> m_draggedNode; | 148 Member<Node> m_draggedNode; |
| 150 FloatRect m_bounds; | 149 FloatRect m_bounds; |
| 151 float m_opacity; | 150 float m_opacity; |
| 152 std::unique_ptr<SkPictureBuilder> m_pictureBuilder; | 151 OwnPtr<SkPictureBuilder> m_pictureBuilder; |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 inline float parentPageZoomFactor(LocalFrame* frame) | 154 inline float parentPageZoomFactor(LocalFrame* frame) |
| 156 { | 155 { |
| 157 Frame* parent = frame->tree().parent(); | 156 Frame* parent = frame->tree().parent(); |
| 158 if (!parent || !parent->isLocalFrame()) | 157 if (!parent || !parent->isLocalFrame()) |
| 159 return 1; | 158 return 1; |
| 160 return toLocalFrame(parent)->pageZoomFactor(); | 159 return toLocalFrame(parent)->pageZoomFactor(); |
| 161 } | 160 } |
| 162 | 161 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 double LocalFrame::devicePixelRatio() const | 588 double LocalFrame::devicePixelRatio() const |
| 590 { | 589 { |
| 591 if (!m_host) | 590 if (!m_host) |
| 592 return 0; | 591 return 0; |
| 593 | 592 |
| 594 double ratio = m_host->deviceScaleFactorDeprecated(); | 593 double ratio = m_host->deviceScaleFactorDeprecated(); |
| 595 ratio *= pageZoomFactor(); | 594 ratio *= pageZoomFactor(); |
| 596 return ratio; | 595 return ratio; |
| 597 } | 596 } |
| 598 | 597 |
| 599 std::unique_ptr<DragImage> LocalFrame::nodeImage(Node& node) | 598 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) |
| 600 { | 599 { |
| 601 m_view->updateAllLifecyclePhasesExceptPaint(); | 600 m_view->updateAllLifecyclePhasesExceptPaint(); |
| 602 LayoutObject* layoutObject = node.layoutObject(); | 601 LayoutObject* layoutObject = node.layoutObject(); |
| 603 if (!layoutObject) | 602 if (!layoutObject) |
| 604 return nullptr; | 603 return nullptr; |
| 605 | 604 |
| 606 // Paint starting at the nearest stacking context, clipped to the object its
elf. | 605 // Paint starting at the nearest stacking context, clipped to the object its
elf. |
| 607 // This will also paint the contents behind the object if the object contain
s transparency | 606 // This will also paint the contents behind the object if the object contain
s transparency |
| 608 // and there are other elements in the same stacking context which stacked b
elow. | 607 // and there are other elements in the same stacking context which stacked b
elow. |
| 609 PaintLayer* layer = layoutObject->enclosingLayer(); | 608 PaintLayer* layer = layoutObject->enclosingLayer(); |
| 610 if (!layer->stackingNode()->isStackingContext()) | 609 if (!layer->stackingNode()->isStackingContext()) |
| 611 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); | 610 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); |
| 612 IntRect absoluteBoundingBox = layoutObject->absoluteBoundingBoxRectIncluding
Descendants(); | 611 IntRect absoluteBoundingBox = layoutObject->absoluteBoundingBoxRectIncluding
Descendants(); |
| 613 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(FloatQuad
(absoluteBoundingBox), UseTransforms).boundingBox(); | 612 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(FloatQuad
(absoluteBoundingBox), UseTransforms).boundingBox(); |
| 614 DragImageBuilder dragImageBuilder(this, boundingBox, &node); | 613 DragImageBuilder dragImageBuilder(this, boundingBox, &node); |
| 615 { | 614 { |
| 616 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), Glob
alPaintFlattenCompositingLayers, LayoutSize()); | 615 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), Glob
alPaintFlattenCompositingLayers, LayoutSize()); |
| 617 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppliedTr
ansform | PaintLayerUncachedClipRects; | 616 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppliedTr
ansform | PaintLayerUncachedClipRects; |
| 618 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), paintin
gInfo, flags); | 617 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), paintin
gInfo, flags); |
| 619 } | 618 } |
| 620 return dragImageBuilder.createImage(); | 619 return dragImageBuilder.createImage(); |
| 621 } | 620 } |
| 622 | 621 |
| 623 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) | 622 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity) |
| 624 { | 623 { |
| 625 if (!selection().isRange()) | 624 if (!selection().isRange()) |
| 626 return nullptr; | 625 return nullptr; |
| 627 | 626 |
| 628 m_view->updateAllLifecyclePhasesExceptPaint(); | 627 m_view->updateAllLifecyclePhasesExceptPaint(); |
| 629 ASSERT(document()->isActive()); | 628 ASSERT(document()->isActive()); |
| 630 | 629 |
| 631 FloatRect paintingRect = FloatRect(selection().bounds()); | 630 FloatRect paintingRect = FloatRect(selection().bounds()); |
| 632 DragImageBuilder dragImageBuilder(this, paintingRect, nullptr, opacity); | 631 DragImageBuilder dragImageBuilder(this, paintingRect, nullptr, opacity); |
| 633 GlobalPaintFlags paintFlags = GlobalPaintSelectionOnly | GlobalPaintFlattenC
ompositingLayers; | 632 GlobalPaintFlags paintFlags = GlobalPaintSelectionOnly | GlobalPaintFlattenC
ompositingLayers; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 m_frame->client()->frameBlameContext()->Enter(); | 829 m_frame->client()->frameBlameContext()->Enter(); |
| 831 } | 830 } |
| 832 | 831 |
| 833 ScopedFrameBlamer::~ScopedFrameBlamer() | 832 ScopedFrameBlamer::~ScopedFrameBlamer() |
| 834 { | 833 { |
| 835 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) | 834 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) |
| 836 m_frame->client()->frameBlameContext()->Leave(); | 835 m_frame->client()->frameBlameContext()->Leave(); |
| 837 } | 836 } |
| 838 | 837 |
| 839 } // namespace blink | 838 } // namespace blink |
| OLD | NEW |