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 "core/InspectorTypeBuilder.h" 33 #include "platform/Timer.h" 34 #include "platform/geometry/FloatQuad.h" 35 #include "platform/geometry/LayoutRect.h" 36 #include "platform/graphics/Color.h" 37 #include "platform/heap/Handle.h" 38 #include "wtf/OwnPtr.h" 39 #include "wtf/PassOwnPtr.h" 40 #include "wtf/RefPtr.h" 41 #include "wtf/Vector.h" 42 #include "wtf/text/WTFString.h" 43 44 namespace WebCore { 45 46 class Color; 47 class EmptyChromeClient; 48 class GraphicsContext; 49 class InspectorClient; 50 class InspectorOverlayHost; 51 class JSONObject; 52 class JSONValue; 53 class Node; 54 class Page; 55 class PlatformGestureEvent; 56 class PlatformKeyboardEvent; 57 class PlatformMouseEvent; 58 class PlatformTouchEvent; 59 60 struct HighlightConfig { 61 WTF_MAKE_FAST_ALLOCATED; 62 public: 63 Color content; 64 Color contentOutline; 65 Color padding; 66 Color border; 67 Color margin; 68 Color eventTarget; 69 bool showInfo; 70 bool showRulers; 71 }; 72 73 enum HighlightType { 74 HighlightTypeNode, 75 HighlightTypeRects, 76 }; 77 78 struct Highlight { 79 Highlight() 80 : type(HighlightTypeNode) 81 , showRulers(false) 82 { 83 } 84 85 void setDataFromConfig(const HighlightConfig& highlightConfig) 86 { 87 contentColor = highlightConfig.content; 88 contentOutlineColor = highlightConfig.contentOutline; 89 paddingColor = highlightConfig.padding; 90 borderColor = highlightConfig.border; 91 marginColor = highlightConfig.margin; 92 eventTargetColor = highlightConfig.eventTarget; 93 showRulers = highlightConfig.showRulers; 94 } 95 96 Color contentColor; 97 Color contentOutlineColor; 98 Color paddingColor; 99 Color borderColor; 100 Color marginColor; 101 Color eventTargetColor; 102 103 // When the type is Node, there are 4 or 5 quads (margin, border, padding, content, optional eventTarget). 104 // When the type is Rects, this is just a list of quads. 105 HighlightType type; 106 Vector<FloatQuad> quads; 107 bool showRulers; 108 }; 109 110 class InspectorOverlay { 111 WTF_MAKE_FAST_ALLOCATED; 112 public: 113 static PassOwnPtr<InspectorOverlay> create(Page* page, InspectorClient* client) 114 { 115 return adoptPtr(new InspectorOverlay(page, client)); 116 } 117 118 ~InspectorOverlay(); 119 120 void update(); 121 void hide(); 122 void paint(GraphicsContext&); 123 void drawOutline(GraphicsContext*, const LayoutRect&, const Color&); 124 bool handleGestureEvent(const PlatformGestureEvent&); 125 bool handleMouseEvent(const PlatformMouseEvent&); 126 bool handleTouchEvent(const PlatformTouchEvent&); 127 bool handleKeyboardEvent(const PlatformKeyboardEvent&); 128 129 void setPausedInDebuggerMessage(const String*); 130 void setInspectModeEnabled(bool); 131 132 void hideHighlight(); 133 void highlightNode(Node*, Node* eventTarget, const HighlightConfig&, bool omitTooltip); 134 void highlightQuad(PassOwnPtr<FloatQuad>, const HighlightConfig&); 135 void showAndHideViewSize(bool showGrid); 136 137 Node* highlightedNode() const; 138 bool getBoxModel(Node*, Vector<FloatQuad>*); 139 PassRefPtr<TypeBuilder::DOM::ShapeOutsideInfo> buildObjectForShapeOutside(Node*); 140 141 void freePage(); 142 143 InspectorOverlayHost* overlayHost() const { return m_overlayHost.get(); } 144 145 void startedRecordingProfile(); 146 void finishedRecordingProfile() { m_activeProfilerCount--; } 147 148 // Methods supporting underlying overlay page. 149 void invalidate(); 150 private: 151 InspectorOverlay(Page*, InspectorClient*); 152 153 bool isEmpty(); 154 155 void drawNodeHighlight(); 156 void drawQuadHighlight(); 157 void drawPausedInDebuggerMessage(); 158 void drawViewSize(); 159 160 Page* overlayPage(); 161 void reset(const IntSize& viewportSize, int scrollX, int scrollY); 162 void evaluateInOverlay(const String& method, const String& argument); 163 void evaluateInOverlay(const String& method, PassRefPtr<JSONValue> argument); 164 void onTimer(Timer<InspectorOverlay>*); 165 166 Page* m_page; 167 InspectorClient* m_client; 168 String m_pausedInDebuggerMessage; 169 bool m_inspectModeEnabled; 170 RefPtrWillBePersistent<Node> m_highlightNode; 171 RefPtrWillBePersistent<Node> m_eventTargetNode; 172 HighlightConfig m_nodeHighlightConfig; 173 OwnPtr<FloatQuad> m_highlightQuad; 174 OwnPtrWillBePersistent<Page> m_overlayPage; 175 OwnPtr<EmptyChromeClient> m_overlayChromeClient; 176 RefPtr<InspectorOverlayHost> m_overlayHost; 177 HighlightConfig m_quadHighlightConfig; 178 bool m_drawViewSize; 179 bool m_drawViewSizeWithGrid; 180 bool m_omitTooltip; 181 Timer<InspectorOverlay> m_timer; 182 int m_activeProfilerCount; 183 }; 184 185 } // namespace WebCore 186 187 188 #endif // InspectorOverlay_h 189