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

Side by Side Diff: native_client_sdk/doc_generated/devguide/coding/view-focus-input-events.html

Issue 438403003: [NaCl SDK Docs] Only generate one top-level <section> element. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 {{+bindTo:partials.standard_nacl_api}} 1 {{+bindTo:partials.standard_nacl_api}}
2 2
3 <section id="view-change-focus-and-input-events"> 3 <section id="view-change-focus-and-input-events">
4 <h1 id="view-change-focus-and-input-events">View Change, Focus, and Input Events </h1> 4 <h1 id="view-change-focus-and-input-events">View Change, Focus, and Input Events </h1>
5 <div class="contents local" id="contents" style="display: none"> 5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap"> 6 <ul class="small-gap">
7 <li><a class="reference internal" href="#overview" id="id2">Overview</a></li> 7 <li><a class="reference internal" href="#overview" id="id2">Overview</a></li>
8 <li><p class="first"><a class="reference internal" href="#handling-browser-event s" id="id3">Handling browser events</a></p> 8 <li><p class="first"><a class="reference internal" href="#handling-browser-event s" id="id3">Handling browser events</a></p>
9 <ul class="small-gap"> 9 <ul class="small-gap">
10 <li><a class="reference internal" href="#didchangeview" id="id4">DidChangeView() </a></li> 10 <li><a class="reference internal" href="#didchangeview" id="id4">DidChangeView() </a></li>
(...skipping 16 matching lines...) Expand all
27 programming techniques. The <code>input_events</code> example is used to 27 programming techniques. The <code>input_events</code> example is used to
28 illustrate how your module can react to keyboard and mouse input 28 illustrate how your module can react to keyboard and mouse input
29 event. The <code>mouse_lock</code> example is used to illustrate how your modul e 29 event. The <code>mouse_lock</code> example is used to illustrate how your modul e
30 can react to view change events. You can find these examples in the 30 can react to view change events. You can find these examples in the
31 <code>/examples/api/input_events</code> and <code>/examples/api/mouse_lock</code > 31 <code>/examples/api/input_events</code> and <code>/examples/api/mouse_lock</code >
32 directories in the Native Client SDK. There is also the 32 directories in the Native Client SDK. There is also the
33 ppapi_simple library that can be used to to implement most of the 33 ppapi_simple library that can be used to to implement most of the
34 boiler plate. The <code>pi_generator</code> example in 34 boiler plate. The <code>pi_generator</code> example in
35 <code>/examples/demo/pi_generator</code> uses ppapi_simple to manage view 35 <code>/examples/demo/pi_generator</code> uses ppapi_simple to manage view
36 change events and 2D graphics.</p> 36 change events and 2D graphics.</p>
37 <section id="overview">
38 <h2 id="overview">Overview</h2> 37 <h2 id="overview">Overview</h2>
39 <p>When a user interacts with the web page using a keyboard, mouse or some other 38 <p>When a user interacts with the web page using a keyboard, mouse or some other
40 input device, the browser generates input events. In a traditional web 39 input device, the browser generates input events. In a traditional web
41 application, these input events are passed to and handled in JavaScript, 40 application, these input events are passed to and handled in JavaScript,
42 typically through event listeners and event handlers. In a Native Client 41 typically through event listeners and event handlers. In a Native Client
43 application, user interaction with an instance of a module (e.g., clicking 42 application, user interaction with an instance of a module (e.g., clicking
44 inside the rectangle managed by a module) also generates input events, which 43 inside the rectangle managed by a module) also generates input events, which
45 are passed to the module. The browser also passes view change and focus events 44 are passed to the module. The browser also passes view change and focus events
46 that affect a module&#8217;s instance to the module. Native Client modules can 45 that affect a module&#8217;s instance to the module. Native Client modules can
47 override certain functions in the <a class="reference external" href="/native-cl ient/pepper_stable/cpp/classpp_1_1_instance">pp::Instance</a> class to handle in put 46 override certain functions in the <a class="reference external" href="/native-cl ient/pepper_stable/cpp/classpp_1_1_instance">pp::Instance</a> class to handle in put
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 <td>An implementation of 148 <td>An implementation of
150 this function 149 this function
151 examines the input 150 examines the input
152 event type and 151 event type and
153 branches accordingly.</td> 152 branches accordingly.</td>
154 </tr> 153 </tr>
155 </tbody> 154 </tbody>
156 </table> 155 </table>
157 <p>These interfaces are found in the <a class="reference external" href="/native -client/pepper_stable/cpp/classpp_1_1_instance">pp::Instance class</a>. The sec tions below 156 <p>These interfaces are found in the <a class="reference external" href="/native -client/pepper_stable/cpp/classpp_1_1_instance">pp::Instance class</a>. The sec tions below
158 provide examples of how to handle these events.</p> 157 provide examples of how to handle these events.</p>
159 </section><section id="handling-browser-events">
160 <h2 id="handling-browser-events">Handling browser events</h2> 158 <h2 id="handling-browser-events">Handling browser events</h2>
161 <section id="didchangeview">
162 <h3 id="didchangeview">DidChangeView()</h3> 159 <h3 id="didchangeview">DidChangeView()</h3>
163 <p>In the <code>mouse_lock</code> example, <code>DidChangeView()</code> checks t he previous size 160 <p>In the <code>mouse_lock</code> example, <code>DidChangeView()</code> checks t he previous size
164 of instance&#8217;s rectangle versus the new size. It also compares 161 of instance&#8217;s rectangle versus the new size. It also compares
165 other state such as whether or not the app is running in full screen mode. 162 other state such as whether or not the app is running in full screen mode.
166 If none of the state has actually changed, no action is needed. 163 If none of the state has actually changed, no action is needed.
167 However, if the size of the view or other state has changed, it frees the 164 However, if the size of the view or other state has changed, it frees the
168 old graphics context and allocates a new one.</p> 165 old graphics context and allocates a new one.</p>
169 <pre class="prettyprint"> 166 <pre class="prettyprint">
170 void MouseLockInstance::DidChangeView(const pp::View&amp; view) { 167 void MouseLockInstance::DidChangeView(const pp::View&amp; view) {
171 // DidChangeView can get called for many reasons, so we only want to 168 // DidChangeView can get called for many reasons, so we only want to
(...skipping 16 matching lines...) Expand all
188 // Remember if we are fullscreen or not 185 // Remember if we are fullscreen or not
189 was_fullscreen_ = view.IsFullscreen(); 186 was_fullscreen_ = view.IsFullscreen();
190 // ... 187 // ...
191 } 188 }
192 </pre> 189 </pre>
193 <p>For more information about graphics contexts and how to manipulate images, se e:</p> 190 <p>For more information about graphics contexts and how to manipulate images, se e:</p>
194 <ul class="small-gap"> 191 <ul class="small-gap">
195 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp _1_1_image_data">pp::ImageData class</a></li> 192 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp _1_1_image_data">pp::ImageData class</a></li>
196 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp _1_1_graphics2_d">pp::Graphics2D class</a></li> 193 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp _1_1_graphics2_d">pp::Graphics2D class</a></li>
197 </ul> 194 </ul>
198 </section><section id="didchangefocus">
199 <h3 id="didchangefocus">DidChangeFocus()</h3> 195 <h3 id="didchangefocus">DidChangeFocus()</h3>
200 <p><code>DidChangeFocus()</code> is called when you click inside or outside of a 196 <p><code>DidChangeFocus()</code> is called when you click inside or outside of a
201 module&#8217;s instance in the web page. When the instance goes out 197 module&#8217;s instance in the web page. When the instance goes out
202 of focus (click outside of the instance), you might do something 198 of focus (click outside of the instance), you might do something
203 like stop an animation. When the instance regains focus, you can 199 like stop an animation. When the instance regains focus, you can
204 restart the animation.</p> 200 restart the animation.</p>
205 <pre class="prettyprint"> 201 <pre class="prettyprint">
206 void DidChangeFocus(bool focus) { 202 void DidChangeFocus(bool focus) {
207 // Do something like stopping animation or a blinking cursor in 203 // Do something like stopping animation or a blinking cursor in
208 // the instance. 204 // the instance.
209 } 205 }
210 </pre> 206 </pre>
211 </section></section><section id="handling-input-events">
212 <h2 id="handling-input-events">Handling input events</h2> 207 <h2 id="handling-input-events">Handling input events</h2>
213 <p>Input events are events that occur when the user interacts with a 208 <p>Input events are events that occur when the user interacts with a
214 module instance using the mouse, keyboard, or other input device 209 module instance using the mouse, keyboard, or other input device
215 (e.g., touch screen). This section describes how the <code>input_events</code> 210 (e.g., touch screen). This section describes how the <code>input_events</code>
216 example handles input events.</p> 211 example handles input events.</p>
217 <section id="registering-a-module-to-accept-input-events">
218 <h3 id="registering-a-module-to-accept-input-events">Registering a module to acc ept input events</h3> 212 <h3 id="registering-a-module-to-accept-input-events">Registering a module to acc ept input events</h3>
219 <p>Before your module can handle these events, you must register your 213 <p>Before your module can handle these events, you must register your
220 module to accept input events using <code>RequestInputEvents()</code> for mouse 214 module to accept input events using <code>RequestInputEvents()</code> for mouse
221 events and <code>RequestFilteringInputEvents()</code> for keyboard events. For t he 215 events and <code>RequestFilteringInputEvents()</code> for keyboard events. For t he
222 <code>input_events</code> example, this is done in the constructor of the 216 <code>input_events</code> example, this is done in the constructor of the
223 <code>InputEventInstance</code> class:</p> 217 <code>InputEventInstance</code> class:</p>
224 <pre class="prettyprint"> 218 <pre class="prettyprint">
225 class InputEventInstance : public pp::Instance { 219 class InputEventInstance : public pp::Instance {
226 public: 220 public:
227 explicit InputEventInstance(PP_Instance instance) 221 explicit InputEventInstance(PP_Instance instance)
228 : pp::Instance(instance), event_thread_(NULL), callback_factory_(this) { 222 : pp::Instance(instance), event_thread_(NULL), callback_factory_(this) {
229 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | 223 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL |
230 PP_INPUTEVENT_CLASS_TOUCH); 224 PP_INPUTEVENT_CLASS_TOUCH);
231 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 225 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
232 } 226 }
233 // ... 227 // ...
234 }; 228 };
235 </pre> 229 </pre>
236 <p><code>RequestInputEvents()</code> and <code>RequestFilteringInputEvents()</co de> accept a 230 <p><code>RequestInputEvents()</code> and <code>RequestFilteringInputEvents()</co de> accept a
237 combination of flags that identify the class of events that the instance is 231 combination of flags that identify the class of events that the instance is
238 requesting to receive. Input event classes are defined in the 232 requesting to receive. Input event classes are defined in the
239 <a class="reference external" href="/native-client/pepper_stable/c/group___enums .html#gafe68e3c1031daa4a6496845ff47649cd">PP_InputEvent_Class</a> 233 <a class="reference external" href="/native-client/pepper_stable/c/group___enums .html#gafe68e3c1031daa4a6496845ff47649cd">PP_InputEvent_Class</a>
240 enumeration in <a class="reference external" href="/native-client/pepper_stable/ c/ppb__input__event_8h">ppb_input_event.h</a>.</p> 234 enumeration in <a class="reference external" href="/native-client/pepper_stable/ c/ppb__input__event_8h">ppb_input_event.h</a>.</p>
241 </section><section id="determining-and-branching-on-event-types">
242 <h3 id="determining-and-branching-on-event-types">Determining and branching on e vent types</h3> 235 <h3 id="determining-and-branching-on-event-types">Determining and branching on e vent types</h3>
243 <p>In a typical implementation, the <code>HandleInputEvent()</code> function det ermines the 236 <p>In a typical implementation, the <code>HandleInputEvent()</code> function det ermines the
244 type of each event using the <code>GetType()</code> function found in the <code> InputEvent</code> 237 type of each event using the <code>GetType()</code> function found in the <code> InputEvent</code>
245 class. The <code>HandleInputEvent()</code> function then uses a switch statement to 238 class. The <code>HandleInputEvent()</code> function then uses a switch statement to
246 branch on the type of input event. Input events are defined in the 239 branch on the type of input event. Input events are defined in the
247 <a class="reference external" href="/native-client/pepper_stable/c/group___enums .html#gaca7296cfec99fcb6646b7144d1d6a0c5">PP_InputEvent_Type</a> 240 <a class="reference external" href="/native-client/pepper_stable/c/group___enums .html#gaca7296cfec99fcb6646b7144d1d6a0c5">PP_InputEvent_Type</a>
248 enumeration in <a class="reference external" href="/native-client/pepper_stable/ c/ppb__input__event_8h">ppb_input_event.h</a>.</p> 241 enumeration in <a class="reference external" href="/native-client/pepper_stable/ c/ppb__input__event_8h">ppb_input_event.h</a>.</p>
249 <pre class="prettyprint"> 242 <pre class="prettyprint">
250 virtual bool HandleInputEvent(const pp::InputEvent&amp; event) { 243 virtual bool HandleInputEvent(const pp::InputEvent&amp; event) {
251 Event* event_ptr = NULL; 244 Event* event_ptr = NULL;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 <code>MouseInputEvent</code>, <code>WheelInputEvent</code>, and <code>KeyboardIn putEvent</code>. 316 <code>MouseInputEvent</code>, <code>WheelInputEvent</code>, and <code>KeyboardIn putEvent</code>.
324 There are also <code>TouchInputEvents</code>. For the latest list of event type s, 317 There are also <code>TouchInputEvents</code>. For the latest list of event type s,
325 see the <a class="reference external" href="/native-client/pepper_stable/c/class pp_1_1_input_event">InputEvent documentation</a>. 318 see the <a class="reference external" href="/native-client/pepper_stable/c/class pp_1_1_input_event">InputEvent documentation</a>.
326 For reference information related to the these event classes, see the 319 For reference information related to the these event classes, see the
327 following documentation:</p> 320 following documentation:</p>
328 <ul class="small-gap"> 321 <ul class="small-gap">
329 <li><a class="reference external" href="/native-client/pepper_stable/c/classpp_1 _1_mouse_input_event">pp::MouseInputEvent class</a></li> 322 <li><a class="reference external" href="/native-client/pepper_stable/c/classpp_1 _1_mouse_input_event">pp::MouseInputEvent class</a></li>
330 <li><a class="reference external" href="/native-client/pepper_stable/c/classpp_1 _1_wheel_input_event">pp::WheelInputEvent class</a></li> 323 <li><a class="reference external" href="/native-client/pepper_stable/c/classpp_1 _1_wheel_input_event">pp::WheelInputEvent class</a></li>
331 <li><a class="reference external" href="/native-client/pepper_stable/c/classpp_1 _1_keyboard_input_event">pp::KeyboardInputEvent class</a></li> 324 <li><a class="reference external" href="/native-client/pepper_stable/c/classpp_1 _1_keyboard_input_event">pp::KeyboardInputEvent class</a></li>
332 </ul> 325 </ul>
333 </section><section id="threading-and-blocking">
334 <h3 id="threading-and-blocking">Threading and blocking</h3> 326 <h3 id="threading-and-blocking">Threading and blocking</h3>
335 <p><code>HandleInputEvent()</code> in this example runs on the main module threa d. 327 <p><code>HandleInputEvent()</code> in this example runs on the main module threa d.
336 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
337 <code>ProcessEventOnWorkerThread</code>). <code>HandleInputEvent()</code> puts e vents in 329 <code>ProcessEventOnWorkerThread</code>). <code>HandleInputEvent()</code> puts e vents in
338 the <code>event_queue_</code> and the worker thread takes events from the 330 the <code>event_queue_</code> and the worker thread takes events from the
339 <code>event_queue_</code>. This processing happens independently of the main 331 <code>event_queue_</code>. This processing happens independently of the main
340 thread, so as not to slow down the browser.</p> 332 thread, so as not to slow down the browser.</p>
341 </section></section></section> 333 </section>
342 334
343 {{/partials.standard_nacl_api}} 335 {{/partials.standard_nacl_api}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698