diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 15:33:05 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 15:33:05 +0000 |
commit | 557fc133e3713b8d711116446b0cea32b8e4435c (patch) | |
tree | 6fe1f9ee9a16bcbd0deb36bc18fcb14c5ef38cf5 /views/events | |
parent | acefdfb19563346ddd4a6831c9a3ecc938db8a96 (diff) | |
download | chromium_src-557fc133e3713b8d711116446b0cea32b8e4435c.zip chromium_src-557fc133e3713b8d711116446b0cea32b8e4435c.tar.gz chromium_src-557fc133e3713b8d711116446b0cea32b8e4435c.tar.bz2 |
event: Create a mouse event out of a touch event.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6931050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84787 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/events')
-rw-r--r-- | views/events/event.h | 15 | ||||
-rw-r--r-- | views/events/event_x.cc | 46 |
2 files changed, 59 insertions, 2 deletions
diff --git a/views/events/event.h b/views/events/event.h index 88b4693..5ede973 100644 --- a/views/events/event.h +++ b/views/events/event.h @@ -105,6 +105,8 @@ class Event { flags_(model.flags()) { } + void set_type(ui::EventType type) { type_ = type; } + private: void operator=(const Event&); @@ -154,6 +156,10 @@ class LocatedEvent : public Event { gfx::Point location_; }; +#if defined(TOUCH_UI) +class TouchEvent; +#endif + //////////////////////////////////////////////////////////////////////////////// // // MouseEvent class @@ -171,6 +177,15 @@ class MouseEvent : public LocatedEvent { // from |source| coordinate system to |target| coordinate system. MouseEvent(const MouseEvent& model, View* source, View* target); +#if defined(TOUCH_UI) + // Creates a new MouseEvent from a TouchEvent. The location of the TouchEvent + // is the same as the MouseEvent. Other attributes (e.g. type, flags) are + // mapped from the TouchEvent to appropriate MouseEvent attributes. + // GestureManager uses this to convert TouchEvents that are not handled by any + // view. + MouseEvent(const TouchEvent& touch, FromNativeEvent2 from_native); +#endif + // TODO(msw): Kill this legacy constructor when we update uses. // Create a new mouse event MouseEvent(ui::EventType type, int x, int y, int flags) diff --git a/views/events/event_x.cc b/views/events/event_x.cc index 74b6ca3..332a80f 100644 --- a/views/events/event_x.cc +++ b/views/events/event_x.cc @@ -97,7 +97,6 @@ ui::EventType GetTouchEventType(XEvent* xev) { if (!factory->IsSlotUsed(slot)) { // This is a new touch point. - factory->SetSlotUsed(slot, true); return ui::ET_TOUCH_PRESSED; } @@ -108,7 +107,6 @@ ui::EventType GetTouchEventType(XEvent* xev) { if (tracking == 0l) { // The touch point has been released. - factory->SetSlotUsed(slot, false); return ui::ET_TOUCH_RELEASED; } @@ -370,6 +368,42 @@ MouseEvent::MouseEvent(NativeEvent2 native_event_2, : LocatedEvent(native_event_2, from_native) { } +MouseEvent::MouseEvent(const TouchEvent& touch, + FromNativeEvent2 from_native) + : LocatedEvent(touch.native_event_2(), from_native) { + // The location of the event is correctly extracted from the native event. But + // it is necessary to update the event type. + ui::EventType mtype = ui::ET_UNKNOWN; + switch (touch.type()) { + case ui::ET_TOUCH_RELEASED: + mtype = ui::ET_MOUSE_RELEASED; + break; + case ui::ET_TOUCH_PRESSED: + mtype = ui::ET_MOUSE_PRESSED; + break; + case ui::ET_TOUCH_MOVED: + mtype = ui::ET_MOUSE_MOVED; + break; + default: + NOTREACHED() << "Invalid mouse event."; + } + set_type(mtype); + + // It may not be possible to extract the button-information necessary for a + // MouseEvent from the native event for a TouchEvent, so the flags are + // explicitly updated as well. The button is approximated from the touchpoint + // identity. + int new_flags = flags() & ~(ui::EF_LEFT_BUTTON_DOWN | + ui::EF_RIGHT_BUTTON_DOWN | + ui::EF_MIDDLE_BUTTON_DOWN); + int button = ui::EF_LEFT_BUTTON_DOWN; + if (touch.identity() == 1) + button = ui::EF_RIGHT_BUTTON_DOWN; + else if (touch.identity() == 2) + button = ui::EF_MIDDLE_BUTTON_DOWN; + set_flags(new_flags | button); +} + //////////////////////////////////////////////////////////////////////////////// // MouseWheelEvent, public: @@ -390,6 +424,14 @@ TouchEvent::TouchEvent(NativeEvent2 native_event_2, radius_(GetTouchRadiusFromXEvent(native_event_2)), angle_(GetTouchAngleFromXEvent(native_event_2)), ratio_(GetTouchRatioFromXEvent(native_event_2)) { + if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { + TouchFactory* factory = TouchFactory::GetInstance(); + float slot; + if (factory->ExtractTouchParam(*native_event_2, + TouchFactory::TP_SLOT_ID, &slot)) { + factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); + } + } } #endif |