346b871a57033934e178f40642a56d7fc2200cd38e9194476184de9a9e02046b2d60535ecf57d0dff7368020fbcd9d06e877a44cf23a530f05d3e77c090517 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export class ViewUserInputEvents {
  6. constructor(coordinatesConverter) {
  7. this.onKeyDown = null;
  8. this.onKeyUp = null;
  9. this.onContextMenu = null;
  10. this.onMouseMove = null;
  11. this.onMouseLeave = null;
  12. this.onMouseDown = null;
  13. this.onMouseUp = null;
  14. this.onMouseDrag = null;
  15. this.onMouseDrop = null;
  16. this.onMouseDropCanceled = null;
  17. this.onMouseWheel = null;
  18. this._coordinatesConverter = coordinatesConverter;
  19. }
  20. emitKeyDown(e) {
  21. var _a;
  22. (_a = this.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(this, e);
  23. }
  24. emitKeyUp(e) {
  25. var _a;
  26. (_a = this.onKeyUp) === null || _a === void 0 ? void 0 : _a.call(this, e);
  27. }
  28. emitContextMenu(e) {
  29. var _a;
  30. (_a = this.onContextMenu) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  31. }
  32. emitMouseMove(e) {
  33. var _a;
  34. (_a = this.onMouseMove) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  35. }
  36. emitMouseLeave(e) {
  37. var _a;
  38. (_a = this.onMouseLeave) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  39. }
  40. emitMouseDown(e) {
  41. var _a;
  42. (_a = this.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  43. }
  44. emitMouseUp(e) {
  45. var _a;
  46. (_a = this.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  47. }
  48. emitMouseDrag(e) {
  49. var _a;
  50. (_a = this.onMouseDrag) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  51. }
  52. emitMouseDrop(e) {
  53. var _a;
  54. (_a = this.onMouseDrop) === null || _a === void 0 ? void 0 : _a.call(this, this._convertViewToModelMouseEvent(e));
  55. }
  56. emitMouseDropCanceled() {
  57. var _a;
  58. (_a = this.onMouseDropCanceled) === null || _a === void 0 ? void 0 : _a.call(this);
  59. }
  60. emitMouseWheel(e) {
  61. var _a;
  62. (_a = this.onMouseWheel) === null || _a === void 0 ? void 0 : _a.call(this, e);
  63. }
  64. _convertViewToModelMouseEvent(e) {
  65. if (e.target) {
  66. return {
  67. event: e.event,
  68. target: this._convertViewToModelMouseTarget(e.target)
  69. };
  70. }
  71. return e;
  72. }
  73. _convertViewToModelMouseTarget(target) {
  74. return ViewUserInputEvents.convertViewToModelMouseTarget(target, this._coordinatesConverter);
  75. }
  76. static convertViewToModelMouseTarget(target, coordinatesConverter) {
  77. const result = Object.assign({}, target);
  78. if (result.position) {
  79. result.position = coordinatesConverter.convertViewPositionToModelPosition(result.position);
  80. }
  81. if (result.range) {
  82. result.range = coordinatesConverter.convertViewRangeToModelRange(result.range);
  83. }
  84. return result;
  85. }
  86. }