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

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

Issue 10544089: Implement the file chooser as a new resource "host" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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/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 #include "ppapi/cpp/dev/file_chooser_dev.h"
brettw 2012/06/30 19:01:58 Ignore the changes in this file; I'll revert befor
15 #include "ppapi/utility/completion_callback_factory.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);
23 } 25 }
(...skipping 13 matching lines...) Expand all
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) {
45 paint_manager_.Initialize(this, this, false); 47 paint_manager_.Initialize(this, this, false);
46 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 48 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
49 callback_factory_.Initialize(this);
50 }
51
52 pp::FileChooser_Dev chooser_;
53 pp::CompletionCallbackFactory<MyInstance> callback_factory_;
54
55 void GotFile(int32_t result, const std::vector<pp::FileRef>& files) {
47 } 56 }
48 57
49 virtual bool HandleInputEvent(const pp::InputEvent& event) { 58 virtual bool HandleInputEvent(const pp::InputEvent& event) {
50 switch (event.GetType()) { 59 switch (event.GetType()) {
51 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { 60 case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
61 chooser_ = pp::FileChooser_Dev(this, PP_FILECHOOSERMODE_OPEN, "text/html ");
62 chooser_.Show(callback_factory_.NewCallbackWithOutput(&MyInstance::GotFi le));
63
52 pp::MouseInputEvent mouse_event(event); 64 pp::MouseInputEvent mouse_event(event);
53 // Update the square on a mouse down. 65 // Update the square on a mouse down.
54 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { 66 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
55 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()), 67 UpdateSquare(static_cast<int>(mouse_event.GetPosition().x()),
56 static_cast<int>(mouse_event.GetPosition().y())); 68 static_cast<int>(mouse_event.GetPosition().y()));
57 } 69 }
58 return true; 70 return true;
59 } 71 }
60 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { 72 case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
61 pp::MouseInputEvent mouse_event(event); 73 pp::MouseInputEvent mouse_event(event);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 }; 164 };
153 165
154 namespace pp { 166 namespace pp {
155 167
156 // Factory function for your specialization of the Module object. 168 // Factory function for your specialization of the Module object.
157 Module* CreateModule() { 169 Module* CreateModule() {
158 return new MyModule(); 170 return new MyModule();
159 } 171 }
160 172
161 } // namespace pp 173 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698