Chromium Code Reviews| 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 | 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 9 * rights reserved. | 9 * rights reserved. |
| 10 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> | 10 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 #include "third_party/skia/include/core/SkImage.h" | 100 #include "third_party/skia/include/core/SkImage.h" |
| 101 #include "wtf/PtrUtil.h" | 101 #include "wtf/PtrUtil.h" |
| 102 #include "wtf/StdLibExtras.h" | 102 #include "wtf/StdLibExtras.h" |
| 103 | 103 |
| 104 namespace blink { | 104 namespace blink { |
| 105 | 105 |
| 106 using namespace HTMLNames; | 106 using namespace HTMLNames; |
| 107 | 107 |
| 108 namespace { | 108 namespace { |
| 109 | 109 |
| 110 // Convenience class for initializing a GraphicsContext to build a DragImage | 110 // Converts from bounds in CSS space to device space based on the given |
|
pdr.
2017/03/28 21:01:30
Can we DCHECK in the paired display item code that
chrishtr
2017/03/28 21:43:23
Yes, but even with this patch they are still used,
| |
| 111 // from a specific region specified by |bounds|. After painting the using | 111 // frame. |
| 112 // context(), the DragImage returned from createImage() will only contain the | 112 static FloatRect deviceSpaceBounds(const FloatRect cssBounds, |
| 113 // content in |bounds| with the appropriate device scale factor included. | 113 const LocalFrame& frame) { |
| 114 class DragImageBuilder { | 114 float deviceScaleFactor = frame.page()->deviceScaleFactorDeprecated(); |
| 115 STACK_ALLOCATED(); | 115 float pageScaleFactor = frame.page()->visualViewport().scale(); |
| 116 FloatRect deviceBounds(cssBounds); | |
| 117 deviceBounds.setWidth(cssBounds.width() * deviceScaleFactor * | |
| 118 pageScaleFactor); | |
| 119 deviceBounds.setHeight(cssBounds.height() * deviceScaleFactor * | |
| 120 pageScaleFactor); | |
| 121 return deviceBounds; | |
| 122 } | |
| 116 | 123 |
| 117 public: | 124 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled |
| 118 DragImageBuilder(const LocalFrame& localFrame, const FloatRect& bounds) | 125 // in device space. |
| 119 : m_localFrame(&localFrame), m_bounds(bounds) { | 126 static std::unique_ptr<DragImage> createDragImage( |
| 120 // TODO(oshima): Remove this when all platforms are migrated to | 127 const LocalFrame& frame, |
| 121 // use-zoom-for-dsf. | 128 float opacity, |
| 122 float deviceScaleFactor = | 129 RespectImageOrientationEnum imageOrientation, |
| 123 m_localFrame->page()->deviceScaleFactorDeprecated(); | 130 const FloatRect& cssBounds, |
| 124 float pageScaleFactor = m_localFrame->page()->visualViewport().scale(); | 131 sk_sp<PaintRecord> contents) { |
| 125 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor * pageScaleFactor); | 132 float deviceScaleFactor = frame.page()->deviceScaleFactorDeprecated(); |
| 126 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor * pageScaleFactor); | 133 float pageScaleFactor = frame.page()->visualViewport().scale(); |
| 127 m_builder = WTF::wrapUnique(new PaintRecordBuilder( | |
| 128 SkRect::MakeIWH(m_bounds.width(), m_bounds.height()))); | |
| 129 | 134 |
| 130 AffineTransform transform; | 135 FloatRect deviceBounds = deviceSpaceBounds(cssBounds, frame); |
| 131 transform.scale(deviceScaleFactor * pageScaleFactor, | |
| 132 deviceScaleFactor * pageScaleFactor); | |
| 133 transform.translate(-m_bounds.x(), -m_bounds.y()); | |
| 134 context().getPaintController().createAndAppend<BeginTransformDisplayItem>( | |
| 135 *m_builder, transform); | |
| 136 } | |
| 137 | 136 |
| 138 GraphicsContext& context() { return m_builder->context(); } | 137 AffineTransform transform; |
| 138 transform.scale(deviceScaleFactor * pageScaleFactor, | |
|
pdr.
2017/03/28 21:01:30
supernit: transform.scale(deviceScaleFactor * page
chrishtr
2017/03/28 21:43:23
Done.
| |
| 139 deviceScaleFactor * pageScaleFactor); | |
| 140 transform.translate(-deviceBounds.x(), -deviceBounds.y()); | |
| 139 | 141 |
| 140 std::unique_ptr<DragImage> createImage( | 142 PaintRecorder recorder; |
| 141 float opacity, | 143 PaintCanvas* canvas = recorder.beginRecording(deviceBounds); |
| 142 RespectImageOrientationEnum imageOrientation = | 144 canvas->concat(affineTransformToSkMatrix(transform)); |
| 143 DoNotRespectImageOrientation) { | 145 canvas->drawPicture(contents); |
| 144 context().getPaintController().endItem<EndTransformDisplayItem>(*m_builder); | |
| 145 // TODO(fmalita): endRecording() should return a non-const SKP. | |
| 146 sk_sp<PaintRecord> record( | |
| 147 const_cast<PaintRecord*>(m_builder->endRecording().release())); | |
| 148 | 146 |
| 149 // Rasterize upfront, since DragImage::create() is going to do it anyway | 147 // Rasterize upfront, since DragImage::create() is going to do it anyway |
| 150 // (SkImage::asLegacyBitmap). | 148 // (SkImage::asLegacyBitmap). |
| 151 SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); | 149 SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 152 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | 150 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( |
| 153 m_bounds.width(), m_bounds.height(), &surfaceProps); | 151 deviceBounds.width(), deviceBounds.height(), &surfaceProps); |
| 154 if (!surface) | 152 if (!surface) |
| 155 return nullptr; | 153 return nullptr; |
| 154 recorder.finishRecordingAsPicture()->playback(surface->getCanvas()); | |
| 155 RefPtr<Image> image = StaticBitmapImage::create(surface->makeImageSnapshot()); | |
| 156 float screenDeviceScaleFactor = | |
| 157 frame.page()->chromeClient().screenInfo().deviceScaleFactor; | |
| 156 | 158 |
| 157 record->playback(surface->getCanvas()); | 159 return DragImage::create(image.get(), imageOrientation, |
| 158 RefPtr<Image> image = | 160 screenDeviceScaleFactor, InterpolationHigh, opacity); |
| 159 StaticBitmapImage::create(surface->makeImageSnapshot()); | 161 } |
| 160 | |
| 161 float screenDeviceScaleFactor = | |
| 162 m_localFrame->page()->chromeClient().screenInfo().deviceScaleFactor; | |
| 163 | |
| 164 return DragImage::create(image.get(), imageOrientation, | |
| 165 screenDeviceScaleFactor, InterpolationHigh, | |
| 166 opacity); | |
| 167 } | |
| 168 | |
| 169 private: | |
| 170 const Member<const LocalFrame> m_localFrame; | |
| 171 FloatRect m_bounds; | |
| 172 std::unique_ptr<PaintRecordBuilder> m_builder; | |
| 173 }; | |
| 174 | 162 |
| 175 class DraggedNodeImageBuilder { | 163 class DraggedNodeImageBuilder { |
| 176 STACK_ALLOCATED(); | 164 STACK_ALLOCATED(); |
| 177 | 165 |
| 178 public: | 166 public: |
| 179 DraggedNodeImageBuilder(const LocalFrame& localFrame, Node& node) | 167 DraggedNodeImageBuilder(const LocalFrame& localFrame, Node& node) |
| 180 : m_localFrame(&localFrame), | 168 : m_localFrame(&localFrame), |
| 181 m_node(&node) | 169 m_node(&node) |
| 182 #if DCHECK_IS_ON() | 170 #if DCHECK_IS_ON() |
| 183 , | 171 , |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 211 // stacking context which stacked below. | 199 // stacking context which stacked below. |
| 212 PaintLayer* layer = draggedLayoutObject->enclosingLayer(); | 200 PaintLayer* layer = draggedLayoutObject->enclosingLayer(); |
| 213 if (!layer->stackingNode()->isStackingContext()) | 201 if (!layer->stackingNode()->isStackingContext()) |
| 214 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); | 202 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); |
| 215 IntRect absoluteBoundingBox = | 203 IntRect absoluteBoundingBox = |
| 216 draggedLayoutObject->absoluteBoundingBoxRectIncludingDescendants(); | 204 draggedLayoutObject->absoluteBoundingBoxRectIncludingDescendants(); |
| 217 FloatRect boundingBox = | 205 FloatRect boundingBox = |
| 218 layer->layoutObject() | 206 layer->layoutObject() |
| 219 .absoluteToLocalQuad(FloatQuad(absoluteBoundingBox), UseTransforms) | 207 .absoluteToLocalQuad(FloatQuad(absoluteBoundingBox), UseTransforms) |
| 220 .boundingBox(); | 208 .boundingBox(); |
| 221 DragImageBuilder dragImageBuilder(*m_localFrame, boundingBox); | 209 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), |
| 222 { | 210 GlobalPaintFlattenCompositingLayers, |
| 223 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), | 211 LayoutSize()); |
| 224 GlobalPaintFlattenCompositingLayers, | 212 PaintLayerFlags flags = PaintLayerHaveTransparency | |
| 225 LayoutSize()); | 213 PaintLayerAppliedTransform | |
| 226 PaintLayerFlags flags = PaintLayerHaveTransparency | | 214 PaintLayerUncachedClipRects; |
| 227 PaintLayerAppliedTransform | | 215 PaintRecordBuilder builder(deviceSpaceBounds(boundingBox, *m_localFrame)); |
| 228 PaintLayerUncachedClipRects; | 216 PaintLayerPainter(*layer).paint(builder.context(), paintingInfo, flags); |
| 229 PaintLayerPainter(*layer).paint(dragImageBuilder.context(), paintingInfo, | 217 return createDragImage( |
| 230 flags); | 218 *m_localFrame, 1.0f, |
| 231 } | 219 LayoutObject::shouldRespectImageOrientation(draggedLayoutObject), |
| 232 return dragImageBuilder.createImage( | 220 boundingBox, builder.endRecording()); |
| 233 1.0f, LayoutObject::shouldRespectImageOrientation(draggedLayoutObject)); | |
| 234 } | 221 } |
| 235 | 222 |
| 236 private: | 223 private: |
| 237 const Member<const LocalFrame> m_localFrame; | 224 const Member<const LocalFrame> m_localFrame; |
| 238 const Member<Node> m_node; | 225 const Member<Node> m_node; |
| 239 #if DCHECK_IS_ON() | 226 #if DCHECK_IS_ON() |
| 240 const uint64_t m_domTreeVersion; | 227 const uint64_t m_domTreeVersion; |
| 241 #endif | 228 #endif |
| 242 }; | 229 }; |
| 243 | 230 |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 } | 708 } |
| 722 | 709 |
| 723 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) { | 710 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) { |
| 724 if (!selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()) | 711 if (!selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()) |
| 725 return nullptr; | 712 return nullptr; |
| 726 | 713 |
| 727 m_view->updateAllLifecyclePhasesExceptPaint(); | 714 m_view->updateAllLifecyclePhasesExceptPaint(); |
| 728 ASSERT(document()->isActive()); | 715 ASSERT(document()->isActive()); |
| 729 | 716 |
| 730 FloatRect paintingRect = FloatRect(selection().bounds()); | 717 FloatRect paintingRect = FloatRect(selection().bounds()); |
| 731 DragImageBuilder dragImageBuilder(*this, paintingRect); | |
| 732 GlobalPaintFlags paintFlags = | 718 GlobalPaintFlags paintFlags = |
| 733 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers; | 719 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers; |
| 734 m_view->paintContents(dragImageBuilder.context(), paintFlags, | 720 |
| 721 PaintRecordBuilder builder(deviceSpaceBounds(paintingRect, *this)); | |
| 722 m_view->paintContents(builder.context(), paintFlags, | |
| 735 enclosingIntRect(paintingRect)); | 723 enclosingIntRect(paintingRect)); |
| 736 return dragImageBuilder.createImage(opacity); | 724 return createDragImage(*this, opacity, DoNotRespectImageOrientation, |
| 725 paintingRect, builder.endRecording()); | |
| 737 } | 726 } |
| 738 | 727 |
| 739 String LocalFrame::selectedText() const { | 728 String LocalFrame::selectedText() const { |
| 740 return selection().selectedText(); | 729 return selection().selectedText(); |
| 741 } | 730 } |
| 742 | 731 |
| 743 String LocalFrame::selectedTextForClipboard() const { | 732 String LocalFrame::selectedTextForClipboard() const { |
| 744 if (!document()) | 733 if (!document()) |
| 745 return emptyString; | 734 return emptyString; |
| 746 DCHECK(!document()->needsLayoutTreeUpdate()); | 735 DCHECK(!document()->needsLayoutTreeUpdate()); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) | 903 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) |
| 915 m_frame->client()->frameBlameContext()->Enter(); | 904 m_frame->client()->frameBlameContext()->Enter(); |
| 916 } | 905 } |
| 917 | 906 |
| 918 ScopedFrameBlamer::~ScopedFrameBlamer() { | 907 ScopedFrameBlamer::~ScopedFrameBlamer() { |
| 919 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) | 908 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) |
| 920 m_frame->client()->frameBlameContext()->Leave(); | 909 m_frame->client()->frameBlameContext()->Leave(); |
| 921 } | 910 } |
| 922 | 911 |
| 923 } // namespace blink | 912 } // namespace blink |
| OLD | NEW |