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..11cc6e16c0ed538ba08b3c852c2130a4ec55836f 100644 |
| --- a/Source/core/inspector/InspectorOverlay.cpp |
| +++ b/Source/core/inspector/InspectorOverlay.cpp |
| @@ -483,7 +483,121 @@ static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) |
| return result.release(); |
| } |
| -static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) |
| +// CSS shapes |
| +struct PathApplyInfo { |
|
pfeldman
2014/05/02 10:49:23
Move this to anonymous namespace above.
Habib Virji
2014/05/02 11:11:28
Done.
|
| + FrameView* rootView; |
| + FrameView* view; |
| + JSONArray* array; |
| + RenderObject* renderer; |
| + const ShapeOutsideInfo* shapeOutsideInfo; |
| +}; |
| + |
| +static void appendPathCommandAndPoints(PathApplyInfo* info, const String& command, const FloatPoint points[], unsigned length) |
| +{ |
| + FloatPoint point; |
| + info->array->pushString(command); |
| + 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()); |
| + info->array->pushNumber(point.y()); |
| + } |
| +} |
| + |
| +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<JSONValue> > buildArrayForShapeOutside(PassRefPtr<JSONValue> value) |
|
pfeldman
2014/05/02 10:49:23
I was mentioning that I am not sure I understand t
Habib Virji
2014/05/02 11:11:28
I get following compilation error, if i pass JSONA
Habib Virji
2014/05/02 11:38:52
Done.
|
| +{ |
| + RefPtr<TypeBuilder::Array<JSONValue> > array = TypeBuilder::Array<JSONValue>::create(); |
| + array->addItem(value); |
| + return array.release(); |
| +} |
| + |
| +static RefPtr<TypeBuilder::Array<double> > buildArrayForQuadTypeBuilder(const FloatQuad& quad) |
|
pfeldman
2014/05/02 10:49:23
I would have updated existing buildArrayForQuad wi
Habib Virji
2014/05/02 11:11:28
Ok, let me know will update accordingly.
|
| +{ |
| + 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(); |
| + RefPtr<JSONArray> marginShapePath = JSONArray::create(); |
| + |
| + 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(buildArrayForShapeOutside(shapePath)) |
|
pfeldman
2014/05/02 10:49:23
This I don't understand. shapePath is already an a
Habib Virji
2014/05/02 11:11:28
Mentioned above reason for doing this. Idea is to
Habib Virji
2014/05/02 11:38:52
Done.
|
| + .setMarginShape(buildArrayForShapeOutside(marginShapePath)); |
|
pfeldman
2014/05/02 10:49:23
ditto
Habib Virji
2014/05/02 11:38:52
Done.
|
| + |
| + 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 +639,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 +659,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); |
| } |