ChunkedUpdateDrawingArea.cpp [plain text]
#include "config.h"
#include "ChunkedUpdateDrawingArea.h"
#include "DrawingAreaMessageKinds.h"
#include "DrawingAreaProxyMessageKinds.h"
#include "MessageID.h"
#include "UpdateChunk.h"
#include "WebCoreArgumentCoders.h"
#include "WebPage.h"
#include "WebProcess.h"
using namespace WebCore;
namespace WebKit {
ChunkedUpdateDrawingArea::ChunkedUpdateDrawingArea(WebPage* webPage)
: DrawingArea(DrawingAreaTypeChunkedUpdate, webPage)
, m_isWaitingForUpdate(false)
, m_paintingIsSuspended(false)
, m_displayTimer(WebProcess::shared().runLoop(), this, &ChunkedUpdateDrawingArea::display)
{
}
ChunkedUpdateDrawingArea::~ChunkedUpdateDrawingArea()
{
}
void ChunkedUpdateDrawingArea::scroll(const IntRect& scrollRect, const IntSize& scrollOffset)
{
setNeedsDisplay(scrollRect);
}
void ChunkedUpdateDrawingArea::setNeedsDisplay(const IntRect& rect)
{
m_dirtyRect.unite(rect);
scheduleDisplay();
}
void ChunkedUpdateDrawingArea::display()
{
ASSERT(!m_isWaitingForUpdate);
if (m_paintingIsSuspended)
return;
if (m_dirtyRect.isEmpty())
return;
m_webPage->layoutIfNeeded();
IntRect dirtyRect = m_dirtyRect;
m_dirtyRect = IntRect();
UpdateChunk updateChunk(dirtyRect);
paintIntoUpdateChunk(&updateChunk);
WebProcess::shared().connection()->deprecatedSend(DrawingAreaProxyLegacyMessage::Update, m_webPage->pageID(), CoreIPC::In(updateChunk));
m_isWaitingForUpdate = true;
m_displayTimer.stop();
}
void ChunkedUpdateDrawingArea::forceRepaint()
{
m_isWaitingForUpdate = false;
display();
}
void ChunkedUpdateDrawingArea::scheduleDisplay()
{
if (m_paintingIsSuspended)
return;
if (m_isWaitingForUpdate)
return;
if (m_dirtyRect.isEmpty())
return;
if (m_displayTimer.isActive())
return;
m_displayTimer.startOneShot(0);
}
void ChunkedUpdateDrawingArea::setSize(const IntSize& viewSize)
{
ASSERT_ARG(viewSize, !viewSize.isEmpty());
m_isWaitingForUpdate = false;
m_webPage->setSize(viewSize);
m_webPage->layoutIfNeeded();
if (m_paintingIsSuspended) {
ASSERT(!m_displayTimer.isActive());
WebProcess::shared().connection()->deprecatedSend(DrawingAreaProxyLegacyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(UpdateChunk()));
return;
}
UpdateChunk updateChunk(IntRect(0, 0, viewSize.width(), viewSize.height()));
paintIntoUpdateChunk(&updateChunk);
m_displayTimer.stop();
WebProcess::shared().connection()->deprecatedSend(DrawingAreaProxyLegacyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(updateChunk));
}
void ChunkedUpdateDrawingArea::suspendPainting()
{
ASSERT(!m_paintingIsSuspended);
m_paintingIsSuspended = true;
m_displayTimer.stop();
}
void ChunkedUpdateDrawingArea::deprecatedResumePainting(bool forceRepaint)
{
ASSERT(m_paintingIsSuspended);
m_paintingIsSuspended = false;
if (forceRepaint) {
m_dirtyRect = m_webPage->bounds();
}
scheduleDisplay();
}
void ChunkedUpdateDrawingArea::didUpdate()
{
m_isWaitingForUpdate = false;
display();
}
void ChunkedUpdateDrawingArea::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
{
switch (messageID.get<DrawingAreaLegacyMessage::Kind>()) {
case DrawingAreaLegacyMessage::SetSize: {
IntSize size;
if (!arguments->decode(CoreIPC::Out(size)))
return;
setSize(size);
break;
}
case DrawingAreaLegacyMessage::SuspendPainting:
suspendPainting();
break;
case DrawingAreaLegacyMessage::ResumePainting: {
bool forceRepaint;
if (!arguments->decode(CoreIPC::Out(forceRepaint)))
return;
deprecatedResumePainting(forceRepaint);
break;
}
case DrawingAreaLegacyMessage::DidUpdate:
didUpdate();
break;
default:
ASSERT_NOT_REACHED();
break;
}
}
}