mouse: emulate scrolling with left+right pressed

Many mice and trackballs without scroll wheels also lack a middle
button, meaning that they can't activate scroll wheel emulation.
Activating it when the left and right buttons are held simultaneously
improves the user experience with such devices.

BUG=b:234160991
TEST=With Logitech Trackman Marble (which has no middle button), check
     scrolling emulation works. With 3M Ergonomic Mouse (which has a
     middle button but no wheel) check that middle-click still works.

Change-Id: Iffe1de3503e97562952ff451549cd4118abf1f89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/gestures/+/3673134
Tested-by: Harry Cutts <hcutts@chromium.org>
Reviewed-by: Sean O'Brien <seobrien@chromium.org>
Commit-Queue: Harry Cutts <hcutts@chromium.org>
diff --git a/src/mouse_interpreter.cc b/src/mouse_interpreter.cc
index ce4d47f..f24837c 100644
--- a/src/mouse_interpreter.cc
+++ b/src/mouse_interpreter.cc
@@ -93,8 +93,12 @@
   if (!force_scroll_wheel_emulation_.val_ && hwprops_->has_wheel)
     return false;
 
-  bool down = hwstate.buttons_down & GESTURES_BUTTON_MIDDLE;
-  bool prev_down = prev_state_.buttons_down & GESTURES_BUTTON_MIDDLE;
+  bool down = hwstate.buttons_down & GESTURES_BUTTON_MIDDLE ||
+              (hwstate.buttons_down & GESTURES_BUTTON_LEFT &&
+               hwstate.buttons_down & GESTURES_BUTTON_RIGHT);
+  bool prev_down = prev_state_.buttons_down & GESTURES_BUTTON_MIDDLE ||
+                   (prev_state_.buttons_down & GESTURES_BUTTON_LEFT &&
+                    prev_state_.buttons_down & GESTURES_BUTTON_RIGHT);
   bool raising = down && !prev_down;
   bool falling = !down && prev_down;
 
@@ -110,8 +114,8 @@
     ProduceGesture(Gesture(kGestureButtonsChange,
                            prev_state_.timestamp,
                            hwstate.timestamp,
-                           GESTURES_BUTTON_MIDDLE,
-                           GESTURES_BUTTON_MIDDLE,
+                           prev_state_.buttons_down,
+                           prev_state_.buttons_down,
                            false)); // is_tap
   }