summaryrefslogtreecommitdiffstats
path: root/WebKit/chromium/src/WebInputEventConversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/chromium/src/WebInputEventConversion.cpp')
-rw-r--r--WebKit/chromium/src/WebInputEventConversion.cpp102
1 files changed, 97 insertions, 5 deletions
diff --git a/WebKit/chromium/src/WebInputEventConversion.cpp b/WebKit/chromium/src/WebInputEventConversion.cpp
index 147f88b..24eb372 100644
--- a/WebKit/chromium/src/WebInputEventConversion.cpp
+++ b/WebKit/chromium/src/WebInputEventConversion.cpp
@@ -40,6 +40,7 @@
#include "PlatformWheelEvent.h"
#include "ScrollView.h"
#include "WebInputEvent.h"
+#include "WheelEvent.h"
#include "Widget.h"
using namespace WebCore;
@@ -103,7 +104,7 @@ PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
// MakePlatformKeyboardEvent --------------------------------------------------
-static inline const PlatformKeyboardEvent::Type toPlatformKeyboardEventType(WebInputEvent::Type type)
+static inline PlatformKeyboardEvent::Type toPlatformKeyboardEventType(WebInputEvent::Type type)
{
switch (type) {
case WebInputEvent::KeyUp:
@@ -168,6 +169,64 @@ bool PlatformKeyboardEventBuilder::isCharacterKey() const
return true;
}
+#if ENABLE(TOUCH_EVENTS)
+static inline TouchEventType toPlatformTouchEventType(const WebInputEvent::Type type)
+{
+ switch (type) {
+ case WebInputEvent::TouchStart:
+ return TouchStart;
+ case WebInputEvent::TouchMove:
+ return TouchMove;
+ case WebInputEvent::TouchEnd:
+ return TouchEnd;
+ case WebInputEvent::TouchCancel:
+ return TouchCancel;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return TouchStart;
+}
+
+static inline PlatformTouchPoint::State toPlatformTouchPointState(const WebTouchPoint::State state)
+{
+ switch (state) {
+ case WebTouchPoint::StateReleased:
+ return PlatformTouchPoint::TouchReleased;
+ case WebTouchPoint::StatePressed:
+ return PlatformTouchPoint::TouchPressed;
+ case WebTouchPoint::StateMoved:
+ return PlatformTouchPoint::TouchMoved;
+ case WebTouchPoint::StateStationary:
+ return PlatformTouchPoint::TouchStationary;
+ case WebTouchPoint::StateCancelled:
+ return PlatformTouchPoint::TouchCancelled;
+ case WebTouchPoint::StateUndefined:
+ ASSERT_NOT_REACHED();
+ }
+ return PlatformTouchPoint::TouchReleased;
+}
+
+PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTouchPoint& point)
+{
+ m_id = point.id;
+ m_state = toPlatformTouchPointState(point.state);
+ m_pos = widget->convertFromContainingWindow(point.position);
+ m_screenPos = point.screenPosition;
+}
+
+PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTouchEvent& event)
+{
+ m_type = toPlatformTouchEventType(event.type);
+ m_ctrlKey = event.modifiers & WebInputEvent::ControlKey;
+ m_altKey = event.modifiers & WebInputEvent::AltKey;
+ m_shiftKey = event.modifiers & WebInputEvent::ShiftKey;
+ m_metaKey = event.modifiers & WebInputEvent::MetaKey;
+
+ for (int i = 0; i < event.touchPointsLength; ++i)
+ m_touchPoints.append(PlatformTouchPointBuilder(widget, event.touchPoints[i]));
+}
+#endif
+
static int getWebInputModifiers(const UIEventWithKeyState& event)
{
int modifiers = 0;
@@ -182,7 +241,7 @@ static int getWebInputModifiers(const UIEventWithKeyState& event)
return modifiers;
}
-WebMouseEventBuilder::WebMouseEventBuilder(const ScrollView* view, const MouseEvent& event)
+WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const MouseEvent& event)
{
if (event.type() == eventNames().mousemoveEvent)
type = WebInputEvent::MouseMove;
@@ -194,6 +253,8 @@ WebMouseEventBuilder::WebMouseEventBuilder(const ScrollView* view, const MouseEv
type = WebInputEvent::MouseDown;
else if (event.type() == eventNames().mouseupEvent)
type = WebInputEvent::MouseUp;
+ else if (event.type() == eventNames().contextmenuEvent)
+ type = WebInputEvent::ContextMenu;
else
return; // Skip all other mouse events.
timeStampSeconds = event.timeStamp() * 1.0e-3;
@@ -222,16 +283,42 @@ WebMouseEventBuilder::WebMouseEventBuilder(const ScrollView* view, const MouseEv
break;
}
}
- IntPoint p = view->contentsToWindow(IntPoint(event.pageX(), event.pageY()));
+ ScrollView* view = widget->parent();
+ IntPoint p = view->contentsToWindow(
+ IntPoint(event.absoluteLocation().x(), event.absoluteLocation().y()));
globalX = event.screenX();
globalY = event.screenY();
windowX = p.x();
windowY = p.y();
- x = event.offsetX();
- y = event.offsetY();
+ x = event.absoluteLocation().x() - widget->pos().x();
+ y = event.absoluteLocation().y() - widget->pos().y();
clickCount = event.detail();
}
+WebMouseWheelEventBuilder::WebMouseWheelEventBuilder(const Widget* widget, const WheelEvent& event)
+{
+ if (event.type() != eventNames().mousewheelEvent)
+ return;
+ type = WebInputEvent::MouseWheel;
+ timeStampSeconds = event.timeStamp() * 1.0e-3;
+ modifiers = getWebInputModifiers(event);
+ ScrollView* view = widget->parent();
+ IntPoint p = view->contentsToWindow(
+ IntPoint(event.absoluteLocation().x(), event.absoluteLocation().y()));
+ globalX = event.screenX();
+ globalY = event.screenY();
+ windowX = p.x();
+ windowY = p.y();
+ x = event.absoluteLocation().x() - widget->pos().x();
+ y = event.absoluteLocation().y() - widget->pos().y();
+ deltaX = static_cast<float>(event.rawDeltaX());
+ deltaY = static_cast<float>(event.rawDeltaY());
+ // The 120 is from WheelEvent::initWheelEvent().
+ wheelTicksX = static_cast<float>(event.wheelDeltaX()) / 120;
+ wheelTicksY = static_cast<float>(event.wheelDeltaY()) / 120;
+ scrollByPage = event.granularity() == WheelEvent::Page;
+}
+
WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event)
{
if (event.type() == eventNames().keydownEvent)
@@ -245,6 +332,11 @@ WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event)
modifiers = getWebInputModifiers(event);
timeStampSeconds = event.timeStamp() * 1.0e-3;
windowsKeyCode = event.keyCode();
+
+ // The platform keyevent does not exist if the event was created using
+ // initKeyboardEvent.
+ if (!event.keyEvent())
+ return;
nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode();
unsigned int numChars = std::min(event.keyEvent()->text().length(),
static_cast<unsigned int>(WebKeyboardEvent::textLengthCap));