OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <math.h> | 5 #include <math.h> |
6 #include <stdio.h> // FIXME(brettw) erase me. | 6 #include <stdio.h> // FIXME(brettw) erase me. |
7 #ifndef _WIN32 | 7 #ifndef _WIN32 |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #endif | 9 #endif |
10 #include <time.h> | 10 #include <time.h> |
(...skipping 26 matching lines...) Expand all Loading... |
37 y++) { | 37 y++) { |
38 for (int x = std::max(0, left); | 38 for (int x = std::max(0, left); |
39 x < std::min(image->size().width() - 1, left + width); | 39 x < std::min(image->size().width() - 1, left + width); |
40 x++) | 40 x++) |
41 *image->GetAddr32(pp::Point(x, y)) = color; | 41 *image->GetAddr32(pp::Point(x, y)) = color; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 class MyScriptableObject : public pp::deprecated::ScriptableObject { | 45 class MyScriptableObject : public pp::deprecated::ScriptableObject { |
46 public: | 46 public: |
| 47 MyScriptableObject(pp::Instance* instance) : instance_(instance) {} |
| 48 |
47 virtual bool HasMethod(const pp::Var& method, pp::Var* exception) { | 49 virtual bool HasMethod(const pp::Var& method, pp::Var* exception) { |
48 return method.AsString() == "toString"; | 50 return method.AsString() == "toString"; |
49 } | 51 } |
50 | 52 |
51 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) { | 53 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) { |
52 if (name.is_string() && name.AsString() == "blah") | 54 if (name.is_string() && name.AsString() == "blah") |
53 return true; | 55 return true; |
54 return false; | 56 return false; |
55 } | 57 } |
56 | 58 |
57 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception) { | 59 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception) { |
58 if (name.is_string() && name.AsString() == "blah") | 60 if (name.is_string() && name.AsString() == "blah") |
59 return new MyScriptableObject(); | 61 return pp::Var(instance_, new MyScriptableObject(instance_)); |
60 return pp::Var(); | 62 return pp::Var(); |
61 } | 63 } |
62 | 64 |
63 virtual void GetAllPropertyNames(std::vector<pp::Var>* names, | 65 virtual void GetAllPropertyNames(std::vector<pp::Var>* names, |
64 pp::Var* exception) { | 66 pp::Var* exception) { |
65 names->push_back("blah"); | 67 names->push_back("blah"); |
66 } | 68 } |
67 | 69 |
68 virtual pp::Var Call(const pp::Var& method, | 70 virtual pp::Var Call(const pp::Var& method, |
69 const std::vector<pp::Var>& args, | 71 const std::vector<pp::Var>& args, |
70 pp::Var* exception) { | 72 pp::Var* exception) { |
71 if (method.AsString() == "toString") | 73 if (method.AsString() == "toString") |
72 return pp::Var("hello world"); | 74 return pp::Var("hello world"); |
73 return pp::Var(); | 75 return pp::Var(); |
74 } | 76 } |
| 77 |
| 78 private: |
| 79 pp::Instance* instance_; |
75 }; | 80 }; |
76 | 81 |
77 class MyFetcherClient { | 82 class MyFetcherClient { |
78 public: | 83 public: |
79 virtual void DidFetch(bool success, const std::string& data) = 0; | 84 virtual void DidFetch(bool success, const std::string& data) = 0; |
80 }; | 85 }; |
81 | 86 |
82 class MyFetcher { | 87 class MyFetcher { |
83 public: | 88 public: |
84 MyFetcher() : client_(NULL) { | 89 MyFetcher() : client_(NULL) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 189 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
185 return true; | 190 return true; |
186 case PP_INPUTEVENT_TYPE_KEYDOWN: | 191 case PP_INPUTEVENT_TYPE_KEYDOWN: |
187 return true; | 192 return true; |
188 default: | 193 default: |
189 return false; | 194 return false; |
190 } | 195 } |
191 } | 196 } |
192 | 197 |
193 virtual pp::Var GetInstanceObject() { | 198 virtual pp::Var GetInstanceObject() { |
194 return new MyScriptableObject(); | 199 return pp::Var(this, new MyScriptableObject(this)); |
195 } | 200 } |
196 | 201 |
197 pp::ImageData PaintImage(int width, int height) { | 202 pp::ImageData PaintImage(int width, int height) { |
198 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 203 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
199 pp::Size(width, height), false); | 204 pp::Size(width, height), false); |
200 if (image.is_null()) { | 205 if (image.is_null()) { |
201 printf("Couldn't allocate the image data\n"); | 206 printf("Couldn't allocate the image data\n"); |
202 return image; | 207 return image; |
203 } | 208 } |
204 | 209 |
205 // Fill with semitransparent gradient. | 210 // Fill with semitransparent gradient. |
206 for (int y = 0; y < image.size().height(); y++) { | 211 for (int y = 0; y < image.size().height(); y++) { |
207 char* row = &static_cast<char*>(image.data())[y * image.stride()]; | 212 char* row = &static_cast<char*>(image.data())[y * image.stride()]; |
208 for (int x = 0; x < image.size().width(); x++) { | 213 for (int x = 0; x < image.size().width(); x++) { |
(...skipping 24 matching lines...) Expand all Loading... |
233 } | 238 } |
234 | 239 |
235 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { | 240 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { |
236 if (position.size().width() == width_ && | 241 if (position.size().width() == width_ && |
237 position.size().height() == height_) | 242 position.size().height() == height_) |
238 return; // We don't care about the position, only the size. | 243 return; // We don't care about the position, only the size. |
239 | 244 |
240 width_ = position.size().width(); | 245 width_ = position.size().width(); |
241 height_ = position.size().height(); | 246 height_ = position.size().height(); |
242 | 247 |
243 device_context_ = pp::Graphics2D(pp::Size(width_, height_), false); | 248 device_context_ = pp::Graphics2D(this, pp::Size(width_, height_), false); |
244 if (!BindGraphics(device_context_)) { | 249 if (!BindGraphics(device_context_)) { |
245 printf("Couldn't bind the device context\n"); | 250 printf("Couldn't bind the device context\n"); |
246 return; | 251 return; |
247 } | 252 } |
248 | 253 |
249 Paint(); | 254 Paint(); |
250 } | 255 } |
251 | 256 |
252 void UpdateFps() { | 257 void UpdateFps() { |
253 // Time code doesn't currently compile on Windows, just skip FPS for now. | 258 // Time code doesn't currently compile on Windows, just skip FPS for now. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 346 } |
342 console_.Call("appendChild", doc.Call("createTextNode", var)); | 347 console_.Call("appendChild", doc.Call("createTextNode", var)); |
343 console_.Call("appendChild", doc.Call("createTextNode", "\n")); | 348 console_.Call("appendChild", doc.Call("createTextNode", "\n")); |
344 } | 349 } |
345 | 350 |
346 void SayHello() { | 351 void SayHello() { |
347 pp::Var window = GetWindowObject(); | 352 pp::Var window = GetWindowObject(); |
348 pp::Var doc = window.GetProperty("document"); | 353 pp::Var doc = window.GetProperty("document"); |
349 pp::Var body = doc.GetProperty("body"); | 354 pp::Var body = doc.GetProperty("body"); |
350 | 355 |
351 pp::Var obj(new MyScriptableObject()); | 356 pp::Var obj(this, new MyScriptableObject(this)); |
352 | 357 |
353 // Our object should have its toString method called. | 358 // Our object should have its toString method called. |
354 Log("Testing MyScriptableObject::toString():"); | 359 Log("Testing MyScriptableObject::toString():"); |
355 Log(obj); | 360 Log(obj); |
356 | 361 |
357 // body.appendChild(body) should throw an exception | 362 // body.appendChild(body) should throw an exception |
358 Log("\nCalling body.appendChild(body):"); | 363 Log("\nCalling body.appendChild(body):"); |
359 pp::Var exception; | 364 pp::Var exception; |
360 body.Call("appendChild", body, &exception); | 365 body.Call("appendChild", body, &exception); |
361 Log(exception); | 366 Log(exception); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 }; | 422 }; |
418 | 423 |
419 namespace pp { | 424 namespace pp { |
420 | 425 |
421 // Factory function for your specialization of the Module object. | 426 // Factory function for your specialization of the Module object. |
422 Module* CreateModule() { | 427 Module* CreateModule() { |
423 return new MyModule(); | 428 return new MyModule(); |
424 } | 429 } |
425 | 430 |
426 } // namespace pp | 431 } // namespace pp |
OLD | NEW |