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

Side by Side Diff: ppapi/examples/input/pointer_event_input.cc

Issue 10873074: ppapi: Make sure the touch-event interface is detected correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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" 8 #include "ppapi/cpp/input_event.h"
9 #include "ppapi/cpp/instance.h" 9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/size.h" 11 #include "ppapi/cpp/size.h"
(...skipping 24 matching lines...) Expand all
36 } 36 }
37 37
38 class MyInstance : public pp::Instance, public pp::PaintManager::Client { 38 class MyInstance : public pp::Instance, public pp::PaintManager::Client {
39 public: 39 public:
40 MyInstance(PP_Instance instance) 40 MyInstance(PP_Instance instance)
41 : pp::Instance(instance), 41 : pp::Instance(instance),
42 paint_manager_(), 42 paint_manager_(),
43 last_x_(0), 43 last_x_(0),
44 last_y_(0) { 44 last_y_(0) {
45 paint_manager_.Initialize(this, this, false); 45 paint_manager_.Initialize(this, this, false);
46 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 46 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_TOUCH);
47 } 47 }
48 48
49 virtual bool HandleInputEvent(const pp::InputEvent& event) { 49 virtual bool HandleInputEvent(const pp::InputEvent& event) {
50 switch (event.GetType()) { 50 switch (event.GetType()) {
51 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { 51 case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
52 pp::MouseInputEvent mouse_event(event); 52 pp::MouseInputEvent mouse_event(event);
53 // Update the square on a mouse down. 53 // Update the square on a mouse down.
54 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { 54 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
55 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()), 55 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()),
56 static_cast<int>(mouse_event.GetPosition().y())); 56 static_cast<int>(mouse_event.GetPosition().y()));
57 } 57 }
58 return true; 58 return true;
59 } 59 }
60 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { 60 case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
61 pp::MouseInputEvent mouse_event(event); 61 pp::MouseInputEvent mouse_event(event);
62 // Update the square on a drag. 62 // Update the square on a drag.
63 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { 63 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
64 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()), 64 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()),
65 static_cast<int>(mouse_event.GetPosition().y())); 65 static_cast<int>(mouse_event.GetPosition().y()));
66 } 66 }
67 return true; 67 return true;
68 } 68 }
69
70 case PP_INPUTEVENT_TYPE_TOUCHSTART: {
71 pp::TouchInputEvent touch(event);
72 // Update the square on a touch down.
73 uint32_t count = touch.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES);
74 for (uint32_t i = 0; i < count; ++i) {
75 pp::TouchPoint point = touch.GetTouchByIndex(
76 PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i);
77 UpdateSquare(static_cast<int>(point.position().x()),
78 static_cast<int>(point.position().y()));
79 }
80 return true;
81 }
82 case PP_INPUTEVENT_TYPE_TOUCHMOVE:
83 case PP_INPUTEVENT_TYPE_TOUCHEND:
84 case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
85 return true;
86
69 default: 87 default:
70 return false; 88 return false;
71 } 89 }
72 } 90 }
73 91
74 virtual void DidChangeView(const pp::View& view) { 92 virtual void DidChangeView(const pp::View& view) {
75 paint_manager_.SetSize(view.GetRect().size()); 93 paint_manager_.SetSize(view.GetRect().size());
76 } 94 }
77 95
78 // PaintManager::Client implementation. 96 // PaintManager::Client implementation.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 }; 170 };
153 171
154 namespace pp { 172 namespace pp {
155 173
156 // Factory function for your specialization of the Module object. 174 // Factory function for your specialization of the Module object.
157 Module* CreateModule() { 175 Module* CreateModule() {
158 return new MyModule(); 176 return new MyModule();
159 } 177 }
160 178
161 } // namespace pp 179 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698