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/text/WTFString.h"
42
43namespace blink {
44
45class Color;
46class EmptyChromeClient;
47class GraphicsContext;
48class InspectorClient;
49class InspectorOverlayHost;
50class JSONValue;
51class Node;
52class Page;
53class PlatformGestureEvent;
54class PlatformKeyboardEvent;
55class PlatformMouseEvent;
56class PlatformTouchEvent;
57
58struct HighlightConfig {
59    WTF_MAKE_FAST_ALLOCATED;
60public:
61    Color content;
62    Color contentOutline;
63    Color padding;
64    Color border;
65    Color margin;
66    Color eventTarget;
67    Color shape;
68    Color shapeMargin;
69
70    bool showInfo;
71    bool showRulers;
72    bool showExtensionLines;
73};
74
75class InspectorOverlay {
76    WTF_MAKE_FAST_ALLOCATED;
77public:
78    static PassOwnPtr<InspectorOverlay> create(Page* page, InspectorClient* client)
79    {
80        return adoptPtr(new InspectorOverlay(page, client));
81    }
82
83    ~InspectorOverlay();
84
85    void update();
86    void hide();
87    void paint(GraphicsContext&);
88    void drawOutline(GraphicsContext*, const LayoutRect&, const Color&);
89    bool handleGestureEvent(const PlatformGestureEvent&);
90    bool handleMouseEvent(const PlatformMouseEvent&);
91    bool handleTouchEvent(const PlatformTouchEvent&);
92    bool handleKeyboardEvent(const PlatformKeyboardEvent&);
93
94    void setPausedInDebuggerMessage(const String*);
95    void setInspectModeEnabled(bool);
96
97    void hideHighlight();
98    void highlightNode(Node*, Node* eventTarget, const HighlightConfig&, bool omitTooltip);
99    void highlightQuad(PassOwnPtr<FloatQuad>, const HighlightConfig&);
100    void showAndHideViewSize(bool showGrid);
101
102    Node* highlightedNode() const;
103    bool getBoxModel(Node*, RefPtr<TypeBuilder::DOM::BoxModel>&);
104
105    void freePage();
106
107    InspectorOverlayHost* overlayHost() const { return m_overlayHost.get(); }
108
109    void startedRecordingProfile();
110    void finishedRecordingProfile() { m_activeProfilerCount--; }
111
112    // Methods supporting underlying overlay page.
113    void invalidate();
114private:
115    InspectorOverlay(Page*, InspectorClient*);
116
117    bool isEmpty();
118
119    void drawNodeHighlight();
120    void drawQuadHighlight();
121    void drawPausedInDebuggerMessage();
122    void drawViewSize();
123
124    Page* overlayPage();
125    void reset(const IntSize& viewportSize, int scrollX, int scrollY);
126    void evaluateInOverlay(const String& method, const String& argument);
127    void evaluateInOverlay(const String& method, PassRefPtr<JSONValue> argument);
128    void onTimer(Timer<InspectorOverlay>*);
129
130    Page* m_page;
131    InspectorClient* m_client;
132    String m_pausedInDebuggerMessage;
133    bool m_inspectModeEnabled;
134    RefPtrWillBePersistent<Node> m_highlightNode;
135    RefPtrWillBePersistent<Node> m_eventTargetNode;
136    HighlightConfig m_nodeHighlightConfig;
137    OwnPtr<FloatQuad> m_highlightQuad;
138    OwnPtrWillBePersistent<Page> m_overlayPage;
139    OwnPtr<EmptyChromeClient> m_overlayChromeClient;
140    RefPtrWillBePersistent<InspectorOverlayHost> m_overlayHost;
141    HighlightConfig m_quadHighlightConfig;
142    bool m_drawViewSize;
143    bool m_drawViewSizeWithGrid;
144    bool m_omitTooltip;
145    Timer<InspectorOverlay> m_timer;
146    int m_activeProfilerCount;
147};
148
149} // namespace blink
150
151
152#endif // InspectorOverlay_h
153