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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 } | 476 } |
| 477 | 477 |
| 478 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) | 478 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) |
| 479 { | 479 { |
| 480 RefPtr<JSONObject> result = JSONObject::create(); | 480 RefPtr<JSONObject> result = JSONObject::create(); |
| 481 result->setNumber("width", size.width()); | 481 result->setNumber("width", size.width()); |
| 482 result->setNumber("height", size.height()); | 482 result->setNumber("height", size.height()); |
| 483 return result.release(); | 483 return result.release(); |
| 484 } | 484 } |
| 485 | 485 |
| 486 static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) | 486 // CSS shapes |
| 487 struct PathApplyInfo { | |
| 488 FrameView* rootView; | |
| 489 FrameView* view; | |
| 490 JSONArray* array; | |
| 491 RenderObject* renderer; | |
| 492 const ShapeOutsideInfo* shapeOutsideInfo; | |
| 493 }; | |
| 494 | |
| 495 static void appendPathCommandAndPoints(PathApplyInfo* info, const String& comman d, const FloatPoint points[], unsigned length) | |
| 496 { | |
| 497 FloatPoint point; | |
| 498 info->array->pushString(command); | |
| 499 for (unsigned i = 0; i < length; i++) { | |
| 500 point = info->shapeOutsideInfo->shapeToRendererPoint(points[i]); | |
| 501 point = info->view->contentsToRootView(roundedIntPoint(info->renderer->l ocalToAbsolute(point))) + info->rootView->scrollOffset(); | |
| 502 info->array->pushNumber(point.x()); | |
| 503 info->array->pushNumber(point.y()); | |
| 504 } | |
| 505 } | |
| 506 | |
| 507 static void appendPathSegment(void* info, const PathElement* pathElement) | |
| 508 { | |
| 509 PathApplyInfo* pathApplyInfo = static_cast<PathApplyInfo*>(info); | |
| 510 FloatPoint point; | |
| 511 switch (pathElement->type) { | |
| 512 // The points member will contain 1 value. | |
| 513 case PathElementMoveToPoint: | |
| 514 appendPathCommandAndPoints(pathApplyInfo, "M", pathElement->points, 1); | |
| 515 break; | |
| 516 // The points member will contain 1 value. | |
| 517 case PathElementAddLineToPoint: | |
| 518 appendPathCommandAndPoints(pathApplyInfo, "L", pathElement->points, 1); | |
| 519 break; | |
| 520 // The points member will contain 3 values. | |
| 521 case PathElementAddCurveToPoint: | |
| 522 appendPathCommandAndPoints(pathApplyInfo, "C", pathElement->points, 3); | |
| 523 break; | |
| 524 // The points member will contain 2 values. | |
| 525 case PathElementAddQuadCurveToPoint: | |
| 526 appendPathCommandAndPoints(pathApplyInfo, "Q", pathElement->points, 2); | |
| 527 break; | |
| 528 // The points member will contain no values. | |
| 529 case PathElementCloseSubpath: | |
| 530 appendPathCommandAndPoints(pathApplyInfo, "Z", 0, 0); | |
| 531 break; | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 static PassRefPtr<JSONObject> buildObjectForShapeOutsideLocal(Node* node) | |
| 536 { | |
| 537 RenderObject* renderer = node->renderer(); | |
| 538 RefPtr<JSONObject> shapeObject = JSONObject::create(); | |
| 539 | |
| 540 if (renderer && renderer->isBox()) { | |
| 541 LocalFrame* containingFrame = node->document().frame(); | |
| 542 RenderBox* renderBox = toRenderBox(renderer); | |
| 543 if (renderBox) { | |
| 544 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideIn fo(); | |
| 545 if (!shapeOutsideInfo) | |
| 546 return shapeObject.release(); | |
| 547 | |
| 548 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoun dingBox(); | |
| 549 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shape Bounds)); | |
| 550 FrameView* mainView = containingFrame->page()->mainFrame()->view(); | |
| 551 FrameView* containingView = containingFrame->view(); | |
| 552 contentsQuadToPage(mainView, containingView, shapeQuad); | |
| 553 shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad)); | |
| 554 | |
| 555 Shape::DisplayPaths paths; | |
| 556 shapeOutsideInfo->computedShape().buildDisplayPaths(paths); | |
| 557 | |
| 558 if (paths.shape.length()) { | |
| 559 RefPtr<JSONArray> shapePath = JSONArray::create(); | |
| 560 RefPtr<JSONArray> marginShapePath = JSONArray::create(); | |
| 561 PathApplyInfo info; | |
| 562 info.rootView = mainView; | |
| 563 info.view = containingView; | |
| 564 info.array = shapePath.get(); | |
| 565 info.renderer = renderBox; | |
| 566 info.shapeOutsideInfo = shapeOutsideInfo; | |
| 567 paths.shape.apply(&info, &appendPathSegment); | |
| 568 shapeObject->setArray("shape", shapePath.release()); | |
| 569 if (paths.marginShape.length()) { | |
| 570 info.array = marginShapePath.get(); | |
| 571 paths.marginShape.apply(&info, &appendPathSegment); | |
| 572 } | |
| 573 shapeObject->setArray("marginShape", marginShapePath.release()); | |
| 574 } | |
| 575 } | |
| 576 } | |
| 577 return shapeObject.release(); | |
| 578 } | |
| 579 | |
| 580 static RefPtr<TypeBuilder::Array<JSONValue> > buildArrayForShapeOutside(PassRefP tr<JSONValue> value) | |
| 581 { | |
| 582 RefPtr<TypeBuilder::Array<JSONValue> > array = TypeBuilder::Array<JSONValue> ::create(); | |
| 583 array->addItem(value); | |
| 584 return array.release(); | |
| 585 } | |
| 586 | |
| 587 static RefPtr<TypeBuilder::Array<double> > buildArrayForQuadTypeBuilder(const Fl oatQuad& quad) | |
| 588 { | |
| 589 RefPtr<TypeBuilder::Array<double> > array = TypeBuilder::Array<double>::crea te(); | |
| 590 array->addItem(quad.p1().x()); | |
| 591 array->addItem(quad.p1().y()); | |
| 592 array->addItem(quad.p2().x()); | |
| 593 array->addItem(quad.p2().y()); | |
| 594 array->addItem(quad.p3().x()); | |
| 595 array->addItem(quad.p3().y()); | |
| 596 array->addItem(quad.p4().x()); | |
| 597 array->addItem(quad.p4().y()); | |
| 598 return array.release(); | |
| 599 } | |
| 600 | |
| 601 PassRefPtr<TypeBuilder::DOM::ShapeOutsideInfo> InspectorOverlay::buildObjectForS hapeOutside(Node* node) | |
| 602 { | |
| 603 // Initialize the shapeObject | |
| 604 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeObject = TypeBuilder::DOM::S hapeOutsideInfo::create() | |
|
pfeldman
2014/05/02 07:21:54
You don't need this, see below.
Habib Virji
2014/05/02 09:39:22
Done.
| |
| 605 .setBounds(buildArrayForQuadTypeBuilder(FloatQuad())) | |
| 606 .setShape(buildArrayForShapeOutside(JSONValue::null())) | |
| 607 .setMarginShape(buildArrayForShapeOutside(JSONValue::null())); | |
| 608 | |
| 609 RenderObject* renderer = node->renderer(); | |
| 610 if (renderer->isBox()) { // This check is necessary as shapeOutside is not m andatory part of box model:w | |
|
pfeldman
2014/05/02 07:21:54
Since shapeOutside is optional, lets start with
Habib Virji
2014/05/02 09:39:22
Done.
| |
| 611 | |
| 612 RenderBox* renderBox = toRenderBox(renderer); | |
| 613 if (renderBox && renderBox->shapeOutsideInfo()) { | |
| 614 RefPtr<JSONObject> value = buildObjectForShapeOutsideLocal(node); | |
|
pfeldman
2014/05/02 07:21:54
Now instead of doing this, I'd suggest that you in
Habib Virji
2014/05/02 09:39:22
Done.
| |
| 615 if (!value) | |
| 616 return shapeObject.release(); | |
| 617 shapeObject = TypeBuilder::DOM::ShapeOutsideInfo::create() | |
| 618 .setBounds(buildArrayForQuadTypeBuilder(FloatQuad())) | |
|
pfeldman
2014/05/02 07:21:54
Why empty quad here?
Habib Virji
2014/05/02 09:39:22
Done.
| |
| 619 .setShape(buildArrayForShapeOutside(value->getArray("shape"))) | |
| 620 .setMarginShape(buildArrayForShapeOutside(value->getArray("margi nShape"))); | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 return shapeObject.release(); | |
| 625 } | |
| 626 | |
| 627 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec t>& shapeObject, Node* node) | |
| 487 { | 628 { |
| 488 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 629 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
| 489 Element* element = toElement(node); | 630 Element* element = toElement(node); |
| 490 Element* realElement = element; | 631 Element* realElement = element; |
| 491 PseudoElement* pseudoElement = 0; | 632 PseudoElement* pseudoElement = 0; |
| 492 if (element->isPseudoElement()) { | 633 if (element->isPseudoElement()) { |
| 493 pseudoElement = toPseudoElement(element); | 634 pseudoElement = toPseudoElement(element); |
| 494 realElement = element->parentOrShadowHostElement(); | 635 realElement = element->parentOrShadowHostElement(); |
| 495 } | 636 } |
| 496 bool isXHTML = realElement->document().isXHTMLDocument(); | 637 bool isXHTML = realElement->document().isXHTMLDocument(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 518 if (!classNames.isEmpty()) | 659 if (!classNames.isEmpty()) |
| 519 elementInfo->setString("className", classNames.toString()); | 660 elementInfo->setString("className", classNames.toString()); |
| 520 | 661 |
| 521 RenderObject* renderer = node->renderer(); | 662 RenderObject* renderer = node->renderer(); |
| 522 LocalFrame* containingFrame = node->document().frame(); | 663 LocalFrame* containingFrame = node->document().frame(); |
| 523 FrameView* containingView = containingFrame->view(); | 664 FrameView* containingView = containingFrame->view(); |
| 524 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); | 665 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); |
| 525 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; | 666 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; |
| 526 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); | 667 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); |
| 527 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); | 668 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); |
| 669 if (renderer->isBox() && shapeObject) | |
| 670 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); | |
| 528 highlightObject->setObject("elementInfo", elementInfo.release()); | 671 highlightObject->setObject("elementInfo", elementInfo.release()); |
| 529 } | 672 } |
| 530 | 673 |
| 531 void InspectorOverlay::drawNodeHighlight() | 674 void InspectorOverlay::drawNodeHighlight() |
| 532 { | 675 { |
| 533 if (!m_highlightNode) | 676 if (!m_highlightNode) |
| 534 return; | 677 return; |
| 535 | 678 |
| 536 Highlight highlight; | 679 Highlight highlight; |
| 537 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; | 680 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; |
| 538 if (m_eventTargetNode) { | 681 if (m_eventTargetNode) { |
| 539 Highlight eventTargetHighlight; | 682 Highlight eventTargetHighlight; |
| 540 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); | 683 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); |
| 541 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. | 684 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. |
| 542 } | 685 } |
| 543 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 686 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
| 544 | 687 |
| 545 Node* node = m_highlightNode.get(); | 688 Node* node = m_highlightNode.get(); |
| 689 RefPtr<JSONObject> shapeObject = buildObjectForShapeOutsideLocal(node); | |
|
pfeldman
2014/05/02 07:21:54
RefPtr<JSONObject> shapeObject = buildObjectForSha
Habib Virji
2014/05/02 09:39:22
Done.
| |
| 546 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) | 690 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) |
| 547 setElementInfo(highlightObject, node); | 691 setElementInfo(highlightObject, shapeObject, node); |
| 548 evaluateInOverlay("drawNodeHighlight", highlightObject); | 692 evaluateInOverlay("drawNodeHighlight", highlightObject); |
| 549 } | 693 } |
| 550 | 694 |
| 551 void InspectorOverlay::drawQuadHighlight() | 695 void InspectorOverlay::drawQuadHighlight() |
| 552 { | 696 { |
| 553 if (!m_highlightQuad) | 697 if (!m_highlightQuad) |
| 554 return; | 698 return; |
| 555 | 699 |
| 556 Highlight highlight; | 700 Highlight highlight; |
| 557 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); | 701 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 hideHighlight(); | 827 hideHighlight(); |
| 684 } | 828 } |
| 685 | 829 |
| 686 void InspectorOverlay::startedRecordingProfile() | 830 void InspectorOverlay::startedRecordingProfile() |
| 687 { | 831 { |
| 688 if (!m_activeProfilerCount++) | 832 if (!m_activeProfilerCount++) |
| 689 freePage(); | 833 freePage(); |
| 690 } | 834 } |
| 691 | 835 |
| 692 } // namespace WebCore | 836 } // namespace WebCore |
| OLD | NEW |