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" | 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" |
12 #include "ppapi/cpp/view.h" | 12 #include "ppapi/cpp/view.h" |
13 #include "ppapi/utility/graphics/paint_manager.h" | 13 #include "ppapi/utility/graphics/paint_manager.h" |
14 | 14 |
15 #include "ppapi/cpp/dev/file_chooser_dev.h" | |
16 #include "ppapi/utility/completion_callback_factory.h" | |
17 | |
15 // Number of pixels to each side of the center of the square that we draw. | 18 // Number of pixels to each side of the center of the square that we draw. |
16 static const int kSquareRadius = 2; | 19 static const int kSquareRadius = 2; |
17 | 20 |
18 // We identify our square by the center point. This computes the rect for the | 21 // We identify our square by the center point. This computes the rect for the |
19 // square given that point. | 22 // square given that point. |
20 pp::Rect SquareForPoint(int x, int y) { | 23 pp::Rect SquareForPoint(int x, int y) { |
21 return PP_MakeRectFromXYWH(x - kSquareRadius, y - kSquareRadius, | 24 return PP_MakeRectFromXYWH(x - kSquareRadius, y - kSquareRadius, |
22 kSquareRadius * 2 + 1, kSquareRadius * 2 + 1); | 25 kSquareRadius * 2 + 1, kSquareRadius * 2 + 1); |
23 } | 26 } |
24 | 27 |
(...skipping 12 matching lines...) Expand all Loading... | |
37 | 40 |
38 class MyInstance : public pp::Instance, public pp::PaintManager::Client { | 41 class MyInstance : public pp::Instance, public pp::PaintManager::Client { |
39 public: | 42 public: |
40 MyInstance(PP_Instance instance) | 43 MyInstance(PP_Instance instance) |
41 : pp::Instance(instance), | 44 : pp::Instance(instance), |
42 paint_manager_(), | 45 paint_manager_(), |
43 last_x_(0), | 46 last_x_(0), |
44 last_y_(0) { | 47 last_y_(0) { |
45 paint_manager_.Initialize(this, this, false); | 48 paint_manager_.Initialize(this, this, false); |
46 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 49 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
50 callback_factory_.Initialize(this); | |
51 } | |
52 | |
53 pp::FileChooser_Dev chooser_; | |
54 pp::CompletionCallbackFactory<MyInstance> callback_factory_; | |
55 | |
56 void GotFile(int32_t result, const std::vector<pp::FileRef>& files) { | |
47 } | 57 } |
48 | 58 |
49 virtual bool HandleInputEvent(const pp::InputEvent& event) { | 59 virtual bool HandleInputEvent(const pp::InputEvent& event) { |
50 switch (event.GetType()) { | 60 switch (event.GetType()) { |
51 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { | 61 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { |
62 chooser_ = pp::FileChooser_Dev(this, PP_FILECHOOSERMODE_OPEN, "text/html "); | |
63 chooser_.Show(callback_factory_.NewCallbackWithOutput(&MyInstance::GotFi le)); | |
raymes
2012/07/29 15:53:24
Were you going to hook this up? Seems like it's no
brettw
2012/07/30 05:46:37
Ignore this file, I was using it as a manual test.
| |
64 | |
52 pp::MouseInputEvent mouse_event(event); | 65 pp::MouseInputEvent mouse_event(event); |
53 // Update the square on a mouse down. | 66 // Update the square on a mouse down. |
54 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { | 67 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { |
55 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()), | 68 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()), |
56 static_cast<int>(mouse_event.GetPosition().y())); | 69 static_cast<int>(mouse_event.GetPosition().y())); |
57 } | 70 } |
58 return true; | 71 return true; |
59 } | 72 } |
60 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { | 73 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { |
61 pp::MouseInputEvent mouse_event(event); | 74 pp::MouseInputEvent mouse_event(event); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 }; | 165 }; |
153 | 166 |
154 namespace pp { | 167 namespace pp { |
155 | 168 |
156 // Factory function for your specialization of the Module object. | 169 // Factory function for your specialization of the Module object. |
157 Module* CreateModule() { | 170 Module* CreateModule() { |
158 return new MyModule(); | 171 return new MyModule(); |
159 } | 172 } |
160 | 173 |
161 } // namespace pp | 174 } // namespace pp |
OLD | NEW |