BackingStoreClient.cpp [plain text]
#include "config.h"
#include "BackingStoreClient.h"
#include "BackingStore.h"
#include "BackingStore_p.h"
#include "FloatPoint.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLFrameOwnerElement.h"
#include "Page.h"
#include "RenderBox.h"
#include "WebPage_p.h"
#include <BlackBerryPlatformViewportAccessor.h>
using namespace WebCore;
namespace BlackBerry {
namespace WebKit {
static inline IntSize pointToSize(const IntPoint& point)
{
return IntSize(point.x(), point.y());
}
BackingStoreClient* BackingStoreClient::create(Frame* frame, Frame* parentFrame, WebPage* parentPage)
{
ASSERT_UNUSED(parentFrame, !parentFrame);
BackingStoreClient* it = new BackingStoreClient(frame, parentPage);
return it;
}
BackingStoreClient::BackingStoreClient(Frame* frame, WebPage* parentPage)
: m_frame(frame)
, m_webPage(parentPage)
, m_backingStore(0)
, m_isClientGeneratedScroll(false)
, m_isScrollNotificationSuppressed(false)
{
m_backingStore = new BackingStore(m_webPage, this);
}
BackingStoreClient::~BackingStoreClient()
{
delete m_backingStore;
m_backingStore = 0;
m_frame = 0;
}
IntPoint BackingStoreClient::scrollPosition() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntPoint();
return m_frame->view()->scrollPosition() - pointToSize(m_frame->view()->minimumScrollPosition());
}
IntPoint BackingStoreClient::transformedScrollPosition() const
{
return m_webPage->webkitThreadViewportAccessor()->pixelScrollPosition();
}
void BackingStoreClient::setScrollPosition(const IntPoint& pos)
{
ASSERT(m_frame);
if (!m_frame->view())
return;
if (pos == scrollPosition())
return;
m_isScrollNotificationSuppressed = true;
m_frame->view()->setScrollPosition(pos + pointToSize(m_frame->view()->minimumScrollPosition()));
m_isScrollNotificationSuppressed = false;
}
IntPoint BackingStoreClient::maximumScrollPosition() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntPoint();
return m_frame->view()->maximumScrollPosition() - pointToSize(m_frame->view()->minimumScrollPosition());
}
IntPoint BackingStoreClient::transformedMaximumScrollPosition() const
{
return m_webPage->webkitThreadViewportAccessor()->roundToPixelFromDocumentContents(WebCore::FloatPoint(maximumScrollPosition()));
}
IntSize BackingStoreClient::actualVisibleSize() const
{
return m_webPage->webkitThreadViewportAccessor()->documentViewportSize();
}
IntSize BackingStoreClient::transformedActualVisibleSize() const
{
ASSERT(isMainFrame());
return m_webPage->webkitThreadViewportAccessor()->pixelViewportSize();
}
IntSize BackingStoreClient::viewportSize() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntSize();
ASSERT(isMainFrame());
return m_webPage->d->viewportSize();
}
IntSize BackingStoreClient::transformedViewportSize() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntSize();
ASSERT(isMainFrame());
return m_webPage->d->transformedViewportSize();
}
IntRect BackingStoreClient::visibleContentsRect() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntRect();
IntRect visibleContentRect = m_frame->view()->visibleContentRect();
ASSERT(isMainFrame());
return visibleContentRect;
}
IntSize BackingStoreClient::contentsSize() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntSize();
return m_frame->view()->contentsSize();
}
WebPagePrivate::LoadState BackingStoreClient::loadState() const
{
return m_webPage->d->loadState();
}
bool BackingStoreClient::isLoading() const
{
return m_webPage->d->isLoading();
}
bool BackingStoreClient::isFocused() const
{
return m_frame && m_frame->page() && m_frame->page()->focusController()
&& m_frame->page()->focusController()->focusedFrame() == m_frame;
}
bool BackingStoreClient::isClientGeneratedScroll() const
{
return m_isClientGeneratedScroll;
}
void BackingStoreClient::setIsClientGeneratedScroll(bool flag)
{
m_isClientGeneratedScroll = flag;
}
bool BackingStoreClient::isScrollNotificationSuppressed() const
{
return m_isScrollNotificationSuppressed;
}
void BackingStoreClient::setIsScrollNotificationSuppressed(bool flag)
{
m_isScrollNotificationSuppressed = flag;
}
void BackingStoreClient::checkOriginOfCurrentScrollOperation()
{
if (isScrollNotificationSuppressed())
return;
ASSERT(isMainFrame());
m_webPage->d->notifyTransformedScrollChanged();
}
}
}