Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Unified Diff: Source/core/inspector/InspectorOverlay.cpp

Issue 237313003: CSS shapes support in Web Inspector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated test to use inspector protocol instead of internals Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/inspector/InspectorOverlay.h ('k') | Source/core/inspector/InspectorOverlayPage.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorOverlay.cpp
diff --git a/Source/core/inspector/InspectorOverlay.cpp b/Source/core/inspector/InspectorOverlay.cpp
index 522204b02d4aaeead087fe736ea53120844822af..3e919b8d5351e6308de7c9852c9c3e124103415c 100644
--- a/Source/core/inspector/InspectorOverlay.cpp
+++ b/Source/core/inspector/InspectorOverlay.cpp
@@ -483,7 +483,100 @@ 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;
+ 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 PassRefPtr<JSONObject> buildObjectForShapeOutside(Node *node)
+{
+ 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);
@@ -525,6 +618,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 +638,9 @@ void InspectorOverlay::drawNodeHighlight()
RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight);
Node* node = m_highlightNode.get();
+ RefPtr<JSONObject> shapeObject = buildObjectForShapeOutside(node);
if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInfo && node->renderer() && node->document().frame())
- setElementInfo(highlightObject, node);
+ setElementInfo(highlightObject, shapeObject, node);
evaluateInOverlay("drawNodeHighlight", highlightObject);
}
@@ -662,8 +758,10 @@ void InspectorOverlay::onTimer(Timer<InspectorOverlay>*)
update();
}
-bool InspectorOverlay::getBoxModel(Node* node, Vector<FloatQuad>* quads)
+bool InspectorOverlay::getBoxModel(Node* node, Vector<FloatQuad>* quads, String& shapeOutsideStr)
{
+ RefPtr<JSONObject> shapeOutsideInfo = buildObjectForShapeOutside(node);
+ shapeOutsideStr = shapeOutsideInfo ? shapeOutsideInfo->toJSONString() : String();
pfeldman 2014/04/30 07:43:48 You should not serialize shape into a string, decl
Habib Virji 2014/05/01 09:52:07 Done.
return buildNodeQuads(node, *quads);
}
« no previous file with comments | « Source/core/inspector/InspectorOverlay.h ('k') | Source/core/inspector/InspectorOverlayPage.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698