domeventdata.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/view/observer/domeventdata
  7. */
  8. import extend from '@ckeditor/ckeditor5-utils/src/lib/lodash/extend';
  9. /**
  10. * Information about a DOM event in context of the {@link module:engine/view/document~Document}.
  11. * It wraps the native event, which usually should not be used as the wrapper contains
  12. * additional data (like key code for keyboard events).
  13. */
  14. export default class DomEventData {
  15. /**
  16. * @param {module:engine/view/document~Document} document The instance of the tree view Document.
  17. * @param {Event} domEvent The DOM event.
  18. * @param {Object} [additionalData] Additional properties that the instance should contain.
  19. */
  20. constructor( document, domEvent, additionalData ) {
  21. /**
  22. * The instance of the document.
  23. *
  24. * @readonly
  25. * @member {module:engine/view/document~Document} module:engine/view/observer/observer~Observer.DomEvent#view
  26. */
  27. this.document = document;
  28. /**
  29. * The DOM event.
  30. *
  31. * @readonly
  32. * @member {Event} module:engine/view/observer/observer~Observer.DomEvent#domEvent
  33. */
  34. this.domEvent = domEvent;
  35. /**
  36. * The DOM target.
  37. *
  38. * @readonly
  39. * @member {HTMLElement} module:engine/view/observer/observer~Observer.DomEvent#target
  40. */
  41. this.domTarget = domEvent.target;
  42. extend( this, additionalData );
  43. }
  44. /**
  45. * The tree view element representing the target.
  46. *
  47. * @readonly
  48. * @type module:engine/view/element~Element
  49. */
  50. get target() {
  51. return this.document.domConverter.getCorrespondingViewElement( this.domTarget );
  52. }
  53. /**
  54. * Prevents the native's event default action.
  55. */
  56. preventDefault() {
  57. this.domEvent.preventDefault();
  58. }
  59. /**
  60. * Stops native event propagation.
  61. */
  62. stopPropagation() {
  63. this.domEvent.stopPropagation();
  64. }
  65. }