Skip to content
Permalink
Browse files

fix(event): fix FloatInput,IntInput->drag over in pointer lock->movement

  • Loading branch information...
yyc-git committed May 29, 2019
1 parent 8c84794 commit a085859f835c4af20e8f188ad6a998a181ed1f86
@@ -172,7 +172,7 @@ module Method = {
computeNewValue(
state.inputValue |> OptionService.unsafeGet |> float_of_string,
state.canBeZero,
MouseEventService.getMovementDeltaWhenPointerLocked(e),
MouseEventService.getMovementDeltaWhenPointerLockedAndFixBug(e)|> WonderLog.Log.print,
)
|> string_of_float,
),
@@ -89,7 +89,7 @@ module Method = {
Some(
computeNewValue(
state.inputValue |> OptionService.unsafeGet |> int_of_string,
MouseEventService.getMovementDeltaWhenPointerLocked(e),
MouseEventService.getMovementDeltaWhenPointerLockedAndFixBug(e),
)
|> string_of_int,
),
@@ -88,7 +88,7 @@ module DomEvent = {
|> WonderBsMost.Most.flatMap(event =>
fromPointDomEvent("mousemove", engineState)
/*!
fix chrome bug for getMovementDeltaWhenPointerLocked:
fix chrome bug for getMovementDeltaWhenPointerLockedAndFixBug:
the first movementDelta->x >100!
*/
|> WonderBsMost.Most.skip(2)
@@ -23,7 +23,13 @@ let isRightMouseButton = (event: EventType.customEvent) =>
}
);

let getMovementDeltaWhenPointerLocked = mouseDomEvent =>
let _replaceExceptionMovementDeltaToZero =
((movementX, movementY) as movementDelta) =>
Js.Math.abs_int(movementX) > 500 || Js.Math.abs_int(movementY) > 500 ?
(0, 0) : movementDelta;

let getMovementDeltaWhenPointerLockedAndFixBug = mouseDomEvent =>
Wonderjs.HandleMouseEventMainService._getMovementDeltaWhenPointerLocked(
mouseDomEvent,
);
)
|> _replaceExceptionMovementDeltaToZero;
@@ -0,0 +1,43 @@
open Wonder_jest;
open Expect;
open Expect.Operators;
open Sinon;

let _ =
describe("MouseEventService", () => {
let sandbox = getSandboxDefaultVal();

beforeEach(() => sandbox := createSandbox());
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe("getMovementDeltaWhenPointerLockedAndFixBug", () =>
describe("replace exception movement delta to zero data", () => {
test("if movementX > 500, return zero", () =>
MouseEventService.getMovementDeltaWhenPointerLockedAndFixBug(
MouseEventTool.buildMouseDomEvent(
~movementX=501,
~movementY=1,
(),
),
)
|> expect == (0, 0)
);
test("if movementY > 500, return zero", () =>
MouseEventService.getMovementDeltaWhenPointerLockedAndFixBug(
MouseEventTool.buildMouseDomEvent(
~movementX=1,
~movementY=501,
(),
),
)
|> expect == (0, 0)
);
test("else, return data", () =>
MouseEventService.getMovementDeltaWhenPointerLockedAndFixBug(
MouseEventTool.buildMouseDomEvent(~movementX=1, ~movementY=2, ()),
)
|> expect == (1, 2)
);
})
);
});

0 comments on commit a085859

Please sign in to comment.
You can’t perform that action at this time.