Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 } | 488 } |
| 489 | 489 |
| 490 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) | 490 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) |
| 491 { | 491 { |
| 492 RefPtr<JSONObject> result = JSONObject::create(); | 492 RefPtr<JSONObject> result = JSONObject::create(); |
| 493 result->setNumber("width", size.width()); | 493 result->setNumber("width", size.width()); |
| 494 result->setNumber("height", size.height()); | 494 result->setNumber("height", size.height()); |
| 495 return result.release(); | 495 return result.release(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) | 498 // CSS shapes |
| 499 struct PathApplyInfo { | |
| 500 FrameView* rootView; | |
| 501 FrameView* view; | |
| 502 JSONArray* array; | |
| 503 RenderObject* renderer; | |
| 504 const ShapeOutsideInfo* shapeOutsideInfo; | |
| 505 }; | |
| 506 | |
| 507 static void appendPathCommandAndPoints(PathApplyInfo* info, const String& comman d, const FloatPoint points[], unsigned length) | |
| 508 { | |
| 509 FloatPoint point; | |
| 510 info->array->pushString(command); | |
| 511 for (unsigned i = 0; i < length; i++) { | |
| 512 point = info->shapeOutsideInfo->shapeToRendererPoint(points[i]); | |
| 513 point = info->view->contentsToRootView(roundedIntPoint(info->renderer->l ocalToAbsolute(point))) + info->rootView->scrollOffset(); | |
| 514 info->array->pushNumber(point.x()); | |
| 515 info->array->pushNumber(point.y()); | |
| 516 } | |
| 517 } | |
| 518 | |
| 519 static void appendPathSegment(void* info, const PathElement* pathElement) | |
| 520 { | |
| 521 PathApplyInfo* pathApplyInfo = static_cast<PathApplyInfo*>(info); | |
| 522 FloatPoint point; | |
|
rwlbuis
2014/04/24 15:17:27
point is not used?
Habib Virji
2014/04/24 17:12:22
Done.
| |
| 523 switch (pathElement->type) { | |
| 524 // The points member will contain 1 value. | |
| 525 case PathElementMoveToPoint: | |
| 526 appendPathCommandAndPoints(pathApplyInfo, "M", pathElement->points, 1); | |
| 527 break; | |
| 528 // The points member will contain 1 value. | |
| 529 case PathElementAddLineToPoint: | |
| 530 appendPathCommandAndPoints(pathApplyInfo, "L", pathElement->points, 1); | |
| 531 break; | |
| 532 // The points member will contain 3 values. | |
| 533 case PathElementAddCurveToPoint: | |
| 534 appendPathCommandAndPoints(pathApplyInfo, "C", pathElement->points, 3); | |
| 535 break; | |
| 536 // The points member will contain 2 values. | |
| 537 case PathElementAddQuadCurveToPoint: | |
| 538 appendPathCommandAndPoints(pathApplyInfo, "Q", pathElement->points, 2); | |
| 539 break; | |
| 540 // The points member will contain no values. | |
| 541 case PathElementCloseSubpath: | |
| 542 appendPathCommandAndPoints(pathApplyInfo, "Z", 0, 0); | |
| 543 break; | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 PassRefPtr<JSONObject> InspectorOverlay::buildObjectForShapeOutside() | |
| 548 { | |
| 549 Node* node = m_highlightNode.get(); | |
| 550 RenderObject* renderer = node->renderer(); | |
| 551 if (renderer && renderer->isBox()) { | |
| 552 LocalFrame* containingFrame = node->document().frame(); | |
| 553 RenderBox* renderBox = toRenderBox(renderer); | |
| 554 | |
| 555 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo() ; | |
| 556 if (!shapeOutsideInfo) | |
| 557 return nullptr; | |
| 558 | |
| 559 RefPtr<JSONObject> shapeObject = JSONObject::create(); | |
| 560 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBounding Box(); | |
| 561 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBoun ds)); | |
| 562 FrameView* mainView = containingFrame->page()->mainFrame()->view(); | |
| 563 FrameView* containingView = containingFrame->view(); | |
| 564 contentsQuadToPage(mainView, containingView, shapeQuad); | |
| 565 shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad)); | |
| 566 | |
| 567 Shape::DisplayPaths paths; | |
| 568 shapeOutsideInfo->computedShape().buildDisplayPaths(paths); | |
| 569 | |
| 570 if (paths.shape.length()) { | |
| 571 RefPtr<JSONArray> shapePath = JSONArray::create(); | |
| 572 PathApplyInfo info; | |
| 573 info.rootView = mainView; | |
| 574 info.view = containingView; | |
| 575 info.array = shapePath.get(); | |
| 576 info.renderer = renderBox; | |
| 577 info.shapeOutsideInfo = shapeOutsideInfo; | |
| 578 paths.shape.apply(&info, &appendPathSegment); | |
| 579 shapeObject->setArray("shape", shapePath.release()); | |
| 580 if (paths.marginShape.length()) { | |
| 581 shapePath = JSONArray::create(); | |
| 582 info.array = shapePath.get(); | |
| 583 paths.marginShape.apply(&info, &appendPathSegment); | |
| 584 shapeObject->setArray("marginShape", shapePath.release()); | |
| 585 } | |
| 586 } | |
| 587 return shapeObject.release(); | |
| 588 } | |
| 589 return nullptr; | |
| 590 } | |
| 591 | |
| 592 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec t>& shapeObject, Node* node) | |
| 499 { | 593 { |
| 500 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 594 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
| 501 Element* element = toElement(node); | 595 Element* element = toElement(node); |
| 502 Element* realElement = element; | 596 Element* realElement = element; |
| 503 PseudoElement* pseudoElement = 0; | 597 PseudoElement* pseudoElement = 0; |
| 504 if (element->isPseudoElement()) { | 598 if (element->isPseudoElement()) { |
| 505 pseudoElement = toPseudoElement(element); | 599 pseudoElement = toPseudoElement(element); |
| 506 realElement = element->parentOrShadowHostElement(); | 600 realElement = element->parentOrShadowHostElement(); |
| 507 } | 601 } |
| 508 bool isXHTML = realElement->document().isXHTMLDocument(); | 602 bool isXHTML = realElement->document().isXHTMLDocument(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 530 if (!classNames.isEmpty()) | 624 if (!classNames.isEmpty()) |
| 531 elementInfo->setString("className", classNames.toString()); | 625 elementInfo->setString("className", classNames.toString()); |
| 532 | 626 |
| 533 RenderObject* renderer = node->renderer(); | 627 RenderObject* renderer = node->renderer(); |
| 534 LocalFrame* containingFrame = node->document().frame(); | 628 LocalFrame* containingFrame = node->document().frame(); |
| 535 FrameView* containingView = containingFrame->view(); | 629 FrameView* containingView = containingFrame->view(); |
| 536 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); | 630 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); |
| 537 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; | 631 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; |
| 538 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); | 632 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); |
| 539 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); | 633 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); |
| 634 if (renderer->isBox() && shapeObject) | |
| 635 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); | |
| 540 highlightObject->setObject("elementInfo", elementInfo.release()); | 636 highlightObject->setObject("elementInfo", elementInfo.release()); |
| 541 } | 637 } |
| 542 | 638 |
| 543 void InspectorOverlay::drawNodeHighlight() | 639 void InspectorOverlay::drawNodeHighlight() |
| 544 { | 640 { |
| 545 if (!m_highlightNode) | 641 if (!m_highlightNode) |
| 546 return; | 642 return; |
| 547 | 643 |
| 548 Highlight highlight; | 644 Highlight highlight; |
| 549 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; | 645 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; |
| 550 if (m_eventTargetNode) { | 646 if (m_eventTargetNode) { |
| 551 Highlight eventTargetHighlight; | 647 Highlight eventTargetHighlight; |
| 552 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); | 648 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); |
| 553 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. | 649 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. |
| 554 } | 650 } |
| 555 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 651 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
| 652 RefPtr<JSONObject> shapeObject = buildObjectForShapeOutside(); | |
| 556 | 653 |
| 557 Node* node = m_highlightNode.get(); | 654 Node* node = m_highlightNode.get(); |
| 558 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) | 655 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) |
| 559 setElementInfo(highlightObject, node); | 656 setElementInfo(highlightObject, shapeObject, node); |
| 560 evaluateInOverlay("drawNodeHighlight", highlightObject); | 657 evaluateInOverlay("drawNodeHighlight", highlightObject); |
| 561 } | 658 } |
| 562 | 659 |
| 563 void InspectorOverlay::drawQuadHighlight() | 660 void InspectorOverlay::drawQuadHighlight() |
| 564 { | 661 { |
| 565 if (!m_highlightQuad) | 662 if (!m_highlightQuad) |
| 566 return; | 663 return; |
| 567 | 664 |
| 568 Highlight highlight; | 665 Highlight highlight; |
| 569 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); | 666 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 m_timer.stop(); | 789 m_timer.stop(); |
| 693 } | 790 } |
| 694 | 791 |
| 695 void InspectorOverlay::startedRecordingProfile() | 792 void InspectorOverlay::startedRecordingProfile() |
| 696 { | 793 { |
| 697 if (!m_activeProfilerCount++) | 794 if (!m_activeProfilerCount++) |
| 698 freePage(); | 795 freePage(); |
| 699 } | 796 } |
| 700 | 797 |
| 701 } // namespace WebCore | 798 } // namespace WebCore |
| OLD | NEW |