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

Unified Diff: third_party/WebKit/Source/core/frame/LocalFrame.cpp

Issue 2916043002: Move LocalFrame::DragImageForSelection DragController (Closed)
Patch Set: updated Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/LocalFrame.cpp
diff --git a/third_party/WebKit/Source/core/frame/LocalFrame.cpp b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
index 3eefa4fb1b4e989b32a932a7221951863416ce44..7b91a44c07e7e88c8977a7a508205471a64f87f7 100644
--- a/third_party/WebKit/Source/core/frame/LocalFrame.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
@@ -52,7 +52,6 @@
#include "core/frame/LocalFrameView.h"
#include "core/frame/PerformanceMonitor.h"
#include "core/frame/Settings.h"
-#include "core/frame/VisualViewport.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLPlugInElement.h"
#include "core/html/PluginDocument.h"
@@ -66,31 +65,22 @@
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoadRequest.h"
#include "core/loader/NavigationScheduler.h"
-#include "core/page/ChromeClient.h"
#include "core/page/FocusController.h"
-#include "core/page/Page.h"
#include "core/page/scrolling/ScrollingCoordinator.h"
#include "core/paint/ObjectPainter.h"
-#include "core/paint/PaintInfo.h"
-#include "core/paint/PaintLayer.h"
-#include "core/paint/PaintLayerPainter.h"
#include "core/paint/TransformRecorder.h"
#include "core/plugins/PluginView.h"
#include "core/probe/CoreProbes.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/timing/Performance.h"
-#include "platform/DragImage.h"
#include "platform/Histogram.h"
#include "platform/PluginScriptForbiddenScope.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/ScriptForbiddenScope.h"
#include "platform/WebFrameScheduler.h"
-#include "platform/graphics/GraphicsContext.h"
-#include "platform/graphics/StaticBitmapImage.h"
#include "platform/graphics/paint/ClipRecorder.h"
#include "platform/graphics/paint/PaintCanvas.h"
#include "platform/graphics/paint/PaintController.h"
-#include "platform/graphics/paint/PaintRecordBuilder.h"
#include "platform/graphics/paint/TransformDisplayItem.h"
#include "platform/json/JSONValues.h"
#include "platform/loader/fetch/FetchParameters.h"
@@ -103,10 +93,7 @@
#include "platform/wtf/StdLibExtras.h"
#include "public/platform/InterfaceProvider.h"
#include "public/platform/InterfaceRegistry.h"
-#include "public/platform/WebScreenInfo.h"
#include "public/platform/WebURLRequest.h"
-#include "third_party/skia/include/core/SkImage.h"
-#include "third_party/skia/include/core/SkSurface.h"
namespace blink {
@@ -114,133 +101,6 @@ using namespace HTMLNames;
namespace {
-// Converts from bounds in CSS space to device space based on the given
-// frame.
-static FloatRect DeviceSpaceBounds(const FloatRect css_bounds,
- const LocalFrame& frame) {
- float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated();
- float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale();
- FloatRect device_bounds(css_bounds);
- device_bounds.SetWidth(css_bounds.Width() * device_scale_factor *
- page_scale_factor);
- device_bounds.SetHeight(css_bounds.Height() * device_scale_factor *
- page_scale_factor);
- return device_bounds;
-}
-
-// Returns a DragImage whose bitmap contains |contents|, positioned and scaled
-// in device space.
-static std::unique_ptr<DragImage> CreateDragImage(
- const LocalFrame& frame,
- float opacity,
- RespectImageOrientationEnum image_orientation,
- const FloatRect& css_bounds,
- PaintRecordBuilder& builder,
- const PropertyTreeState& property_tree_state) {
- float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated();
- float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale();
-
- FloatRect device_bounds = DeviceSpaceBounds(css_bounds, frame);
-
- AffineTransform transform;
- transform.Scale(device_scale_factor * page_scale_factor);
- transform.Translate(-device_bounds.X(), -device_bounds.Y());
-
- // Rasterize upfront, since DragImage::create() is going to do it anyway
- // (SkImage::asLegacyBitmap).
- SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry);
- sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
- device_bounds.Width(), device_bounds.Height(), &surface_props);
- if (!surface)
- return nullptr;
-
- SkiaPaintCanvas skia_paint_canvas(surface->getCanvas());
- skia_paint_canvas.concat(AffineTransformToSkMatrix(transform));
- builder.EndRecording(skia_paint_canvas, property_tree_state);
-
- RefPtr<Image> image = StaticBitmapImage::Create(surface->makeImageSnapshot());
- float screen_device_scale_factor =
- frame.GetPage()->GetChromeClient().GetScreenInfo().device_scale_factor;
-
- return DragImage::Create(image.Get(), image_orientation,
- screen_device_scale_factor, kInterpolationHigh,
- opacity);
-}
-
-class DraggedNodeImageBuilder {
- STACK_ALLOCATED();
-
- public:
- DraggedNodeImageBuilder(const LocalFrame& local_frame, Node& node)
- : local_frame_(&local_frame),
- node_(&node)
-#if DCHECK_IS_ON()
- ,
- dom_tree_version_(node.GetDocument().DomTreeVersion())
-#endif
- {
- for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_))
- descendant.SetDragged(true);
- }
-
- ~DraggedNodeImageBuilder() {
-#if DCHECK_IS_ON()
- DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion());
-#endif
- for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_))
- descendant.SetDragged(false);
- }
-
- std::unique_ptr<DragImage> CreateImage() {
-#if DCHECK_IS_ON()
- DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion());
-#endif
- // Construct layout object for |m_node| with pseudo class "-webkit-drag"
- local_frame_->View()->UpdateAllLifecyclePhasesExceptPaint();
- LayoutObject* const dragged_layout_object = node_->GetLayoutObject();
- if (!dragged_layout_object)
- return nullptr;
- // Paint starting at the nearest stacking context, clipped to the object
- // itself. This will also paint the contents behind the object if the
- // object contains transparency and there are other elements in the same
- // stacking context which stacked below.
- PaintLayer* layer = dragged_layout_object->EnclosingLayer();
- if (!layer->StackingNode()->IsStackingContext())
- layer = layer->StackingNode()->AncestorStackingContextNode()->Layer();
- IntRect absolute_bounding_box =
- dragged_layout_object->AbsoluteBoundingBoxRectIncludingDescendants();
- FloatRect bounding_box =
- layer->GetLayoutObject()
- .AbsoluteToLocalQuad(FloatQuad(absolute_bounding_box),
- kUseTransforms)
- .BoundingBox();
- PaintLayerPaintingInfo painting_info(layer, LayoutRect(bounding_box),
- kGlobalPaintFlattenCompositingLayers,
- LayoutSize());
- PaintLayerFlags flags = kPaintLayerHaveTransparency |
- kPaintLayerAppliedTransform |
- kPaintLayerUncachedClipRects;
- PaintRecordBuilder builder(DeviceSpaceBounds(bounding_box, *local_frame_));
- PaintLayerPainter(*layer).Paint(builder.Context(), painting_info, flags);
- PropertyTreeState border_box_properties = PropertyTreeState::Root();
- if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
- border_box_properties =
- *layer->GetLayoutObject().LocalBorderBoxProperties();
- }
- return CreateDragImage(
- *local_frame_, 1.0f,
- LayoutObject::ShouldRespectImageOrientation(dragged_layout_object),
- bounding_box, builder, border_box_properties);
- }
-
- private:
- const Member<const LocalFrame> local_frame_;
- const Member<Node> node_;
-#if DCHECK_IS_ON()
- const uint64_t dom_tree_version_;
-#endif
-};
-
inline float ParentPageZoomFactor(LocalFrame* frame) {
Frame* parent = frame->Tree().Parent();
if (!parent || !parent->IsLocalFrame())
@@ -740,29 +600,6 @@ double LocalFrame::DevicePixelRatio() const {
return ratio;
}
-std::unique_ptr<DragImage> LocalFrame::NodeImage(Node& node) {
- DraggedNodeImageBuilder image_node(*this, node);
- return image_node.CreateImage();
-}
-
-std::unique_ptr<DragImage> LocalFrame::DragImageForSelection(float opacity) {
- if (!Selection().ComputeVisibleSelectionInDOMTreeDeprecated().IsRange())
- return nullptr;
-
- view_->UpdateAllLifecyclePhasesExceptPaint();
- DCHECK(GetDocument()->IsActive());
-
- FloatRect painting_rect = FloatRect(Selection().Bounds());
- GlobalPaintFlags paint_flags =
- kGlobalPaintSelectionOnly | kGlobalPaintFlattenCompositingLayers;
-
- PaintRecordBuilder builder(DeviceSpaceBounds(painting_rect, *this));
- view_->PaintContents(builder.Context(), paint_flags,
- EnclosingIntRect(painting_rect));
- return CreateDragImage(*this, opacity, kDoNotRespectImageOrientation,
- painting_rect, builder, PropertyTreeState::Root());
-}
-
String LocalFrame::SelectedText() const {
return Selection().SelectedText();
}

Powered by Google App Engine
This is Rietveld 408576698