compositionobserver.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/view/observer/compositionobserver
  7. */
  8. import DomEventObserver from './domeventobserver';
  9. /**
  10. * {@link module:engine/view/document~Document#event:compositionstart Compositionstart},
  11. * {@link module:engine/view/document~Document#event:compositionupdate compositionupdate} and
  12. * {@link module:engine/view/document~Document#event:compositionend compositionend} events observer.
  13. *
  14. * Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
  15. *
  16. * @extends module:engine/view/observer/domeventobserver~DomEventObserver
  17. */
  18. export default class CompositionObserver extends DomEventObserver {
  19. constructor( view ) {
  20. super( view );
  21. this.domEventType = [ 'compositionstart', 'compositionupdate', 'compositionend' ];
  22. const document = this.document;
  23. document.on( 'compositionstart', () => {
  24. document.isComposing = true;
  25. } );
  26. document.on( 'compositionend', () => {
  27. document.isComposing = false;
  28. } );
  29. }
  30. onDomEvent( domEvent ) {
  31. this.fire( domEvent.type, domEvent );
  32. }
  33. }
  34. /**
  35. * Fired when composition starts inside one of the editables.
  36. *
  37. * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
  38. *
  39. * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
  40. * {@link module:engine/view/view~View} this event is available by default.
  41. *
  42. * @see module:engine/view/observer/compositionobserver~CompositionObserver
  43. * @event module:engine/view/document~Document#event:compositionstart
  44. * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
  45. */
  46. /**
  47. * Fired when composition is updated inside one of the editables.
  48. *
  49. * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
  50. *
  51. * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
  52. * {@link module:engine/view/view~View} this event is available by default.
  53. *
  54. * @see module:engine/view/observer/compositionobserver~CompositionObserver
  55. * @event module:engine/view/document~Document#event:compositionupdate
  56. * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
  57. */
  58. /**
  59. * Fired when composition ends inside one of the editables.
  60. *
  61. * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
  62. *
  63. * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
  64. * {@link module:engine/view/view~View} this event is available by default.
  65. *
  66. * @see module:engine/view/observer/compositionobserver~CompositionObserver
  67. * @event module:engine/view/document~Document#event:compositionend
  68. * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
  69. */