summaryrefslogtreecommitdiffstats
path: root/views/events/event.h
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-11 16:51:25 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-11 16:51:25 +0000
commit6545f1cdbbe569d404f916bef157f201028b63a0 (patch)
tree4d849f4aad386cc4cad08f94f314d78cfb7f55a5 /views/events/event.h
parent5d451ad21fc1836a024cabecc1172c32fbe92b03 (diff)
downloadchromium_src-6545f1cdbbe569d404f916bef157f201028b63a0.zip
chromium_src-6545f1cdbbe569d404f916bef157f201028b63a0.tar.gz
chromium_src-6545f1cdbbe569d404f916bef157f201028b63a0.tar.bz2
Adds the ability to construct a KeyEvent from a NativeEvent[2], and converts some code to use it.
Removes some of the Windows-specific stuff from KeyEvent. BUG=72040 TEST=none Review URL: http://codereview.chromium.org/6487002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74614 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/events/event.h')
-rw-r--r--views/events/event.h84
1 files changed, 31 insertions, 53 deletions
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_