diff options
author | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 17:14:33 +0000 |
---|---|---|
committer | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 17:14:33 +0000 |
commit | e4dd339604ada87f8479c4d509911feb10b0e7fe (patch) | |
tree | 9419aa990fc8331d48d4a62c4aab4dd7af9c99c1 /ui | |
parent | 7a6b150c5b41a4aaf265284b930c96721a1ed15c (diff) | |
download | chromium_src-e4dd339604ada87f8479c4d509911feb10b0e7fe.zip chromium_src-e4dd339604ada87f8479c4d509911feb10b0e7fe.tar.gz chromium_src-e4dd339604ada87f8479c4d509911feb10b0e7fe.tar.bz2 |
Consolidate ui::NativeEvent and base::NativeEvent
Note: I didn't add Wayland version of NativeEvent because the type is defined in ui, which base shouldn't depend on. I looked at the original CL and this typedef in message_pump_wayland seems to be added after reviewer gave LGTM.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8113028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104123 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/desktop.cc | 2 | ||||
-rw-r--r-- | ui/aura/desktop.h | 2 | ||||
-rw-r--r-- | ui/aura/event.cc | 13 | ||||
-rw-r--r-- | ui/aura/event.h | 15 | ||||
-rw-r--r-- | ui/base/events.h | 39 | ||||
-rw-r--r-- | ui/base/wayland/events_wayland.cc | 14 | ||||
-rw-r--r-- | ui/base/win/events_win.cc | 28 | ||||
-rw-r--r-- | ui/base/x/events_x.cc | 14 |
8 files changed, 55 insertions, 72 deletions
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc index 6af7e40..a01c2b1 100644 --- a/ui/aura/desktop.cc +++ b/ui/aura/desktop.cc @@ -133,7 +133,7 @@ void Desktop::WindowDestroying(Window* window) { SetActiveWindow(GetTopmostWindowToActivate(window), NULL); } -bool Desktop::DispatchNativeEvent(const ui::NativeEvent& event) { +bool Desktop::DispatchNativeEvent(const base::NativeEvent& event) { // TODO(oshima): consolidate windows and linux. #if defined(OS_WIN) return host_->Dispatch(event); diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h index dcbea6d..e944dcb 100644 --- a/ui/aura/desktop.h +++ b/ui/aura/desktop.h @@ -93,7 +93,7 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate { void WindowDestroying(Window* window); // Dispatch NativeEvent. - bool DispatchNativeEvent(const ui::NativeEvent& event); + bool DispatchNativeEvent(const base::NativeEvent& event); static Desktop* GetInstance(); diff --git a/ui/aura/event.cc b/ui/aura/event.cc index aae9d65..cabeae5 100644 --- a/ui/aura/event.cc +++ b/ui/aura/event.cc @@ -15,7 +15,9 @@ Event::Event(ui::EventType type, int flags) Init(); } -Event::Event(const ui::NativeEvent& native_event, ui::EventType type, int flags) +Event::Event(const base::NativeEvent& native_event, + ui::EventType type, + int flags) : type_(type), time_stamp_(base::Time::NowFromSystemTime()), flags_(flags) { @@ -33,11 +35,11 @@ void Event::Init() { memset(&native_event_, 0, sizeof(native_event_)); } -void Event::InitWithNativeEvent(const ui::NativeEvent& native_event) { +void Event::InitWithNativeEvent(const base::NativeEvent& native_event) { native_event_ = native_event; } -LocatedEvent::LocatedEvent(const ui::NativeEvent& native_event) +LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) : Event(native_event, ui::EventTypeFromNative(native_event), ui::EventFlagsFromNative(native_event)), @@ -60,7 +62,7 @@ LocatedEvent::LocatedEvent(ui::EventType type, location_(location) { } -MouseEvent::MouseEvent(const ui::NativeEvent& native_event) +MouseEvent::MouseEvent(const base::NativeEvent& native_event) : LocatedEvent(native_event) { } @@ -82,7 +84,7 @@ MouseEvent::MouseEvent(ui::EventType type, : LocatedEvent(type, location, flags) { } -KeyEvent::KeyEvent(const ui::NativeEvent& native_event) +KeyEvent::KeyEvent(const base::NativeEvent& native_event) : Event(native_event, ui::EventTypeFromNative(native_event), ui::EventFlagsFromNative(native_event)), @@ -97,4 +99,3 @@ KeyEvent::KeyEvent(ui::EventType type, } } // namespace aura - diff --git a/ui/aura/event.h b/ui/aura/event.h index f619c12..a084f87 100644 --- a/ui/aura/event.h +++ b/ui/aura/event.h @@ -7,6 +7,7 @@ #pragma once #include "base/basictypes.h" +#include "base/event_types.h" #include "base/time.h" #include "ui/aura/aura_export.h" #include "ui/base/events.h" @@ -19,14 +20,14 @@ class Window; class AURA_EXPORT Event { public: - const ui::NativeEvent& native_event() const { return native_event_; } + const base::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(const ui::NativeEvent& native_event, ui::EventType type, int flags); + Event(const base::NativeEvent& native_event, ui::EventType type, int flags); Event(const Event& copy); void set_type(ui::EventType type) { type_ = type; } @@ -35,9 +36,9 @@ class AURA_EXPORT Event { // Safely initializes the native event members of this class. void Init(); - void InitWithNativeEvent(const ui::NativeEvent& native_event); + void InitWithNativeEvent(const base::NativeEvent& native_event); - ui::NativeEvent native_event_; + base::NativeEvent native_event_; ui::EventType type_; base::Time time_stamp_; int flags_; @@ -50,7 +51,7 @@ class AURA_EXPORT LocatedEvent : public Event { gfx::Point location() const { return location_; } protected: - explicit LocatedEvent(const ui::NativeEvent& native_event); + explicit LocatedEvent(const base::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 @@ -68,7 +69,7 @@ class AURA_EXPORT LocatedEvent : public Event { class AURA_EXPORT MouseEvent : public LocatedEvent { public: - explicit MouseEvent(const ui::NativeEvent& native_event); + explicit MouseEvent(const base::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 @@ -88,7 +89,7 @@ class AURA_EXPORT MouseEvent : public LocatedEvent { class AURA_EXPORT KeyEvent : public Event { public: - explicit KeyEvent(const ui::NativeEvent& native_event); + explicit KeyEvent(const base::NativeEvent& native_event); // Used for synthetic events in testing. KeyEvent(ui::EventType type, diff --git a/ui/base/events.h b/ui/base/events.h index b0f3824..21b59db 100644 --- a/ui/base/events.h +++ b/ui/base/events.h @@ -6,6 +6,7 @@ #define UI_BASE_EVENTS_H_ #pragma once +#include "base/event_types.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/gfx/native_widget_types.h" @@ -13,26 +14,7 @@ namespace gfx { class Point; } -#if defined(USE_X11) -typedef union _XEvent XEvent; -#endif -#if defined(USE_WAYLAND) namespace ui { -union WaylandEvent; -} -#endif - -namespace ui { - -#if defined(OS_WIN) -typedef MSG NativeEvent; -#elif defined(USE_WAYLAND) -typedef ui::WaylandEvent* NativeEvent; -#elif defined(USE_X11) -typedef XEvent* NativeEvent; -#else -typedef void* NativeEvent; -#endif // Event types. (prefixed because of a conflict with windows headers) enum EventType { @@ -55,10 +37,7 @@ enum EventType { ET_FOCUS_CHANGE, }; -// Event flags currently supported. Although this is a "views" -// file, this header is used on non-views platforms (e.g. OSX). For -// example, these EventFlags are used by the automation provider for -// all platforms. +// Event flags currently supported enum EventFlags { EF_CAPS_LOCK_DOWN = 1 << 0, EF_SHIFT_DOWN = 1 << 1, @@ -92,22 +71,24 @@ enum TouchStatus { }; // Get the EventType from a native event. -UI_EXPORT EventType EventTypeFromNative(const NativeEvent& native_event); +UI_EXPORT EventType EventTypeFromNative(const base::NativeEvent& native_event); // Get the EventFlags from a native event. -UI_EXPORT int EventFlagsFromNative(const NativeEvent& native_event); +UI_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event); // Get the location from a native event. -UI_EXPORT gfx::Point EventLocationFromNative(const NativeEvent& native_event); +UI_EXPORT gfx::Point EventLocationFromNative( + const base::NativeEvent& native_event); // Returns the KeyboardCode from a native event. -UI_EXPORT KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event); +UI_EXPORT KeyboardCode KeyboardCodeFromNative( + const base::NativeEvent& native_event); // Returns true if the message is a mouse event. -UI_EXPORT bool IsMouseEvent(const NativeEvent& native_event); +UI_EXPORT bool IsMouseEvent(const base::NativeEvent& native_event); // Get the mouse wheel offset from a native event. -UI_EXPORT int GetMouseWheelOffset(const NativeEvent& native_event); +UI_EXPORT int GetMouseWheelOffset(const base::NativeEvent& native_event); } // namespace ui diff --git a/ui/base/wayland/events_wayland.cc b/ui/base/wayland/events_wayland.cc index 35d5c09..df6ffac 100644 --- a/ui/base/wayland/events_wayland.cc +++ b/ui/base/wayland/events_wayland.cc @@ -36,7 +36,7 @@ int GetEventFlagsFromState(unsigned int state) { return flags; } -int GetButtonEventFlagsFromNativeEvent(const ui::NativeEvent& native_event) { +int GetButtonEventFlagsFromNativeEvent(const base::NativeEvent& native_event) { // TODO(dnicoara): Need to add double click. int flags = 0; switch (native_event->button.button) { @@ -54,7 +54,7 @@ int GetButtonEventFlagsFromNativeEvent(const ui::NativeEvent& native_event) { namespace ui { -EventType EventTypeFromNative(const NativeEvent& native_event) { +EventType EventTypeFromNative(const base::NativeEvent& native_event) { switch (native_event->type) { case WAYLAND_BUTTON: switch (native_event->button.button) { @@ -85,7 +85,7 @@ EventType EventTypeFromNative(const NativeEvent& native_event) { return ET_UNKNOWN; } -int EventFlagsFromNative(const NativeEvent& native_event) { +int EventFlagsFromNative(const base::NativeEvent& native_event) { switch (native_event->type) { case WAYLAND_BUTTON: return GetButtonEventFlagsFromNativeEvent(native_event) | @@ -101,7 +101,7 @@ int EventFlagsFromNative(const NativeEvent& native_event) { } } -gfx::Point EventLocationFromNative(const NativeEvent& native_event) { +gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { switch (native_event->type) { case WAYLAND_BUTTON: return gfx::Point(native_event->button.x, native_event->button.y); @@ -115,17 +115,17 @@ gfx::Point EventLocationFromNative(const NativeEvent& native_event) { } } -KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) { +KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { return KeyboardCodeFromXKeysym(native_event->key.sym); } -bool IsMouseEvent(const NativeEvent& native_event) { +bool IsMouseEvent(const base::NativeEvent& native_event) { return native_event->type == WAYLAND_BUTTON || native_event->type == WAYLAND_MOTION || native_event->type == WAYLAND_POINTER_FOCUS; } -int GetMouseWheelOffset(const NativeEvent& native_event) { +int GetMouseWheelOffset(const base::NativeEvent& native_event) { return native_event->button.button == ui::SCROLL_UP ? kWheelScrollAmount : -kWheelScrollAmount; } diff --git a/ui/base/win/events_win.cc b/ui/base/win/events_win.cc index bb28c1d..47edce7 100644 --- a/ui/base/win/events_win.cc +++ b/ui/base/win/events_win.cc @@ -13,7 +13,7 @@ namespace { // Get the native mouse key state from the native event message type. -int GetNativeMouseKey(const ui::NativeEvent& native_event) { +int GetNativeMouseKey(const base::NativeEvent& native_event) { switch (native_event.message) { case WM_LBUTTONDBLCLK: case WM_LBUTTONDOWN: @@ -47,26 +47,26 @@ int GetNativeMouseKey(const ui::NativeEvent& native_event) { return 0; } -bool IsButtonDown(const ui::NativeEvent& native_event) { +bool IsButtonDown(const base::NativeEvent& native_event) { return ((MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2) & native_event.wParam) != 0; } -bool IsClientMouseEvent(const ui::NativeEvent& native_event) { +bool IsClientMouseEvent(const base::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 ui::NativeEvent& native_event) { +bool IsNonClientMouseEvent(const base::NativeEvent& native_event) { return native_event.message == WM_NCMOUSELEAVE || native_event.message == WM_NCMOUSEHOVER || (native_event.message >= WM_NCMOUSEMOVE && native_event.message <= WM_NCXBUTTONDBLCLK); } -bool IsDoubleClickMouseEvent(const ui::NativeEvent& native_event) { +bool IsDoubleClickMouseEvent(const base::NativeEvent& native_event) { return native_event.message == WM_NCLBUTTONDBLCLK || native_event.message == WM_NCMBUTTONDBLCLK || native_event.message == WM_NCRBUTTONDBLCLK || @@ -77,7 +77,7 @@ bool IsDoubleClickMouseEvent(const ui::NativeEvent& native_event) { native_event.message == WM_XBUTTONDBLCLK; } -bool IsKeyEvent(const ui::NativeEvent& native_event) { +bool IsKeyEvent(const base::NativeEvent& native_event) { return native_event.message == WM_KEYDOWN || native_event.message == WM_SYSKEYDOWN || native_event.message == WM_CHAR || @@ -87,7 +87,7 @@ bool IsKeyEvent(const ui::NativeEvent& native_event) { // Returns a mask corresponding to the set of pressed modifier keys. // Checks the current global state and the state sent by client mouse messages. -int KeyStateFlagsFromNative(const ui::NativeEvent& native_event) { +int KeyStateFlagsFromNative(const base::NativeEvent& native_event) { int flags = 0; flags |= (GetKeyState(VK_MENU) & 0x80) ? ui::EF_ALT_DOWN : 0; flags |= (GetKeyState(VK_SHIFT) & 0x80) ? ui::EF_SHIFT_DOWN : 0; @@ -109,7 +109,7 @@ int KeyStateFlagsFromNative(const ui::NativeEvent& native_event) { // Returns a mask corresponding to the set of pressed mouse buttons. // This includes the button of the given message, even if it is being released. -int MouseStateFlagsFromNative(const ui::NativeEvent& native_event) { +int MouseStateFlagsFromNative(const base::NativeEvent& native_event) { // 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. Instead, we need to track the modified button @@ -133,7 +133,7 @@ int MouseStateFlagsFromNative(const ui::NativeEvent& native_event) { namespace ui { -EventType EventTypeFromNative(const NativeEvent& native_event) { +EventType EventTypeFromNative(const base::NativeEvent& native_event) { switch (native_event.message) { case WM_KEYDOWN: case WM_SYSKEYDOWN: @@ -183,7 +183,7 @@ EventType EventTypeFromNative(const NativeEvent& native_event) { return ET_UNKNOWN; } -int EventFlagsFromNative(const NativeEvent& native_event) { +int EventFlagsFromNative(const base::NativeEvent& native_event) { int flags = KeyStateFlagsFromNative(native_event); if (IsMouseEvent(native_event)) flags |= MouseStateFlagsFromNative(native_event); @@ -191,7 +191,7 @@ int EventFlagsFromNative(const NativeEvent& native_event) { return flags; } -gfx::Point EventLocationFromNative(const NativeEvent& native_event) { +gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { // Client message. The position is contained in the LPARAM. if (IsClientMouseEvent(native_event)) return gfx::Point(native_event.lParam); @@ -204,16 +204,16 @@ gfx::Point EventLocationFromNative(const NativeEvent& native_event) { return gfx::Point(native_point); } -KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) { +KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { return KeyboardCodeForWindowsKeyCode(native_event.wParam); } -bool IsMouseEvent(const NativeEvent& native_event) { +bool IsMouseEvent(const base::NativeEvent& native_event) { return IsClientMouseEvent(native_event) || IsNonClientMouseEvent(native_event); } -int GetMouseWheelOffset(const NativeEvent& native_event) { +int GetMouseWheelOffset(const base::NativeEvent& native_event) { DCHECK(native_event.message == WM_MOUSEWHEEL); return GET_WHEEL_DELTA_WPARAM(native_event.wParam); } diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc index 1bce88d..71687d4 100644 --- a/ui/base/x/events_x.cc +++ b/ui/base/x/events_x.cc @@ -66,7 +66,7 @@ int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { return buttonflags; } -ui::EventType GetTouchEventType(const ui::NativeEvent& native_event) { +ui::EventType GetTouchEventType(const base::NativeEvent& native_event) { XIDeviceEvent* event = static_cast<XIDeviceEvent*>(native_event->xcookie.data); #if defined(USE_XI2_MT) @@ -131,7 +131,7 @@ ui::EventType GetTouchEventType(const ui::NativeEvent& native_event) { namespace ui { -EventType EventTypeFromNative(const NativeEvent& native_event) { +EventType EventTypeFromNative(const base::NativeEvent& native_event) { switch (native_event->type) { case KeyPress: return ET_KEY_PRESSED; @@ -176,7 +176,7 @@ EventType EventTypeFromNative(const NativeEvent& native_event) { return ET_UNKNOWN; } -int EventFlagsFromNative(const NativeEvent& native_event) { +int EventFlagsFromNative(const base::NativeEvent& native_event) { switch (native_event->type) { case KeyPress: case KeyRelease: @@ -207,7 +207,7 @@ int EventFlagsFromNative(const NativeEvent& native_event) { return 0; } -gfx::Point EventLocationFromNative(const NativeEvent& native_event) { +gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { switch (native_event->type) { case ButtonPress: case ButtonRelease: @@ -224,11 +224,11 @@ gfx::Point EventLocationFromNative(const NativeEvent& native_event) { return gfx::Point(); } -KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) { +KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { return KeyboardCodeFromXKeyEvent(native_event); } -bool IsMouseEvent(const NativeEvent& native_event) { +bool IsMouseEvent(const base::NativeEvent& native_event) { if (native_event->type == ButtonPress || native_event->type == ButtonRelease || native_event->type == MotionNotify) @@ -243,7 +243,7 @@ bool IsMouseEvent(const NativeEvent& native_event) { return false; } -int GetMouseWheelOffset(const NativeEvent& native_event) { +int GetMouseWheelOffset(const base::NativeEvent& native_event) { if (native_event->type == GenericEvent) { XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); |