OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 2627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2638 { | 2638 { |
2639 JavaScriptDebugServer::shared().addBreakpoint(sourceID, lineNumber); | 2639 JavaScriptDebugServer::shared().addBreakpoint(sourceID, lineNumber); |
2640 } | 2640 } |
2641 | 2641 |
2642 void InspectorController::removeBreakpoint(intptr_t sourceID, unsigned lineNumbe
r) | 2642 void InspectorController::removeBreakpoint(intptr_t sourceID, unsigned lineNumbe
r) |
2643 { | 2643 { |
2644 JavaScriptDebugServer::shared().removeBreakpoint(sourceID, lineNumber); | 2644 JavaScriptDebugServer::shared().removeBreakpoint(sourceID, lineNumber); |
2645 } | 2645 } |
2646 #endif | 2646 #endif |
2647 | 2647 |
2648 static void drawOutlinedRect(GraphicsContext& context, const IntRect& rect, cons
t Color& fillColor) | 2648 static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, co
nst Color& fillColor) |
2649 { | 2649 { |
2650 static const int outlineThickness = 1; | 2650 static const int outlineThickness = 2; |
2651 static const Color outlineColor(62, 86, 180, 228); | 2651 static const Color outlineColor(62, 86, 180, 228); |
2652 | 2652 |
2653 IntRect outline = rect; | 2653 Path quadPath; |
2654 outline.inflate(outlineThickness); | 2654 quadPath.moveTo(quad.p1()); |
| 2655 quadPath.addLineTo(quad.p2()); |
| 2656 quadPath.addLineTo(quad.p3()); |
| 2657 quadPath.addLineTo(quad.p4()); |
| 2658 quadPath.closeSubpath(); |
| 2659 |
| 2660 // Clear the quad |
| 2661 { |
| 2662 context.save(); |
| 2663 context.setCompositeOperation(CompositeClear); |
| 2664 context.addPath(quadPath); |
| 2665 context.fillPath(); |
| 2666 context.restore(); |
| 2667 } |
2655 | 2668 |
2656 context.clearRect(outline); | 2669 // Clip out the quad, then draw with a 2px stroke to get a pixel |
| 2670 // of outline (because inflating a quad is hard) |
| 2671 { |
| 2672 context.save(); |
| 2673 context.addPath(quadPath); |
| 2674 context.clipOut(quadPath); |
2657 | 2675 |
2658 context.save(); | 2676 context.addPath(quadPath); |
2659 context.clipOut(rect); | 2677 context.setStrokeThickness(outlineThickness); |
2660 context.fillRect(outline, outlineColor); | 2678 context.setStrokeColor(outlineColor); |
2661 context.restore(); | 2679 context.strokePath(); |
2662 | 2680 |
2663 context.fillRect(rect, fillColor); | 2681 context.restore(); |
| 2682 } |
| 2683 |
| 2684 // Now do the fill |
| 2685 context.addPath(quadPath); |
| 2686 context.setFillColor(fillColor); |
| 2687 context.fillPath(); |
2664 } | 2688 } |
2665 | 2689 |
2666 static void drawHighlightForBoxes(GraphicsContext& context, const Vector<IntRect
>& lineBoxRects, const IntRect& contentBox, const IntRect& paddingBox, const Int
Rect& borderBox, const IntRect& marginBox) | 2690 static void drawHighlightForBoxes(GraphicsContext& context, const Vector<FloatQu
ad>& lineBoxQuads, const FloatQuad& contentQuad, const FloatQuad& paddingQuad, c
onst FloatQuad& borderQuad, const FloatQuad& marginQuad) |
2667 { | 2691 { |
2668 static const Color contentBoxColor(125, 173, 217, 128); | 2692 static const Color contentBoxColor(125, 173, 217, 128); |
2669 static const Color paddingBoxColor(125, 173, 217, 160); | 2693 static const Color paddingBoxColor(125, 173, 217, 160); |
2670 static const Color borderBoxColor(125, 173, 217, 192); | 2694 static const Color borderBoxColor(125, 173, 217, 192); |
2671 static const Color marginBoxColor(125, 173, 217, 228); | 2695 static const Color marginBoxColor(125, 173, 217, 228); |
2672 | 2696 |
2673 if (!lineBoxRects.isEmpty()) { | 2697 if (!lineBoxQuads.isEmpty()) { |
2674 for (size_t i = 0; i < lineBoxRects.size(); ++i) | 2698 for (size_t i = 0; i < lineBoxQuads.size(); ++i) |
2675 drawOutlinedRect(context, lineBoxRects[i], contentBoxColor); | 2699 drawOutlinedQuad(context, lineBoxQuads[i], contentBoxColor); |
2676 return; | 2700 return; |
2677 } | 2701 } |
2678 | 2702 |
2679 if (marginBox != borderBox) | 2703 if (marginQuad != borderQuad) |
2680 drawOutlinedRect(context, marginBox, marginBoxColor); | 2704 drawOutlinedQuad(context, marginQuad, marginBoxColor); |
2681 if (borderBox != paddingBox) | 2705 if (borderQuad != paddingQuad) |
2682 drawOutlinedRect(context, borderBox, borderBoxColor); | 2706 drawOutlinedQuad(context, borderQuad, borderBoxColor); |
2683 if (paddingBox != contentBox) | 2707 if (paddingQuad != contentQuad) |
2684 drawOutlinedRect(context, paddingBox, paddingBoxColor); | 2708 drawOutlinedQuad(context, paddingQuad, paddingBoxColor); |
2685 drawOutlinedRect(context, contentBox, contentBoxColor); | 2709 |
| 2710 drawOutlinedQuad(context, contentQuad, contentBoxColor); |
2686 } | 2711 } |
2687 | 2712 |
2688 static inline void convertFromFrameToMainFrame(Frame* frame, IntRect& rect) | 2713 static inline void convertFromFrameToMainFrame(Frame* frame, IntRect& rect) |
2689 { | 2714 { |
2690 rect = frame->page()->mainFrame()->view()->windowToContents(frame->view()->c
ontentsToWindow(rect)); | 2715 rect = frame->page()->mainFrame()->view()->windowToContents(frame->view()->c
ontentsToWindow(rect)); |
2691 } | 2716 } |
2692 | 2717 |
| 2718 static inline IntSize frameToMainFrameOffset(Frame* frame) |
| 2719 { |
| 2720 IntPoint mainFramePoint = frame->page()->mainFrame()->view()->windowToConten
ts(frame->view()->contentsToWindow(IntPoint())); |
| 2721 return mainFramePoint - IntPoint(); |
| 2722 } |
| 2723 |
2693 void InspectorController::drawNodeHighlight(GraphicsContext& context) const | 2724 void InspectorController::drawNodeHighlight(GraphicsContext& context) const |
2694 { | 2725 { |
2695 if (!m_highlightedNode) | 2726 if (!m_highlightedNode) |
2696 return; | 2727 return; |
2697 | 2728 |
2698 RenderObject* renderer = m_highlightedNode->renderer(); | 2729 RenderObject* renderer = m_highlightedNode->renderer(); |
2699 Frame* containingFrame = m_highlightedNode->document()->frame(); | 2730 Frame* containingFrame = m_highlightedNode->document()->frame(); |
2700 if (!renderer || !containingFrame) | 2731 if (!renderer || !containingFrame) |
2701 return; | 2732 return; |
2702 | 2733 |
2703 IntRect contentBox = renderer->absoluteContentBox(); | 2734 IntRect contentBox = renderer->contentBox(); |
2704 IntRect boundingBox = renderer->absoluteBoundingBoxRect(); | |
2705 | 2735 |
2706 // FIXME: Should we add methods to RenderObject to obtain these rects? | 2736 // FIXME: Should we add methods to RenderObject to obtain these rects? |
2707 IntRect paddingBox(contentBox.x() - renderer->paddingLeft(), contentBox.y()
- renderer->paddingTop(), contentBox.width() + renderer->paddingLeft() + rendere
r->paddingRight(), contentBox.height() + renderer->paddingTop() + renderer->padd
ingBottom()); | 2737 IntRect paddingBox(contentBox.x() - renderer->paddingLeft(), contentBox.y()
- renderer->paddingTop(), |
2708 IntRect borderBox(paddingBox.x() - renderer->borderLeft(), paddingBox.y() -
renderer->borderTop(), paddingBox.width() + renderer->borderLeft() + renderer->b
orderRight(), paddingBox.height() + renderer->borderTop() + renderer->borderBott
om()); | 2738 contentBox.width() + renderer->paddingLeft() + renderer->
paddingRight(), contentBox.height() + renderer->paddingTop() + renderer->padding
Bottom()); |
2709 IntRect marginBox(borderBox.x() - renderer->marginLeft(), borderBox.y() - re
nderer->marginTop(), borderBox.width() + renderer->marginLeft() + renderer->marg
inRight(), borderBox.height() + renderer->marginTop() + renderer->marginBottom()
); | 2739 IntRect borderBox(paddingBox.x() - renderer->borderLeft(), paddingBox.y() -
renderer->borderTop(), |
| 2740 paddingBox.width() + renderer->borderLeft() + renderer->bo
rderRight(), paddingBox.height() + renderer->borderTop() + renderer->borderBotto
m()); |
| 2741 IntRect marginBox(borderBox.x() - renderer->marginLeft(), borderBox.y() - re
nderer->marginTop(), |
| 2742 borderBox.width() + renderer->marginLeft() + renderer->mar
ginRight(), borderBox.height() + renderer->marginTop() + renderer->marginBottom(
)); |
2710 | 2743 |
2711 convertFromFrameToMainFrame(containingFrame, contentBox); | |
2712 convertFromFrameToMainFrame(containingFrame, paddingBox); | |
2713 convertFromFrameToMainFrame(containingFrame, borderBox); | |
2714 convertFromFrameToMainFrame(containingFrame, marginBox); | |
2715 convertFromFrameToMainFrame(containingFrame, boundingBox); | |
2716 | 2744 |
2717 Vector<IntRect> lineBoxRects; | 2745 IntSize mainFrameOffset = frameToMainFrameOffset(containingFrame); |
| 2746 |
| 2747 FloatQuad absContentQuad = renderer->localToAbsoluteQuad(FloatRect(contentBo
x)); |
| 2748 FloatQuad absPaddingQuad = renderer->localToAbsoluteQuad(FloatRect(paddingBo
x)); |
| 2749 FloatQuad absBorderQuad = renderer->localToAbsoluteQuad(FloatRect(borderBox)
); |
| 2750 FloatQuad absMarginQuad = renderer->localToAbsoluteQuad(FloatRect(marginBox)
); |
| 2751 |
| 2752 absContentQuad.move(mainFrameOffset); |
| 2753 absPaddingQuad.move(mainFrameOffset); |
| 2754 absBorderQuad.move(mainFrameOffset); |
| 2755 absMarginQuad.move(mainFrameOffset); |
| 2756 |
| 2757 IntRect boundingBox = renderer->absoluteBoundingBoxRect(true); |
| 2758 boundingBox.move(mainFrameOffset); |
| 2759 |
| 2760 Vector<FloatQuad> lineBoxQuads; |
2718 if (renderer->isInline() || (renderer->isText() && !m_highlightedNode->isSVG
Element())) { | 2761 if (renderer->isInline() || (renderer->isText() && !m_highlightedNode->isSVG
Element())) { |
2719 // FIXME: We should show margins/padding/border for inlines. | 2762 // FIXME: We should show margins/padding/border for inlines. |
2720 renderer->addLineBoxRects(lineBoxRects); | 2763 renderer->collectAbsoluteLineBoxQuads(lineBoxQuads); |
2721 } | 2764 } |
2722 | 2765 |
2723 for (unsigned i = 0; i < lineBoxRects.size(); ++i) | 2766 for (unsigned i = 0; i < lineBoxQuads.size(); ++i) |
2724 convertFromFrameToMainFrame(containingFrame, lineBoxRects[i]); | 2767 lineBoxQuads[i] += mainFrameOffset; |
2725 | 2768 |
2726 if (lineBoxRects.isEmpty() && contentBox.isEmpty()) { | 2769 if (lineBoxQuads.isEmpty() && contentBox.isEmpty()) { |
2727 // If we have no line boxes and our content box is empty, we'll just dra
w our bounding box. | 2770 // If we have no line boxes and our content box is empty, we'll just dra
w our bounding box. |
2728 // This can happen, e.g., with an <a> enclosing an <img style="float:rig
ht">. | 2771 // This can happen, e.g., with an <a> enclosing an <img style="float:rig
ht">. |
2729 // FIXME: Can we make this better/more accurate? The <a> in the above ca
se has no | 2772 // FIXME: Can we make this better/more accurate? The <a> in the above ca
se has no |
2730 // width/height but the highlight makes it appear to be the size of the
<img>. | 2773 // width/height but the highlight makes it appear to be the size of the
<img>. |
2731 lineBoxRects.append(boundingBox); | 2774 lineBoxQuads.append(FloatRect(boundingBox)); |
2732 } | 2775 } |
2733 | 2776 |
2734 ASSERT(m_inspectedPage); | 2777 ASSERT(m_inspectedPage); |
2735 | 2778 |
2736 FrameView* view = m_inspectedPage->mainFrame()->view(); | 2779 FrameView* view = m_inspectedPage->mainFrame()->view(); |
2737 FloatRect overlayRect = view->visibleContentRect(); | 2780 FloatRect overlayRect = view->visibleContentRect(); |
2738 | 2781 |
2739 if (!overlayRect.contains(boundingBox) && !boundingBox.contains(enclosingInt
Rect(overlayRect))) { | 2782 if (!overlayRect.contains(boundingBox) && !boundingBox.contains(enclosingInt
Rect(overlayRect))) { |
2740 Element* element; | 2783 Element* element; |
2741 if (m_highlightedNode->isElementNode()) | 2784 if (m_highlightedNode->isElementNode()) |
2742 element = static_cast<Element*>(m_highlightedNode.get()); | 2785 element = static_cast<Element*>(m_highlightedNode.get()); |
2743 else | 2786 else |
2744 element = static_cast<Element*>(m_highlightedNode->parent()); | 2787 element = static_cast<Element*>(m_highlightedNode->parent()); |
2745 overlayRect = view->visibleContentRect(); | 2788 overlayRect = view->visibleContentRect(); |
2746 } | 2789 } |
2747 | 2790 |
2748 context.translate(-overlayRect.x(), -overlayRect.y()); | 2791 context.translate(-overlayRect.x(), -overlayRect.y()); |
2749 | 2792 |
2750 drawHighlightForBoxes(context, lineBoxRects, contentBox, paddingBox, borderB
ox, marginBox); | 2793 drawHighlightForBoxes(context, lineBoxQuads, absContentQuad, absPaddingQuad,
absBorderQuad, absMarginQuad); |
2751 } | 2794 } |
2752 | 2795 |
2753 void InspectorController::count(const UString& title, unsigned lineNumber, const
String& sourceID) | 2796 void InspectorController::count(const UString& title, unsigned lineNumber, const
String& sourceID) |
2754 { | 2797 { |
2755 String identifier = String(title) + String::format("@%s:%d", sourceID.utf8()
.data(), lineNumber); | 2798 String identifier = String(title) + String::format("@%s:%d", sourceID.utf8()
.data(), lineNumber); |
2756 HashMap<String, unsigned>::iterator it = m_counts.find(identifier); | 2799 HashMap<String, unsigned>::iterator it = m_counts.find(identifier); |
2757 int count; | 2800 int count; |
2758 if (it == m_counts.end()) | 2801 if (it == m_counts.end()) |
2759 count = 1; | 2802 count = 1; |
2760 else { | 2803 else { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2840 } | 2883 } |
2841 | 2884 |
2842 void InspectorController::didPause() | 2885 void InspectorController::didPause() |
2843 { | 2886 { |
2844 JSValueRef exception = 0; | 2887 JSValueRef exception = 0; |
2845 callFunction(m_scriptContext, m_scriptObject, "pausedScript", 0, 0, exceptio
n); | 2888 callFunction(m_scriptContext, m_scriptObject, "pausedScript", 0, 0, exceptio
n); |
2846 } | 2889 } |
2847 #endif | 2890 #endif |
2848 | 2891 |
2849 } // namespace WebCore | 2892 } // namespace WebCore |
OLD | NEW |