| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 namespace { | 97 namespace { |
| 98 | 98 |
| 99 // 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 |
| 100 // 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 |
| 101 // 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 |
| 102 // factor included. | 102 // factor included. |
| 103 class DragImageBuilder { | 103 class DragImageBuilder { |
| 104 STACK_ALLOCATED(); | 104 STACK_ALLOCATED(); |
| 105 public: | 105 public: |
| 106 DragImageBuilder(const LocalFrame* localFrame, const FloatRect& bounds, Node
* draggedNode, float opacity = 1) | 106 DragImageBuilder(const LocalFrame& localFrame, const FloatRect& bounds) |
| 107 : m_localFrame(localFrame) | 107 : m_localFrame(&localFrame) |
| 108 , m_draggedNode(draggedNode) | |
| 109 , m_bounds(bounds) | 108 , m_bounds(bounds) |
| 110 , m_opacity(opacity) | |
| 111 { | 109 { |
| 112 if (m_draggedNode && m_draggedNode->layoutObject()) | |
| 113 m_draggedNode->layoutObject()->updateDragState(true); | |
| 114 // TODO(oshima): Remove this when all platforms are migrated to use-zoom
-for-dsf. | 110 // TODO(oshima): Remove this when all platforms are migrated to use-zoom
-for-dsf. |
| 115 float deviceScaleFactor = m_localFrame->host()->deviceScaleFactorDepreca
ted(); | 111 float deviceScaleFactor = m_localFrame->host()->deviceScaleFactorDepreca
ted(); |
| 116 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor); | 112 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor); |
| 117 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor); | 113 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor); |
| 118 m_pictureBuilder = wrapUnique(new SkPictureBuilder(SkRect::MakeIWH(m_bou
nds.width(), m_bounds.height()))); | 114 m_pictureBuilder = wrapUnique(new SkPictureBuilder(SkRect::MakeIWH(m_bou
nds.width(), m_bounds.height()))); |
| 119 | 115 |
| 120 AffineTransform transform; | 116 AffineTransform transform; |
| 121 transform.scale(deviceScaleFactor, deviceScaleFactor); | 117 transform.scale(deviceScaleFactor, deviceScaleFactor); |
| 122 transform.translate(-m_bounds.x(), -m_bounds.y()); | 118 transform.translate(-m_bounds.x(), -m_bounds.y()); |
| 123 context().getPaintController().createAndAppend<BeginTransformDisplayItem
>(*m_pictureBuilder, transform); | 119 context().getPaintController().createAndAppend<BeginTransformDisplayItem
>(*m_pictureBuilder, transform); |
| 124 } | 120 } |
| 125 | 121 |
| 126 GraphicsContext& context() { return m_pictureBuilder->context(); } | 122 GraphicsContext& context() { return m_pictureBuilder->context(); } |
| 127 | 123 |
| 128 std::unique_ptr<DragImage> createImage() | 124 std::unique_ptr<DragImage> createImage( |
| 125 float opacity, |
| 126 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat
ion) |
| 129 { | 127 { |
| 130 if (m_draggedNode && m_draggedNode->layoutObject()) | |
| 131 m_draggedNode->layoutObject()->updateDragState(false); | |
| 132 context().getPaintController().endItem<EndTransformDisplayItem>(*m_pictu
reBuilder); | 128 context().getPaintController().endItem<EndTransformDisplayItem>(*m_pictu
reBuilder); |
| 133 // TODO(fmalita): endRecording() should return a non-const SKP. | 129 // TODO(fmalita): endRecording() should return a non-const SKP. |
| 134 sk_sp<SkPicture> recording(const_cast<SkPicture*>(m_pictureBuilder->endR
ecording().leakRef())); | 130 sk_sp<SkPicture> recording(const_cast<SkPicture*>(m_pictureBuilder->endR
ecording().leakRef())); |
| 135 RefPtr<SkImage> skImage = fromSkSp(SkImage::MakeFromPicture(std::move(re
cording), | 131 RefPtr<SkImage> skImage = fromSkSp(SkImage::MakeFromPicture(std::move(re
cording), |
| 136 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr
)); | 132 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr
)); |
| 137 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); | 133 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); |
| 138 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat
ion; | |
| 139 if (m_draggedNode && m_draggedNode->layoutObject()) | |
| 140 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra
ggedNode->layoutObject()); | |
| 141 | |
| 142 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr
eenInfo().deviceScaleFactor; | 134 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr
eenInfo().deviceScaleFactor; |
| 143 | 135 |
| 144 return DragImage::create(image.get(), imageOrientation, screenDeviceScal
eFactor, InterpolationHigh, m_opacity); | 136 return DragImage::create(image.get(), imageOrientation, screenDeviceScal
eFactor, InterpolationHigh, opacity); |
| 145 } | 137 } |
| 146 | 138 |
| 147 private: | 139 private: |
| 148 Member<const LocalFrame> m_localFrame; | 140 const Member<const LocalFrame> m_localFrame; |
| 149 Member<Node> m_draggedNode; | |
| 150 FloatRect m_bounds; | 141 FloatRect m_bounds; |
| 151 float m_opacity; | |
| 152 std::unique_ptr<SkPictureBuilder> m_pictureBuilder; | 142 std::unique_ptr<SkPictureBuilder> m_pictureBuilder; |
| 153 }; | 143 }; |
| 154 | 144 |
| 145 class NodeImageBuilder { |
| 146 STACK_ALLOCATED(); |
| 147 public: |
| 148 NodeImageBuilder(const LocalFrame& localFrame, const Node& node) |
| 149 : m_localFrame(&localFrame) |
| 150 , m_draggedLayoutObject(draggedLayoutObjectOf(localFrame, node)) |
| 151 #if DCHECK_IS_ON() |
| 152 , m_layoutCount(m_localFrame->view()->layoutCount()) |
| 153 #endif |
| 154 { |
| 155 } |
| 156 |
| 157 ~NodeImageBuilder() |
| 158 { |
| 159 DCHECK(isValid()); |
| 160 if (!m_draggedLayoutObject) |
| 161 return; |
| 162 DCHECK(m_draggedLayoutObject->isDragging()); |
| 163 m_draggedLayoutObject->updateDragState(false); |
| 164 } |
| 165 |
| 166 std::unique_ptr<DragImage> createImage() |
| 167 { |
| 168 DCHECK(isValid()); |
| 169 if (!m_draggedLayoutObject) |
| 170 return nullptr; |
| 171 // Paint starting at the nearest stacking context, clipped to the object |
| 172 // itself. This will also paint the contents behind the object if the |
| 173 // object contains transparency and there are other elements in the same |
| 174 // stacking context which stacked below. |
| 175 PaintLayer* layer = m_draggedLayoutObject->enclosingLayer(); |
| 176 if (!layer->stackingNode()->isStackingContext()) |
| 177 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(
); |
| 178 IntRect absoluteBoundingBox = m_draggedLayoutObject->absoluteBoundingBox
RectIncludingDescendants(); |
| 179 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(Float
Quad(absoluteBoundingBox), UseTransforms).boundingBox(); |
| 180 DragImageBuilder dragImageBuilder(*m_localFrame, boundingBox); |
| 181 { |
| 182 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox),
GlobalPaintFlattenCompositingLayers, LayoutSize()); |
| 183 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppli
edTransform | PaintLayerUncachedClipRects; |
| 184 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), pai
ntingInfo, flags); |
| 185 } |
| 186 return dragImageBuilder.createImage(1.0f, LayoutObject::shouldRespectIma
geOrientation(m_draggedLayoutObject)); |
| 187 } |
| 188 |
| 189 private: |
| 190 static LayoutObject* draggedLayoutObjectOf(const LocalFrame& localFrame, con
st Node& node) |
| 191 { |
| 192 // TODO(yosin): We should handle pseudo-class ":-webkit-drag" as similar |
| 193 // as ":hover" and ":active", rather than using flag in |LayoutObject|, |
| 194 // to avoid update layout tree here. |
| 195 localFrame.view()->updateAllLifecyclePhasesExceptPaint(); |
| 196 LayoutObject* layoutObject = node.layoutObject(); |
| 197 if (!layoutObject) |
| 198 return nullptr; |
| 199 // Update layout object for |node| with pseudo-class ":-webkit-drag". |
| 200 layoutObject->updateDragState(true); |
| 201 localFrame.view()->updateAllLifecyclePhasesExceptPaint(); |
| 202 // |node| with pseudo-class ":-webkit-drag" may blow away layout object. |
| 203 return node.layoutObject(); |
| 204 } |
| 205 |
| 206 bool isValid() const |
| 207 { |
| 208 #if DCHECK_IS_ON() |
| 209 return m_layoutCount == m_localFrame->view()->layoutCount(); |
| 210 #else |
| 211 return true; |
| 212 #endif |
| 213 } |
| 214 |
| 215 const Member<const LocalFrame> m_localFrame; |
| 216 |
| 217 // This class manages |isDrag()| of |m_draggedLayoutObject|. |
| 218 LayoutObject* const m_draggedLayoutObject; |
| 219 |
| 220 #if DCHECK_IS_ON() |
| 221 const int m_layoutCount; |
| 222 #endif |
| 223 }; |
| 224 |
| 155 inline float parentPageZoomFactor(LocalFrame* frame) | 225 inline float parentPageZoomFactor(LocalFrame* frame) |
| 156 { | 226 { |
| 157 Frame* parent = frame->tree().parent(); | 227 Frame* parent = frame->tree().parent(); |
| 158 if (!parent || !parent->isLocalFrame()) | 228 if (!parent || !parent->isLocalFrame()) |
| 159 return 1; | 229 return 1; |
| 160 return toLocalFrame(parent)->pageZoomFactor(); | 230 return toLocalFrame(parent)->pageZoomFactor(); |
| 161 } | 231 } |
| 162 | 232 |
| 163 inline float parentTextZoomFactor(LocalFrame* frame) | 233 inline float parentTextZoomFactor(LocalFrame* frame) |
| 164 { | 234 { |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 if (!m_host) | 661 if (!m_host) |
| 592 return 0; | 662 return 0; |
| 593 | 663 |
| 594 double ratio = m_host->deviceScaleFactorDeprecated(); | 664 double ratio = m_host->deviceScaleFactorDeprecated(); |
| 595 ratio *= pageZoomFactor(); | 665 ratio *= pageZoomFactor(); |
| 596 return ratio; | 666 return ratio; |
| 597 } | 667 } |
| 598 | 668 |
| 599 std::unique_ptr<DragImage> LocalFrame::nodeImage(Node& node) | 669 std::unique_ptr<DragImage> LocalFrame::nodeImage(Node& node) |
| 600 { | 670 { |
| 601 m_view->updateAllLifecyclePhasesExceptPaint(); | 671 NodeImageBuilder imageNode(*this, node); |
| 602 LayoutObject* layoutObject = node.layoutObject(); | 672 return imageNode.createImage(); |
| 603 if (!layoutObject) | |
| 604 return nullptr; | |
| 605 | |
| 606 // 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 | |
| 608 // and there are other elements in the same stacking context which stacked b
elow. | |
| 609 PaintLayer* layer = layoutObject->enclosingLayer(); | |
| 610 if (!layer->stackingNode()->isStackingContext()) | |
| 611 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); | |
| 612 IntRect absoluteBoundingBox = layoutObject->absoluteBoundingBoxRectIncluding
Descendants(); | |
| 613 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(FloatQuad
(absoluteBoundingBox), UseTransforms).boundingBox(); | |
| 614 DragImageBuilder dragImageBuilder(this, boundingBox, &node); | |
| 615 { | |
| 616 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), Glob
alPaintFlattenCompositingLayers, LayoutSize()); | |
| 617 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppliedTr
ansform | PaintLayerUncachedClipRects; | |
| 618 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), paintin
gInfo, flags); | |
| 619 } | |
| 620 return dragImageBuilder.createImage(); | |
| 621 } | 673 } |
| 622 | 674 |
| 623 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) | 675 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) |
| 624 { | 676 { |
| 625 if (!selection().isRange()) | 677 if (!selection().isRange()) |
| 626 return nullptr; | 678 return nullptr; |
| 627 | 679 |
| 628 m_view->updateAllLifecyclePhasesExceptPaint(); | 680 m_view->updateAllLifecyclePhasesExceptPaint(); |
| 629 ASSERT(document()->isActive()); | 681 ASSERT(document()->isActive()); |
| 630 | 682 |
| 631 FloatRect paintingRect = FloatRect(selection().bounds()); | 683 FloatRect paintingRect = FloatRect(selection().bounds()); |
| 632 DragImageBuilder dragImageBuilder(this, paintingRect, nullptr, opacity); | 684 DragImageBuilder dragImageBuilder(*this, paintingRect); |
| 633 GlobalPaintFlags paintFlags = GlobalPaintSelectionOnly | GlobalPaintFlattenC
ompositingLayers; | 685 GlobalPaintFlags paintFlags = GlobalPaintSelectionOnly | GlobalPaintFlattenC
ompositingLayers; |
| 634 m_view->paintContents(dragImageBuilder.context(), paintFlags, enclosingIntRe
ct(paintingRect)); | 686 m_view->paintContents(dragImageBuilder.context(), paintFlags, enclosingIntRe
ct(paintingRect)); |
| 635 return dragImageBuilder.createImage(); | 687 return dragImageBuilder.createImage(opacity); |
| 636 } | 688 } |
| 637 | 689 |
| 638 String LocalFrame::selectedText() const | 690 String LocalFrame::selectedText() const |
| 639 { | 691 { |
| 640 return selection().selectedText(); | 692 return selection().selectedText(); |
| 641 } | 693 } |
| 642 | 694 |
| 643 String LocalFrame::selectedTextForClipboard() const | 695 String LocalFrame::selectedTextForClipboard() const |
| 644 { | 696 { |
| 645 return selection().selectedTextForClipboard(); | 697 return selection().selectedTextForClipboard(); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 m_frame->client()->frameBlameContext()->Enter(); | 882 m_frame->client()->frameBlameContext()->Enter(); |
| 831 } | 883 } |
| 832 | 884 |
| 833 ScopedFrameBlamer::~ScopedFrameBlamer() | 885 ScopedFrameBlamer::~ScopedFrameBlamer() |
| 834 { | 886 { |
| 835 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) | 887 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) |
| 836 m_frame->client()->frameBlameContext()->Leave(); | 888 m_frame->client()->frameBlameContext()->Leave(); |
| 837 } | 889 } |
| 838 | 890 |
| 839 } // namespace blink | 891 } // namespace blink |
| OLD | NEW |