| OLD | NEW |
| 1 // Copyright (c) 2010 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2010 The Native Client Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // C headers | 5 // C headers |
| 6 #include <cassert> | 6 #include <cassert> |
| 7 #include <cstdio> | 7 #include <cstdio> |
| 8 | 8 |
| 9 // C++ headers | 9 // C++ headers |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 // This is the class to which EventInstance delegates event handling. For each | 24 // This is the class to which EventInstance delegates event handling. For each |
| 25 // input event, we append a description of the event on to events_ and then | 25 // input event, we append a description of the event on to events_ and then |
| 26 // printf the event we just received. We expose events_ as a JavaScript | 26 // printf the event we just received. We expose events_ as a JavaScript |
| 27 // property named "events". Each time this property is accessed, we clear it | 27 // property named "events". Each time this property is accessed, we clear it |
| 28 // so that future requests for "events" will only include events that happened | 28 // so that future requests for "events" will only include events that happened |
| 29 // since the last request for "events". | 29 // since the last request for "events". |
| 30 class EventHandler : public pp::deprecated::ScriptableObject { | 30 class EventHandler : public pp::deprecated::ScriptableObject { |
| 31 public: | 31 public: |
| 32 explicit EventHandler(int64_t instance) | 32 explicit EventHandler(PP_Instance instance) |
| 33 : instance_(instance), | 33 : instance_(instance), |
| 34 events_() { | 34 events_() { |
| 35 std::printf("EventHandler created.\n"); | 35 std::printf("EventHandler created.\n"); |
| 36 } | 36 } |
| 37 ~EventHandler() { | 37 ~EventHandler() { |
| 38 std::printf("EventHandler destroyed.\n"); | 38 std::printf("EventHandler destroyed.\n"); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual bool HasProperty(const pp::Var& property_name, pp::Var* exception) { | 41 virtual bool HasProperty(const pp::Var& property_name, pp::Var* exception) { |
| 42 return (property_name.is_string() && | 42 return (property_name.is_string() && |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 << (wheel_event.scroll_by_page ? "true" : "false") | 171 << (wheel_event.scroll_by_page ? "true" : "false") |
| 172 << "\n"; | 172 << "\n"; |
| 173 events_ += stream.str(); | 173 events_ += stream.str(); |
| 174 std::printf("%s", stream.str().c_str()); | 174 std::printf("%s", stream.str().c_str()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 | 177 |
| 178 private: | 178 private: |
| 179 // The resource number of the pp::Instance that created us (for use in | 179 // The resource number of the pp::Instance that created us (for use in |
| 180 // output). | 180 // output). |
| 181 int64_t instance_; | 181 PP_Instance instance_; |
| 182 // A string representing input events, exposed to JavaScript as "events". | 182 // A string representing input events, exposed to JavaScript as "events". |
| 183 // It contains a description of each input event that has happened since the | 183 // It contains a description of each input event that has happened since the |
| 184 // last time the "events" JavaScript property was accessed. | 184 // last time the "events" JavaScript property was accessed. |
| 185 std::string events_; | 185 std::string events_; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 // EventInstance handles input events by passing them to an appropriate function | 188 // EventInstance handles input events by passing them to an appropriate function |
| 189 // on event_handler_. See EventHandler more more information. | 189 // on event_handler_. See EventHandler more more information. |
| 190 class EventInstance : public pp::Instance { | 190 class EventInstance : public pp::Instance { |
| 191 public: | 191 public: |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 280 |
| 281 // Implement the required pp::CreateModule function that creates our specific | 281 // Implement the required pp::CreateModule function that creates our specific |
| 282 // kind of Module (in this case, EventModule). This is part of the glue code | 282 // kind of Module (in this case, EventModule). This is part of the glue code |
| 283 // that makes our example accessible to ppapi. | 283 // that makes our example accessible to ppapi. |
| 284 namespace pp { | 284 namespace pp { |
| 285 Module* CreateModule() { | 285 Module* CreateModule() { |
| 286 std::printf("Creating EventModule.\n"); | 286 std::printf("Creating EventModule.\n"); |
| 287 return new EventModule(); | 287 return new EventModule(); |
| 288 } | 288 } |
| 289 } | 289 } |
| OLD | NEW |