Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: third_party/WebKit/Source/core/frame/LocalFrame.cpp

Issue 2094653002: Make LocalFrame::nodeImage() to take an image for the element with :-webkit-drag pseudo class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-06-23T15:48:19 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, Layo utObject* layoutObject, float opacity = 1)
107 : m_localFrame(localFrame) 107 : m_localFrame(localFrame)
108 , m_draggedNode(draggedNode) 108 , m_draggedLayoutObject(layoutObject)
109 , m_bounds(bounds) 109 , m_bounds(bounds)
110 , m_opacity(opacity) 110 , m_opacity(opacity)
111 { 111 {
112 if (m_draggedNode && m_draggedNode->layoutObject()) 112 DCHECK(!m_draggedLayoutObject || m_draggedLayoutObject->isDragging());
113 m_draggedNode->layoutObject()->updateDragState(true);
114 // TODO(oshima): Remove this when all platforms are migrated to use-zoom -for-dsf. 113 // TODO(oshima): Remove this when all platforms are migrated to use-zoom -for-dsf.
115 float deviceScaleFactor = m_localFrame->host()->deviceScaleFactorDepreca ted(); 114 float deviceScaleFactor = m_localFrame->host()->deviceScaleFactorDepreca ted();
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 = wrapUnique(new SkPictureBuilder(SkRect::MakeIWH(m_bou nds.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
125 ~DragImageBuilder()
126 {
127 if (!m_draggedLayoutObject)
128 return;
129 DCHECK(m_draggedLayoutObject->isDragging());
130 m_draggedLayoutObject->updateDragState(false);
131 }
132
126 GraphicsContext& context() { return m_pictureBuilder->context(); } 133 GraphicsContext& context() { return m_pictureBuilder->context(); }
127 134
128 std::unique_ptr<DragImage> createImage() 135 std::unique_ptr<DragImage> createImage()
129 { 136 {
130 if (m_draggedNode && m_draggedNode->layoutObject())
131 m_draggedNode->layoutObject()->updateDragState(false);
132 context().getPaintController().endItem<EndTransformDisplayItem>(*m_pictu reBuilder); 137 context().getPaintController().endItem<EndTransformDisplayItem>(*m_pictu reBuilder);
133 // TODO(fmalita): endRecording() should return a non-const SKP. 138 // TODO(fmalita): endRecording() should return a non-const SKP.
134 sk_sp<SkPicture> recording(const_cast<SkPicture*>(m_pictureBuilder->endR ecording().leakRef())); 139 sk_sp<SkPicture> recording(const_cast<SkPicture*>(m_pictureBuilder->endR ecording().leakRef()));
135 RefPtr<SkImage> skImage = fromSkSp(SkImage::MakeFromPicture(std::move(re cording), 140 RefPtr<SkImage> skImage = fromSkSp(SkImage::MakeFromPicture(std::move(re cording),
136 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr )); 141 SkISize::Make(m_bounds.width(), m_bounds.height()), nullptr, nullptr ));
137 RefPtr<Image> image = StaticBitmapImage::create(skImage.release()); 142 RefPtr<Image> image = StaticBitmapImage::create(skImage.release());
138 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat ion; 143 RespectImageOrientationEnum imageOrientation = DoNotRespectImageOrientat ion;
139 if (m_draggedNode && m_draggedNode->layoutObject()) 144 if (m_draggedLayoutObject)
140 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra ggedNode->layoutObject()); 145 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra ggedLayoutObject);
141 146
142 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr eenInfo().deviceScaleFactor; 147 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr eenInfo().deviceScaleFactor;
143 148
144 return DragImage::create(image.get(), imageOrientation, screenDeviceScal eFactor, InterpolationHigh, m_opacity); 149 return DragImage::create(image.get(), imageOrientation, screenDeviceScal eFactor, InterpolationHigh, m_opacity);
145 } 150 }
146 151
147 private: 152 private:
148 Member<const LocalFrame> m_localFrame; 153 Member<const LocalFrame> m_localFrame;
149 Member<Node> m_draggedNode; 154 LayoutObject* const m_draggedLayoutObject;
pdr. 2016/06/23 20:29:13 Why "LayoutObject* const" instead of "const Layout
yosin_UTC9 2016/06/24 06:02:57 |m_layoutObject| is read-only member and |LayoutOb
150 FloatRect m_bounds; 155 FloatRect m_bounds;
151 float m_opacity; 156 float const m_opacity;
152 std::unique_ptr<SkPictureBuilder> m_pictureBuilder; 157 std::unique_ptr<SkPictureBuilder> m_pictureBuilder;
153 }; 158 };
154 159
155 inline float parentPageZoomFactor(LocalFrame* frame) 160 inline float parentPageZoomFactor(LocalFrame* frame)
156 { 161 {
157 Frame* parent = frame->tree().parent(); 162 Frame* parent = frame->tree().parent();
158 if (!parent || !parent->isLocalFrame()) 163 if (!parent || !parent->isLocalFrame())
159 return 1; 164 return 1;
160 return toLocalFrame(parent)->pageZoomFactor(); 165 return toLocalFrame(parent)->pageZoomFactor();
161 } 166 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 if (!m_host) 596 if (!m_host)
592 return 0; 597 return 0;
593 598
594 double ratio = m_host->deviceScaleFactorDeprecated(); 599 double ratio = m_host->deviceScaleFactorDeprecated();
595 ratio *= pageZoomFactor(); 600 ratio *= pageZoomFactor();
596 return ratio; 601 return ratio;
597 } 602 }
598 603
599 std::unique_ptr<DragImage> LocalFrame::nodeImage(Node& node) 604 std::unique_ptr<DragImage> LocalFrame::nodeImage(Node& node)
600 { 605 {
606 // TODO(yosin): We should handle pseudo-class ":drag" as similar as
pdr. 2016/06/23 20:29:13 I was a little confused by ":drag", I think we use
yosin_UTC9 2016/06/24 06:02:57 Done.
607 // ":hover" and ":active", rather than using flag in |LayoutObject|, to
608 // avoid update layout tree here.
601 m_view->updateAllLifecyclePhasesExceptPaint(); 609 m_view->updateAllLifecyclePhasesExceptPaint();
602 LayoutObject* layoutObject = node.layoutObject(); 610 LayoutObject* layoutObject = node.layoutObject();
603 if (!layoutObject) 611 if (!layoutObject)
604 return nullptr; 612 return nullptr;
605 613
614 // Update layout object for |node| with pseudo-class ":drag".
615 layoutObject->updateDragState(true);
pdr. 2016/06/23 20:29:13 Previously, calling updateDragState was the respon
yosin_UTC9 2016/06/24 06:02:57 I introduce |NodeImageBuilder| class and make its
616 m_view->updateAllLifecyclePhasesExceptPaint();
617 // |node| with pseudo-class ":drag" may blow away layout object.
618 layoutObject = node.layoutObject();
619 if (!layoutObject)
620 return nullptr;
606 // Paint starting at the nearest stacking context, clipped to the object its elf. 621 // 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 622 // 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. 623 // and there are other elements in the same stacking context which stacked b elow.
609 PaintLayer* layer = layoutObject->enclosingLayer(); 624 PaintLayer* layer = layoutObject->enclosingLayer();
610 if (!layer->stackingNode()->isStackingContext()) 625 if (!layer->stackingNode()->isStackingContext())
611 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); 626 layer = layer->stackingNode()->ancestorStackingContextNode()->layer();
612 IntRect absoluteBoundingBox = layoutObject->absoluteBoundingBoxRectIncluding Descendants(); 627 IntRect absoluteBoundingBox = layoutObject->absoluteBoundingBoxRectIncluding Descendants();
613 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(FloatQuad (absoluteBoundingBox), UseTransforms).boundingBox(); 628 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(FloatQuad (absoluteBoundingBox), UseTransforms).boundingBox();
614 DragImageBuilder dragImageBuilder(this, boundingBox, &node); 629 DragImageBuilder dragImageBuilder(this, boundingBox, layoutObject);
615 { 630 {
616 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), Glob alPaintFlattenCompositingLayers, LayoutSize()); 631 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), Glob alPaintFlattenCompositingLayers, LayoutSize());
617 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppliedTr ansform | PaintLayerUncachedClipRects; 632 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppliedTr ansform | PaintLayerUncachedClipRects;
618 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), paintin gInfo, flags); 633 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), paintin gInfo, flags);
619 } 634 }
620 return dragImageBuilder.createImage(); 635 return dragImageBuilder.createImage();
621 } 636 }
622 637
623 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) 638 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity)
624 { 639 {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 m_frame->client()->frameBlameContext()->Enter(); 845 m_frame->client()->frameBlameContext()->Enter();
831 } 846 }
832 847
833 ScopedFrameBlamer::~ScopedFrameBlamer() 848 ScopedFrameBlamer::~ScopedFrameBlamer()
834 { 849 {
835 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) 850 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext())
836 m_frame->client()->frameBlameContext()->Leave(); 851 m_frame->client()->frameBlameContext()->Leave();
837 } 852 }
838 853
839 } // namespace blink 854 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698