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

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

Issue 10909138: Convert the async device ID getter to a chrome resource host (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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/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/private/flash_device_id.h"
yzshen1 2012/09/11 00:53:17 I think you are not going to commit this file, rig
11 #include "ppapi/cpp/size.h" 12 #include "ppapi/cpp/size.h"
12 #include "ppapi/cpp/view.h" 13 #include "ppapi/cpp/view.h"
14 #include "ppapi/utility/completion_callback_factory.h"
13 #include "ppapi/utility/graphics/paint_manager.h" 15 #include "ppapi/utility/graphics/paint_manager.h"
14 16
15 // Number of pixels to each side of the center of the square that we draw. 17 // Number of pixels to each side of the center of the square that we draw.
16 static const int kSquareRadius = 2; 18 static const int kSquareRadius = 2;
17 19
18 // We identify our square by the center point. This computes the rect for the 20 // We identify our square by the center point. This computes the rect for the
19 // square given that point. 21 // square given that point.
20 pp::Rect SquareForPoint(int x, int y) { 22 pp::Rect SquareForPoint(int x, int y) {
21 return PP_MakeRectFromXYWH(x - kSquareRadius, y - kSquareRadius, 23 return PP_MakeRectFromXYWH(x - kSquareRadius, y - kSquareRadius,
22 kSquareRadius * 2 + 1, kSquareRadius * 2 + 1); 24 kSquareRadius * 2 + 1, kSquareRadius * 2 + 1);
(...skipping 12 matching lines...) Expand all
35 } 37 }
36 } 38 }
37 39
38 class MyInstance : public pp::Instance, public pp::PaintManager::Client { 40 class MyInstance : public pp::Instance, public pp::PaintManager::Client {
39 public: 41 public:
40 MyInstance(PP_Instance instance) 42 MyInstance(PP_Instance instance)
41 : pp::Instance(instance), 43 : pp::Instance(instance),
42 paint_manager_(), 44 paint_manager_(),
43 last_x_(0), 45 last_x_(0),
44 last_y_(0) { 46 last_y_(0) {
47 factory_.Initialize(this);
48 device_id_ = pp::flash::DeviceID(this);
49
45 paint_manager_.Initialize(this, this, false); 50 paint_manager_.Initialize(this, this, false);
46 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 51 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
47 } 52 }
48 53
54 pp::CompletionCallbackFactory<MyInstance> factory_;
55 pp::flash::DeviceID device_id_;
56
57 void GotDeviceID(int32_t result, const pp::Var& id) {
58 std::string value = id.AsString();
59 value.append("");
60 }
61
49 virtual bool HandleInputEvent(const pp::InputEvent& event) { 62 virtual bool HandleInputEvent(const pp::InputEvent& event) {
50 switch (event.GetType()) { 63 switch (event.GetType()) {
51 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { 64 case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
65 device_id_.GetDeviceID(factory_.NewCallbackWithOutput(
66 &MyInstance::GotDeviceID));
67
52 pp::MouseInputEvent mouse_event(event); 68 pp::MouseInputEvent mouse_event(event);
53 // Update the square on a mouse down. 69 // Update the square on a mouse down.
54 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { 70 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
55 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()), 71 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()),
56 static_cast<int>(mouse_event.GetPosition().y())); 72 static_cast<int>(mouse_event.GetPosition().y()));
57 } 73 }
58 return true; 74 return true;
59 } 75 }
60 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { 76 case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
61 pp::MouseInputEvent mouse_event(event); 77 pp::MouseInputEvent mouse_event(event);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 }; 168 };
153 169
154 namespace pp { 170 namespace pp {
155 171
156 // Factory function for your specialization of the Module object. 172 // Factory function for your specialization of the Module object.
157 Module* CreateModule() { 173 Module* CreateModule() {
158 return new MyModule(); 174 return new MyModule();
159 } 175 }
160 176
161 } // namespace pp 177 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698