| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "ppapi/c/pp_input_event.h" | 5 #include "ppapi/c/pp_input_event.h" |
| 6 #include "ppapi/cpp/graphics_2d.h" | 6 #include "ppapi/cpp/graphics_2d.h" |
| 7 #include "ppapi/cpp/image_data.h" | 7 #include "ppapi/cpp/image_data.h" |
| 8 #include "ppapi/cpp/input_event.h" | |
| 9 #include "ppapi/cpp/instance.h" | 8 #include "ppapi/cpp/instance.h" |
| 10 #include "ppapi/cpp/module.h" | 9 #include "ppapi/cpp/module.h" |
| 11 #include "ppapi/cpp/paint_manager.h" | 10 #include "ppapi/cpp/paint_manager.h" |
| 12 #include "ppapi/cpp/size.h" | 11 #include "ppapi/cpp/size.h" |
| 13 | 12 |
| 14 // Number of pixels to each side of the center of the square that we draw. | 13 // Number of pixels to each side of the center of the square that we draw. |
| 15 static const int kSquareRadius = 2; | 14 static const int kSquareRadius = 2; |
| 16 | 15 |
| 17 // We identify our square by the center point. This computes the rect for the | 16 // We identify our square by the center point. This computes the rect for the |
| 18 // square given that point. | 17 // square given that point. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 } | 34 } |
| 36 | 35 |
| 37 class MyInstance : public pp::Instance, public pp::PaintManager::Client { | 36 class MyInstance : public pp::Instance, public pp::PaintManager::Client { |
| 38 public: | 37 public: |
| 39 MyInstance(PP_Instance instance) | 38 MyInstance(PP_Instance instance) |
| 40 : pp::Instance(instance), | 39 : pp::Instance(instance), |
| 41 paint_manager_(), | 40 paint_manager_(), |
| 42 last_x_(0), | 41 last_x_(0), |
| 43 last_y_(0) { | 42 last_y_(0) { |
| 44 paint_manager_.Initialize(this, this, false); | 43 paint_manager_.Initialize(this, this, false); |
| 45 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | |
| 46 } | 44 } |
| 47 | 45 |
| 48 virtual bool HandleInputEvent(const pp::InputEvent& event) { | 46 virtual bool HandleInputEvent(const PP_InputEvent& event) { |
| 49 switch (event.GetType()) { | 47 switch (event.type) { |
| 50 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { | 48 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { |
| 51 pp::MouseInputEvent mouse_event(event); | 49 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; |
| 52 // Update the square on a mouse down. | 50 // Update the square on a mouse down. |
| 53 if (mouse_event.GetMouseButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { | 51 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { |
| 54 UpdateSquare(static_cast<int>(mouse_event.GetMousePosition().x()), | 52 UpdateSquare(static_cast<int>(mouse_event.x), |
| 55 static_cast<int>(mouse_event.GetMousePosition().y())); | 53 static_cast<int>(mouse_event.y)); |
| 56 } | 54 } |
| 57 return true; | 55 return true; |
| 58 } | 56 } |
| 59 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { | 57 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { |
| 60 pp::MouseInputEvent mouse_event(event); | 58 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; |
| 61 // Update the square on a drag. | 59 // Update the square on a drag. |
| 62 if (mouse_event.GetMouseButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { | 60 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { |
| 63 UpdateSquare(static_cast<int>(mouse_event.GetMousePosition().x()), | 61 UpdateSquare(static_cast<int>(mouse_event.x), |
| 64 static_cast<int>(mouse_event.GetMousePosition().y())); | 62 static_cast<int>(mouse_event.y)); |
| 65 } | 63 } |
| 66 return true; | 64 return true; |
| 67 } | 65 } |
| 68 default: | 66 default: |
| 69 return false; | 67 return false; |
| 70 } | 68 } |
| 71 } | 69 } |
| 72 | 70 |
| 73 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { | 71 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { |
| 74 paint_manager_.SetSize(position.size()); | 72 paint_manager_.SetSize(position.size()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 }; | 149 }; |
| 152 | 150 |
| 153 namespace pp { | 151 namespace pp { |
| 154 | 152 |
| 155 // Factory function for your specialization of the Module object. | 153 // Factory function for your specialization of the Module object. |
| 156 Module* CreateModule() { | 154 Module* CreateModule() { |
| 157 return new MyModule(); | 155 return new MyModule(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 } // namespace pp | 158 } // namespace pp |
| OLD | NEW |