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 { | |
pfeldman
2014/05/02 10:49:23
Move this to anonymous namespace above.
Habib Virji
2014/05/02 11:11:28
Done.
| |
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 RefPtr<TypeBuilder::Array<JSONValue> > buildArrayForShapeOutside(PassRefP tr<JSONValue> value) | |
pfeldman
2014/05/02 10:49:23
I was mentioning that I am not sure I understand t
Habib Virji
2014/05/02 11:11:28
I get following compilation error, if i pass JSONA
Habib Virji
2014/05/02 11:38:52
Done.
| |
536 { | |
537 RefPtr<TypeBuilder::Array<JSONValue> > array = TypeBuilder::Array<JSONValue> ::create(); | |
538 array->addItem(value); | |
539 return array.release(); | |
540 } | |
541 | |
542 static RefPtr<TypeBuilder::Array<double> > buildArrayForQuadTypeBuilder(const Fl oatQuad& quad) | |
pfeldman
2014/05/02 10:49:23
I would have updated existing buildArrayForQuad wi
Habib Virji
2014/05/02 11:11:28
Ok, let me know will update accordingly.
| |
543 { | |
544 RefPtr<TypeBuilder::Array<double> > array = TypeBuilder::Array<double>::crea te(); | |
545 array->addItem(quad.p1().x()); | |
546 array->addItem(quad.p1().y()); | |
547 array->addItem(quad.p2().x()); | |
548 array->addItem(quad.p2().y()); | |
549 array->addItem(quad.p3().x()); | |
550 array->addItem(quad.p3().y()); | |
551 array->addItem(quad.p4().x()); | |
552 array->addItem(quad.p4().y()); | |
553 return array.release(); | |
554 } | |
555 | |
556 PassRefPtr<TypeBuilder::DOM::ShapeOutsideInfo> InspectorOverlay::buildObjectForS hapeOutside(Node* node) | |
557 { | |
558 RenderObject* renderer = node->renderer(); | |
559 if (!renderer || !renderer->isBox() || !toRenderBox(renderer)->shapeOutsideI nfo()) | |
560 return nullptr; | |
561 | |
562 LocalFrame* containingFrame = node->document().frame(); | |
563 RenderBox* renderBox = toRenderBox(renderer); | |
564 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo(); | |
565 | |
566 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox( ); | |
567 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBounds)) ; | |
568 FrameView* mainView = containingFrame->page()->mainFrame()->view(); | |
569 FrameView* containingView = containingFrame->view(); | |
570 contentsQuadToPage(mainView, containingView, shapeQuad); | |
571 | |
572 Shape::DisplayPaths paths; | |
573 shapeOutsideInfo->computedShape().buildDisplayPaths(paths); | |
574 RefPtr<JSONArray> shapePath = JSONArray::create(); | |
575 RefPtr<JSONArray> marginShapePath = JSONArray::create(); | |
576 | |
577 if (paths.shape.length()) { | |
578 PathApplyInfo info; | |
579 info.rootView = mainView; | |
580 info.view = containingView; | |
581 info.array = shapePath.get(); | |
582 info.renderer = renderBox; | |
583 info.shapeOutsideInfo = shapeOutsideInfo; | |
584 paths.shape.apply(&info, &appendPathSegment); | |
585 | |
586 if (paths.marginShape.length()) { | |
587 info.array = marginShapePath.get(); | |
588 paths.marginShape.apply(&info, &appendPathSegment); | |
589 } | |
590 } | |
591 | |
592 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeTypeBuilder = TypeBuilder::D OM::ShapeOutsideInfo::create() | |
593 .setBounds(buildArrayForQuadTypeBuilder(shapeQuad)) | |
594 .setShape(buildArrayForShapeOutside(shapePath)) | |
pfeldman
2014/05/02 10:49:23
This I don't understand. shapePath is already an a
Habib Virji
2014/05/02 11:11:28
Mentioned above reason for doing this. Idea is to
Habib Virji
2014/05/02 11:38:52
Done.
| |
595 .setMarginShape(buildArrayForShapeOutside(marginShapePath)); | |
pfeldman
2014/05/02 10:49:23
ditto
Habib Virji
2014/05/02 11:38:52
Done.
| |
596 | |
597 return shapeTypeBuilder.release(); | |
598 } | |
599 | |
600 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec t>& shapeObject, Node* node) | |
487 { | 601 { |
488 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 602 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
489 Element* element = toElement(node); | 603 Element* element = toElement(node); |
490 Element* realElement = element; | 604 Element* realElement = element; |
491 PseudoElement* pseudoElement = 0; | 605 PseudoElement* pseudoElement = 0; |
492 if (element->isPseudoElement()) { | 606 if (element->isPseudoElement()) { |
493 pseudoElement = toPseudoElement(element); | 607 pseudoElement = toPseudoElement(element); |
494 realElement = element->parentOrShadowHostElement(); | 608 realElement = element->parentOrShadowHostElement(); |
495 } | 609 } |
496 bool isXHTML = realElement->document().isXHTMLDocument(); | 610 bool isXHTML = realElement->document().isXHTMLDocument(); |
(...skipping 21 matching lines...) Expand all Loading... | |
518 if (!classNames.isEmpty()) | 632 if (!classNames.isEmpty()) |
519 elementInfo->setString("className", classNames.toString()); | 633 elementInfo->setString("className", classNames.toString()); |
520 | 634 |
521 RenderObject* renderer = node->renderer(); | 635 RenderObject* renderer = node->renderer(); |
522 LocalFrame* containingFrame = node->document().frame(); | 636 LocalFrame* containingFrame = node->document().frame(); |
523 FrameView* containingView = containingFrame->view(); | 637 FrameView* containingView = containingFrame->view(); |
524 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); | 638 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); |
525 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; | 639 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; |
526 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); | 640 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())); | 641 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); |
642 if (renderer->isBox() && shapeObject) | |
643 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); | |
528 highlightObject->setObject("elementInfo", elementInfo.release()); | 644 highlightObject->setObject("elementInfo", elementInfo.release()); |
529 } | 645 } |
530 | 646 |
531 void InspectorOverlay::drawNodeHighlight() | 647 void InspectorOverlay::drawNodeHighlight() |
532 { | 648 { |
533 if (!m_highlightNode) | 649 if (!m_highlightNode) |
534 return; | 650 return; |
535 | 651 |
536 Highlight highlight; | 652 Highlight highlight; |
537 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; | 653 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; |
538 if (m_eventTargetNode) { | 654 if (m_eventTargetNode) { |
539 Highlight eventTargetHighlight; | 655 Highlight eventTargetHighlight; |
540 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); | 656 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); |
541 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. | 657 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. |
542 } | 658 } |
543 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 659 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
544 | 660 |
545 Node* node = m_highlightNode.get(); | 661 Node* node = m_highlightNode.get(); |
662 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeObject = buildObjectForShape Outside(node); | |
663 RefPtr<JSONObject> shapeObjectJSON = shapeObject ? shapeObject->asObject() : nullptr; | |
546 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) | 664 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) |
547 setElementInfo(highlightObject, node); | 665 setElementInfo(highlightObject, shapeObjectJSON, node); |
548 evaluateInOverlay("drawNodeHighlight", highlightObject); | 666 evaluateInOverlay("drawNodeHighlight", highlightObject); |
549 } | 667 } |
550 | 668 |
551 void InspectorOverlay::drawQuadHighlight() | 669 void InspectorOverlay::drawQuadHighlight() |
552 { | 670 { |
553 if (!m_highlightQuad) | 671 if (!m_highlightQuad) |
554 return; | 672 return; |
555 | 673 |
556 Highlight highlight; | 674 Highlight highlight; |
557 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); | 675 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 hideHighlight(); | 801 hideHighlight(); |
684 } | 802 } |
685 | 803 |
686 void InspectorOverlay::startedRecordingProfile() | 804 void InspectorOverlay::startedRecordingProfile() |
687 { | 805 { |
688 if (!m_activeProfilerCount++) | 806 if (!m_activeProfilerCount++) |
689 freePage(); | 807 freePage(); |
690 } | 808 } |
691 | 809 |
692 } // namespace WebCore | 810 } // namespace WebCore |
OLD | NEW |