diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 02:47:24 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 02:47:24 +0000 |
commit | 91e20036b8f64ca6fdf5f5c039f7e44f5aa39cbf (patch) | |
tree | 4d9be997f9719c3175cb0fd1a633238b8794723d | |
parent | a3b9f461cc5696349276e09c4c396a030ecab1e0 (diff) | |
download | chromium_src-91e20036b8f64ca6fdf5f5c039f7e44f5aa39cbf.zip chromium_src-91e20036b8f64ca6fdf5f5c039f7e44f5aa39cbf.tar.gz chromium_src-91e20036b8f64ca6fdf5f5c039f7e44f5aa39cbf.tar.bz2 |
Send GestureFlingStart and GestureFlingCancel when cmt sends them
BUG=114818
TEST=None
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=127606
Review URL: https://chromiumcodereview.appspot.com/9601022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127629 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.cc | 8 | ||||
-rw-r--r-- | content/browser/renderer_host/web_input_event_aura.cc | 21 | ||||
-rw-r--r-- | content/browser/renderer_host/web_input_event_aura.h | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/web_input_event_aurax11.cc | 26 | ||||
-rw-r--r-- | ui/aura/event.cc | 10 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.cc | 2 | ||||
-rw-r--r-- | ui/base/events.h | 14 | ||||
-rw-r--r-- | ui/base/win/events_win.cc | 10 | ||||
-rw-r--r-- | ui/base/x/events_x.cc | 122 |
9 files changed, 190 insertions, 24 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index cf9f28b..7f462cf 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -925,8 +925,12 @@ bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { } else if (event->type() == ui::ET_SCROLL) { WebKit::WebMouseWheelEvent mouse_wheel_event = content::MakeWebMouseWheelEvent(static_cast<aura::ScrollEvent*>(event)); - if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) - host_->ForwardWheelEvent(mouse_wheel_event); + host_->ForwardWheelEvent(mouse_wheel_event); + } else if (event->type() == ui::ET_SCROLL_FLING_START || + event->type() == ui::ET_SCROLL_FLING_CANCEL) { + WebKit::WebGestureEvent gesture_event = + content::MakeWebGestureEvent(static_cast<aura::ScrollEvent*>(event)); + host_->ForwardGestureEvent(gesture_event); } else if (CanRendererHandleEvent(event)) { WebKit::WebMouseEvent mouse_event = content::MakeWebMouseEvent(event); ModifyEventMovementAndCoords(&mouse_event); diff --git a/content/browser/renderer_host/web_input_event_aura.cc b/content/browser/renderer_host/web_input_event_aura.cc index a395fed..f9bd2ba 100644 --- a/content/browser/renderer_host/web_input_event_aura.cc +++ b/content/browser/renderer_host/web_input_event_aura.cc @@ -30,6 +30,8 @@ WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent( aura::KeyEvent* event); WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( aura::GestureEvent* event); +WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( + aura::ScrollEvent* event); WebKit::WebTouchPoint* UpdateWebTouchEventFromAuraEvent( aura::TouchEvent* event, WebKit::WebTouchEvent* web_event); #endif @@ -155,6 +157,25 @@ WebKit::WebGestureEvent MakeWebGestureEvent(aura::GestureEvent* event) { return gesture_event; } +WebKit::WebGestureEvent MakeWebGestureEvent(aura::ScrollEvent* event) { + WebKit::WebGestureEvent gesture_event; + +#if defined(OS_WIN) + gesture_event = MakeWebGestureEventFromNativeEvent(event->native_event()); +#else + gesture_event = MakeWebGestureEventFromAuraEvent(event); +#endif + + gesture_event.x = event->x(); + gesture_event.y = event->y(); + + const gfx::Point root_point = event->root_location(); + gesture_event.globalX = root_point.x(); + gesture_event.globalY = root_point.y(); + + return gesture_event; +} + WebKit::WebTouchPoint* UpdateWebTouchEvent(aura::TouchEvent* event, WebKit::WebTouchEvent* web_event) { #if defined(OS_WIN) diff --git a/content/browser/renderer_host/web_input_event_aura.h b/content/browser/renderer_host/web_input_event_aura.h index 40599ea..839c51d 100644 --- a/content/browser/renderer_host/web_input_event_aura.h +++ b/content/browser/renderer_host/web_input_event_aura.h @@ -23,6 +23,7 @@ WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::MouseEvent* event); WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::ScrollEvent* event); WebKit::WebKeyboardEvent MakeWebKeyboardEvent(aura::KeyEvent* event); WebKit::WebGestureEvent MakeWebGestureEvent(aura::GestureEvent* event); +WebKit::WebGestureEvent MakeWebGestureEvent(aura::ScrollEvent* event); // Updates the WebTouchEvent based on the TouchEvent. It returns the updated // WebTouchPoint contained in the WebTouchEvent, or NULL if no point was diff --git a/content/browser/renderer_host/web_input_event_aurax11.cc b/content/browser/renderer_host/web_input_event_aurax11.cc index 0729c28..63af7c8 100644 --- a/content/browser/renderer_host/web_input_event_aurax11.cc +++ b/content/browser/renderer_host/web_input_event_aurax11.cc @@ -250,6 +250,32 @@ WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( return webkit_event; } +WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( + aura::ScrollEvent* event) { + WebKit::WebGestureEvent webkit_event; + + switch (event->type()) { + case ui::ET_SCROLL: + webkit_event.type = WebKit::WebInputEvent::GestureScrollUpdate; + break; + case ui::ET_SCROLL_FLING_START: + webkit_event.type = WebKit::WebInputEvent::GestureFlingStart; + break; + case ui::ET_SCROLL_FLING_CANCEL: + webkit_event.type = WebKit::WebInputEvent::GestureFlingCancel; + break; + default: + NOTREACHED() << "Unknown gesture type: " << event->type(); + } + + webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); + webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); + webkit_event.deltaX = event->x_offset(); + webkit_event.deltaY = event->y_offset(); + + return webkit_event; +} + WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent( aura::KeyEvent* event) { base::NativeEvent native_event = event->native_event(); diff --git a/ui/aura/event.cc b/ui/aura/event.cc index c2a0510..37076dc 100644 --- a/ui/aura/event.cc +++ b/ui/aura/event.cc @@ -368,7 +368,14 @@ KeyEvent* KeyEvent::Copy() { ScrollEvent::ScrollEvent(const base::NativeEvent& native_event) : MouseEvent(native_event) { - ui::GetScrollOffsets(native_event, &x_offset_, &y_offset_); + if (type() == ui::ET_SCROLL) { + ui::GetScrollOffsets(native_event, &x_offset_, &y_offset_); + double start, end; + ui::GetGestureTimes(native_event, &start, &end); + } else if (type() == ui::ET_SCROLL_FLING_START) { + bool is_cancel; + ui::GetFlingData(native_event, &x_offset_, &y_offset_, &is_cancel); + } } GestureEvent::GestureEvent(ui::EventType type, @@ -381,7 +388,6 @@ GestureEvent::GestureEvent(ui::EventType type, : LocatedEvent(type, gfx::Point(x, y), gfx::Point(x, y), flags), delta_x_(delta_x), delta_y_(delta_y) { - // XXX: Why is aura::Event::time_stamp_ a TimeDelta instead of a Time? set_time_stamp(base::TimeDelta::FromSeconds(time_stamp.ToDoubleT())); } diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc index 3a91aea..8fa1cec 100644 --- a/ui/aura/root_window_host_linux.cc +++ b/ui/aura/root_window_host_linux.cc @@ -419,6 +419,8 @@ base::MessagePumpDispatcher::DispatchStatus RootWindowHostLinux::Dispatch( handled = root_window_->DispatchMouseEvent(&mouseev); break; } + case ui::ET_SCROLL_FLING_START: + case ui::ET_SCROLL_FLING_CANCEL: case ui::ET_SCROLL: { ScrollEvent scrollev(xev); handled = root_window_->DispatchScrollEvent(&scrollev); diff --git a/ui/base/events.h b/ui/base/events.h index 8d5b120..3f14254 100644 --- a/ui/base/events.h +++ b/ui/base/events.h @@ -40,7 +40,6 @@ enum EventType { ET_TOUCH_CANCELLED, ET_DROP_TARGET_EVENT, ET_FOCUS_CHANGE, - ET_SCROLL, ET_TRANSLATED_KEY_PRESS, ET_TRANSLATED_KEY_RELEASE, @@ -55,6 +54,12 @@ enum EventType { ET_GESTURE_PINCH_END, ET_GESTURE_PINCH_UPDATE, ET_GESTURE_LONG_PRESS, + + // Scroll support. + // TODO[davemoore] we need to unify these events w/ touch and gestures. + ET_SCROLL, + ET_SCROLL_FLING_START, + ET_SCROLL_FLING_CANCEL, }; // Event flags currently supported @@ -160,6 +165,13 @@ UI_EXPORT float GetTouchAngle(const base::NativeEvent& native_event); // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0. UI_EXPORT float GetTouchForce(const base::NativeEvent& native_event); +// Gets the fling velocity from a native event. is_cancel is set to true if +// this was a tap down, intended to stop an ongoing fling. +UI_EXPORT bool GetFlingData(const base::NativeEvent& native_event, + float* vx, + float* vy, + bool* is_cancel); + // Returns whether this is a scroll event and optionally gets the amount to be // scrolled. |x_offset| and |y_offset| can be NULL. UI_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event, diff --git a/ui/base/win/events_win.cc b/ui/base/win/events_win.cc index b0a8521..80fbe17 100644 --- a/ui/base/win/events_win.cc +++ b/ui/base/win/events_win.cc @@ -249,6 +249,16 @@ float GetTouchForce(const base::NativeEvent& native_event) { bool GetScrollOffsets(const base::NativeEvent& native_event, float* x_offset, float* y_offset) { + // Not supported in Windows. + NOTIMPLEMENTED(); + return false; +} + +bool GetFlingData(const base::NativeEvent& native_event, + float* vx, + float* vy, + bool* is_cancel) { + // Not supported in Windows. NOTIMPLEMENTED(); return false; } diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc index 7d69dc6..1674cd2 100644 --- a/ui/base/x/events_x.cc +++ b/ui/base/x/events_x.cc @@ -27,6 +27,11 @@ #define AXIS_LABEL_PROP_ABS_START_TIME "Abs Start Timestamp" #define AXIS_LABEL_PROP_ABS_END_TIME "Abs End Timestamp" +// Fling properties +#define AXIS_LABEL_PROP_ABS_FLING_X "Abs Fling X Velocity" +#define AXIS_LABEL_PROP_ABS_FLING_Y "Abs Fling Y Velocity" +#define AXIS_LABEL_PROP_ABS_FLING_STATE "Abs Fling State" + namespace { // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. @@ -64,6 +69,10 @@ class UI_EXPORT CMTEventData { Atom start_time = XInternAtom(display, AXIS_LABEL_PROP_ABS_START_TIME, false); Atom end_time = XInternAtom(display, AXIS_LABEL_PROP_ABS_END_TIME, false); + Atom fling_vx = XInternAtom(display, AXIS_LABEL_PROP_ABS_FLING_X, false); + Atom fling_vy = XInternAtom(display, AXIS_LABEL_PROP_ABS_FLING_Y, false); + Atom fling_state = + XInternAtom(display, AXIS_LABEL_PROP_ABS_FLING_STATE, false); for (int i = 0; i < count; ++i) { XIDeviceInfo* info = info_list + i; @@ -72,6 +81,7 @@ class UI_EXPORT CMTEventData { continue; Valuators valuators; + bool is_cmt = false; for (int j = 0; j < info->num_classes; ++j) { if (info->classes[j]->type != XIValuatorClass) continue; @@ -81,19 +91,30 @@ class UI_EXPORT CMTEventData { int number = v->number; if (number > valuators.max) valuators.max = number; - if (v->label == x_axis) - valuators.x_scroll = number; - else if (v->label == y_axis) - valuators.y_scroll = number; - else if (v->label == start_time) + if (v->label == x_axis) { + valuators.scroll_x = number; + is_cmt = true; + } else if (v->label == y_axis) { + valuators.scroll_y = number; + is_cmt = true; + } else if (v->label == start_time) { valuators.start_time = number; - else if (v->label == end_time) + is_cmt = true; + } else if (v->label == end_time) { valuators.end_time = number; + is_cmt = true; + } else if (v->label == fling_vx) { + valuators.fling_vx = number; + is_cmt = true; + } else if (v->label == fling_vy) { + valuators.fling_vy = number; + is_cmt = true; + } else if (v->label == fling_state) { + valuators.fling_state = number; + is_cmt = true; + } } - if (valuators.x_scroll >= 0 || - valuators.y_scroll >= 0 || - valuators.start_time >= 0 || - valuators.end_time >= 0) { + if (is_cmt) { device_to_valuators_[info->deviceid] = valuators; cmt_devices_[info->deviceid] = true; } @@ -116,8 +137,8 @@ class UI_EXPORT CMTEventData { return false; const Valuators v = device_to_valuators_[xiev->deviceid]; - bool has_x_offset = XIMaskIsSet(xiev->valuators.mask, v.x_scroll); - bool has_y_offset = XIMaskIsSet(xiev->valuators.mask, v.y_scroll); + bool has_x_offset = XIMaskIsSet(xiev->valuators.mask, v.scroll_x); + bool has_y_offset = XIMaskIsSet(xiev->valuators.mask, v.scroll_y); bool is_scroll = has_x_offset || has_y_offset; if (!is_scroll || (!x_offset && !y_offset)) @@ -126,9 +147,9 @@ class UI_EXPORT CMTEventData { double* valuators = xiev->valuators.values; for (int i = 0; i <= v.max; ++i) { if (XIMaskIsSet(xiev->valuators.mask, i)) { - if (x_offset && v.x_scroll == i) + if (x_offset && v.scroll_x == i) *x_offset = -(*valuators); - else if (y_offset && v.y_scroll == i) + else if (y_offset && v.scroll_y == i) *y_offset = -(*valuators); valuators++; } @@ -137,6 +158,44 @@ class UI_EXPORT CMTEventData { return true; } + bool GetFlingData(const XEvent& xev, + float* vx, float* vy, + bool* is_cancel) { + XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); + + *vx = 0; + *vy = 0; + *is_cancel = false; + + if (!cmt_devices_[xiev->deviceid]) + return false; + + const Valuators v = device_to_valuators_[xiev->deviceid]; + if (!XIMaskIsSet(xiev->valuators.mask, v.fling_vx) || + !XIMaskIsSet(xiev->valuators.mask, v.fling_vy) || + !XIMaskIsSet(xiev->valuators.mask, v.fling_state)) + return false; + + double* valuators = xiev->valuators.values; + for (int i = 0; i <= v.max; ++i) { + if (XIMaskIsSet(xiev->valuators.mask, i)) { + // Convert values to unsigned ints represending ms before storing them, + // as that is how they were encoded before conversion to doubles. + if (v.fling_vx == i) + *vx = + -static_cast<double>(static_cast<int>(*valuators)) / 1000; + else if (v.fling_vy == i) + *vy = + -static_cast<double>(static_cast<int>(*valuators)) / 1000; + else if (v.fling_state == i) + *is_cancel = !!static_cast<unsigned int>(*valuators); + valuators++; + } + } + + return true; + } + bool GetGestureTimes(const XEvent& xev, double* start_time, double* end_time) { @@ -176,13 +235,25 @@ class UI_EXPORT CMTEventData { struct Valuators { int max; - int x_scroll; - int y_scroll; + int scroll_x; + int scroll_y; int start_time; int end_time; + int fling_vx; + int fling_vy; + int fling_state; Valuators() - : max(-1), x_scroll(-1), y_scroll(-1), start_time(-1), end_time(-1) {} + : max(-1), + scroll_x(-1), + scroll_y(-1), + start_time(-1), + end_time(-1), + fling_vx(-1), + fling_vy(-1), + fling_state(-1) { + + } }; @@ -460,13 +531,18 @@ EventType EventTypeFromNative(const base::NativeEvent& native_event) { return xievent->evtype == XI_ButtonPress ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED; } - case XI_Motion: - if (GetScrollOffsets(native_event, NULL, NULL)) + case XI_Motion: { + float vx, vy; + bool is_cancel; + if (GetFlingData(native_event, &vx, &vy, &is_cancel)) { + return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; + } else if (GetScrollOffsets(native_event, NULL, NULL)) return ET_SCROLL; else if (GetButtonMaskForX2Event(xievent)) { return ET_MOUSE_DRAGGED; } else return ET_MOUSE_MOVED; + } } } default: @@ -721,6 +797,14 @@ bool GetScrollOffsets(const base::NativeEvent& native_event, *native_event, x_offset, y_offset); } +bool GetFlingData(const base::NativeEvent& native_event, + float* vx, + float* vy, + bool* is_cancel) { + return CMTEventData::GetInstance()->GetFlingData( + *native_event, vx, vy, is_cancel); +} + bool GetGestureTimes(const base::NativeEvent& native_event, double* start_time, double* end_time) { |