2 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "ChromeClientQt.h"
32 #include "FrameLoadRequest.h"
33 #include "FrameLoader.h"
34 #include "FrameLoaderClientQt.h"
35 #include "FrameView.h"
36 #include "NotImplemented.h"
37 #include "WindowFeatures.h"
40 #include "qwebpage_p.h"
41 #include "qwebframe_p.h"
47 ChromeClientQt::ChromeClientQt(QWebPage* webPage)
54 ChromeClientQt::~ChromeClientQt()
59 void ChromeClientQt::setWindowRect(const FloatRect& rect)
63 emit m_webPage->geometryChangeRequest(QRect(qRound(rect.x()), qRound(rect.y()),
64 qRound(rect.width()), qRound(rect.height())));
68 FloatRect ChromeClientQt::windowRect()
73 QWidget* view = m_webPage->view();
76 return IntRect(view->topLevelWidget()->geometry());
80 FloatRect ChromeClientQt::pageRect()
84 return FloatRect(QRectF(QPointF(0,0), m_webPage->viewportSize()));
88 float ChromeClientQt::scaleFactor()
95 void ChromeClientQt::focus()
99 QWidget* view = m_webPage->view();
107 void ChromeClientQt::unfocus()
111 QWidget* view = m_webPage->view();
117 bool ChromeClientQt::canTakeFocus(FocusDirection)
119 // This is called when cycling through links/focusable objects and we
120 // reach the last focusable object. Then we want to claim that we can
121 // take the focus to avoid wrapping.
125 void ChromeClientQt::takeFocus(FocusDirection)
127 // don't do anything. This is only called when cycling to links/focusable objects,
128 // which in turn is called from focusNextPrevChild. We let focusNextPrevChild
129 // call QWidget::focusNextPrevChild accordingly, so there is no need to do anything
134 Page* ChromeClientQt::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features)
136 QWebPage *newPage = features.dialog ? m_webPage->createModalDialog() : m_webPage->createWindow();
139 newPage->mainFrame()->load(request.resourceRequest().url());
140 return newPage->d->page;
143 void ChromeClientQt::show()
147 QWidget* view = m_webPage->view();
150 view->topLevelWidget()->show();
154 bool ChromeClientQt::canRunModal()
161 void ChromeClientQt::runModal()
167 void ChromeClientQt::setToolbarsVisible(bool)
173 bool ChromeClientQt::toolbarsVisible()
180 void ChromeClientQt::setStatusbarVisible(bool)
186 bool ChromeClientQt::statusbarVisible()
193 void ChromeClientQt::setScrollbarsVisible(bool)
199 bool ChromeClientQt::scrollbarsVisible()
206 void ChromeClientQt::setMenubarVisible(bool)
211 bool ChromeClientQt::menubarVisible()
217 void ChromeClientQt::setResizable(bool)
222 void ChromeClientQt::addMessageToConsole(const String& message, unsigned int lineNumber,
223 const String& sourceID)
226 QString y = sourceID;
227 m_webPage->javaScriptConsoleMessage(x, lineNumber, y);
230 void ChromeClientQt::chromeDestroyed()
235 bool ChromeClientQt::canRunBeforeUnloadConfirmPanel()
240 bool ChromeClientQt::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
242 return runJavaScriptConfirm(frame, message);
245 void ChromeClientQt::closeWindowSoon()
247 m_webPage->mainFrame()->d->frame->loader()->stopAllLoaders();
248 m_webPage->deleteLater();
251 void ChromeClientQt::runJavaScriptAlert(Frame* f, const String& msg)
254 FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(f->loader()->client());
255 m_webPage->javaScriptAlert(fl->webFrame(), x);
258 bool ChromeClientQt::runJavaScriptConfirm(Frame* f, const String& msg)
261 FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(f->loader()->client());
262 return m_webPage->javaScriptConfirm(fl->webFrame(), x);
265 bool ChromeClientQt::runJavaScriptPrompt(Frame* f, const String& message, const String& defaultValue, String& result)
268 FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(f->loader()->client());
269 bool rc = m_webPage->javaScriptPrompt(fl->webFrame(), (QString)message, (QString)defaultValue, &x);
274 void ChromeClientQt::setStatusbarText(const String& msg)
277 emit m_webPage->statusBarTextChanged(x);
280 bool ChromeClientQt::shouldInterruptJavaScript()
286 bool ChromeClientQt::tabsToLinks() const
288 return m_webPage->settings()->testAttribute(QWebSettings::LinksIncludedInFocusChain);
291 IntRect ChromeClientQt::windowResizerRect() const
296 void ChromeClientQt::addToDirtyRegion(const IntRect& r)
298 QWidget* view = m_webPage->view();
301 rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize()));
307 void ChromeClientQt::scrollBackingStore(int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect)
309 QWidget* view = m_webPage->view();
311 view->scroll(dx, dy, scrollViewRect);
314 void ChromeClientQt::updateBackingStore()
318 void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult&, unsigned /*modifierFlags*/)
323 void ChromeClientQt::setToolTip(const String&)
328 void ChromeClientQt::print(Frame*)
333 unsigned long long ChromeClientQt::requestQuotaIncreaseForNewDatabase(Frame*, SecurityOrigin*, const String&, unsigned long long)
339 unsigned long long ChromeClientQt::requestQuotaIncreaseForDatabaseOperation(Frame*, SecurityOrigin*, const String&, unsigned long long)