| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/inspector/InspectorHighlight.h" | 5 #include "core/inspector/InspectorHighlight.h" |
| 6 | 6 |
| 7 #include "core/dom/ClientRect.h" | 7 #include "core/dom/ClientRect.h" |
| 8 #include "core/dom/PseudoElement.h" | 8 #include "core/dom/PseudoElement.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
| 11 #include "core/layout/LayoutInline.h" | 11 #include "core/layout/LayoutInline.h" |
| 12 #include "core/layout/LayoutObject.h" | 12 #include "core/layout/LayoutObject.h" |
| 13 #include "core/layout/shapes/ShapeOutsideInfo.h" | 13 #include "core/layout/shapes/ShapeOutsideInfo.h" |
| 14 #include "core/style/ComputedStyleConstants.h" | 14 #include "core/style/ComputedStyleConstants.h" |
| 15 #include "platform/graphics/Path.h" | 15 #include "platform/graphics/Path.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class PathBuilder { | 21 class PathBuilder { |
| 22 STACK_ALLOCATED(); | 22 STACK_ALLOCATED(); |
| 23 WTF_MAKE_NONCOPYABLE(PathBuilder); | 23 WTF_MAKE_NONCOPYABLE(PathBuilder); |
| 24 public: | 24 public: |
| 25 PathBuilder() : m_path(JSONArray::create()) { } | 25 PathBuilder() : m_path(protocol::ListValue::create()) { } |
| 26 virtual ~PathBuilder() { } | 26 virtual ~PathBuilder() { } |
| 27 | 27 |
| 28 PassRefPtr<JSONArray> path() const { return m_path; } | 28 PassRefPtr<protocol::ListValue> path() const { return m_path; } |
| 29 | 29 |
| 30 void appendPath(const Path& path) | 30 void appendPath(const Path& path) |
| 31 { | 31 { |
| 32 path.apply(this, &PathBuilder::appendPathElement); | 32 path.apply(this, &PathBuilder::appendPathElement); |
| 33 } | 33 } |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 virtual FloatPoint translatePoint(const FloatPoint& point) { return point; } | 36 virtual FloatPoint translatePoint(const FloatPoint& point) { return point; } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 static void appendPathElement(void* pathBuilder, const PathElement* pathElem
ent) | 39 static void appendPathElement(void* pathBuilder, const PathElement* pathElem
ent) |
| 40 { | 40 { |
| 41 static_cast<PathBuilder*>(pathBuilder)->appendPathElement(pathElement); | 41 static_cast<PathBuilder*>(pathBuilder)->appendPathElement(pathElement); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void appendPathElement(const PathElement*); | 44 void appendPathElement(const PathElement*); |
| 45 void appendPathCommandAndPoints(const char* command, const FloatPoint points
[], size_t length); | 45 void appendPathCommandAndPoints(const char* command, const FloatPoint points
[], size_t length); |
| 46 | 46 |
| 47 RefPtr<JSONArray> m_path; | 47 RefPtr<protocol::ListValue> m_path; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 void PathBuilder::appendPathCommandAndPoints(const char* command, const FloatPoi
nt points[], size_t length) | 50 void PathBuilder::appendPathCommandAndPoints(const char* command, const FloatPoi
nt points[], size_t length) |
| 51 { | 51 { |
| 52 m_path->pushString(command); | 52 m_path->pushValue(protocol::StringValue::create(command)); |
| 53 for (size_t i = 0; i < length; i++) { | 53 for (size_t i = 0; i < length; i++) { |
| 54 FloatPoint point = translatePoint(points[i]); | 54 FloatPoint point = translatePoint(points[i]); |
| 55 m_path->pushNumber(point.x()); | 55 m_path->pushValue(protocol::FundamentalValue::create(point.x())); |
| 56 m_path->pushNumber(point.y()); | 56 m_path->pushValue(protocol::FundamentalValue::create(point.y())); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void PathBuilder::appendPathElement(const PathElement* pathElement) | 60 void PathBuilder::appendPathElement(const PathElement* pathElement) |
| 61 { | 61 { |
| 62 switch (pathElement->type) { | 62 switch (pathElement->type) { |
| 63 // The points member will contain 1 value. | 63 // The points member will contain 1 value. |
| 64 case PathElementMoveToPoint: | 64 case PathElementMoveToPoint: |
| 65 appendPathCommandAndPoints("M", pathElement->points, 1); | 65 appendPathCommandAndPoints("M", pathElement->points, 1); |
| 66 break; | 66 break; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 class ShapePathBuilder : public PathBuilder { | 86 class ShapePathBuilder : public PathBuilder { |
| 87 public: | 87 public: |
| 88 ShapePathBuilder(FrameView& view, LayoutObject& layoutObject, const ShapeOut
sideInfo& shapeOutsideInfo) | 88 ShapePathBuilder(FrameView& view, LayoutObject& layoutObject, const ShapeOut
sideInfo& shapeOutsideInfo) |
| 89 : m_view(&view) | 89 : m_view(&view) |
| 90 , m_layoutObject(layoutObject) | 90 , m_layoutObject(layoutObject) |
| 91 , m_shapeOutsideInfo(shapeOutsideInfo) { } | 91 , m_shapeOutsideInfo(shapeOutsideInfo) { } |
| 92 | 92 |
| 93 static RefPtr<JSONArray> buildPath(FrameView& view, LayoutObject& layoutObje
ct, const ShapeOutsideInfo& shapeOutsideInfo, const Path& path) | 93 static RefPtr<protocol::ListValue> buildPath(FrameView& view, LayoutObject&
layoutObject, const ShapeOutsideInfo& shapeOutsideInfo, const Path& path) |
| 94 { | 94 { |
| 95 ShapePathBuilder builder(view, layoutObject, shapeOutsideInfo); | 95 ShapePathBuilder builder(view, layoutObject, shapeOutsideInfo); |
| 96 builder.appendPath(path); | 96 builder.appendPath(path); |
| 97 return builder.path(); | 97 return builder.path(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 protected: | 100 protected: |
| 101 virtual FloatPoint translatePoint(const FloatPoint& point) | 101 virtual FloatPoint translatePoint(const FloatPoint& point) |
| 102 { | 102 { |
| 103 FloatPoint layoutObjectPoint = m_shapeOutsideInfo.shapeToLayoutObjectPoi
nt(point); | 103 FloatPoint layoutObjectPoint = m_shapeOutsideInfo.shapeToLayoutObjectPoi
nt(point); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 shapeOutsideInfo->computedShape().buildDisplayPaths(*paths); | 157 shapeOutsideInfo->computedShape().buildDisplayPaths(*paths); |
| 158 | 158 |
| 159 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox(
); | 159 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox(
); |
| 160 *bounds = layoutBox->localToAbsoluteQuad(FloatRect(shapeBounds)); | 160 *bounds = layoutBox->localToAbsoluteQuad(FloatRect(shapeBounds)); |
| 161 contentsQuadToViewport(containingView, *bounds); | 161 contentsQuadToViewport(containingView, *bounds); |
| 162 | 162 |
| 163 return shapeOutsideInfo; | 163 return shapeOutsideInfo; |
| 164 } | 164 } |
| 165 | 165 |
| 166 PassRefPtr<JSONObject> buildElementInfo(Element* element) | 166 PassRefPtr<protocol::DictionaryValue> buildElementInfo(Element* element) |
| 167 { | 167 { |
| 168 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 168 RefPtr<protocol::DictionaryValue> elementInfo = protocol::DictionaryValue::c
reate(); |
| 169 Element* realElement = element; | 169 Element* realElement = element; |
| 170 PseudoElement* pseudoElement = nullptr; | 170 PseudoElement* pseudoElement = nullptr; |
| 171 if (element->isPseudoElement()) { | 171 if (element->isPseudoElement()) { |
| 172 pseudoElement = toPseudoElement(element); | 172 pseudoElement = toPseudoElement(element); |
| 173 realElement = element->parentOrShadowHostElement(); | 173 realElement = element->parentOrShadowHostElement(); |
| 174 } | 174 } |
| 175 bool isXHTML = realElement->document().isXHTMLDocument(); | 175 bool isXHTML = realElement->document().isXHTMLDocument(); |
| 176 elementInfo->setString("tagName", isXHTML ? realElement->nodeName() : realEl
ement->nodeName().lower()); | 176 elementInfo->setString("tagName", isXHTML ? realElement->nodeName() : realEl
ement->nodeName().lower()); |
| 177 elementInfo->setString("idValue", realElement->getIdAttribute()); | 177 elementInfo->setString("idValue", realElement->getIdAttribute()); |
| 178 StringBuilder classNames; | 178 StringBuilder classNames; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 207 ClientRect* boundingBox = element->getBoundingClientRect(); | 207 ClientRect* boundingBox = element->getBoundingClientRect(); |
| 208 elementInfo->setString("nodeWidth", String::number(boundingBox->width())); | 208 elementInfo->setString("nodeWidth", String::number(boundingBox->width())); |
| 209 elementInfo->setString("nodeHeight", String::number(boundingBox->height())); | 209 elementInfo->setString("nodeHeight", String::number(boundingBox->height())); |
| 210 | 210 |
| 211 return elementInfo; | 211 return elementInfo; |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace | 214 } // namespace |
| 215 | 215 |
| 216 InspectorHighlight::InspectorHighlight() | 216 InspectorHighlight::InspectorHighlight() |
| 217 : m_highlightPaths(JSONArray::create()) | 217 : m_highlightPaths(protocol::ListValue::create()) |
| 218 , m_showRulers(false) | 218 , m_showRulers(false) |
| 219 , m_showExtensionLines(false) | 219 , m_showExtensionLines(false) |
| 220 , m_displayAsMaterial(false) | 220 , m_displayAsMaterial(false) |
| 221 { | 221 { |
| 222 } | 222 } |
| 223 | 223 |
| 224 InspectorHighlightConfig::InspectorHighlightConfig() | 224 InspectorHighlightConfig::InspectorHighlightConfig() |
| 225 : showInfo(false) | 225 : showInfo(false) |
| 226 , showRulers(false) | 226 , showRulers(false) |
| 227 , showExtensionLines(false) | 227 , showExtensionLines(false) |
| 228 , displayAsMaterial(false) | 228 , displayAsMaterial(false) |
| 229 { | 229 { |
| 230 } | 230 } |
| 231 | 231 |
| 232 InspectorHighlight::InspectorHighlight(Node* node, const InspectorHighlightConfi
g& highlightConfig, bool appendElementInfo) | 232 InspectorHighlight::InspectorHighlight(Node* node, const InspectorHighlightConfi
g& highlightConfig, bool appendElementInfo) |
| 233 : m_highlightPaths(JSONArray::create()) | 233 : m_highlightPaths(protocol::ListValue::create()) |
| 234 , m_showRulers(highlightConfig.showRulers) | 234 , m_showRulers(highlightConfig.showRulers) |
| 235 , m_showExtensionLines(highlightConfig.showExtensionLines) | 235 , m_showExtensionLines(highlightConfig.showExtensionLines) |
| 236 , m_displayAsMaterial(highlightConfig.displayAsMaterial) | 236 , m_displayAsMaterial(highlightConfig.displayAsMaterial) |
| 237 { | 237 { |
| 238 appendPathsForShapeOutside(node, highlightConfig); | 238 appendPathsForShapeOutside(node, highlightConfig); |
| 239 appendNodeHighlight(node, highlightConfig); | 239 appendNodeHighlight(node, highlightConfig); |
| 240 if (appendElementInfo && node->isElementNode()) | 240 if (appendElementInfo && node->isElementNode()) |
| 241 m_elementInfo = buildElementInfo(toElement(node)); | 241 m_elementInfo = buildElementInfo(toElement(node)); |
| 242 } | 242 } |
| 243 | 243 |
| 244 InspectorHighlight::~InspectorHighlight() | 244 InspectorHighlight::~InspectorHighlight() |
| 245 { | 245 { |
| 246 } | 246 } |
| 247 | 247 |
| 248 void InspectorHighlight::appendQuad(const FloatQuad& quad, const Color& fillColo
r, const Color& outlineColor, const String& name) | 248 void InspectorHighlight::appendQuad(const FloatQuad& quad, const Color& fillColo
r, const Color& outlineColor, const String& name) |
| 249 { | 249 { |
| 250 Path path = quadToPath(quad); | 250 Path path = quadToPath(quad); |
| 251 PathBuilder builder; | 251 PathBuilder builder; |
| 252 builder.appendPath(path); | 252 builder.appendPath(path); |
| 253 appendPath(builder.path(), fillColor, outlineColor, name); | 253 appendPath(builder.path(), fillColor, outlineColor, name); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void InspectorHighlight::appendPath(PassRefPtr<JSONArray> path, const Color& fil
lColor, const Color& outlineColor, const String& name) | 256 void InspectorHighlight::appendPath(PassRefPtr<protocol::ListValue> path, const
Color& fillColor, const Color& outlineColor, const String& name) |
| 257 { | 257 { |
| 258 RefPtr<JSONObject> object = JSONObject::create(); | 258 RefPtr<protocol::DictionaryValue> object = protocol::DictionaryValue::create
(); |
| 259 object->setValue("path", path); | 259 object->setValue("path", path); |
| 260 object->setString("fillColor", fillColor.serialized()); | 260 object->setString("fillColor", fillColor.serialized()); |
| 261 if (outlineColor != Color::transparent) | 261 if (outlineColor != Color::transparent) |
| 262 object->setString("outlineColor", outlineColor.serialized()); | 262 object->setString("outlineColor", outlineColor.serialized()); |
| 263 if (!name.isEmpty()) | 263 if (!name.isEmpty()) |
| 264 object->setString("name", name); | 264 object->setString("name", name); |
| 265 m_highlightPaths->pushObject(object.release()); | 265 m_highlightPaths->pushValue(object.release()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void InspectorHighlight::appendEventTargetQuads(Node* eventTargetNode, const Ins
pectorHighlightConfig& highlightConfig) | 268 void InspectorHighlight::appendEventTargetQuads(Node* eventTargetNode, const Ins
pectorHighlightConfig& highlightConfig) |
| 269 { | 269 { |
| 270 if (eventTargetNode->layoutObject()) { | 270 if (eventTargetNode->layoutObject()) { |
| 271 FloatQuad border, unused; | 271 FloatQuad border, unused; |
| 272 if (buildNodeQuads(eventTargetNode, &unused, &unused, &border, &unused)) | 272 if (buildNodeQuads(eventTargetNode, &unused, &unused, &border, &unused)) |
| 273 appendQuad(border, highlightConfig.eventTarget); | 273 appendQuad(border, highlightConfig.eventTarget); |
| 274 } | 274 } |
| 275 } | 275 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 314 |
| 315 FloatQuad content, padding, border, margin; | 315 FloatQuad content, padding, border, margin; |
| 316 if (!buildNodeQuads(node, &content, &padding, &border, &margin)) | 316 if (!buildNodeQuads(node, &content, &padding, &border, &margin)) |
| 317 return; | 317 return; |
| 318 appendQuad(content, highlightConfig.content, highlightConfig.contentOutline,
"content"); | 318 appendQuad(content, highlightConfig.content, highlightConfig.contentOutline,
"content"); |
| 319 appendQuad(padding, highlightConfig.padding, Color::transparent, "padding"); | 319 appendQuad(padding, highlightConfig.padding, Color::transparent, "padding"); |
| 320 appendQuad(border, highlightConfig.border, Color::transparent, "border"); | 320 appendQuad(border, highlightConfig.border, Color::transparent, "border"); |
| 321 appendQuad(margin, highlightConfig.margin, Color::transparent, "margin"); | 321 appendQuad(margin, highlightConfig.margin, Color::transparent, "margin"); |
| 322 } | 322 } |
| 323 | 323 |
| 324 PassRefPtr<JSONObject> InspectorHighlight::asJSONObject() const | 324 PassRefPtr<protocol::DictionaryValue> InspectorHighlight::asProtocolValue() cons
t |
| 325 { | 325 { |
| 326 RefPtr<JSONObject> object = JSONObject::create(); | 326 RefPtr<protocol::DictionaryValue> object = protocol::DictionaryValue::create
(); |
| 327 object->setArray("paths", m_highlightPaths); | 327 object->setArray("paths", m_highlightPaths); |
| 328 object->setBoolean("showRulers", m_showRulers); | 328 object->setBoolean("showRulers", m_showRulers); |
| 329 object->setBoolean("showExtensionLines", m_showExtensionLines); | 329 object->setBoolean("showExtensionLines", m_showExtensionLines); |
| 330 if (m_elementInfo) | 330 if (m_elementInfo) |
| 331 object->setObject("elementInfo", m_elementInfo); | 331 object->setObject("elementInfo", m_elementInfo); |
| 332 object->setBoolean("displayAsMaterial", m_displayAsMaterial); | 332 object->setBoolean("displayAsMaterial", m_displayAsMaterial); |
| 333 return object.release(); | 333 return object.release(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 // static | 336 // static |
| (...skipping 18 matching lines...) Expand all Loading... |
| 355 .setMargin(buildArrayForQuad(margin)) | 355 .setMargin(buildArrayForQuad(margin)) |
| 356 .setWidth(modelObject ? adjustForAbsoluteZoom(modelObject->pixelSnappedO
ffsetWidth(), modelObject) : boundingBox.width()) | 356 .setWidth(modelObject ? adjustForAbsoluteZoom(modelObject->pixelSnappedO
ffsetWidth(), modelObject) : boundingBox.width()) |
| 357 .setHeight(modelObject ? adjustForAbsoluteZoom(modelObject->pixelSnapped
OffsetHeight(), modelObject) : boundingBox.height()).build(); | 357 .setHeight(modelObject ? adjustForAbsoluteZoom(modelObject->pixelSnapped
OffsetHeight(), modelObject) : boundingBox.height()).build(); |
| 358 | 358 |
| 359 Shape::DisplayPaths paths; | 359 Shape::DisplayPaths paths; |
| 360 FloatQuad boundsQuad; | 360 FloatQuad boundsQuad; |
| 361 protocol::ErrorSupport errors; | 361 protocol::ErrorSupport errors; |
| 362 if (const ShapeOutsideInfo* shapeOutsideInfo = shapeOutsideInfoForNode(node,
&paths, &boundsQuad)) { | 362 if (const ShapeOutsideInfo* shapeOutsideInfo = shapeOutsideInfoForNode(node,
&paths, &boundsQuad)) { |
| 363 (*model)->setShapeOutside(protocol::DOM::ShapeOutsideInfo::create() | 363 (*model)->setShapeOutside(protocol::DOM::ShapeOutsideInfo::create() |
| 364 .setBounds(buildArrayForQuad(boundsQuad)) | 364 .setBounds(buildArrayForQuad(boundsQuad)) |
| 365 .setShape(protocol::Array<RefPtr<JSONValue>>::parse(ShapePathBuilder
::buildPath(*view, *layoutObject, *shapeOutsideInfo, paths.shape), &errors)) | 365 .setShape(protocol::Array<RefPtr<protocol::Value>>::parse(ShapePathB
uilder::buildPath(*view, *layoutObject, *shapeOutsideInfo, paths.shape), &errors
)) |
| 366 .setMarginShape(protocol::Array<RefPtr<JSONValue>>::parse(ShapePathB
uilder::buildPath(*view, *layoutObject, *shapeOutsideInfo, paths.marginShape), &
errors)) | 366 .setMarginShape(protocol::Array<RefPtr<protocol::Value>>::parse(Shap
ePathBuilder::buildPath(*view, *layoutObject, *shapeOutsideInfo, paths.marginSha
pe), &errors)) |
| 367 .build()); | 367 .build()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 return true; | 370 return true; |
| 371 } | 371 } |
| 372 | 372 |
| 373 bool InspectorHighlight::buildNodeQuads(Node* node, FloatQuad* content, FloatQua
d* padding, FloatQuad* border, FloatQuad* margin) | 373 bool InspectorHighlight::buildNodeQuads(Node* node, FloatQuad* content, FloatQua
d* padding, FloatQuad* border, FloatQuad* margin) |
| 374 { | 374 { |
| 375 LayoutObject* layoutObject = node->layoutObject(); | 375 LayoutObject* layoutObject = node->layoutObject(); |
| 376 if (!layoutObject) | 376 if (!layoutObject) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 config.shape = Color(0, 0, 0, 0); | 445 config.shape = Color(0, 0, 0, 0); |
| 446 config.shapeMargin = Color(128, 128, 128, 0); | 446 config.shapeMargin = Color(128, 128, 128, 0); |
| 447 config.showInfo = true; | 447 config.showInfo = true; |
| 448 config.showRulers = true; | 448 config.showRulers = true; |
| 449 config.showExtensionLines = true; | 449 config.showExtensionLines = true; |
| 450 config.displayAsMaterial = false; | 450 config.displayAsMaterial = false; |
| 451 return config; | 451 return config; |
| 452 } | 452 } |
| 453 | 453 |
| 454 } // namespace blink | 454 } // namespace blink |
| OLD | NEW |