| OLD | NEW |
| 1 // Copyright (c) 2010 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 <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> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 | 13 |
| 14 #include "ppapi/c/dev/ppb_console_dev.h" | 14 #include "ppapi/c/dev/ppb_console_dev.h" |
| 15 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
| 15 #include "ppapi/c/dev/ppp_printing_dev.h" | 16 #include "ppapi/c/dev/ppp_printing_dev.h" |
| 16 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 17 #include "ppapi/c/pp_input_event.h" | 18 #include "ppapi/c/pp_input_event.h" |
| 18 #include "ppapi/c/pp_rect.h" | 19 #include "ppapi/c/pp_rect.h" |
| 19 #include "ppapi/cpp/completion_callback.h" | 20 #include "ppapi/cpp/completion_callback.h" |
| 20 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 21 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
| 21 #include "ppapi/cpp/graphics_2d.h" | 22 #include "ppapi/cpp/graphics_2d.h" |
| 22 #include "ppapi/cpp/image_data.h" | 23 #include "ppapi/cpp/image_data.h" |
| 23 #include "ppapi/cpp/instance.h" | 24 #include "ppapi/cpp/instance.h" |
| 24 #include "ppapi/cpp/module.h" | 25 #include "ppapi/cpp/module.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 157 |
| 157 class MyInstance : public pp::Instance, public MyFetcherClient { | 158 class MyInstance : public pp::Instance, public MyFetcherClient { |
| 158 public: | 159 public: |
| 159 MyInstance(PP_Instance instance) | 160 MyInstance(PP_Instance instance) |
| 160 : pp::Instance(instance), | 161 : pp::Instance(instance), |
| 161 time_at_last_check_(0.0), | 162 time_at_last_check_(0.0), |
| 162 fetcher_(NULL), | 163 fetcher_(NULL), |
| 163 width_(0), | 164 width_(0), |
| 164 height_(0), | 165 height_(0), |
| 165 animation_counter_(0), | 166 animation_counter_(0), |
| 166 print_settings_valid_(false) {} | 167 print_settings_valid_(false), |
| 168 showing_custom_cursor_(false) {} |
| 167 | 169 |
| 168 virtual ~MyInstance() { | 170 virtual ~MyInstance() { |
| 169 if (fetcher_) { | 171 if (fetcher_) { |
| 170 delete fetcher_; | 172 delete fetcher_; |
| 171 fetcher_ = NULL; | 173 fetcher_ = NULL; |
| 172 } | 174 } |
| 173 } | 175 } |
| 174 | 176 |
| 175 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 177 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 176 return true; | 178 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 187 virtual bool HandleDocumentLoad(const pp::URLLoader& loader) { | 189 virtual bool HandleDocumentLoad(const pp::URLLoader& loader) { |
| 188 fetcher_ = new MyFetcher(); | 190 fetcher_ = new MyFetcher(); |
| 189 fetcher_->StartWithOpenedLoader(loader, this); | 191 fetcher_->StartWithOpenedLoader(loader, this); |
| 190 return true; | 192 return true; |
| 191 } | 193 } |
| 192 | 194 |
| 193 virtual bool HandleInputEvent(const PP_InputEvent& event) { | 195 virtual bool HandleInputEvent(const PP_InputEvent& event) { |
| 194 switch (event.type) { | 196 switch (event.type) { |
| 195 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 197 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| 196 SayHello(); | 198 SayHello(); |
| 199 ToggleCursor(); |
| 197 return true; | 200 return true; |
| 198 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 201 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
| 199 return true; | 202 return true; |
| 200 case PP_INPUTEVENT_TYPE_KEYDOWN: | 203 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 201 return true; | 204 return true; |
| 202 default: | 205 default: |
| 203 return false; | 206 return false; |
| 204 } | 207 } |
| 205 } | 208 } |
| 206 | 209 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 Log(PP_LOGLEVEL_LOG, "Downloaded location.href:"); | 391 Log(PP_LOGLEVEL_LOG, "Downloaded location.href:"); |
| 389 if (success) { | 392 if (success) { |
| 390 Log(PP_LOGLEVEL_LOG, data); | 393 Log(PP_LOGLEVEL_LOG, data); |
| 391 } else { | 394 } else { |
| 392 Log(PP_LOGLEVEL_ERROR, "Failed to download."); | 395 Log(PP_LOGLEVEL_ERROR, "Failed to download."); |
| 393 } | 396 } |
| 394 delete fetcher_; | 397 delete fetcher_; |
| 395 fetcher_ = NULL; | 398 fetcher_ = NULL; |
| 396 } | 399 } |
| 397 | 400 |
| 401 void ToggleCursor() { |
| 402 const PPB_CursorControl_Dev* cursor_control = |
| 403 reinterpret_cast<const PPB_CursorControl_Dev*>( |
| 404 pp::Module::Get()->GetBrowserInterface( |
| 405 PPB_CURSOR_CONTROL_DEV_INTERFACE)); |
| 406 if (!cursor_control) |
| 407 return; |
| 408 |
| 409 if (showing_custom_cursor_) { |
| 410 cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_POINTER, 0, NULL); |
| 411 } else { |
| 412 pp::ImageData image_data(this, pp::ImageData::GetNativeImageDataFormat(), |
| 413 pp::Size(50, 50), false); |
| 414 FillRect(&image_data, 0, 0, 50, 50, |
| 415 image_data.format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL ? |
| 416 0x80800000 : 0x80000080); |
| 417 pp::Point hot_spot(0, 0); |
| 418 cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_CUSTOM, |
| 419 image_data.pp_resource(), &hot_spot.pp_point()); |
| 420 } |
| 421 |
| 422 showing_custom_cursor_ = !showing_custom_cursor_; |
| 423 } |
| 424 |
| 398 pp::Var console_; | 425 pp::Var console_; |
| 399 pp::Graphics2D device_context_; | 426 pp::Graphics2D device_context_; |
| 400 | 427 |
| 401 double time_at_last_check_; | 428 double time_at_last_check_; |
| 402 | 429 |
| 403 MyFetcher* fetcher_; | 430 MyFetcher* fetcher_; |
| 404 | 431 |
| 405 int width_; | 432 int width_; |
| 406 int height_; | 433 int height_; |
| 407 | 434 |
| 408 // Incremented for each flush we get. | 435 // Incremented for each flush we get. |
| 409 int animation_counter_; | 436 int animation_counter_; |
| 410 bool print_settings_valid_; | 437 bool print_settings_valid_; |
| 411 PP_PrintSettings_Dev print_settings_; | 438 PP_PrintSettings_Dev print_settings_; |
| 439 |
| 440 bool showing_custom_cursor_; |
| 412 }; | 441 }; |
| 413 | 442 |
| 414 void FlushCallback(void* data, int32_t result) { | 443 void FlushCallback(void* data, int32_t result) { |
| 415 static_cast<MyInstance*>(data)->OnFlush(); | 444 static_cast<MyInstance*>(data)->OnFlush(); |
| 416 } | 445 } |
| 417 | 446 |
| 418 class MyModule : public pp::Module { | 447 class MyModule : public pp::Module { |
| 419 public: | 448 public: |
| 420 MyModule() : pp::Module() {} | 449 MyModule() : pp::Module() {} |
| 421 virtual ~MyModule() {} | 450 virtual ~MyModule() {} |
| 422 | 451 |
| 423 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 452 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 424 return new MyInstance(instance); | 453 return new MyInstance(instance); |
| 425 } | 454 } |
| 426 }; | 455 }; |
| 427 | 456 |
| 428 namespace pp { | 457 namespace pp { |
| 429 | 458 |
| 430 // Factory function for your specialization of the Module object. | 459 // Factory function for your specialization of the Module object. |
| 431 Module* CreateModule() { | 460 Module* CreateModule() { |
| 432 return new MyModule(); | 461 return new MyModule(); |
| 433 } | 462 } |
| 434 | 463 |
| 435 } // namespace pp | 464 } // namespace pp |
| OLD | NEW |