Cancel composition when focused node was changed
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / WebCoreSupport / WebInspectorClient.cpp
1 /*
2  * Copyright (C) 2010 Apple 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  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "WebInspectorClient.h"
28
29 #if ENABLE(INSPECTOR)
30
31 #include "WebInspector.h"
32 #include "WebPage.h"
33 #include <WebCore/InspectorController.h>
34 #include <WebCore/Page.h>
35 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
36 #include <WebCore/Settings.h>
37 #endif
38
39 using namespace WebCore;
40
41 namespace WebKit {
42
43 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
44 void WebInspectorClient::attachRemoteFrontend()
45 {
46     if (!m_page || !m_page->corePage())
47         return;
48
49     Settings* settings = m_page->corePage()->settings();
50     if (settings)
51         settings->setDeveloperExtrasEnabled(true);
52
53     m_remoteFrontend = true;
54     InspectorController *controller = m_page->corePage()->inspectorController();
55     if (controller)
56         controller->connectFrontend(this);
57 }
58
59 void WebInspectorClient::detachRemoteFrontend()
60 {
61     if (!m_page || !m_page->corePage())
62         return;
63
64     Settings* settings = m_page->corePage()->settings();
65     if (settings)
66         settings->setDeveloperExtrasEnabled(false);
67
68     m_remoteFrontend = false;
69     InspectorController *controller = m_page->corePage()->inspectorController();
70     if (controller)
71         controller->disconnectFrontend();
72 }
73 #endif
74
75 void WebInspectorClient::inspectorDestroyed()
76 {
77 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
78     WebInspectorServerTizen::server()->unregisterClient(this);
79 #endif
80     closeInspectorFrontend();
81     delete this;
82 }
83
84 WebCore::InspectorFrontendChannel* WebInspectorClient::openInspectorFrontend(InspectorController*)
85 {
86     WebPage* inspectorPage = m_page->inspector()->createInspectorPage();
87     ASSERT_UNUSED(inspectorPage, inspectorPage);
88     return this;
89 }
90
91 void WebInspectorClient::closeInspectorFrontend()
92 {
93     if (m_page->inspector()) {
94         m_page->inspector()->didClose();
95     }
96 }
97
98 void WebInspectorClient::bringFrontendToFront()
99 {
100     m_page->inspector()->bringToFront();
101 }
102
103 void WebInspectorClient::didResizeMainFrame(Frame*)
104 {
105     if (m_page->inspector())
106         m_page->inspector()->updateDockingAvailability();
107 }
108
109 void WebInspectorClient::highlight()
110 {
111     if (!m_highlightOverlay) {
112         RefPtr<PageOverlay> highlightOverlay = PageOverlay::create(this);
113         m_highlightOverlay = highlightOverlay.get();
114         m_page->installPageOverlay(highlightOverlay.release());
115     } else
116         m_highlightOverlay->setNeedsDisplay();
117 }
118
119 void WebInspectorClient::hideHighlight()
120 {
121     if (m_highlightOverlay)
122         m_page->uninstallPageOverlay(m_highlightOverlay, false);
123 }
124
125 bool WebInspectorClient::sendMessageToFrontend(const String& message)
126 {
127 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
128     if (m_remoteFrontend)
129         return WebInspectorServerTizen::server()->webSocketSend(message);
130 #endif
131     WebInspector* inspector = m_page->inspector();
132     if (!inspector)
133         return false;
134
135 #if ENABLE(INSPECTOR_SERVER)
136     if (inspector->hasRemoteFrontendConnected()) {
137         inspector->sendMessageToRemoteFrontend(message);
138         return true;
139     }
140 #endif
141
142     WebPage* inspectorPage = inspector->inspectorPage();
143     if (inspectorPage)
144         return doDispatchMessageOnFrontendPage(inspectorPage->corePage(), message);
145
146     return false;
147 }
148
149 void WebInspectorClient::pageOverlayDestroyed(PageOverlay*)
150 {
151 }
152
153 void WebInspectorClient::willMoveToWebPage(PageOverlay*, WebPage* webPage)
154 {
155     if (webPage)
156         return;
157
158     // The page overlay is moving away from the web page, reset it.
159     ASSERT(m_highlightOverlay);
160     m_highlightOverlay = 0;
161 }
162
163 void WebInspectorClient::didMoveToWebPage(PageOverlay*, WebPage*)
164 {
165 }
166
167 void WebInspectorClient::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& context, const WebCore::IntRect& dirtyRect)
168 {
169     m_page->corePage()->inspectorController()->drawHighlight(context);
170 }
171
172 bool WebInspectorClient::mouseEvent(PageOverlay*, const WebMouseEvent&)
173 {
174     return false;
175 }
176
177 } // namespace WebKit
178
179 #endif // ENABLE(INSPECTOR)