ChromeClientQt.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*
  2. * Copyright (C) 2006 Zack Rusin <zack@kde.org>
  3. * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
  4. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  25. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "config.h"
  30. #include "ChromeClientQt.h"
  31. #include "ApplicationCacheStorage.h"
  32. #include "ColorChooser.h"
  33. #include "ColorChooserClient.h"
  34. #include "DatabaseManager.h"
  35. #include "Document.h"
  36. #include "FileChooser.h"
  37. #include "FileIconLoader.h"
  38. #include "Frame.h"
  39. #include "FrameLoadRequest.h"
  40. #include "FrameLoader.h"
  41. #include "FrameLoaderClientQt.h"
  42. #include "FrameView.h"
  43. #include "Geolocation.h"
  44. #if USE(ACCELERATED_COMPOSITING)
  45. #include "GraphicsLayer.h"
  46. #endif
  47. #include "HTMLFormElement.h"
  48. #include "HitTestResult.h"
  49. #include "Icon.h"
  50. #include "NavigationAction.h"
  51. #include "NetworkingContext.h"
  52. #include "NotImplemented.h"
  53. #include "Page.h"
  54. #include "PopupMenuQt.h"
  55. #include "QWebFrameAdapter.h"
  56. #include "QWebPageAdapter.h"
  57. #include "QWebPageClient.h"
  58. #include "ScrollbarTheme.h"
  59. #include "SearchPopupMenuQt.h"
  60. #include "SecurityOrigin.h"
  61. #include "TextureMapperLayerClientQt.h"
  62. #include "TiledBackingStore.h"
  63. #include "ViewportArguments.h"
  64. #include "WindowFeatures.h"
  65. #include "qwebkitplatformplugin.h"
  66. #include "qwebsecurityorigin.h"
  67. #include "qwebsecurityorigin_p.h"
  68. #include "qwebsettings.h"
  69. #include <qabstractanimation.h>
  70. #include <qdebug.h>
  71. #include <qeventloop.h>
  72. #include <qwindow.h>
  73. #include <wtf/CurrentTime.h>
  74. #include <wtf/OwnPtr.h>
  75. #if ENABLE(VIDEO) && ((USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)) || USE(QT_MULTIMEDIA))
  76. #include "FullScreenVideoQt.h"
  77. #include "HTMLMediaElement.h"
  78. #include "HTMLNames.h"
  79. #include "HTMLVideoElement.h"
  80. #if USE(QT_MULTIMEDIA)
  81. #include "MediaPlayerPrivateQt.h"
  82. #endif
  83. #endif
  84. namespace WebCore {
  85. #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
  86. class RefreshAnimation : public QAbstractAnimation {
  87. public:
  88. RefreshAnimation(ChromeClientQt* chromeClient)
  89. : QAbstractAnimation()
  90. , m_chromeClient(chromeClient)
  91. , m_animationScheduled(false)
  92. { }
  93. virtual int duration() const { return -1; }
  94. void scheduleAnimation()
  95. {
  96. m_animationScheduled = true;
  97. if (state() != QAbstractAnimation::Running)
  98. QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
  99. }
  100. protected:
  101. virtual void updateCurrentTime(int currentTime)
  102. {
  103. UNUSED_PARAM(currentTime);
  104. if (m_animationScheduled) {
  105. m_animationScheduled = false;
  106. m_chromeClient->serviceScriptedAnimations();
  107. } else
  108. stop();
  109. }
  110. private:
  111. ChromeClientQt* m_chromeClient;
  112. bool m_animationScheduled;
  113. };
  114. #endif
  115. bool ChromeClientQt::dumpVisitedLinksCallbacks = false;
  116. ChromeClientQt::ChromeClientQt(QWebPageAdapter* webPageAdapter)
  117. : m_webPage(webPageAdapter)
  118. , m_eventLoop(0)
  119. #if ENABLE(VIDEO) && ((USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)) || USE(QT_MULTIMEDIA))
  120. , m_fullScreenVideo(0)
  121. #endif
  122. {
  123. toolBarsVisible = statusBarVisible = menuBarVisible = true;
  124. }
  125. ChromeClientQt::~ChromeClientQt()
  126. {
  127. if (m_eventLoop)
  128. m_eventLoop->exit();
  129. #if ENABLE(VIDEO) && ((USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)) || USE(QT_MULTIMEDIA))
  130. delete m_fullScreenVideo;
  131. #endif
  132. }
  133. void ChromeClientQt::setWindowRect(const FloatRect& rect)
  134. {
  135. if (!m_webPage)
  136. return;
  137. m_webPage->setWindowRect(QRect(qRound(rect.x()), qRound(rect.y()), qRound(rect.width()), qRound(rect.height())));
  138. }
  139. /*!
  140. windowRect represents the rect of the Window, including all interface elements
  141. like toolbars/scrollbars etc. It is used by the viewport meta tag as well as
  142. by the DOM Window object: outerHeight(), outerWidth(), screenX(), screenY().
  143. */
  144. FloatRect ChromeClientQt::windowRect()
  145. {
  146. if (!platformPageClient())
  147. return FloatRect();
  148. return platformPageClient()->windowRect();
  149. }
  150. bool ChromeClientQt::allowsAcceleratedCompositing() const
  151. {
  152. if (!platformPageClient())
  153. return false;
  154. #if USE(ACCELERATED_COMPOSITING)
  155. return true;
  156. #else
  157. return false;
  158. #endif
  159. }
  160. FloatRect ChromeClientQt::pageRect()
  161. {
  162. if (!m_webPage)
  163. return FloatRect();
  164. return FloatRect(QRectF(QPointF(0, 0), m_webPage->viewportSize()));
  165. }
  166. void ChromeClientQt::focus()
  167. {
  168. if (!m_webPage)
  169. return;
  170. m_webPage->setFocus();
  171. }
  172. void ChromeClientQt::unfocus()
  173. {
  174. if (!m_webPage)
  175. return;
  176. m_webPage->unfocus();
  177. }
  178. bool ChromeClientQt::canTakeFocus(FocusDirection)
  179. {
  180. // This is called when cycling through links/focusable objects and we
  181. // reach the last focusable object. Then we want to claim that we can
  182. // take the focus to avoid wrapping.
  183. return true;
  184. }
  185. void ChromeClientQt::takeFocus(FocusDirection)
  186. {
  187. // don't do anything. This is only called when cycling to links/focusable objects,
  188. // which in turn is called from focusNextPrevChild. We let focusNextPrevChild
  189. // call QWidget::focusNextPrevChild accordingly, so there is no need to do anything
  190. // here.
  191. }
  192. void ChromeClientQt::focusedNodeChanged(Node*)
  193. {
  194. }
  195. void ChromeClientQt::focusedFrameChanged(Frame*)
  196. {
  197. }
  198. Page* ChromeClientQt::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features, const NavigationAction&)
  199. {
  200. QWebPageAdapter* newPage = m_webPage->createWindow(features.dialog);
  201. if (!newPage)
  202. return 0;
  203. return newPage->page;
  204. }
  205. void ChromeClientQt::show()
  206. {
  207. if (!m_webPage)
  208. return;
  209. m_webPage->show();
  210. }
  211. bool ChromeClientQt::canRunModal()
  212. {
  213. return true;
  214. }
  215. void ChromeClientQt::runModal()
  216. {
  217. m_eventLoop = new QEventLoop();
  218. QEventLoop* eventLoop = m_eventLoop;
  219. m_eventLoop->exec();
  220. delete eventLoop;
  221. }
  222. void ChromeClientQt::setToolbarsVisible(bool visible)
  223. {
  224. toolBarsVisible = visible;
  225. QMetaObject::invokeMethod(m_webPage->handle(), "toolBarVisibilityChangeRequested", Q_ARG(bool, visible));
  226. }
  227. bool ChromeClientQt::toolbarsVisible()
  228. {
  229. return toolBarsVisible;
  230. }
  231. void ChromeClientQt::setStatusbarVisible(bool visible)
  232. {
  233. QMetaObject::invokeMethod(m_webPage->handle(), "statusBarVisibilityChangeRequested", Q_ARG(bool, visible));
  234. statusBarVisible = visible;
  235. }
  236. bool ChromeClientQt::statusbarVisible()
  237. {
  238. return statusBarVisible;
  239. }
  240. void ChromeClientQt::setScrollbarsVisible(bool)
  241. {
  242. notImplemented();
  243. }
  244. bool ChromeClientQt::scrollbarsVisible()
  245. {
  246. notImplemented();
  247. return true;
  248. }
  249. void ChromeClientQt::setMenubarVisible(bool visible)
  250. {
  251. menuBarVisible = visible;
  252. QMetaObject::invokeMethod(m_webPage->handle(), "menuBarVisibilityChangeRequested", Q_ARG(bool, visible));
  253. }
  254. bool ChromeClientQt::menubarVisible()
  255. {
  256. return menuBarVisible;
  257. }
  258. void ChromeClientQt::setResizable(bool)
  259. {
  260. notImplemented();
  261. }
  262. void ChromeClientQt::addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID)
  263. {
  264. QString x = message;
  265. QString y = sourceID;
  266. UNUSED_PARAM(columnNumber);
  267. m_webPage->javaScriptConsoleMessage(x, lineNumber, y);
  268. }
  269. void ChromeClientQt::chromeDestroyed()
  270. {
  271. delete this;
  272. }
  273. bool ChromeClientQt::canRunBeforeUnloadConfirmPanel()
  274. {
  275. return true;
  276. }
  277. bool ChromeClientQt::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
  278. {
  279. return runJavaScriptConfirm(frame, message);
  280. }
  281. void ChromeClientQt::closeWindowSoon()
  282. {
  283. m_webPage->page->setGroupName(String());
  284. m_webPage->page->mainFrame()->loader()->stopAllLoaders();
  285. QMetaObject::invokeMethod(m_webPage->handle(), "windowCloseRequested");
  286. }
  287. void ChromeClientQt::runJavaScriptAlert(Frame* f, const String& msg)
  288. {
  289. m_webPage->javaScriptAlert(QWebFrameAdapter::kit(f), msg);
  290. }
  291. bool ChromeClientQt::runJavaScriptConfirm(Frame* f, const String& msg)
  292. {
  293. return m_webPage->javaScriptConfirm(QWebFrameAdapter::kit(f), msg);
  294. }
  295. bool ChromeClientQt::runJavaScriptPrompt(Frame* f, const String& message, const String& defaultValue, String& result)
  296. {
  297. QString x = result;
  298. QWebFrameAdapter* webFrame = QWebFrameAdapter::kit(f);
  299. bool rc = m_webPage->javaScriptPrompt(webFrame, message, defaultValue, &x);
  300. // Fix up a quirk in the QInputDialog class. If no input happened the string should be empty
  301. // but it is null. See https://bugs.webkit.org/show_bug.cgi?id=30914.
  302. if (rc && x.isNull())
  303. result = String("");
  304. else
  305. result = x;
  306. return rc;
  307. }
  308. void ChromeClientQt::setStatusbarText(const String& msg)
  309. {
  310. QString x = msg;
  311. QMetaObject::invokeMethod(m_webPage->handle(), "statusBarMessage", Q_ARG(QString, x));
  312. }
  313. bool ChromeClientQt::shouldInterruptJavaScript()
  314. {
  315. return m_webPage->shouldInterruptJavaScript();
  316. }
  317. KeyboardUIMode ChromeClientQt::keyboardUIMode()
  318. {
  319. return m_webPage->settings->testAttribute(QWebSettings::LinksIncludedInFocusChain)
  320. ? KeyboardAccessTabsToLinks : KeyboardAccessDefault;
  321. }
  322. IntRect ChromeClientQt::windowResizerRect() const
  323. {
  324. #if defined(Q_WS_MAC)
  325. if (!m_webPage)
  326. return IntRect();
  327. QWebPageClient* pageClient = platformPageClient();
  328. if (!pageClient)
  329. return IntRect();
  330. QWindow* topLevelWidget = pageClient->ownerWindow();
  331. if (!topLevelWidget)
  332. return IntRect();
  333. QRect topLevelGeometry(topLevelWidget->geometry());
  334. // There's no API in Qt to query for the size of the resizer, so we assume
  335. // it has the same width and height as the scrollbar thickness.
  336. int scollbarThickness = ScrollbarTheme::theme()->scrollbarThickness();
  337. // There's no API in Qt to query for the position of the resizer. Sometimes
  338. // it's drawn by the system, and sometimes it's a QSizeGrip. For RTL locales
  339. // it might even be on the lower left side of the window, but in WebKit we
  340. // always draw scrollbars on the right hand side, so we assume this to be the
  341. // location when computing the resize rect to reserve for WebKit.
  342. QPoint resizeCornerTopLeft = QPoint(topLevelGeometry.width(), topLevelGeometry.height())
  343. - QPoint(scollbarThickness, scollbarThickness))
  344. - m_webPage->viewRectRelativeToWindow().topLeft();
  345. QRect resizeCornerRect = QRect(resizeCornerTopLeft, QSize(scollbarThickness, scollbarThickness));
  346. return resizeCornerRect.intersected(pageClient->geometryRelativeToOwnerWidget());
  347. #else
  348. return IntRect();
  349. #endif
  350. }
  351. void ChromeClientQt::invalidateRootView(const IntRect& windowRect, bool)
  352. {
  353. #if USE(TILED_BACKING_STORE)
  354. if (platformPageClient()) {
  355. WebCore::TiledBackingStore* backingStore = m_webPage->mainFrameAdapter()->frame->tiledBackingStore();
  356. if (!backingStore)
  357. return;
  358. backingStore->invalidate(windowRect);
  359. }
  360. #else
  361. Q_UNUSED(windowRect);
  362. #endif
  363. }
  364. void ChromeClientQt::invalidateContentsAndRootView(const IntRect& windowRect, bool)
  365. {
  366. // No double buffer, so only update the QWidget if content changed.
  367. if (platformPageClient()) {
  368. QRect rect(windowRect);
  369. rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize()));
  370. if (!rect.isEmpty())
  371. platformPageClient()->update(rect);
  372. }
  373. QMetaObject::invokeMethod(m_webPage->handle(), "repaintRequested", Qt::QueuedConnection, Q_ARG(QRect, windowRect));
  374. // FIXME: There is no "immediate" support for window painting. This should be done always whenever the flag
  375. // is set.
  376. }
  377. void ChromeClientQt::invalidateContentsForSlowScroll(const IntRect& windowRect, bool immediate)
  378. {
  379. invalidateContentsAndRootView(windowRect, immediate);
  380. }
  381. void ChromeClientQt::scroll(const IntSize& delta, const IntRect& scrollViewRect, const IntRect&)
  382. {
  383. if (platformPageClient())
  384. platformPageClient()->scroll(delta.width(), delta.height(), scrollViewRect);
  385. QMetaObject::invokeMethod(m_webPage->handle(), "scrollRequested", Q_ARG(int, delta.width()), Q_ARG(int, delta.height()), Q_ARG(QRect, scrollViewRect));
  386. }
  387. #if USE(TILED_BACKING_STORE)
  388. void ChromeClientQt::delegatedScrollRequested(const IntPoint& point)
  389. {
  390. const QPoint ofs = m_webPage->mainFrameAdapter()->scrollPosition();
  391. IntSize currentPosition(ofs.x(), ofs.y());
  392. int x = point.x() - currentPosition.width();
  393. int y = point.y() - currentPosition.height();
  394. const QRect rect(QPoint(0, 0), m_webPage->viewportSize());
  395. QMetaObject::invokeMethod(m_webPage->handle(), "scrollRequested", Q_ARG(int, x), Q_ARG(int, y), Q_ARG(QRect, rect));
  396. }
  397. #endif
  398. IntRect ChromeClientQt::rootViewToScreen(const IntRect& rect) const
  399. {
  400. QWebPageClient* pageClient = platformPageClient();
  401. if (!pageClient)
  402. return rect;
  403. QWindow* ownerWindow = pageClient->ownerWindow();
  404. if (!ownerWindow)
  405. return rect;
  406. QRect screenRect(rect);
  407. screenRect.translate(ownerWindow->mapToGlobal(m_webPage->viewRectRelativeToWindow().topLeft()));
  408. return screenRect;
  409. }
  410. IntPoint ChromeClientQt::screenToRootView(const IntPoint& point) const
  411. {
  412. QWebPageClient* pageClient = platformPageClient();
  413. if (!pageClient)
  414. return point;
  415. QWindow* ownerWindow = pageClient->ownerWindow();
  416. if (!ownerWindow)
  417. return point;
  418. return ownerWindow->mapFromGlobal(point) - m_webPage->viewRectRelativeToWindow().topLeft();
  419. }
  420. PlatformPageClient ChromeClientQt::platformPageClient() const
  421. {
  422. return m_webPage->client.data();
  423. }
  424. void ChromeClientQt::contentsSizeChanged(Frame* frame, const IntSize& size) const
  425. {
  426. if (frame->loader()->networkingContext())
  427. QWebFrameAdapter::kit(frame)->contentsSizeDidChange(size);
  428. }
  429. void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult& result, unsigned)
  430. {
  431. TextDirection dir;
  432. if (result.absoluteLinkURL() != lastHoverURL
  433. || result.title(dir) != lastHoverTitle
  434. || result.textContent() != lastHoverContent) {
  435. lastHoverURL = result.absoluteLinkURL();
  436. lastHoverTitle = result.title(dir);
  437. lastHoverContent = result.textContent();
  438. QMetaObject::invokeMethod(m_webPage->handle(), "linkHovered", Q_ARG(QString, lastHoverURL.string()),
  439. Q_ARG(QString, lastHoverTitle), Q_ARG(QString, lastHoverContent));
  440. }
  441. }
  442. void ChromeClientQt::setToolTip(const String &tip, TextDirection)
  443. {
  444. m_webPage->setToolTip(tip);
  445. }
  446. void ChromeClientQt::print(Frame* frame)
  447. {
  448. emit m_webPage->printRequested(QWebFrameAdapter::kit(frame));
  449. }
  450. #if ENABLE(SQL_DATABASE)
  451. void ChromeClientQt::exceededDatabaseQuota(Frame* frame, const String& databaseName, DatabaseDetails)
  452. {
  453. quint64 quota = QWebSettings::offlineStorageDefaultQuota();
  454. if (!DatabaseManager::manager().hasEntryForOrigin(frame->document()->securityOrigin()))
  455. DatabaseManager::manager().setQuota(frame->document()->securityOrigin(), quota);
  456. m_webPage->databaseQuotaExceeded(QWebFrameAdapter::kit(frame), databaseName);
  457. }
  458. #endif
  459. void ChromeClientQt::reachedMaxAppCacheSize(int64_t)
  460. {
  461. // FIXME: Free some space.
  462. notImplemented();
  463. }
  464. void ChromeClientQt::reachedApplicationCacheOriginQuota(SecurityOrigin* origin, int64_t totalSpaceNeeded)
  465. {
  466. int64_t quota;
  467. quint64 defaultOriginQuota = WebCore::cacheStorage().defaultOriginQuota();
  468. QWebSecurityOriginPrivate* priv = new QWebSecurityOriginPrivate(origin);
  469. QWebSecurityOrigin* securityOrigin = new QWebSecurityOrigin(priv);
  470. if (!WebCore::cacheStorage().calculateQuotaForOrigin(origin, quota))
  471. WebCore::cacheStorage().storeUpdatedQuotaForOrigin(origin, defaultOriginQuota);
  472. m_webPage->applicationCacheQuotaExceeded(securityOrigin, defaultOriginQuota, static_cast<quint64>(totalSpaceNeeded));
  473. }
  474. #if ENABLE(INPUT_TYPE_COLOR)
  475. PassOwnPtr<ColorChooser> ChromeClientQt::createColorChooser(ColorChooserClient* client, const Color& color)
  476. {
  477. const QColor selectedColor = m_webPage->colorSelectionRequested(QColor(color));
  478. client->didChooseColor(selectedColor);
  479. client->didEndChooser();
  480. return nullptr;
  481. }
  482. #endif
  483. void ChromeClientQt::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
  484. {
  485. RefPtr<FileChooser> fileChooser = prpFileChooser;
  486. QStringList suggestedFileNames;
  487. for (unsigned i = 0; i < fileChooser->settings().selectedFiles.size(); ++i)
  488. suggestedFileNames += fileChooser->settings().selectedFiles[i];
  489. const bool allowMultiple = fileChooser->settings().allowsMultipleFiles;
  490. QStringList result = m_webPage->chooseFiles(QWebFrameAdapter::kit(frame), allowMultiple, suggestedFileNames);
  491. if (!result.isEmpty()) {
  492. if (allowMultiple) {
  493. Vector<String> names;
  494. for (int i = 0; i < result.count(); ++i)
  495. names.append(result.at(i));
  496. fileChooser->chooseFiles(names);
  497. } else
  498. fileChooser->chooseFile(result.first());
  499. }
  500. }
  501. void ChromeClientQt::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
  502. {
  503. loader->notifyFinished(Icon::createIconForFiles(filenames));
  504. }
  505. void ChromeClientQt::setCursor(const Cursor& cursor)
  506. {
  507. #ifndef QT_NO_CURSOR
  508. QWebPageClient* pageClient = platformPageClient();
  509. if (!pageClient)
  510. return;
  511. pageClient->setCursor(*cursor.platformCursor());
  512. #else
  513. UNUSED_PARAM(cursor);
  514. #endif
  515. }
  516. #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
  517. void ChromeClientQt::scheduleAnimation()
  518. {
  519. if (!m_refreshAnimation)
  520. m_refreshAnimation = adoptPtr(new RefreshAnimation(this));
  521. m_refreshAnimation->scheduleAnimation();
  522. }
  523. void ChromeClientQt::serviceScriptedAnimations()
  524. {
  525. m_webPage->mainFrameAdapter()->frame->view()->serviceScriptedAnimations(currentTime());
  526. }
  527. #endif
  528. #if USE(ACCELERATED_COMPOSITING)
  529. void ChromeClientQt::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
  530. {
  531. if (!m_textureMapperLayerClient)
  532. m_textureMapperLayerClient = adoptPtr(new TextureMapperLayerClientQt(m_webPage->mainFrameAdapter()));
  533. m_textureMapperLayerClient->setRootGraphicsLayer(graphicsLayer);
  534. }
  535. void ChromeClientQt::setNeedsOneShotDrawingSynchronization()
  536. {
  537. // we want the layers to synchronize next time we update the screen anyway
  538. if (m_textureMapperLayerClient)
  539. m_textureMapperLayerClient->markForSync(false);
  540. }
  541. void ChromeClientQt::scheduleCompositingLayerFlush()
  542. {
  543. // we want the layers to synchronize ASAP
  544. if (m_textureMapperLayerClient)
  545. m_textureMapperLayerClient->markForSync(true);
  546. }
  547. ChromeClient::CompositingTriggerFlags ChromeClientQt::allowedCompositingTriggers() const
  548. {
  549. if (allowsAcceleratedCompositing())
  550. return ThreeDTransformTrigger | CanvasTrigger | AnimationTrigger | AnimatedOpacityTrigger;
  551. return 0;
  552. }
  553. #endif
  554. #if USE(TILED_BACKING_STORE)
  555. IntRect ChromeClientQt::visibleRectForTiledBackingStore() const
  556. {
  557. if (!platformPageClient() || !m_webPage)
  558. return IntRect();
  559. if (!platformPageClient()->viewResizesToContentsEnabled()) {
  560. const QPoint ofs = m_webPage->mainFrameAdapter()->scrollPosition();
  561. IntSize offset(ofs.x(), ofs.y());
  562. return QRect(QPoint(offset.width(), offset.height()), m_webPage->mainFrameAdapter()->frameRect().size());
  563. }
  564. return enclosingIntRect(FloatRect(platformPageClient()->graphicsItemVisibleRect()));
  565. }
  566. #endif
  567. #if ENABLE(VIDEO) && ((USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)) || USE(QT_MULTIMEDIA))
  568. FullScreenVideoQt* ChromeClientQt::fullScreenVideo()
  569. {
  570. if (!m_fullScreenVideo)
  571. m_fullScreenVideo = new FullScreenVideoQt(this);
  572. return m_fullScreenVideo;
  573. }
  574. bool ChromeClientQt::supportsFullscreenForNode(const Node* node)
  575. {
  576. ASSERT(node);
  577. return node->hasTagName(HTMLNames::videoTag) && fullScreenVideo()->isValid();
  578. }
  579. bool ChromeClientQt::requiresFullscreenForVideoPlayback()
  580. {
  581. return fullScreenVideo()->requiresFullScreenForVideoPlayback();
  582. }
  583. void ChromeClientQt::enterFullscreenForNode(Node* node)
  584. {
  585. ASSERT(node && node->hasTagName(HTMLNames::videoTag));
  586. fullScreenVideo()->enterFullScreenForNode(node);
  587. }
  588. void ChromeClientQt::exitFullscreenForNode(Node* node)
  589. {
  590. ASSERT(node && node->hasTagName(HTMLNames::videoTag));
  591. fullScreenVideo()->exitFullScreenForNode(node);
  592. }
  593. #endif
  594. PassOwnPtr<QWebSelectMethod> ChromeClientQt::createSelectPopup() const
  595. {
  596. OwnPtr<QWebSelectMethod> result = m_platformPlugin.createSelectInputMethod();
  597. if (result)
  598. return result.release();
  599. #if !defined(QT_NO_COMBOBOX)
  600. return adoptPtr(m_webPage->createSelectPopup());
  601. #else
  602. return nullptr;
  603. #endif
  604. }
  605. void ChromeClientQt::dispatchViewportPropertiesDidChange(const ViewportArguments&) const
  606. {
  607. m_webPage->emitViewportChangeRequested();
  608. }
  609. #if USE(QT_MULTIMEDIA)
  610. QWebFullScreenVideoHandler* ChromeClientQt::createFullScreenVideoHandler()
  611. {
  612. QWebFullScreenVideoHandler* handler = m_platformPlugin.createFullScreenVideoHandler().leakPtr();
  613. if (!handler)
  614. handler = m_webPage->createFullScreenVideoHandler();
  615. return handler;
  616. }
  617. #endif
  618. bool ChromeClientQt::selectItemWritingDirectionIsNatural()
  619. {
  620. return false;
  621. }
  622. bool ChromeClientQt::selectItemAlignmentFollowsMenuWritingDirection()
  623. {
  624. return false;
  625. }
  626. bool ChromeClientQt::hasOpenedPopup() const
  627. {
  628. notImplemented();
  629. return false;
  630. }
  631. PassRefPtr<PopupMenu> ChromeClientQt::createPopupMenu(PopupMenuClient* client) const
  632. {
  633. return adoptRef(new PopupMenuQt(client, this));
  634. }
  635. PassRefPtr<SearchPopupMenu> ChromeClientQt::createSearchPopupMenu(PopupMenuClient* client) const
  636. {
  637. return adoptRef(new SearchPopupMenuQt(createPopupMenu(client)));
  638. }
  639. void ChromeClientQt::populateVisitedLinks()
  640. {
  641. // We don't need to do anything here because history is tied to QWebPage rather than stored
  642. // in a separate database
  643. if (dumpVisitedLinksCallbacks) {
  644. printf("Asked to populate visited links for WebView \"%s\"\n",
  645. qPrintable(QUrl(m_webPage->mainFrameAdapter()->url).toString()));
  646. }
  647. }
  648. } // namespace WebCore