Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 #include "ppapi/c/pp_errors.h" | |
| 6 #include "ppapi/cpp/input_event.h" | |
| 7 #include "ppapi/cpp/instance.h" | |
| 8 #include "ppapi/cpp/module.h" | |
| 9 #include "ppapi/utility/completion_callback_factory.h" | |
| 10 #include "ppapi/utility/threading/simple_thread.h" | |
| 11 | |
| 12 class MyInstance : public pp::Instance { | |
| 13 public: | |
| 14 MyInstance(PP_Instance instance) : pp::Instance(instance) { | |
| 15 thread_ = new pp::SimpleThread(this); | |
| 16 factory_.Initialize(this); | |
| 17 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | |
|
bbudge
2012/01/25 00:35:26
Would it work if this was moved to Init()? It seem
| |
| 18 } | |
| 19 | |
| 20 virtual ~MyInstance() { | |
| 21 delete thread_; | |
| 22 } | |
| 23 | |
| 24 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | |
| 25 thread_->Start(); | |
| 26 thread_->message_loop().PostWork( | |
| 27 factory_.NewCallback(&MyInstance::CallOnBackground)); | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 virtual bool HandleInputEvent(const pp::InputEvent& event) { | |
| 32 switch (event.GetType()) { | |
| 33 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | |
| 34 return true; | |
| 35 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | |
| 36 return true; | |
| 37 case PP_INPUTEVENT_TYPE_KEYDOWN: | |
| 38 return true; | |
| 39 default: | |
| 40 return false; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 virtual void DidChangeView(const pp::View& view) { | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 void CallOnBackground(int32_t result) { | |
| 49 } | |
| 50 | |
| 51 pp::CompletionCallbackFactory<MyInstance> factory_; | |
| 52 | |
| 53 pp::SimpleThread* thread_; | |
| 54 }; | |
| 55 | |
| 56 | |
| 57 class MyModule : public pp::Module { | |
| 58 public: | |
| 59 MyModule() : pp::Module() {} | |
| 60 virtual ~MyModule() {} | |
| 61 | |
| 62 virtual pp::Instance* CreateInstance(PP_Instance instance) { | |
| 63 return new MyInstance(instance); | |
| 64 } | |
| 65 }; | |
| 66 | |
| 67 namespace pp { | |
| 68 | |
| 69 // Factory function for your specialization of the Module object. | |
| 70 Module* CreateModule() { | |
| 71 return new MyModule(); | |
| 72 } | |
| 73 | |
| 74 } // namespace pp | |
| OLD | NEW |