Panning works again (while holding shift)

This commit is contained in:
Tamius Han 2018-12-02 23:51:34 +01:00
parent bf5a51963b
commit 5043190441
6 changed files with 64 additions and 32 deletions

View File

@ -18,6 +18,7 @@ Debug = {
playerDetectDebug: true, playerDetectDebug: true,
periodic: true, periodic: true,
videoRescan: true, videoRescan: true,
mousemove: true,
arDetect: { arDetect: {
edgeDetect: true edgeDetect: true
}, },

View File

@ -47,9 +47,6 @@ class PlayerData {
return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width); return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width);
} }
panListener(event) {
this.panHandler(event);
}
start(){ start(){
this.startChangeDetection(); this.startChangeDetection();
@ -61,7 +58,6 @@ class PlayerData {
} }
destroy() { destroy() {
this.element.removeEventListener('mousemove', this.panListener);
this.stopChangeDetection(); this.stopChangeDetection();
} }
@ -170,12 +166,6 @@ class PlayerData {
} }
panHandler(event) {
if (this.extensionMode !== ExtensionMode.Full) {
return;
}
this.videoData.panHandler(event);
}
getPlayerDimensions(elementNames){ getPlayerDimensions(elementNames){
// element names — reserved for future use. If element names are provided, this function should return first element that // element names — reserved for future use. If element names are provided, this function should return first element that
@ -188,7 +178,6 @@ class PlayerData {
if(this.element) { if(this.element) {
const ths = this; const ths = this;
this.element.removeEventListener('mousemove', this.panListener);
} }
this.element = undefined; this.element = undefined;
this.dimensions = undefined; this.dimensions = undefined;
@ -256,10 +245,8 @@ class PlayerData {
} }
const ths = this; const ths = this;
if(this.element) { if(this.element) {
this.element.removeEventListener('mousemove', (event) => ths.panListener);
} }
this.element = element; this.element = element;
this.element.addEventListener('mousemove', ths.panListener);
} else { } else {
this.dimensions = { this.dimensions = {
width: candidate_width, width: candidate_width,
@ -268,10 +255,8 @@ class PlayerData {
}; };
const ths = this; const ths = this;
if(this.element) { if(this.element) {
this.element.removeEventListener('mousemove', (event) => ths.panListener);
} }
this.element = playerCandidateNode; this.element = playerCandidateNode;
this.element.addEventListener('mousemove', (event) => ths.panListener);
} }
} }

View File

@ -22,6 +22,8 @@ class VideoData {
if (Debug.init) { if (Debug.init) {
console.log("[VideoData::ctor] Created videoData with vdid", this.vdid,"\nextension mode:", this.extensionMode); console.log("[VideoData::ctor] Created videoData with vdid", this.vdid,"\nextension mode:", this.extensionMode);
} }
this.pageInfo.initMouseActionHandler(this);
} }
firstTimeArdInit(){ firstTimeArdInit(){
@ -148,7 +150,7 @@ class VideoData {
this.resizer.setLastAr('original'); this.resizer.setLastAr('original');
} }
panHandler(event) { panHandler(event, forcePan) {
if(this.destroyed) { if(this.destroyed) {
throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}}; throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
} }
@ -156,7 +158,7 @@ class VideoData {
this.destroy(); this.destroy();
return; return;
} }
this.resizer.panHandler(event); this.resizer.panHandler(event, forcePan);
} }
setPanMode(mode) { setPanMode(mode) {

View File

@ -68,12 +68,23 @@ class ActionHandler {
document.addEventListener('keydown', (event) => ths.handleKeydown(event) ); document.addEventListener('keydown', (event) => ths.handleKeydown(event) );
document.addEventListener('keyup', (event) => ths.handleKeyup(event) ); document.addEventListener('keyup', (event) => ths.handleKeyup(event) );
this.pageInfo.setActionHandler(this);
if (Debug.debug) { if (Debug.debug) {
console.log("[ActionHandler::init] initialization complete"); console.log("[ActionHandler::init] initialization complete");
} }
} }
registerHandleMouse(videoData) {
if (Debug.debug) {
console.log("[ActionHandler::registerHandleMouse] registering handle mouse for videodata:", videoData)
}
var ths = this;
if (videoData.player && videoData.player.element) {
videoData.player.element.addEventListener('mousemove', (event) => ths.handleMouseMove(event, videoData));
}
}
preventAction() { preventAction() {
var activeElement = document.activeElement; var activeElement = document.activeElement;
@ -96,9 +107,11 @@ class ActionHandler {
Debug.debug = true; // undisable Debug.debug = true; // undisable
} }
if (PlayerData.isFullScreen()) { // lately youtube has allowed you to read and write comments while watching video in
return false; // fullscreen mode. We can no longer do this.
} // if (PlayerData.isFullScreen()) {
// return false;
// }
if (this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1) { if (this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1) {
return true; return true;
} }
@ -119,7 +132,7 @@ class ActionHandler {
shortcut.shiftKey === event.shiftKey shortcut.shiftKey === event.shiftKey
} }
execAction(actions, event, shortcutIndex) { execAction(actions, event, shortcutIndex, videoData) {
if(Debug.debug && Debug.keyboard ){ if(Debug.debug && Debug.keyboard ){
console.log("%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event); console.log("%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event);
} }
@ -144,9 +157,10 @@ class ActionHandler {
} else if (cmd.action === "toggle-pan") { } else if (cmd.action === "toggle-pan") {
this.pageInfo.setPanMode(cmd.arg) this.pageInfo.setPanMode(cmd.arg)
} else if (cmd.action === "pan") { } else if (cmd.action === "pan") {
// todo: handle this if (videoData) {
videoData.panHandler(event, true);
}
} }
} }
return; return;
@ -154,6 +168,7 @@ class ActionHandler {
} }
} }
handleKeyup(event) { handleKeyup(event) {
if(Debug.debug && Debug.keyboard ){ if(Debug.debug && Debug.keyboard ){
console.log("%c[ActionHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keydown: ", event.keyup, "event:", event); console.log("%c[ActionHandler::handleKeyup] we pressed a key: ", "color: #ff0", event.key , " | keydown: ", event.keyup, "event:", event);
@ -184,4 +199,12 @@ class ActionHandler {
this.execAction(this.keyDownActions, event, 0); this.execAction(this.keyDownActions, event, 0);
} }
handleMouseMove(event, videoData) {
if (Debug.debug && Debug.mousemove) {
console.log("[ActionHandler::handleMouseMove] mouse move is being handled.\nevent:", event, "\nvideo data:", videoData);
}
videoData.panHandler(event);
this.execAction(this.mouseMoveActions, event, undefined, videoData)
}
} }

View File

@ -7,6 +7,7 @@ class PageInfo {
this.siteDisabled = false; this.siteDisabled = false;
this.videos = []; this.videos = [];
this.settings = settings; this.settings = settings;
this.actionHandlerInitQueue = [];
this.lastUrl = window.location.href; this.lastUrl = window.location.href;
this.extensionMode = extensionMode; this.extensionMode = extensionMode;
@ -41,6 +42,22 @@ class PageInfo {
this.rescan(RescanReason.MANUAL); this.rescan(RescanReason.MANUAL);
} }
initMouseActionHandler(videoData) {
if (this.actionHandler) {
this.actionHandler.registerHandleMouse(videoData);
} else {
this.actionHandlerInitQueue.push(videoData);
}
}
setActionHandler(actionHandler) {
this.actionHandler = actionHandler;
for (var item of this.actionHandlerInitQueue) {
this.actionHandler.registerHandleMouse(item);
}
this.actionHandlerInitQueue = [];
}
rescan(rescanReason){ rescan(rescanReason){
const oldVideoCount = this.videos.length; const oldVideoCount = this.videos.length;
@ -249,7 +266,6 @@ class PageInfo {
} }
startArDetection(playingOnly){ startArDetection(playingOnly){
if (Debug.debug) { if (Debug.debug) {
console.log('[PageInfo::startArDetection()] starting automatic ar detection!') console.log('[PageInfo::startArDetection()] starting automatic ar detection!')

View File

@ -151,20 +151,25 @@ if(Debug.debug)
this.restore(); this.restore();
} }
panHandler(event) { panHandler(event, forcePan) {
// console.log("this.conf.canPan:", this.conf.canPan) // console.log("this.conf.canPan:", this.conf.canPan)
if (this.canPan) { if (this.canPan || forcePan) {
// console.log("event?", event)
// console.log("this?", this)
if(!this.conf.player || !this.conf.player.element) { if(!this.conf.player || !this.conf.player.element) {
return; return;
} }
// dont allow weird floats
this.videoFloat = 'center';
const player = this.conf.player.element; const player = this.conf.player.element;
const relativeX = (event.pageX - player.offsetLeft) / player.offsetWidth; const relativeX = (event.pageX - player.offsetLeft) / player.offsetWidth;
const relativeY = (event.pageY - player.offsetTop) / player.offsetHeight; const relativeY = (event.pageY - player.offsetTop) / player.offsetHeight;
if (Debug.debug && Debug.mousemove) {
console.log("[Resizer::panHandler] mousemove.pageX, pageY:", event.pageX, event.pageY,
"\nrelativeX/Y:", relativeX, relativeY)
}
this.setPan(relativeX, relativeY); this.setPan(relativeX, relativeY);
} }
} }
@ -324,8 +329,8 @@ if(Debug.debug)
if(wdiff < 0 && hdiff < 0) { if(wdiff < 0 && hdiff < 0) {
return translate; return translate;
} }
translate.x = wdiff * this.pan.relativeOffsetX / this.zoom.scale; translate.x = wdiff * this.pan.relativeOffsetX * this.zoom.scale;
translate.y = hdiff * this.pan.relativeOffsetY / this.zoom.scale; translate.y = hdiff * this.pan.relativeOffsetY * this.zoom.scale;
} else { } else {
if (this.videoFloat == "left") { if (this.videoFloat == "left") {
translate.x += wdiffAfterzoom * 0.5; translate.x += wdiffAfterzoom * 0.5;