summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-26 22:04:44 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-26 22:04:44 +0000
commita3e2de75e309b527cd694b16d23100bbec1710d9 (patch)
tree30f49027fbf74758595ee30b0b301206a4c2becf
parente30e4d816f7e32f2be39f32159e020d3b037de04 (diff)
downloadchromium_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
-rw-r--r--chrome/browser/chrome_browser_main.cc4
-rw-r--r--chrome/browser/chromeos/frame/panel_controller.cc8
-rw-r--r--chrome/browser/ui/views/dropdown_bar_host_gtk.cc2
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc2
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_win.cc4
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_container_native.cc2
-rw-r--r--chrome/common/native_web_keyboard_event_views.cc4
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/event.cc28
-rw-r--r--ui/aura/event.h24
-rw-r--r--ui/aura/event_win.cc222
-rw-r--r--ui/aura/event_x.cc193
-rw-r--r--ui/base/events.h46
-rw-r--r--ui/base/touch/OWNERS1
-rw-r--r--ui/base/touch/touch_factory.cc (renamed from views/touchui/touch_factory.cc)28
-rw-r--r--ui/base/touch/touch_factory.h (renamed from views/touchui/touch_factory.h)14
-rw-r--r--ui/base/wayland/events_wayland.cc133
-rw-r--r--ui/base/win/events_win.cc210
-rw-r--r--ui/base/x/events_x.cc241
-rw-r--r--ui/ui.gyp19
-rw-r--r--ui/ui_views.gypi2
-rw-r--r--ui/views/events/event.cc19
-rw-r--r--ui/views/events/event.h13
-rw-r--r--ui/views/events/event_win.cc187
-rw-r--r--ui/views/native_types.h20
-rw-r--r--ui/views/widget/native_widget.h2
-rw-r--r--ui/views/widget/widget.h2
-rw-r--r--views/controls/menu/menu_controller.cc2
-rw-r--r--views/controls/textfield/textfield.cc4
-rw-r--r--views/events/event.cc70
-rw-r--r--views/events/event.h99
-rw-r--r--views/events/event_aura.cc91
-rw-r--r--views/events/event_gtk.cc214
-rw-r--r--views/events/event_utils_win.cc31
-rw-r--r--views/events/event_utils_win.h34
-rw-r--r--views/events/event_wayland.cc193
-rw-r--r--views/events/event_win.cc288
-rw-r--r--views/events/event_x.cc387
-rw-r--r--views/focus/accelerator_handler_touch.cc30
-rw-r--r--views/ime/input_method_gtk.cc6
-rw-r--r--views/ime/input_method_ibus.cc15
-rw-r--r--views/native_types.h66
-rw-r--r--views/touchui/gesture_manager.cc3
-rw-r--r--views/views.gyp12
-rw-r--r--views/widget/native_widget_gtk.cc18
45 files changed, 1061 insertions, 1934 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 8e6dd57..334957e 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -191,7 +191,7 @@
#endif
#if defined(TOUCH_UI)
-#include "views/touchui/touch_factory.h"
+#include "ui/base/touch/touch_factory.h"
#endif
#if defined(USE_AURA)
@@ -1753,7 +1753,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunInternal() {
#endif
#if defined(TOUCH_UI)
- views::TouchFactory::GetInstance()->set_keep_mouse_cursor(
+ ui::TouchFactory::GetInstance()->set_keep_mouse_cursor(
CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor));
#endif
diff --git a/chrome/browser/chromeos/frame/panel_controller.cc b/chrome/browser/chromeos/frame/panel_controller.cc
index cf3c1c1..a81beff 100644
--- a/chrome/browser/chromeos/frame/panel_controller.cc
+++ b/chrome/browser/chromeos/frame/panel_controller.cc
@@ -268,12 +268,12 @@ bool PanelController::TitleMousePressed(const views::MouseEvent& event) {
dragging_ = false;
#if !defined(TOUCH_UI) && !defined(USE_AURA)
- const GdkEvent* gdk_event = event.native_event();
+ const GdkEvent* gdk_event = event.gdk_event();
GdkEventButton last_button_event = gdk_event->button;
mouse_down_abs_x_ = last_button_event.x_root;
mouse_down_abs_y_ = last_button_event.y_root;
#else
- const XEvent* xev = event.native_event_2();
+ const XEvent* xev = event.native_event();
gfx::Point abs_location = RootLocationFromXEvent(xev);
mouse_down_abs_x_ = abs_location.x();
mouse_down_abs_y_ = abs_location.y();
@@ -332,12 +332,12 @@ bool PanelController::TitleMouseDragged(const views::MouseEvent& event) {
}
#if !defined(TOUCH_UI)
- const GdkEvent* gdk_event = event.native_event();
+ const GdkEvent* gdk_event = event.gdk_event();
GdkEventMotion last_motion_event = gdk_event->motion;
int x_root = last_motion_event.x_root;
int y_root = last_motion_event.y_root;
#else
- const XEvent* xev = event.native_event_2();
+ const XEvent* xev = event.native_event();
gfx::Point abs_location = RootLocationFromXEvent(xev);
int x_root = abs_location.x();
int y_root = abs_location.y();
diff --git a/chrome/browser/ui/views/dropdown_bar_host_gtk.cc b/chrome/browser/ui/views/dropdown_bar_host_gtk.cc
index 32f6c99..7b89a66 100644
--- a/chrome/browser/ui/views/dropdown_bar_host_gtk.cc
+++ b/chrome/browser/ui/views/dropdown_bar_host_gtk.cc
@@ -50,6 +50,6 @@ NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent(
return wke;
#else
- return NativeWebKeyboardEvent(&key_event.native_event()->key);
+ return NativeWebKeyboardEvent(&key_event.gdk_event()->key);
#endif
}
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index b5b7d0b..66fefaa 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -1004,7 +1004,7 @@ void LocationBarView::RefreshPageActionViews() {
#if defined(OS_WIN) && !defined(USE_AURA)
void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) {
- UINT flags = event.GetWindowsFlags();
+ UINT flags = event.native_event().wParam;
gfx::Point screen_point(event.location());
ConvertPointToScreen(this, &screen_point);
if (views::Widget::IsPureViews())
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
index d299409..e5503dc 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
@@ -45,6 +45,7 @@
#include "ui/base/dragdrop/drop_target.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_win.h"
+#include "ui/base/events.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_win.h"
@@ -53,7 +54,6 @@
#include "ui/gfx/canvas_skia.h"
#include "views/controls/textfield/native_textfield_win.h"
#include "views/drag_utils.h"
-#include "views/events/event_utils_win.h"
#include "views/widget/widget.h"
#pragma comment(lib, "oleacc.lib") // Needed for accessibility support.
@@ -994,7 +994,7 @@ bool OmniboxViewWin::SkipDefaultKeyEventProcessing(
// entering special characters. We do translate alt-home.
if (event.IsAltDown() && (key != ui::VKEY_HOME) &&
views::NativeTextfieldWin::IsNumPadDigit(key,
- views::IsExtendedKey(event)))
+ (event.flags() & ui::EF_EXTENDED) != 0))
return true;
// Skip accelerators for key combinations omnibox wants to crack. This list
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_container_native.cc b/chrome/browser/ui/views/tab_contents/tab_contents_container_native.cc
index 69633aa..2ce176a 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_container_native.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_container_native.cc
@@ -83,7 +83,7 @@ bool TabContentsContainer::OnMousePressed(const views::MouseEvent& event) {
}
// It is necessary to look at the native event to determine what special
// button was pressed.
- views::NativeEvent2 native_event = event.native_event_2();
+ views::NativeEvent native_event = event.native_event();
if (!native_event)
return false;
diff --git a/chrome/common/native_web_keyboard_event_views.cc b/chrome/common/native_web_keyboard_event_views.cc
index 4d0a5c9..f36f668 100644
--- a/chrome/common/native_web_keyboard_event_views.cc
+++ b/chrome/common/native_web_keyboard_event_views.cc
@@ -49,9 +49,9 @@ NativeWebKeyboardEventViews::NativeWebKeyboardEventViews(
// |os_event| is a MSG struct, so we can copy it directly.
os_event = event.native_event();
#elif defined(TOOLKIT_USES_GTK)
- if (event.native_event()) {
+ if (event.gdk_event()) {
os_event =
- reinterpret_cast<GdkEventKey*>(gdk_event_copy(event.native_event()));
+ reinterpret_cast<GdkEventKey*>(gdk_event_copy(event.gdk_event()));
nativeKeyCode = os_event->keyval;
} else {
os_event = NULL;
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
diff --git a/ui/base/events.h b/ui/base/events.h
index 03e67d0..b0f3824 100644
--- a/ui/base/events.h
+++ b/ui/base/events.h
@@ -6,8 +6,34 @@
#define UI_BASE_EVENTS_H_
#pragma once
+#include "ui/base/keycodes/keyboard_codes.h"
+#include "ui/gfx/native_widget_types.h"
+
+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 {
ET_UNKNOWN = 0,
@@ -42,6 +68,7 @@ enum EventFlags {
EF_MIDDLE_BUTTON_DOWN = 1 << 5,
EF_RIGHT_BUTTON_DOWN = 1 << 6,
EF_COMMAND_DOWN = 1 << 7, // Only useful on OSX
+ EF_EXTENDED = 1 << 8, // Windows extended key (see WM_KEYDOWN doc)
};
// Flags specific to mouse events
@@ -64,7 +91,24 @@ enum TouchStatus {
// unused touch event was handled.
};
+// Get the EventType from a native event.
+UI_EXPORT EventType EventTypeFromNative(const NativeEvent& native_event);
+
+// Get the EventFlags from a native event.
+UI_EXPORT int EventFlagsFromNative(const NativeEvent& native_event);
+
+// Get the location from a native event.
+UI_EXPORT gfx::Point EventLocationFromNative(const NativeEvent& native_event);
+
+// Returns the KeyboardCode from a native event.
+UI_EXPORT KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event);
+
+// Returns true if the message is a mouse event.
+UI_EXPORT bool IsMouseEvent(const NativeEvent& native_event);
+
+// Get the mouse wheel offset from a native event.
+UI_EXPORT int GetMouseWheelOffset(const NativeEvent& native_event);
+
} // namespace ui
#endif // UI_BASE_EVENTS_H_
-
diff --git a/ui/base/touch/OWNERS b/ui/base/touch/OWNERS
new file mode 100644
index 0000000..b8e32c1
--- /dev/null
+++ b/ui/base/touch/OWNERS
@@ -0,0 +1 @@
+sadrul@chromium.org
diff --git a/views/touchui/touch_factory.cc b/ui/base/touch/touch_factory.cc
index e644bca..c4f72b1 100644
--- a/views/touchui/touch_factory.cc
+++ b/ui/base/touch/touch_factory.cc
@@ -2,7 +2,7 @@
// 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"
+#include "ui/base/touch/touch_factory.h"
#if defined(TOOLKIT_USES_GTK)
// TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only.
@@ -29,25 +29,25 @@ int kCursorIdleSeconds = 5;
// the X device information through Atom name matching.
XIValuatorClassInfo* FindTPValuator(Display* display,
XIDeviceInfo* info,
- views::TouchFactory::TouchParam tp) {
+ ui::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;
+ ui::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" },
+ { ui::TouchFactory::TP_TOUCH_MAJOR, "Abs MT Touch Major" },
+ { ui::TouchFactory::TP_TOUCH_MINOR, "Abs MT Touch Minor" },
+ { ui::TouchFactory::TP_ORIENTATION, "Abs MT Orientation" },
+ { ui::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" },
+ { ui::TouchFactory::TP_SLOT_ID, "Abs MT Slot ID" },
#endif
- { views::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" },
- { views::TouchFactory::TP_LAST_ENTRY, NULL },
+ { ui::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" },
+ { ui::TouchFactory::TP_LAST_ENTRY, NULL },
};
const char* atom_tp = NULL;
@@ -82,7 +82,7 @@ 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);
+ ui::TouchFactory* factory = static_cast<ui::TouchFactory*>(data);
if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL &&
GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD &&
@@ -101,7 +101,7 @@ gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams,
guint realize_signal_id = 0;
guint realize_hook_id = 0;
-void SetupGtkWidgetRealizeNotifier(views::TouchFactory* factory) {
+void SetupGtkWidgetRealizeNotifier(ui::TouchFactory* factory) {
gpointer klass = g_type_class_ref(GTK_TYPE_WIDGET);
g_signal_parse_name("realize", GTK_TYPE_WIDGET,
@@ -122,7 +122,7 @@ void RemoveGtkWidgetRealizeNotifier() {
} // namespace
-namespace views {
+namespace ui {
// static
TouchFactory* TouchFactory::GetInstance() {
@@ -499,4 +499,4 @@ bool TouchFactory::GetTouchParamRange(unsigned int deviceid,
return false;
}
-} // namespace views
+} // namespace ui
diff --git a/views/touchui/touch_factory.h b/ui/base/touch/touch_factory.h
index ca281e4..a461738 100644
--- a/views/touchui/touch_factory.h
+++ b/ui/base/touch/touch_factory.h
@@ -2,8 +2,8 @@
// 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_
+#ifndef UI_BASE_TOUCH_TOUCH_FACTORY_H_
+#define UI_BASE_TOUCH_TOUCH_FACTORY_H_
#pragma once
#include <bitset>
@@ -11,17 +11,17 @@
#include "base/memory/singleton.h"
#include "base/timer.h"
-#include "views/views_export.h"
+#include "ui/base/ui_export.h"
typedef unsigned long Cursor;
typedef unsigned long Window;
typedef struct _XDisplay Display;
typedef union _XEvent XEvent;
-namespace views {
+namespace ui {
// Functions related to determining touch devices.
-class VIEWS_EXPORT TouchFactory {
+class UI_EXPORT TouchFactory {
public:
// Define the touch params following the Multi-touch Protocol.
enum TouchParam {
@@ -201,6 +201,6 @@ class VIEWS_EXPORT TouchFactory {
DISALLOW_COPY_AND_ASSIGN(TouchFactory);
};
-} // namespace views
+} // namespace ui
-#endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_
+#endif // UI_BASE_TOUCH_TOUCH_FACTORY_H_
diff --git a/ui/base/wayland/events_wayland.cc b/ui/base/wayland/events_wayland.cc
new file mode 100644
index 0000000..35d5c09
--- /dev/null
+++ b/ui/base/wayland/events_wayland.cc
@@ -0,0 +1,133 @@
+// 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/base/events.h"
+
+#include <X11/extensions/XInput2.h>
+
+#include "base/logging.h"
+#include "ui/base/keycodes/keyboard_code_conversion_x.h"
+#include "ui/wayland/events/wayland_event.h"
+#include "ui/gfx/point.h"
+
+namespace {
+
+// Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
+static int kWheelScrollAmount = 53;
+
+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(const ui::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;
+}
+
+} // namespace
+
+namespace ui {
+
+EventType EventTypeFromNative(const NativeEvent& native_event) {
+ switch (native_event->type) {
+ case WAYLAND_BUTTON:
+ switch (native_event->button.button) {
+ case LEFT_BUTTON:
+ case RIGHT_BUTTON:
+ case MIDDLE_BUTTON:
+ return native_event->button.state ? ET_MOUSE_PRESSED
+ : ET_MOUSE_RELEASED;
+ case SCROLL_UP:
+ case SCROLL_DOWN:
+ return ET_MOUSEWHEEL;
+ default:
+ break;
+ }
+ break;
+ case WAYLAND_KEY:
+ return native_event->key.state ? ET_KEY_PRESSED : ET_KEY_RELEASED;
+ case WAYLAND_MOTION:
+ return ET_MOUSE_MOVED;
+ case WAYLAND_POINTER_FOCUS:
+ return native_event->pointer_focus.state ? ET_MOUSE_ENTERED
+ : ET_MOUSE_EXITED;
+ case WAYLAND_KEYBOARD_FOCUS:
+ return ET_UNKNOWN;
+ default:
+ break;
+ }
+ return ET_UNKNOWN;
+}
+
+int EventFlagsFromNative(const NativeEvent& native_event) {
+ switch (native_event->type) {
+ case WAYLAND_BUTTON:
+ return GetButtonEventFlagsFromNativeEvent(native_event) |
+ GetEventFlagsFromState(native_event->button.modifiers);
+ case WAYLAND_KEY:
+ return GetEventFlagsFromState(native_event->key.modifiers);
+ case WAYLAND_MOTION:
+ return GetEventFlagsFromState(native_event->motion.modifiers);
+ case WAYLAND_KEYBOARD_FOCUS:
+ return GetEventFlagsFromState(native_event->keyboard_focus.modifiers);
+ default:
+ return 0;
+ }
+}
+
+gfx::Point EventLocationFromNative(const NativeEvent& native_event) {
+ switch (native_event->type) {
+ case WAYLAND_BUTTON:
+ return gfx::Point(native_event->button.x, native_event->button.y);
+ case WAYLAND_MOTION:
+ return gfx::Point(native_event->motion.x, native_event->motion.y);
+ case WAYLAND_POINTER_FOCUS:
+ return gfx::Point(native_event->pointer_focus.x,
+ native_event->pointer_focus.y);
+ default:
+ return gfx::Point();
+ }
+}
+
+KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) {
+ return KeyboardCodeFromXKeysym(native_event->key.sym);
+}
+
+bool IsMouseEvent(const 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) {
+ return native_event->button.button == ui::SCROLL_UP ?
+ kWheelScrollAmount : -kWheelScrollAmount;
+}
+
+} // namespace ui
diff --git a/ui/base/win/events_win.cc b/ui/base/win/events_win.cc
new file mode 100644
index 0000000..e841b28
--- /dev/null
+++ b/ui/base/win/events_win.cc
@@ -0,0 +1,210 @@
+// 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 <windowsx.h>
+
+#include "ui/base/events.h"
+
+#include "base/logging.h"
+#include "ui/base/keycodes/keyboard_code_conversion_win.h"
+#include "ui/gfx/point.h"
+
+namespace {
+
+// Get the native mouse key state from the native event message type.
+int GetNativeMouseKey(const ui::NativeEvent& native_event) {
+ switch (native_event.message) {
+ case WM_LBUTTONDBLCLK:
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONUP:
+ case WM_NCLBUTTONDBLCLK:
+ case WM_NCLBUTTONDOWN:
+ case WM_NCLBUTTONUP:
+ return MK_LBUTTON;
+ case WM_MBUTTONDBLCLK:
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONUP:
+ case WM_NCMBUTTONDBLCLK:
+ case WM_NCMBUTTONDOWN:
+ case WM_NCMBUTTONUP:
+ return MK_MBUTTON;
+ case WM_RBUTTONDBLCLK:
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONUP:
+ case WM_NCRBUTTONDBLCLK:
+ case WM_NCRBUTTONDOWN:
+ case WM_NCRBUTTONUP:
+ return MK_RBUTTON;
+ case WM_NCXBUTTONDBLCLK:
+ case WM_NCXBUTTONDOWN:
+ case WM_NCXBUTTONUP:
+ case WM_XBUTTONDBLCLK:
+ case WM_XBUTTONDOWN:
+ case WM_XBUTTONUP:
+ return MK_XBUTTON1;
+ }
+ return 0;
+}
+
+bool IsButtonDown(const ui::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) {
+ 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) {
+ 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) {
+ return native_event.message == WM_NCLBUTTONDBLCLK ||
+ native_event.message == WM_NCMBUTTONDBLCLK ||
+ native_event.message == WM_NCRBUTTONDBLCLK ||
+ native_event.message == WM_NCXBUTTONDBLCLK ||
+ native_event.message == WM_LBUTTONDBLCLK ||
+ native_event.message == WM_MBUTTONDBLCLK ||
+ native_event.message == WM_RBUTTONDBLCLK ||
+ native_event.message == WM_XBUTTONDBLCLK;
+}
+
+// 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 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;
+ flags |= (HIWORD(native_event.lParam) & KF_EXTENDED) ? ui::EF_EXTENDED : 0;
+
+ // Most client mouse messages include key state information.
+ if (IsClientMouseEvent(native_event)) {
+ int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam);
+ flags |= (win_flags & MK_SHIFT) ? ui::EF_SHIFT_DOWN : 0;
+ flags |= (win_flags & MK_CONTROL) ? ui::EF_CONTROL_DOWN : 0;
+ }
+
+ return flags;
+}
+
+// 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) {
+ // 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
+ // independently and audit event consumers to do the right thing.
+ int win_flags = GetNativeMouseKey(native_event);
+
+ // Client mouse messages provide key states in their WPARAMs.
+ if (IsClientMouseEvent(native_event))
+ win_flags |= GET_KEYSTATE_WPARAM(native_event.wParam);
+
+ int flags = 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;
+ flags |= IsDoubleClickMouseEvent(native_event) ? ui::EF_IS_DOUBLE_CLICK: 0;
+ flags |= IsNonClientMouseEvent(native_event) ? ui::EF_IS_NON_CLIENT : 0;
+ return flags;
+}
+
+} // namespace
+
+namespace ui {
+
+EventType EventTypeFromNative(const NativeEvent& native_event) {
+ switch (native_event.message) {
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ case WM_CHAR:
+ return ET_KEY_PRESSED;
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ return 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 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 ET_MOUSE_RELEASED;
+ case WM_MOUSEMOVE:
+ return IsButtonDown(native_event) ? ET_MOUSE_DRAGGED : ET_MOUSE_MOVED;
+ case WM_NCMOUSEMOVE:
+ return ET_MOUSE_MOVED;
+ case WM_MOUSEWHEEL:
+ return ET_MOUSEWHEEL;
+ case WM_MOUSELEAVE:
+ case WM_NCMOUSELEAVE:
+ return ET_MOUSE_EXITED;
+ default:
+ NOTREACHED();
+ }
+ return ET_UNKNOWN;
+}
+
+int EventFlagsFromNative(const NativeEvent& native_event) {
+ int flags = KeyStateFlagsFromNative(native_event);
+ if (IsMouseEvent(native_event))
+ flags |= MouseStateFlagsFromNative(native_event);
+
+ return flags;
+}
+
+gfx::Point EventLocationFromNative(const NativeEvent& native_event) {
+ // Client message. The position is contained in the LPARAM.
+ if (IsClientMouseEvent(native_event))
+ return gfx::Point(native_event.lParam);
+ DCHECK(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 = { GET_X_LPARAM(native_event.lParam),
+ GET_Y_LPARAM(native_event.lParam) };
+ ScreenToClient(native_event.hwnd, &native_point);
+ return gfx::Point(native_point);
+}
+
+KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) {
+ return KeyboardCodeForWindowsKeyCode(native_event.wParam);
+}
+
+bool IsMouseEvent(const NativeEvent& native_event) {
+ return IsClientMouseEvent(native_event) ||
+ IsNonClientMouseEvent(native_event);
+}
+
+int GetMouseWheelOffset(const NativeEvent& native_event) {
+ DCHECK(native_event.message == WM_MOUSEWHEEL);
+ return GET_WHEEL_DELTA_WPARAM(native_event.wParam);
+}
+
+} // namespace ui
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc
new file mode 100644
index 0000000..2e8f57a
--- /dev/null
+++ b/ui/base/x/events_x.cc
@@ -0,0 +1,241 @@
+// 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/base/events.h"
+
+#include <X11/extensions/XInput2.h>
+
+#include "base/logging.h"
+#include "ui/base/keycodes/keyboard_code_conversion_x.h"
+#include "ui/base/touch/touch_factory.h"
+#include "ui/gfx/point.h"
+
+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(const ui::NativeEvent& native_event) {
+#if defined(USE_XI2_MT)
+ XIEvent* event = static_cast<XIEvent*>(native_event->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 = &native_event->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?
+
+ ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
+ float slot;
+ if (!factory->ExtractTouchParam(*native_event, ui::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(*native_event,
+ ui::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)
+}
+
+} // namespace
+
+namespace ui {
+
+EventType EventTypeFromNative(const NativeEvent& native_event) {
+ switch (native_event->type) {
+ case KeyPress:
+ return ET_KEY_PRESSED;
+ case KeyRelease:
+ return ET_KEY_RELEASED;
+ case ButtonPress:
+ if (native_event->xbutton.button == 4 ||
+ native_event->xbutton.button == 5)
+ return ET_MOUSEWHEEL;
+ return ET_MOUSE_PRESSED;
+ case ButtonRelease:
+ if (native_event->xbutton.button == 4 ||
+ native_event->xbutton.button == 5)
+ return ET_MOUSEWHEEL;
+ return ET_MOUSE_RELEASED;
+ case MotionNotify:
+ if (native_event->xmotion.state &
+ (Button1Mask | Button2Mask | Button3Mask))
+ return ET_MOUSE_DRAGGED;
+ return 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) ?
+ ET_MOUSEWHEEL : ET_MOUSE_PRESSED;
+ case XI_ButtonRelease:
+ return (xievent->detail == 4 || xievent->detail == 5) ?
+ ET_MOUSEWHEEL : ET_MOUSE_RELEASED;
+ case XI_Motion:
+ return GetButtonMaskForX2Event(xievent) ?
+ ET_MOUSE_DRAGGED : ET_MOUSE_MOVED;
+ }
+ }
+ default:
+ NOTREACHED();
+ break;
+ }
+ return ET_UNKNOWN;
+}
+
+int EventFlagsFromNative(const NativeEvent& native_event) {
+ switch (native_event->type) {
+ case KeyPress:
+ case KeyRelease:
+ return GetEventFlagsFromXState(native_event->xbutton.state);
+ case ButtonPress:
+ case ButtonRelease:
+ return GetEventFlagsFromXState(native_event->xbutton.state) |
+ GetEventFlagsForButton(native_event->xbutton.button);
+ case MotionNotify:
+ return GetEventFlagsFromXState(native_event->xmotion.state);
+ case GenericEvent: {
+ XIDeviceEvent* xievent =
+ static_cast<XIDeviceEvent*>(native_event->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;
+}
+
+gfx::Point EventLocationFromNative(const NativeEvent& native_event) {
+ switch (native_event->type) {
+ case ButtonPress:
+ case ButtonRelease:
+ return gfx::Point(native_event->xbutton.x, native_event->xbutton.y);
+ case MotionNotify:
+ return gfx::Point(native_event->xmotion.x, native_event->xmotion.y);
+ case GenericEvent: {
+ XIDeviceEvent* xievent =
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data);
+ return gfx::Point(static_cast<int>(xievent->event_x),
+ static_cast<int>(xievent->event_y));
+ }
+ }
+ return gfx::Point();
+}
+
+KeyboardCode KeyboardCodeFromNative(const NativeEvent& native_event) {
+ return KeyboardCodeFromXKeyEvent(native_event);
+}
+
+bool IsMouseEvent(const NativeEvent& native_event) {
+ if (native_event->type == ButtonPress ||
+ native_event->type == ButtonRelease ||
+ native_event->type == MotionNotify)
+ return true;
+ if (native_event->type == GenericEvent) {
+ XIDeviceEvent* xievent =
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data);
+ return xievent->evtype == XI_ButtonPress ||
+ xievent->evtype == XI_ButtonRelease ||
+ xievent->evtype == XI_Motion;
+ }
+ return false;
+}
+
+int GetMouseWheelOffset(const NativeEvent& native_event) {
+ if (native_event->type == GenericEvent) {
+ XIDeviceEvent* xiev =
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data);
+ return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount;
+ }
+ return native_event->xbutton.button == 4 ?
+ kWheelScrollAmount : -kWheelScrollAmount;
+}
+
+} // namespace ui
diff --git a/ui/ui.gyp b/ui/ui.gyp
index 7bf788c..05ecab0 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -16,10 +16,6 @@
['exclude', 'views/'],
]}],
['touchui==0', {'sources/': [
- ['exclude', 'event_x.cc$'],
- ['exclude', 'native_menu_x.cc$'],
- ['exclude', 'native_menu_x.h$'],
- ['exclude', 'touchui/'],
['exclude', '_(touch)\\.cc$'],
]}],
],
@@ -189,6 +185,8 @@
'base/text/text_elider.h',
'base/theme_provider.cc',
'base/theme_provider.h',
+ 'base/touch/touch_factory.cc',
+ 'base/touch/touch_factory.h',
'base/ui_base_exports.cc',
'base/ui_base_paths.cc',
'base/ui_base_paths.h',
@@ -198,6 +196,8 @@
'base/ui_export.h',
'base/view_prop.cc',
'base/view_prop.h',
+ 'base/wayland/events_wayland.cc',
+ 'base/win/events_win.cc',
'base/win/hwnd_util.cc',
'base/win/hwnd_util.h',
'base/win/ime_input.cc',
@@ -210,6 +210,7 @@
'base/win/window_impl.h',
'base/x/active_window_watcher_x.cc',
'base/x/active_window_watcher_x.h',
+ 'base/x/events_x.cc',
'base/x/x11_util.cc',
'base/x/x11_util.h',
'base/x/x11_util_internal.h',
@@ -409,6 +410,8 @@
],
'sources!': [
'base/clipboard/clipboard_aura.cc',
+ 'base/touch/touch_factory.cc',
+ 'base/touch/touch_factory.h',
'gfx/pango_util.h',
'gfx/pango_util.cc',
'gfx/platform_font_pango.cc',
@@ -454,6 +457,8 @@
}],
['OS=="mac"', {
'sources!': [
+ 'base/touch/touch_factory.cc',
+ 'base/touch/touch_factory.h',
'gfx/pango_util.h',
'gfx/pango_util.cc',
'gfx/platform_font_pango.h',
@@ -482,6 +487,12 @@
'sources!': [
'base/keycodes/keyboard_code_conversion_x.cc',
'base/keycodes/keyboard_code_conversion_x.h',
+ 'base/x/active_window_watcher_x.cc',
+ 'base/x/active_window_watcher_x.h',
+ 'base/x/events_x.cc',
+ 'base/x/x11_util.cc',
+ 'base/x/x11_util.h',
+ 'base/x/x11_util_internal.h',
],
}],
['chromeos==1', {
diff --git a/ui/ui_views.gypi b/ui/ui_views.gypi
index e901918..915cce8 100644
--- a/ui/ui_views.gypi
+++ b/ui/ui_views.gypi
@@ -19,7 +19,6 @@
'views/events/drag_controller.h',
'views/events/event.cc',
'views/events/event.h',
- 'views/events/event_win.cc',
'views/events/focus_event.cc',
'views/events/focus_event.h',
'views/focus/accelerator_handler.h',
@@ -32,7 +31,6 @@
'views/layout/fill_layout.h',
'views/layout/layout_manager.cc',
'views/layout/layout_manager.h',
- 'views/native_types.h',
'views/rendering/border.cc',
'views/rendering/border.h',
'views/view.cc',
diff --git a/ui/views/events/event.cc b/ui/views/events/event.cc
index c4e7697..544c2ad 100644
--- a/ui/views/events/event.cc
+++ b/ui/views/events/event.cc
@@ -50,8 +50,27 @@ LocatedEvent::LocatedEvent(const LocatedEvent& other,
////////////////////////////////////////////////////////////////////////////////
// MouseEvent, public:
+MouseEvent::MouseEvent(const ui::NativeEvent& native_event)
+ : LocatedEvent(ui::EventTypeFromNative(native_event),
+ ui::EventLocationFromNative(native_event),
+ ui::EventFlagsFromNative(native_event)) {
+}
+
MouseEvent::MouseEvent(const MouseEvent& other, View* source, View* target)
: LocatedEvent(other, source, target) {
}
+KeyEvent::KeyEvent(const ui::NativeEvent& native_event)
+ : Event(ui::EventTypeFromNative(native_event),
+ ui::EventFlagsFromNative(native_event)),
+ key_code_(ui::KeyboardCodeFromNative(native_event)) {
+}
+
+MouseWheelEvent::MouseWheelEvent(const ui::NativeEvent& native_event)
+ : LocatedEvent(ui::EventTypeFromNative(native_event),
+ ui::EventLocationFromNative(native_event),
+ ui::EventFlagsFromNative(native_event)),
+ offset_(ui::GetMouseWheelOffset(native_event)) {
+}
+
} // namespace ui
diff --git a/ui/views/events/event.h b/ui/views/events/event.h
index 0eafa83..002608c 100644
--- a/ui/views/events/event.h
+++ b/ui/views/events/event.h
@@ -10,7 +10,6 @@
#include "ui/base/events.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/point.h"
-#include "ui/views/native_types.h"
class OSExchangeData;
@@ -82,7 +81,7 @@ class LocatedEvent : public Event {
class MouseEvent : public LocatedEvent {
public:
- explicit MouseEvent(NativeEvent native_event);
+ explicit MouseEvent(const ui::NativeEvent& native_event);
MouseEvent(const MouseEvent& other, View* source, View* target);
@@ -115,23 +114,19 @@ class MouseEvent : public LocatedEvent {
class KeyEvent : public Event {
public:
- explicit KeyEvent(NativeEvent native_event);
+ explicit KeyEvent(const ui::NativeEvent& native_event);
KeyboardCode key_code() const { return key_code_; }
- int repeat_count() const { return repeat_count_; }
-
private:
KeyboardCode key_code_;
- int repeat_count_;
- int message_flags_;
DISALLOW_COPY_AND_ASSIGN(KeyEvent);
};
class MouseWheelEvent : public LocatedEvent {
public:
- explicit MouseWheelEvent(NativeEvent native_event);
+ explicit MouseWheelEvent(const ui::NativeEvent& native_event);
int offset() const { return offset_; }
@@ -144,7 +139,7 @@ class MouseWheelEvent : public LocatedEvent {
/*
class DropTargetEvent : public LocatedEvent {
public:
- explicit DropTargetEvent(NativeEvent native_event);
+ explicit DropTargetEvent(const ui::NativeEvent& native_event);
const OSExchangeData& data() const { return data_; }
int source_operations() const { return source_operations_; }
diff --git a/ui/views/events/event_win.cc b/ui/views/events/event_win.cc
deleted file mode 100644
index 9259a54c..0000000
--- a/ui/views/events/event_win.cc
+++ /dev/null
@@ -1,187 +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/views/events/event.h"
-
-#include <windowsx.h>
-
-#include "base/logging.h"
-#include "ui/base/keycodes/keyboard_code_conversion_win.h"
-
-namespace ui {
-
-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;
-}
-
-// Convert windows message identifiers to Event types.
-ui::Event::EventType EventTypeFromNative(NativeEvent native_event) {
- switch (native_event.message) {
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- case WM_CHAR:
- return ui::Event::ET_KEY_PRESSED;
- case WM_KEYUP:
- case WM_SYSKEYUP:
- return ui::Event::ET_KEY_RELEASED;
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDOWN:
- case WM_NCLBUTTONDOWN:
- case WM_NCMBUTTONDOWN:
- case WM_NCRBUTTONDOWN:
- case WM_RBUTTONDOWN:
- return ui::Event::ET_MOUSE_PRESSED;
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONUP:
- case WM_MBUTTONDBLCLK:
- case WM_MBUTTONUP:
- case WM_NCLBUTTONDBLCLK:
- case WM_NCLBUTTONUP:
- case WM_NCMBUTTONDBLCLK:
- case WM_NCMBUTTONUP:
- case WM_NCRBUTTONDBLCLK:
- case WM_NCRBUTTONUP:
- case WM_RBUTTONDBLCLK:
- case WM_RBUTTONUP:
- return ui::Event::ET_MOUSE_RELEASED;
- case WM_MOUSEMOVE:
- case WM_NCMOUSEMOVE:
- return ui::Event::ET_MOUSE_MOVED;
- case WM_MOUSEWHEEL:
- return ui::Event::ET_MOUSEWHEEL;
- case WM_MOUSELEAVE:
- case WM_NCMOUSELEAVE:
- return ui::Event::ET_MOUSE_EXITED;
- default:
- NOTREACHED();
- }
- return ui::Event::ET_UNKNOWN;
-}
-
-bool IsClientMouseEvent(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(NativeEvent native_event) {
- return native_event.message == WM_NCMOUSELEAVE ||
- native_event.message == WM_NCMOUSEHOVER ||
- (native_event.message >= WM_NCMOUSEMOVE &&
- native_event.message <= WM_NCXBUTTONDBLCLK);
-}
-
-gfx::Point MousePositionFromNative(NativeEvent native_event) {
- // Client message. The position is contained in the LPARAM.
- if (IsClientMouseEvent(native_event))
- return gfx::Point(native_event.lParam);
- DCHECK(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 = { GET_X_LPARAM(native_event.lParam),
- GET_Y_LPARAM(native_event.lParam) };
- ScreenToClient(native_event.hwnd, &native_point);
- return gfx::Point(native_point);
-}
-
-int MouseEventFlagsFromNative(NativeEvent native_event) {
- int flags = 0;
-
- // Check if the event occurred in the non-client area.
- if (IsNonClientMouseEvent(native_event))
- flags |= ui::MouseEvent::EF_IS_NON_CLIENT;
-
- // Check for double click events.
- switch (native_event.message) {
- case WM_NCLBUTTONDBLCLK:
- case WM_NCMBUTTONDBLCLK:
- case WM_NCRBUTTONDBLCLK:
- case WM_LBUTTONDBLCLK:
- case WM_MBUTTONDBLCLK:
- case WM_RBUTTONDBLCLK:
- flags |= ui::MouseEvent::EF_IS_DOUBLE_CLICK;
- break;
- }
-
- // Check for pressed buttons.
- if (IsClientMouseEvent(native_event)) {
- if (native_event.wParam & MK_LBUTTON)
- flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN;
- if (native_event.wParam & MK_MBUTTON)
- flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN;
- if (native_event.wParam & MK_RBUTTON)
- flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN;
- } else if (IsNonClientMouseEvent(native_event)) {
- switch (native_event.message) {
- case WM_NCLBUTTONDOWN:
- flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN;
- break;
- case WM_NCMBUTTONDOWN:
- flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN;
- break;
- case WM_NCRBUTTONDOWN:
- flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN;
- break;
- }
- }
-
- // Finally make sure the key state flags are included.
- return flags | GetKeyStateFlags();
-}
-
-int MouseWheelEventFlagsFromNative(NativeEvent native_event) {
- int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam);
- int flags = 0;
- flags |= (win_flags & MK_CONTROL) ? ui::MouseEvent::EF_CONTROL_DOWN : 0;
- flags |= (win_flags & MK_SHIFT) ? ui::MouseEvent::EF_SHIFT_DOWN : 0;
- flags |= (GetKeyState(VK_MENU) < 0) ? ui::MouseEvent::EF_ALT_DOWN : 0;
- flags |= (win_flags & MK_LBUTTON) ? ui::MouseEvent::EF_LEFT_BUTTON_DOWN : 0;
- flags |= (win_flags & MK_MBUTTON) ? ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN : 0;
- flags |= (win_flags & MK_RBUTTON) ? ui::MouseEvent::EF_RIGHT_BUTTON_DOWN : 0;
- return flags;
-}
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-// KeyEvent, public:
-
-KeyEvent::KeyEvent(NativeEvent native_event)
- : Event(EventTypeFromNative(native_event), GetKeyStateFlags()),
- key_code_(KeyboardCodeForWindowsKeyCode(native_event.wParam)),
- repeat_count_(native_event.lParam & 0xFFFF),
- message_flags_((native_event.lParam & 0xFFFF0000) >> 16) {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// MouseEvent, public:
-
-MouseEvent::MouseEvent(NativeEvent native_event)
- : LocatedEvent(EventTypeFromNative(native_event),
- MousePositionFromNative(native_event),
- MouseEventFlagsFromNative(native_event)) {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// MouseWheelEvent, public:
-
-MouseWheelEvent::MouseWheelEvent(NativeEvent native_event)
- : LocatedEvent(ET_MOUSEWHEEL,
- MousePositionFromNative(native_event),
- MouseWheelEventFlagsFromNative(native_event)),
- offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) {
-}
-
-} // namespace ui
-
diff --git a/ui/views/native_types.h b/ui/views/native_types.h
deleted file mode 100644
index 73b0358..0000000
--- a/ui/views/native_types.h
+++ /dev/null
@@ -1,20 +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 UI_VIEWS_NATIVE_TYPES_H_
-#define UI_VIEWS_NATIVE_TYPES_H_
-#pragma once
-
-#include "ui/gfx/native_widget_types.h"
-
-namespace ui {
-
-#if defined(OS_WIN)
-typedef MSG NativeEvent;
-#endif
-
-} // namespace ui
-
-#endif // UI_VIEWS_NATIVE_TYPES_H_
-
diff --git a/ui/views/widget/native_widget.h b/ui/views/widget/native_widget.h
index 87bd146..13f0d04 100644
--- a/ui/views/widget/native_widget.h
+++ b/ui/views/widget/native_widget.h
@@ -5,7 +5,7 @@
#ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_H_
#define UI_VIEWS_WIDGET_NATIVE_WIDGET_H_
-#include "ui/views/native_types.h"
+#include "ui/gfx/native_widget_types.h"
namespace gfx{
class Path;
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index 532b8506..af6cdd9 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -8,8 +8,8 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
+#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
-#include "ui/views/native_types.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/widget/native_widget_listener.h"
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/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);