Add a mechanism to store and retrieve preferences for the Web Inspector.
[WebKit-https.git] / WebKit / qt / WebCoreSupport / InspectorClientQt.cpp
1 /*
2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
3  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4  * Copyright (C) 2008 Holger Hans Peter Freyther
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1.  Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer. 
12  * 2.  Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution. 
15  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16  *     its contributors may be used to endorse or promote products derived
17  *     from this software without specific prior written permission. 
18  *
19  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "InspectorClientQt.h"
33
34 #include "qwebpage.h"
35 #include "qwebpage_p.h"
36 #include "qwebview.h"
37
38 #include <QtCore/QCoreApplication>
39
40 #include "InspectorController.h"
41 #include "NotImplemented.h"
42 #include "Page.h"
43 #include "PlatformString.h"
44
45 namespace WebCore {
46
47 class InspectorClientWebPage : public QWebPage
48 {
49     Q_OBJECT
50     friend class InspectorClientQt;
51 public:
52     QWebPage* createWindow(QWebPage::WebWindowType)
53     {
54         QWidget *w = new QWebView(0);
55         QWebPage *page = new QWebPage(w);
56         page->setView(w);
57         connect(page, SIGNAL(destroyed()), w, SLOT(deleteLater()));
58         return page;
59     }
60
61 Q_SIGNALS:
62     void attachRequested();
63     void detachRequested();
64 };
65
66
67 class InspectorClientView : public QWebView {
68 public:
69     InspectorClientView(InspectorController* controller)
70         : QWebView(0)
71         , m_controller(controller)
72     {
73         setPage(new InspectorClientWebPage);
74         connect(page(), SIGNAL(destroyed()), SLOT(deleteLater()));
75     }
76
77 protected:
78
79     void closeEvent(QCloseEvent* ev)
80     {
81         QWidget::closeEvent(ev);
82         m_controller->setWindowVisible(false);
83     }
84
85 private:
86     InspectorController* m_controller;
87 };
88
89
90 InspectorClientQt::InspectorClientQt(QWebPage* page)
91     : m_inspectedWebPage(page)
92 {}
93
94 void InspectorClientQt::inspectorDestroyed()
95 {
96     delete this;
97 }
98
99 Page* InspectorClientQt::createPage()
100 {
101     if (m_webPage)
102         return m_webPage->d->page;
103
104     InspectorClientView* view = new InspectorClientView(m_inspectedWebPage->d->page->inspectorController());
105     m_webPage.set(qobject_cast<InspectorClientWebPage*>(view->page()));
106     m_webPage->mainFrame()->load(QString::fromLatin1("qrc:/webkit/inspector/inspector.html"));
107     m_webPage->view()->setMinimumSize(400,300);
108     return m_webPage->d->page;
109 }
110
111 String InspectorClientQt::localizedStringsURL()
112 {
113     notImplemented();
114     return String();
115 }
116
117 void InspectorClientQt::showWindow()
118 {
119     if (!m_webPage)
120         return;
121
122     updateWindowTitle();
123     m_webPage->view()->show();
124     m_inspectedWebPage->d->page->inspectorController()->setWindowVisible(true);
125 }
126
127 void InspectorClientQt::closeWindow()
128 {
129     if (!m_webPage)
130         return;
131
132     m_webPage->view()->hide();
133     m_inspectedWebPage->d->page->inspectorController()->setWindowVisible(false);
134 }
135
136 bool InspectorClientQt::windowVisible()
137 {
138     if (!m_webPage)
139         return false;
140     return m_webPage->view()->isVisible();
141 }
142
143 void InspectorClientQt::attachWindow()
144 {
145     if (!m_webPage)
146         return;
147
148     emit m_webPage->attachRequested();
149 }
150
151 void InspectorClientQt::detachWindow()
152 {
153     if (!m_webPage)
154         return;
155
156     emit m_webPage->detachRequested();
157 }
158
159 void InspectorClientQt::setAttachedWindowHeight(unsigned height)
160 {
161     notImplemented();
162 }
163
164 void InspectorClientQt::highlight(Node* node)
165 {
166     notImplemented();
167 }
168
169 void InspectorClientQt::hideHighlight()
170 {
171     notImplemented();
172 }
173
174 void InspectorClientQt::inspectedURLChanged(const String& newURL)
175 {
176     m_inspectedURL = newURL;
177     updateWindowTitle();
178 }
179
180 void InspectorClientQt::updateWindowTitle()
181 {
182     if (!m_webPage)
183         return;
184
185     QString caption = QCoreApplication::translate("QWebPage", "Web Inspector - %2");
186     m_webPage->view()->setWindowTitle(caption.arg(m_inspectedURL));
187 }
188
189 void InspectorClientQt::populateSetting(const String& key, InspectorController::Setting& setting)
190 {
191     notImplemented();
192 }
193
194 void InspectorClientQt::storeSetting(const String& key, const InspectorController::Setting& setting)
195 {
196     notImplemented();
197 }
198
199 void InspectorClientQt::removeSetting(const String& key)
200 {
201     notImplemented();
202 }
203
204 }
205
206 #include "InspectorClientQt.moc"