Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / inspector / InspectorOverlay.h
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 "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     void resize(const IntSize&);
125     bool handleGestureEvent(const PlatformGestureEvent&);
126     bool handleMouseEvent(const PlatformMouseEvent&);
127     bool handleTouchEvent(const PlatformTouchEvent&);
128     bool handleKeyboardEvent(const PlatformKeyboardEvent&);
129
130     void setPausedInDebuggerMessage(const String*);
131     void setInspectModeEnabled(bool);
132
133     void hideHighlight();
134     void highlightNode(Node*, Node* eventTarget, const HighlightConfig&, bool omitTooltip);
135     void highlightQuad(PassOwnPtr<FloatQuad>, const HighlightConfig&);
136     void showAndHideViewSize(bool showGrid);
137
138     Node* highlightedNode() const;
139     bool getBoxModel(Node*, Vector<FloatQuad>*);
140     PassRefPtr<TypeBuilder::DOM::ShapeOutsideInfo> buildObjectForShapeOutside(Node*);
141
142     void freePage();
143
144     InspectorOverlayHost* overlayHost() const { return m_overlayHost.get(); }
145
146     void startedRecordingProfile();
147     void finishedRecordingProfile() { m_activeProfilerCount--; }
148
149     // Methods supporting underlying overlay page.
150     void invalidate();
151 private:
152     InspectorOverlay(Page*, InspectorClient*);
153
154     bool isEmpty();
155
156     void drawNodeHighlight();
157     void drawQuadHighlight();
158     void drawPausedInDebuggerMessage();
159     void drawViewSize();
160
161     Page* overlayPage();
162     void reset(const IntSize& viewportSize, const IntSize& frameViewFullSize, int scrollX, int scrollY);
163     void evaluateInOverlay(const String& method, const String& argument);
164     void evaluateInOverlay(const String& method, PassRefPtr<JSONValue> argument);
165     void onTimer(Timer<InspectorOverlay>*);
166
167     Page* m_page;
168     InspectorClient* m_client;
169     String m_pausedInDebuggerMessage;
170     bool m_inspectModeEnabled;
171     RefPtr<Node> m_highlightNode;
172     RefPtr<Node> m_eventTargetNode;
173     HighlightConfig m_nodeHighlightConfig;
174     OwnPtr<FloatQuad> m_highlightQuad;
175     OwnPtrWillBePersistent<Page> m_overlayPage;
176     OwnPtr<EmptyChromeClient> m_overlayChromeClient;
177     RefPtr<InspectorOverlayHost> m_overlayHost;
178     HighlightConfig m_quadHighlightConfig;
179     IntSize m_size;
180     bool m_drawViewSize;
181     bool m_drawViewSizeWithGrid;
182     bool m_omitTooltip;
183     Timer<InspectorOverlay> m_timer;
184     int m_activeProfilerCount;
185 };
186
187 } // namespace WebCore
188
189
190 #endif // InspectorOverlay_h