2017-06-08 05:25:47 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-08-29 00:09:52 +08:00
|
|
|
import SlideCalcUtil from '/imports/utils/slideCalcUtils';
|
2018-08-30 04:20:42 +08:00
|
|
|
// After lots of trial and error on why synching doesn't work properly, I found I had to
|
|
|
|
// multiply the coordinates by 2. There's something I don't understand probably on the
|
|
|
|
// canvas coordinate system. (ralam feb 22, 2012)
|
2018-08-29 00:09:52 +08:00
|
|
|
const MYSTERY_NUM = 2;
|
2018-05-12 00:01:24 +08:00
|
|
|
const CURSOR_INTERVAL = 16;
|
2018-08-14 03:29:38 +08:00
|
|
|
const HUNDRED_PERCENT = 100;
|
2018-08-23 01:53:04 +08:00
|
|
|
const MAX_PERCENT = 400;
|
2017-08-27 16:12:27 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
export default class PresentationOverlay extends Component {
|
2017-02-07 08:10:50 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// last sent coordinates
|
2017-09-01 09:42:00 +08:00
|
|
|
this.lastSentClientX = 0;
|
|
|
|
this.lastSentClientY = 0;
|
2017-02-07 08:10:50 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// last updated coordinates
|
2017-09-01 09:42:00 +08:00
|
|
|
this.currentClientX = 0;
|
|
|
|
this.currentClientY = 0;
|
2017-05-27 03:05:19 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// id of the setInterval()
|
|
|
|
this.intervalId = 0;
|
2018-08-14 03:29:38 +08:00
|
|
|
this.state = {
|
2018-08-29 00:09:52 +08:00
|
|
|
zoom: props.zoom,
|
2018-08-14 03:29:38 +08:00
|
|
|
};
|
2017-02-07 08:10:50 +08:00
|
|
|
|
2017-12-02 11:35:15 +08:00
|
|
|
// Mobile Firefox has a bug where e.preventDefault on touchstart doesn't prevent
|
|
|
|
// onmousedown from triggering right after. Thus we have to track it manually.
|
|
|
|
// In case if it's fixed one day - there is another issue, React one.
|
|
|
|
// https://github.com/facebook/react/issues/9809
|
|
|
|
// Check it to figure if you can add onTouchStart in render(), or should use raw DOM api
|
|
|
|
this.touchStarted = false;
|
|
|
|
|
|
|
|
this.handleTouchStart = this.handleTouchStart.bind(this);
|
|
|
|
this.handleTouchMove = this.handleTouchMove.bind(this);
|
|
|
|
this.handleTouchEnd = this.handleTouchEnd.bind(this);
|
|
|
|
this.handleTouchCancel = this.handleTouchCancel.bind(this);
|
2017-02-07 08:10:50 +08:00
|
|
|
this.mouseMoveHandler = this.mouseMoveHandler.bind(this);
|
|
|
|
this.checkCursor = this.checkCursor.bind(this);
|
|
|
|
this.mouseEnterHandler = this.mouseEnterHandler.bind(this);
|
|
|
|
this.mouseOutHandler = this.mouseOutHandler.bind(this);
|
2017-09-01 09:42:00 +08:00
|
|
|
this.getTransformedSvgPoint = this.getTransformedSvgPoint.bind(this);
|
|
|
|
this.svgCoordinateToPercentages = this.svgCoordinateToPercentages.bind(this);
|
2018-08-14 03:29:38 +08:00
|
|
|
this.mouseZoomHandler = this.mouseZoomHandler.bind(this);
|
2018-08-23 01:53:04 +08:00
|
|
|
this.zoomCalculation = this.zoomCalculation.bind(this);
|
|
|
|
this.doZoomCall = this.doZoomCall.bind(this);
|
2018-09-12 22:36:04 +08:00
|
|
|
this.tapHandler = this.tapHandler.bind(this);
|
2018-08-23 01:53:04 +08:00
|
|
|
this.zoomCall = this.zoomCall.bind(this);
|
2018-08-29 00:09:52 +08:00
|
|
|
|
2018-09-18 02:02:52 +08:00
|
|
|
this.panZoom = this.panZoom.bind(this);
|
|
|
|
this.pinchZoom = this.pinchZoom.bind(this);
|
|
|
|
this.toolbarZoom = this.toolbarZoom.bind(this);
|
|
|
|
|
2018-08-29 00:09:52 +08:00
|
|
|
this.isPortraitDoc = this.isPortraitDoc.bind(this);
|
|
|
|
this.doWidthBoundsDetection = this.doWidthBoundsDetection.bind(this);
|
|
|
|
this.doHeightBoundsDetection = this.doHeightBoundsDetection.bind(this);
|
|
|
|
this.calcViewedRegion = this.calcViewedRegion.bind(this);
|
|
|
|
this.onZoom = this.onZoom.bind(this);
|
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
const {
|
|
|
|
viewBoxWidth,
|
|
|
|
viewBoxHeight,
|
2018-08-29 00:09:52 +08:00
|
|
|
slideWidth,
|
2018-08-23 01:53:04 +08:00
|
|
|
slideHeight,
|
2018-08-29 00:09:52 +08:00
|
|
|
slide,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
this.fitToPage = false;
|
|
|
|
|
2018-09-12 22:36:04 +08:00
|
|
|
this.viewportW = slideWidth;
|
|
|
|
this.viewportH = slideHeight;
|
2018-08-29 00:09:52 +08:00
|
|
|
|
|
|
|
this.viewedRegionX = slide.xOffset;
|
|
|
|
this.viewedRegionY = slide.yOffset;
|
|
|
|
this.viewedRegionW = (viewBoxWidth / slideWidth) * 100;
|
|
|
|
this.viewedRegionH = (viewBoxHeight / slideHeight) * 100;
|
|
|
|
|
|
|
|
this.pageOrigW = slideWidth;
|
|
|
|
this.pageOrigH = slideHeight;
|
|
|
|
|
2018-09-12 22:36:04 +08:00
|
|
|
this.calcPageW = this.pageOrigW / (this.viewedRegionW / HUNDRED_PERCENT);
|
|
|
|
this.calcPageH = this.pageOrigH / (this.viewedRegionH / HUNDRED_PERCENT);
|
2018-08-29 00:09:52 +08:00
|
|
|
this.calcPageX = (this.viewedRegionX / HUNDRED_PERCENT) * this.calcPageW;
|
|
|
|
this.calcPageY = (this.viewedRegionY / HUNDRED_PERCENT) * this.calcPageH;
|
2018-09-12 22:36:04 +08:00
|
|
|
|
|
|
|
this.tapedTwice = false;
|
2018-09-18 02:02:52 +08:00
|
|
|
this.touches = [];
|
2018-08-29 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const {
|
|
|
|
viewBoxWidth,
|
2018-08-23 01:53:04 +08:00
|
|
|
slideWidth,
|
|
|
|
zoomChanger,
|
|
|
|
} = this.props;
|
|
|
|
|
2018-08-29 00:09:52 +08:00
|
|
|
const realZoom = (viewBoxWidth / slideWidth) * 100;
|
2018-09-12 22:36:04 +08:00
|
|
|
|
2018-08-29 00:09:52 +08:00
|
|
|
const zoomPercentage = (Math.round((100 / realZoom) * 100));
|
2018-09-18 02:02:52 +08:00
|
|
|
const roundedUpToFive = Math.round(zoomPercentage / 5) * 5;
|
|
|
|
zoomChanger(roundedUpToFive);
|
2018-08-23 01:53:04 +08:00
|
|
|
}
|
|
|
|
|
2018-09-05 01:37:36 +08:00
|
|
|
componentDidUpdate(prevProps) {
|
2018-08-29 00:09:52 +08:00
|
|
|
const {
|
2018-08-23 01:53:04 +08:00
|
|
|
zoom,
|
2018-09-05 01:37:36 +08:00
|
|
|
delta,
|
2018-09-18 02:02:52 +08:00
|
|
|
touchZoom,
|
2018-08-23 01:53:04 +08:00
|
|
|
} = this.props;
|
2018-09-18 02:02:52 +08:00
|
|
|
const isDifferent = zoom !== this.state.zoom && !touchZoom;
|
2018-09-05 01:37:36 +08:00
|
|
|
const moveSLide = ((delta.x !== prevProps.delta.x)
|
|
|
|
|| (delta.y !== prevProps.delta.y)) && !isDifferent;
|
2018-09-18 02:02:52 +08:00
|
|
|
const isTouchZoom = zoom !== this.state.zoom && touchZoom;
|
2018-09-05 01:37:36 +08:00
|
|
|
if (moveSLide) {
|
2018-09-18 02:02:52 +08:00
|
|
|
this.panZoom();
|
2018-09-05 01:37:36 +08:00
|
|
|
}
|
2018-08-23 01:53:04 +08:00
|
|
|
|
2018-09-18 02:02:52 +08:00
|
|
|
if (isTouchZoom) {
|
|
|
|
this.pinchZoom();
|
|
|
|
}
|
2018-08-23 01:53:04 +08:00
|
|
|
|
2018-08-29 03:30:37 +08:00
|
|
|
if (isDifferent) {
|
2018-09-18 02:02:52 +08:00
|
|
|
this.toolbarZoom();
|
2018-08-23 01:53:04 +08:00
|
|
|
}
|
|
|
|
}
|
2018-08-29 00:09:52 +08:00
|
|
|
|
|
|
|
onZoom(zoomValue, mouseX, mouseY) {
|
|
|
|
let absXcoordInPage = (Math.abs(this.calcPageX) * MYSTERY_NUM) + mouseX;
|
|
|
|
let absYcoordInPage = (Math.abs(this.calcPageY) * MYSTERY_NUM) + mouseY;
|
|
|
|
|
|
|
|
const relXcoordInPage = absXcoordInPage / this.calcPageW;
|
|
|
|
const relYcoordInPage = absYcoordInPage / this.calcPageH;
|
|
|
|
|
2018-10-19 01:03:11 +08:00
|
|
|
if (this.isPortraitDoc() && this.fitToPage) {
|
2018-08-29 00:09:52 +08:00
|
|
|
this.calcPageH = (this.viewportH * zoomValue) / HUNDRED_PERCENT;
|
|
|
|
this.calcPageW = (this.pageOrigW / this.pageOrigH) * this.calcPageH;
|
2018-10-19 01:03:11 +08:00
|
|
|
} else if (!this.isPortraitDoc() && this.fitToPage) {
|
2018-08-29 00:09:52 +08:00
|
|
|
this.calcPageW = (this.viewportW * zoomValue) / HUNDRED_PERCENT;
|
|
|
|
this.calcPageH = (this.viewportH * zoomValue) / HUNDRED_PERCENT;
|
|
|
|
} else {
|
|
|
|
this.calcPageW = (this.viewportW * zoomValue) / HUNDRED_PERCENT;
|
|
|
|
this.calcPageH = (this.calcPageW / this.pageOrigW) * this.pageOrigH;
|
|
|
|
}
|
|
|
|
|
|
|
|
absXcoordInPage = relXcoordInPage * this.calcPageW;
|
|
|
|
absYcoordInPage = relYcoordInPage * this.calcPageH;
|
|
|
|
|
|
|
|
this.calcPageX = -((absXcoordInPage - mouseX) / MYSTERY_NUM);
|
|
|
|
this.calcPageY = -((absYcoordInPage - mouseY) / MYSTERY_NUM);
|
|
|
|
|
|
|
|
this.doWidthBoundsDetection();
|
|
|
|
this.doHeightBoundsDetection();
|
|
|
|
|
|
|
|
this.calcViewedRegion();
|
2017-02-07 08:10:50 +08:00
|
|
|
}
|
2018-08-29 00:09:52 +08:00
|
|
|
|
2017-09-01 09:42:00 +08:00
|
|
|
getTransformedSvgPoint(clientX, clientY) {
|
|
|
|
const svgObject = this.props.getSvgRef();
|
|
|
|
const screenPoint = svgObject.createSVGPoint();
|
|
|
|
screenPoint.x = clientX;
|
|
|
|
screenPoint.y = clientY;
|
|
|
|
// transform a screen point to svg point
|
|
|
|
const CTM = svgObject.getScreenCTM();
|
2018-08-23 01:53:04 +08:00
|
|
|
|
2017-09-01 09:42:00 +08:00
|
|
|
return screenPoint.matrixTransform(CTM.inverse());
|
2017-02-07 08:10:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-18 02:02:52 +08:00
|
|
|
panZoom() {
|
|
|
|
const {
|
|
|
|
delta,
|
|
|
|
} = this.props;
|
|
|
|
this.deltaX = delta.x;
|
|
|
|
this.deltaY = delta.y;
|
|
|
|
this.calcPageX += delta.x * -1;
|
|
|
|
this.calcPageY += delta.y * -1;
|
|
|
|
this.doHeightBoundsDetection();
|
|
|
|
this.doWidthBoundsDetection();
|
|
|
|
this.calcViewedRegion();
|
|
|
|
this.zoomCall(
|
|
|
|
this.state.zoom,
|
|
|
|
this.viewedRegionW,
|
|
|
|
this.viewedRegionH,
|
|
|
|
this.viewedRegionX,
|
|
|
|
this.viewedRegionY,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
pinchZoom() {
|
|
|
|
const {
|
|
|
|
zoom,
|
|
|
|
} = this.props;
|
|
|
|
const posX = this.touches[0].clientX;
|
|
|
|
const posY = this.touches[0].clientY;
|
|
|
|
this.doZoomCall(zoom, posX, posY);
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbarZoom() {
|
|
|
|
const {
|
|
|
|
getSvgRef,
|
|
|
|
zoom,
|
|
|
|
} = this.props;
|
|
|
|
const svgRect = getSvgRef().getBoundingClientRect();
|
|
|
|
const svgCenterX = svgRect.left + (svgRect.width / 2);
|
|
|
|
const svgCenterY = svgRect.top + (svgRect.height / 2);
|
|
|
|
this.doZoomCall(zoom, svgCenterX, svgCenterY);
|
|
|
|
}
|
|
|
|
|
2018-08-29 00:09:52 +08:00
|
|
|
isPortraitDoc() {
|
|
|
|
return this.pageOrigH > this.pageOrigW;
|
|
|
|
}
|
|
|
|
|
|
|
|
doWidthBoundsDetection() {
|
|
|
|
const verifyPositionToBound = (this.calcPageW + (this.calcPageX * MYSTERY_NUM));
|
|
|
|
if (this.calcPageX >= 0) {
|
|
|
|
this.calcPageX = 0;
|
|
|
|
} else if (verifyPositionToBound < this.viewportW) {
|
|
|
|
this.calcPageX = (this.viewportW - this.calcPageW) / MYSTERY_NUM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doHeightBoundsDetection() {
|
|
|
|
const verifyPositionToBound = (this.calcPageH + (this.calcPageY * MYSTERY_NUM));
|
|
|
|
if (this.calcPageY >= 0) {
|
|
|
|
this.calcPageY = 0;
|
|
|
|
} else if (verifyPositionToBound < this.viewportH) {
|
|
|
|
this.calcPageY = (this.viewportH - this.calcPageH) / MYSTERY_NUM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
calcViewedRegion() {
|
|
|
|
this.viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(this.viewportW, this.calcPageW);
|
|
|
|
this.viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(this.viewportH, this.calcPageH);
|
|
|
|
this.viewedRegionX = SlideCalcUtil.calcViewedRegionX(this.calcPageX, this.calcPageW);
|
|
|
|
this.viewedRegionY = SlideCalcUtil.calcViewedRegionY(this.calcPageY, this.calcPageH);
|
|
|
|
}
|
|
|
|
|
2017-02-07 08:10:50 +08:00
|
|
|
checkCursor() {
|
2017-07-29 08:29:40 +08:00
|
|
|
// check if the cursor hasn't moved since last check
|
2017-09-01 09:42:00 +08:00
|
|
|
if (this.lastSentClientX !== this.currentClientX
|
|
|
|
|| this.lastSentClientY !== this.currentClientY) {
|
|
|
|
const { currentClientX, currentClientY } = this;
|
|
|
|
// retrieving a transformed coordinate
|
|
|
|
let transformedSvgPoint = this.getTransformedSvgPoint(currentClientX, currentClientY);
|
2018-08-29 00:09:52 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// determining the cursor's coordinates as percentages from the slide's width/height
|
2017-09-01 09:42:00 +08:00
|
|
|
transformedSvgPoint = this.svgCoordinateToPercentages(transformedSvgPoint);
|
2017-07-29 08:29:40 +08:00
|
|
|
// updating last sent raw coordinates
|
2017-09-01 09:42:00 +08:00
|
|
|
this.lastSentClientX = currentClientX;
|
|
|
|
this.lastSentClientY = currentClientY;
|
2017-07-29 08:29:40 +08:00
|
|
|
|
|
|
|
// sending the update to the server
|
2018-04-10 07:18:49 +08:00
|
|
|
this.props.updateCursor({
|
|
|
|
xPercent: transformedSvgPoint.x,
|
|
|
|
yPercent: transformedSvgPoint.y,
|
|
|
|
whiteboardId: this.props.whiteboardId,
|
|
|
|
});
|
2017-02-07 08:10:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 09:42:00 +08:00
|
|
|
// receives an svg coordinate and changes the values to percentages of the slide's width/height
|
|
|
|
svgCoordinateToPercentages(svgPoint) {
|
|
|
|
const point = {
|
|
|
|
x: (svgPoint.x / this.props.slideWidth) * 100,
|
|
|
|
y: (svgPoint.y / this.props.slideHeight) * 100,
|
|
|
|
};
|
|
|
|
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
zoomCalculation(zoom, mouseX, mouseY) {
|
|
|
|
const svgPosition = this.getTransformedSvgPoint(mouseX, mouseY);
|
2018-08-29 00:09:52 +08:00
|
|
|
this.onZoom(zoom, svgPosition.x, svgPosition.y);
|
2017-12-02 11:35:15 +08:00
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
return {
|
2018-08-29 00:09:52 +08:00
|
|
|
viewedRegionW: this.viewedRegionW,
|
|
|
|
viewedRegionH: this.viewedRegionH,
|
|
|
|
viewedRegionX: this.viewedRegionX,
|
|
|
|
viewedRegionY: this.viewedRegionY,
|
2018-08-23 01:53:04 +08:00
|
|
|
};
|
2018-08-16 19:20:02 +08:00
|
|
|
}
|
2017-12-02 11:35:15 +08:00
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
zoomCall(zoom, w, h, x, y) {
|
2018-08-14 03:29:38 +08:00
|
|
|
const {
|
|
|
|
zoomSlide,
|
|
|
|
podId,
|
|
|
|
currentSlideNum,
|
2018-09-20 02:10:25 +08:00
|
|
|
isPresenter,
|
2018-08-23 01:53:04 +08:00
|
|
|
} = this.props;
|
2018-09-20 02:10:25 +08:00
|
|
|
if (!isPresenter) return;
|
2018-08-23 01:53:04 +08:00
|
|
|
zoomSlide(currentSlideNum, podId, w, h, x, y);
|
|
|
|
this.setState({ zoom });
|
2018-09-20 02:10:25 +08:00
|
|
|
this.props.zoomChanger(zoom);
|
2018-08-23 01:53:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
doZoomCall(zoom, mouseX, mouseY) {
|
|
|
|
const zoomData = this.zoomCalculation(zoom, mouseX, mouseY);
|
2018-08-29 00:09:52 +08:00
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
const {
|
|
|
|
viewedRegionW,
|
|
|
|
viewedRegionH,
|
|
|
|
viewedRegionX,
|
|
|
|
viewedRegionY,
|
|
|
|
} = zoomData;
|
|
|
|
|
|
|
|
this.zoomCall(zoom, viewedRegionW, viewedRegionH, viewedRegionX, viewedRegionY);
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseZoomHandler(e) {
|
2018-08-29 00:09:52 +08:00
|
|
|
const {
|
|
|
|
zoom,
|
|
|
|
whiteboardId,
|
|
|
|
updateCursor,
|
|
|
|
} = this.props;
|
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
let newZoom = zoom;
|
|
|
|
if (e.deltaY < 0) {
|
|
|
|
newZoom += 5;
|
|
|
|
}
|
|
|
|
if (e.deltaY > 0) {
|
|
|
|
newZoom -= 5;
|
|
|
|
}
|
|
|
|
if (newZoom <= HUNDRED_PERCENT) {
|
|
|
|
newZoom = HUNDRED_PERCENT;
|
|
|
|
} else if (newZoom >= MAX_PERCENT) {
|
|
|
|
newZoom = MAX_PERCENT;
|
2018-10-19 01:03:11 +08:00
|
|
|
}
|
2018-08-23 01:53:04 +08:00
|
|
|
|
|
|
|
const mouseX = e.clientX;
|
|
|
|
const mouseY = e.clientY;
|
2018-08-29 00:09:52 +08:00
|
|
|
const svgPosition = this.getTransformedSvgPoint(mouseX, mouseY);
|
|
|
|
const svgPercentage = this.svgCoordinateToPercentages(svgPosition);
|
|
|
|
|
2018-08-23 01:53:04 +08:00
|
|
|
this.doZoomCall(newZoom, mouseX, mouseY);
|
2018-08-29 00:09:52 +08:00
|
|
|
updateCursor({
|
|
|
|
xPercent: svgPercentage.x,
|
|
|
|
yPercent: svgPercentage.y,
|
|
|
|
whiteboardId,
|
|
|
|
});
|
2018-08-14 03:29:38 +08:00
|
|
|
}
|
2018-09-12 22:36:04 +08:00
|
|
|
tapHandler(event) {
|
2018-10-19 01:03:11 +08:00
|
|
|
if (event.touches.length === 2) return;
|
2018-09-18 02:02:52 +08:00
|
|
|
if (!this.tapedTwice) {
|
|
|
|
this.tapedTwice = true;
|
|
|
|
setTimeout(() => this.tapedTwice = false, 300);
|
|
|
|
return;
|
2018-09-12 22:36:04 +08:00
|
|
|
}
|
2017-12-02 11:35:15 +08:00
|
|
|
event.preventDefault();
|
2018-09-12 22:36:04 +08:00
|
|
|
const sizeDefault = this.state.zoom === HUNDRED_PERCENT;
|
2017-12-02 11:35:15 +08:00
|
|
|
|
2018-10-19 01:03:11 +08:00
|
|
|
if (sizeDefault) {
|
2018-09-12 22:36:04 +08:00
|
|
|
this.doZoomCall(200, this.currentClientX, this.currentClientY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.doZoomCall(HUNDRED_PERCENT, 0, 0);
|
2018-10-19 01:03:11 +08:00
|
|
|
}
|
2018-08-14 03:29:38 +08:00
|
|
|
|
2017-12-02 11:35:15 +08:00
|
|
|
handleTouchStart(event) {
|
|
|
|
// to prevent default behavior (scrolling) on devices (in Safari), when you draw a text box
|
|
|
|
window.addEventListener('touchend', this.handleTouchEnd, { passive: false });
|
|
|
|
window.addEventListener('touchmove', this.handleTouchMove, { passive: false });
|
|
|
|
window.addEventListener('touchcancel', this.handleTouchCancel, true);
|
|
|
|
|
|
|
|
this.touchStarted = true;
|
|
|
|
|
|
|
|
const { clientX, clientY } = event.changedTouches[0];
|
|
|
|
this.currentClientX = clientX;
|
|
|
|
this.currentClientY = clientY;
|
2018-09-18 02:02:52 +08:00
|
|
|
if (event.touches.length === 2) {
|
|
|
|
this.touches = [...event.touches];
|
|
|
|
}
|
2017-12-02 11:35:15 +08:00
|
|
|
|
|
|
|
const intervalId = setInterval(this.checkCursor, CURSOR_INTERVAL);
|
|
|
|
this.intervalId = intervalId;
|
2018-09-12 22:36:04 +08:00
|
|
|
this.tapHandler(event);
|
2017-12-02 11:35:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTouchMove(event) {
|
2018-06-26 22:01:05 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
2017-12-02 11:35:15 +08:00
|
|
|
const { clientX, clientY } = event.changedTouches[0];
|
|
|
|
|
|
|
|
this.currentClientX = clientX;
|
|
|
|
this.currentClientY = clientY;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTouchEnd(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
// touch ended, removing the interval
|
|
|
|
clearInterval(this.intervalId);
|
|
|
|
this.intervalId = 0;
|
|
|
|
|
|
|
|
// resetting the touchStarted flag
|
|
|
|
this.touchStarted = false;
|
|
|
|
|
|
|
|
// setting the coords to negative values and send the last message (the cursor will disappear)
|
|
|
|
this.currentClientX = -1;
|
|
|
|
this.currentClientY = -1;
|
|
|
|
this.checkCursor();
|
|
|
|
|
|
|
|
window.removeEventListener('touchend', this.handleTouchEnd, { passive: false });
|
|
|
|
window.removeEventListener('touchmove', this.handleTouchMove, { passive: false });
|
|
|
|
window.removeEventListener('touchcancel', this.handleTouchCancel, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTouchCancel(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
// touch was cancelled, removing the interval
|
|
|
|
clearInterval(this.intervalId);
|
|
|
|
this.intervalId = 0;
|
|
|
|
|
|
|
|
// resetting the touchStarted flag
|
|
|
|
this.touchStarted = false;
|
|
|
|
|
|
|
|
// setting the coords to negative values and send the last message (the cursor will disappear)
|
|
|
|
this.currentClientX = -1;
|
|
|
|
this.currentClientY = -1;
|
|
|
|
this.checkCursor();
|
|
|
|
|
|
|
|
window.removeEventListener('touchend', this.handleTouchEnd, { passive: false });
|
|
|
|
window.removeEventListener('touchmove', this.handleTouchMove, { passive: false });
|
|
|
|
window.removeEventListener('touchcancel', this.handleTouchCancel, true);
|
|
|
|
}
|
|
|
|
|
2017-09-01 09:42:00 +08:00
|
|
|
mouseMoveHandler(event) {
|
2017-12-02 11:35:15 +08:00
|
|
|
if (this.touchStarted) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-01 09:42:00 +08:00
|
|
|
// for the case where you change settings in one of the lists (which are displayed on the slide)
|
|
|
|
// the mouse starts pointing to the slide right away and mouseEnter doesn't fire
|
|
|
|
// so we call it manually here
|
|
|
|
if (!this.intervalId) {
|
|
|
|
this.mouseEnterHandler();
|
|
|
|
}
|
|
|
|
|
2017-12-02 11:35:15 +08:00
|
|
|
this.currentClientX = event.clientX;
|
|
|
|
this.currentClientY = event.clientY;
|
2017-09-01 09:42:00 +08:00
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
mouseEnterHandler() {
|
2017-12-02 11:35:15 +08:00
|
|
|
if (this.touchStarted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-27 16:12:27 +08:00
|
|
|
const intervalId = setInterval(this.checkCursor, CURSOR_INTERVAL);
|
2017-05-27 03:05:19 +08:00
|
|
|
this.intervalId = intervalId;
|
2017-02-07 08:10:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
mouseOutHandler() {
|
|
|
|
// mouse left the whiteboard, removing the interval
|
2017-05-27 03:05:19 +08:00
|
|
|
clearInterval(this.intervalId);
|
|
|
|
this.intervalId = 0;
|
2017-07-29 08:29:40 +08:00
|
|
|
|
|
|
|
// setting the coords to negative values and send the last message (the cursor will disappear)
|
2017-09-01 09:42:00 +08:00
|
|
|
this.currentClientX = -1;
|
|
|
|
this.currentClientY = -1;
|
2017-07-29 08:29:40 +08:00
|
|
|
this.checkCursor();
|
2017-02-07 08:10:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<foreignObject
|
|
|
|
clipPath="url(#viewBox)"
|
2017-05-27 04:06:34 +08:00
|
|
|
x="0"
|
|
|
|
y="0"
|
|
|
|
width={this.props.slideWidth}
|
|
|
|
height={this.props.slideHeight}
|
2018-06-30 01:58:31 +08:00
|
|
|
// maximun value of z-index to prevent other things from overlapping
|
|
|
|
style={{ zIndex: 2 ** 31 - 1 }}
|
2017-02-07 08:10:50 +08:00
|
|
|
>
|
2017-07-29 08:29:40 +08:00
|
|
|
<div
|
2017-12-02 11:35:15 +08:00
|
|
|
onTouchStart={this.handleTouchStart}
|
2017-07-29 08:29:40 +08:00
|
|
|
onMouseOut={this.mouseOutHandler}
|
|
|
|
onMouseEnter={this.mouseEnterHandler}
|
|
|
|
onMouseMove={this.mouseMoveHandler}
|
2018-08-14 03:29:38 +08:00
|
|
|
onWheel={this.mouseZoomHandler}
|
|
|
|
onBlur={() => {}}
|
2017-12-02 11:35:15 +08:00
|
|
|
style={{ width: '100%', height: '100%', touchAction: 'none' }}
|
2017-07-29 08:29:40 +08:00
|
|
|
>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
2017-02-07 08:10:50 +08:00
|
|
|
</foreignObject>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 08:29:40 +08:00
|
|
|
|
|
|
|
PresentationOverlay.propTypes = {
|
2018-04-10 07:18:49 +08:00
|
|
|
whiteboardId: PropTypes.string.isRequired,
|
|
|
|
|
2017-09-01 09:42:00 +08:00
|
|
|
// Defines a function which returns a reference to the main svg object
|
|
|
|
getSvgRef: PropTypes.func.isRequired,
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// Defines the calculated slide width (in svg coordinate system)
|
|
|
|
slideWidth: PropTypes.number.isRequired,
|
|
|
|
|
|
|
|
// Defines the calculated slide height (in svg coordinate system)
|
|
|
|
slideHeight: PropTypes.number.isRequired,
|
|
|
|
|
|
|
|
// A function to send a cursor update
|
|
|
|
updateCursor: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
// As a child we expect only a WhiteboardOverlay at this point
|
|
|
|
children: PropTypes.element.isRequired,
|
|
|
|
};
|