Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cmath> | 5 #include <cmath> |
| 6 #include <stdarg.h> | 6 #include <stdarg.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "ppapi/c/dev/ppb_console_dev.h" | 9 #include "ppapi/c/dev/ppb_console_dev.h" |
| 10 #include "ppapi/c/ppb_input_event.h" | 10 #include "ppapi/c/ppb_input_event.h" |
| 11 #include "ppapi/cpp/graphics_2d.h" | 11 #include "ppapi/cpp/graphics_2d.h" |
| 12 #include "ppapi/cpp/image_data.h" | 12 #include "ppapi/cpp/image_data.h" |
| 13 #include "ppapi/cpp/input_event.h" | 13 #include "ppapi/cpp/input_event.h" |
| 14 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
| 15 #include "ppapi/cpp/logging.h" | 15 #include "ppapi/cpp/logging.h" |
| 16 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/mouse_lock.h" | 17 #include "ppapi/cpp/mouse_lock.h" |
| 18 #include "ppapi/cpp/private/flash_fullscreen.h" | |
| 18 #include "ppapi/cpp/rect.h" | 19 #include "ppapi/cpp/rect.h" |
| 19 #include "ppapi/cpp/var.h" | 20 #include "ppapi/cpp/var.h" |
| 20 #include "ppapi/utility/completion_callback_factory.h" | 21 #include "ppapi/utility/completion_callback_factory.h" |
| 21 | 22 |
| 22 class MyInstance : public pp::Instance, public pp::MouseLock { | 23 class MyInstance : public pp::Instance, public pp::MouseLock { |
| 23 public: | 24 public: |
| 24 explicit MyInstance(PP_Instance instance) | 25 explicit MyInstance(PP_Instance instance) |
| 25 : pp::Instance(instance), | 26 : pp::Instance(instance), |
| 26 pp::MouseLock(this), | 27 pp::MouseLock(this), |
| 27 width_(0), | 28 width_(0), |
| 28 height_(0), | 29 height_(0), |
| 29 mouse_locked_(false), | 30 mouse_locked_(false), |
| 30 pending_paint_(false), | 31 pending_paint_(false), |
| 31 waiting_for_flush_completion_(false), | 32 waiting_for_flush_completion_(false), |
| 32 callback_factory_(this), | 33 callback_factory_(this), |
| 33 console_(NULL) { | 34 console_(NULL), |
| 35 flash_fullscreen_(this) { | |
| 34 } | 36 } |
| 35 virtual ~MyInstance() {} | 37 virtual ~MyInstance() {} |
| 36 | 38 |
| 37 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 39 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 38 console_ = reinterpret_cast<const PPB_Console_Dev*>( | 40 console_ = reinterpret_cast<const PPB_Console_Dev*>( |
| 39 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); | 41 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); |
| 40 if (!console_) | 42 if (!console_) |
| 41 return false; | 43 return false; |
| 42 | 44 |
| 43 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | | 45 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 59 pp::MouseInputEvent mouse_event(event); | 61 pp::MouseInputEvent mouse_event(event); |
| 60 mouse_movement_ = mouse_event.GetMovement(); | 62 mouse_movement_ = mouse_event.GetMovement(); |
| 61 static unsigned int i = 0; | 63 static unsigned int i = 0; |
| 62 Log(PP_LOGLEVEL_LOG, "[%d] movementX: %d; movementY: %d\n", i++, | 64 Log(PP_LOGLEVEL_LOG, "[%d] movementX: %d; movementY: %d\n", i++, |
| 63 mouse_movement_.x(), mouse_movement_.y()); | 65 mouse_movement_.x(), mouse_movement_.y()); |
| 64 Paint(); | 66 Paint(); |
| 65 return true; | 67 return true; |
| 66 } | 68 } |
| 67 case PP_INPUTEVENT_TYPE_KEYDOWN: { | 69 case PP_INPUTEVENT_TYPE_KEYDOWN: { |
| 68 pp::KeyboardInputEvent key_event(event); | 70 pp::KeyboardInputEvent key_event(event); |
| 69 // Lock the mouse when the Enter key is pressed. | |
| 70 if (key_event.GetKeyCode() == 13) { | 71 if (key_event.GetKeyCode() == 13) { |
| 72 // Lock the mouse when the Enter key is pressed. | |
| 71 if (mouse_locked_) | 73 if (mouse_locked_) |
| 72 UnlockMouse(); | 74 UnlockMouse(); |
| 73 else | 75 else |
| 74 LockMouse(callback_factory_.NewCallback(&MyInstance::DidLockMouse)); | 76 LockMouse(callback_factory_.NewCallback(&MyInstance::DidLockMouse)); |
| 75 return true; | 77 return true; |
| 78 } else if (key_event.GetKeyCode() == 70) { | |
|
scheib
2012/05/29 21:47:14
Document in HTML how and why to enter this mode.
yzshen1
2012/05/30 06:41:30
I have revised the HTML page.
I didn't do it becau
| |
| 79 // Enter Flash fullscreen mode when the 'f' key is pressed. | |
| 80 if (!flash_fullscreen_.IsFullscreen()) | |
| 81 flash_fullscreen_.SetFullscreen(true); | |
| 82 return true; | |
| 76 } | 83 } |
| 77 return false; | 84 return false; |
| 78 } | 85 } |
| 79 default: | 86 default: |
| 80 return false; | 87 return false; |
| 81 } | 88 } |
| 82 } | 89 } |
| 83 | 90 |
| 84 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { | 91 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { |
| 85 if (position.size().width() == width_ && | 92 if (position.size().width() == width_ && |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 bool within_bound_1 = | 199 bool within_bound_1 = |
| 193 ((y - anchor_1.y()) * (vertex.x() - anchor_1.x())) > | 200 ((y - anchor_1.y()) * (vertex.x() - anchor_1.x())) > |
| 194 ((vertex.y() - anchor_1.y()) * (x - anchor_1.x())); | 201 ((vertex.y() - anchor_1.y()) * (x - anchor_1.x())); |
| 195 bool within_bound_2 = | 202 bool within_bound_2 = |
| 196 ((y - anchor_2.y()) * (vertex.x() - anchor_2.x())) < | 203 ((y - anchor_2.y()) * (vertex.x() - anchor_2.x())) < |
| 197 ((vertex.y() - anchor_2.y()) * (x - anchor_2.x())); | 204 ((vertex.y() - anchor_2.y()) * (x - anchor_2.x())); |
| 198 bool within_bound_3 = | 205 bool within_bound_3 = |
| 199 (direction == UP && y < center_y) || | 206 (direction == UP && y < center_y) || |
| 200 (direction == DOWN && y > center_y) || | 207 (direction == DOWN && y > center_y) || |
| 201 (direction == LEFT && x < center_x) || | 208 (direction == LEFT && x < center_x) || |
| 202 (direction == RIGHT && x > center_y); | 209 (direction == RIGHT && x > center_x); |
| 203 | 210 |
| 204 if (within_bound_1 && within_bound_2 && within_bound_3) { | 211 if (within_bound_1 && within_bound_2 && within_bound_3) { |
| 205 *image.GetAddr32(pp::Point(x, y)) = foreground_color; | 212 *image.GetAddr32(pp::Point(x, y)) = foreground_color; |
| 206 continue; | 213 continue; |
| 207 } | 214 } |
| 208 } | 215 } |
| 209 *image.GetAddr32(pp::Point(x, y)) = kBackgroundColor; | 216 *image.GetAddr32(pp::Point(x, y)) = kBackgroundColor; |
| 210 } | 217 } |
| 211 } | 218 } |
| 212 | 219 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 237 bool mouse_locked_; | 244 bool mouse_locked_; |
| 238 pp::Point mouse_movement_; | 245 pp::Point mouse_movement_; |
| 239 | 246 |
| 240 bool pending_paint_; | 247 bool pending_paint_; |
| 241 bool waiting_for_flush_completion_; | 248 bool waiting_for_flush_completion_; |
| 242 | 249 |
| 243 pp::CompletionCallbackFactory<MyInstance> callback_factory_; | 250 pp::CompletionCallbackFactory<MyInstance> callback_factory_; |
| 244 | 251 |
| 245 const PPB_Console_Dev* console_; | 252 const PPB_Console_Dev* console_; |
| 246 | 253 |
| 254 pp::FlashFullscreen flash_fullscreen_; | |
| 255 | |
| 247 pp::Graphics2D device_context_; | 256 pp::Graphics2D device_context_; |
| 248 }; | 257 }; |
| 249 | 258 |
| 250 // This object is the global object representing this plugin library as long | 259 // This object is the global object representing this plugin library as long |
| 251 // as it is loaded. | 260 // as it is loaded. |
| 252 class MyModule : public pp::Module { | 261 class MyModule : public pp::Module { |
| 253 public: | 262 public: |
| 254 MyModule() : pp::Module() {} | 263 MyModule() : pp::Module() {} |
| 255 virtual ~MyModule() {} | 264 virtual ~MyModule() {} |
| 256 | 265 |
| 257 // Override CreateInstance to create your customized Instance object. | 266 // Override CreateInstance to create your customized Instance object. |
| 258 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 267 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 259 return new MyInstance(instance); | 268 return new MyInstance(instance); |
| 260 } | 269 } |
| 261 }; | 270 }; |
| 262 | 271 |
| 263 namespace pp { | 272 namespace pp { |
| 264 | 273 |
| 265 // Factory function for your specialization of the Module object. | 274 // Factory function for your specialization of the Module object. |
| 266 Module* CreateModule() { | 275 Module* CreateModule() { |
| 267 return new MyModule(); | 276 return new MyModule(); |
| 268 } | 277 } |
| 269 | 278 |
| 270 } // namespace pp | 279 } // namespace pp |
| 271 | 280 |
| OLD | NEW |