Bug 781039 - Mouse input support for gonk, r=cjones
authorMichael Wu <mwu@mozilla.com>
Fri, 24 Aug 2012 14:06:19 -0400
changeset 105359 0eb750ce354b9f9b55e768012a6b809547429046
parent 105358 8bd8ec63a020a56aa9d654d99c83bf6b97c5efe1
child 105360 3331ec03e60fe6bd4bf8b4ba79679c44515c8443
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerscjones
bugs781039
milestone17.0a1
Bug 781039 - Mouse input support for gonk, r=cjones
widget/gonk/nsAppShell.cpp
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -227,27 +227,112 @@ maybeSendKeyEvent(int keyCode, bool pres
 {
     if (keyCode < ArrayLength(kKeyMapping) && kKeyMapping[keyCode])
         sendKeyEvent(kKeyMapping[keyCode], pressed, timeMs);
     else
         VERBOSE_LOG("Got unknown key event code. type 0x%04x code 0x%04x value %d",
                     keyCode, pressed);
 }
 
+class GeckoPointerController : public PointerControllerInterface {
+    float mX;
+    float mY;
+    int32_t mButtonState;
+    InputReaderConfiguration* mConfig;
+public:
+    GeckoPointerController(InputReaderConfiguration* config)
+        : mX(0)
+        , mY(0)
+        , mButtonState(0)
+        , mConfig(config)
+    {}
+
+    virtual bool getBounds(float* outMinX, float* outMinY,
+            float* outMaxX, float* outMaxY) const;
+    virtual void move(float deltaX, float deltaY);
+    virtual void setButtonState(int32_t buttonState);
+    virtual int32_t getButtonState() const;
+    virtual void setPosition(float x, float y);
+    virtual void getPosition(float* outX, float* outY) const;
+    virtual void fade(Transition transition) {}
+    virtual void unfade(Transition transition) {}
+    virtual void setPresentation(Presentation presentation) {}
+    virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
+            BitSet32 spotIdBits) {}
+    virtual void clearSpots() {}
+};
+
+bool
+GeckoPointerController::getBounds(float* outMinX,
+                                  float* outMinY,
+                                  float* outMaxX,
+                                  float* outMaxY) const
+{
+    int32_t width, height, orientation;
+
+    mConfig->getDisplayInfo(0, false, &width, &height, &orientation);
+
+    *outMinX = *outMinY = 0;
+    if (orientation == DISPLAY_ORIENTATION_90 ||
+        orientation == DISPLAY_ORIENTATION_270) {
+        *outMaxX = height;
+        *outMaxY = width;
+    } else {
+        *outMaxX = width;
+        *outMaxY = height;
+    }
+    return true;
+}
+
+void
+GeckoPointerController::move(float deltaX, float deltaY)
+{
+    float minX, minY, maxX, maxY;
+    getBounds(&minX, &minY, &maxX, &maxY);
+
+    mX = clamped(mX + deltaX, minX, maxX);
+    mY = clamped(mY + deltaY, minY, maxY);
+}
+
+void
+GeckoPointerController::setButtonState(int32_t buttonState)
+{
+    mButtonState = buttonState;
+}
+
+int32_t
+GeckoPointerController::getButtonState() const
+{
+    return mButtonState;
+}
+
+void
+GeckoPointerController::setPosition(float x, float y)
+{
+    mX = x;
+    mY = y;
+}
+
+void
+GeckoPointerController::getPosition(float* outX, float* outY) const
+{
+    *outX = mX;
+    *outY = mY;
+}
+
 class GeckoInputReaderPolicy : public InputReaderPolicyInterface {
     InputReaderConfiguration mConfig;
 public:
     GeckoInputReaderPolicy() {}
 
     virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
     virtual sp<PointerControllerInterface> obtainPointerController(int32_t
 deviceId)
     {
-        MOZ_NOT_REACHED("Input device configuration failed.");
-        return NULL;
+        return new GeckoPointerController(&mConfig);
     };
     void setDisplayInfo();
 
 protected:
     virtual ~GeckoInputReaderPolicy() {}
 };
 
 class GeckoInputDispatcher : public InputDispatcherInterface {
@@ -342,26 +427,31 @@ GeckoInputDispatcher::dispatchOnce()
         data = mEventQueue.front();
         mEventQueue.pop();
         if (!mEventQueue.empty())
             gAppShell->NotifyNativeEvent();
     }
 
     switch (data.type) {
     case UserInputData::MOTION_DATA: {
-        nsEventStatus status = sendTouchEvent(data);
+        nsEventStatus status = nsEventStatus_eIgnore;
+        if ((data.action & AMOTION_EVENT_ACTION_MASK) !=
+            AMOTION_EVENT_ACTION_HOVER_MOVE) {
+            status = sendTouchEvent(data);
+        }
 
         uint32_t msg;
         switch (data.action & AMOTION_EVENT_ACTION_MASK) {
         case AMOTION_EVENT_ACTION_DOWN:
             msg = NS_MOUSE_BUTTON_DOWN;
             break;
         case AMOTION_EVENT_ACTION_POINTER_DOWN:
         case AMOTION_EVENT_ACTION_POINTER_UP:
         case AMOTION_EVENT_ACTION_MOVE:
+        case AMOTION_EVENT_ACTION_HOVER_MOVE:
             msg = NS_MOUSE_MOVE;
             break;
         case AMOTION_EVENT_ACTION_OUTSIDE:
         case AMOTION_EVENT_ACTION_CANCEL:
         case AMOTION_EVENT_ACTION_UP:
             msg = NS_MOUSE_BUTTON_UP;
             break;
         }
@@ -426,18 +516,20 @@ GeckoInputDispatcher::notifyMotion(const
         Touch& touch = data.motion.touches[i];
         touch.id = args->pointerProperties[i].id;
         memcpy(&touch.coords, &args->pointerCoords[i], sizeof(*args->pointerCoords));
     }
     {
         MutexAutoLock lock(mQueueLock);
         if (!mEventQueue.empty() &&
              mEventQueue.back().type == UserInputData::MOTION_DATA &&
+           ((mEventQueue.back().action & AMOTION_EVENT_ACTION_MASK) ==
+             AMOTION_EVENT_ACTION_MOVE ||
             (mEventQueue.back().action & AMOTION_EVENT_ACTION_MASK) ==
-             AMOTION_EVENT_ACTION_MOVE)
+             AMOTION_EVENT_ACTION_HOVER_MOVE))
             mEventQueue.back() = data;
         else
             mEventQueue.push(data);
     }
     gAppShell->NotifyNativeEvent();
 }