Index: views/events/event_x.cc |
diff --git a/views/events/event_x.cc b/views/events/event_x.cc |
index 1f54303e6b30ca1533e295e2336fc2fee3361d31..d3301fb93169c40ed570b8b88fb944900b52aacf 100644 |
--- a/views/events/event_x.cc |
+++ b/views/events/event_x.cc |
@@ -12,213 +12,21 @@ |
#include "base/logging.h" |
#include "base/utf_string_conversions.h" |
#include "ui/base/keycodes/keyboard_code_conversion_x.h" |
-#include "views/touchui/touch_factory.h" |
+#include "ui/base/touchui/touch_factory.h" |
#include "views/widget/root_view.h" |
namespace views { |
namespace { |
-// Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. |
-static int kWheelScrollAmount = 53; |
- |
-int GetEventFlagsFromXState(unsigned int state) { |
- int flags = 0; |
- if (state & ControlMask) |
- flags |= ui::EF_CONTROL_DOWN; |
- if (state & ShiftMask) |
- flags |= ui::EF_SHIFT_DOWN; |
- if (state & Mod1Mask) |
- flags |= ui::EF_ALT_DOWN; |
- if (state & LockMask) |
- flags |= ui::EF_CAPS_LOCK_DOWN; |
- if (state & Button1Mask) |
- flags |= ui::EF_LEFT_BUTTON_DOWN; |
- if (state & Button2Mask) |
- flags |= ui::EF_MIDDLE_BUTTON_DOWN; |
- if (state & Button3Mask) |
- flags |= ui::EF_RIGHT_BUTTON_DOWN; |
- |
- return flags; |
-} |
- |
-// Get the event flag for the button in XButtonEvent. During a ButtonPress |
-// event, |state| in XButtonEvent does not include the button that has just been |
-// pressed. Instead |state| contains flags for the buttons (if any) that had |
-// already been pressed before the current button, and |button| stores the most |
-// current pressed button. So, if you press down left mouse button, and while |
-// pressing it down, press down the right mouse button, then for the latter |
-// event, |state| would have Button1Mask set but not Button3Mask, and |button| |
-// would be 3. |
-int GetEventFlagsForButton(int button) { |
- switch (button) { |
- case 1: |
- return ui::EF_LEFT_BUTTON_DOWN; |
- case 2: |
- return ui::EF_MIDDLE_BUTTON_DOWN; |
- case 3: |
- return ui::EF_RIGHT_BUTTON_DOWN; |
- } |
- |
- DLOG(WARNING) << "Unexpected button (" << button << ") received."; |
- return 0; |
-} |
- |
-int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { |
- int buttonflags = 0; |
- |
- for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { |
- if (XIMaskIsSet(xievent->buttons.mask, i)) { |
- buttonflags |= GetEventFlagsForButton(i); |
- } |
- } |
- |
- return buttonflags; |
-} |
- |
-ui::EventType GetTouchEventType(XEvent* xev) { |
- XGenericEventCookie* cookie = &xev->xcookie; |
- DCHECK_EQ(cookie->evtype, XI_Motion); |
- |
- // Note: We will not generate a _STATIONARY event here. It will be created, |
- // when necessary, by a RWHVV. |
- // TODO(sad): When should _CANCELLED be generated? |
- |
- TouchFactory* factory = TouchFactory::GetInstance(); |
- float slot; |
- if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot)) |
- return ui::ET_UNKNOWN; |
- |
- if (!factory->IsSlotUsed(slot)) { |
- // This is a new touch point. |
- return ui::ET_TOUCH_PRESSED; |
- } |
- |
- float tracking; |
- if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID, |
- &tracking)) |
- return ui::ET_UNKNOWN; |
- |
- if (tracking == 0l) { |
- // The touch point has been released. |
- return ui::ET_TOUCH_RELEASED; |
- } |
- |
- return ui::ET_TOUCH_MOVED; |
-} |
- |
int GetTouchIDFromXEvent(XEvent* xev) { |
float slot = 0; |
- if (!TouchFactory::GetInstance()->ExtractTouchParam( |
- *xev, TouchFactory::TP_SLOT_ID, &slot)) |
+ if (!ui::TouchFactory::GetInstance()->ExtractTouchParam( |
+ *xev, ui::TouchFactory::TP_SLOT_ID, &slot)) |
LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; |
return slot; |
} |
-ui::EventType EventTypeFromNative(NativeEvent2 native_event) { |
- switch (native_event->type) { |
- case KeyPress: |
- return ui::ET_KEY_PRESSED; |
- case KeyRelease: |
- return ui::ET_KEY_RELEASED; |
- case ButtonPress: |
- if (native_event->xbutton.button == 4 || |
- native_event->xbutton.button == 5) |
- return ui::ET_MOUSEWHEEL; |
- return ui::ET_MOUSE_PRESSED; |
- case ButtonRelease: |
- if (native_event->xbutton.button == 4 || |
- native_event->xbutton.button == 5) |
- return ui::ET_MOUSEWHEEL; |
- return ui::ET_MOUSE_RELEASED; |
- case MotionNotify: |
- if (native_event->xmotion.state & |
- (Button1Mask | Button2Mask | Button3Mask)) |
- return ui::ET_MOUSE_DRAGGED; |
- return ui::ET_MOUSE_MOVED; |
- case GenericEvent: { |
- XIDeviceEvent* xievent = |
- static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
- if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) |
- return GetTouchEventType(native_event); |
- switch (xievent->evtype) { |
- case XI_ButtonPress: |
- return (xievent->detail == 4 || xievent->detail == 5) ? |
- ui::ET_MOUSEWHEEL : ui::ET_MOUSE_PRESSED; |
- case XI_ButtonRelease: |
- return (xievent->detail == 4 || xievent->detail == 5) ? |
- ui::ET_MOUSEWHEEL : ui::ET_MOUSE_RELEASED; |
- case XI_Motion: |
- return GetButtonMaskForX2Event(xievent) ? ui::ET_MOUSE_DRAGGED : |
- ui::ET_MOUSE_MOVED; |
- } |
- } |
- default: |
- NOTREACHED(); |
- break; |
- } |
- return ui::ET_UNKNOWN; |
-} |
- |
-int GetMouseWheelOffset(XEvent* xev) { |
- if (xev->type == GenericEvent) { |
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
- return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount; |
- } |
- return xev->xbutton.button == 4 ? kWheelScrollAmount : -kWheelScrollAmount; |
-} |
- |
-gfx::Point GetEventLocation(XEvent* xev) { |
- switch (xev->type) { |
- case ButtonPress: |
- case ButtonRelease: |
- return gfx::Point(xev->xbutton.x, xev->xbutton.y); |
- |
- case MotionNotify: |
- return gfx::Point(xev->xmotion.x, xev->xmotion.y); |
- |
- case GenericEvent: { |
- XIDeviceEvent* xievent = |
- static_cast<XIDeviceEvent*>(xev->xcookie.data); |
- return gfx::Point(static_cast<int>(xievent->event_x), |
- static_cast<int>(xievent->event_y)); |
- } |
- } |
- |
- return gfx::Point(); |
-} |
- |
-int GetLocatedEventFlags(XEvent* xev) { |
- switch (xev->type) { |
- case ButtonPress: |
- case ButtonRelease: |
- return GetEventFlagsFromXState(xev->xbutton.state) | |
- GetEventFlagsForButton(xev->xbutton.button); |
- |
- case MotionNotify: |
- return GetEventFlagsFromXState(xev->xmotion.state); |
- |
- case GenericEvent: { |
- XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
- bool touch = |
- TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); |
- switch (xievent->evtype) { |
- case XI_ButtonPress: |
- case XI_ButtonRelease: |
- return GetButtonMaskForX2Event(xievent) | |
- GetEventFlagsFromXState(xievent->mods.effective) | |
- (touch ? 0 : GetEventFlagsForButton(xievent->detail)); |
- |
- case XI_Motion: |
- return GetButtonMaskForX2Event(xievent) | |
- GetEventFlagsFromXState(xievent->mods.effective); |
- } |
- } |
- } |
- |
- return 0; |
-} |
- |
uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { |
char buf[6]; |
int bytes_written = XLookupString(key, buf, 6, NULL, NULL); |
@@ -230,20 +38,20 @@ uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { |
} |
float GetTouchParamFromXEvent(XEvent* xev, |
- TouchFactory::TouchParam tp, |
+ ui::TouchFactory::TouchParam tp, |
float default_value) { |
- TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); |
+ ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); |
return default_value; |
} |
float GetTouchForceFromXEvent(XEvent* xev) { |
float force = 0.0; |
- force = GetTouchParamFromXEvent(xev, TouchFactory::TP_PRESSURE, 0.0); |
+ force = GetTouchParamFromXEvent(xev, ui::TouchFactory::TP_PRESSURE, 0.0); |
unsigned int deviceid = |
static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid; |
// Force is normalized to fall into [0, 1] |
- if (!TouchFactory::GetInstance()->NormalizeTouchParam( |
- deviceid, TouchFactory::TP_PRESSURE, &force)) |
+ if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( |
+ deviceid, ui::TouchFactory::TP_PRESSURE, &force)) |
force = 0.0; |
return force; |
} |
@@ -257,7 +65,7 @@ uint16 GetCharacterFromGdkKeyval(guint keyval) { |
return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; |
} |
-GdkEventKey* GetGdkEventKeyFromNative(NativeEvent native_event) { |
+GdkEventKey* GetGdkEventKeyFromNative(const ui::NativeEvent& native_event) { |
DCHECK(native_event->type == GDK_KEY_PRESS || |
native_event->type == GDK_KEY_RELEASE); |
return &native_event->key; |
@@ -268,7 +76,7 @@ GdkEventKey* GetGdkEventKeyFromNative(NativeEvent native_event) { |
//////////////////////////////////////////////////////////////////////////////// |
// Event, private: |
-void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, |
+void Event::InitWithNativeEvent2(const ui::NativeEvent2& native_event_2, |
FromNativeEvent2) { |
native_event_ = NULL; |
// TODO(beng): remove once we rid views of Gtk/Gdk. |
@@ -278,24 +86,25 @@ void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, |
//////////////////////////////////////////////////////////////////////////////// |
// LocatedEvent, protected: |
-LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, |
+LocatedEvent::LocatedEvent(const ui::NativeEvent2& native_event_2, |
FromNativeEvent2 from_native) |
: Event(native_event_2, |
- EventTypeFromNative(native_event_2), |
- GetLocatedEventFlags(native_event_2), |
+ ui::EventTypeFromNative(native_event_2), |
+ ui::EventFlagsFromNative(native_event_2), |
from_native), |
- location_(GetEventLocation(native_event_2)) { |
+ location_(ui::EventLocationFromNative(native_event_2)) { |
} |
//////////////////////////////////////////////////////////////////////////////// |
// KeyEvent, public: |
-KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) |
+KeyEvent::KeyEvent(const ui::NativeEvent2& native_event_2, |
+ FromNativeEvent2 from_native) |
: Event(native_event_2, |
- EventTypeFromNative(native_event_2), |
- GetEventFlagsFromXState(native_event_2->xkey.state), |
+ ui::EventTypeFromNative(native_event_2), |
+ ui::EventFlagsFromNative(native_event_2), |
from_native), |
- key_code_(ui::KeyboardCodeFromXKeyEvent(native_event_2)), |
+ key_code_(ui::KeyboardCodeFromNative(native_event_2)), |
character_(0), |
unmodified_character_(0) { |
} |
@@ -372,7 +181,7 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const { |
//////////////////////////////////////////////////////////////////////////////// |
// MouseEvent, public: |
-MouseEvent::MouseEvent(NativeEvent2 native_event_2, |
+MouseEvent::MouseEvent(const ui::NativeEvent2& native_event_2, |
FromNativeEvent2 from_native) |
: LocatedEvent(native_event_2, from_native) { |
} |
@@ -380,34 +189,34 @@ MouseEvent::MouseEvent(NativeEvent2 native_event_2, |
//////////////////////////////////////////////////////////////////////////////// |
// MouseWheelEvent, public: |
-MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, |
+MouseWheelEvent::MouseWheelEvent(const ui::NativeEvent2& native_event_2, |
FromNativeEvent2 from_native) |
: MouseEvent(native_event_2, from_native), |
- offset_(GetMouseWheelOffset(native_event_2)) { |
+ offset_(ui::GetMouseWheelOffset(native_event_2)) { |
} |
//////////////////////////////////////////////////////////////////////////////// |
// TouchEvent, public: |
-TouchEvent::TouchEvent(NativeEvent2 native_event_2, |
+TouchEvent::TouchEvent(const ui::NativeEvent2& native_event_2, |
FromNativeEvent2 from_native) |
: LocatedEvent(native_event_2, from_native), |
touch_id_(GetTouchIDFromXEvent(native_event_2)), |
radius_x_(GetTouchParamFromXEvent(native_event_2, |
- TouchFactory::TP_TOUCH_MAJOR, |
+ ui::TouchFactory::TP_TOUCH_MAJOR, |
2.0) / 2.0), |
radius_y_(GetTouchParamFromXEvent(native_event_2, |
- TouchFactory::TP_TOUCH_MINOR, |
+ ui::TouchFactory::TP_TOUCH_MINOR, |
2.0) / 2.0), |
rotation_angle_(GetTouchParamFromXEvent(native_event_2, |
- TouchFactory::TP_ORIENTATION, |
+ ui::TouchFactory::TP_ORIENTATION, |
0.0)), |
force_(GetTouchForceFromXEvent(native_event_2)) { |
if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
- TouchFactory* factory = TouchFactory::GetInstance(); |
+ ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
float slot; |
if (factory->ExtractTouchParam(*native_event_2, |
- TouchFactory::TP_SLOT_ID, &slot)) { |
+ ui::TouchFactory::TP_SLOT_ID, &slot)) { |
factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
} |
} |