@itwin/core-frontend
Version:
iTwin.js frontend components
53 lines • 2.49 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Tools
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventController = void 0;
const ToolAdmin_1 = require("./ToolAdmin");
/**
* An EventController maps user input events from a Viewport to the ToolAdmin so that tools can process them.
* Viewports are assigned an EventController when they are registered with ViewManager.addViewport and they are destroyed with ViewManager.dropViewport.
* @public
* @extensions
*/
class EventController {
vp;
_removals = [];
constructor(vp) {
this.vp = vp;
const element = vp.parentDiv;
if (element === undefined)
return;
// Put events on the parentDiv to allows us to stopPropagation of events to the view canvas when they are meant for a sibling of view canvas (markup canvas, for example).
this.addDomListeners(["mousedown", "mouseup", "mousemove", "mouseover", "mouseout", "wheel", "touchstart", "touchend", "touchcancel", "touchmove"], element);
element.oncontextmenu = element.onselectstart = () => false;
}
destroy() {
this._removals.forEach((remove) => remove());
this._removals.length = 0;
}
/**
* Call element.addEventListener for each type of DOM event supplied. Creates a listener that will forward the HTML event to ToolAdmin.addEvent.
* Records the listener in the [[removals]] member so they are removed when this EventController is destroyed.
* @param domType An array of DOM event types to pass to element.addEventListener
* @param element The HTML element to which the listeners are added
*/
addDomListeners(domType, element) {
const vp = this.vp;
const listener = (ev) => {
ev.preventDefault();
ToolAdmin_1.ToolAdmin.addEvent(ev, vp);
};
domType.forEach((type) => {
element.addEventListener(type, listener, false);
this._removals.push(() => element.removeEventListener(type, listener, false));
});
}
}
exports.EventController = EventController;
//# sourceMappingURL=EventController.js.map
;