Chromium Code Reviews| Index: Source/core/inspector/InspectorOverlay.cpp |
| diff --git a/Source/core/inspector/InspectorOverlay.cpp b/Source/core/inspector/InspectorOverlay.cpp |
| index 2d1b2246b0f473052f95333a02937068d089d86b..0eb2753068a8540f756f30a82a25c2036171d17a 100644 |
| --- a/Source/core/inspector/InspectorOverlay.cpp |
| +++ b/Source/core/inspector/InspectorOverlay.cpp |
| @@ -495,7 +495,101 @@ static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) |
| return result.release(); |
| } |
| -static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) |
| +// CSS shapes |
| +struct PathApplyInfo { |
| + 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; |
|
rwlbuis
2014/04/24 15:17:27
point is not used?
Habib Virji
2014/04/24 17:12:22
Done.
|
| + 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; |
| + } |
| +} |
| + |
| +PassRefPtr<JSONObject> InspectorOverlay::buildObjectForShapeOutside() |
| +{ |
| + Node* node = m_highlightNode.get(); |
| + RenderObject* renderer = node->renderer(); |
| + if (renderer && renderer->isBox()) { |
| + LocalFrame* containingFrame = node->document().frame(); |
| + RenderBox* renderBox = toRenderBox(renderer); |
| + |
| + const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo(); |
| + if (!shapeOutsideInfo) |
| + return nullptr; |
| + |
| + RefPtr<JSONObject> shapeObject = JSONObject::create(); |
| + LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox(); |
| + FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBounds)); |
| + FrameView* mainView = containingFrame->page()->mainFrame()->view(); |
| + FrameView* containingView = containingFrame->view(); |
| + contentsQuadToPage(mainView, containingView, shapeQuad); |
| + shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad)); |
| + |
| + Shape::DisplayPaths paths; |
| + shapeOutsideInfo->computedShape().buildDisplayPaths(paths); |
| + |
| + if (paths.shape.length()) { |
| + RefPtr<JSONArray> shapePath = JSONArray::create(); |
| + PathApplyInfo info; |
| + info.rootView = mainView; |
| + info.view = containingView; |
| + info.array = shapePath.get(); |
| + info.renderer = renderBox; |
| + info.shapeOutsideInfo = shapeOutsideInfo; |
| + paths.shape.apply(&info, &appendPathSegment); |
| + shapeObject->setArray("shape", shapePath.release()); |
| + if (paths.marginShape.length()) { |
| + shapePath = JSONArray::create(); |
| + info.array = shapePath.get(); |
| + paths.marginShape.apply(&info, &appendPathSegment); |
| + shapeObject->setArray("marginShape", shapePath.release()); |
| + } |
| + } |
| + return shapeObject.release(); |
| + } |
| + return nullptr; |
| +} |
| + |
| +static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObject>& shapeObject, Node* node) |
| { |
| RefPtr<JSONObject> elementInfo = JSONObject::create(); |
| Element* element = toElement(node); |
| @@ -537,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()); |
| } |
| @@ -553,10 +649,11 @@ void InspectorOverlay::drawNodeHighlight() |
| highlight.quads.append(eventTargetHighlight.quads[1]); // Add border from eventTargetNode to highlight. |
| } |
| RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
| + RefPtr<JSONObject> shapeObject = buildObjectForShapeOutside(); |
| Node* node = m_highlightNode.get(); |
| if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInfo && node->renderer() && node->document().frame()) |
| - setElementInfo(highlightObject, node); |
| + setElementInfo(highlightObject, shapeObject, node); |
| evaluateInOverlay("drawNodeHighlight", highlightObject); |
| } |