|
OLD | NEW |
---|---|
(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.GetEventType()) { | |
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); | |
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 GetEventType() 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 GetEventTimeStamp() 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 GetEventModifiers() const; | |
68 | |
69 | |
darin (slow to review)
2011/07/01 20:51:15
nit: whitespace
| |
70 }; | |
71 | |
72 class MouseInputEvent : public InputEvent { | |
73 public: | |
74 /// Constructs an is_null() mouse input event object. | |
75 MouseInputEvent(); | |
76 | |
77 /// Constructs a mouse input event object from the given generic input | |
78 /// event. If the given event is itself is_null() or is not a mouse input | |
79 /// event, the mouse object will be is_null(). | |
80 explicit MouseInputEvent(const InputEvent& event); | |
81 | |
82 /// Returns the mouse position for a mouse input event. | |
83 /// | |
84 /// @return The mouse button associated with mouse down and up events. This | |
85 /// value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave | |
86 /// events, and for all non-mouse events. | |
87 PP_InputEvent_MouseButton GetMouseButton() const; | |
88 | |
89 /// Returns the pixel location of a mouse input event. This value is in | |
90 /// floating-point units to support high-resolution input events. | |
91 /// | |
92 /// @return The point associated with the mouse event, relative to the upper- | |
93 /// left of the instance receiving the event. These values can be negative for | |
94 /// mouse drags. The return value will be (0, 0) for non-mouse events. | |
95 Point GetMousePosition() const; | |
96 | |
97 // TODO(brettw) figure out exactly what this means. | |
98 int32_t GetMouseClickCount() const; | |
99 }; | |
100 | |
101 class WheelInputEvent : public InputEvent { | |
102 public: | |
103 /// Constructs an is_null() wheel input event object. | |
104 WheelInputEvent(); | |
105 | |
106 /// Constructs a wheel input event object from the given generic input | |
107 /// event. If the given event is itself is_null() or is not a wheel input | |
108 /// event, the wheel object will be is_null(). | |
109 explicit WheelInputEvent(const InputEvent& event); | |
110 | |
111 /// Indicates the amount vertically and horizontally the user has requested | |
112 /// to scroll by with their mouse wheel. A scroll down or to the right (where | |
113 /// the content moves up or left) is represented as positive values, and | |
114 /// a scroll up or to the left (where the content moves down or right) is | |
115 /// represented as negative values. | |
116 /// | |
117 /// The units are either in pixels (when scroll_by_page is false) or pages | |
118 /// (when scroll_by_page is true). For example, y = -3 means scroll up 3 | |
119 /// pixels when scroll_by_page is false, and scroll up 3 pages when | |
120 /// scroll_by_page is true. | |
121 /// | |
122 /// This amount is system dependent and will take into account the user's | |
123 /// preferred scroll sensitivity and potentially also nonlinear acceleration | |
124 /// based on the speed of the scrolling. | |
125 /// | |
126 /// Devices will be of varying resolution. Some mice with large detents will | |
127 /// only generate integer scroll amounts. But fractional values are also | |
128 /// possible, for example, on some trackpads and newer mice that don't have | |
129 /// "clicks". | |
130 FloatPoint GetWheelDelta() const; | |
131 | |
132 /// The number of "clicks" of the scroll wheel that have produced the | |
133 /// event. The value may have system-specific acceleration applied to it, | |
134 /// depending on the device. The positive and negative meanings are the same | |
135 /// as for GetWheelDelta(). | |
136 /// | |
137 /// If you are scrolling, you probably want to use the delta values. These | |
138 /// tick events can be useful if you aren't doing actual scrolling and don't | |
139 /// want or pixel values. An example may be cycling between different items in | |
140 /// a game. | |
141 /// | |
142 /// You may receive fractional values for the wheel ticks if the mouse wheel | |
143 /// is high resolution or doesn't have "clicks". If your program wants | |
144 /// discrete events (as in the "picking items" example) you should accumulate | |
145 /// fractional click values from multiple messages until the total value | |
146 /// reaches positive or negative one. This should represent a similar amount | |
147 /// of scrolling as for a mouse that has a discrete mouse wheel. | |
148 FloatPoint GetWheelTicks() const; | |
149 }; | |
150 | |
darin (slow to review)
2011/07/01 20:51:15
me being annoying (ignore if you like): should we
brettw
2011/07/01 21:14:52
I thought about it and was on the fence, but decid
| |
151 class KeyboardInputEvent : public InputEvent { | |
152 public: | |
153 /// Constructs an is_null() keyboard input event object. | |
154 KeyboardInputEvent(); | |
155 | |
156 /// Constructs a keyboard input event object from the given generic input | |
157 /// event. If the given event is itself is_null() or is not a keyboard input | |
158 /// event, the keybaord object will be is_null(). | |
159 explicit KeyboardInputEvent(const InputEvent& event); | |
160 | |
161 /// Returns the DOM |keyCode| field for the keyboard event. | |
162 /// Chrome populates this with the Windows-style Virtual Key code of the key. | |
163 uint32_t GetKeyCode() const; | |
164 | |
165 /// Returns the typed character for the given character event. | |
166 /// | |
167 /// @return A string var representing a single typed character for character | |
168 /// input events. For non-character input events the return value will be an | |
169 /// undefined var. | |
170 Var GetCharacterText() const; | |
171 }; | |
172 | |
173 } // namespace pp | |
174 | |
175 #endif // PPAPI_CPP_INPUT_EVENT_H_ | |
OLD | NEW |