diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 22:04:44 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 22:04:44 +0000 |
commit | a3e2de75e309b527cd694b16d23100bbec1710d9 (patch) | |
tree | 30f49027fbf74758595ee30b0b301206a4c2becf /views | |
parent | e30e4d816f7e32f2be39f32159e020d3b037de04 (diff) | |
download | chromium_src-a3e2de75e309b527cd694b16d23100bbec1710d9.zip chromium_src-a3e2de75e309b527cd694b16d23100bbec1710d9.tar.gz chromium_src-a3e2de75e309b527cd694b16d23100bbec1710d9.tar.bz2 |
Consolidate/cleanup event cracking code; single out GdkEvents; saves ~850 lines.
Move ui::NativeEvent typdefs and common functions to ui/base/events.h.
Remove NativeEvent2 typedef, single out GdkEvent* uses that should be removed.
Implement platform specific ui/base/[platform]/events_[platform].cc.
Revise views::NativeEvent definitions (to support Aura abstraction).
Consolidate Event[Type/Flags/Location]FromNative(), GetMouseWheelOffset(), etc.
Remove GetRepeatCount(), GetWindowsFlags(), IsExtendedKey(), etc.
Add IsMouseEvent(), KeyboardCodeFromNative(), EF_EXTENDED flag, etc.
Localize GetFlagsFromGdkEvent(), move some file locals to new helpers files.
Move views/touchui/touch_factory.h|cc to ui/base/touch.
Stop mixing Windows mouse events' MK_*BUTTON into their wParams.
BUG=93945
TEST=No build breaks (many configs...), no mouse/key behavior changes.
Review URL: http://codereview.chromium.org/7942004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu_controller.cc | 2 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 4 | ||||
-rw-r--r-- | views/events/event.cc | 70 | ||||
-rw-r--r-- | views/events/event.h | 99 | ||||
-rw-r--r-- | views/events/event_aura.cc | 91 | ||||
-rw-r--r-- | views/events/event_gtk.cc | 214 | ||||
-rw-r--r-- | views/events/event_utils_win.cc | 31 | ||||
-rw-r--r-- | views/events/event_utils_win.h | 34 | ||||
-rw-r--r-- | views/events/event_wayland.cc | 193 | ||||
-rw-r--r-- | views/events/event_win.cc | 288 | ||||
-rw-r--r-- | views/events/event_x.cc | 387 | ||||
-rw-r--r-- | views/focus/accelerator_handler_touch.cc | 30 | ||||
-rw-r--r-- | views/ime/input_method_gtk.cc | 6 | ||||
-rw-r--r-- | views/ime/input_method_ibus.cc | 15 | ||||
-rw-r--r-- | views/native_types.h | 66 | ||||
-rw-r--r-- | views/touchui/gesture_manager.cc | 3 | ||||
-rw-r--r-- | views/touchui/touch_factory.cc | 502 | ||||
-rw-r--r-- | views/touchui/touch_factory.h | 206 | ||||
-rw-r--r-- | views/views.gyp | 12 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 18 |
20 files changed, 323 insertions, 1948 deletions
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 1255610..8d94a02 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -1826,7 +1826,7 @@ void MenuController::RepostEvent(SubmenuView* source, if (event_type) { if (in_client_area) { - PostMessage(window, event_type, event.GetWindowsFlags(), + PostMessage(window, event_type, event.native_event().wParam, MAKELPARAM(window_x, window_y)); } else { PostMessage(window, event_type, nc_hit_result, diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index 148430a..e884e70 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -30,7 +30,6 @@ // ViewHierarchyChanged is removed. #include "views/controls/textfield/native_textfield_views.h" #include "views/controls/textfield/native_textfield_win.h" -#include "views/events/event_utils_win.h" #endif namespace views { @@ -341,7 +340,8 @@ bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { // We don't translate accelerators for ALT + NumPad digit on Windows, they are // used for entering special characters. We do translate alt-home. if (e.IsAltDown() && (key != ui::VKEY_HOME) && - NativeTextfieldWin::IsNumPadDigit(key, IsExtendedKey(e))) + NativeTextfieldWin::IsNumPadDigit(key, + (e.flags() & ui::EF_EXTENDED) != 0)) return true; #endif return false; diff --git a/views/events/event.cc b/views/events/event.cc index a8db132..c9cfecc 100644 --- a/views/events/event.cc +++ b/views/events/event.cc @@ -17,36 +17,45 @@ Event::Event(ui::EventType type, int flags) : type_(type), time_stamp_(base::Time::NowFromSystemTime()), flags_(flags) { - Init(); + // Safely initialize the pointer/struct to null/empty. + memset(&native_event_, 0, sizeof(native_event_)); +#if defined(TOOLKIT_USES_GTK) + gdk_event_ = NULL; +#endif } -Event::Event(NativeEvent native_event, ui::EventType type, int flags) - : type_(type), - time_stamp_(base::Time::NowFromSystemTime()), - flags_(flags) { - InitWithNativeEvent(native_event); -} - -Event::Event(NativeEvent2 native_event_2, ui::EventType type, int flags, - FromNativeEvent2 from_native) - : native_event_2_(native_event_2), +Event::Event(const NativeEvent& native_event, ui::EventType type, int flags) + : native_event_(native_event), type_(type), time_stamp_(base::Time::NowFromSystemTime()), flags_(flags) { - InitWithNativeEvent2(native_event_2, from_native); +#if defined(TOOLKIT_USES_GTK) + gdk_event_ = NULL; +#endif } //////////////////////////////////////////////////////////////////////////////// // LocatedEvent, protected: +#if !defined(USE_AURA) +LocatedEvent::LocatedEvent(const NativeEvent& native_event) + : Event(native_event, + ui::EventTypeFromNative(native_event), + ui::EventFlagsFromNative(native_event)), + location_(ui::EventLocationFromNative(native_event)) { +} +#endif + // TODO(msw): Kill this legacy constructor when we update uses. -LocatedEvent::LocatedEvent(ui::EventType type, const gfx::Point& location, +LocatedEvent::LocatedEvent(ui::EventType type, + const gfx::Point& location, int flags) : Event(type, flags), location_(location) { } -LocatedEvent::LocatedEvent(const LocatedEvent& model, View* source, +LocatedEvent::LocatedEvent(const LocatedEvent& model, + View* source, View* target) : Event(model), location_(model.location_) { @@ -63,7 +72,19 @@ LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root) //////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: -KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, +#if !defined(USE_AURA) +KeyEvent::KeyEvent(const NativeEvent& native_event) + : Event(native_event, + ui::EventTypeFromNative(native_event), + ui::EventFlagsFromNative(native_event)), + key_code_(ui::KeyboardCodeFromNative(native_event)), + character_(0), + unmodified_character_(0) { +} +#endif + +KeyEvent::KeyEvent(ui::EventType type, + ui::KeyboardCode key_code, int event_flags) : Event(type, event_flags), key_code_(key_code), @@ -175,13 +196,16 @@ uint16 KeyEvent::GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags) { //////////////////////////////////////////////////////////////////////////////// // MouseEvent, public: +MouseEvent::MouseEvent(const NativeEvent& native_event) + : LocatedEvent(native_event) { +} + MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) : LocatedEvent(model, source, target) { } -MouseEvent::MouseEvent(const TouchEvent& touch, - FromNativeEvent2 from_native) - : LocatedEvent(touch.native_event_2(), from_native) { +MouseEvent::MouseEvent(const TouchEvent& touch) + : LocatedEvent(touch.native_event()) { // 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; @@ -216,6 +240,16 @@ MouseEvent::MouseEvent(const TouchEvent& touch, } //////////////////////////////////////////////////////////////////////////////// +// MouseWheelEvent, public: + +#if !defined(USE_AURA) +MouseWheelEvent::MouseWheelEvent(const ui::NativeEvent& native_event) + : MouseEvent(native_event), + offset_(ui::GetMouseWheelOffset(native_event)) { +} +#endif + +//////////////////////////////////////////////////////////////////////////////// // TouchEvent, public: TouchEvent::TouchEvent(ui::EventType type, diff --git a/views/events/event.h b/views/events/event.h index 4231598..cd9e648 100644 --- a/views/events/event.h +++ b/views/events/event.h @@ -11,20 +11,31 @@ #include "ui/base/events.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/gfx/point.h" -#include "views/native_types.h" #include "views/views_export.h" -#if defined(USE_X11) -typedef union _XEvent XEvent; -#endif - namespace ui { class OSExchangeData; } -using ui::OSExchangeData; + +#if defined(USE_AURA) +namespace aura { +class Event; +} +#endif + +// TODO(msw): Remove GTK support from views event code when possible. +#if defined(TOOLKIT_USES_GTK) +typedef union _GdkEvent GdkEvent; +#endif namespace views { +#if defined(USE_AURA) +typedef aura::Event* NativeEvent; +#else +typedef ui::NativeEvent NativeEvent; +#endif + class View; namespace internal { @@ -32,11 +43,6 @@ class NativeWidgetView; class RootView; } -#if defined(OS_WIN) || defined(USE_AURA) -VIEWS_EXPORT bool IsClientMouseEvent(const views::NativeEvent& native_event); -VIEWS_EXPORT bool IsNonClientMouseEvent(const views::NativeEvent& native_event); -#endif - //////////////////////////////////////////////////////////////////////////////// // // Event class @@ -51,13 +57,10 @@ VIEWS_EXPORT bool IsNonClientMouseEvent(const views::NativeEvent& native_event); //////////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT Event { public: - // This type exists to distinguish between the NativeEvent and NativeEvent2 - // constructors. - // TODO(beng): remove once we rid views of Gtk/Gdk. - struct FromNativeEvent2 {}; - const NativeEvent& native_event() const { return native_event_; } - const NativeEvent2& native_event_2() const { return native_event_2_; } +#if defined(TOOLKIT_USES_GTK) + GdkEvent* gdk_event() const { return gdk_event_; } +#endif ui::EventType type() const { return type_; } const base::Time& time_stamp() const { return time_stamp_; } int flags() const { return flags_; } @@ -88,26 +91,15 @@ class VIEWS_EXPORT Event { type_ == ui::ET_TOUCH_CANCELLED; } -#if defined(OS_WIN) && !defined(USE_AURA) - // Returns the EventFlags in terms of windows flags. - int GetWindowsFlags() const; -#elif defined(OS_LINUX) - // Get the views::Event flags from a native GdkEvent. - static int GetFlagsFromGdkEvent(NativeEvent native_event); -#endif - protected: Event(ui::EventType type, int flags); - Event(NativeEvent native_event, ui::EventType type, int flags); - // Because the world is complicated, sometimes we have two different kinds of - // NativeEvent in play in the same executable. See native_types.h for the tale - // of woe. - Event(NativeEvent2 native_event, ui::EventType type, int flags, - FromNativeEvent2); + Event(const NativeEvent& native_event, ui::EventType type, int flags); +#if defined(TOOLKIT_USES_GTK) + Event(GdkEvent* gdk_event, ui::EventType type, int flags); +#endif Event(const Event& model) : native_event_(model.native_event()), - native_event_2_(model.native_event_2()), type_(model.type()), time_stamp_(model.time_stamp()), flags_(model.flags()) { @@ -118,13 +110,10 @@ class VIEWS_EXPORT Event { private: void operator=(const Event&); - // Safely initializes the native event members of this class. - void Init(); - void InitWithNativeEvent(NativeEvent native_event); - void InitWithNativeEvent2(NativeEvent2 native_event_2, FromNativeEvent2); - NativeEvent native_event_; - NativeEvent2 native_event_2_; +#if defined(TOOLKIT_USES_GTK) + GdkEvent* gdk_event_; +#endif ui::EventType type_; base::Time time_stamp_; int flags_; @@ -145,8 +134,10 @@ class VIEWS_EXPORT LocatedEvent : public Event { const gfx::Point& location() const { return location_; } protected: - explicit LocatedEvent(NativeEvent native_event); - LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); + explicit LocatedEvent(const NativeEvent& native_event); +#if defined(TOOLKIT_USES_GTK) + explicit LocatedEvent(GdkEvent* gdk_event); +#endif // TODO(msw): Kill this legacy constructor when we update uses. // Simple initialization from cracked metadata. @@ -175,8 +166,10 @@ class TouchEvent; //////////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT MouseEvent : public LocatedEvent { public: - explicit MouseEvent(NativeEvent native_event); - MouseEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); + explicit MouseEvent(const NativeEvent& native_event); +#if defined(TOOLKIT_USES_GTK) + explicit MouseEvent(GdkEvent* gdk_event); +#endif // Create a new MouseEvent which is identical to the provided model. // If source / target views are provided, the model location will be converted @@ -188,7 +181,7 @@ class VIEWS_EXPORT MouseEvent : public LocatedEvent { // 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); + explicit MouseEvent(const TouchEvent& touch); // TODO(msw): Kill this legacy constructor when we update uses. // Create a new mouse event @@ -247,7 +240,7 @@ class VIEWS_EXPORT MouseEvent : public LocatedEvent { //////////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT TouchEvent : public LocatedEvent { public: - TouchEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); + explicit TouchEvent(const NativeEvent& native_event); // Create a new touch event. TouchEvent(ui::EventType type, @@ -305,8 +298,10 @@ class VIEWS_EXPORT TouchEvent : public LocatedEvent { //////////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT KeyEvent : public Event { public: - explicit KeyEvent(NativeEvent native_event); - KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); + explicit KeyEvent(const NativeEvent& native_event); +#if defined(TOOLKIT_USES_GTK) + explicit KeyEvent(GdkEvent* gdk_event); +#endif // Creates a new KeyEvent synthetically (i.e. not in response to an input // event from the host environment). This is typically only used in testing as @@ -381,8 +376,10 @@ class VIEWS_EXPORT MouseWheelEvent : public MouseEvent { // See |offset| for details. static const int kWheelDelta; - explicit MouseWheelEvent(NativeEvent native_event); - MouseWheelEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); + explicit MouseWheelEvent(const NativeEvent& native_event); +#if defined(TOOLKIT_USES_GTK) + explicit MouseWheelEvent(GdkEvent* gdk_event); +#endif // The amount to scroll. This is in multiples of kWheelDelta. int offset() const { return offset_; } @@ -411,7 +408,7 @@ class VIEWS_EXPORT MouseWheelEvent : public MouseEvent { //////////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT DropTargetEvent : public LocatedEvent { public: - DropTargetEvent(const OSExchangeData& data, + DropTargetEvent(const ui::OSExchangeData& data, int x, int y, int source_operations) @@ -421,12 +418,12 @@ class VIEWS_EXPORT DropTargetEvent : public LocatedEvent { // TODO(msw): Hook up key state flags for CTRL + drag and drop, etc. } - const OSExchangeData& data() const { return data_; } + const ui::OSExchangeData& data() const { return data_; } int source_operations() const { return source_operations_; } private: // Data associated with the drag/drop session. - const OSExchangeData& data_; + const ui::OSExchangeData& data_; // Bitmask of supported ui::DragDropTypes::DragOperation by the source. int source_operations_; diff --git a/views/events/event_aura.cc b/views/events/event_aura.cc index 57c9d97..f5bda06 100644 --- a/views/events/event_aura.cc +++ b/views/events/event_aura.cc @@ -9,84 +9,24 @@ namespace views { -namespace { - -int GetKeyStateFlags() { - NOTIMPLEMENTED(); - return 0; -} - -ui::EventType EventTypeFromNative(NativeEvent native_event) { - return native_event->type(); -} - -int EventFlagsFromNative(NativeEvent native_event) { - return native_event->flags(); -} - -} - -bool IsClientMouseEvent(const views::NativeEvent& native_event) { - return true; -} - -bool IsNonClientMouseEvent(const views::NativeEvent& native_event) { - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Event, private: - -void Event::Init() { -} - -void Event::InitWithNativeEvent(NativeEvent native_event) { - native_event_ = native_event; - // TODO(beng): remove once we rid views of Gtk/Gdk. - native_event_2_ = NULL; -} - -void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, - FromNativeEvent2) { - // No one should ever call this on Aura. - // TODO(beng): remove once we rid views of Gtk/Gdk. - NOTREACHED(); - native_event_2_ = NULL; -} - //////////////////////////////////////////////////////////////////////////////// // LocatedEvent, protected: -LocatedEvent::LocatedEvent(NativeEvent native_event) +LocatedEvent::LocatedEvent(const NativeEvent& native_event) : Event(native_event, native_event->type(), native_event->flags()), location_(static_cast<aura::LocatedEvent*>(native_event)->location()) { } -LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { - // No one should ever call this on Windows. - // TODO(msw): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - //////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: -KeyEvent::KeyEvent(NativeEvent native_event) - : Event(native_event, native_event->type(), GetKeyStateFlags()), +KeyEvent::KeyEvent(const NativeEvent& native_event) + : Event(native_event, native_event->type(), native_event->flags()), key_code_(static_cast<aura::KeyEvent*>(native_event)->key_code()), character_(0), unmodified_character_(0) { } -KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) - : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { - // No one should ever call this on Windows. - // TODO(beng): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - uint16 KeyEvent::GetCharacter() const { NOTIMPLEMENTED(); return key_code_; @@ -98,34 +38,11 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const { } //////////////////////////////////////////////////////////////////////////////// -// MouseEvent, public: - -MouseEvent::MouseEvent(NativeEvent native_event) - : LocatedEvent(native_event) { -} - -MouseEvent::MouseEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : LocatedEvent(native_event_2, from_native) { - // No one should ever call this on Windows. - // TODO(msw): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - -//////////////////////////////////////////////////////////////////////////////// // MouseWheelEvent, public: -MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) +MouseWheelEvent::MouseWheelEvent(const NativeEvent& native_event) : MouseEvent(native_event), offset_(0 /* TODO(beng): obtain */) { } -MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : MouseEvent(native_event_2, from_native) { - // No one should ever call this on Windows. - // TODO(msw): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - } // namespace views diff --git a/views/events/event_gtk.cc b/views/events/event_gtk.cc index 13c8a8d..9221d69 100644 --- a/views/events/event_gtk.cc +++ b/views/events/event_gtk.cc @@ -8,85 +8,27 @@ #include "base/logging.h" #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" - -namespace views { +#include "ui/gfx/point.h" namespace { -ui::EventType EventTypeFromNative(NativeEvent native_event) { - // Add new event types as necessary. - switch (native_event->type) { - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_PRESS: - return ui::ET_MOUSE_PRESSED; - case GDK_BUTTON_RELEASE: - return ui::ET_MOUSE_RELEASED; - case GDK_DRAG_MOTION: - return ui::ET_MOUSE_DRAGGED; - case GDK_ENTER_NOTIFY: - return ui::ET_MOUSE_ENTERED; +unsigned int GetGdkStateFromNative(GdkEvent* gdk_event) { + switch (gdk_event->type) { case GDK_KEY_PRESS: - return ui::ET_KEY_PRESSED; case GDK_KEY_RELEASE: - return ui::ET_KEY_RELEASED; - case GDK_LEAVE_NOTIFY: - return ui::ET_MOUSE_EXITED; - case GDK_MOTION_NOTIFY: - if (native_event->motion.state & GDK_BUTTON1_MASK || - native_event->motion.state & GDK_BUTTON2_MASK || - native_event->motion.state & GDK_BUTTON3_MASK || - native_event->motion.state & GDK_BUTTON4_MASK || - native_event->motion.state & GDK_BUTTON5_MASK) { - return ui::ET_MOUSE_DRAGGED; - } - return ui::ET_MOUSE_MOVED; - case GDK_SCROLL: - return ui::ET_MOUSEWHEEL; - default: - NOTREACHED(); - break; - } - return ui::ET_UNKNOWN; -} - -GdkEventKey* GetGdkEventKeyFromNative(NativeEvent native_event) { - DCHECK(native_event->type == GDK_KEY_PRESS || - native_event->type == GDK_KEY_RELEASE); - return &native_event->key; -} - -gfx::Point GetMouseEventLocation(NativeEvent native_event) { - double x = 0, y = 0; - if (gdk_event_get_coords(native_event, &x, &y)) - return gfx::Point(static_cast<int>(x), static_cast<int>(y)); - return gfx::Point(); -} - -int GetMouseWheelOffset(NativeEvent native_event) { - DCHECK(native_event->type == GDK_SCROLL); - int offset = (native_event->scroll.direction == GDK_SCROLL_UP || - native_event->scroll.direction == GDK_SCROLL_LEFT) ? 1 : -1; - return MouseWheelEvent::kWheelDelta * offset; -} - -unsigned int GetGdkStateFromNative(NativeEvent native_event) { - switch (native_event->type) { - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - return native_event->key.state; + return gdk_event->key.state; case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: - return native_event->button.state; + return gdk_event->button.state; case GDK_SCROLL: - return native_event->scroll.state; + return gdk_event->scroll.state; case GDK_MOTION_NOTIFY: - return native_event->motion.state; + return gdk_event->motion.state; case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: - return native_event->crossing.state; + return gdk_event->crossing.state; default: NOTREACHED(); break; @@ -106,21 +48,55 @@ int GetFlagsFromGdkState(unsigned int state) { return flags; } -} // namespace - //////////////////////////////////////////////////////////////////////////////// -// Event, public: +// These functions mirror ui/base/events.h, but GTK is in the midst of removal. -// static -int Event::GetFlagsFromGdkEvent(NativeEvent native_event) { - int flags = GetFlagsFromGdkState(GetGdkStateFromNative(native_event)); - if (native_event->type == GDK_2BUTTON_PRESS) +ui::EventType EventTypeFromNative(GdkEvent* gdk_event) { + // Add new event types as necessary. + switch (gdk_event->type) { + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + case GDK_BUTTON_PRESS: + return ui::ET_MOUSE_PRESSED; + case GDK_BUTTON_RELEASE: + return ui::ET_MOUSE_RELEASED; + case GDK_DRAG_MOTION: + return ui::ET_MOUSE_DRAGGED; + case GDK_ENTER_NOTIFY: + return ui::ET_MOUSE_ENTERED; + case GDK_KEY_PRESS: + return ui::ET_KEY_PRESSED; + case GDK_KEY_RELEASE: + return ui::ET_KEY_RELEASED; + case GDK_LEAVE_NOTIFY: + return ui::ET_MOUSE_EXITED; + case GDK_MOTION_NOTIFY: + if (gdk_event->motion.state & GDK_BUTTON1_MASK || + gdk_event->motion.state & GDK_BUTTON2_MASK || + gdk_event->motion.state & GDK_BUTTON3_MASK || + gdk_event->motion.state & GDK_BUTTON4_MASK || + gdk_event->motion.state & GDK_BUTTON5_MASK) { + return ui::ET_MOUSE_DRAGGED; + } + return ui::ET_MOUSE_MOVED; + case GDK_SCROLL: + return ui::ET_MOUSEWHEEL; + default: + NOTREACHED(); + break; + } + return ui::ET_UNKNOWN; +} + +int EventFlagsFromNative(GdkEvent* gdk_event) { + int flags = GetFlagsFromGdkState(GetGdkStateFromNative(gdk_event)); + if (gdk_event->type == GDK_2BUTTON_PRESS) flags |= ui::EF_IS_DOUBLE_CLICK; - if (native_event->type == GDK_BUTTON_PRESS || - native_event->type == GDK_2BUTTON_PRESS || - native_event->type == GDK_3BUTTON_PRESS || - native_event->type == GDK_BUTTON_RELEASE) { - switch (native_event->button.button) { + if (gdk_event->type == GDK_BUTTON_PRESS || + gdk_event->type == GDK_2BUTTON_PRESS || + gdk_event->type == GDK_3BUTTON_PRESS || + gdk_event->type == GDK_BUTTON_RELEASE) { + switch (gdk_event->button.button) { case 1: return flags | ui::EF_LEFT_BUTTON_DOWN; case 2: @@ -132,54 +108,84 @@ int Event::GetFlagsFromGdkEvent(NativeEvent native_event) { return flags; } -//////////////////////////////////////////////////////////////////////////////// -// Event, private: +gfx::Point EventLocationFromNative(GdkEvent* gdk_event) { + double x = 0, y = 0; + if (gdk_event_get_coords(gdk_event, &x, &y)) + return gfx::Point(static_cast<int>(x), static_cast<int>(y)); + return gfx::Point(); +} -void Event::Init() { - native_event_ = NULL; - native_event_2_ = NULL; +ui::KeyboardCode KeyboardCodeFromNative(GdkEvent* gdk_event) { + DCHECK(gdk_event->type == GDK_KEY_PRESS || + gdk_event->type == GDK_KEY_RELEASE); + return ui::KeyboardCodeFromGdkEventKey(&gdk_event->key); } -void Event::InitWithNativeEvent(NativeEvent native_event) { - native_event_ = native_event; - // TODO(beng): remove once we rid views of Gtk/Gdk. - native_event_2_ = NULL; +bool IsMouseEvent(GdkEvent* gdk_event) { + return gdk_event->type == GDK_MOTION_NOTIFY || + gdk_event->type == GDK_BUTTON_PRESS || + gdk_event->type == GDK_2BUTTON_PRESS || + gdk_event->type == GDK_3BUTTON_PRESS || + gdk_event->type == GDK_BUTTON_RELEASE; } -//////////////////////////////////////////////////////////////////////////////// -// LocatedEvent, protected: +int GetMouseWheelOffset(GdkEvent* gdk_event) { + DCHECK(gdk_event->type == GDK_SCROLL); + int offset = (gdk_event->scroll.direction == GDK_SCROLL_UP || + gdk_event->scroll.direction == GDK_SCROLL_LEFT) ? 1 : -1; + return offset; +} -LocatedEvent::LocatedEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - GetFlagsFromGdkEvent(native_event)), - location_(GetMouseEventLocation(native_event)) { +} // namespace + +namespace views { + +//////////////////////////////////////////////////////////////////////////////// +// Event, protected: + +Event::Event(GdkEvent* gdk_event, ui::EventType type, int flags) + : native_event_(NULL), + gdk_event_(gdk_event), + type_(type), + time_stamp_(base::Time::NowFromSystemTime()), + flags_(flags) { } //////////////////////////////////////////////////////////////////////////////// -// MouseEvent, public: +// LocatedEvent, protected: -MouseEvent::MouseEvent(NativeEvent native_event) - : LocatedEvent(native_event) { +LocatedEvent::LocatedEvent(GdkEvent* gdk_event) + : Event(gdk_event, + EventTypeFromNative(gdk_event), + EventFlagsFromNative(gdk_event)), + location_(EventLocationFromNative(gdk_event)) { } //////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: -KeyEvent::KeyEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - GetFlagsFromGdkEvent(native_event)), - key_code_(ui::KeyboardCodeFromGdkEventKey( - GetGdkEventKeyFromNative(native_event))), +KeyEvent::KeyEvent(GdkEvent* gdk_event) + : Event(gdk_event, + EventTypeFromNative(gdk_event), + EventFlagsFromNative(gdk_event)), + key_code_(KeyboardCodeFromNative(gdk_event)), character_(0), unmodified_character_(0) { } //////////////////////////////////////////////////////////////////////////////// +// MouseEvent, public: + +MouseEvent::MouseEvent(GdkEvent* gdk_event) + : LocatedEvent(gdk_event) { +} + +//////////////////////////////////////////////////////////////////////////////// // MouseWheelEvent, public: -MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) - : MouseEvent(native_event), - offset_(GetMouseWheelOffset(native_event)) { +MouseWheelEvent::MouseWheelEvent(GdkEvent* gdk_event) + : MouseEvent(gdk_event), + offset_(kWheelDelta * GetMouseWheelOffset(gdk_event)) { } } // namespace views diff --git a/views/events/event_utils_win.cc b/views/events/event_utils_win.cc deleted file mode 100644 index 7d29271..0000000 --- a/views/events/event_utils_win.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/events/event_utils_win.h" - -#include "ui/base/events.h" -#include "views/events/event.h" - -namespace views { - -int GetRepeatCount(const KeyEvent& event) { - return LOWORD(event.native_event().lParam); -} - -bool IsExtendedKey(const KeyEvent& event) { - return (HIWORD(event.native_event().lParam) & KF_EXTENDED) == KF_EXTENDED; -} - -int GetWindowsFlags(const Event& event) { - // TODO(beng): need support for x1/x2. - int result = 0; - result |= (event.flags() & ui::EF_SHIFT_DOWN) ? MK_SHIFT : 0; - result |= (event.flags() & ui::EF_CONTROL_DOWN) ? MK_CONTROL : 0; - result |= (event.flags() & ui::EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0; - result |= (event.flags() & ui::EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0; - result |= (event.flags() & ui::EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0; - return result; -} - -} // namespace views diff --git a/views/events/event_utils_win.h b/views/events/event_utils_win.h deleted file mode 100644 index b11b45c..0000000 --- a/views/events/event_utils_win.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_EVENTS_EVENT_UTILS_WIN_H_ -#define VIEWS_EVENTS_EVENT_UTILS_WIN_H_ -#pragma once - -#include "ui/gfx/native_widget_types.h" -#include "views/views_export.h" - -// Windows-specific Event utilities. Add functionality here rather than adding -// #ifdefs to event.h - -namespace views { - -class Event; -class KeyEvent; - -// Returns the repeat count of the specified KeyEvent. Valid only for -// KeyEvents constructed from a MSG. -int GetRepeatCount(const KeyEvent& event); - -// Returns true if the affected key is a Windows extended key. See documentation -// for WM_KEYDOWN for explanation. -// Valid only for KeyEvents constructed from a MSG. -VIEWS_EXPORT bool IsExtendedKey(const KeyEvent& event); - -// Return a mask of windows key/button state flags for the event object. -int GetWindowsFlags(const Event& event); - -} // namespace views - -#endif // VIEWS_EVENTS_EVENT_UTILS_WIN_H_ diff --git a/views/events/event_wayland.cc b/views/events/event_wayland.cc index 92b5482..95d564f 100644 --- a/views/events/event_wayland.cc +++ b/views/events/event_wayland.cc @@ -4,191 +4,13 @@ #include "views/events/event.h" -#include <X11/Xlib.h> - #include "base/logging.h" -#include "ui/base/keycodes/keyboard_code_conversion_x.h" -#include "ui/wayland/events/wayland_event.h" namespace views { -namespace { - -static int kWheelScrollAmount = 53; - -ui::EventType EventTypeFromNative(NativeEvent native_event) { - switch (native_event->type) { - case ui::WAYLAND_BUTTON: - switch (native_event->button.button) { - case ui::LEFT_BUTTON: - case ui::RIGHT_BUTTON: - case ui::MIDDLE_BUTTON: - return native_event->button.state ? ui::ET_MOUSE_PRESSED - : ui::ET_MOUSE_RELEASED; - case ui::SCROLL_UP: - case ui::SCROLL_DOWN: - return ui::ET_MOUSEWHEEL; - default: - break; - } - break; - case ui::WAYLAND_KEY: - return native_event->key.state ? ui::ET_KEY_PRESSED - : ui::ET_KEY_RELEASED; - case ui::WAYLAND_MOTION: - return ui::ET_MOUSE_MOVED; - case ui::WAYLAND_POINTER_FOCUS: - return native_event->pointer_focus.state ? ui::ET_MOUSE_ENTERED - : ui::ET_MOUSE_EXITED; - case ui::WAYLAND_KEYBOARD_FOCUS: - return ui::ET_UNKNOWN; - default: - break; - } - return ui::ET_UNKNOWN; -} - -gfx::Point GetMouseEventLocation(NativeEvent native_event) { - switch (native_event->type) { - case ui::WAYLAND_BUTTON: - return gfx::Point(native_event->button.x, native_event->button.y); - case ui::WAYLAND_MOTION: - return gfx::Point(native_event->motion.x, native_event->motion.y); - case ui::WAYLAND_POINTER_FOCUS: - return gfx::Point(native_event->pointer_focus.x, - native_event->pointer_focus.y); - default: - return gfx::Point(0, 0); - } -} - -int GetEventFlagsFromState(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; -} - -int GetButtonEventFlagsFromNativeEvent(NativeEvent native_event) { - // TODO(dnicoara): Need to add double click. - int flags = 0; - switch (native_event->button.button) { - case ui::LEFT_BUTTON: - return flags | ui::EF_LEFT_BUTTON_DOWN; - case ui::MIDDLE_BUTTON: - return flags | ui::EF_MIDDLE_BUTTON_DOWN; - case ui::RIGHT_BUTTON: - return flags | ui::EF_RIGHT_BUTTON_DOWN; - } - return flags; -} - -int GetEventFlagsFromNativeEvent(NativeEvent native_event) { - switch (native_event->type) { - case ui::WAYLAND_BUTTON: - return GetButtonEventFlagsFromNativeEvent(native_event) | - GetEventFlagsFromState(native_event->button.modifiers); - case ui::WAYLAND_KEY: - return GetEventFlagsFromState(native_event->key.modifiers); - case ui::WAYLAND_MOTION: - return GetEventFlagsFromState(native_event->motion.modifiers); - case ui::WAYLAND_KEYBOARD_FOCUS: - return GetEventFlagsFromState(native_event->keyboard_focus.modifiers); - default: - return 0; - } -} - -int GetMouseWheelOffset(NativeEvent native_event) { - if (native_event->button.button == ui::SCROLL_UP) { - return kWheelScrollAmount; - } else { - return -kWheelScrollAmount; - } -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// Event, private: - -void Event::Init() { - native_event_ = NULL; - native_event_2_ = NULL; -} - -void Event::InitWithNativeEvent(NativeEvent native_event) { - native_event_ = native_event; - // TODO(dnicoara): Remove once we rid views of Gtk/Gdk. - native_event_2_ = NULL; -} - -void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, - FromNativeEvent2) { - native_event_2_ = NULL; - // TODO(dnicoara): Remove once we rid views of Gtk/Gdk. - native_event_2_ = native_event_2; -} - -//////////////////////////////////////////////////////////////////////////////// -// MouseEvent, public: - -MouseEvent::MouseEvent(NativeEvent native_event) - : LocatedEvent(native_event) { -} - -MouseEvent::MouseEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : LocatedEvent(native_event_2, from_native) { - // TODO(dnicoara): Remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - -//////////////////////////////////////////////////////////////////////////////// -// LocatedEvent, protected: - -LocatedEvent::LocatedEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - GetEventFlagsFromNativeEvent(native_event)), - location_(GetMouseEventLocation(native_event)) { -} - -LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { - // TODO(dnicoara) Remove once we rid views of Gtk. - NOTREACHED(); -} - ////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: - -KeyEvent::KeyEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - GetEventFlagsFromNativeEvent(native_event)), - key_code_(ui::KeyboardCodeFromXKeysym(native_event->key.sym)) { -} - -KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) - : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { - // TODO(dnicoara) Remove once we rid views of Gtk. - NOTREACHED(); -} - uint16 KeyEvent::GetCharacter() const { return GetCharacterFromKeyCode(key_code_, flags()); } @@ -197,19 +19,4 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const { return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); } -////////////////////////////////////////////////////////////////////////////// -// MouseWheelEvent, public: - -MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) - : MouseEvent(native_event), - offset_(GetMouseWheelOffset(native_event)) { -} - -MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : MouseEvent(native_event_2, from_native) { - // TODO(dnicoara) Remove once we rid views of Gtk. - NOTREACHED(); -} - } // namespace views diff --git a/views/events/event_win.cc b/views/events/event_win.cc index 6f0eab0..b066c2d 100644 --- a/views/events/event_win.cc +++ b/views/events/event_win.cc @@ -4,263 +4,13 @@ #include "views/events/event.h" -#include <windows.h> - #include "base/logging.h" -#include "ui/base/keycodes/keyboard_code_conversion_win.h" namespace views { -namespace { - -// Returns a mask corresponding to the set of modifier keys that are currently -// pressed. Windows key messages don't come with control key state as parameters -// as with mouse messages, so we need to explicitly ask for these states. -int GetKeyStateFlags() { - int flags = 0; - flags |= (GetKeyState(VK_MENU) & 0x80)? ui::EF_ALT_DOWN : 0; - flags |= (GetKeyState(VK_SHIFT) & 0x80)? ui::EF_SHIFT_DOWN : 0; - flags |= (GetKeyState(VK_CONTROL) & 0x80)? ui::EF_CONTROL_DOWN : 0; - return flags; -} - -bool IsButtonDown(NativeEvent native_event) { - return (native_event.wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | - MK_XBUTTON1 | MK_XBUTTON2)) != 0; -} - -// Convert windows message identifiers to Event types. -ui::EventType EventTypeFromNative(NativeEvent native_event) { - switch (native_event.message) { - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - case WM_CHAR: - return ui::ET_KEY_PRESSED; - case WM_KEYUP: - case WM_SYSKEYUP: - return ui::ET_KEY_RELEASED; - case WM_LBUTTONDBLCLK: - case WM_LBUTTONDOWN: - case WM_MBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_NCLBUTTONDBLCLK: - case WM_NCLBUTTONDOWN: - case WM_NCMBUTTONDBLCLK: - case WM_NCMBUTTONDOWN: - case WM_NCRBUTTONDBLCLK: - case WM_NCRBUTTONDOWN: - case WM_NCXBUTTONDBLCLK: - case WM_NCXBUTTONDOWN: - case WM_RBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_XBUTTONDBLCLK: - case WM_XBUTTONDOWN: - return ui::ET_MOUSE_PRESSED; - case WM_LBUTTONUP: - case WM_MBUTTONUP: - case WM_NCLBUTTONUP: - case WM_NCMBUTTONUP: - case WM_NCRBUTTONUP: - case WM_NCXBUTTONUP: - case WM_RBUTTONUP: - case WM_XBUTTONUP: - return ui::ET_MOUSE_RELEASED; - case WM_MOUSEMOVE: - return IsButtonDown(native_event) ? ui::ET_MOUSE_DRAGGED : - ui::ET_MOUSE_MOVED; - case WM_NCMOUSEMOVE: - return ui::ET_MOUSE_MOVED; - case WM_MOUSEWHEEL: - return ui::ET_MOUSEWHEEL; - case WM_MOUSELEAVE: - case WM_NCMOUSELEAVE: - return ui::ET_MOUSE_EXITED; - default: - NOTREACHED(); - } - return ui::ET_UNKNOWN; -} - -// Get views::Event flags from a native Windows message -int EventFlagsFromNative(NativeEvent native_event) { - int flags = 0; - - // TODO(msw): ORing the pressed/released button into the flags is _wrong_. - // It makes it impossible to tell which button was modified when multiple - // buttons are/were held down. We need to instead put the modified button into - // a separate member on the MouseEvent, then audit all consumers of - // MouseEvents to fix them to use the resulting values correctly. - switch (native_event.message) { - case WM_LBUTTONDBLCLK: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_NCLBUTTONDBLCLK: - case WM_NCLBUTTONDOWN: - case WM_NCLBUTTONUP: - native_event.wParam |= MK_LBUTTON; - break; - case WM_MBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_NCMBUTTONDBLCLK: - case WM_NCMBUTTONDOWN: - case WM_NCMBUTTONUP: - native_event.wParam |= MK_MBUTTON; - break; - case WM_RBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_NCRBUTTONDBLCLK: - case WM_NCRBUTTONDOWN: - case WM_NCRBUTTONUP: - native_event.wParam |= MK_RBUTTON; - break; - case WM_NCXBUTTONDBLCLK: - case WM_NCXBUTTONDOWN: - case WM_NCXBUTTONUP: - case WM_XBUTTONDBLCLK: - case WM_XBUTTONDOWN: - case WM_XBUTTONUP: - native_event.wParam |= MK_XBUTTON1; - break; - } - - // Check if the event occurred in the non-client area. - if (IsNonClientMouseEvent(native_event)) - flags |= ui::EF_IS_NON_CLIENT; - - // Check for double click events. - switch (native_event.message) { - case WM_NCLBUTTONDBLCLK: - case WM_NCMBUTTONDBLCLK: - case WM_NCRBUTTONDBLCLK: - case WM_NCXBUTTONDBLCLK: - case WM_LBUTTONDBLCLK: - case WM_MBUTTONDBLCLK: - case WM_RBUTTONDBLCLK: - case WM_XBUTTONDBLCLK: - flags |= ui::EF_IS_DOUBLE_CLICK; - break; - } - - // For non-client mouse message, the WPARAM value represents the hit test - // result, instead of the key state. - switch (native_event.message) { - case WM_NCLBUTTONDOWN: - case WM_NCLBUTTONUP: - flags |= ui::EF_LEFT_BUTTON_DOWN; - break; - case WM_NCMBUTTONDOWN: - case WM_NCMBUTTONUP: - flags |= ui::EF_MIDDLE_BUTTON_DOWN; - break; - case WM_NCRBUTTONDOWN: - case WM_NCRBUTTONUP: - flags |= ui::EF_RIGHT_BUTTON_DOWN; - break; - default: { - UINT win_flags = GET_KEYSTATE_WPARAM(native_event.wParam); - flags |= (win_flags & MK_CONTROL) ? ui::EF_CONTROL_DOWN : 0; - flags |= (win_flags & MK_SHIFT) ? ui::EF_SHIFT_DOWN : 0; - flags |= (GetKeyState(VK_MENU) < 0) ? ui::EF_ALT_DOWN : 0; - flags |= (win_flags & MK_LBUTTON) ? ui::EF_LEFT_BUTTON_DOWN : 0; - flags |= (win_flags & MK_MBUTTON) ? ui::EF_MIDDLE_BUTTON_DOWN : 0; - flags |= (win_flags & MK_RBUTTON) ? ui::EF_RIGHT_BUTTON_DOWN : 0; - break; - } - } - - return flags; -} - -} // namespace - -bool IsClientMouseEvent(const views::NativeEvent& native_event) { - return native_event.message == WM_MOUSELEAVE || - native_event.message == WM_MOUSEHOVER || - (native_event.message >= WM_MOUSEFIRST && - native_event.message <= WM_MOUSELAST); -} - -bool IsNonClientMouseEvent(const views::NativeEvent& native_event) { - return native_event.message == WM_NCMOUSELEAVE || - native_event.message == WM_NCMOUSEHOVER || - (native_event.message >= WM_NCMOUSEMOVE && - native_event.message <= WM_NCXBUTTONDBLCLK); -} - -//////////////////////////////////////////////////////////////////////////////// -// Event, public: - -int Event::GetWindowsFlags() const { - // TODO: need support for x1/x2. - int result = 0; - result |= (flags_ & ui::EF_SHIFT_DOWN) ? MK_SHIFT : 0; - result |= (flags_ & ui::EF_CONTROL_DOWN) ? MK_CONTROL : 0; - result |= (flags_ & ui::EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0; - result |= (flags_ & ui::EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0; - result |= (flags_ & ui::EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0; - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -// Event, private: - -void Event::Init() { - ZeroMemory(&native_event_, sizeof(native_event_)); - native_event_2_ = NULL; -} - -void Event::InitWithNativeEvent(NativeEvent native_event) { - native_event_ = native_event; - // TODO(beng): remove once we rid views of Gtk/Gdk. - native_event_2_ = NULL; -} - -void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, - FromNativeEvent2) { - // No one should ever call this on Windows. - // TODO(beng): remove once we rid views of Gtk/Gdk. - NOTREACHED(); - native_event_2_ = NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// LocatedEvent, protected: - -LocatedEvent::LocatedEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - EventFlagsFromNative(native_event)), - location_(native_event.pt.x, native_event.pt.y) { -} - -LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { - // No one should ever call this on Windows. - // TODO(msw): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - //////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: -KeyEvent::KeyEvent(NativeEvent native_event) - : Event(native_event, - EventTypeFromNative(native_event), - GetKeyStateFlags()), - key_code_(ui::KeyboardCodeForWindowsKeyCode(native_event.wParam)), - character_(0), - unmodified_character_(0) { -} - -KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) - : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { - // No one should ever call this on Windows. - // TODO(beng): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - uint16 KeyEvent::GetCharacter() const { if (character_) return character_; @@ -276,42 +26,4 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const { GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); } -//////////////////////////////////////////////////////////////////////////////// -// MouseEvent, public: - -MouseEvent::MouseEvent(NativeEvent native_event) - : LocatedEvent(native_event) { - if (IsNonClientMouseEvent(native_event)) { - // Non-client message. The position is contained in a POINTS structure in - // LPARAM, and is in screen coordinates so we have to convert to client. - POINT native_point = location_.ToPOINT(); - ScreenToClient(native_event.hwnd, &native_point); - location_ = gfx::Point(native_point); - } -} - -MouseEvent::MouseEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : LocatedEvent(native_event_2, from_native) { - // No one should ever call this on Windows. - // TODO(msw): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - -//////////////////////////////////////////////////////////////////////////////// -// MouseWheelEvent, public: - -MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) - : MouseEvent(native_event), - offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) { -} - -MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : MouseEvent(native_event_2, from_native) { - // No one should ever call this on Windows. - // TODO(msw): remove once we rid views of Gtk/Gdk. - NOTREACHED(); -} - } // namespace views diff --git a/views/events/event_x.cc b/views/events/event_x.cc index fda4aff..9957d5f0 100644 --- a/views/events/event_x.cc +++ b/views/events/event_x.cc @@ -12,234 +12,27 @@ #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/touch/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) { -#if defined(USE_XI2_MT) - XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); - switch(event->evtype) { - case XI_TouchBegin: - return ui::ET_TOUCH_PRESSED; - case XI_TouchUpdate: - return ui::ET_TOUCH_MOVED; - case XI_TouchEnd: - return ui::ET_TOUCH_RELEASED; - } - - return ui::ET_UNKNOWN; -#else - 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; -#endif // defined(USE_XI2_MT) -} - int GetTouchIDFromXEvent(XEvent* xev) { float id = 0; #if defined(USE_XI2_MT) // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new // touch-sequence when TRACKING_ID is used to extract the touch id. - TouchFactory::TouchParam tp = TouchFactory::TP_TRACKING_ID; + ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_TRACKING_ID; #else - TouchFactory::TouchParam tp = TouchFactory::TP_SLOT_ID; + ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_SLOT_ID; #endif - if (!TouchFactory::GetInstance()->ExtractTouchParam( - *xev, tp, &id)) + if (!ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &id)) LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; return id; } -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); @@ -251,26 +44,27 @@ 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; } // The following two functions are copied from event_gtk.cc. These will be // removed when GTK dependency is removed. +#if defined(TOOLKIT_USES_GTK) uint16 GetCharacterFromGdkKeyval(guint keyval) { guint32 ch = gdk_keyval_to_unicode(keyval); @@ -278,67 +72,39 @@ uint16 GetCharacterFromGdkKeyval(guint keyval) { return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; } -GdkEventKey* GetGdkEventKeyFromNative(NativeEvent native_event) { - DCHECK(native_event->type == GDK_KEY_PRESS || - native_event->type == GDK_KEY_RELEASE); - return &native_event->key; +GdkEventKey* GetGdkEventKeyFromNative(GdkEvent* gdk_event) { + DCHECK(gdk_event->type == GDK_KEY_PRESS || + gdk_event->type == GDK_KEY_RELEASE); + return &gdk_event->key; } +#endif } // namespace //////////////////////////////////////////////////////////////////////////////// -// Event, private: - -void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, - FromNativeEvent2) { - native_event_ = NULL; - // TODO(beng): remove once we rid views of Gtk/Gdk. - native_event_2_ = native_event_2; -} - -//////////////////////////////////////////////////////////////////////////////// -// LocatedEvent, protected: - -LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : Event(native_event_2, - EventTypeFromNative(native_event_2), - GetLocatedEventFlags(native_event_2), - from_native), - location_(GetEventLocation(native_event_2)) { -} - -//////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: -KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) - : Event(native_event_2, - EventTypeFromNative(native_event_2), - GetEventFlagsFromXState(native_event_2->xkey.state), - from_native), - key_code_(ui::KeyboardCodeFromXKeyEvent(native_event_2)), - character_(0), - unmodified_character_(0) { -} - uint16 KeyEvent::GetCharacter() const { if (character_) return character_; - if (!native_event_2()) { + if (!native_event()) { +#if defined(TOOLKIT_USES_GTK) // This event may have been created from a Gdk event. - if (IsControlDown() || !native_event()) - return GetCharacterFromKeyCode(key_code_, flags()); - - uint16 ch = GetCharacterFromGdkKeyval( - GetGdkEventKeyFromNative(native_event())->keyval); - return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); + if (!IsControlDown() && gdk_event()) { + uint16 ch = GetCharacterFromGdkKeyval( + GetGdkEventKeyFromNative(gdk_event())->keyval); + if (ch) + return ch; + } +#endif + return GetCharacterFromKeyCode(key_code_, flags()); } - DCHECK(native_event_2()->type == KeyPress || - native_event_2()->type == KeyRelease); + DCHECK(native_event()->type == KeyPress || + native_event()->type == KeyRelease); - uint16 ch = GetCharacterFromXKeyEvent(&native_event_2()->xkey); + uint16 ch = GetCharacterFromXKeyEvent(&native_event()->xkey); return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); } @@ -346,38 +112,37 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const { if (unmodified_character_) return unmodified_character_; - if (!native_event_2()) { + if (!native_event()) { +#if defined(TOOLKIT_USES_GTK) // This event may have been created from a Gdk event. - if (!native_event()) - return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); - - GdkEventKey* key = GetGdkEventKeyFromNative(native_event()); - - static const guint kIgnoredModifiers = - GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | - GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | - GDK_HYPER_MASK | GDK_META_MASK; - - // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask - // out bits used by X11 or Gtk internally. - GdkModifierType modifiers = - static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); - guint keyval = 0; - uint16 ch = 0; - if (gdk_keymap_translate_keyboard_state(NULL, key->hardware_keycode, - modifiers, key->group, &keyval, - NULL, NULL, NULL)) { - ch = GetCharacterFromGdkKeyval(keyval); + if (gdk_event()) { + GdkEventKey* key = GetGdkEventKeyFromNative(gdk_event()); + + static const guint kIgnoredModifiers = + GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | + GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | + GDK_HYPER_MASK | GDK_META_MASK; + + // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask + // out bits used by X11 or Gtk internally. + GdkModifierType modifiers = + static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); + guint keyval = 0; + if (gdk_keymap_translate_keyboard_state(NULL, key->hardware_keycode, + modifiers, key->group, &keyval, NULL, NULL, NULL)) { + uint16 ch = GetCharacterFromGdkKeyval(keyval); + if (ch) + return ch; + } } - - return ch ? ch : - GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); +#endif + return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); } - DCHECK(native_event_2()->type == KeyPress || - native_event_2()->type == KeyRelease); + DCHECK(native_event()->type == KeyPress || + native_event()->type == KeyRelease); - XKeyEvent key = native_event_2()->xkey; + XKeyEvent key = native_event()->xkey; static const unsigned int kIgnoredModifiers = ControlMask | LockMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; @@ -391,45 +156,27 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const { } //////////////////////////////////////////////////////////////////////////////// -// MouseEvent, public: - -MouseEvent::MouseEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : LocatedEvent(native_event_2, from_native) { -} - -//////////////////////////////////////////////////////////////////////////////// -// MouseWheelEvent, public: - -MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, - FromNativeEvent2 from_native) - : MouseEvent(native_event_2, from_native), - offset_(GetMouseWheelOffset(native_event_2)) { -} - -//////////////////////////////////////////////////////////////////////////////// // TouchEvent, public: -TouchEvent::TouchEvent(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, +TouchEvent::TouchEvent(const ui::NativeEvent& native_event) + : LocatedEvent(native_event), + touch_id_(GetTouchIDFromXEvent(native_event)), + radius_x_(GetTouchParamFromXEvent(native_event, + ui::TouchFactory::TP_TOUCH_MAJOR, 2.0) / 2.0), - radius_y_(GetTouchParamFromXEvent(native_event_2, - TouchFactory::TP_TOUCH_MINOR, + radius_y_(GetTouchParamFromXEvent(native_event, + ui::TouchFactory::TP_TOUCH_MINOR, 2.0) / 2.0), - rotation_angle_(GetTouchParamFromXEvent(native_event_2, - TouchFactory::TP_ORIENTATION, + rotation_angle_(GetTouchParamFromXEvent(native_event, + ui::TouchFactory::TP_ORIENTATION, 0.0)), - force_(GetTouchForceFromXEvent(native_event_2)) { + force_(GetTouchForceFromXEvent(native_event)) { #if !defined(USE_XI2_MT) 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)) { + if (factory->ExtractTouchParam(*native_event, + ui::TouchFactory::TP_SLOT_ID, &slot)) { factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); } } diff --git a/views/focus/accelerator_handler_touch.cc b/views/focus/accelerator_handler_touch.cc index fbfa2f8..c9784dd 100644 --- a/views/focus/accelerator_handler_touch.cc +++ b/views/focus/accelerator_handler_touch.cc @@ -8,11 +8,11 @@ #include <gtk/gtk.h> #include <X11/extensions/XInput2.h> +#include "ui/base/touch/touch_factory.h" #include "views/accelerator.h" #include "views/events/event.h" #include "views/focus/focus_manager.h" #include "views/ime/input_method.h" -#include "views/touchui/touch_factory.h" #include "views/view.h" #include "views/widget/native_widget.h" @@ -54,7 +54,7 @@ bool DispatchX2Event(Widget* widget, XEvent* xev) { Event::FromNativeEvent2 from_native; // Hide the cursor when a touch event comes in. - TouchFactory::GetInstance()->SetCursorVisible(false, false); + ui::TouchFactory::GetInstance()->SetCursorVisible(false, false); // If the TouchEvent is processed by |widget|, then return. TouchEvent touch(xev, from_native); @@ -71,19 +71,18 @@ bool DispatchX2Event(Widget* widget, XEvent* xev) { case XI_ButtonRelease: case XI_Motion: { XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); - Event::FromNativeEvent2 from_native; // Scrolling the wheel generates press/release events with button id's 4 // and 5. In case of a wheelscroll, we do not want to show the cursor. if (xievent->detail == 4 || xievent->detail == 5) { - MouseWheelEvent wheelev(xev, from_native); + MouseWheelEvent wheelev(xev); return widget->OnMouseEvent(wheelev); } // Is the event coming from a touch device? - if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { + if (ui::TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { // Hide the cursor when a touch event comes in. - TouchFactory::GetInstance()->SetCursorVisible(false, false); + ui::TouchFactory::GetInstance()->SetCursorVisible(false, false); // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are // ignored, as XI_Motion events contain enough data to detect finger @@ -94,7 +93,7 @@ bool DispatchX2Event(Widget* widget, XEvent* xev) { // If the TouchEvent is processed by |widget|, then return. Otherwise // let it fall through so it can be used as a MouseEvent, if desired. - TouchEvent touch(xev, from_native); + TouchEvent touch(xev); if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) return true; @@ -103,7 +102,7 @@ bool DispatchX2Event(Widget* widget, XEvent* xev) { // RootView::OnTouchEvent. return false; } else { - MouseEvent mouseev(xev, from_native); + MouseEvent mouseev(xev); // Show the cursor. Start a timer to hide the cursor after a delay on // move (not drag) events, or if the only button pressed is released. @@ -112,7 +111,7 @@ bool DispatchX2Event(Widget* widget, XEvent* xev) { (mouseev.IsOnlyLeftMouseButton() || mouseev.IsOnlyMiddleMouseButton() || mouseev.IsOnlyRightMouseButton()); - TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); + ui::TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); return widget->OnMouseEvent(mouseev); } @@ -126,12 +125,12 @@ bool DispatchXEvent(XEvent* xev) { XID xwindow = xev->xany.window; if (xev->type == GenericEvent) { - if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) + if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) return true; // Consume the event. XGenericEventCookie* cookie = &xev->xcookie; if (cookie->evtype == XI_HierarchyChanged) { - TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); + ui::TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); return true; } @@ -142,11 +141,10 @@ bool DispatchXEvent(XEvent* xev) { GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); Widget* widget = FindWidgetForGdkWindow(gwind); if (widget) { - Event::FromNativeEvent2 from_native; switch (xev->type) { case KeyPress: case KeyRelease: { - KeyEvent keyev(xev, from_native); + KeyEvent keyev(xev); InputMethod* ime = widget->GetInputMethod(); // Always dispatch key events to the input method first, to make sure // that the input method's hotkeys work all time. @@ -160,12 +158,12 @@ bool DispatchXEvent(XEvent* xev) { case ButtonRelease: if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { // Scrolling the wheel triggers button press/release events. - MouseWheelEvent wheelev(xev, from_native); + MouseWheelEvent wheelev(xev); return widget->OnMouseEvent(wheelev); } // fallthrough case MotionNotify: { - MouseEvent mouseev(xev, from_native); + MouseEvent mouseev(xev); return widget->OnMouseEvent(mouseev); } @@ -179,7 +177,7 @@ bool DispatchXEvent(XEvent* xev) { } void SetTouchDeviceList(std::vector<unsigned int>& devices) { - TouchFactory::GetInstance()->SetTouchDeviceList(devices); + ui::TouchFactory::GetInstance()->SetTouchDeviceList(devices); } AcceleratorHandler::AcceleratorHandler() {} diff --git a/views/ime/input_method_gtk.cc b/views/ime/input_method_gtk.cc index 6cb35b2..146cf6a 100644 --- a/views/ime/input_method_gtk.cc +++ b/views/ime/input_method_gtk.cc @@ -127,8 +127,8 @@ void InputMethodGtk::DispatchKeyEvent(const KeyEvent& key) { result_text_.clear(); // If it's a fake key event, then we need to synthesize a GdkEventKey. - GdkEvent* event = key.native_event() ? key.native_event() : - SynthesizeGdkEventKey(key); + GdkEvent* event = key.gdk_event() ? key.gdk_event() : + SynthesizeGdkEventKey(key); gboolean filtered = gtk_im_context_filter_keypress( context_focused_ ? context_ : context_simple_, &event->key); @@ -152,7 +152,7 @@ void InputMethodGtk::DispatchKeyEvent(const KeyEvent& key) { } // Free the synthesized event if there was no underlying native event. - if (event != key.native_event()) + if (event != key.gdk_event()) gdk_event_free(event); } diff --git a/views/ime/input_method_ibus.cc b/views/ime/input_method_ibus.cc index ae22de2..94ee14c 100644 --- a/views/ime/input_method_ibus.cc +++ b/views/ime/input_method_ibus.cc @@ -62,8 +62,8 @@ void IBusKeyEventFromViewsKeyEvent(const views::KeyEvent& key, guint32* ibus_keycode, guint32* ibus_state) { #if defined(TOUCH_UI) - if (key.native_event_2()) { - XKeyEvent* x_key = reinterpret_cast<XKeyEvent*>(key.native_event_2()); + if (key.native_event()) { + XKeyEvent* x_key = reinterpret_cast<XKeyEvent*>(key.native_event()); // Yes, ibus uses X11 keysym. We cannot use XLookupKeysym(), which doesn't // translate Shift and CapsLock states. KeySym keysym = NoSymbol; @@ -72,8 +72,8 @@ void IBusKeyEventFromViewsKeyEvent(const views::KeyEvent& key, *ibus_keycode = x_key->keycode; } #elif defined(TOOLKIT_USES_GTK) - if (key.native_event()) { - GdkEventKey* gdk_key = reinterpret_cast<GdkEventKey*>(key.native_event()); + if (key.gdk_event()) { + GdkEventKey* gdk_key = reinterpret_cast<GdkEventKey*>(key.gdk_event()); *ibus_keyval = gdk_key->keyval; *ibus_keycode = gdk_key->hardware_keycode; } @@ -223,8 +223,8 @@ InputMethodIBus::PendingKeyEvent::PendingKeyEvent(InputMethodIBus* input_method, DCHECK(input_method_); #if defined(TOUCH_UI) - if (key.native_event_2()) - x_event_ = *reinterpret_cast<XKeyEvent*>(key.native_event_2()); + if (key.native_event()) + x_event_ = *reinterpret_cast<XKeyEvent*>(key.native_event()); else memset(&x_event_, 0, sizeof(x_event_)); #endif @@ -241,8 +241,7 @@ void InputMethodIBus::PendingKeyEvent::ProcessPostIME(bool handled) { #if defined(TOUCH_UI) if (x_event_.type == KeyPress || x_event_.type == KeyRelease) { - Event::FromNativeEvent2 from_native; - KeyEvent key(reinterpret_cast<XEvent*>(&x_event_), from_native); + KeyEvent key(reinterpret_cast<XEvent*>(&x_event_)); input_method_->ProcessKeyEventPostIME(key, ibus_keyval_, handled); return; } diff --git a/views/native_types.h b/views/native_types.h deleted file mode 100644 index a5070e7..0000000 --- a/views/native_types.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_NATIVE_TYPES_H_ -#define VIEWS_NATIVE_TYPES_H_ -#pragma once - -#include "ui/gfx/native_widget_types.h" - -#if defined(OS_LINUX) -typedef union _GdkEvent GdkEvent; -#endif -#if defined(USE_X11) -typedef union _XEvent XEvent; -#endif -#if defined(USE_WAYLAND) -namespace ui { -union WaylandEvent; -} -#endif - -#if defined(USE_AURA) -namespace aura { -class Event; -} -#endif - -namespace views { - -// A note about NativeEvent and NativeEvent2. -// 1. Eventually TOOLKIT_VIEWS will converge on using XEvent as we remove -// Gtk/Gdk from the stack. -// 2. TOUCH_UI needs XEvents now for certain event types. -// 3. TOUCH_UI also needs GdkEvents for certain event types. -// -// => NativeEvent and NativeEvent2. -// -// Once we replace usage of Gtk/Gdk types with Xlib types across the board in -// views, we can remove NativeEvent2 and typedef XEvent* to NativeEvent. The -// world will then be beautiful(ish). - -#if defined(USE_AURA) -typedef aura::Event* NativeEvent; -#elif defined(OS_WIN) -typedef MSG NativeEvent; -#elif defined(OS_LINUX) - -#if defined(USE_WAYLAND) -typedef ui::WaylandEvent* NativeEvent; -#else -typedef GdkEvent* NativeEvent; -#endif - -#endif - -#if defined(USE_X11) -typedef XEvent* NativeEvent2; -#else -typedef void* NativeEvent2; -#endif - -} // namespace views - -#endif // VIEWS_NATIVE_TYPES_H_ - diff --git a/views/touchui/gesture_manager.cc b/views/touchui/gesture_manager.cc index cf966ae..723db77 100644 --- a/views/touchui/gesture_manager.cc +++ b/views/touchui/gesture_manager.cc @@ -36,8 +36,7 @@ bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event, // Conver the touch-event into a mouse-event. This mouse-event gets its // location information from the native-event, so it needs to convert the // coordinate to the target widget. - Event::FromNativeEvent2 from_native; - MouseEvent mouseev(event, from_native); + MouseEvent mouseev(event); if (ViewsDelegate::views_delegate->GetDefaultParentView()) { // TODO(oshima): We may need to send the event back through // window manager to handle mouse capture correctly. diff --git a/views/touchui/touch_factory.cc b/views/touchui/touch_factory.cc deleted file mode 100644 index e644bca..0000000 --- a/views/touchui/touch_factory.cc +++ /dev/null @@ -1,502 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/touchui/touch_factory.h" - -#if defined(TOOLKIT_USES_GTK) -// TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only. -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#endif -#include <X11/cursorfont.h> -#include <X11/extensions/XInput.h> -#include <X11/extensions/XInput2.h> -#include <X11/extensions/XIproto.h> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "ui/base/x/x11_util.h" - -namespace { - -// The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. -int kCursorIdleSeconds = 5; - -// Given the TouchParam, return the correspoding XIValuatorClassInfo using -// the X device information through Atom name matching. -XIValuatorClassInfo* FindTPValuator(Display* display, - XIDeviceInfo* info, - views::TouchFactory::TouchParam tp) { - // Lookup table for mapping TouchParam to Atom string used in X. - // A full set of Atom strings can be found at xserver-properties.h. - static struct { - views::TouchFactory::TouchParam tp; - const char* atom; - } kTouchParamAtom[] = { - { views::TouchFactory::TP_TOUCH_MAJOR, "Abs MT Touch Major" }, - { views::TouchFactory::TP_TOUCH_MINOR, "Abs MT Touch Minor" }, - { views::TouchFactory::TP_ORIENTATION, "Abs MT Orientation" }, - { views::TouchFactory::TP_PRESSURE, "Abs MT Pressure" }, -#if !defined(USE_XI2_MT) - // For Slot ID, See this chromeos revision: http://git.chromium.org/gitweb/? - // p=chromiumos/overlays/chromiumos-overlay.git; - // a=commit;h=9164d0a75e48c4867e4ef4ab51f743ae231c059a - { views::TouchFactory::TP_SLOT_ID, "Abs MT Slot ID" }, -#endif - { views::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" }, - { views::TouchFactory::TP_LAST_ENTRY, NULL }, - }; - - const char* atom_tp = NULL; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTouchParamAtom); i++) { - if (tp == kTouchParamAtom[i].tp) { - atom_tp = kTouchParamAtom[i].atom; - break; - } - } - - if (!atom_tp) - return NULL; - - for (int i = 0; i < info->num_classes; i++) { - if (info->classes[i]->type != XIValuatorClass) - continue; - XIValuatorClassInfo* v = - reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]); - - const char* atom = XGetAtomName(display, v->label); - if (atom && strcmp(atom, atom_tp) == 0) - return v; - } - - return NULL; -} - -#if defined(TOOLKIT_USES_GTK) -// Setup XInput2 select for the GtkWidget. -gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams, - const GValue* pvalues, gpointer data) { - GtkWidget* widget = GTK_WIDGET(g_value_get_object(pvalues)); - GdkWindow* window = widget->window; - views::TouchFactory* factory = static_cast<views::TouchFactory*>(data); - - if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL && - GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD && - GDK_WINDOW_TYPE(window) != GDK_WINDOW_DIALOG) - return true; - - factory->SetupXI2ForXWindow(GDK_WINDOW_XID(window)); - return true; -} - -// We need to capture all the GDK windows that get created, and start -// listening for XInput2 events. So we setup a callback to the 'realize' -// signal for GTK+ widgets, so that whenever the signal triggers for any -// GtkWidget, which means the GtkWidget should now have a GdkWindow, we can -// setup XInput2 events for the GdkWindow. -guint realize_signal_id = 0; -guint realize_hook_id = 0; - -void SetupGtkWidgetRealizeNotifier(views::TouchFactory* factory) { - gpointer klass = g_type_class_ref(GTK_TYPE_WIDGET); - - g_signal_parse_name("realize", GTK_TYPE_WIDGET, - &realize_signal_id, NULL, FALSE); - realize_hook_id = g_signal_add_emission_hook(realize_signal_id, 0, - GtkWidgetRealizeCallback, static_cast<gpointer>(factory), NULL); - - g_type_class_unref(klass); -} - -void RemoveGtkWidgetRealizeNotifier() { - if (realize_signal_id != 0) - g_signal_remove_emission_hook(realize_signal_id, realize_hook_id); - realize_signal_id = 0; - realize_hook_id = 0; -} -#endif - -} // namespace - -namespace views { - -// static -TouchFactory* TouchFactory::GetInstance() { - return Singleton<TouchFactory>::get(); -} - -TouchFactory::TouchFactory() - : is_cursor_visible_(true), - keep_mouse_cursor_(false), - cursor_timer_(), - pointer_device_lookup_(), -#if defined(USE_XI2_MT) - touch_device_list_() { -#else - touch_device_list_(), - slots_used_() { -#endif -#if defined(TOUCH_UI) - if (!base::MessagePumpForUI::HasXInput2()) - return; -#endif - - char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - XColor black; - black.red = black.green = black.blue = 0; - Display* display = ui::GetXDisplay(); - Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), - nodata, 8, 8); - invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, - &black, &black, 0, 0); - arrow_cursor_ = XCreateFontCursor(display, XC_arrow); - - SetCursorVisible(false, false); - UpdateDeviceList(display); - -#if defined(TOOLKIT_USES_GTK) - // TODO(sad): Here, we only setup so that the X windows created by GTK+ are - // setup for XInput2 events. We need a way to listen for XInput2 events for X - // windows created by other means (e.g. for context menus). - SetupGtkWidgetRealizeNotifier(this); -#endif - // Make sure the list of devices is kept up-to-date by listening for - // XI_HierarchyChanged event on the root window. - unsigned char mask[XIMaskLen(XI_LASTEVENT)]; - memset(mask, 0, sizeof(mask)); - - XISetMask(mask, XI_HierarchyChanged); - - XIEventMask evmask; - evmask.deviceid = XIAllDevices; - evmask.mask_len = sizeof(mask); - evmask.mask = mask; - XISelectEvents(display, ui::GetX11RootWindow(), &evmask, 1); -} - -TouchFactory::~TouchFactory() { -#if defined(TOUCH_UI) - if (!base::MessagePumpForUI::HasXInput2()) - return; -#endif - - SetCursorVisible(true, false); - Display* display = ui::GetXDisplay(); - XFreeCursor(display, invisible_cursor_); - XFreeCursor(display, arrow_cursor_); - -#if defined(TOOLKIT_USES_GTK) - RemoveGtkWidgetRealizeNotifier(); -#endif -} - -void TouchFactory::UpdateDeviceList(Display* display) { - // Detect touch devices. - // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does - // not provide enough information to detect a touch device. As a result, the - // old version of query function (XListInputDevices) is used instead. - // If XInput2 is not supported, this will return null (with count of -1) so - // we assume there cannot be any touch devices. - int count = 0; - touch_device_lookup_.reset(); - touch_device_list_.clear(); -#if !defined(USE_XI2_MT) - XDeviceInfo* devlist = XListInputDevices(display, &count); - for (int i = 0; i < count; i++) { - if (devlist[i].type) { - const char* devtype = XGetAtomName(display, devlist[i].type); - if (devtype && !strcmp(devtype, XI_TOUCHSCREEN)) { - touch_device_lookup_[devlist[i].id] = true; - touch_device_list_.push_back(devlist[i].id); - } - } - } - if (devlist) - XFreeDeviceList(devlist); -#endif - - // Instead of asking X for the list of devices all the time, let's maintain a - // list of pointer devices we care about. - // It should not be necessary to select for slave devices. XInput2 provides - // enough information to the event callback to decide which slave device - // triggered the event, thus decide whether the 'pointer event' is a - // 'mouse event' or a 'touch event'. - // However, on some desktops, some events from a master pointer are - // not delivered to the client. So we select for slave devices instead. - // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which - // is possible), then the device is detected as a floating device, and a - // floating device is not connected to a master device. So it is necessary to - // also select on the floating devices. - pointer_device_lookup_.reset(); - XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); - for (int i = 0; i < count; i++) { - XIDeviceInfo* devinfo = devices + i; -#if defined(USE_XI2_MT) - for (int k = 0; k < devinfo->num_classes; ++k) { - XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; - if (xiclassinfo->type == XITouchClass) { - XITouchClassInfo* tci = - reinterpret_cast<XITouchClassInfo *>(xiclassinfo); - // Only care direct touch device (such as touch screen) right now - if (tci->mode == XIDirectTouch) { - touch_device_lookup_[devinfo->deviceid] = true; - touch_device_list_.push_back(devinfo->deviceid); - } - } - } -#endif - if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) - pointer_device_lookup_[devinfo->deviceid] = true; - } - if (devices) - XIFreeDeviceInfo(devices); - - SetupValuator(); -} - -bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { - DCHECK_EQ(GenericEvent, xev->type); - XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); - XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); - -#if defined(USE_XI2_MT) - if (event->evtype == XI_TouchBegin || - event->evtype == XI_TouchUpdate || - event->evtype == XI_TouchEnd) { - return touch_device_lookup_[xiev->sourceid]; - } -#endif - if (event->evtype != XI_ButtonPress && - event->evtype != XI_ButtonRelease && - event->evtype != XI_Motion) - return true; - - return pointer_device_lookup_[xiev->deviceid]; -} - -void TouchFactory::SetupXI2ForXWindow(Window window) { - // Setup mask for mouse events. It is possible that a device is loaded/plugged - // in after we have setup XInput2 on a window. In such cases, we need to - // either resetup XInput2 for the window, so that we get events from the new - // device, or we need to listen to events from all devices, and then filter - // the events from uninteresting devices. We do the latter because that's - // simpler. - - Display* display = ui::GetXDisplay(); - - unsigned char mask[XIMaskLen(XI_LASTEVENT)]; - memset(mask, 0, sizeof(mask)); - -#if defined(USE_XI2_MT) - XISetMask(mask, XI_TouchBegin); - XISetMask(mask, XI_TouchUpdate); - XISetMask(mask, XI_TouchEnd); -#endif - XISetMask(mask, XI_ButtonPress); - XISetMask(mask, XI_ButtonRelease); - XISetMask(mask, XI_Motion); - - XIEventMask evmask; - evmask.deviceid = XIAllDevices; - evmask.mask_len = sizeof(mask); - evmask.mask = mask; - XISelectEvents(display, window, &evmask, 1); - XFlush(display); -} - -void TouchFactory::SetTouchDeviceList( - const std::vector<unsigned int>& devices) { - touch_device_lookup_.reset(); - touch_device_list_.clear(); - for (std::vector<unsigned int>::const_iterator iter = devices.begin(); - iter != devices.end(); ++iter) { - DCHECK(*iter < touch_device_lookup_.size()); - touch_device_lookup_[*iter] = true; - touch_device_list_.push_back(*iter); - } - - SetupValuator(); -} - -bool TouchFactory::IsTouchDevice(unsigned deviceid) const { - return deviceid < touch_device_lookup_.size() ? - touch_device_lookup_[deviceid] : false; -} - -#if !defined(USE_XI2_MT) -bool TouchFactory::IsSlotUsed(int slot) const { - CHECK_LT(slot, kMaxTouchPoints); - return slots_used_[slot]; -} - -void TouchFactory::SetSlotUsed(int slot, bool used) { - CHECK_LT(slot, kMaxTouchPoints); - slots_used_[slot] = used; -} -#endif - -bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { -#if defined(TOUCH_UI) - if (!base::MessagePumpForUI::HasXInput2() || - touch_device_list_.empty()) - return true; -#endif - - unsigned char mask[XIMaskLen(XI_LASTEVENT)]; - bool success = true; - - memset(mask, 0, sizeof(mask)); -#if defined(USE_XI2_MT) - XISetMask(mask, XI_TouchBegin); - XISetMask(mask, XI_TouchUpdate); - XISetMask(mask, XI_TouchEnd); -#endif - XISetMask(mask, XI_ButtonPress); - XISetMask(mask, XI_ButtonRelease); - XISetMask(mask, XI_Motion); - - XIEventMask evmask; - evmask.mask_len = sizeof(mask); - evmask.mask = mask; - for (std::vector<int>::const_iterator iter = - touch_device_list_.begin(); - iter != touch_device_list_.end(); ++iter) { - evmask.deviceid = *iter; - Status status = XIGrabDevice(display, *iter, window, CurrentTime, None, - GrabModeAsync, GrabModeAsync, False, &evmask); - success = success && status == GrabSuccess; - } - - return success; -} - -bool TouchFactory::UngrabTouchDevices(Display* display) { -#if defined(TOUCH_UI) - if (!base::MessagePumpForUI::HasXInput2()) - return true; -#endif - - bool success = true; - for (std::vector<int>::const_iterator iter = - touch_device_list_.begin(); - iter != touch_device_list_.end(); ++iter) { - Status status = XIUngrabDevice(display, *iter, CurrentTime); - success = success && status == GrabSuccess; - } - return success; -} - -void TouchFactory::SetCursorVisible(bool show, bool start_timer) { -#if defined(TOUCH_UI) - if (!base::MessagePumpForUI::HasXInput2()) - return; -#endif - - // The cursor is going to be shown. Reset the timer for hiding it. - if (show && start_timer) { - cursor_timer_.Stop(); - cursor_timer_.Start( - FROM_HERE, base::TimeDelta::FromSeconds(kCursorIdleSeconds), - this, &TouchFactory::HideCursorForInactivity); - } else { - cursor_timer_.Stop(); - } - - if (show == is_cursor_visible_) - return; - - is_cursor_visible_ = show; - - Display* display = ui::GetXDisplay(); - Window window = DefaultRootWindow(display); - - if (is_cursor_visible_) { - XDefineCursor(display, window, arrow_cursor_); - } else { - XDefineCursor(display, window, invisible_cursor_); - } -} - -void TouchFactory::SetupValuator() { - memset(valuator_lookup_, -1, sizeof(valuator_lookup_)); - memset(touch_param_min_, 0, sizeof(touch_param_min_)); - memset(touch_param_max_, 0, sizeof(touch_param_max_)); - - Display* display = ui::GetXDisplay(); - int ndevice; - XIDeviceInfo* info_list = XIQueryDevice(display, XIAllDevices, &ndevice); - - for (int i = 0; i < ndevice; i++) { - XIDeviceInfo* info = info_list + i; - - if (!IsTouchDevice(info->deviceid)) - continue; - - for (int j = 0; j < TP_LAST_ENTRY; j++) { - TouchParam tp = static_cast<TouchParam>(j); - XIValuatorClassInfo* valuator = FindTPValuator(display, info, tp); - if (valuator) { - valuator_lookup_[info->deviceid][j] = valuator->number; - touch_param_min_[info->deviceid][j] = valuator->min; - touch_param_max_[info->deviceid][j] = valuator->max; - } - } - } - - if (info_list) - XIFreeDeviceInfo(info_list); -} - -bool TouchFactory::ExtractTouchParam(const XEvent& xev, - TouchParam tp, - float* value) { - XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); - if (xiev->sourceid >= kMaxDeviceNum) - return false; - int v = valuator_lookup_[xiev->sourceid][tp]; - if (v >= 0 && XIMaskIsSet(xiev->valuators.mask, v)) { - *value = xiev->valuators.values[v]; - return true; - } - -#if defined(USE_XI2_MT) - // With XInput2 MT, Tracking ID is provided in the detail field. - if (tp == TP_TRACKING_ID) { - *value = xiev->detail; - return true; - } -#endif - - return false; -} - -bool TouchFactory::NormalizeTouchParam(unsigned int deviceid, - TouchParam tp, - float* value) { - float max_value; - float min_value; - if (GetTouchParamRange(deviceid, tp, &min_value, &max_value)) { - *value = (*value - min_value) / (max_value - min_value); - DCHECK(*value >= 0.0 && *value <= 1.0); - return true; - } - return false; -} - -bool TouchFactory::GetTouchParamRange(unsigned int deviceid, - TouchParam tp, - float* min, - float* max) { - if (valuator_lookup_[deviceid][tp] >= 0) { - *min = touch_param_min_[deviceid][tp]; - *max = touch_param_max_[deviceid][tp]; - return true; - } - return false; -} - -} // namespace views diff --git a/views/touchui/touch_factory.h b/views/touchui/touch_factory.h deleted file mode 100644 index ca281e4..0000000 --- a/views/touchui/touch_factory.h +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_TOUCHUI_TOUCH_FACTORY_H_ -#define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ -#pragma once - -#include <bitset> -#include <vector> - -#include "base/memory/singleton.h" -#include "base/timer.h" -#include "views/views_export.h" - -typedef unsigned long Cursor; -typedef unsigned long Window; -typedef struct _XDisplay Display; -typedef union _XEvent XEvent; - -namespace views { - -// Functions related to determining touch devices. -class VIEWS_EXPORT TouchFactory { - public: - // Define the touch params following the Multi-touch Protocol. - enum TouchParam { - TP_TOUCH_MAJOR = 0, // Length of the touch area. - TP_TOUCH_MINOR, // Width of the touch area. - TP_ORIENTATION, // Angle between the X-axis and the major axis of the - // touch area. - TP_PRESSURE, // Pressure of the touch contact. - - // NOTE: A touch event can have multiple touch points. So when we receive a - // touch event, we need to determine which point triggered the event. - // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can - // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and - // (X - 1), where X is the maximum touch points supported by the device. The - // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion - // event that comes from a currently-unused 'Slot ID' indicates the creation - // of a new touch point, and any event that comes with a 0 value for - // 'Tracking ID' marks the removal of a touch point. During the lifetime of - // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress - // and XI_ButtonRelease events are ignored. -#if !defined(USE_XI2_MT) - TP_SLOT_ID, // ID of the finger that triggered a touch event - // (useful when tracking multiple simultaneous - // touches) -#endif - // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to - // track individual touch. 'Tracking ID' is an unsigned 32-bit value and - // is increased for each new touch. It will wrap back to 0 when reaching - // the numerical limit. - TP_TRACKING_ID, // ID of the touch point. - - TP_LAST_ENTRY - }; - - // Returns the TouchFactory singleton. - static TouchFactory* GetInstance(); - - // Updates the list of devices. - void UpdateDeviceList(Display* display); - - // Checks whether an XI2 event should be processed or not (i.e. if the event - // originated from a device we are interested in). - bool ShouldProcessXI2Event(XEvent* xevent); - - // Setup an X Window for XInput2 events. - void SetupXI2ForXWindow(::Window xid); - - // Keeps a list of touch devices so that it is possible to determine if a - // pointer event is a touch-event or a mouse-event. The list is reset each - // time this is called. - void SetTouchDeviceList(const std::vector<unsigned int>& devices); - - // Is the device a touch-device? - bool IsTouchDevice(unsigned int deviceid) const; - -#if !defined(USE_XI2_MT) - // Is the slot ID currently used? - bool IsSlotUsed(int slot) const; - - // Marks a slot as being used/unused. - void SetSlotUsed(int slot, bool used); -#endif - - // Grabs the touch devices for the specified window on the specified display. - // Returns if grab was successful for all touch devices. - bool GrabTouchDevices(Display* display, ::Window window); - - // Ungrabs the touch devices. Returns if ungrab was successful for all touch - // devices. - bool UngrabTouchDevices(Display* display); - - // Updates the root window to show (or hide) the cursor. Also indicate whether - // the timer should be started to automatically hide the cursor after a - // certain duration of inactivity (i.e. it is ignored if |show| is false). - void SetCursorVisible(bool show, bool start_timer); - - // Whether the cursor is currently visible or not. - bool is_cursor_visible() const { - return is_cursor_visible_; - } - - // Extract the TouchParam from the XEvent. Return true and the value is set - // if the TouchParam is found, false and value unchanged if the TouchParam - // is not found. - bool ExtractTouchParam(const XEvent& xev, TouchParam tp, float* value); - - // Normalize the TouchParam with value on deviceid to fall into [0, 1]. - // *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp) - // Returns true and sets the normalized value in|value| if normalization is - // successful. Returns false and |value| is unchanged otherwise. - bool NormalizeTouchParam(unsigned int deviceid, TouchParam tp, float* value); - - // Extract the range of the TouchParam. Return true if the range is available - // and written into min & max, false if the range is not available. - bool GetTouchParamRange(unsigned int deviceid, - TouchParam tp, - float* min, - float* max); - - void set_keep_mouse_cursor(bool keep) { keep_mouse_cursor_ = keep; } - bool keep_mouse_cursor() const { return keep_mouse_cursor_; } - - private: - TouchFactory(); - - ~TouchFactory(); - - void HideCursorForInactivity() { - SetCursorVisible(false, false); - } - - // Setup the internal bookkeeping of the touch params valuator information for - // touch devices - void SetupValuator(); - - // Requirement for Signleton - friend struct DefaultSingletonTraits<TouchFactory>; - - // The default cursor is hidden after startup, and when the mouse pointer is - // idle for a while. Once there is some event from a mouse device, the cursor - // is immediately displayed. - bool is_cursor_visible_; - - // Whether to turn off automatic hiding of mouse cursor. This is useful for - // debugging touch build on the desktop. - bool keep_mouse_cursor_; - - // The cursor is hidden if it is idle for a certain amount time. This timer - // is used to keep track of the idleness. - base::OneShotTimer<TouchFactory> cursor_timer_; - - // The default cursor. - Cursor arrow_cursor_; - - // The invisible cursor. - Cursor invisible_cursor_; - - // NOTE: To keep track of touch devices, we currently maintain a lookup table - // to quickly decide if a device is a touch device or not. We also maintain a - // list of the touch devices. Ideally, there will be only one touch device, - // and instead of having the lookup table and the list, there will be a single - // identifier for the touch device. This can be completed after enough testing - // on real touch devices. - - static const int kMaxDeviceNum = 128; - - // A quick lookup table for determining if events from the pointer device - // should be processed. - std::bitset<kMaxDeviceNum> pointer_device_lookup_; - - // A quick lookup table for determining if a device is a touch device. - std::bitset<kMaxDeviceNum> touch_device_lookup_; - - // The list of touch devices. - std::vector<int> touch_device_list_; - - // Index table to find the valuator for the TouchParam on the specific device - // by valuator_lookup_[device_id][touch_params]. Use 2-D array to get fast - // index at the expense of space. If the kMaxDeviceNum grows larger that the - // space waste becomes a concern, the 2D lookup table can be replaced by a - // hash map. - signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; - - // Index table to find the min & max value of the TouchParam on a specific - // device. - int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; - int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; - -#if !defined(USE_XI2_MT) - // Maximum simultaneous touch points. - static const int kMaxTouchPoints = 32; - - // A lookup table for slots in use for a touch event. - std::bitset<kMaxTouchPoints> slots_used_; -#endif - - DISALLOW_COPY_AND_ASSIGN(TouchFactory); -}; - -} // namespace views - -#endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ diff --git a/views/views.gyp b/views/views.gyp index 3d5e995..3c0ade1 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -13,7 +13,6 @@ ['include', '_(win)\\.cc$'], ['include', '/win/'], ['include', '/win_[^/]*\\.cc$'], - ['exclude', 'touchui/touch_factory.cc'], ]}], ['touchui==0', { 'sources/': [ @@ -260,8 +259,6 @@ 'events/event_gtk.cc', 'events/event_wayland.cc', 'events/event_win.cc', - 'events/event_utils_win.cc', - 'events/event_utils_win.h', 'events/event_x.cc', 'focus/accelerator_handler.h', 'focus/accelerator_handler_aura.cc', @@ -332,8 +329,6 @@ 'repeat_controller.h', 'touchui/gesture_manager.cc', 'touchui/gesture_manager.h', - 'touchui/touch_factory.cc', - 'touchui/touch_factory.h', 'touchui/touch_selection_controller.cc', 'touchui/touch_selection_controller.h', 'touchui/touch_selection_controller_impl.cc', @@ -426,8 +421,6 @@ ['exclude', '_(gtk|x)\\.cc$'], ['exclude', '/(gtk|x)_[^/]*\\.cc$'], ['exclude', 'focus/accelerator_handler_touch.cc'], - ['exclude', 'touchui/touch_factory.cc'], - ['exclude', 'touchui/touch_factory.h'], ['include', 'controls/menu/native_menu_views.cc'], ['include', 'controls/menu/native_menu_views.h'], ['include', 'drag_utils_gtk.cc'], @@ -542,6 +535,11 @@ '<(DEPTH)/third_party/wtl/include', ], }], + ['use_x11==0', { + 'sources!': [ + 'events/event_x.cc', + ], + }], ], }, { diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index b6a2280..21eda27 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -42,8 +42,8 @@ #include "views/window/hit_test.h" #if defined(TOUCH_UI) +#include "ui/base/touch/touch_factory.h" #include "views/widget/tooltip_manager_views.h" -#include "views/touchui/touch_factory.h" #else #include "views/widget/tooltip_manager_gtk.h" #endif @@ -380,7 +380,7 @@ NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) #if defined(TOUCH_UI) // Make sure the touch factory is initialized so that it can setup XInput2 for // the widget. - TouchFactory::GetInstance(); + ui::TouchFactory::GetInstance(); #endif static bool installed_message_loop_observer = false; if (!installed_message_loop_observer) { @@ -926,7 +926,7 @@ void NativeWidgetGtk::SetMouseCapture() { ::Window window = GDK_WINDOW_XID(window_contents()->window); Display* display = GDK_WINDOW_XDISPLAY(window_contents()->window); bool xi2grab = - TouchFactory::GetInstance()->GrabTouchDevices(display, window); + ui::TouchFactory::GetInstance()->GrabTouchDevices(display, window); // xi2grab should always succeed if has_pointer_grab_ succeeded. DCHECK(xi2grab); has_pointer_grab_ = has_pointer_grab_ && xi2grab; @@ -946,7 +946,7 @@ void NativeWidgetGtk::ReleaseMouseCapture() { has_pointer_grab_ = false; gdk_pointer_ungrab(GDK_CURRENT_TIME); #if defined(TOUCH_UI) - TouchFactory::GetInstance()->UngrabTouchDevices( + ui::TouchFactory::GetInstance()->UngrabTouchDevices( GDK_WINDOW_XDISPLAY(window_contents()->window)); #endif } @@ -1310,9 +1310,9 @@ void NativeWidgetGtk::SchedulePaintInRect(const gfx::Rect& rect) { void NativeWidgetGtk::SetCursor(gfx::NativeCursor cursor) { #if defined(TOUCH_UI) - if (TouchFactory::GetInstance()->keep_mouse_cursor()) + if (ui::TouchFactory::GetInstance()->keep_mouse_cursor()) cursor = gfx::GetCursor(GDK_ARROW); - else if (!TouchFactory::GetInstance()->is_cursor_visible()) + else if (!ui::TouchFactory::GetInstance()->is_cursor_visible()) cursor = gfx::GetCursor(GDK_BLANK_CURSOR); #endif // |window_contents_| is placed on top of |widget_|. So the cursor needs to be @@ -1694,7 +1694,7 @@ gboolean NativeWidgetGtk::OnFocusOut(GtkWidget* widget, GdkEventFocus* event) { } gboolean NativeWidgetGtk::OnEventKey(GtkWidget* widget, GdkEventKey* event) { - KeyEvent key(reinterpret_cast<NativeEvent>(event)); + KeyEvent key(reinterpret_cast<GdkEvent*>(event)); InputMethod* input_method = GetWidget()->GetInputMethod(); if (input_method) input_method->DispatchKeyEvent(key); @@ -1751,7 +1751,7 @@ gboolean NativeWidgetGtk::OnGrabBrokeEvent(GtkWidget* widget, GdkEvent* event) { ReleaseMouseCapture(); #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) - TouchFactory::GetInstance()->UngrabTouchDevices( + ui::TouchFactory::GetInstance()->UngrabTouchDevices( GDK_WINDOW_XDISPLAY(window_contents()->window)); #endif return false; // To let other widgets get the event. @@ -1846,7 +1846,7 @@ void NativeWidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { // To prevent GtkWindow from handling the key event as a keybinding, we need // to bypass GtkWindow's default key event handler and dispatch the event // here. - GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); + GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.gdk_event()); if (!handled && event && GTK_IS_WINDOW(widget_)) handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event); |