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 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#include <wtf/RefPtr.h> 36#include <wtf/Vector.h> 37#include <wtf/text/WTFString.h> 38 39namespace Inspector { 40class InspectorObject; 41class InspectorValue; 42} 43 44namespace WebCore { 45 46class Color; 47class GraphicsContext; 48class InspectorClient; 49class IntRect; 50class Node; 51class Page; 52 53struct HighlightConfig { 54 WTF_MAKE_FAST_ALLOCATED; 55public: 56 Color content; 57 Color contentOutline; 58 Color padding; 59 Color border; 60 Color margin; 61 bool showInfo; 62 bool usePageCoordinates; 63}; 64 65enum HighlightType { 66 HighlightTypeNode, 67 HighlightTypeRects, 68}; 69 70struct Highlight { 71 Highlight() 72 : type(HighlightTypeNode) 73 , usePageCoordinates(true) 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 usePageCoordinates = highlightConfig.usePageCoordinates; 85 } 86 87 Color contentColor; 88 Color contentOutlineColor; 89 Color paddingColor; 90 Color borderColor; 91 Color marginColor; 92 93 // When the type is Node, there are 4 quads (margin, border, padding, content). 94 // When the type is Rects, this is just a list of quads. 95 HighlightType type; 96 Vector<FloatQuad> quads; 97 bool usePageCoordinates; 98}; 99 100class InspectorOverlay { 101 WTF_MAKE_FAST_ALLOCATED; 102public: 103 InspectorOverlay(Page&, InspectorClient*); 104 ~InspectorOverlay(); 105 106 enum class CoordinateSystem { 107 View, // Adjusts for the main frame's scroll offset. 108 Document, // Does not adjust for the main frame's scroll offset. 109 }; 110 111 void update(); 112 void paint(GraphicsContext&); 113 void drawOutline(GraphicsContext*, const LayoutRect&, const Color&); 114 void getHighlight(Highlight*, CoordinateSystem) const; 115 116 void setPausedInDebuggerMessage(const String*); 117 118 void hideHighlight(); 119 void highlightNode(Node*, const HighlightConfig&); 120 void highlightQuad(std::unique_ptr<FloatQuad>, const HighlightConfig&); 121 122 Node* highlightedNode() const; 123 124 void didSetSearchingForNode(bool enabled); 125 126 void setIndicating(bool indicating); 127 128 PassRefPtr<Inspector::InspectorObject> buildObjectForHighlightedNode() const; 129 130 void freePage(); 131private: 132 bool shouldShowOverlay() const; 133 void drawGutter(); 134 void drawNodeHighlight(); 135 void drawQuadHighlight(); 136 void drawPausedInDebuggerMessage(); 137 Page* overlayPage(); 138 void reset(const IntSize& viewportSize, const IntSize& frameViewFullSize); 139 void evaluateInOverlay(const String& method); 140 void evaluateInOverlay(const String& method, const String& argument); 141 void evaluateInOverlay(const String& method, PassRefPtr<Inspector::InspectorValue> argument); 142 143 Page& m_page; 144 InspectorClient* m_client; 145 String m_pausedInDebuggerMessage; 146 RefPtr<Node> m_highlightNode; 147 HighlightConfig m_nodeHighlightConfig; 148 std::unique_ptr<FloatQuad> m_highlightQuad; 149 std::unique_ptr<Page> m_overlayPage; 150 HighlightConfig m_quadHighlightConfig; 151 bool m_indicating; 152}; 153 154} // namespace WebCore 155 156 157#endif // InspectorOverlay_h 158