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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "core/editing/spellcheck/SpellChecker.h" | 45 #include "core/editing/spellcheck/SpellChecker.h" |
46 #include "core/events/Event.h" | 46 #include "core/events/Event.h" |
47 #include "core/frame/ContentSettingsClient.h" | 47 #include "core/frame/ContentSettingsClient.h" |
48 #include "core/frame/EventHandlerRegistry.h" | 48 #include "core/frame/EventHandlerRegistry.h" |
49 #include "core/frame/FrameConsole.h" | 49 #include "core/frame/FrameConsole.h" |
50 #include "core/frame/LocalDOMWindow.h" | 50 #include "core/frame/LocalDOMWindow.h" |
51 #include "core/frame/LocalFrameClient.h" | 51 #include "core/frame/LocalFrameClient.h" |
52 #include "core/frame/LocalFrameView.h" | 52 #include "core/frame/LocalFrameView.h" |
53 #include "core/frame/PerformanceMonitor.h" | 53 #include "core/frame/PerformanceMonitor.h" |
54 #include "core/frame/Settings.h" | 54 #include "core/frame/Settings.h" |
55 #include "core/frame/VisualViewport.h" | |
56 #include "core/html/HTMLFrameElementBase.h" | 55 #include "core/html/HTMLFrameElementBase.h" |
57 #include "core/html/HTMLPlugInElement.h" | 56 #include "core/html/HTMLPlugInElement.h" |
58 #include "core/html/PluginDocument.h" | 57 #include "core/html/PluginDocument.h" |
59 #include "core/input/EventHandler.h" | 58 #include "core/input/EventHandler.h" |
60 #include "core/inspector/ConsoleMessage.h" | 59 #include "core/inspector/ConsoleMessage.h" |
61 #include "core/layout/HitTestResult.h" | 60 #include "core/layout/HitTestResult.h" |
62 #include "core/layout/LayoutView.h" | 61 #include "core/layout/LayoutView.h" |
63 #include "core/layout/api/LayoutPartItem.h" | 62 #include "core/layout/api/LayoutPartItem.h" |
64 #include "core/layout/api/LayoutViewItem.h" | 63 #include "core/layout/api/LayoutViewItem.h" |
65 #include "core/layout/compositing/PaintLayerCompositor.h" | 64 #include "core/layout/compositing/PaintLayerCompositor.h" |
66 #include "core/loader/DocumentLoader.h" | 65 #include "core/loader/DocumentLoader.h" |
67 #include "core/loader/FrameLoadRequest.h" | 66 #include "core/loader/FrameLoadRequest.h" |
68 #include "core/loader/NavigationScheduler.h" | 67 #include "core/loader/NavigationScheduler.h" |
69 #include "core/page/ChromeClient.h" | |
70 #include "core/page/FocusController.h" | 68 #include "core/page/FocusController.h" |
71 #include "core/page/Page.h" | |
72 #include "core/page/scrolling/ScrollingCoordinator.h" | 69 #include "core/page/scrolling/ScrollingCoordinator.h" |
73 #include "core/paint/ObjectPainter.h" | 70 #include "core/paint/ObjectPainter.h" |
74 #include "core/paint/PaintInfo.h" | |
75 #include "core/paint/PaintLayer.h" | |
76 #include "core/paint/PaintLayerPainter.h" | |
77 #include "core/paint/TransformRecorder.h" | 71 #include "core/paint/TransformRecorder.h" |
78 #include "core/plugins/PluginView.h" | 72 #include "core/plugins/PluginView.h" |
79 #include "core/probe/CoreProbes.h" | 73 #include "core/probe/CoreProbes.h" |
80 #include "core/svg/SVGDocumentExtensions.h" | 74 #include "core/svg/SVGDocumentExtensions.h" |
81 #include "core/timing/Performance.h" | 75 #include "core/timing/Performance.h" |
82 #include "platform/DragImage.h" | |
83 #include "platform/Histogram.h" | 76 #include "platform/Histogram.h" |
84 #include "platform/PluginScriptForbiddenScope.h" | 77 #include "platform/PluginScriptForbiddenScope.h" |
85 #include "platform/RuntimeEnabledFeatures.h" | 78 #include "platform/RuntimeEnabledFeatures.h" |
86 #include "platform/ScriptForbiddenScope.h" | 79 #include "platform/ScriptForbiddenScope.h" |
87 #include "platform/WebFrameScheduler.h" | 80 #include "platform/WebFrameScheduler.h" |
88 #include "platform/graphics/GraphicsContext.h" | |
89 #include "platform/graphics/StaticBitmapImage.h" | |
90 #include "platform/graphics/paint/ClipRecorder.h" | 81 #include "platform/graphics/paint/ClipRecorder.h" |
91 #include "platform/graphics/paint/PaintCanvas.h" | 82 #include "platform/graphics/paint/PaintCanvas.h" |
92 #include "platform/graphics/paint/PaintController.h" | 83 #include "platform/graphics/paint/PaintController.h" |
93 #include "platform/graphics/paint/PaintRecordBuilder.h" | |
94 #include "platform/graphics/paint/TransformDisplayItem.h" | 84 #include "platform/graphics/paint/TransformDisplayItem.h" |
95 #include "platform/json/JSONValues.h" | 85 #include "platform/json/JSONValues.h" |
96 #include "platform/loader/fetch/FetchParameters.h" | 86 #include "platform/loader/fetch/FetchParameters.h" |
97 #include "platform/loader/fetch/ResourceFetcher.h" | 87 #include "platform/loader/fetch/ResourceFetcher.h" |
98 #include "platform/loader/fetch/ResourceRequest.h" | 88 #include "platform/loader/fetch/ResourceRequest.h" |
99 #include "platform/plugins/PluginData.h" | 89 #include "platform/plugins/PluginData.h" |
100 #include "platform/scheduler/renderer/web_view_scheduler.h" | 90 #include "platform/scheduler/renderer/web_view_scheduler.h" |
101 #include "platform/text/TextStream.h" | 91 #include "platform/text/TextStream.h" |
102 #include "platform/wtf/PtrUtil.h" | 92 #include "platform/wtf/PtrUtil.h" |
103 #include "platform/wtf/StdLibExtras.h" | 93 #include "platform/wtf/StdLibExtras.h" |
104 #include "public/platform/InterfaceProvider.h" | 94 #include "public/platform/InterfaceProvider.h" |
105 #include "public/platform/InterfaceRegistry.h" | 95 #include "public/platform/InterfaceRegistry.h" |
106 #include "public/platform/WebScreenInfo.h" | |
107 #include "public/platform/WebURLRequest.h" | 96 #include "public/platform/WebURLRequest.h" |
108 #include "third_party/skia/include/core/SkImage.h" | |
109 #include "third_party/skia/include/core/SkSurface.h" | |
110 | 97 |
111 namespace blink { | 98 namespace blink { |
112 | 99 |
113 using namespace HTMLNames; | 100 using namespace HTMLNames; |
114 | 101 |
115 namespace { | 102 namespace { |
116 | 103 |
117 // Converts from bounds in CSS space to device space based on the given | |
118 // frame. | |
119 static FloatRect DeviceSpaceBounds(const FloatRect css_bounds, | |
120 const LocalFrame& frame) { | |
121 float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated(); | |
122 float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale(); | |
123 FloatRect device_bounds(css_bounds); | |
124 device_bounds.SetWidth(css_bounds.Width() * device_scale_factor * | |
125 page_scale_factor); | |
126 device_bounds.SetHeight(css_bounds.Height() * device_scale_factor * | |
127 page_scale_factor); | |
128 return device_bounds; | |
129 } | |
130 | |
131 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled | |
132 // in device space. | |
133 static std::unique_ptr<DragImage> CreateDragImage( | |
134 const LocalFrame& frame, | |
135 float opacity, | |
136 RespectImageOrientationEnum image_orientation, | |
137 const FloatRect& css_bounds, | |
138 PaintRecordBuilder& builder, | |
139 const PropertyTreeState& property_tree_state) { | |
140 float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated(); | |
141 float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale(); | |
142 | |
143 FloatRect device_bounds = DeviceSpaceBounds(css_bounds, frame); | |
144 | |
145 AffineTransform transform; | |
146 transform.Scale(device_scale_factor * page_scale_factor); | |
147 transform.Translate(-device_bounds.X(), -device_bounds.Y()); | |
148 | |
149 // Rasterize upfront, since DragImage::create() is going to do it anyway | |
150 // (SkImage::asLegacyBitmap). | |
151 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | |
152 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | |
153 device_bounds.Width(), device_bounds.Height(), &surface_props); | |
154 if (!surface) | |
155 return nullptr; | |
156 | |
157 SkiaPaintCanvas skia_paint_canvas(surface->getCanvas()); | |
158 skia_paint_canvas.concat(AffineTransformToSkMatrix(transform)); | |
159 builder.EndRecording(skia_paint_canvas, property_tree_state); | |
160 | |
161 RefPtr<Image> image = StaticBitmapImage::Create(surface->makeImageSnapshot()); | |
162 float screen_device_scale_factor = | |
163 frame.GetPage()->GetChromeClient().GetScreenInfo().device_scale_factor; | |
164 | |
165 return DragImage::Create(image.Get(), image_orientation, | |
166 screen_device_scale_factor, kInterpolationHigh, | |
167 opacity); | |
168 } | |
169 | |
170 class DraggedNodeImageBuilder { | |
171 STACK_ALLOCATED(); | |
172 | |
173 public: | |
174 DraggedNodeImageBuilder(const LocalFrame& local_frame, Node& node) | |
175 : local_frame_(&local_frame), | |
176 node_(&node) | |
177 #if DCHECK_IS_ON() | |
178 , | |
179 dom_tree_version_(node.GetDocument().DomTreeVersion()) | |
180 #endif | |
181 { | |
182 for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_)) | |
183 descendant.SetDragged(true); | |
184 } | |
185 | |
186 ~DraggedNodeImageBuilder() { | |
187 #if DCHECK_IS_ON() | |
188 DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); | |
189 #endif | |
190 for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_)) | |
191 descendant.SetDragged(false); | |
192 } | |
193 | |
194 std::unique_ptr<DragImage> CreateImage() { | |
195 #if DCHECK_IS_ON() | |
196 DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); | |
197 #endif | |
198 // Construct layout object for |m_node| with pseudo class "-webkit-drag" | |
199 local_frame_->View()->UpdateAllLifecyclePhasesExceptPaint(); | |
200 LayoutObject* const dragged_layout_object = node_->GetLayoutObject(); | |
201 if (!dragged_layout_object) | |
202 return nullptr; | |
203 // Paint starting at the nearest stacking context, clipped to the object | |
204 // itself. This will also paint the contents behind the object if the | |
205 // object contains transparency and there are other elements in the same | |
206 // stacking context which stacked below. | |
207 PaintLayer* layer = dragged_layout_object->EnclosingLayer(); | |
208 if (!layer->StackingNode()->IsStackingContext()) | |
209 layer = layer->StackingNode()->AncestorStackingContextNode()->Layer(); | |
210 IntRect absolute_bounding_box = | |
211 dragged_layout_object->AbsoluteBoundingBoxRectIncludingDescendants(); | |
212 FloatRect bounding_box = | |
213 layer->GetLayoutObject() | |
214 .AbsoluteToLocalQuad(FloatQuad(absolute_bounding_box), | |
215 kUseTransforms) | |
216 .BoundingBox(); | |
217 PaintLayerPaintingInfo painting_info(layer, LayoutRect(bounding_box), | |
218 kGlobalPaintFlattenCompositingLayers, | |
219 LayoutSize()); | |
220 PaintLayerFlags flags = kPaintLayerHaveTransparency | | |
221 kPaintLayerAppliedTransform | | |
222 kPaintLayerUncachedClipRects; | |
223 PaintRecordBuilder builder(DeviceSpaceBounds(bounding_box, *local_frame_)); | |
224 PaintLayerPainter(*layer).Paint(builder.Context(), painting_info, flags); | |
225 PropertyTreeState border_box_properties = PropertyTreeState::Root(); | |
226 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | |
227 border_box_properties = | |
228 *layer->GetLayoutObject().LocalBorderBoxProperties(); | |
229 } | |
230 return CreateDragImage( | |
231 *local_frame_, 1.0f, | |
232 LayoutObject::ShouldRespectImageOrientation(dragged_layout_object), | |
233 bounding_box, builder, border_box_properties); | |
234 } | |
235 | |
236 private: | |
237 const Member<const LocalFrame> local_frame_; | |
238 const Member<Node> node_; | |
239 #if DCHECK_IS_ON() | |
240 const uint64_t dom_tree_version_; | |
241 #endif | |
242 }; | |
243 | |
244 inline float ParentPageZoomFactor(LocalFrame* frame) { | 104 inline float ParentPageZoomFactor(LocalFrame* frame) { |
245 Frame* parent = frame->Tree().Parent(); | 105 Frame* parent = frame->Tree().Parent(); |
246 if (!parent || !parent->IsLocalFrame()) | 106 if (!parent || !parent->IsLocalFrame()) |
247 return 1; | 107 return 1; |
248 return ToLocalFrame(parent)->PageZoomFactor(); | 108 return ToLocalFrame(parent)->PageZoomFactor(); |
249 } | 109 } |
250 | 110 |
251 inline float ParentTextZoomFactor(LocalFrame* frame) { | 111 inline float ParentTextZoomFactor(LocalFrame* frame) { |
252 Frame* parent = frame->Tree().Parent(); | 112 Frame* parent = frame->Tree().Parent(); |
253 if (!parent || !parent->IsLocalFrame()) | 113 if (!parent || !parent->IsLocalFrame()) |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 593 |
734 double LocalFrame::DevicePixelRatio() const { | 594 double LocalFrame::DevicePixelRatio() const { |
735 if (!page_) | 595 if (!page_) |
736 return 0; | 596 return 0; |
737 | 597 |
738 double ratio = page_->DeviceScaleFactorDeprecated(); | 598 double ratio = page_->DeviceScaleFactorDeprecated(); |
739 ratio *= PageZoomFactor(); | 599 ratio *= PageZoomFactor(); |
740 return ratio; | 600 return ratio; |
741 } | 601 } |
742 | 602 |
743 std::unique_ptr<DragImage> LocalFrame::NodeImage(Node& node) { | |
744 DraggedNodeImageBuilder image_node(*this, node); | |
745 return image_node.CreateImage(); | |
746 } | |
747 | |
748 std::unique_ptr<DragImage> LocalFrame::DragImageForSelection(float opacity) { | |
749 if (!Selection().ComputeVisibleSelectionInDOMTreeDeprecated().IsRange()) | |
750 return nullptr; | |
751 | |
752 view_->UpdateAllLifecyclePhasesExceptPaint(); | |
753 DCHECK(GetDocument()->IsActive()); | |
754 | |
755 FloatRect painting_rect = FloatRect(Selection().Bounds()); | |
756 GlobalPaintFlags paint_flags = | |
757 kGlobalPaintSelectionOnly | kGlobalPaintFlattenCompositingLayers; | |
758 | |
759 PaintRecordBuilder builder(DeviceSpaceBounds(painting_rect, *this)); | |
760 view_->PaintContents(builder.Context(), paint_flags, | |
761 EnclosingIntRect(painting_rect)); | |
762 return CreateDragImage(*this, opacity, kDoNotRespectImageOrientation, | |
763 painting_rect, builder, PropertyTreeState::Root()); | |
764 } | |
765 | |
766 String LocalFrame::SelectedText() const { | 603 String LocalFrame::SelectedText() const { |
767 return Selection().SelectedText(); | 604 return Selection().SelectedText(); |
768 } | 605 } |
769 | 606 |
770 String LocalFrame::SelectedTextForClipboard() const { | 607 String LocalFrame::SelectedTextForClipboard() const { |
771 if (!GetDocument()) | 608 if (!GetDocument()) |
772 return g_empty_string; | 609 return g_empty_string; |
773 DCHECK(!GetDocument()->NeedsLayoutTreeUpdate()); | 610 DCHECK(!GetDocument()->NeedsLayoutTreeUpdate()); |
774 return Selection().SelectedTextForClipboard(); | 611 return Selection().SelectedTextForClipboard(); |
775 } | 612 } |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 node = GetDocument()->FocusedElement(); | 1032 node = GetDocument()->FocusedElement(); |
1196 } | 1033 } |
1197 | 1034 |
1198 if (node) { | 1035 if (node) { |
1199 return node->GetWebPluginContainerBase(); | 1036 return node->GetWebPluginContainerBase(); |
1200 } | 1037 } |
1201 return nullptr; | 1038 return nullptr; |
1202 } | 1039 } |
1203 | 1040 |
1204 } // namespace blink | 1041 } // namespace blink |
OLD | NEW |