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