2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Trolltech ASA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "InspectorClientQt.h"
34 #include "qwebpage_p.h"
35 #include <QtCore/QCoreApplication>
37 #include "InspectorController.h"
38 #include "NotImplemented.h"
40 #include "PlatformString.h"
44 class InspectorClientWebPage : public QWebPage
47 QWebPage* createWindow()
49 QWidget *w = new QWidget(0);
50 QWebPage *page = new QWebPage(w);
52 connect(page, SIGNAL(destroyed()), w, SLOT(deleteLater()));
58 class InspectorClientView : public QWidget {
60 InspectorClientView(InspectorController* controller)
62 , m_controller(controller)
63 , m_page(new InspectorClientWebPage)
65 m_page->setView(this);
66 connect(m_page, SIGNAL(destroyed()), SLOT(deleteLater()));
69 QWebPage* page() const { return m_page; }
71 void hideEvent(QHideEvent* ev)
73 QWidget::hideEvent(ev);
74 m_controller->setWindowVisible(false);
77 void closeEvent(QCloseEvent* ev)
79 QWidget::closeEvent(ev);
80 m_controller->setWindowVisible(false);
84 InspectorController* m_controller;
89 InspectorClientQt::InspectorClientQt(QWebPage* page)
90 : m_inspectedWebPage(page)
94 void InspectorClientQt::inspectorDestroyed()
99 Page* InspectorClientQt::createPage()
102 return m_webPage->d->page;
104 InspectorClientView* view = new InspectorClientView(m_inspectedWebPage->d->page->inspectorController());
105 m_webPage.set(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;
111 String InspectorClientQt::localizedStringsURL()
117 void InspectorClientQt::showWindow()
123 m_webPage->view()->show();
124 m_inspectedWebPage->d->page->inspectorController()->setWindowVisible(true);
127 void InspectorClientQt::closeWindow()
132 m_webPage->view()->hide();
133 m_inspectedWebPage->d->page->inspectorController()->setWindowVisible(false);
136 bool InspectorClientQt::windowVisible()
140 return m_webPage->view()->isVisible();
143 void InspectorClientQt::attachWindow()
145 ASSERT(m_inspectedWebPage);
153 void InspectorClientQt::detachWindow()
155 ASSERT(m_inspectedWebPage);
163 void InspectorClientQt::highlight(Node* node)
168 void InspectorClientQt::hideHighlight()
173 void InspectorClientQt::inspectedURLChanged(const String& newURL)
175 m_inspectedURL = newURL;
179 void InspectorClientQt::updateWindowTitle()
184 QString caption = QCoreApplication::translate("QWebPage", "Web Inspector - %2");
185 m_webPage->view()->setWindowTitle(caption.arg(m_inspectedURL));