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 PassRefPtr<JSONObject> InspectorOverlay::buildObjectForShapeOutside(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 void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec
t>& shapeObject, Node* node) |
487 { | 581 { |
488 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 582 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
489 Element* element = toElement(node); | 583 Element* element = toElement(node); |
490 Element* realElement = element; | 584 Element* realElement = element; |
491 PseudoElement* pseudoElement = 0; | 585 PseudoElement* pseudoElement = 0; |
492 if (element->isPseudoElement()) { | 586 if (element->isPseudoElement()) { |
493 pseudoElement = toPseudoElement(element); | 587 pseudoElement = toPseudoElement(element); |
494 realElement = element->parentOrShadowHostElement(); | 588 realElement = element->parentOrShadowHostElement(); |
495 } | 589 } |
496 bool isXHTML = realElement->document().isXHTMLDocument(); | 590 bool isXHTML = realElement->document().isXHTMLDocument(); |
(...skipping 21 matching lines...) Expand all Loading... |
518 if (!classNames.isEmpty()) | 612 if (!classNames.isEmpty()) |
519 elementInfo->setString("className", classNames.toString()); | 613 elementInfo->setString("className", classNames.toString()); |
520 | 614 |
521 RenderObject* renderer = node->renderer(); | 615 RenderObject* renderer = node->renderer(); |
522 LocalFrame* containingFrame = node->document().frame(); | 616 LocalFrame* containingFrame = node->document().frame(); |
523 FrameView* containingView = containingFrame->view(); | 617 FrameView* containingView = containingFrame->view(); |
524 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView
(renderer->absoluteBoundingBoxRect())); | 618 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView
(renderer->absoluteBoundingBoxRect())); |
525 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB
oxModelObject(renderer) : 0; | 619 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB
oxModelObject(renderer) : 0; |
526 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb
soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi
dth())); | 620 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())); | 621 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA
bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox.
height())); |
| 622 if (renderer->isBox() && shapeObject) |
| 623 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); |
528 highlightObject->setObject("elementInfo", elementInfo.release()); | 624 highlightObject->setObject("elementInfo", elementInfo.release()); |
529 } | 625 } |
530 | 626 |
531 void InspectorOverlay::drawNodeHighlight() | 627 void InspectorOverlay::drawNodeHighlight() |
532 { | 628 { |
533 if (!m_highlightNode) | 629 if (!m_highlightNode) |
534 return; | 630 return; |
535 | 631 |
536 Highlight highlight; | 632 Highlight highlight; |
537 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight)
; | 633 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight)
; |
538 if (m_eventTargetNode) { | 634 if (m_eventTargetNode) { |
539 Highlight eventTargetHighlight; | 635 Highlight eventTargetHighlight; |
540 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even
tTargetHighlight); | 636 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even
tTargetHighlight); |
541 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro
m eventTargetNode to highlight. | 637 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro
m eventTargetNode to highlight. |
542 } | 638 } |
543 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 639 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
544 | 640 |
545 Node* node = m_highlightNode.get(); | 641 Node* node = m_highlightNode.get(); |
| 642 RefPtr<JSONObject> shapeObject = buildObjectForShapeOutside(node); |
546 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf
o && node->renderer() && node->document().frame()) | 643 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf
o && node->renderer() && node->document().frame()) |
547 setElementInfo(highlightObject, node); | 644 setElementInfo(highlightObject, shapeObject, node); |
548 evaluateInOverlay("drawNodeHighlight", highlightObject); | 645 evaluateInOverlay("drawNodeHighlight", highlightObject); |
549 } | 646 } |
550 | 647 |
551 void InspectorOverlay::drawQuadHighlight() | 648 void InspectorOverlay::drawQuadHighlight() |
552 { | 649 { |
553 if (!m_highlightQuad) | 650 if (!m_highlightQuad) |
554 return; | 651 return; |
555 | 652 |
556 Highlight highlight; | 653 Highlight highlight; |
557 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig
ht); | 654 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig
ht); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 hideHighlight(); | 780 hideHighlight(); |
684 } | 781 } |
685 | 782 |
686 void InspectorOverlay::startedRecordingProfile() | 783 void InspectorOverlay::startedRecordingProfile() |
687 { | 784 { |
688 if (!m_activeProfilerCount++) | 785 if (!m_activeProfilerCount++) |
689 freePage(); | 786 freePage(); |
690 } | 787 } |
691 | 788 |
692 } // namespace WebCore | 789 } // namespace WebCore |
OLD | NEW |