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> buildObjectForShapeOutside(Node *node) | |
536 { | |
537 RenderObject* renderer = node->renderer(); | |
538 if (renderer && renderer->isBox()) { | |
539 LocalFrame* containingFrame = node->document().frame(); | |
540 RenderBox* renderBox = toRenderBox(renderer); | |
541 | |
542 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo() ; | |
543 if (!shapeOutsideInfo) | |
544 return nullptr; | |
545 | |
546 RefPtr<JSONObject> shapeObject = JSONObject::create(); | |
547 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBounding Box(); | |
548 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBoun ds)); | |
549 FrameView* mainView = containingFrame->page()->mainFrame()->view(); | |
550 FrameView* containingView = containingFrame->view(); | |
551 contentsQuadToPage(mainView, containingView, shapeQuad); | |
552 shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad)); | |
553 | |
554 Shape::DisplayPaths paths; | |
555 shapeOutsideInfo->computedShape().buildDisplayPaths(paths); | |
556 | |
557 if (paths.shape.length()) { | |
558 RefPtr<JSONArray> shapePath = JSONArray::create(); | |
559 PathApplyInfo info; | |
560 info.rootView = mainView; | |
561 info.view = containingView; | |
562 info.array = shapePath.get(); | |
563 info.renderer = renderBox; | |
564 info.shapeOutsideInfo = shapeOutsideInfo; | |
565 paths.shape.apply(&info, &appendPathSegment); | |
566 shapeObject->setArray("shape", shapePath.release()); | |
567 if (paths.marginShape.length()) { | |
568 shapePath = JSONArray::create(); | |
569 info.array = shapePath.get(); | |
570 paths.marginShape.apply(&info, &appendPathSegment); | |
571 shapeObject->setArray("marginShape", shapePath.release()); | |
572 } | |
573 } | |
574 return shapeObject.release(); | |
575 } | |
576 return nullptr; | |
577 } | |
578 | |
579 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec t>& shapeObject, Node* node) | |
487 { | 580 { |
488 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 581 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
489 Element* element = toElement(node); | 582 Element* element = toElement(node); |
490 Element* realElement = element; | 583 Element* realElement = element; |
491 PseudoElement* pseudoElement = 0; | 584 PseudoElement* pseudoElement = 0; |
492 if (element->isPseudoElement()) { | 585 if (element->isPseudoElement()) { |
493 pseudoElement = toPseudoElement(element); | 586 pseudoElement = toPseudoElement(element); |
494 realElement = element->parentOrShadowHostElement(); | 587 realElement = element->parentOrShadowHostElement(); |
495 } | 588 } |
496 bool isXHTML = realElement->document().isXHTMLDocument(); | 589 bool isXHTML = realElement->document().isXHTMLDocument(); |
(...skipping 21 matching lines...) Expand all Loading... | |
518 if (!classNames.isEmpty()) | 611 if (!classNames.isEmpty()) |
519 elementInfo->setString("className", classNames.toString()); | 612 elementInfo->setString("className", classNames.toString()); |
520 | 613 |
521 RenderObject* renderer = node->renderer(); | 614 RenderObject* renderer = node->renderer(); |
522 LocalFrame* containingFrame = node->document().frame(); | 615 LocalFrame* containingFrame = node->document().frame(); |
523 FrameView* containingView = containingFrame->view(); | 616 FrameView* containingView = containingFrame->view(); |
524 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); | 617 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); |
525 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; | 618 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; |
526 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); | 619 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())); | 620 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); |
621 if (renderer->isBox() && shapeObject) | |
622 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); | |
528 highlightObject->setObject("elementInfo", elementInfo.release()); | 623 highlightObject->setObject("elementInfo", elementInfo.release()); |
529 } | 624 } |
530 | 625 |
531 void InspectorOverlay::drawNodeHighlight() | 626 void InspectorOverlay::drawNodeHighlight() |
532 { | 627 { |
533 if (!m_highlightNode) | 628 if (!m_highlightNode) |
534 return; | 629 return; |
535 | 630 |
536 Highlight highlight; | 631 Highlight highlight; |
537 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; | 632 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; |
538 if (m_eventTargetNode) { | 633 if (m_eventTargetNode) { |
539 Highlight eventTargetHighlight; | 634 Highlight eventTargetHighlight; |
540 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); | 635 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); |
541 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. | 636 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. |
542 } | 637 } |
543 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 638 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
544 | 639 |
545 Node* node = m_highlightNode.get(); | 640 Node* node = m_highlightNode.get(); |
641 RefPtr<JSONObject> shapeObject = buildObjectForShapeOutside(node); | |
546 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) | 642 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) |
547 setElementInfo(highlightObject, node); | 643 setElementInfo(highlightObject, shapeObject, node); |
548 evaluateInOverlay("drawNodeHighlight", highlightObject); | 644 evaluateInOverlay("drawNodeHighlight", highlightObject); |
549 } | 645 } |
550 | 646 |
551 void InspectorOverlay::drawQuadHighlight() | 647 void InspectorOverlay::drawQuadHighlight() |
552 { | 648 { |
553 if (!m_highlightQuad) | 649 if (!m_highlightQuad) |
554 return; | 650 return; |
555 | 651 |
556 Highlight highlight; | 652 Highlight highlight; |
557 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); | 653 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 command->pushValue(argument); | 751 command->pushValue(argument); |
656 overlayPage()->mainFrame()->script().executeScriptInMainWorld("dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhenScriptsDisable d); | 752 overlayPage()->mainFrame()->script().executeScriptInMainWorld("dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhenScriptsDisable d); |
657 } | 753 } |
658 | 754 |
659 void InspectorOverlay::onTimer(Timer<InspectorOverlay>*) | 755 void InspectorOverlay::onTimer(Timer<InspectorOverlay>*) |
660 { | 756 { |
661 m_drawViewSize = false; | 757 m_drawViewSize = false; |
662 update(); | 758 update(); |
663 } | 759 } |
664 | 760 |
665 bool InspectorOverlay::getBoxModel(Node* node, Vector<FloatQuad>* quads) | 761 bool InspectorOverlay::getBoxModel(Node* node, Vector<FloatQuad>* quads, String& shapeOutsideStr) |
666 { | 762 { |
763 RefPtr<JSONObject> shapeOutsideInfo = buildObjectForShapeOutside(node); | |
764 shapeOutsideStr = shapeOutsideInfo ? shapeOutsideInfo->toJSONString() : Stri ng(); | |
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.
| |
667 return buildNodeQuads(node, *quads); | 765 return buildNodeQuads(node, *quads); |
668 } | 766 } |
669 | 767 |
670 void InspectorOverlay::freePage() | 768 void InspectorOverlay::freePage() |
671 { | 769 { |
672 if (m_overlayPage) { | 770 if (m_overlayPage) { |
673 // FIXME: This logic is duplicated in SVGImage and WebViewImpl. Perhaps it can be combined | 771 // FIXME: This logic is duplicated in SVGImage and WebViewImpl. Perhaps it can be combined |
674 // into Page's destructor. | 772 // into Page's destructor. |
675 m_overlayPage->mainFrame()->loader().frameDetached(); | 773 m_overlayPage->mainFrame()->loader().frameDetached(); |
676 m_overlayPage->willBeDestroyed(); | 774 m_overlayPage->willBeDestroyed(); |
677 m_overlayPage.clear(); | 775 m_overlayPage.clear(); |
678 } | 776 } |
679 m_overlayChromeClient.clear(); | 777 m_overlayChromeClient.clear(); |
680 m_timer.stop(); | 778 m_timer.stop(); |
681 | 779 |
682 // This will clear internal structures and issue update to the client. Safe to call last. | 780 // This will clear internal structures and issue update to the client. Safe to call last. |
683 hideHighlight(); | 781 hideHighlight(); |
684 } | 782 } |
685 | 783 |
686 void InspectorOverlay::startedRecordingProfile() | 784 void InspectorOverlay::startedRecordingProfile() |
687 { | 785 { |
688 if (!m_activeProfilerCount++) | 786 if (!m_activeProfilerCount++) |
689 freePage(); | 787 freePage(); |
690 } | 788 } |
691 | 789 |
692 } // namespace WebCore | 790 } // namespace WebCore |
OLD | NEW |