Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: Source/core/inspector/InspectorOverlay.cpp

Issue 237313003: CSS shapes support in Web Inspector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Combined buildObjectForShapeOutside static and member function, and made setShapeOutside optional Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 RefPtr<TypeBuilder::Array<JSONValue> > buildArrayForShapeOutside(PassRefP tr<JSONValue> value)
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)
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()) // This check is necessary as shapeOutside is not mandatory part of box m odel
pfeldman 2014/05/02 10:12:07 I don't think you need this comment.
Habib Virji 2014/05/02 10:33:08 Done.
560 return nullptr;
561
562 RefPtr<JSONObject> shapeObject = JSONObject::create();
563 LocalFrame* containingFrame = node->document().frame();
564 RenderBox* renderBox = toRenderBox(renderer);
565 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo();
566
567 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox( );
568 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBounds)) ;
569 FrameView* mainView = containingFrame->page()->mainFrame()->view();
570 FrameView* containingView = containingFrame->view();
571 contentsQuadToPage(mainView, containingView, shapeQuad);
572 shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad));
pfeldman 2014/05/02 10:12:07 This is unused.
Habib Virji 2014/05/02 10:33:08 On test, I am not using it but in the inspector si
573
574 Shape::DisplayPaths paths;
575 shapeOutsideInfo->computedShape().buildDisplayPaths(paths);
576
577 if (paths.shape.length()) {
578 RefPtr<JSONArray> shapePath = JSONArray::create();
579 RefPtr<JSONArray> marginShapePath = JSONArray::create();
580
581 PathApplyInfo info;
582 info.rootView = mainView;
583 info.view = containingView;
584 info.array = shapePath.get();
585 info.renderer = renderBox;
586 info.shapeOutsideInfo = shapeOutsideInfo;
587
588 paths.shape.apply(&info, &appendPathSegment);
589 shapeObject->setArray("shape", shapePath.release());
590
591 if (paths.marginShape.length()) {
592 info.array = marginShapePath.get();
593 paths.marginShape.apply(&info, &appendPathSegment);
594 }
595 shapeObject->setArray("marginShape", marginShapePath.release());
596 }
597
598 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeTypeBuilder = TypeBuilder::D OM::ShapeOutsideInfo::create()
599 .setBounds(buildArrayForQuadTypeBuilder(shapeQuad))
600 .setShape(buildArrayForShapeOutside(shapeObject->getArray("shape")))
pfeldman 2014/05/02 10:12:07 Why creating shapeObject first and fetching its pr
Habib Virji 2014/05/02 10:33:08 Yep valid point. corrected.
601 .setMarginShape(buildArrayForShapeOutside(shapeObject->getArray("marginS hape")));
602
603 return shapeTypeBuilder.release();
604 }
605
606 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec t>& shapeObject, Node* node)
487 { 607 {
488 RefPtr<JSONObject> elementInfo = JSONObject::create(); 608 RefPtr<JSONObject> elementInfo = JSONObject::create();
489 Element* element = toElement(node); 609 Element* element = toElement(node);
490 Element* realElement = element; 610 Element* realElement = element;
491 PseudoElement* pseudoElement = 0; 611 PseudoElement* pseudoElement = 0;
492 if (element->isPseudoElement()) { 612 if (element->isPseudoElement()) {
493 pseudoElement = toPseudoElement(element); 613 pseudoElement = toPseudoElement(element);
494 realElement = element->parentOrShadowHostElement(); 614 realElement = element->parentOrShadowHostElement();
495 } 615 }
496 bool isXHTML = realElement->document().isXHTMLDocument(); 616 bool isXHTML = realElement->document().isXHTMLDocument();
(...skipping 21 matching lines...) Expand all
518 if (!classNames.isEmpty()) 638 if (!classNames.isEmpty())
519 elementInfo->setString("className", classNames.toString()); 639 elementInfo->setString("className", classNames.toString());
520 640
521 RenderObject* renderer = node->renderer(); 641 RenderObject* renderer = node->renderer();
522 LocalFrame* containingFrame = node->document().frame(); 642 LocalFrame* containingFrame = node->document().frame();
523 FrameView* containingView = containingFrame->view(); 643 FrameView* containingView = containingFrame->view();
524 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); 644 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect()));
525 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; 645 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0;
526 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); 646 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())); 647 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height()));
648 if (renderer->isBox() && shapeObject)
649 elementInfo->setObject("shapeOutsideInfo", shapeObject.release());
528 highlightObject->setObject("elementInfo", elementInfo.release()); 650 highlightObject->setObject("elementInfo", elementInfo.release());
529 } 651 }
530 652
531 void InspectorOverlay::drawNodeHighlight() 653 void InspectorOverlay::drawNodeHighlight()
532 { 654 {
533 if (!m_highlightNode) 655 if (!m_highlightNode)
534 return; 656 return;
535 657
536 Highlight highlight; 658 Highlight highlight;
537 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; 659 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ;
538 if (m_eventTargetNode) { 660 if (m_eventTargetNode) {
539 Highlight eventTargetHighlight; 661 Highlight eventTargetHighlight;
540 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); 662 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight);
541 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. 663 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight.
542 } 664 }
543 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); 665 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight);
544 666
545 Node* node = m_highlightNode.get(); 667 Node* node = m_highlightNode.get();
668 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeObject = buildObjectForShape Outside(node);
669 RefPtr<JSONObject> shapeObjectJSON = shapeObject ? shapeObject->asObject() : nullptr;
546 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) 670 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame())
547 setElementInfo(highlightObject, node); 671 setElementInfo(highlightObject, shapeObjectJSON, node);
548 evaluateInOverlay("drawNodeHighlight", highlightObject); 672 evaluateInOverlay("drawNodeHighlight", highlightObject);
549 } 673 }
550 674
551 void InspectorOverlay::drawQuadHighlight() 675 void InspectorOverlay::drawQuadHighlight()
552 { 676 {
553 if (!m_highlightQuad) 677 if (!m_highlightQuad)
554 return; 678 return;
555 679
556 Highlight highlight; 680 Highlight highlight;
557 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); 681 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 hideHighlight(); 807 hideHighlight();
684 } 808 }
685 809
686 void InspectorOverlay::startedRecordingProfile() 810 void InspectorOverlay::startedRecordingProfile()
687 { 811 {
688 if (!m_activeProfilerCount++) 812 if (!m_activeProfilerCount++)
689 freePage(); 813 freePage();
690 } 814 }
691 815
692 } // namespace WebCore 816 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorOverlay.h ('k') | Source/core/inspector/InspectorOverlayPage.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698