WebKitThreadViewportAccessor.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2012, 2013 Research In Motion Limited. All rights reserved.
  3. */
  4. #include "config.h"
  5. #include "WebKitThreadViewportAccessor.h"
  6. #include "WebPage_p.h"
  7. #include <BlackBerryPlatformMessageClient.h>
  8. #include <BlackBerryPlatformPrimitives.h>
  9. using BlackBerry::Platform::IntPoint;
  10. using BlackBerry::Platform::IntSize;
  11. using BlackBerry::Platform::ViewportAccessor;
  12. namespace BlackBerry {
  13. namespace WebKit {
  14. WebKitThreadViewportAccessor::WebKitThreadViewportAccessor(WebPagePrivate* webPagePrivate)
  15. : m_webPagePrivate(webPagePrivate)
  16. {
  17. }
  18. IntSize WebKitThreadViewportAccessor::pixelContentsSize() const
  19. {
  20. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  21. double scaleFactor = scale();
  22. if (scaleFactor != 1.0) {
  23. // Round down to avoid showing partially rendered pixels.
  24. IntSize size = documentContentsSize();
  25. return IntSize(
  26. floorf(size.width() * scaleFactor),
  27. floorf(size.height() * scaleFactor));
  28. }
  29. return documentContentsSize();
  30. }
  31. IntSize WebKitThreadViewportAccessor::documentContentsSize() const
  32. {
  33. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  34. return m_webPagePrivate->contentsSize();
  35. }
  36. IntPoint WebKitThreadViewportAccessor::pixelScrollPosition() const
  37. {
  38. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  39. return roundToPixelFromDocumentContents(documentScrollPosition());
  40. }
  41. IntPoint WebKitThreadViewportAccessor::documentScrollPosition() const
  42. {
  43. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  44. return m_webPagePrivate->scrollPosition();
  45. }
  46. IntSize WebKitThreadViewportAccessor::pixelViewportSize() const
  47. {
  48. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  49. return m_webPagePrivate->transformedActualVisibleSize();
  50. }
  51. IntSize WebKitThreadViewportAccessor::documentViewportSize() const
  52. {
  53. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  54. return roundToDocumentFromPixelContents(pixelViewportRect()).size();
  55. }
  56. IntPoint WebKitThreadViewportAccessor::destinationSurfaceOffset() const
  57. {
  58. // FIXME: This should somehow get its offset from a reliable source.
  59. return IntPoint(0, 0);
  60. }
  61. double WebKitThreadViewportAccessor::scale() const
  62. {
  63. ASSERT(Platform::webKitThreadMessageClient()->isCurrentThread());
  64. return m_webPagePrivate->currentScale();
  65. }
  66. } // namespace WebKit
  67. } // namespace BlackBerry