Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: ppapi/cpp/input_event.h

Issue 7285010: Implement an input event resource. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_CPP_INPUT_EVENT_H_
6 #define PPAPI_CPP_INPUT_EVENT_H_
7
8 #include "ppapi/c/ppb_input_event.h"
9 #include "ppapi/cpp/resource.h"
10
11 namespace pp {
12
13 class FloatPoint;
14 class Point;
15 class Var;
16
17 /// Represents an input event resource. Normally you will get passed this
18 /// object through the HandleInputEvent on the Instance object.
19 ///
20 /// Typically you would check the type of the event and then create the
21 /// appropriate event-specific object to query the properties.
22 ///
23 /// bool MyInstance::HandleInputEvent(const pp::InputEvent& event) {
24 /// switch (event.GetType()) {
25 /// case PP_INPUTEVENT_TYPE_MOUSE_DOWN {
26 /// pp::MouseInputEvent mouse_event(event);
27 /// return HandleMouseDown(mouse_event.GetMousePosition());
28 /// }
29 /// default:
30 /// return false;
31 /// }
32 class InputEvent : public Resource {
33 public:
34 /// Default constructor that creates an is_null() InputEvent object.
35 InputEvent();
36
37 /// Constructs an input event from the given input event resource ID. The
38 /// InputEvent object will be is_null() if the given resource is not a valid
39 /// input event.
40 InputEvent(PP_Resource input_event_resource);
dmichael (off chromium) 2011/07/05 15:37:24 explicit
41
42 ~InputEvent();
43
44 /// Returns the type of input event for the given input event resource.
45 /// This is valid for all input events. Returns PP_INPUTEVENT_TYPE_UNDEFINED
46 /// if the resource is invalid.
47 PP_InputEvent_Type GetType() const;
48
49 /// Returns the time that the event was generated. This will be before the
50 /// current time since processing and dispatching the event has some overhead.
51 /// Use this value to compare the times the user generated two events without
52 /// being sensitive to variable processing time.
53 ///
54 /// The return value is in time ticks, which is a monotonically increasing
55 /// clock not related to the wall clock time. It will not change if the user
56 /// changes their clock or daylight savings time starts, so can be reliably
57 /// used to compare events. This means, however, that you can't correlate
58 /// event times to a particular time of day on the system clock.
59 PP_TimeTicks GetTimeStamp() const;
60
61 /// Returns a bitfield indicating which modifiers were down at the time of
62 /// the event. This is a combination of the flags in the
63 /// PP_InputEvent_Modifier enum.
64 ///
65 /// @return The modifiers associated with the event, or 0 if the given
66 /// resource is not a valid event resource.
67 uint32_t GetModifiers() const;
68 };
69
70 class MouseInputEvent : public InputEvent {
71 public:
72 /// Constructs an is_null() mouse input event object.
73 MouseInputEvent();
74
75 /// Constructs a mouse input event object from the given generic input
76 /// event. If the given event is itself is_null() or is not a mouse input
77 /// event, the mouse object will be is_null().
78 explicit MouseInputEvent(const InputEvent& event);
79
80 /// Returns the mouse position for a mouse input event.
81 ///
82 /// @return The mouse button associated with mouse down and up events. This
83 /// value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave
84 /// events, and for all non-mouse events.
85 PP_InputEvent_MouseButton GetMouseButton() const;
86
87 /// Returns the pixel location of a mouse input event. This value is in
88 /// floating-point units to support high-resolution input events.
89 ///
90 /// @return The point associated with the mouse event, relative to the upper-
91 /// left of the instance receiving the event. These values can be negative for
92 /// mouse drags. The return value will be (0, 0) for non-mouse events.
93 Point GetMousePosition() const;
94
95 // TODO(brettw) figure out exactly what this means.
96 int32_t GetMouseClickCount() const;
97 };
98
99 class WheelInputEvent : public InputEvent {
100 public:
101 /// Constructs an is_null() wheel input event object.
102 WheelInputEvent();
103
104 /// Constructs a wheel input event object from the given generic input
105 /// event. If the given event is itself is_null() or is not a wheel input
106 /// event, the wheel object will be is_null().
107 explicit WheelInputEvent(const InputEvent& event);
108
109 /// Indicates the amount vertically and horizontally the user has requested
110 /// to scroll by with their mouse wheel. A scroll down or to the right (where
111 /// the content moves up or left) is represented as positive values, and
112 /// a scroll up or to the left (where the content moves down or right) is
113 /// represented as negative values.
114 ///
115 /// The units are either in pixels (when scroll_by_page is false) or pages
116 /// (when scroll_by_page is true). For example, y = -3 means scroll up 3
117 /// pixels when scroll_by_page is false, and scroll up 3 pages when
118 /// scroll_by_page is true.
119 ///
120 /// This amount is system dependent and will take into account the user's
121 /// preferred scroll sensitivity and potentially also nonlinear acceleration
122 /// based on the speed of the scrolling.
123 ///
124 /// Devices will be of varying resolution. Some mice with large detents will
125 /// only generate integer scroll amounts. But fractional values are also
126 /// possible, for example, on some trackpads and newer mice that don't have
127 /// "clicks".
128 FloatPoint GetWheelDelta() const;
129
130 /// The number of "clicks" of the scroll wheel that have produced the
131 /// event. The value may have system-specific acceleration applied to it,
132 /// depending on the device. The positive and negative meanings are the same
133 /// as for GetWheelDelta().
134 ///
135 /// If you are scrolling, you probably want to use the delta values. These
136 /// tick events can be useful if you aren't doing actual scrolling and don't
137 /// want or pixel values. An example may be cycling between different items in
138 /// a game.
139 ///
140 /// You may receive fractional values for the wheel ticks if the mouse wheel
141 /// is high resolution or doesn't have "clicks". If your program wants
142 /// discrete events (as in the "picking items" example) you should accumulate
143 /// fractional click values from multiple messages until the total value
144 /// reaches positive or negative one. This should represent a similar amount
145 /// of scrolling as for a mouse that has a discrete mouse wheel.
146 FloatPoint GetWheelTicks() const;
147
148 // Indicates if the scroll delta x/y indicates pages or lines to
149 // scroll by.
150 //
151 // @return PP_TRUE if the event is a wheel event and the user is scrolling
152 // by pages. PP_FALSE if not or if the resource is not a wheel event.
153 bool GetScrollByPage() const;
154 };
155
156 class KeyboardInputEvent : public InputEvent {
157 public:
158 /// Constructs an is_null() keyboard input event object.
159 KeyboardInputEvent();
160
161 /// Constructs a keyboard input event object from the given generic input
162 /// event. If the given event is itself is_null() or is not a keyboard input
163 /// event, the keybaord object will be is_null().
164 explicit KeyboardInputEvent(const InputEvent& event);
165
166 /// Returns the DOM |keyCode| field for the keyboard event.
167 /// Chrome populates this with the Windows-style Virtual Key code of the key.
168 uint32_t GetKeyCode() const;
169
170 /// Returns the typed character for the given character event.
171 ///
172 /// @return A string var representing a single typed character for character
173 /// input events. For non-character input events the return value will be an
174 /// undefined var.
175 Var GetCharacterText() const;
176 };
177
178 } // namespace pp
179
180 #endif // PPAPI_CPP_INPUT_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698