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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #include "core/rendering/style/RenderStyleConstants.h" | 52 #include "core/rendering/style/RenderStyleConstants.h" |
53 #include "platform/JSONValues.h" | 53 #include "platform/JSONValues.h" |
54 #include "platform/PlatformMouseEvent.h" | 54 #include "platform/PlatformMouseEvent.h" |
55 #include "platform/graphics/GraphicsContextStateSaver.h" | 55 #include "platform/graphics/GraphicsContextStateSaver.h" |
56 #include "wtf/text/StringBuilder.h" | 56 #include "wtf/text/StringBuilder.h" |
57 | 57 |
58 namespace WebCore { | 58 namespace WebCore { |
59 | 59 |
60 namespace { | 60 namespace { |
61 | 61 |
62 struct PathApplyInfo { | |
63 FrameView* rootView; | |
64 FrameView* view; | |
65 JSONArray* array; | |
pfeldman
2014/05/02 11:45:07
TypeBuilder::Array<JSONValue>* array;
Habib Virji
2014/05/02 12:39:32
Done.
| |
66 RenderObject* renderer; | |
67 const ShapeOutsideInfo* shapeOutsideInfo; | |
68 }; | |
69 | |
62 class InspectorOverlayChromeClient FINAL: public EmptyChromeClient { | 70 class InspectorOverlayChromeClient FINAL: public EmptyChromeClient { |
63 public: | 71 public: |
64 InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlay* overlay ) | 72 InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlay* overlay ) |
65 : m_client(client) | 73 : m_client(client) |
66 , m_overlay(overlay) | 74 , m_overlay(overlay) |
67 { } | 75 { } |
68 | 76 |
69 virtual void setCursor(const Cursor& cursor) OVERRIDE | 77 virtual void setCursor(const Cursor& cursor) OVERRIDE |
70 { | 78 { |
71 m_client.setCursor(cursor); | 79 m_client.setCursor(cursor); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 } | 484 } |
477 | 485 |
478 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) | 486 static PassRefPtr<JSONObject> buildObjectForSize(const IntSize& size) |
479 { | 487 { |
480 RefPtr<JSONObject> result = JSONObject::create(); | 488 RefPtr<JSONObject> result = JSONObject::create(); |
481 result->setNumber("width", size.width()); | 489 result->setNumber("width", size.width()); |
482 result->setNumber("height", size.height()); | 490 result->setNumber("height", size.height()); |
483 return result.release(); | 491 return result.release(); |
484 } | 492 } |
485 | 493 |
486 static void setElementInfo(RefPtr<JSONObject>& highlightObject, Node* node) | 494 // CSS shapes |
495 static void appendPathCommandAndPoints(PathApplyInfo* info, const String& comman d, const FloatPoint points[], unsigned length) | |
496 { | |
497 FloatPoint point; | |
498 info->array->pushString(command); | |
pfeldman
2014/05/02 11:45:07
info->array->addItem(JSONString::create(command));
Habib Virji
2014/05/02 12:39:32
Done.
| |
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()); | |
pfeldman
2014/05/02 11:45:07
info->array->addItem(JSONBasicValue::create(point.
Habib Virji
2014/05/02 12:39:32
Done.
| |
503 info->array->pushNumber(point.y()); | |
pfeldman
2014/05/02 11:45:07
info->array->addItem(JSONBasicValue::create(point.
Habib Virji
2014/05/02 12:39:32
Done.
| |
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<double> > buildArrayForQuadTypeBuilder(const Fl oatQuad& quad) | |
536 { | |
537 RefPtr<TypeBuilder::Array<double> > array = TypeBuilder::Array<double>::crea te(); | |
538 array->addItem(quad.p1().x()); | |
539 array->addItem(quad.p1().y()); | |
540 array->addItem(quad.p2().x()); | |
541 array->addItem(quad.p2().y()); | |
542 array->addItem(quad.p3().x()); | |
543 array->addItem(quad.p3().y()); | |
544 array->addItem(quad.p4().x()); | |
545 array->addItem(quad.p4().y()); | |
546 return array.release(); | |
547 } | |
548 | |
549 PassRefPtr<TypeBuilder::DOM::ShapeOutsideInfo> InspectorOverlay::buildObjectForS hapeOutside(Node* node) | |
550 { | |
551 RenderObject* renderer = node->renderer(); | |
552 if (!renderer || !renderer->isBox() || !toRenderBox(renderer)->shapeOutsideI nfo()) | |
553 return nullptr; | |
554 | |
555 LocalFrame* containingFrame = node->document().frame(); | |
556 RenderBox* renderBox = toRenderBox(renderer); | |
557 const ShapeOutsideInfo* shapeOutsideInfo = renderBox->shapeOutsideInfo(); | |
558 | |
559 LayoutRect shapeBounds = shapeOutsideInfo->computedShapePhysicalBoundingBox( ); | |
560 FloatQuad shapeQuad = renderBox->localToAbsoluteQuad(FloatRect(shapeBounds)) ; | |
561 FrameView* mainView = containingFrame->page()->mainFrame()->view(); | |
562 FrameView* containingView = containingFrame->view(); | |
563 contentsQuadToPage(mainView, containingView, shapeQuad); | |
564 | |
565 Shape::DisplayPaths paths; | |
566 shapeOutsideInfo->computedShape().buildDisplayPaths(paths); | |
567 RefPtr<JSONArray> shapePath = JSONArray::create(); | |
pfeldman
2014/05/02 11:45:07
RefPtr<TypeBuilder::Array<JSONValue> > shapePath =
| |
568 RefPtr<JSONArray> marginShapePath = JSONArray::create(); | |
pfeldman
2014/05/02 11:45:07
RefPtr<TypeBuilder::Array<JSONValue> > marginShape
| |
569 | |
570 if (paths.shape.length()) { | |
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 | |
579 if (paths.marginShape.length()) { | |
580 info.array = marginShapePath.get(); | |
581 paths.marginShape.apply(&info, &appendPathSegment); | |
582 } | |
583 } | |
584 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeTypeBuilder = TypeBuilder::D OM::ShapeOutsideInfo::create() | |
585 .setBounds(buildArrayForQuadTypeBuilder(shapeQuad)) | |
586 .setShape(TypeBuilder::Array<JSONValue>::runtimeCast(shapePath)) | |
587 .setMarginShape(TypeBuilder::Array<JSONValue>::runtimeCast(marginShapePa th)); | |
588 | |
589 return shapeTypeBuilder.release(); | |
590 } | |
591 | |
592 static void setElementInfo(RefPtr<JSONObject>& highlightObject, RefPtr<JSONObjec t>& shapeObject, Node* node) | |
487 { | 593 { |
488 RefPtr<JSONObject> elementInfo = JSONObject::create(); | 594 RefPtr<JSONObject> elementInfo = JSONObject::create(); |
489 Element* element = toElement(node); | 595 Element* element = toElement(node); |
490 Element* realElement = element; | 596 Element* realElement = element; |
491 PseudoElement* pseudoElement = 0; | 597 PseudoElement* pseudoElement = 0; |
492 if (element->isPseudoElement()) { | 598 if (element->isPseudoElement()) { |
493 pseudoElement = toPseudoElement(element); | 599 pseudoElement = toPseudoElement(element); |
494 realElement = element->parentOrShadowHostElement(); | 600 realElement = element->parentOrShadowHostElement(); |
495 } | 601 } |
496 bool isXHTML = realElement->document().isXHTMLDocument(); | 602 bool isXHTML = realElement->document().isXHTMLDocument(); |
(...skipping 21 matching lines...) Expand all Loading... | |
518 if (!classNames.isEmpty()) | 624 if (!classNames.isEmpty()) |
519 elementInfo->setString("className", classNames.toString()); | 625 elementInfo->setString("className", classNames.toString()); |
520 | 626 |
521 RenderObject* renderer = node->renderer(); | 627 RenderObject* renderer = node->renderer(); |
522 LocalFrame* containingFrame = node->document().frame(); | 628 LocalFrame* containingFrame = node->document().frame(); |
523 FrameView* containingView = containingFrame->view(); | 629 FrameView* containingView = containingFrame->view(); |
524 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); | 630 IntRect boundingBox = pixelSnappedIntRect(containingView->contentsToRootView (renderer->absoluteBoundingBoxRect())); |
525 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; | 631 RenderBoxModelObject* modelObject = renderer->isBoxModelObject() ? toRenderB oxModelObject(renderer) : 0; |
526 elementInfo->setString("nodeWidth", String::number(modelObject ? adjustForAb soluteZoom(modelObject->pixelSnappedOffsetWidth(), modelObject) : boundingBox.wi dth())); | 632 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())); | 633 elementInfo->setString("nodeHeight", String::number(modelObject ? adjustForA bsoluteZoom(modelObject->pixelSnappedOffsetHeight(), modelObject) : boundingBox. height())); |
634 if (renderer->isBox() && shapeObject) | |
635 elementInfo->setObject("shapeOutsideInfo", shapeObject.release()); | |
528 highlightObject->setObject("elementInfo", elementInfo.release()); | 636 highlightObject->setObject("elementInfo", elementInfo.release()); |
529 } | 637 } |
530 | 638 |
531 void InspectorOverlay::drawNodeHighlight() | 639 void InspectorOverlay::drawNodeHighlight() |
532 { | 640 { |
533 if (!m_highlightNode) | 641 if (!m_highlightNode) |
534 return; | 642 return; |
535 | 643 |
536 Highlight highlight; | 644 Highlight highlight; |
537 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; | 645 buildNodeHighlight(m_highlightNode.get(), m_nodeHighlightConfig, &highlight) ; |
538 if (m_eventTargetNode) { | 646 if (m_eventTargetNode) { |
539 Highlight eventTargetHighlight; | 647 Highlight eventTargetHighlight; |
540 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); | 648 buildNodeHighlight(m_eventTargetNode.get(), m_nodeHighlightConfig, &even tTargetHighlight); |
541 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. | 649 highlight.quads.append(eventTargetHighlight.quads[1]); // Add border fro m eventTargetNode to highlight. |
542 } | 650 } |
543 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); | 651 RefPtr<JSONObject> highlightObject = buildObjectForHighlight(highlight); |
544 | 652 |
545 Node* node = m_highlightNode.get(); | 653 Node* node = m_highlightNode.get(); |
654 RefPtr<TypeBuilder::DOM::ShapeOutsideInfo> shapeObject = buildObjectForShape Outside(node); | |
655 RefPtr<JSONObject> shapeObjectJSON = shapeObject ? shapeObject->asObject() : nullptr; | |
546 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) | 656 if (node->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInf o && node->renderer() && node->document().frame()) |
547 setElementInfo(highlightObject, node); | 657 setElementInfo(highlightObject, shapeObjectJSON, node); |
548 evaluateInOverlay("drawNodeHighlight", highlightObject); | 658 evaluateInOverlay("drawNodeHighlight", highlightObject); |
549 } | 659 } |
550 | 660 |
551 void InspectorOverlay::drawQuadHighlight() | 661 void InspectorOverlay::drawQuadHighlight() |
552 { | 662 { |
553 if (!m_highlightQuad) | 663 if (!m_highlightQuad) |
554 return; | 664 return; |
555 | 665 |
556 Highlight highlight; | 666 Highlight highlight; |
557 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); | 667 buildQuadHighlight(m_page, *m_highlightQuad, m_quadHighlightConfig, &highlig ht); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 hideHighlight(); | 793 hideHighlight(); |
684 } | 794 } |
685 | 795 |
686 void InspectorOverlay::startedRecordingProfile() | 796 void InspectorOverlay::startedRecordingProfile() |
687 { | 797 { |
688 if (!m_activeProfilerCount++) | 798 if (!m_activeProfilerCount++) |
689 freePage(); | 799 freePage(); |
690 } | 800 } |
691 | 801 |
692 } // namespace WebCore | 802 } // namespace WebCore |
OLD | NEW |