1/* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef InspectorOverlay_h 30#define InspectorOverlay_h 31 32#include "Color.h" 33#include "FloatQuad.h" 34#include "LayoutRect.h" 35 36#include <wtf/OwnPtr.h> 37#include <wtf/PassOwnPtr.h> 38#include <wtf/RefPtr.h> 39#include <wtf/Vector.h> 40#include <wtf/text/WTFString.h> 41 42namespace WebCore { 43 44class Color; 45class GraphicsContext; 46class InspectorClient; 47class InspectorValue; 48class IntRect; 49class Node; 50class Page; 51 52struct HighlightConfig { 53 WTF_MAKE_FAST_ALLOCATED; 54public: 55 Color content; 56 Color contentOutline; 57 Color padding; 58 Color border; 59 Color margin; 60 bool showInfo; 61 bool showRulers; 62 bool usePageCoordinates; 63}; 64 65enum HighlightType { 66 HighlightTypeNode, 67 HighlightTypeRects, 68}; 69 70struct Highlight { 71 Highlight() 72 : type(HighlightTypeNode) 73 , showRulers(false) 74 { 75 } 76 77 void setDataFromConfig(const HighlightConfig& highlightConfig) 78 { 79 contentColor = highlightConfig.content; 80 contentOutlineColor = highlightConfig.contentOutline; 81 paddingColor = highlightConfig.padding; 82 borderColor = highlightConfig.border; 83 marginColor = highlightConfig.margin; 84 showRulers = highlightConfig.showRulers; 85 usePageCoordinates = highlightConfig.usePageCoordinates; 86 } 87 88 Color contentColor; 89 Color contentOutlineColor; 90 Color paddingColor; 91 Color borderColor; 92 Color marginColor; 93 94 // When the type is Node, there are 4 quads (margin, border, padding, content). 95 // When the type is Rects, this is just a list of quads. 96 HighlightType type; 97 Vector<FloatQuad> quads; 98 bool showRulers; 99 bool usePageCoordinates; 100}; 101 102class InspectorOverlay { 103 WTF_MAKE_FAST_ALLOCATED; 104public: 105 static PassOwnPtr<InspectorOverlay> create(Page* page, InspectorClient* client) 106 { 107 return adoptPtr(new InspectorOverlay(page, client)); 108 } 109 ~InspectorOverlay(); 110 111 void update(); 112 void paint(GraphicsContext&); 113 void drawOutline(GraphicsContext*, const LayoutRect&, const Color&); 114 void getHighlight(Highlight*) const; 115 void resize(const IntSize&); 116 117 void setPausedInDebuggerMessage(const String*); 118 119 void hideHighlight(); 120 void highlightNode(Node*, const HighlightConfig&); 121 void highlightQuad(PassOwnPtr<FloatQuad>, const HighlightConfig&); 122 123 Node* highlightedNode() const; 124 125 void freePage(); 126private: 127 InspectorOverlay(Page*, InspectorClient*); 128 129 void drawGutter(); 130 void drawNodeHighlight(); 131 void drawQuadHighlight(); 132 void drawPausedInDebuggerMessage(); 133 Page* overlayPage(); 134 void reset(const IntSize& viewportSize, const IntSize& frameViewFullSize); 135 void evaluateInOverlay(const String& method, const String& argument); 136 void evaluateInOverlay(const String& method, PassRefPtr<InspectorValue> argument); 137 138 Page* m_page; 139 InspectorClient* m_client; 140 String m_pausedInDebuggerMessage; 141 RefPtr<Node> m_highlightNode; 142 HighlightConfig m_nodeHighlightConfig; 143 OwnPtr<FloatQuad> m_highlightQuad; 144 OwnPtr<Page> m_overlayPage; 145 HighlightConfig m_quadHighlightConfig; 146 IntSize m_size; 147}; 148 149} // namespace WebCore 150 151 152#endif // InspectorOverlay_h 153