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 switch (pathElement->type) { |
| 523 // The points member will contain 1 value. |
| 524 case PathElementMoveToPoint: |
| 525 appendPathCommandAndPoints(pathApplyInfo, "M", pathElement->points, 1); |
| 526 break; |
| 527 // The points member will contain 1 value. |
| 528 case PathElementAddLineToPoint: |
| 529 appendPathCommandAndPoints(pathApplyInfo, "L", pathElement->points, 1); |
| 530 break; |
| 531 // The points member will contain 3 values. |
| 532 case PathElementAddCurveToPoint: |
| 533 appendPathCommandAndPoints(pathApplyInfo, "C", pathElement->points, 3); |
| 534 break; |
| 535 // The points member will contain 2 values. |
| 536 case PathElementAddQuadCurveToPoint: |
| 537 appendPathCommandAndPoints(pathApplyInfo, "Q", pathElement->points, 2); |
| 538 break; |
| 539 // The points member will contain no values. |
| 540 case PathElementCloseSubpath: |
| 541 appendPathCommandAndPoints(pathApplyInfo, "Z", 0, 0); |
| 542 break; |
| 543 } |
| 544 } |
| 545 |
| 546 PassRefPtr<JSONObject> InspectorOverlay::buildObjectForShapeOutside() |
| 547 { |
| 548 Node* node = m_highlightNode.get(); |
| 549 RenderObject* renderer = node->renderer(); |
| 550 if (renderer && renderer->isBox()) { |
| 551 LocalFrame* containingFrame = node->document().frame(); |
| 552 RenderBox* renderBox = toRenderBox(renderer); |
| 553 |
| 554 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo()
; |
| 555 if (!shapeOutsideInfo) |
| 556 return nullptr; |
| 557 |
| 558 RefPtr<JSONObject> shapeObject = JSONObject::create(); |
| 559 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBounding
Box(); |
| 560 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBoun
ds)); |
| 561 FrameView* mainView = containingFrame->page()->mainFrame()->view(); |
| 562 FrameView* containingView = containingFrame->view(); |
| 563 contentsQuadToPage(mainView, containingView, shapeQuad); |
| 564 shapeObject->setArray("bounds", buildArrayForQuad(shapeQuad)); |
| 565 |
| 566 Shape::DisplayPaths paths; |
| 567 shapeOutsideInfo->computedShape().buildDisplayPaths(paths); |
| 568 |
| 569 if (paths.shape.length()) { |
| 570 RefPtr<JSONArray> shapePath = JSONArray::create(); |
| 571 PathApplyInfo info; |
| 572 info.rootView = mainView; |
| 573 info.view = containingView; |
| 574 info.array = shapePath.get(); |
| 575 info.renderer = renderBox; |
| 576 info.shapeOutsideInfo = shapeOutsideInfo; |
| 577 paths.shape.apply(&info, &appendPathSegment); |
| 578 shapeObject->setArray("shape", shapePath.release()); |
| 579 if (paths.marginShape.length()) { |
| 580 shapePath = JSONArray::create(); |
| 581 info.array = shapePath.get(); |
| 582 paths.marginShape.apply(&info, &appendPathSegment); |
| 583 shapeObject->setArray("marginShape", shapePath.release()); |
| 584 } |
| 585 } |
| 586 return shapeObject.release(); |
| 587 } |
| 588 return nullptr; |
| 589 } |
| 590 |
| 591 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec
t>& shapeObject, Node* node) |
499 { | 592 { |
500 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 593 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
501 Element* element = toElement(node); | 594 Element* element = toElement(node); |
502 Element* realElement = element; | 595 Element* realElement = element; |
503 PseudoElement* pseudoElement = 0; | 596 PseudoElement* pseudoElement = 0; |
504 if (element->isPseudoElement()) { | 597 if (element->isPseudoElement()) { |
505 pseudoElement = toPseudoElement(element); | 598 pseudoElement = toPseudoElement(element); |
506 realElement = element->parentOrShadowHostElement(); | 599 realElement = element->parentOrShadowHostElement(); |
507 } | 600 } |
508 bool isXHTML = realElement->document().isXHTMLDocument(); | 601 bool isXHTML = realElement->document().isXHTMLDocument(); |
(...skipping 21 matching lines...) Expand all Loading... |
530 if (!classNames.isEmpty()) | 623 if (!classNames.isEmpty()) |
531 elementInfo->setString("className", classNames.toString()); | 624 elementInfo->setString("className", classNames.toString()); |
532 | 625 |
533 RenderObject* renderer = node->renderer(); | 626 RenderObject* renderer = node->renderer(); |
534 LocalFrame* containingFrame = node->document().frame(); | 627 LocalFrame* containingFrame = node->document().frame(); |
535 FrameView* containingView = containingFrame->view(); | 628 FrameView* containingView = containingFrame->view(); |
536 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView
(renderer->absoluteBoundingBoxRect())); | 629 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView
(renderer->absoluteBoundingBoxRect())); |
537 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB
oxModelObject(renderer) : 0; | 630 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB
oxModelObject(renderer) : 0; |
538 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb
soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi
dth())); | 631 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())); | 632 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA
bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox.
height())); |
| 633 if (renderer->isBox() && shapeObject) |
| 634 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); |
540 highlightObject->setObject("elementInfo", elementInfo.release()); | 635 highlightObject->setObject("elementInfo", elementInfo.release()); |
541 } | 636 } |
542 | 637 |
543 void InspectorOverlay::drawNodeHighlight() | 638 void InspectorOverlay::drawNodeHighlight() |
544 { | 639 { |
545 if (!m_highlightNode) | 640 if (!m_highlightNode) |
546 return; | 641 return; |
547 | 642 |
548 Highlight highlight; | 643 Highlight highlight; |
549 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight)
; | 644 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight)
; |
550 if (m_eventTargetNode) { | 645 if (m_eventTargetNode) { |
551 Highlight eventTargetHighlight; | 646 Highlight eventTargetHighlight; |
552 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even
tTargetHighlight); | 647 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even
tTargetHighlight); |
553 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro
m eventTargetNode to highlight. | 648 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro
m eventTargetNode to highlight. |
554 } | 649 } |
555 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 650 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
| 651 RefPtr<JSONObject> shapeObject = buildObjectForShapeOutside(); |
556 | 652 |
557 Node* node = m_highlightNode.get(); | 653 Node* node = m_highlightNode.get(); |
558 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf
o && node->renderer() && node->document().frame()) | 654 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf
o && node->renderer() && node->document().frame()) |
559 setElementInfo(highlightObject, node); | 655 setElementInfo(highlightObject, shapeObject, node); |
560 evaluateInOverlay("drawNodeHighlight", highlightObject); | 656 evaluateInOverlay("drawNodeHighlight", highlightObject); |
561 } | 657 } |
562 | 658 |
563 void InspectorOverlay::drawQuadHighlight() | 659 void InspectorOverlay::drawQuadHighlight() |
564 { | 660 { |
565 if (!m_highlightQuad) | 661 if (!m_highlightQuad) |
566 return; | 662 return; |
567 | 663 |
568 Highlight highlight; | 664 Highlight highlight; |
569 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig
ht); | 665 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(); | 788 m_timer.stop(); |
693 } | 789 } |
694 | 790 |
695 void InspectorOverlay::startedRecordingProfile() | 791 void InspectorOverlay::startedRecordingProfile() |
696 { | 792 { |
697 if (!m_activeProfilerCount++) | 793 if (!m_activeProfilerCount++) |
698 freePage(); | 794 freePage(); |
699 } | 795 } |
700 | 796 |
701 } // namespace WebCore | 797 } // namespace WebCore |
OLD | NEW |