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 /ui/aura | |
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 'ui/aura')
-rw-r--r-- | ui/aura/aura.gyp | 2 | ||||
-rw-r--r-- | ui/aura/event.cc | 28 | ||||
-rw-r--r-- | ui/aura/event.h | 24 | ||||
-rw-r--r-- | ui/aura/event_win.cc | 222 | ||||
-rw-r--r-- | ui/aura/event_x.cc | 193 |
5 files changed, 34 insertions, 435 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index c97ba686..ef34a40 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -34,8 +34,6 @@ 'event.h', 'event_filter.cc', 'event_filter.h', - 'event_win.cc', - 'event_x.cc', 'focus_manager.cc', 'focus_manager.h', 'hit_test.h', diff --git a/ui/aura/event.cc b/ui/aura/event.cc index 6846f2e..aae9d65 100644 --- a/ui/aura/event.cc +++ b/ui/aura/event.cc @@ -15,7 +15,7 @@ Event::Event(ui::EventType type, int flags) Init(); } -Event::Event(NativeEvent native_event, ui::EventType type, int flags) +Event::Event(const ui::NativeEvent& native_event, ui::EventType type, int flags) : type_(type), time_stamp_(base::Time::NowFromSystemTime()), flags_(flags) { @@ -29,6 +29,21 @@ Event::Event(const Event& copy) flags_(copy.flags_) { } +void Event::Init() { + memset(&native_event_, 0, sizeof(native_event_)); +} + +void Event::InitWithNativeEvent(const ui::NativeEvent& native_event) { + native_event_ = native_event; +} + +LocatedEvent::LocatedEvent(const ui::NativeEvent& native_event) + : Event(native_event, + ui::EventTypeFromNative(native_event), + ui::EventFlagsFromNative(native_event)), + location_(ui::EventLocationFromNative(native_event)) { +} + LocatedEvent::LocatedEvent(const LocatedEvent& model, Window* source, Window* target) @@ -45,6 +60,10 @@ LocatedEvent::LocatedEvent(ui::EventType type, location_(location) { } +MouseEvent::MouseEvent(const ui::NativeEvent& native_event) + : LocatedEvent(native_event) { +} + MouseEvent::MouseEvent(const MouseEvent& model, Window* source, Window* target) : LocatedEvent(model, source, target) { } @@ -63,6 +82,13 @@ MouseEvent::MouseEvent(ui::EventType type, : LocatedEvent(type, location, flags) { } +KeyEvent::KeyEvent(const ui::NativeEvent& native_event) + : Event(native_event, + ui::EventTypeFromNative(native_event), + ui::EventFlagsFromNative(native_event)), + key_code_(ui::KeyboardCodeFromNative(native_event)) { +} + KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, int flags) diff --git a/ui/aura/event.h b/ui/aura/event.h index 3560805..f619c12 100644 --- a/ui/aura/event.h +++ b/ui/aura/event.h @@ -13,30 +13,20 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/gfx/point.h" -#if defined(USE_X11) -typedef union _XEvent XEvent; -#endif - namespace aura { -#if defined(OS_WIN) -typedef MSG NativeEvent; -#elif defined(USE_X11) -typedef XEvent* NativeEvent; -#endif - class Window; class AURA_EXPORT Event { public: - const NativeEvent& native_event() const { return native_event_; } + const ui::NativeEvent& native_event() const { return native_event_; } ui::EventType type() const { return type_; } const base::Time& time_stamp() const { return time_stamp_; } int flags() const { return flags_; } protected: Event(ui::EventType type, int flags); - Event(NativeEvent native_event, ui::EventType type, int flags); + Event(const ui::NativeEvent& native_event, ui::EventType type, int flags); Event(const Event& copy); void set_type(ui::EventType type) { type_ = type; } @@ -45,9 +35,9 @@ class AURA_EXPORT Event { // Safely initializes the native event members of this class. void Init(); - void InitWithNativeEvent(NativeEvent native_event); + void InitWithNativeEvent(const ui::NativeEvent& native_event); - NativeEvent native_event_; + ui::NativeEvent native_event_; ui::EventType type_; base::Time time_stamp_; int flags_; @@ -60,7 +50,7 @@ class AURA_EXPORT LocatedEvent : public Event { gfx::Point location() const { return location_; } protected: - explicit LocatedEvent(NativeEvent native_event); + explicit LocatedEvent(const ui::NativeEvent& native_event); // Create a new LocatedEvent which is identical to the provided model. // If source / target windows are provided, the model location will be @@ -78,7 +68,7 @@ class AURA_EXPORT LocatedEvent : public Event { class AURA_EXPORT MouseEvent : public LocatedEvent { public: - explicit MouseEvent(NativeEvent native_event); + explicit MouseEvent(const ui::NativeEvent& native_event); // Create a new MouseEvent which is identical to the provided model. // If source / target windows are provided, the model location will be @@ -98,7 +88,7 @@ class AURA_EXPORT MouseEvent : public LocatedEvent { class AURA_EXPORT KeyEvent : public Event { public: - explicit KeyEvent(NativeEvent native_event); + explicit KeyEvent(const ui::NativeEvent& native_event); // Used for synthetic events in testing. KeyEvent(ui::EventType type, diff --git a/ui/aura/event_win.cc b/ui/aura/event_win.cc deleted file mode 100644 index 6bb6a78..0000000 --- a/ui/aura/event_win.cc +++ /dev/null @@ -1,222 +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 "ui/aura/event.h" - -#include "base/logging.h" -#include "ui/base/keycodes/keyboard_code_conversion_win.h" - -namespace aura { - -namespace { - -bool IsClientMouseEvent(const 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 NativeEvent& native_event) { - return native_event.message == WM_NCMOUSELEAVE || - native_event.message == WM_NCMOUSEHOVER || - (native_event.message >= WM_NCMOUSEMOVE && - native_event.message <= WM_NCXBUTTONDBLCLK); -} - -// 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 - -void Event::Init() { - ZeroMemory(&native_event_, sizeof(native_event_)); -} - -void Event::InitWithNativeEvent(NativeEvent native_event) { - native_event_ = native_event; -} - -LocatedEvent::LocatedEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - EventFlagsFromNative(native_event)), - location_(native_event.pt.x, native_event.pt.y) { -} - -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); - } -} - -KeyEvent::KeyEvent(NativeEvent native_event) - : Event(native_event, - EventTypeFromNative(native_event), - GetKeyStateFlags()), - key_code_(ui::KeyboardCodeForWindowsKeyCode(native_event.wParam)) { -} - -} // namespace aura diff --git a/ui/aura/event_x.cc b/ui/aura/event_x.cc deleted file mode 100644 index 323d6a5..0000000 --- a/ui/aura/event_x.cc +++ /dev/null @@ -1,193 +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 "ui/aura/event.h" - -#include <X11/Xlib.h> -#include <X11/extensions/XInput2.h> - -#include "base/logging.h" -#include "ui/base/keycodes/keyboard_code_conversion_x.h" - -namespace aura { - -namespace { - -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 EventTypeFromNative(NativeEvent 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); - // TODO(sad): Determine if sourceid is a touch device. - 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; -} - -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 = false; // TODO(sad): Determine if xievent->sourceid is a - // touch device. - 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; -} - -} // namespace - -void Event::Init() { - memset(&native_event_, 0, sizeof(native_event_)); -} - -void Event::InitWithNativeEvent(NativeEvent native_event) { - native_event_ = native_event; -} - -LocatedEvent::LocatedEvent(NativeEvent native_event) - : Event(native_event, EventTypeFromNative(native_event), - GetLocatedEventFlags(native_event)), - location_(GetEventLocation(native_event)) { -} - -MouseEvent::MouseEvent(NativeEvent native_event) - : LocatedEvent(native_event) { -} - -KeyEvent::KeyEvent(NativeEvent native_event) - : Event(native_event, - EventTypeFromNative(native_event), - GetEventFlagsFromXState(native_event->xbutton.state)), - key_code_(ui::KeyboardCodeFromXKeyEvent(native_event)) { -} - -} // namespace aura |