Chromium Code Reviews| Index: Source/core/inspector/InspectorOverlay.cpp |
| diff --git a/Source/core/inspector/InspectorOverlay.cpp b/Source/core/inspector/InspectorOverlay.cpp |
| index 522204b02d4aaeead087fe736ea53120844822af..d05cd46e4f8c5572173f15f4b3bdc12de91fdc4f 100644 |
| --- a/Source/core/inspector/InspectorOverlay.cpp |
| +++ b/Source/core/inspector/InspectorOverlay.cpp |
| @@ -59,6 +59,14 @@ namespace WebCore { |
| namespace { |
| +struct PathApplyInfo { |
| + FrameView* rootView; |
| + FrameView* view; |
| + JSONArray* array; |
|
pfeldman
2014/05/02 11:45:07
TypeBuilder::Array<JSONValue>* array;
Habib Virji
2014/05/02 12:39:32
Done.
|
| + RenderObject* renderer; |
| + const ShapeOutsideInfo* shapeOutsideInfo; |
| +}; |
| + |
| class InspectorOverlayChromeClient FINAL: public EmptyChromeClient { |
| public: |
| InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlay* overlay) |
| @@ -483,7 +491,105 @@ static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) |
| return result.release(); |
| } |
| -static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) |
| +// CSS shapes |
| +static void appendPathCommandAndPoints(PathApplyInfo* info, const String& command, const FloatPoint points[], unsigned length) |
| +{ |
| + FloatPoint point; |
| + info->array->pushString(command); |
|
pfeldman
2014/05/02 11:45:07
info->array->addItem(JSONString::create(command));
Habib Virji
2014/05/02 12:39:32
Done.
|
| + for (unsigned i = 0; i < length; i++) { |
| + point = info->shapeOutsideInfo->shapeToRendererPoint(points[i]); |
| + point = info->view->contentsToRootView(roundedIntPoint(info->renderer->localToAbsolute(point))) + info->rootView->scrollOffset(); |
| + info->array->pushNumber(point.x()); |
|
pfeldman
2014/05/02 11:45:07
info->array->addItem(JSONBasicValue::create(point.
Habib Virji
2014/05/02 12:39:32
Done.
|
| + info->array->pushNumber(point.y()); |
|
pfeldman
2014/05/02 11:45:07
info->array->addItem(JSONBasicValue::create(point.
Habib Virji
2014/05/02 12:39:32
Done.
|
| + } |
| +} |
| + |
| +static void appendPathSegment(void* info, const PathElement* pathElement) |
| +{ |
| + PathApplyInfo* pathApplyInfo = static_cast<PathApplyInfo*>(info); |
| + FloatPoint point; |
| + switch (pathElement->type) { |
| + // The points member will contain 1 value. |
| + case PathElementMoveToPoint: |
| + appendPathCommandAndPoints(pathApplyInfo, "M", pathElement->points, 1); |
| + break; |
| + // The points member will contain 1 value. |
| + case PathElementAddLineToPoint: |
| + appendPathCommandAndPoints(pathApplyInfo, "L", pathElement->points, 1); |
| + break; |
| + // The points member will contain 3 values. |
| + case PathElementAddCurveToPoint: |
| + appendPathCommandAndPoints(pathApplyInfo, "C", pathElement->points, 3); |
| + break; |
| + // The points member will contain 2 values. |
| + case PathElementAddQuadCurveToPoint: |
| + appendPathCommandAndPoints(pathApplyInfo, "Q", pathElement->points, 2); |
| + break; |
| + // The points member will contain no values. |
| + case PathElementCloseSubpath: |
| + appendPathCommandAndPoints(pathApplyInfo, "Z", 0, 0); |
| + break; |
| + } |
| +} |
| + |
| +static RefPtr<TypeBuilder::Array<double> > buildArrayForQuadTypeBuilder(const FloatQuad& quad) |
| +{ |
| + RefPtr<TypeBuilder::Array<double> > array = TypeBuilder::Array<double>::create(); |
| + array->addItem(quad.p1().x()); |
| + array->addItem(quad.p1().y()); |
| + array->addItem(quad.p2().x()); |
| + array->addItem(quad.p2().y()); |
| + array->addItem(quad.p3().x()); |
| + array->addItem(quad.p3().y()); |
| + array->addItem(quad.p4().x()); |
| + array->addItem(quad.p4().y()); |
| + return array.release(); |
| +} |
| + |
| +PassRefPtr<TypeBuilder::DOM::ShapeOutsideInfo> InspectorOverlay::buildObjectForShapeOutside(Node* node) |
| +{ |
| + RenderObject* renderer = node->renderer(); |
| + if (!renderer || !renderer->isBox() || !toRenderBox(renderer)->shapeOutsideInfo()) |
| + return nullptr; |
| + |
| + LocalFrame* containingFrame = node->document().frame(); |
| + RenderBox* renderBox = toRenderBox(renderer); |
| + const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo(); |
| + |
| + LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox(); |
| + FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBounds)); |
| + FrameView* mainView = containingFrame->page()->mainFrame()->view(); |
| + FrameView* containingView = containingFrame->view(); |
| + contentsQuadToPage(mainView, containingView, shapeQuad); |
| + |
| + Shape::DisplayPaths paths; |
| + shapeOutsideInfo->computedShape().buildDisplayPaths(paths); |
| + RefPtr<JSONArray> shapePath = JSONArray::create(); |
|
pfeldman
2014/05/02 11:45:07
RefPtr<TypeBuilder::Array<JSONValue> > shapePath =
|
| + RefPtr<JSONArray> marginShapePath = JSONArray::create(); |
|
pfeldman
2014/05/02 11:45:07
RefPtr<TypeBuilder::Array<JSONValue> > marginShape
|
| + |
| + if (paths.shape.length()) { |
| + PathApplyInfo info; |
| + info.rootView = mainView; |
| + info.view = containingView; |
| + info.array = shapePath.get(); |
| + info.renderer = renderBox; |
| + info.shapeOutsideInfo = shapeOutsideInfo; |
| + paths.shape.apply(&info, &appendPathSegment); |
| + |
| + if (paths.marginShape.length()) { |
| + info.array = marginShapePath.get(); |
| + paths.marginShape.apply(&info, &appendPathSegment); |
| + } |
| + } |
| + RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeTypeBuilder = TypeBuilder::DOM::ShapeOutsideInfo::create() |
| + .setBounds(buildArrayForQuadTypeBuilder(shapeQuad)) |
| + .setShape(TypeBuilder::Array<JSONValue>::runtimeCast(shapePath)) |
| + .setMarginShape(TypeBuilder::Array<JSONValue>::runtimeCast(marginShapePath)); |
| + |
| + return shapeTypeBuilder.release(); |
| +} |
| + |
| +static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObject>& shapeObject, Node* node) |
| { |
| RefPtr<JSONObject> elementInfo = JSONObject::create(); |
| Element* element = toElement(node); |
| @@ -525,6 +631,8 @@ static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) |
| RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderBoxModelObject(renderer) : 0; |
| elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAbsoluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.width())); |
| elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForAbsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox.height())); |
| + if (renderer->isBox() && shapeObject) |
| + elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); |
| highlightObject->setObject("elementInfo", elementInfo.release()); |
| } |
| @@ -543,8 +651,10 @@ void InspectorOverlay::drawNodeHighlight() |
| RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
| Node* node = m_highlightNode.get(); |
| + RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeObject = buildObjectForShapeOutside(node); |
| + RefPtr<JSONObject> shapeObjectJSON = shapeObject ? shapeObject->asObject() : nullptr; |
| if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInfo && node->renderer() && node->document().frame()) |
| - setElementInfo(highlightObject, node); |
| + setElementInfo(highlightObject, shapeObjectJSON, node); |
| evaluateInOverlay("drawNodeHighlight", highlightObject); |
| } |