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

Side by Side Diff: ppapi/examples/2d/paint_manager_example.cc

Issue 7452002: Remove HandleInputEvent from PPP_Instance and freeze to 1.0. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 5 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) 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"
8 #include "ppapi/cpp/instance.h" 9 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
10 #include "ppapi/cpp/paint_manager.h" 11 #include "ppapi/cpp/paint_manager.h"
11 #include "ppapi/cpp/size.h" 12 #include "ppapi/cpp/size.h"
12 13
13 // Number of pixels to each side of the center of the square that we draw. 14 // Number of pixels to each side of the center of the square that we draw.
14 static const int kSquareRadius = 2; 15 static const int kSquareRadius = 2;
15 16
16 // We identify our square by the center point. This computes the rect for the 17 // We identify our square by the center point. This computes the rect for the
17 // square given that point. 18 // square given that point.
(...skipping 16 matching lines...) Expand all
34 } 35 }
35 36
36 class MyInstance : public pp::Instance, public pp::PaintManager::Client { 37 class MyInstance : public pp::Instance, public pp::PaintManager::Client {
37 public: 38 public:
38 MyInstance(PP_Instance instance) 39 MyInstance(PP_Instance instance)
39 : pp::Instance(instance), 40 : pp::Instance(instance),
40 paint_manager_(), 41 paint_manager_(),
41 last_x_(0), 42 last_x_(0),
42 last_y_(0) { 43 last_y_(0) {
43 paint_manager_.Initialize(this, this, false); 44 paint_manager_.Initialize(this, this, false);
45 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
brettw 2011/07/20 04:18:48 Can you remove "Filtering" here? I'd like to encou
44 } 46 }
45 47
46 virtual bool HandleInputEvent(const PP_InputEvent& event) { 48 virtual bool HandleInputEvent(const pp::InputEvent& event) {
47 switch (event.type) { 49 switch (event.GetType()) {
48 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { 50 case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
49 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; 51 pp::MouseInputEvent mouse_event(event);
50 // Update the square on a mouse down. 52 // Update the square on a mouse down.
51 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { 53 if (mouse_event.GetMouseButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
52 UpdateSquare(static_cast<int>(mouse_event.x), 54 UpdateSquare(static_cast<int>(mouse_event.GetMousePosition().x()),
53 static_cast<int>(mouse_event.y)); 55 static_cast<int>(mouse_event.GetMousePosition().y()));
54 } 56 }
55 return true; 57 return true;
56 } 58 }
57 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { 59 case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
58 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; 60 pp::MouseInputEvent mouse_event(event);
59 // Update the square on a drag. 61 // Update the square on a drag.
60 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { 62 if (mouse_event.GetMouseButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
61 UpdateSquare(static_cast<int>(mouse_event.x), 63 UpdateSquare(static_cast<int>(mouse_event.GetMousePosition().x()),
62 static_cast<int>(mouse_event.y)); 64 static_cast<int>(mouse_event.GetMousePosition().y()));
63 } 65 }
64 return true; 66 return true;
65 } 67 }
66 default: 68 default:
67 return false; 69 return false;
68 } 70 }
69 } 71 }
70 72
71 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { 73 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) {
72 paint_manager_.SetSize(position.size()); 74 paint_manager_.SetSize(position.size());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 }; 151 };
150 152
151 namespace pp { 153 namespace pp {
152 154
153 // Factory function for your specialization of the Module object. 155 // Factory function for your specialization of the Module object.
154 Module* CreateModule() { 156 Module* CreateModule() {
155 return new MyModule(); 157 return new MyModule();
156 } 158 }
157 159
158 } // namespace pp 160 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698