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/LayoutEmbeddedContentItem.h" | 62 #include "core/layout/api/LayoutEmbeddedContentItem.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/DragController.h" | 68 #include "core/page/DragController.h" |
71 #include "core/page/FocusController.h" | 69 #include "core/page/FocusController.h" |
72 #include "core/page/Page.h" | |
73 #include "core/page/scrolling/ScrollingCoordinator.h" | 70 #include "core/page/scrolling/ScrollingCoordinator.h" |
74 #include "core/paint/ObjectPainter.h" | 71 #include "core/paint/ObjectPainter.h" |
75 #include "core/paint/PaintInfo.h" | |
76 #include "core/paint/PaintLayer.h" | |
77 #include "core/paint/PaintLayerPainter.h" | |
78 #include "core/paint/TransformRecorder.h" | 72 #include "core/paint/TransformRecorder.h" |
79 #include "core/plugins/PluginView.h" | 73 #include "core/plugins/PluginView.h" |
80 #include "core/probe/CoreProbes.h" | 74 #include "core/probe/CoreProbes.h" |
81 #include "core/svg/SVGDocumentExtensions.h" | 75 #include "core/svg/SVGDocumentExtensions.h" |
82 #include "core/timing/Performance.h" | 76 #include "core/timing/Performance.h" |
83 #include "platform/DragImage.h" | |
84 #include "platform/Histogram.h" | 77 #include "platform/Histogram.h" |
85 #include "platform/PluginScriptForbiddenScope.h" | 78 #include "platform/PluginScriptForbiddenScope.h" |
86 #include "platform/RuntimeEnabledFeatures.h" | 79 #include "platform/RuntimeEnabledFeatures.h" |
87 #include "platform/ScriptForbiddenScope.h" | 80 #include "platform/ScriptForbiddenScope.h" |
88 #include "platform/WebFrameScheduler.h" | 81 #include "platform/WebFrameScheduler.h" |
89 #include "platform/graphics/GraphicsContext.h" | |
90 #include "platform/graphics/StaticBitmapImage.h" | |
91 #include "platform/graphics/paint/ClipRecorder.h" | 82 #include "platform/graphics/paint/ClipRecorder.h" |
92 #include "platform/graphics/paint/PaintCanvas.h" | 83 #include "platform/graphics/paint/PaintCanvas.h" |
93 #include "platform/graphics/paint/PaintController.h" | 84 #include "platform/graphics/paint/PaintController.h" |
94 #include "platform/graphics/paint/PaintRecordBuilder.h" | |
95 #include "platform/graphics/paint/TransformDisplayItem.h" | 85 #include "platform/graphics/paint/TransformDisplayItem.h" |
96 #include "platform/instrumentation/resource_coordinator/FrameResourceCoordinator
.h" | 86 #include "platform/instrumentation/resource_coordinator/FrameResourceCoordinator
.h" |
97 #include "platform/json/JSONValues.h" | 87 #include "platform/json/JSONValues.h" |
98 #include "platform/loader/fetch/FetchParameters.h" | 88 #include "platform/loader/fetch/FetchParameters.h" |
99 #include "platform/loader/fetch/ResourceFetcher.h" | 89 #include "platform/loader/fetch/ResourceFetcher.h" |
100 #include "platform/loader/fetch/ResourceRequest.h" | 90 #include "platform/loader/fetch/ResourceRequest.h" |
101 #include "platform/plugins/PluginData.h" | 91 #include "platform/plugins/PluginData.h" |
102 #include "platform/scheduler/renderer/web_view_scheduler.h" | 92 #include "platform/scheduler/renderer/web_view_scheduler.h" |
103 #include "platform/text/TextStream.h" | 93 #include "platform/text/TextStream.h" |
104 #include "platform/wtf/PtrUtil.h" | 94 #include "platform/wtf/PtrUtil.h" |
105 #include "platform/wtf/StdLibExtras.h" | 95 #include "platform/wtf/StdLibExtras.h" |
106 #include "public/platform/InterfaceProvider.h" | 96 #include "public/platform/InterfaceProvider.h" |
107 #include "public/platform/InterfaceRegistry.h" | 97 #include "public/platform/InterfaceRegistry.h" |
108 #include "public/platform/WebScreenInfo.h" | |
109 #include "public/platform/WebURLRequest.h" | 98 #include "public/platform/WebURLRequest.h" |
110 #include "third_party/skia/include/core/SkImage.h" | |
111 #include "third_party/skia/include/core/SkSurface.h" | |
112 | 99 |
113 namespace blink { | 100 namespace blink { |
114 | 101 |
115 using namespace HTMLNames; | 102 using namespace HTMLNames; |
116 | 103 |
117 // static | |
118 // Converts from bounds in CSS space to device space based on the given | |
119 // frame. | |
120 // TODO(tanvir.rizvi): DeviceSpaceBounds is used for drag related functionality | |
121 // and is irrelevant to core functionality of LocalFrame. This should be moved | |
122 // out of LocalFrame to appropriate place. | |
123 FloatRect DataTransfer::DeviceSpaceBounds(const FloatRect css_bounds, | |
124 const LocalFrame& frame) { | |
125 float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated(); | |
126 float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale(); | |
127 FloatRect device_bounds(css_bounds); | |
128 device_bounds.SetWidth(css_bounds.Width() * device_scale_factor * | |
129 page_scale_factor); | |
130 device_bounds.SetHeight(css_bounds.Height() * device_scale_factor * | |
131 page_scale_factor); | |
132 return device_bounds; | |
133 } | |
134 | |
135 // static | |
136 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled | |
137 // in device space. | |
138 // TODO(tanvir.rizvi): CreateDragImageForFrame is used for drag related | |
139 // functionality and is irrelevant to core functionality of LocalFrame. This | |
140 // should be moved out of LocalFrame to appropriate place. | |
141 std::unique_ptr<DragImage> DataTransfer::CreateDragImageForFrame( | |
142 const LocalFrame& frame, | |
143 float opacity, | |
144 RespectImageOrientationEnum image_orientation, | |
145 const FloatRect& css_bounds, | |
146 PaintRecordBuilder& builder, | |
147 const PropertyTreeState& property_tree_state) { | |
148 float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated(); | |
149 float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale(); | |
150 | |
151 FloatRect device_bounds = DeviceSpaceBounds(css_bounds, frame); | |
152 | |
153 AffineTransform transform; | |
154 transform.Scale(device_scale_factor * page_scale_factor); | |
155 transform.Translate(-device_bounds.X(), -device_bounds.Y()); | |
156 | |
157 // Rasterize upfront, since DragImage::create() is going to do it anyway | |
158 // (SkImage::asLegacyBitmap). | |
159 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | |
160 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | |
161 device_bounds.Width(), device_bounds.Height(), &surface_props); | |
162 if (!surface) | |
163 return nullptr; | |
164 | |
165 SkiaPaintCanvas skia_paint_canvas(surface->getCanvas()); | |
166 skia_paint_canvas.concat(AffineTransformToSkMatrix(transform)); | |
167 builder.EndRecording(skia_paint_canvas, property_tree_state); | |
168 | |
169 RefPtr<Image> image = StaticBitmapImage::Create(surface->makeImageSnapshot()); | |
170 float screen_device_scale_factor = | |
171 frame.GetPage()->GetChromeClient().GetScreenInfo().device_scale_factor; | |
172 | |
173 return DragImage::Create(image.Get(), image_orientation, | |
174 screen_device_scale_factor, kInterpolationHigh, | |
175 opacity); | |
176 } | |
177 | |
178 namespace { | 104 namespace { |
179 | 105 |
180 // TODO(tanvir.rizvi): DraggedNodeImageBuilder is used for drag related | |
181 // functionality and is irrelevant to core functionality of LocalFrame. This | |
182 // should be moved out of LocalFrame to appropriate place. | |
183 class DraggedNodeImageBuilder { | |
184 STACK_ALLOCATED(); | |
185 | |
186 public: | |
187 DraggedNodeImageBuilder(const LocalFrame& local_frame, Node& node) | |
188 : local_frame_(&local_frame), | |
189 node_(&node) | |
190 #if DCHECK_IS_ON() | |
191 , | |
192 dom_tree_version_(node.GetDocument().DomTreeVersion()) | |
193 #endif | |
194 { | |
195 for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_)) | |
196 descendant.SetDragged(true); | |
197 } | |
198 | |
199 ~DraggedNodeImageBuilder() { | |
200 #if DCHECK_IS_ON() | |
201 DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); | |
202 #endif | |
203 for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_)) | |
204 descendant.SetDragged(false); | |
205 } | |
206 | |
207 std::unique_ptr<DragImage> CreateImage() { | |
208 #if DCHECK_IS_ON() | |
209 DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); | |
210 #endif | |
211 // Construct layout object for |m_node| with pseudo class "-webkit-drag" | |
212 local_frame_->View()->UpdateAllLifecyclePhasesExceptPaint(); | |
213 LayoutObject* const dragged_layout_object = node_->GetLayoutObject(); | |
214 if (!dragged_layout_object) | |
215 return nullptr; | |
216 // Paint starting at the nearest stacking context, clipped to the object | |
217 // itself. This will also paint the contents behind the object if the | |
218 // object contains transparency and there are other elements in the same | |
219 // stacking context which stacked below. | |
220 PaintLayer* layer = dragged_layout_object->EnclosingLayer(); | |
221 if (!layer->StackingNode()->IsStackingContext()) | |
222 layer = layer->StackingNode()->AncestorStackingContextNode()->Layer(); | |
223 IntRect absolute_bounding_box = | |
224 dragged_layout_object->AbsoluteBoundingBoxRectIncludingDescendants(); | |
225 FloatRect bounding_box = | |
226 layer->GetLayoutObject() | |
227 .AbsoluteToLocalQuad(FloatQuad(absolute_bounding_box), | |
228 kUseTransforms) | |
229 .BoundingBox(); | |
230 PaintLayerPaintingInfo painting_info(layer, LayoutRect(bounding_box), | |
231 kGlobalPaintFlattenCompositingLayers, | |
232 LayoutSize()); | |
233 PaintLayerFlags flags = kPaintLayerHaveTransparency | | |
234 kPaintLayerAppliedTransform | | |
235 kPaintLayerUncachedClipRects; | |
236 PaintRecordBuilder builder( | |
237 DataTransfer::DeviceSpaceBounds(bounding_box, *local_frame_)); | |
238 PaintLayerPainter(*layer).Paint(builder.Context(), painting_info, flags); | |
239 PropertyTreeState border_box_properties = PropertyTreeState::Root(); | |
240 if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled()) { | |
241 border_box_properties = | |
242 *layer->GetLayoutObject().LocalBorderBoxProperties(); | |
243 } | |
244 return DataTransfer::CreateDragImageForFrame( | |
245 *local_frame_, 1.0f, | |
246 LayoutObject::ShouldRespectImageOrientation(dragged_layout_object), | |
247 bounding_box, builder, border_box_properties); | |
248 } | |
249 | |
250 private: | |
251 const Member<const LocalFrame> local_frame_; | |
252 const Member<Node> node_; | |
253 #if DCHECK_IS_ON() | |
254 const uint64_t dom_tree_version_; | |
255 #endif | |
256 }; | |
257 | |
258 inline float ParentPageZoomFactor(LocalFrame* frame) { | 106 inline float ParentPageZoomFactor(LocalFrame* frame) { |
259 Frame* parent = frame->Tree().Parent(); | 107 Frame* parent = frame->Tree().Parent(); |
260 if (!parent || !parent->IsLocalFrame()) | 108 if (!parent || !parent->IsLocalFrame()) |
261 return 1; | 109 return 1; |
262 return ToLocalFrame(parent)->PageZoomFactor(); | 110 return ToLocalFrame(parent)->PageZoomFactor(); |
263 } | 111 } |
264 | 112 |
265 inline float ParentTextZoomFactor(LocalFrame* frame) { | 113 inline float ParentTextZoomFactor(LocalFrame* frame) { |
266 Frame* parent = frame->Tree().Parent(); | 114 Frame* parent = frame->Tree().Parent(); |
267 if (!parent || !parent->IsLocalFrame()) | 115 if (!parent || !parent->IsLocalFrame()) |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 609 |
762 double LocalFrame::DevicePixelRatio() const { | 610 double LocalFrame::DevicePixelRatio() const { |
763 if (!page_) | 611 if (!page_) |
764 return 0; | 612 return 0; |
765 | 613 |
766 double ratio = page_->DeviceScaleFactorDeprecated(); | 614 double ratio = page_->DeviceScaleFactorDeprecated(); |
767 ratio *= PageZoomFactor(); | 615 ratio *= PageZoomFactor(); |
768 return ratio; | 616 return ratio; |
769 } | 617 } |
770 | 618 |
771 // static | |
772 // TODO(tanvir.rizvi): NodeImage is used only by DataTransfer, | |
773 // and is irrelevant to LocalFrame core functionality, so it can be moved to | |
774 // DataTransfer. | |
775 std::unique_ptr<DragImage> DataTransfer::NodeImage(const LocalFrame& frame, | |
776 Node& node) { | |
777 DraggedNodeImageBuilder image_node(frame, node); | |
778 return image_node.CreateImage(); | |
779 } | |
780 | |
781 // static | |
782 // TODO(tanvir.rizvi): DragImageForSelection is used only by DragController, | |
783 // and is irrelevant to LocalFrame core functionality, so it can be moved to | |
784 // DragController. | |
785 std::unique_ptr<DragImage> DragController::DragImageForSelection( | |
786 const LocalFrame& frame, | |
787 float opacity) { | |
788 if (!frame.Selection().ComputeVisibleSelectionInDOMTreeDeprecated().IsRange()) | |
789 return nullptr; | |
790 | |
791 frame.View()->UpdateAllLifecyclePhasesExceptPaint(); | |
792 DCHECK(frame.GetDocument()->IsActive()); | |
793 | |
794 FloatRect painting_rect = FloatRect(frame.Selection().Bounds()); | |
795 GlobalPaintFlags paint_flags = | |
796 kGlobalPaintSelectionOnly | kGlobalPaintFlattenCompositingLayers; | |
797 | |
798 PaintRecordBuilder builder( | |
799 DataTransfer::DeviceSpaceBounds(painting_rect, frame)); | |
800 frame.View()->PaintContents(builder.Context(), paint_flags, | |
801 EnclosingIntRect(painting_rect)); | |
802 return DataTransfer::CreateDragImageForFrame( | |
803 frame, opacity, kDoNotRespectImageOrientation, painting_rect, builder, | |
804 PropertyTreeState::Root()); | |
805 } | |
806 | |
807 String LocalFrame::SelectedText() const { | 619 String LocalFrame::SelectedText() const { |
808 return Selection().SelectedText(); | 620 return Selection().SelectedText(); |
809 } | 621 } |
810 | 622 |
811 String LocalFrame::SelectedTextForClipboard() const { | 623 String LocalFrame::SelectedTextForClipboard() const { |
812 if (!GetDocument()) | 624 if (!GetDocument()) |
813 return g_empty_string; | 625 return g_empty_string; |
814 DCHECK(!GetDocument()->NeedsLayoutTreeUpdate()); | 626 DCHECK(!GetDocument()->NeedsLayoutTreeUpdate()); |
815 return Selection().SelectedTextForClipboard(); | 627 return Selection().SelectedTextForClipboard(); |
816 } | 628 } |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 void LocalFrame::SetViewportIntersectionFromParent( | 1061 void LocalFrame::SetViewportIntersectionFromParent( |
1250 const IntRect& viewport_intersection) { | 1062 const IntRect& viewport_intersection) { |
1251 if (remote_viewport_intersection_ != viewport_intersection) { | 1063 if (remote_viewport_intersection_ != viewport_intersection) { |
1252 remote_viewport_intersection_ = viewport_intersection; | 1064 remote_viewport_intersection_ = viewport_intersection; |
1253 if (View()) | 1065 if (View()) |
1254 View()->ScheduleAnimation(); | 1066 View()->ScheduleAnimation(); |
1255 } | 1067 } |
1256 } | 1068 } |
1257 | 1069 |
1258 } // namespace blink | 1070 } // namespace blink |
OLD | NEW |