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

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

Issue 1736893002: Update drag images to paint from the nearest self painting layer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failures, add a test Created 4 years, 10 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 namespace { 91 namespace {
92 92
93 // Convenience class for initializing a GraphicsContext to build a DragImage fro m a specific 93 // Convenience class for initializing a GraphicsContext to build a DragImage fro m a specific
94 // region specified by |bounds|. After painting the using context(), the DragIma ge returned from 94 // region specified by |bounds|. After painting the using context(), the DragIma ge returned from
95 // createImage() will only contain the content in |bounds| with the appropriate device scale 95 // createImage() will only contain the content in |bounds| with the appropriate device scale
96 // factor included. 96 // factor included.
97 class DragImageBuilder { 97 class DragImageBuilder {
98 STACK_ALLOCATED(); 98 STACK_ALLOCATED();
99 public: 99 public:
100 DragImageBuilder(const LocalFrame* localFrame, const IntRect& bounds, Node* draggedNode, float opacity = 1) 100 DragImageBuilder(const LocalFrame* localFrame, const FloatRect& bounds, Node * draggedNode, float opacity = 1)
101 : m_localFrame(localFrame) 101 : m_localFrame(localFrame)
102 , m_draggedNode(draggedNode) 102 , m_draggedNode(draggedNode)
103 , m_bounds(bounds) 103 , m_bounds(bounds)
104 , m_opacity(opacity) 104 , m_opacity(opacity)
105 { 105 {
106 if (m_draggedNode && m_draggedNode->layoutObject()) 106 if (m_draggedNode && m_draggedNode->layoutObject())
107 m_draggedNode->layoutObject()->updateDragState(true); 107 m_draggedNode->layoutObject()->updateDragState(true);
108 108
109 float deviceScaleFactor = m_localFrame->host()->deviceScaleFactor(); 109 float deviceScaleFactor = m_localFrame->host()->deviceScaleFactor();
110 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor); 110 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor);
(...skipping 22 matching lines...) Expand all
133 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra ggedNode->layoutObject()); 133 imageOrientation = LayoutObject::shouldRespectImageOrientation(m_dra ggedNode->layoutObject());
134 134
135 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr eenInfo().deviceScaleFactor; 135 float screenDeviceScaleFactor = m_localFrame->page()->chromeClient().scr eenInfo().deviceScaleFactor;
136 136
137 return DragImage::create(image.get(), imageOrientation, screenDeviceScal eFactor, InterpolationHigh, m_opacity); 137 return DragImage::create(image.get(), imageOrientation, screenDeviceScal eFactor, InterpolationHigh, m_opacity);
138 } 138 }
139 139
140 private: 140 private:
141 RawPtrWillBeMember<const LocalFrame> m_localFrame; 141 RawPtrWillBeMember<const LocalFrame> m_localFrame;
142 RawPtrWillBeMember<Node> m_draggedNode; 142 RawPtrWillBeMember<Node> m_draggedNode;
143 IntRect m_bounds; 143 FloatRect m_bounds;
144 float m_opacity; 144 float m_opacity;
145 OwnPtr<SkPictureBuilder> m_pictureBuilder; 145 OwnPtr<SkPictureBuilder> m_pictureBuilder;
146 }; 146 };
147 147
148 inline float parentPageZoomFactor(LocalFrame* frame) 148 inline float parentPageZoomFactor(LocalFrame* frame)
149 { 149 {
150 Frame* parent = frame->tree().parent(); 150 Frame* parent = frame->tree().parent();
151 if (!parent || !parent->isLocalFrame()) 151 if (!parent || !parent->isLocalFrame())
152 return 1; 152 return 1;
153 return toLocalFrame(parent)->pageZoomFactor(); 153 return toLocalFrame(parent)->pageZoomFactor();
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 double LocalFrame::devicePixelRatio() const 624 double LocalFrame::devicePixelRatio() const
625 { 625 {
626 if (!m_host) 626 if (!m_host)
627 return 0; 627 return 0;
628 628
629 double ratio = m_host->deviceScaleFactor(); 629 double ratio = m_host->deviceScaleFactor();
630 ratio *= pageZoomFactor(); 630 ratio *= pageZoomFactor();
631 return ratio; 631 return ratio;
632 } 632 }
633 633
634 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage(const GlobalPaintFlags glob alPaintFlags,
635 IntRect paintingRect, Node* draggedNode, float opacity)
636 {
637 ASSERT(document()->isActive());
638 // Not flattening compositing layers will result in a broken image being pai nted.
639 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers);
640
641 DragImageBuilder dragImageBuilder(this, paintingRect, draggedNode, opacity);
642 m_view->paintContents(dragImageBuilder.context(), globalPaintFlags, painting Rect);
643 return dragImageBuilder.createImage();
644 }
645
646 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) 634 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node)
647 { 635 {
648 m_view->updateAllLifecyclePhases(); 636 m_view->updateAllLifecyclePhases();
649 LayoutObject* layoutObject = node.layoutObject(); 637 LayoutObject* layoutObject = node.layoutObject();
650 if (!layoutObject) 638 if (!layoutObject)
651 return nullptr; 639 return nullptr;
652 640
653 // Directly paint boxes as if they are a stacking context. 641 // Paint starting at the nearest painting layer, clipped to the object itsel f.
chrishtr 2016/02/26 18:31:05 s/painting layer/self-painting PaintLayer/.
pdr. 2016/02/26 18:41:38 It's not necessarily the nearest self painting lay
chrishtr 2016/02/26 18:58:53 I don't think the hasSelfPaintingLayerDescendant()
pdr. 2016/02/26 19:28:02 Cool, this makes sense. I've updated this cl to us
654 if (layoutObject->isBox() && layoutObject->container()) { 642 // TODO(pdr): This will also paint the content behind the object if the obje ct contains
655 IntRect boundingBox = layoutObject->absoluteBoundingBoxRectIncludingDesc endants(); 643 // transparency but the layer is opaque. We could directly call layoutObject ->paint(...)
656 LayoutPoint paintOffset = boundingBox.location() - layoutObject->offsetF romContainer(layoutObject->container(), LayoutPoint()); 644 // (see: ObjectPainter::paintAsPseudoStackingContext) but this would skip co mposited children.
chrishtr 2016/02/26 18:31:05 s/composited children/self-painting PaintLayer chi
pdr. 2016/02/26 19:28:02 Done
645 PaintLayer* layer = layoutObject->enclosingLayer();
646 // Find the first layer that will paint content, otherwise the paintLayer ca ll will be a noop.
647 while (layer && !(layer->isSelfPaintingLayer() || layer->hasSelfPaintingLaye rDescendant()))
chrishtr 2016/02/26 18:31:05 How about putting this method on PaintLayer? Paint
pdr. 2016/02/26 19:28:02 Done.
648 layer = layer->parent();
657 649
658 DragImageBuilder dragImageBuilder(this, boundingBox, &node); 650 IntRect absoluteBoundingBox = layoutObject->absoluteBoundingBoxRectIncluding Descendants();
chrishtr 2016/02/26 18:31:05 How about layer->boundingBoxForCompositing() inste
pdr. 2016/02/26 18:41:38 boundingBoxForCompositing would be the layer's bou
chrishtr 2016/02/26 18:58:53 boundingBoxForCompositing is the bounds of the Lay
pdr. 2016/02/26 19:28:02 I don't think we can do this because text needs to
chrishtr 2016/02/26 19:36:27 Oh, I see, you're leaving clipToDirtyRect true on
659 { 651 FloatRect boundingBox = layer->layoutObject()->absoluteToLocalQuad(FloatQuad (absoluteBoundingBox), UseTransforms).boundingBox();
660 PaintInfo paintInfo(dragImageBuilder.context(), boundingBox, PaintPh ase::PaintPhaseForeground, GlobalPaintFlattenCompositingLayers, 0); 652 DragImageBuilder dragImageBuilder(this, boundingBox, &node);
661 ObjectPainter(*layoutObject).paintAsPseudoStackingContext(paintInfo, LayoutPoint(paintOffset)); 653 {
662 } 654 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), Glob alPaintFlattenCompositingLayers, LayoutSize(), 0);
663 return dragImageBuilder.createImage(); 655 PaintLayerFlags flags = PaintLayerHaveTransparency | PaintLayerAppliedTr ansform | PaintLayerUncachedClipRects;
656 PaintLayerPainter(*layer).paintLayer(dragImageBuilder.context(), paintin gInfo, flags);
664 } 657 }
665 658 return dragImageBuilder.createImage();
666 // TODO(pdr): This will also paint the background if the object contains tra nsparency. We can
667 // directly call layoutObject->paint(...) (see: ObjectPainter::paintAsPseudo StackingContext) but
668 // painters are inconsistent about which transform space they expect (see: s vg, inlines, etc.)
669 // TODO(pdr): SVG and inlines are painted offset (crbug.com/579153, crbug.co m/579158).
670 return paintIntoDragImage(GlobalPaintFlattenCompositingLayers, layoutObject- >absoluteBoundingBoxRectIncludingDescendants(), &node);
671 } 659 }
672 660
673 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity) 661 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity)
674 { 662 {
675 if (!selection().isRange()) 663 if (!selection().isRange())
676 return nullptr; 664 return nullptr;
677 665
678 m_view->updateAllLifecyclePhases(); 666 m_view->updateAllLifecyclePhases();
667 ASSERT(document()->isActive());
679 668
680 return paintIntoDragImage(GlobalPaintSelectionOnly | GlobalPaintFlattenCompo sitingLayers, 669 FloatRect paintingRect = FloatRect(selection().bounds());
681 enclosingIntRect(selection().bounds()), nullptr, opacity); 670 DragImageBuilder dragImageBuilder(this, paintingRect, nullptr, opacity);
671 GlobalPaintFlags paintFlags = GlobalPaintSelectionOnly | GlobalPaintFlattenC ompositingLayers;
672 m_view->paintContents(dragImageBuilder.context(), paintFlags, enclosingIntRe ct(paintingRect));
chrishtr 2016/02/26 18:31:05 Here you're giving up on the common code solution?
pdr. 2016/02/26 18:41:38 This is just a small refactoring mentioned in the
chrishtr 2016/02/26 18:58:53 Ah ok. I think the refactoring as stated in the CL
673 return dragImageBuilder.createImage();
682 } 674 }
683 675
684 String LocalFrame::selectedText() const 676 String LocalFrame::selectedText() const
685 { 677 {
686 return selection().selectedText(); 678 return selection().selectedText();
687 } 679 }
688 680
689 String LocalFrame::selectedTextForClipboard() const 681 String LocalFrame::selectedTextForClipboard() const
690 { 682 {
691 return selection().selectedTextForClipboard(); 683 return selection().selectedTextForClipboard();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 { 881 {
890 m_frame->disableNavigation(); 882 m_frame->disableNavigation();
891 } 883 }
892 884
893 FrameNavigationDisabler::~FrameNavigationDisabler() 885 FrameNavigationDisabler::~FrameNavigationDisabler()
894 { 886 {
895 m_frame->enableNavigation(); 887 m_frame->enableNavigation();
896 } 888 }
897 889
898 } // namespace blink 890 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/LocalFrame.h ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698