PageWidgetDelegate.cpp [plain text]
#include "config.h"
#include "PageWidgetDelegate.h"
#include "Frame.h"
#include "FrameView.h"
#include "PageOverlayList.h"
#include "WebInputEvent.h"
#include "WebInputEventConversion.h"
#include "painting/GraphicsContextBuilder.h"
#include <wtf/CurrentTime.h>
using namespace WebCore;
namespace WebKit {
static inline FrameView* mainFrameView(Page* page)
{
if (!page)
return 0;
if (!page->mainFrame())
return 0;
return page->mainFrame()->view();
}
void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime)
{
#if ENABLE(REQUEST_ANIMATION_FRAME)
FrameView* view = mainFrameView(page);
if (!view)
return;
double timeShift = currentTime() - monotonicallyIncreasingTime();
view->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(monotonicFrameBeginTime + timeShift));
#endif
}
void PageWidgetDelegate::layout(Page* page)
{
FrameView* view = mainFrameView(page);
if (!view)
return;
view->setFrameRect(view->frameRect());
view->updateLayoutAndStyleIfNeededRecursive();
}
void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect)
{
if (rect.isEmpty())
return;
GraphicsContextBuilder builder(canvas);
GraphicsContext& gc = builder.context();
IntRect dirtyRect(rect);
gc.save();
FrameView* view = mainFrameView(page);
if (view && page->mainFrame()->document()) {
gc.clip(dirtyRect);
view->paint(&gc, dirtyRect);
if (overlays)
overlays->paintWebFrame(gc);
} else
gc.fillRect(dirtyRect, Color::white, ColorSpaceDeviceRGB);
gc.restore();
}
bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& handler, const WebInputEvent& event)
{
Frame* frame = page ? page->mainFrame() : 0;
switch (event.type) {
case WebInputEvent::MouseMove:
if (!frame || !frame->view())
return true;
handler.handleMouseMove(*frame, *static_cast<const WebMouseEvent*>(&event));
return true;
case WebInputEvent::MouseLeave:
if (!frame || !frame->view())
return true;
handler.handleMouseLeave(*frame, *static_cast<const WebMouseEvent*>(&event));
return true;
case WebInputEvent::MouseDown:
if (!frame || !frame->view())
return true;
handler.handleMouseDown(*frame, *static_cast<const WebMouseEvent*>(&event));
return true;
case WebInputEvent::MouseUp:
if (!frame || !frame->view())
return true;
handler.handleMouseUp(*frame, *static_cast<const WebMouseEvent*>(&event));
return true;
case WebInputEvent::MouseWheel:
if (!frame || !frame->view())
return false;
return handler.handleMouseWheel(*frame, *static_cast<const WebMouseWheelEvent*>(&event));
case WebInputEvent::RawKeyDown:
case WebInputEvent::KeyDown:
case WebInputEvent::KeyUp:
return handler.handleKeyEvent(*static_cast<const WebKeyboardEvent*>(&event));
case WebInputEvent::Char:
return handler.handleCharEvent(*static_cast<const WebKeyboardEvent*>(&event));
#if ENABLE(GESTURE_EVENTS)
case WebInputEvent::GestureScrollBegin:
case WebInputEvent::GestureScrollEnd:
case WebInputEvent::GestureScrollUpdate:
case WebInputEvent::GestureFlingStart:
case WebInputEvent::GestureFlingCancel:
case WebInputEvent::GestureTap:
case WebInputEvent::GestureTapDown:
case WebInputEvent::GestureDoubleTap:
return handler.handleGestureEvent(*static_cast<const WebGestureEvent*>(&event));
#endif
#if ENABLE(TOUCH_EVENTS)
case WebInputEvent::TouchStart:
case WebInputEvent::TouchMove:
case WebInputEvent::TouchEnd:
case WebInputEvent::TouchCancel:
if (!frame || !frame->view())
return false;
return handler.handleTouchEvent(*frame, *static_cast<const WebTouchEvent*>(&event));
#endif
#if ENABLE(GESTURE_EVENTS)
case WebInputEvent::GesturePinchBegin:
case WebInputEvent::GesturePinchEnd:
case WebInputEvent::GesturePinchUpdate:
return false;
#endif
default:
return false;
}
}
void PageWidgetEventHandler::handleMouseMove(Frame& mainFrame, const WebMouseEvent& event)
{
mainFrame.eventHandler()->mouseMoved(PlatformMouseEventBuilder(mainFrame.view(), event));
}
void PageWidgetEventHandler::handleMouseLeave(Frame& mainFrame, const WebMouseEvent& event)
{
mainFrame.eventHandler()->handleMouseMoveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
}
void PageWidgetEventHandler::handleMouseDown(Frame& mainFrame, const WebMouseEvent& event)
{
mainFrame.eventHandler()->handleMousePressEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
}
void PageWidgetEventHandler::handleMouseUp(Frame& mainFrame, const WebMouseEvent& event)
{
mainFrame.eventHandler()->handleMouseReleaseEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
}
bool PageWidgetEventHandler::handleMouseWheel(Frame& mainFrame, const WebMouseWheelEvent& event)
{
return mainFrame.eventHandler()->handleWheelEvent(PlatformWheelEventBuilder(mainFrame.view(), event));
}
#if ENABLE(TOUCH_EVENTS)
bool PageWidgetEventHandler::handleTouchEvent(Frame& mainFrame, const WebTouchEvent& event)
{
return mainFrame.eventHandler()->handleTouchEvent(PlatformTouchEventBuilder(mainFrame.view(), event));
}
#endif
}