2019-10-03 02:36:33 +09:00
|
|
|
define(['inputManager', 'focusManager', 'browser', 'layoutManager', 'events', 'dom'], function (inputManager, focusManager, browser, layoutManager, events, dom) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
var lastMouseInputTime = new Date().getTime();
|
|
|
|
var isMouseIdle;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function mouseIdleTime() {
|
2019-01-10 15:39:37 +03:00
|
|
|
return new Date().getTime() - lastMouseInputTime;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function notifyApp() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-10-03 02:36:33 +09:00
|
|
|
inputManager.notifyMouseMove();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeIdleClasses() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var classList = document.body.classList;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
classList.remove('mouseIdle');
|
|
|
|
classList.remove('mouseIdle-tv');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function addIdleClasses() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var classList = document.body.classList;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
classList.add('mouseIdle');
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
classList.add('mouseIdle-tv');
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
var lastPointerMoveData;
|
2018-10-23 01:05:09 +03:00
|
|
|
function onPointerMove(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var eventX = e.screenX;
|
|
|
|
var eventY = e.screenY;
|
|
|
|
|
|
|
|
// if coord don't exist how could it move
|
|
|
|
if (typeof eventX === "undefined" && typeof eventY === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var obj = lastPointerMoveData;
|
|
|
|
if (!obj) {
|
|
|
|
lastPointerMoveData = {
|
2018-10-23 01:05:09 +03:00
|
|
|
x: eventX,
|
|
|
|
y: eventY
|
2019-01-10 15:39:37 +03:00
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if coord are same, it didn't move
|
|
|
|
if (Math.abs(eventX - obj.x) < 10 && Math.abs(eventY - obj.y) < 10) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.x = eventX;
|
|
|
|
obj.y = eventY;
|
|
|
|
|
|
|
|
lastMouseInputTime = new Date().getTime();
|
|
|
|
notifyApp();
|
|
|
|
|
|
|
|
if (isMouseIdle) {
|
|
|
|
isMouseIdle = false;
|
|
|
|
removeIdleClasses();
|
|
|
|
events.trigger(self, 'mouseactive');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPointerEnter(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var pointerType = e.pointerType || (layoutManager.mobile ? 'touch' : 'mouse');
|
|
|
|
|
|
|
|
if (pointerType === 'mouse') {
|
|
|
|
if (!isMouseIdle) {
|
|
|
|
var parent = focusManager.focusableParent(e.target);
|
|
|
|
if (parent) {
|
|
|
|
focusManager.focus(parent);
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableFocusWithMouse() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!layoutManager.tv) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser.web0s) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser.tv) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseInterval() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!isMouseIdle && mouseIdleTime() >= 5000) {
|
|
|
|
isMouseIdle = true;
|
|
|
|
addIdleClasses();
|
|
|
|
events.trigger(self, 'mouseidle');
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
var mouseInterval;
|
2018-10-23 01:05:09 +03:00
|
|
|
function startMouseInterval() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!mouseInterval) {
|
|
|
|
mouseInterval = setInterval(onMouseInterval, 5000);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function stopMouseInterval() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var interval = mouseInterval;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (interval) {
|
|
|
|
clearInterval(interval);
|
|
|
|
mouseInterval = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
removeIdleClasses();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function initMouse() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
stopMouseInterval();
|
|
|
|
|
|
|
|
dom.removeEventListener(document, (window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!layoutManager.mobile) {
|
|
|
|
startMouseInterval();
|
|
|
|
|
|
|
|
dom.addEventListener(document, (window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dom.removeEventListener(document, (window.PointerEvent ? 'pointerenter' : 'mouseenter'), onPointerEnter, {
|
|
|
|
capture: true,
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
|
|
|
|
if (enableFocusWithMouse()) {
|
|
|
|
dom.addEventListener(document, (window.PointerEvent ? 'pointerenter' : 'mouseenter'), onPointerEnter, {
|
|
|
|
capture: true,
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
initMouse();
|
|
|
|
|
|
|
|
events.on(layoutManager, 'modechange', initMouse);
|
|
|
|
|
|
|
|
return self;
|
2020-02-22 11:47:03 -05:00
|
|
|
});
|