summaryrefslogtreecommitdiffstats
path: root/views/events
diff options
context:
space:
mode:
Diffstat (limited to 'views/events')
-rw-r--r--views/events/event.cc40
-rw-r--r--views/events/event.h84
-rw-r--r--views/events/event_gtk.cc83
-rw-r--r--views/events/event_utils_win.cc31
-rw-r--r--views/events/event_utils_win.h33
-rw-r--r--views/events/event_win.cc125
-rw-r--r--views/events/event_x.cc50
7 files changed, 342 insertions, 104 deletions
diff --git a/views/events/event.cc b/views/events/event.cc
index 565165b..2a814bd 100644
--- a/views/events/event.cc
+++ b/views/events/event.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -8,12 +8,35 @@
namespace views {
+////////////////////////////////////////////////////////////////////////////////
+// Event, protected:
+
Event::Event(ui::EventType type, int flags)
: type_(type),
time_stamp_(base::Time::NowFromSystemTime()),
flags_(flags) {
+ Init();
+}
+
+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),
+ type_(type),
+ time_stamp_(base::Time::NowFromSystemTime()),
+ flags_(flags) {
+ InitWithNativeEvent2(native_event_2, from_native);
}
+////////////////////////////////////////////////////////////////////////////////
+// LocatedEvent, public:
+
LocatedEvent::LocatedEvent(const LocatedEvent& model, View* from, View* to)
: Event(model),
location_(model.location_) {
@@ -21,14 +44,18 @@ LocatedEvent::LocatedEvent(const LocatedEvent& model, View* from, View* to)
View::ConvertPointToView(from, to, &location_);
}
+////////////////////////////////////////////////////////////////////////////////
+// KeyEvent, public:
+
KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code,
- int event_flags, int repeat_count, int message_flags)
+ int event_flags)
: Event(type, event_flags),
- key_code_(key_code),
- repeat_count_(repeat_count),
- message_flags_(message_flags) {
+ key_code_(key_code) {
}
+////////////////////////////////////////////////////////////////////////////////
+// MouseEvent, public:
+
MouseEvent::MouseEvent(ui::EventType type,
View* from,
View* to,
@@ -43,6 +70,9 @@ MouseEvent::MouseEvent(const MouseEvent& model, View* from, View* to)
: LocatedEvent(model, from, to) {
}
+////////////////////////////////////////////////////////////////////////////////
+// TouchEvent, public:
+
#if defined(TOUCH_UI)
TouchEvent::TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id)
: LocatedEvent(type, gfx::Point(x, y), flags),
diff --git a/views/events/event.h b/views/events/event.h
index 385e49c..5382573 100644
--- a/views/events/event.h
+++ b/views/events/event.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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_EVENT_H_
-#define VIEWS_EVENT_H_
+#ifndef VIEWS_EVENTS_EVENT_H_
+#define VIEWS_EVENTS_EVENT_H_
#pragma once
#include "base/basictypes.h"
@@ -13,10 +13,6 @@
#include "ui/gfx/point.h"
#include "views/native_types.h"
-#if defined(OS_LINUX)
-typedef struct _GdkEventKey GdkEventKey;
-#endif
-
#if defined(TOUCH_UI)
typedef union _XEvent XEvent;
#endif
@@ -44,7 +40,13 @@ class View;
////////////////////////////////////////////////////////////////////////////////
class 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_; }
ui::EventType type() const { return type_; }
const base::Time& time_stamp() const { return time_stamp_; }
int flags() const { return flags_; }
@@ -90,6 +92,12 @@ class Event {
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 Event& model)
: native_event_(model.native_event()),
@@ -101,7 +109,13 @@ class 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_;
ui::EventType type_;
base::Time time_stamp_;
int flags_;
@@ -246,64 +260,28 @@ class TouchEvent : public LocatedEvent {
#endif
////////////////////////////////////////////////////////////////////////////////
-//
// KeyEvent class
//
-// A key event is used for any input event related to the keyboard.
-// Note: this event is about key pressed, not typed characters.
+// KeyEvent encapsulates keyboard input events - key press and release.
//
-////////////////////////////////////////////////////////////////////////////////
class KeyEvent : public Event {
public:
- // Create a new key event
- KeyEvent(ui::EventType type,
- ui::KeyboardCode key_code,
- int event_flags,
- int repeat_count,
- int message_flags);
+ explicit KeyEvent(NativeEvent native_event);
+ explicit KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2);
-#if defined(OS_WIN)
+ // 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
+ // some metadata obtainable from the underlying native event is not present.
+ // TODO(beng): see if we can kill this.
KeyEvent(ui::EventType type,
ui::KeyboardCode key_code,
- int event_flags,
- int repeat_count,
- int message_flags,
- UINT message);
-#endif
-#if defined(OS_LINUX)
- explicit KeyEvent(const GdkEventKey* event);
-
- const GdkEventKey* native_event() const { return native_event_; }
-#endif
-#if defined(TOUCH_UI)
- // Create a key event from an X key event.
- explicit KeyEvent(XEvent* xevent);
-#endif
+ int event_flags);
ui::KeyboardCode key_code() const { return key_code_; }
-#if defined(OS_WIN)
- bool IsExtendedKey() const;
-
- UINT message() const { return message_; }
-#endif
-
- int repeat_count() const { return repeat_count_; }
-
-#if defined(OS_WIN)
- static int GetKeyStateFlags();
-#endif
-
private:
-
ui::KeyboardCode key_code_;
- int repeat_count_;
- int message_flags_;
-#if defined(OS_WIN)
- UINT message_;
-#elif defined(OS_LINUX)
- const GdkEventKey* native_event_;
-#endif
+
DISALLOW_COPY_AND_ASSIGN(KeyEvent);
};
@@ -369,4 +347,4 @@ class DropTargetEvent : public LocatedEvent {
} // namespace views
-#endif // VIEWS_EVENT_H_
+#endif // VIEWS_EVENTS_EVENT_H_
diff --git a/views/events/event_gtk.cc b/views/events/event_gtk.cc
index b74621a..37e06d0 100644
--- a/views/events/event_gtk.cc
+++ b/views/events/event_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,24 +6,37 @@
#include <gdk/gdk.h>
+#include "base/logging.h"
#include "ui/base/keycodes/keyboard_code_conversion_gtk.h"
namespace views {
-KeyEvent::KeyEvent(const GdkEventKey* event)
- : Event(event->type == GDK_KEY_PRESS ?
- ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
- GetFlagsFromGdkState(event->state)),
- // TODO(erg): All these values are iffy.
- key_code_(ui::WindowsKeyCodeForGdkKeyCode(event->keyval)),
- repeat_count_(0),
- message_flags_(0)
-#if !defined(TOUCH_UI)
- , native_event_(event)
-#endif
-{
+namespace {
+
+ui::EventType EventTypeFromNative(NativeEvent native_event) {
+ switch (native_event->type) {
+ case GDK_KEY_PRESS:
+ return ui::ET_KEY_PRESSED;
+ case GDK_KEY_RELEASE:
+ return ui::ET_KEY_RELEASED;
+ 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;
+}
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// Event, public:
+
// static
int Event::GetFlagsFromGdkState(int state) {
int flags = 0;
@@ -44,4 +57,48 @@ int Event::GetFlagsFromGdkState(int state) {
return flags;
}
+////////////////////////////////////////////////////////////////////////////////
+// Event, private:
+
+void Event::Init() {
+ native_event_ = NULL;
+ 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;
+}
+
+#if !defined(TOUCH_UI)
+void Event::InitWithNativeEvent2(NativeEvent2 native_event_2,
+ FromNativeEvent2) {
+ // No one should ever call this on non-Touch Linux.
+ // TODO(beng): remove once we rid views of Gtk/Gdk.
+ NOTREACHED();
+ native_event_2_ = NULL;
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// KeyEvent, public:
+
+KeyEvent::KeyEvent(NativeEvent native_event)
+ : Event(native_event, EventTypeFromNative(native_event),
+ GetFlagsFromGdkState(
+ GetGdkEventKeyFromNative(native_event)->state)),
+ key_code_(ui::WindowsKeyCodeForGdkKeyCode(
+ GetGdkEventKeyFromNative(native_event)->keyval)) {
+}
+
+#if !defined(TOUCH_UI)
+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 Gtk-views.
+ // TODO(beng): remove once we rid views of Gtk/Gdk.
+ NOTREACHED();
+}
+#endif
+
} // namespace views
diff --git a/views/events/event_utils_win.cc b/views/events/event_utils_win.cc
new file mode 100644
index 0000000..7d29271
--- /dev/null
+++ b/views/events/event_utils_win.cc
@@ -0,0 +1,31 @@
+// 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
new file mode 100644
index 0000000..9133864
--- /dev/null
+++ b/views/events/event_utils_win.h
@@ -0,0 +1,33 @@
+// 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"
+
+// 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.
+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_win.cc b/views/events/event_win.cc
index 654d4c2..a31b111 100644
--- a/views/events/event_win.cc
+++ b/views/events/event_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,18 +6,75 @@
#include <windows.h>
+#include "base/logging.h"
+#include "ui/base/keycodes/keyboard_code_conversion_win.h"
+
namespace views {
-KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code,
- int event_flags, int repeat_count, int message_flags,
- UINT message)
- : Event(type, event_flags),
- key_code_(key_code),
- repeat_count_(repeat_count),
- message_flags_(message_flags),
- message_(message) {
+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;
+ if (GetKeyState(VK_MENU) & 0x80)
+ flags |= ui::EF_ALT_DOWN;
+ if (GetKeyState(VK_SHIFT) & 0x80)
+ flags |= ui::EF_SHIFT_DOWN;
+ if (GetKeyState(VK_CONTROL) & 0x80)
+ flags |= ui::EF_CONTROL_DOWN;
+ return flags;
+}
+
+// Convert windows message identifiers to Event types.
+ui::EventType EventTypeFromNative(NativeEvent native_event) {
+ switch (native_event.message) {
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ return ui::ET_KEY_PRESSED;
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ return ui::ET_KEY_RELEASED;
+ case WM_LBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_NCLBUTTONDOWN:
+ case WM_NCMBUTTONDOWN:
+ case WM_NCRBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ return ui::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::ET_MOUSE_RELEASED;
+ case WM_MOUSEMOVE:
+ 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;
}
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// Event, public:
+
int Event::GetWindowsFlags() const {
// TODO: need support for x1/x2.
int result = 0;
@@ -47,23 +104,43 @@ int Event::ConvertWindowsFlags(UINT win_flags) {
return r;
}
-// static
-int KeyEvent::GetKeyStateFlags() {
- // Windows Keyboard messages don't come with control key state as parameters
- // like mouse messages do, so we need to explicitly probe for these key
- // states.
- int flags = 0;
- if (GetKeyState(VK_MENU) & 0x80)
- flags |= ui::EF_ALT_DOWN;
- if (GetKeyState(VK_SHIFT) & 0x80)
- flags |= ui::EF_SHIFT_DOWN;
- if (GetKeyState(VK_CONTROL) & 0x80)
- flags |= ui::EF_CONTROL_DOWN;
- return flags;
+////////////////////////////////////////////////////////////////////////////////
+// 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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// KeyEvent, public:
+
+KeyEvent::KeyEvent(NativeEvent native_event)
+ : Event(native_event,
+ EventTypeFromNative(native_event),
+ GetKeyStateFlags()),
+ key_code_(ui::KeyboardCodeForWindowsKeyCode(native_event.wParam)) {
}
-bool KeyEvent::IsExtendedKey() const {
- return (message_flags_ & KF_EXTENDED) == KF_EXTENDED;
+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();
}
} // namespace views
diff --git a/views/events/event_x.cc b/views/events/event_x.cc
index cce5999..a03fad6 100644
--- a/views/events/event_x.cc
+++ b/views/events/event_x.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -62,6 +62,19 @@ int GetEventFlagsForButton(int button) {
return 0;
}
+ui::EventType EventTypeFromNative(NativeEvent2 native_event) {
+ switch (native_event->type) {
+ case KeyPress:
+ return ui::ET_KEY_PRESSED;
+ case KeyRelease:
+ return ui::ET_KEY_RELEASED;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return ui::ET_UNKNOWN;
+}
+
#if defined(HAVE_XINPUT2)
int GetButtonMaskForX2Event(XIDeviceEvent* xievent) {
int buttonflags = 0;
@@ -212,22 +225,38 @@ int GetMouseEventFlags(XEvent* xev) {
} // namespace
-KeyEvent::KeyEvent(XEvent* xev)
- : Event(xev->type == KeyPress ?
- ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
- GetEventFlagsFromXState(xev->xkey.state)),
- key_code_(ui::KeyboardCodeFromXKeyEvent(xev)),
- repeat_count_(0),
- message_flags_(0),
- native_event_(NULL) {
+////////////////////////////////////////////////////////////////////////////////
+// Event, private:
+
+void Event::InitWithNativeEvent2(NativeEvent2 native_event_2) {
+ native_event_ = NULL;
+ // TODO(beng): remove once we rid views of Gtk/Gdk.
+ native_event_2_ = native_event_2;
}
+////////////////////////////////////////////////////////////////////////////////
+// KeyEvent, public:
+
+KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2)
+ : Event(native_event_2,
+ EventTypeFromNative(native_event_2),
+ GetEventFlagsFromXState(native_event_2->xkey.state),
+ FromNativeEvent2),
+ key_code_(ui::KeyboardCodeFromXKeyEvent(native_event_2)) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// MouseEvent, public:
+
MouseEvent::MouseEvent(XEvent* xev)
: LocatedEvent(GetMouseEventType(xev),
GetMouseEventLocation(xev),
GetMouseEventFlags(xev)) {
}
+////////////////////////////////////////////////////////////////////////////////
+// MouseWheelEvent, public:
+
MouseWheelEvent::MouseWheelEvent(XEvent* xev)
: LocatedEvent(ui::ET_MOUSEWHEEL,
GetMouseEventLocation(xev),
@@ -235,6 +264,9 @@ MouseWheelEvent::MouseWheelEvent(XEvent* xev)
offset_(GetMouseWheelOffset(xev)) {
}
+////////////////////////////////////////////////////////////////////////////////
+// TouchEvent, public:
+
#if defined(HAVE_XINPUT2)
TouchEvent::TouchEvent(XEvent* xev)
: LocatedEvent(GetTouchEventType(xev),