ChromeClientManx.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (C) 2008 Apple Computer, Inc. All rights reserved.
  3. * Copyright (C) 2012 Sony Computer Entertainment Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "ChromeClientManx.h"
  28. #include "Console.h"
  29. #include "FileChooser.h"
  30. #include "FloatRect.h"
  31. #include "FocusController.h"
  32. #include "Frame.h"
  33. #include "FrameLoadRequest.h"
  34. #include "FrameView.h"
  35. #include "HTMLInputElement.h"
  36. #include "HTMLNames.h"
  37. #include "HTMLTextAreaElement.h"
  38. #include "HitTestResult.h"
  39. #include "NamedNodeMap.h"
  40. #include "NotImplemented.h"
  41. #include "Page.h"
  42. #include "PopupMenuManx.h"
  43. #include "SearchPopupMenuManx.h"
  44. #include "WebViewPopupMenu.h"
  45. #include "WebViewPrivate.h"
  46. #include "WindowFeatures.h"
  47. #include <stdio.h>
  48. #include <webkit/WebView.h>
  49. #include <wtf/text/CString.h>
  50. #include <wtf/text/WTFString.h>
  51. // #define MYTRACE printf("+++ ChromeClientManx::%s() +++ :L%d\n", __FUNCTION__, __LINE__);
  52. #define MYTRACE
  53. namespace WebCore {
  54. ChromeClientManx::ChromeClientManx(WebKit::WebViewPrivate* webView)
  55. : m_listener(0)
  56. {
  57. m_webView = webView;
  58. }
  59. ChromeClientManx::~ChromeClientManx()
  60. {
  61. }
  62. void ChromeClientManx::chromeDestroyed()
  63. {
  64. MYTRACE;
  65. delete this;
  66. }
  67. void ChromeClientManx::setWindowRect(const FloatRect&)
  68. {
  69. MYTRACE;
  70. notImplemented();
  71. }
  72. FloatRect ChromeClientManx::windowRect()
  73. {
  74. MYTRACE;
  75. notImplemented();
  76. WebCore::IntSize size = m_webView->m_viewSize;
  77. return FloatRect(0, 0, size.width(), size.height());
  78. }
  79. FloatRect ChromeClientManx::pageRect()
  80. {
  81. MYTRACE;
  82. notImplemented();
  83. return FloatRect();
  84. }
  85. void ChromeClientManx::focus()
  86. {
  87. MYTRACE;
  88. notImplemented();
  89. }
  90. void ChromeClientManx::unfocus()
  91. {
  92. MYTRACE;
  93. notImplemented();
  94. }
  95. bool ChromeClientManx::canTakeFocus(FocusDirection)
  96. {
  97. MYTRACE;
  98. // This is called when cycling through links/focusable objects and we
  99. // reach the last focusable object. Then we want to claim that we can
  100. // take the focus to avoid wrapping.
  101. return false;
  102. }
  103. void ChromeClientManx::takeFocus(FocusDirection)
  104. {
  105. MYTRACE;
  106. notImplemented();
  107. }
  108. void ChromeClientManx::focusedNodeChanged(Node* node)
  109. {
  110. MYTRACE;
  111. m_webView->client().didFocusedNodeChanged();
  112. }
  113. void ChromeClientManx::focusedFrameChanged(Frame*)
  114. {
  115. MYTRACE;
  116. notImplemented();
  117. }
  118. Page* ChromeClientManx::createWindow(Frame* frame, const FrameLoadRequest& request, const WindowFeatures& features, const NavigationAction& action)
  119. {
  120. MYTRACE;
  121. CString url = request.resourceRequest().url().string().utf8();
  122. WebKit::WebView* webview = m_webView->client().createWindow(url.data(), (int)features.width, (int)features.height, true);
  123. if (!webview)
  124. return 0;
  125. WebKit::WebViewPrivate* webViewPriv = static_cast<WebKit::WebViewPrivate*>(webview);
  126. // set useragent of parent webview.
  127. webViewPriv->setUserAgent(m_webView->userAgent());
  128. return webViewPriv->m_page.get();
  129. }
  130. Page* ChromeClientManx::createModalDialog(Frame*, const FrameLoadRequest&)
  131. {
  132. MYTRACE;
  133. notImplemented();
  134. return 0;
  135. }
  136. void ChromeClientManx::show()
  137. {
  138. MYTRACE;
  139. notImplemented();
  140. }
  141. bool ChromeClientManx::canRunModal()
  142. {
  143. MYTRACE;
  144. notImplemented();
  145. return false;
  146. }
  147. void ChromeClientManx::runModal()
  148. {
  149. MYTRACE;
  150. notImplemented();
  151. }
  152. void ChromeClientManx::setToolbarsVisible(bool)
  153. {
  154. MYTRACE;
  155. notImplemented();
  156. }
  157. bool ChromeClientManx::toolbarsVisible()
  158. {
  159. MYTRACE;
  160. notImplemented();
  161. return false;
  162. }
  163. void ChromeClientManx::setStatusbarVisible(bool)
  164. {
  165. MYTRACE;
  166. notImplemented();
  167. }
  168. bool ChromeClientManx::statusbarVisible()
  169. {
  170. MYTRACE;
  171. notImplemented();
  172. return false;
  173. }
  174. void ChromeClientManx::setScrollbarsVisible(bool)
  175. {
  176. MYTRACE;
  177. notImplemented();
  178. }
  179. bool ChromeClientManx::scrollbarsVisible()
  180. {
  181. MYTRACE;
  182. notImplemented();
  183. return false;
  184. }
  185. void ChromeClientManx::setMenubarVisible(bool)
  186. {
  187. MYTRACE;
  188. notImplemented();
  189. }
  190. bool ChromeClientManx::menubarVisible()
  191. {
  192. MYTRACE;
  193. notImplemented();
  194. return false;
  195. }
  196. void ChromeClientManx::createSelectPopup(PopupMenuClient* client, int index, const IntRect& rect)
  197. {
  198. MYTRACE;
  199. m_webView->m_popupMenu->show(client, index, rect);
  200. }
  201. bool ChromeClientManx::destroySelectPopup()
  202. {
  203. MYTRACE;
  204. m_webView->m_popupMenu->hide(true);
  205. return true;
  206. }
  207. void ChromeClientManx::setResizable(bool)
  208. {
  209. MYTRACE;
  210. notImplemented();
  211. }
  212. void ChromeClientManx::addMessageToConsole(MessageSource source,
  213. MessageLevel level,
  214. const String& message,
  215. unsigned lineNumber,
  216. unsigned columnNumber,
  217. const String& sourceID)
  218. {
  219. MYTRACE;
  220. notImplemented();
  221. }
  222. bool ChromeClientManx::canRunBeforeUnloadConfirmPanel()
  223. {
  224. MYTRACE;
  225. notImplemented();
  226. return true;
  227. }
  228. bool ChromeClientManx::runBeforeUnloadConfirmPanel(const String& string,
  229. Frame* frame)
  230. {
  231. MYTRACE;
  232. notImplemented();
  233. return true;
  234. }
  235. void ChromeClientManx::closeWindowSoon()
  236. {
  237. MYTRACE;
  238. if (m_webView && m_webView->m_page)
  239. m_webView->m_page->mainFrame()->loader()->stopAllLoaders();
  240. m_webView->client().closeWindowSoon();
  241. }
  242. void ChromeClientManx::runJavaScriptAlert(Frame* frame, const String& string)
  243. {
  244. MYTRACE;
  245. m_webView->client().runJavaScriptAlert(string);
  246. }
  247. bool ChromeClientManx::runJavaScriptConfirm(Frame* frame, const String& string)
  248. {
  249. MYTRACE;
  250. return m_webView->client().runJavaScriptConfirm(string);
  251. }
  252. bool ChromeClientManx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
  253. {
  254. MYTRACE;
  255. WebKit::WebString webResult;
  256. bool ok = m_webView->client().runJavaScriptPrompt(message, defaultValue, webResult);
  257. result = webResult;
  258. return ok;
  259. }
  260. void ChromeClientManx::setStatusbarText(const String&)
  261. {
  262. MYTRACE;
  263. notImplemented();
  264. }
  265. bool ChromeClientManx::shouldInterruptJavaScript()
  266. {
  267. MYTRACE;
  268. notImplemented();
  269. return false;
  270. }
  271. KeyboardUIMode ChromeClientManx::keyboardUIMode()
  272. {
  273. MYTRACE;
  274. bool tabsToLinks = true;
  275. return tabsToLinks ? KeyboardAccessTabsToLinks : KeyboardAccessDefault;
  276. }
  277. bool ChromeClientManx::tabsToLinks() const
  278. {
  279. MYTRACE;
  280. return true;
  281. }
  282. IntRect ChromeClientManx::windowResizerRect() const
  283. {
  284. MYTRACE;
  285. notImplemented();
  286. return IntRect();
  287. }
  288. void ChromeClientManx::invalidateRootView(const IntRect&, bool)
  289. {
  290. m_webView->invalidate(IntRect(), true);
  291. }
  292. void ChromeClientManx::invalidateContentsAndRootView(const IntRect& updateRect, bool immediate)
  293. {
  294. m_webView->invalidate(updateRect, immediate);
  295. }
  296. void ChromeClientManx::invalidateContentsForSlowScroll(const IntRect& updateRect, bool immediate)
  297. {
  298. m_webView->invalidate(updateRect, immediate);
  299. }
  300. void ChromeClientManx::repaint(const IntRect& rect, bool contentChanged, bool immediate, bool repaintContentOnly)
  301. {
  302. notImplemented();
  303. }
  304. void ChromeClientManx::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
  305. {
  306. }
  307. IntPoint ChromeClientManx::screenToRootView(const IntPoint& point) const
  308. {
  309. notImplemented();
  310. return point;
  311. }
  312. IntRect ChromeClientManx::rootViewToScreen(const IntRect& rect) const
  313. {
  314. notImplemented();
  315. return rect;
  316. }
  317. PlatformPageClient ChromeClientManx::platformPageClient() const
  318. {
  319. return m_webView;
  320. }
  321. void ChromeClientManx::dispatchViewportPropertiesDidChange(const ViewportArguments& arguments) const
  322. {
  323. #define PRINTF(...)
  324. // #define PRINTF printf
  325. PRINTF("### dispatchViewportPropertiesDidChange() ###\n");
  326. PRINTF("--- ViewportArguments ---\n");
  327. PRINTF(" type %s\n", arguments.type == ViewportArguments::Implicit ? "Implicit" : "ViewportMeta");
  328. PRINTF(" width %.1f\n", arguments.width);
  329. PRINTF(" minWidth %.1f\n", arguments.minWidth);
  330. PRINTF(" maxWidth %.1f\n", arguments.maxWidth);
  331. PRINTF(" height %.1f\n", arguments.height);
  332. PRINTF(" minHeight %.1f\n", arguments.minHeight);
  333. PRINTF(" maxHeight %.1f\n", arguments.maxHeight);
  334. PRINTF(" zoom %.1f\n", arguments.zoom);
  335. PRINTF(" minZoom %.1f\n", arguments.minZoom);
  336. PRINTF(" maxZoom %.1f\n", arguments.maxZoom);
  337. PRINTF(" userZoom %.1f\n", arguments.userZoom);
  338. PRINTF(" orientation %.1f\n", arguments.orientation);
  339. PRINTF("---\n");
  340. WebCore::Frame *frame = m_webView->m_frame;
  341. if (!frame || !frame->page())
  342. return;
  343. // Zero value implies a parse error, or if not, it is out of range. Ignore such viewport meta tags.
  344. if (!arguments.width || !arguments.height)
  345. return;
  346. IntSize fixedLayoutSize = frame->view()->fixedLayoutSize();
  347. if (fixedLayoutSize.isEmpty())
  348. return;
  349. int desktopWidth = m_webView->m_defaultLayoutWidth;
  350. IntSize deviceSize = m_webView->m_viewSize;
  351. float devicePixelRatio = 1;
  352. PRINTF("--- Device settings ---\n");
  353. PRINTF(" deviceSize (%d, %d)\n", deviceSize.width(), deviceSize.height());
  354. PRINTF(" desktopWidth %d\n", desktopWidth);
  355. PRINTF(" devicePixelRatio %f\n", devicePixelRatio);
  356. PRINTF("---\n");
  357. // Call the common viewport computing logic in ViewportArguments.cpp.
  358. ViewportAttributes computed = computeViewportAttributes(
  359. arguments, desktopWidth, deviceSize.width(), deviceSize.height(),
  360. devicePixelRatio, deviceSize);
  361. PRINTF("=== computeViewportAttributes() ===\n");
  362. PRINTF("--- ComputedViewportAttributes ---\n");
  363. PRINTF(" width %.1f\n", computed.layoutSize.width());
  364. PRINTF(" height %.1f\n", computed.layoutSize.height());
  365. PRINTF(" initialScale %f\n", computed.initialScale);
  366. PRINTF(" maximumScale %f\n", computed.maximumScale);
  367. PRINTF(" minimumScale %f\n", computed.minimumScale);
  368. PRINTF(" userScalable %.1f\n", computed.userScalable);
  369. PRINTF(" orientation %.1f\n", computed.orientation);
  370. PRINTF("---\n");
  371. restrictMinimumScaleFactorToViewportSize(computed, deviceSize, devicePixelRatio);
  372. PRINTF("=== restrictMinimumScaleFactorToViewportSize() ===\n");
  373. PRINTF("--- ComputedViewportAttributes ---\n");
  374. PRINTF(" width %.1f\n", computed.layoutSize.width());
  375. PRINTF(" height %.1f\n", computed.layoutSize.height());
  376. PRINTF(" initialScale %f\n", computed.initialScale);
  377. PRINTF(" maximumScale %f\n", computed.maximumScale);
  378. PRINTF(" minimumScale %f\n", computed.minimumScale);
  379. PRINTF(" userScalable %.1f\n", computed.userScalable);
  380. PRINTF(" orientation %.1f\n", computed.orientation);
  381. PRINTF("---\n");
  382. restrictScaleFactorToInitialScaleIfNotUserScalable(computed);
  383. PRINTF("=== restrictScaleFactorToInitialScaleIfNotUserScalable() ===\n");
  384. PRINTF("--- ComputedViewportAttributes ---\n");
  385. PRINTF(" width %.1f\n", computed.layoutSize.width());
  386. PRINTF(" height %.1f\n", computed.layoutSize.height());
  387. PRINTF(" initialScale %f\n", computed.initialScale);
  388. PRINTF(" maximumScale %f\n", computed.maximumScale);
  389. PRINTF(" minimumScale %f\n", computed.minimumScale);
  390. PRINTF(" userScalable %.1f\n", computed.userScalable);
  391. PRINTF(" orientation %.1f\n", computed.orientation);
  392. PRINTF("---\n");
  393. m_webView->m_viewportAttr = computed;
  394. frame->view()->setFixedLayoutSize(flooredIntSize(computed.layoutSize));
  395. IntRect actualVisibleRect = m_webView->m_frame->view()->visibleContentRect();
  396. IntSize visibleSize(computed.layoutSize.width(), computed.layoutSize.height());
  397. actualVisibleRect.setSize(visibleSize);
  398. m_webView->m_frame->view()->setFixedVisibleContentRect(actualVisibleRect);
  399. m_webView->client().didViewportChanged(computed.initialScale, computed.maximumScale, computed.minimumScale, computed.userScalable);
  400. }
  401. void ChromeClientManx::contentsSizeChanged(Frame* frame, const IntSize& size) const
  402. {
  403. MYTRACE;
  404. // Ignore child frame.
  405. if (frame != m_webView->m_frame)
  406. return;
  407. int width = size.width();
  408. int height = size.height();
  409. // Update view's contents size since it may have changed.
  410. m_webView->m_contentsWidth = width;
  411. m_webView->m_contentsHeight = height;
  412. #if USE(ACCELERATED_COMPOSITING)
  413. m_webView->m_acceleratedCompositingContext->resizeRootLayer(size);
  414. #endif
  415. PRINTF("### contentsSizeChanged (%d, %d) ###\n", width, height);
  416. m_webView->client().didContentSizeChanged(width, height);
  417. }
  418. void ChromeClientManx::scrollBackingStore(int dx, int dy,
  419. const IntRect& scrollViewRect,
  420. const IntRect& clipRect)
  421. {
  422. notImplemented();
  423. }
  424. void ChromeClientManx::updateBackingStore()
  425. {
  426. notImplemented();
  427. }
  428. void ChromeClientManx::mouseDidMoveOverElement(const HitTestResult& hit, unsigned modifierFlags)
  429. {
  430. }
  431. void ChromeClientManx::setToolTip(const String& tip, TextDirection)
  432. {
  433. notImplemented();
  434. }
  435. void ChromeClientManx::print(Frame*)
  436. {
  437. notImplemented();
  438. }
  439. #if ENABLE(SQL_DATABASE)
  440. void ChromeClientManx::exceededDatabaseQuota(Frame*, const String&, DatabaseDetails)
  441. {
  442. notImplemented();
  443. }
  444. #endif
  445. void ChromeClientManx::reachedMaxAppCacheSize(int64_t spaceNeeded)
  446. {
  447. notImplemented();
  448. }
  449. void ChromeClientManx::reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t)
  450. {
  451. notImplemented();
  452. }
  453. #if USE(ACCELERATED_COMPOSITING)
  454. void ChromeClientManx::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* rootLayer)
  455. {
  456. WebKit::AcceleratedCompositingContext* context = m_webView->m_acceleratedCompositingContext.get();
  457. bool turningOffCompositing = !rootLayer && context->enabled();
  458. bool turningOnCompositing = rootLayer && !context->enabled();
  459. context->setRootCompositingLayer(rootLayer);
  460. if (turningOnCompositing)
  461. m_webView->releaseTiles();
  462. if (turningOffCompositing)
  463. notImplemented();
  464. }
  465. void ChromeClientManx::setNeedsOneShotDrawingSynchronization()
  466. {
  467. WebKit::AcceleratedCompositingContext* context = m_webView->m_acceleratedCompositingContext.get();
  468. context->scheduleLayerFlush();
  469. }
  470. void ChromeClientManx::scheduleCompositingLayerFlush()
  471. {
  472. WebKit::AcceleratedCompositingContext* context = m_webView->m_acceleratedCompositingContext.get();
  473. context->scheduleLayerFlush();
  474. }
  475. #endif
  476. void ChromeClientManx::runOpenPanel(Frame*, PassRefPtr<FileChooser> file)
  477. {
  478. m_file = file;
  479. m_webView->client().runOpenPanel();
  480. }
  481. void ChromeClientManx::loadIconForFiles(const Vector<String>&, FileIconLoader*)
  482. {
  483. notImplemented();
  484. }
  485. void ChromeClientManx::setCursor(const WebCore::Cursor& cursor)
  486. {
  487. m_webView->client().setCursor(cursor.type());
  488. }
  489. void ChromeClientManx::setCursorHiddenUntilMouseMoves(bool)
  490. {
  491. notImplemented();
  492. }
  493. #if ENABLE(TOUCH_EVENTS)
  494. void ChromeClientManx::needTouchEvents(bool)
  495. {
  496. notImplemented();
  497. }
  498. #endif
  499. bool ChromeClientManx::selectItemWritingDirectionIsNatural()
  500. {
  501. return true;
  502. }
  503. bool ChromeClientManx::selectItemAlignmentFollowsMenuWritingDirection()
  504. {
  505. return false;
  506. }
  507. bool ChromeClientManx::hasOpenedPopup() const
  508. {
  509. notImplemented();
  510. return false;
  511. }
  512. PassRefPtr<PopupMenu> ChromeClientManx::createPopupMenu(PopupMenuClient* client) const
  513. {
  514. return adoptRef(new PopupMenuManx(client));
  515. }
  516. PassRefPtr<SearchPopupMenu> ChromeClientManx::createSearchPopupMenu(PopupMenuClient* client) const
  517. {
  518. return adoptRef(new SearchPopupMenuManx(client));
  519. }
  520. void ChromeClientManx::setUpload(const char* path)
  521. {
  522. if (m_file)
  523. m_file->chooseFile(String(path));
  524. }
  525. void ChromeClientManx::elementDidFocus(const WebCore::Node* node)
  526. {
  527. MYTRACE;
  528. #if 0
  529. if (node) {
  530. printf(" node=(type:%d)'%s'\n",
  531. node->nodeType(),
  532. node->nodeName().utf8().data());
  533. }
  534. #endif
  535. }
  536. void ChromeClientManx::elementDidBlur(const Node* node)
  537. {
  538. MYTRACE;
  539. #if 0
  540. if (node) {
  541. printf(" node=(type:%d)'%s'\n",
  542. node->nodeType(),
  543. node->nodeName().utf8().data());
  544. }
  545. #endif
  546. }
  547. #if USE(TILED_BACKING_STORE)
  548. void ChromeClientManx::delegatedScrollRequested(const IntPoint& point)
  549. {
  550. m_webView->client().delegatedScrollRequested(point);
  551. }
  552. IntRect ChromeClientManx::visibleRectForTiledBackingStore() const
  553. {
  554. return m_webView->m_frame->view()->visibleContentRect();
  555. }
  556. #endif
  557. }