| 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/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/instrumentation/resource_coordinator/FrameResourceCoordinator
.h" | 85 #include "platform/instrumentation/resource_coordinator/FrameResourceCoordinator
.h" |
| 96 #include "platform/json/JSONValues.h" | 86 #include "platform/json/JSONValues.h" |
| 97 #include "platform/loader/fetch/FetchParameters.h" | 87 #include "platform/loader/fetch/FetchParameters.h" |
| 98 #include "platform/loader/fetch/ResourceFetcher.h" | 88 #include "platform/loader/fetch/ResourceFetcher.h" |
| 99 #include "platform/loader/fetch/ResourceRequest.h" | 89 #include "platform/loader/fetch/ResourceRequest.h" |
| 100 #include "platform/plugins/PluginData.h" | 90 #include "platform/plugins/PluginData.h" |
| 101 #include "platform/scheduler/renderer/web_view_scheduler.h" | 91 #include "platform/scheduler/renderer/web_view_scheduler.h" |
| 102 #include "platform/text/TextStream.h" | 92 #include "platform/text/TextStream.h" |
| 103 #include "platform/wtf/PtrUtil.h" | 93 #include "platform/wtf/PtrUtil.h" |
| 104 #include "platform/wtf/StdLibExtras.h" | 94 #include "platform/wtf/StdLibExtras.h" |
| 105 #include "public/platform/InterfaceProvider.h" | 95 #include "public/platform/InterfaceProvider.h" |
| 106 #include "public/platform/InterfaceRegistry.h" | 96 #include "public/platform/InterfaceRegistry.h" |
| 107 #include "public/platform/WebScreenInfo.h" | |
| 108 #include "public/platform/WebURLRequest.h" | 97 #include "public/platform/WebURLRequest.h" |
| 109 #include "third_party/skia/include/core/SkImage.h" | |
| 110 #include "third_party/skia/include/core/SkSurface.h" | |
| 111 | 98 |
| 112 namespace blink { | 99 namespace blink { |
| 113 | 100 |
| 114 using namespace HTMLNames; | 101 using namespace HTMLNames; |
| 115 | 102 |
| 116 namespace { | 103 namespace { |
| 117 | 104 |
| 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 static FloatRect 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 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled | |
| 136 // in device space. | |
| 137 // TODO(tanvir.rizvi): CreateDragImageForFrame is used for drag related | |
| 138 // functionality and is irrelevant to core functionality of LocalFrame. This | |
| 139 // should be moved out of LocalFrame to appropriate place. | |
| 140 static std::unique_ptr<DragImage> CreateDragImageForFrame( | |
| 141 const LocalFrame& frame, | |
| 142 float opacity, | |
| 143 RespectImageOrientationEnum image_orientation, | |
| 144 const FloatRect& css_bounds, | |
| 145 PaintRecordBuilder& builder, | |
| 146 const PropertyTreeState& property_tree_state) { | |
| 147 float device_scale_factor = frame.GetPage()->DeviceScaleFactorDeprecated(); | |
| 148 float page_scale_factor = frame.GetPage()->GetVisualViewport().Scale(); | |
| 149 | |
| 150 FloatRect device_bounds = DeviceSpaceBounds(css_bounds, frame); | |
| 151 | |
| 152 AffineTransform transform; | |
| 153 transform.Scale(device_scale_factor * page_scale_factor); | |
| 154 transform.Translate(-device_bounds.X(), -device_bounds.Y()); | |
| 155 | |
| 156 // Rasterize upfront, since DragImage::create() is going to do it anyway | |
| 157 // (SkImage::asLegacyBitmap). | |
| 158 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); | |
| 159 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | |
| 160 device_bounds.Width(), device_bounds.Height(), &surface_props); | |
| 161 if (!surface) | |
| 162 return nullptr; | |
| 163 | |
| 164 SkiaPaintCanvas skia_paint_canvas(surface->getCanvas()); | |
| 165 skia_paint_canvas.concat(AffineTransformToSkMatrix(transform)); | |
| 166 builder.EndRecording(skia_paint_canvas, property_tree_state); | |
| 167 | |
| 168 RefPtr<Image> image = StaticBitmapImage::Create(surface->makeImageSnapshot()); | |
| 169 float screen_device_scale_factor = | |
| 170 frame.GetPage()->GetChromeClient().GetScreenInfo().device_scale_factor; | |
| 171 | |
| 172 return DragImage::Create(image.Get(), image_orientation, | |
| 173 screen_device_scale_factor, kInterpolationHigh, | |
| 174 opacity); | |
| 175 } | |
| 176 | |
| 177 // TODO(tanvir.rizvi): DraggedNodeImageBuilder is used for drag related | |
| 178 // functionality and is irrelevant to core functionality of LocalFrame. This | |
| 179 // should be moved out of LocalFrame to appropriate place. | |
| 180 class DraggedNodeImageBuilder { | |
| 181 STACK_ALLOCATED(); | |
| 182 | |
| 183 public: | |
| 184 DraggedNodeImageBuilder(const LocalFrame& local_frame, Node& node) | |
| 185 : local_frame_(&local_frame), | |
| 186 node_(&node) | |
| 187 #if DCHECK_IS_ON() | |
| 188 , | |
| 189 dom_tree_version_(node.GetDocument().DomTreeVersion()) | |
| 190 #endif | |
| 191 { | |
| 192 for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_)) | |
| 193 descendant.SetDragged(true); | |
| 194 } | |
| 195 | |
| 196 ~DraggedNodeImageBuilder() { | |
| 197 #if DCHECK_IS_ON() | |
| 198 DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); | |
| 199 #endif | |
| 200 for (Node& descendant : NodeTraversal::InclusiveDescendantsOf(*node_)) | |
| 201 descendant.SetDragged(false); | |
| 202 } | |
| 203 | |
| 204 std::unique_ptr<DragImage> CreateImage() { | |
| 205 #if DCHECK_IS_ON() | |
| 206 DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); | |
| 207 #endif | |
| 208 // Construct layout object for |m_node| with pseudo class "-webkit-drag" | |
| 209 local_frame_->View()->UpdateAllLifecyclePhasesExceptPaint(); | |
| 210 LayoutObject* const dragged_layout_object = node_->GetLayoutObject(); | |
| 211 if (!dragged_layout_object) | |
| 212 return nullptr; | |
| 213 // Paint starting at the nearest stacking context, clipped to the object | |
| 214 // itself. This will also paint the contents behind the object if the | |
| 215 // object contains transparency and there are other elements in the same | |
| 216 // stacking context which stacked below. | |
| 217 PaintLayer* layer = dragged_layout_object->EnclosingLayer(); | |
| 218 if (!layer->StackingNode()->IsStackingContext()) | |
| 219 layer = layer->StackingNode()->AncestorStackingContextNode()->Layer(); | |
| 220 IntRect absolute_bounding_box = | |
| 221 dragged_layout_object->AbsoluteBoundingBoxRectIncludingDescendants(); | |
| 222 FloatRect bounding_box = | |
| 223 layer->GetLayoutObject() | |
| 224 .AbsoluteToLocalQuad(FloatQuad(absolute_bounding_box), | |
| 225 kUseTransforms) | |
| 226 .BoundingBox(); | |
| 227 PaintLayerPaintingInfo painting_info(layer, LayoutRect(bounding_box), | |
| 228 kGlobalPaintFlattenCompositingLayers, | |
| 229 LayoutSize()); | |
| 230 PaintLayerFlags flags = kPaintLayerHaveTransparency | | |
| 231 kPaintLayerAppliedTransform | | |
| 232 kPaintLayerUncachedClipRects; | |
| 233 PaintRecordBuilder builder(DeviceSpaceBounds(bounding_box, *local_frame_)); | |
| 234 PaintLayerPainter(*layer).Paint(builder.Context(), painting_info, flags); | |
| 235 PropertyTreeState border_box_properties = PropertyTreeState::Root(); | |
| 236 if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled()) { | |
| 237 border_box_properties = | |
| 238 *layer->GetLayoutObject().LocalBorderBoxProperties(); | |
| 239 } | |
| 240 return CreateDragImageForFrame( | |
| 241 *local_frame_, 1.0f, | |
| 242 LayoutObject::ShouldRespectImageOrientation(dragged_layout_object), | |
| 243 bounding_box, builder, border_box_properties); | |
| 244 } | |
| 245 | |
| 246 private: | |
| 247 const Member<const LocalFrame> local_frame_; | |
| 248 const Member<Node> node_; | |
| 249 #if DCHECK_IS_ON() | |
| 250 const uint64_t dom_tree_version_; | |
| 251 #endif | |
| 252 }; | |
| 253 | |
| 254 inline float ParentPageZoomFactor(LocalFrame* frame) { | 105 inline float ParentPageZoomFactor(LocalFrame* frame) { |
| 255 Frame* parent = frame->Tree().Parent(); | 106 Frame* parent = frame->Tree().Parent(); |
| 256 if (!parent || !parent->IsLocalFrame()) | 107 if (!parent || !parent->IsLocalFrame()) |
| 257 return 1; | 108 return 1; |
| 258 return ToLocalFrame(parent)->PageZoomFactor(); | 109 return ToLocalFrame(parent)->PageZoomFactor(); |
| 259 } | 110 } |
| 260 | 111 |
| 261 inline float ParentTextZoomFactor(LocalFrame* frame) { | 112 inline float ParentTextZoomFactor(LocalFrame* frame) { |
| 262 Frame* parent = frame->Tree().Parent(); | 113 Frame* parent = frame->Tree().Parent(); |
| 263 if (!parent || !parent->IsLocalFrame()) | 114 if (!parent || !parent->IsLocalFrame()) |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 603 |
| 753 double LocalFrame::DevicePixelRatio() const { | 604 double LocalFrame::DevicePixelRatio() const { |
| 754 if (!page_) | 605 if (!page_) |
| 755 return 0; | 606 return 0; |
| 756 | 607 |
| 757 double ratio = page_->DeviceScaleFactorDeprecated(); | 608 double ratio = page_->DeviceScaleFactorDeprecated(); |
| 758 ratio *= PageZoomFactor(); | 609 ratio *= PageZoomFactor(); |
| 759 return ratio; | 610 return ratio; |
| 760 } | 611 } |
| 761 | 612 |
| 762 // TODO(tanvir.rizvi): NodeImage is used only by DataTransfer, | |
| 763 // and is irrelevant to LocalFrame core functionality, so it can be moved to | |
| 764 // DataTransfer. | |
| 765 std::unique_ptr<DragImage> LocalFrame::NodeImage(Node& node) { | |
| 766 DraggedNodeImageBuilder image_node(*this, node); | |
| 767 return image_node.CreateImage(); | |
| 768 } | |
| 769 | |
| 770 // TODO(tanvir.rizvi): DragImageForSelection is used only by DragController, | |
| 771 // and is irrelevant to LocalFrame core functionality, so it can be moved to | |
| 772 // DragController. | |
| 773 std::unique_ptr<DragImage> LocalFrame::DragImageForSelection(float opacity) { | |
| 774 if (!Selection().ComputeVisibleSelectionInDOMTreeDeprecated().IsRange()) | |
| 775 return nullptr; | |
| 776 | |
| 777 view_->UpdateAllLifecyclePhasesExceptPaint(); | |
| 778 DCHECK(GetDocument()->IsActive()); | |
| 779 | |
| 780 FloatRect painting_rect = FloatRect(Selection().Bounds()); | |
| 781 GlobalPaintFlags paint_flags = | |
| 782 kGlobalPaintSelectionOnly | kGlobalPaintFlattenCompositingLayers; | |
| 783 | |
| 784 PaintRecordBuilder builder(DeviceSpaceBounds(painting_rect, *this)); | |
| 785 view_->PaintContents(builder.Context(), paint_flags, | |
| 786 EnclosingIntRect(painting_rect)); | |
| 787 return CreateDragImageForFrame(*this, opacity, kDoNotRespectImageOrientation, | |
| 788 painting_rect, builder, | |
| 789 PropertyTreeState::Root()); | |
| 790 } | |
| 791 | |
| 792 String LocalFrame::SelectedText() const { | 613 String LocalFrame::SelectedText() const { |
| 793 return Selection().SelectedText(); | 614 return Selection().SelectedText(); |
| 794 } | 615 } |
| 795 | 616 |
| 796 String LocalFrame::SelectedTextForClipboard() const { | 617 String LocalFrame::SelectedTextForClipboard() const { |
| 797 if (!GetDocument()) | 618 if (!GetDocument()) |
| 798 return g_empty_string; | 619 return g_empty_string; |
| 799 DCHECK(!GetDocument()->NeedsLayoutTreeUpdate()); | 620 DCHECK(!GetDocument()->NeedsLayoutTreeUpdate()); |
| 800 return Selection().SelectedTextForClipboard(); | 621 return Selection().SelectedTextForClipboard(); |
| 801 } | 622 } |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 void LocalFrame::SetViewportIntersectionFromParent( | 1055 void LocalFrame::SetViewportIntersectionFromParent( |
| 1235 const IntRect& viewport_intersection) { | 1056 const IntRect& viewport_intersection) { |
| 1236 if (remote_viewport_intersection_ != viewport_intersection) { | 1057 if (remote_viewport_intersection_ != viewport_intersection) { |
| 1237 remote_viewport_intersection_ = viewport_intersection; | 1058 remote_viewport_intersection_ = viewport_intersection; |
| 1238 if (View()) | 1059 if (View()) |
| 1239 View()->ScheduleAnimation(); | 1060 View()->ScheduleAnimation(); |
| 1240 } | 1061 } |
| 1241 } | 1062 } |
| 1242 | 1063 |
| 1243 } // namespace blink | 1064 } // namespace blink |
| OLD | NEW |