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

Side by Side Diff: native_client_sdk/src/doc/devguide/coding/view-focus-input-events.rst

Issue 254033002: [NaCl SDK Docs] Remove links to developers.google.com (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
1 .. _view_focus_input_events: 1 .. _view_focus_input_events:
2 2
3 #################################### 3 ####################################
4 View Change, Focus, and Input Events 4 View Change, Focus, and Input Events
5 #################################### 5 ####################################
6 6
7 .. contents:: 7 .. contents::
8 :local: 8 :local:
9 :backlinks: none 9 :backlinks: none
10 :depth: 2 10 :depth: 2
(...skipping 11 matching lines...) Expand all
22 directories in the Native Client SDK. There is also the 22 directories in the Native Client SDK. There is also the
23 ppapi_simple library that can be used to to implement most of the 23 ppapi_simple library that can be used to to implement most of the
24 boiler plate. The ``pi_generator`` example in 24 boiler plate. The ``pi_generator`` example in
25 ``/examples/demo/pi_generator`` uses ppapi_simple to manage view 25 ``/examples/demo/pi_generator`` uses ppapi_simple to manage view
26 change events and 2D graphics. 26 change events and 2D graphics.
27 27
28 28
29 Overview 29 Overview
30 ======== 30 ========
31 31
32 When a user interacts with the web page using a keyboard, mouse or 32 When a user interacts with the web page using a keyboard, mouse or some other
33 some other input device, the browser generates input events. 33 input device, the browser generates input events. In a traditional web
34 In a traditional web application, these input events are 34 application, these input events are passed to and handled in JavaScript,
35 passed to and handled in JavaScript, typically through event listeners 35 typically through event listeners and event handlers. In a Native Client
36 and event handlers. In a Native Client application, user interaction 36 application, user interaction with an instance of a module (e.g., clicking
37 with an instance of a module (e.g., clicking inside the rectangle 37 inside the rectangle managed by a module) also generates input events, which
38 managed by a module) also generates input events, which are passed to 38 are passed to the module. The browser also passes view change and focus events
39 the module. The browser also passes view change and focus events that 39 that affect a module's instance to the module. Native Client modules can
40 affect a module's instance to the module. Native Client modules can
41 override certain functions in the `pp::Instance 40 override certain functions in the `pp::Instance
42 <https://developers.google.com/native-client/peppercpp/classpp_1_1_instance>`_ 41 </native-client/pepper_stable/cpp/classpp_1_1_instance>`_ class to handle input
43 class to handle input and browser events. These functions are listed in 42 and browser events. These functions are listed in the table below:
44 the table below:
45 43
46 44
47 ====================== =============================== ==================== 45 ====================== =============================== ====================
48 Function Event Use 46 Function Event Use
49 ====================== =============================== ==================== 47 ====================== =============================== ====================
50 ``DidChangeView`` Called when the position, An implementation 48 ``DidChangeView`` Called when the position, An implementation
51 size, or clip rectangle of this function 49 size, or clip rectangle of this function
52 of the module's instance in might check the size 50 of the module's instance in might check the size
53 the browser has changed. of the module 51 the browser has changed. of the module
54 This event also occurs instance's rectangle 52 This event also occurs instance's rectangle
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 ``RequestInputEvents()`` 102 ``RequestInputEvents()``
105 for mouse events and 103 for mouse events and
106 ``RequestFilteringInputEvents`` 104 ``RequestFilteringInputEvents``
107 for keyboard events 105 for keyboard events
108 prior to overriding this 106 prior to overriding this
109 function. 107 function.
110 ====================== =============================== ==================== 108 ====================== =============================== ====================
111 109
112 110
113 These interfaces are found in the `pp::Instance class 111 These interfaces are found in the `pp::Instance class
114 <https://developers.google.com/native-client/dev/peppercpp/classpp_1_1_instance> `_. 112 </native-client/pepper_stable/cpp/classpp_1_1_instance>`_. The sections below
115 The sections below provide examples of how to handle these events. 113 provide examples of how to handle these events.
116 114
117 115
118 Handling browser events 116 Handling browser events
119 ======================= 117 =======================
120 118
121 DidChangeView() 119 DidChangeView()
122 --------------- 120 ---------------
123 121
124 In the ``mouse_lock`` example, ``DidChangeView()`` checks the previous size 122 In the ``mouse_lock`` example, ``DidChangeView()`` checks the previous size
125 of instance's rectangle versus the new size. It also compares 123 of instance's rectangle versus the new size. It also compares
(...skipping 23 matching lines...) Expand all
149 // ... 147 // ...
150 148
151 // Remember if we are fullscreen or not 149 // Remember if we are fullscreen or not
152 was_fullscreen_ = view.IsFullscreen(); 150 was_fullscreen_ = view.IsFullscreen();
153 // ... 151 // ...
154 } 152 }
155 153
156 154
157 For more information about graphics contexts and how to manipulate images, see: 155 For more information about graphics contexts and how to manipulate images, see:
158 156
159 * `pp::ImageData class <https://developers.google.com/native-client/dev/peppercp p/classpp_1_1_image_data>`_ 157 * `pp::ImageData class
160 * `pp::Graphics2D class <https://developers.google.com/native-client/dev/pepperc pp/classpp_1_1_graphics2_d>`_ 158 </native-client/pepper_stable/cpp/classpp_1_1_image_data>`_
159 * `pp::Graphics2D class
160 </native-client/pepper_stable/cpp/classpp_1_1_graphics2_d>`_
161 161
162 162
163 DidChangeFocus() 163 DidChangeFocus()
164 ---------------- 164 ----------------
165 165
166 ``DidChangeFocus()`` is called when you click inside or outside of a 166 ``DidChangeFocus()`` is called when you click inside or outside of a
167 module's instance in the web page. When the instance goes out 167 module's instance in the web page. When the instance goes out
168 of focus (click outside of the instance), you might do something 168 of focus (click outside of the instance), you might do something
169 like stop an animation. When the instance regains focus, you can 169 like stop an animation. When the instance regains focus, you can
170 restart the animation. 170 restart the animation.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 : pp::Instance(instance), event_thread_(NULL), callback_factory_(this) { 203 : pp::Instance(instance), event_thread_(NULL), callback_factory_(this) {
204 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | 204 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL |
205 PP_INPUTEVENT_CLASS_TOUCH); 205 PP_INPUTEVENT_CLASS_TOUCH);
206 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 206 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
207 } 207 }
208 // ... 208 // ...
209 }; 209 };
210 210
211 211
212 ``RequestInputEvents()`` and ``RequestFilteringInputEvents()`` accept a 212 ``RequestInputEvents()`` and ``RequestFilteringInputEvents()`` accept a
213 combination of flags that identify the class of events that the 213 combination of flags that identify the class of events that the instance is
214 instance is requesting to receive. Input event classes are defined in 214 requesting to receive. Input event classes are defined in the
215 the `PP_InputEvent_Class 215 `PP_InputEvent_Class
216 <https://developers.google.com/native-client/dev/pepperc/group___enums.html#gafe 68e3c1031daa4a6496845ff47649cd>`_ 216 </native-client/pepper_stable/c/group___enums.html#gafe68e3c1031daa4a6496845ff47 649cd>`_
217 enumeration in `ppb_input_event.h 217 enumeration in `ppb_input_event.h
218 <https://developers.google.com/native-client/dev/pepperc/ppb__input__event_8h>`_ . 218 </native-client/pepper_stable/c/ppb__input__event_8h>`_.
219 219
220 220
221 Determining and branching on event types 221 Determining and branching on event types
222 ---------------------------------------- 222 ----------------------------------------
223 223
224 In a typical implementation, the ``HandleInputEvent()`` function 224 In a typical implementation, the ``HandleInputEvent()`` function determines the
225 determines the type of each event using the ``GetType()`` function found 225 type of each event using the ``GetType()`` function found in the ``InputEvent``
226 in the ``InputEvent`` class. The ``HandleInputEvent()`` function then uses a 226 class. The ``HandleInputEvent()`` function then uses a switch statement to
227 switch statement to branch on the type of input event. Input events 227 branch on the type of input event. Input events are defined in the
228 are defined in the `PP_InputEvent_Type 228 `PP_InputEvent_Type
229 <https://developers.google.com/native-client/dev/pepperc/group___enums.html#gaca 7296cfec99fcb6646b7144d1d6a0c5>`_ 229 </native-client/pepper_stable/c/group___enums.html#gaca7296cfec99fcb6646b7144d1d 6a0c5>`_
230 enumeration in `ppb_input_event.h 230 enumeration in `ppb_input_event.h
231 <https://developers.google.com/native-client/dev/pepperc/ppb__input__event_8h>`_ . 231 </native-client/pepper_stable/c/ppb__input__event_8h>`_.
232 232
233 .. naclcode:: 233 .. naclcode::
234 234
235 virtual bool HandleInputEvent(const pp::InputEvent& event) { 235 virtual bool HandleInputEvent(const pp::InputEvent& event) {
236 Event* event_ptr = NULL; 236 Event* event_ptr = NULL;
237 switch (event.GetType()) { 237 switch (event.GetType()) {
238 case PP_INPUTEVENT_TYPE_UNDEFINED: 238 case PP_INPUTEVENT_TYPE_UNDEFINED:
239 break; 239 break;
240 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 240 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
241 case PP_INPUTEVENT_TYPE_MOUSEUP: 241 case PP_INPUTEVENT_TYPE_MOUSEUP:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return true; 302 return true;
303 } 303 }
304 304
305 305
306 Notice that the generic ``InputEvent`` received by ``HandleInputEvent()`` is 306 Notice that the generic ``InputEvent`` received by ``HandleInputEvent()`` is
307 converted into a specific type after the event type is 307 converted into a specific type after the event type is
308 determined. The event types handled in the example code are 308 determined. The event types handled in the example code are
309 ``MouseInputEvent``, ``WheelInputEvent``, and ``KeyboardInputEvent``. 309 ``MouseInputEvent``, ``WheelInputEvent``, and ``KeyboardInputEvent``.
310 There are also ``TouchInputEvents``. For the latest list of event types, 310 There are also ``TouchInputEvents``. For the latest list of event types,
311 see the `InputEvent documentation 311 see the `InputEvent documentation
312 <https://developers.google.com/native-client/dev/peppercpp/classpp_1_1_input_eve nt>`_. 312 </native-client/pepper_stable/c/classpp_1_1_input_event>`_.
313 For reference information related to the these event classes, see the 313 For reference information related to the these event classes, see the
314 following documentation: 314 following documentation:
315 315
316 * `pp::MouseInputEvent class <https://developers.google.com/native-client/dev/pe ppercpp/classpp_1_1_mouse_input_event>`_ 316 * `pp::MouseInputEvent class
317 * `pp::WheelInputEvent class <https://developers.google.com/native-client/dev/pe ppercpp/classpp_1_1_wheel_input_event>`_ 317 </native-client/pepper_stable/c/classpp_1_1_mouse_input_event>`_
318 * `pp::KeyboardInputEvent class <https://developers.google.com/native-client/dev /peppercpp/classpp_1_1_keyboard_input_event>`_ 318 * `pp::WheelInputEvent class
319 </native-client/pepper_stable/c/classpp_1_1_wheel_input_event>`_
320 * `pp::KeyboardInputEvent class
321 </native-client/pepper_stable/c/classpp_1_1_keyboard_input_event>`_
319 322
320 323
321 Threading and blocking 324 Threading and blocking
322 ---------------------- 325 ----------------------
323 326
324 ``HandleInputEvent()`` in this example runs on the main module thread. 327 ``HandleInputEvent()`` in this example runs on the main module thread.
325 However, the bulk of the work happens on a separate worker thread (see 328 However, the bulk of the work happens on a separate worker thread (see
326 ``ProcessEventOnWorkerThread``). ``HandleInputEvent()`` puts events in 329 ``ProcessEventOnWorkerThread``). ``HandleInputEvent()`` puts events in
327 the ``event_queue_`` and the worker thread takes events from the 330 the ``event_queue_`` and the worker thread takes events from the
328 ``event_queue_``. This processing happens independently of the main 331 ``event_queue_``. This processing happens independently of the main
329 thread, so as not to slow down the browser. 332 thread, so as not to slow down the browser.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698