Home | History | Annotate | Download | only in plugin
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
      6 #define REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "ppapi/cpp/mouse_lock.h"
     11 #include "ppapi/cpp/point.h"
     12 #include "ppapi/utility/completion_callback_factory.h"
     13 #include "remoting/protocol/input_stub.h"
     14 
     15 namespace pp {
     16 class ImageData;
     17 class InputEvent;
     18 class Instance;
     19 }  // namespace pp
     20 
     21 namespace remoting {
     22 
     23 namespace protocol {
     24 class InputStub;
     25 } // namespace protocol
     26 
     27 class PepperInputHandler : public pp::MouseLock {
     28  public:
     29   // |instance| must outlive |this|.
     30   PepperInputHandler(pp::Instance* instance, protocol::InputStub* input_stub);
     31   virtual ~PepperInputHandler();
     32 
     33   bool HandleInputEvent(const pp::InputEvent& event);
     34 
     35   // Enables locking the mouse when the host sets a completely transparent mouse
     36   // cursor.
     37   void AllowMouseLock();
     38 
     39   // Called when the plugin receives or loses focus.
     40   void DidChangeFocus(bool has_focus);
     41 
     42   // Sets the mouse cursor image. Passing NULL image will lock the mouse if
     43   // mouse lock is enabled.
     44   void SetMouseCursor(scoped_ptr<pp::ImageData> image,
     45                       const pp::Point& hotspot);
     46 
     47  private:
     48   enum MouseLockState {
     49     MouseLockDisallowed,
     50     MouseLockOff,
     51     MouseLockRequestPending,
     52     MouseLockOn,
     53     MouseLockCancelling
     54   };
     55 
     56   // pp::MouseLock interface.
     57   virtual void MouseLockLost() OVERRIDE;
     58 
     59   // Requests the browser to lock the mouse and hides the cursor.
     60   void RequestMouseLock();
     61 
     62   // Requests the browser to cancel mouse lock and restores the cursor once
     63   // the lock is gone.
     64   void CancelMouseLock();
     65 
     66   // Applies |cursor_image_| as the custom pointer or uses the standard arrow
     67   // pointer if |cursor_image_| is not available.
     68   void UpdateMouseCursor();
     69 
     70   // Handles completion of the mouse lock request issued by RequestMouseLock().
     71   void OnMouseLocked(int error);
     72 
     73   pp::Instance* instance_;
     74   protocol::InputStub* input_stub_;
     75 
     76   pp::CompletionCallbackFactory<PepperInputHandler> callback_factory_;
     77 
     78   // Custom cursor image sent by the host. |cursor_image_| is set to NULL when
     79   // the cursor image is completely transparent. This can be interpreted as
     80   // a mouse lock request if enabled by the webapp.
     81   scoped_ptr<pp::ImageData> cursor_image_;
     82 
     83   // Hot spot for |cursor_image_|.
     84   pp::Point cursor_hotspot_;
     85 
     86   // True if the plugin has focus.
     87   bool has_focus_;
     88 
     89   MouseLockState mouse_lock_state_;
     90 
     91   // Accumulated sub-pixel and sub-tick deltas from wheel events.
     92   float wheel_delta_x_;
     93   float wheel_delta_y_;
     94   float wheel_ticks_x_;
     95   float wheel_ticks_y_;
     96 
     97   DISALLOW_COPY_AND_ASSIGN(PepperInputHandler);
     98 };
     99 
    100 }  // namespace remoting
    101 
    102 #endif  // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
    103