UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

121 lines • 6.36 kB
// ***************************************************************************** // Copyright (C) 2019 TypeFox and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** var ApplicationShellMouseTracker_1; import { __decorate } from "tslib"; import { ApplicationShell } from './application-shell.js'; import { injectable, inject } from 'inversify'; import { DisposableCollection, Disposable } from '../../common/disposable.js'; import { Emitter } from '../../common/event.js'; import { PanelLayout, SplitPanel } from '@lumino/widgets'; import { addEventListener } from '../widgets/index.js'; import { NativeTabDragService } from './native-tab-drag-service.js'; import { SecondaryWindowService } from '../window/secondary-window-service.js'; /** * Contribution that tracks `mouseup` and `mousedown` events. * * This is required to be able to track the `TabBar`, `DockPanel`, and `SidePanel` resizing and drag and drop events correctly * all over the application. By default, when the mouse is over an `iframe` we lose the mouse tracking ability, so whenever * we click (`mousedown`), we overlay a transparent `div` over the `iframe` in the Mini Browser, then we set the `display` of * the transparent `div` to `none` on `mouseup` events. */ let ApplicationShellMouseTracker = ApplicationShellMouseTracker_1 = class ApplicationShellMouseTracker { constructor() { this.toDispose = new DisposableCollection(); this.toDisposeOnActiveChange = new DisposableCollection(); this.mouseupEmitter = new Emitter(); this.mousedownEmitter = new Emitter(); this.mouseupListener = e => this.mouseupEmitter.fire(e); this.mousedownListener = e => this.mousedownEmitter.fire(e); } onStart() { // Here we need to attach a `mousedown` listener to the `TabBar`s, `DockPanel`s and the `SidePanel`s. Otherwise, Lumino handles the event and stops the propagation. // Track the `mousedown` on the `TabBar` for the currently active widget. this.applicationShell.onDidChangeActiveWidget((args) => { this.toDisposeOnActiveChange.dispose(); if (args.newValue) { const tabBar = this.applicationShell.getTabBarFor(args.newValue); if (tabBar) { this.toDisposeOnActiveChange.push(addEventListener(tabBar.node, 'mousedown', this.mousedownListener, true)); } } }); // Track the `mousedown` events for the `SplitPanel`s, if any. const { layout } = this.applicationShell; if (layout instanceof PanelLayout) { this.toDispose.pushAll(layout.widgets.filter(ApplicationShellMouseTracker_1.isSplitPanel).map(splitPanel => addEventListener(splitPanel.node, 'mousedown', this.mousedownListener, true))); } // Track the `mousedown` on each `DockPanel`. const { mainPanel, bottomPanel, leftPanelHandler, rightPanelHandler } = this.applicationShell; this.toDispose.pushAll([mainPanel, bottomPanel, leftPanelHandler.dockPanel, rightPanelHandler.dockPanel] .map(panel => addEventListener(panel.node, 'mousedown', this.mousedownListener, true))); // The `mouseup` event has to be tracked on the `document`. Lumino attaches to there. document.addEventListener('mouseup', this.mouseupListener, true); // Also track `mouseup` in secondary windows so that overlays are correctly hidden // when the mouse is released in a secondary window. this.toDispose.push(this.secondaryWindowService.onWindowLoaded(win => { win.document.addEventListener('mouseup', this.mouseupListener, true); })); this.toDispose.push(this.secondaryWindowService.onWindowClosed(win => { try { win.document.removeEventListener('mouseup', this.mouseupListener, true); } catch { // window may already be destroyed } })); // Native tab drags end without a `mouseup` event. They may also start in a secondary window, whose `mousedown` events are not tracked. this.toDispose.pushAll([ this.nativeTabDragService.onDidStartDrag(e => this.mousedownEmitter.fire(e)), this.nativeTabDragService.onDidEndDrag(e => this.mouseupEmitter.fire(e)) ]); // Make sure it is disposed in the end. this.toDispose.pushAll([ this.mousedownEmitter, this.mouseupEmitter, Disposable.create(() => document.removeEventListener('mouseup', this.mouseupListener, true)) ]); } onStop() { this.toDispose.dispose(); this.toDisposeOnActiveChange.dispose(); } get onMouseup() { return this.mouseupEmitter.event; } get onMousedown() { return this.mousedownEmitter.event; } }; __decorate([ inject(ApplicationShell) ], ApplicationShellMouseTracker.prototype, "applicationShell", void 0); __decorate([ inject(NativeTabDragService) ], ApplicationShellMouseTracker.prototype, "nativeTabDragService", void 0); __decorate([ inject(SecondaryWindowService) ], ApplicationShellMouseTracker.prototype, "secondaryWindowService", void 0); ApplicationShellMouseTracker = ApplicationShellMouseTracker_1 = __decorate([ injectable() ], ApplicationShellMouseTracker); export { ApplicationShellMouseTracker }; (function (ApplicationShellMouseTracker) { function isSplitPanel(arg) { return arg instanceof SplitPanel; } ApplicationShellMouseTracker.isSplitPanel = isSplitPanel; })(ApplicationShellMouseTracker || (ApplicationShellMouseTracker = {})); //# sourceMappingURL=application-shell-mouse-tracker.js.map