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