@@ -22,12 +22,15 @@ import {
2222 clearFakeSelection
2323} from '../conversion/model-selection-to-view-converters' ;
2424
25- import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin' ;
25+ import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin' ;
26+ import mix from '@ckeditor/ckeditor5-utils/src/mix' ;
2627
2728/**
2829 * Controller for the editing pipeline. The editing pipeline controls {@link ~EditingController#model model} rendering,
2930 * including selection handling. It also creates {@link ~EditingController#view view document} which build a
3031 * browser-independent virtualization over the DOM elements. Editing controller also attach default converters.
32+ *
33+ * @mixes module:utils/observablemixin~ObservableMixin
3134 */
3235export default class EditingController {
3336 /**
@@ -60,6 +63,19 @@ export default class EditingController {
6063 */
6164 this . mapper = new Mapper ( ) ;
6265
66+ /**
67+ * Defines whether controller is in read-only mode.
68+ *
69+ * When controller is read-ony then {module:engine/view/document~Document view document} is read-only as well.
70+ *
71+ * @observable
72+ * @member {Boolean} #isReadOnly
73+ */
74+ this . set ( 'isReadOnly' , false ) ;
75+
76+ // When controller is read-only the view document is read-only as well.
77+ this . view . bind ( 'isReadOnly' ) . to ( this ) ;
78+
6379 /**
6480 * Model to view conversion dispatcher, which converts changes from the model to
6581 * {@link #view editing view}.
@@ -80,39 +96,30 @@ export default class EditingController {
8096 viewSelection : this . view . selection
8197 } ) ;
8298
83- /**
84- * Property keeping all listenters attached by controller on other objects, so it can
85- * stop listening on {@link #destroy}.
86- *
87- * @private
88- * @member {utils.EmitterMixin} #_listener
89- */
90- this . _listener = Object . create ( EmitterMixin ) ;
91-
9299 // Convert changes in model to view.
93- this . _listener . listenTo ( this . model , 'change' , ( evt , type , changes ) => {
100+ this . listenTo ( this . model , 'change' , ( evt , type , changes ) => {
94101 this . modelToView . convertChange ( type , changes ) ;
95102 } , { priority : 'low' } ) ;
96103
97104 // Convert model selection to view.
98- this . _listener . listenTo ( this . model , 'changesDone' , ( ) => {
105+ this . listenTo ( this . model , 'changesDone' , ( ) => {
99106 const selection = this . model . selection ;
100107
101108 this . modelToView . convertSelection ( selection ) ;
102109 this . view . render ( ) ;
103110 } , { priority : 'low' } ) ;
104111
105112 // Convert model markers changes.
106- this . _listener . listenTo ( this . model . markers , 'add' , ( evt , marker ) => {
113+ this . listenTo ( this . model . markers , 'add' , ( evt , marker ) => {
107114 this . modelToView . convertMarker ( 'addMarker' , marker . name , marker . getRange ( ) ) ;
108115 } ) ;
109116
110- this . _listener . listenTo ( this . model . markers , 'remove' , ( evt , marker ) => {
117+ this . listenTo ( this . model . markers , 'remove' , ( evt , marker ) => {
111118 this . modelToView . convertMarker ( 'removeMarker' , marker . name , marker . getRange ( ) ) ;
112119 } ) ;
113120
114121 // Convert view selection to model.
115- this . _listener . listenTo ( this . view , 'selectionChange' , convertSelectionChange ( this . model , this . mapper ) ) ;
122+ this . listenTo ( this . view , 'selectionChange' , convertSelectionChange ( this . model , this . mapper ) ) ;
116123
117124 // Attach default content converters.
118125 this . modelToView . on ( 'insert:$text' , insertText ( ) , { priority : 'lowest' } ) ;
@@ -158,6 +165,8 @@ export default class EditingController {
158165 */
159166 destroy ( ) {
160167 this . view . destroy ( ) ;
161- this . _listener . stopListening ( ) ;
168+ this . stopListening ( ) ;
162169 }
163170}
171+
172+ mix ( EditingController , ObservableMixin ) ;
0 commit comments