| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
ve.ce.SurfaceObserver = function VeCeSurfaceObserver( surface ) { |
| 16 |
|
| 17 |
this.surface = surface; |
| 18 |
this.domDocument = surface.attachedRoot.getElementDocument(); |
| 19 |
this.polling = false; |
| 20 |
this.disabled = false; |
| 21 |
this.timeoutId = null; |
| 22 |
this.pollInterval = 250; |
| 23 |
this.rangeState = null; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
OO.initClass( ve.ce.SurfaceObserver ); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
ve.ce.SurfaceObserver.prototype.clear = function () { |
| 36 |
this.rangeState = null; |
| 37 |
}; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
ve.ce.SurfaceObserver.prototype.detach = function () { |
| 43 |
this.surface = null; |
| 44 |
this.domDocument = null; |
| 45 |
this.rangeState = null; |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
ve.ce.SurfaceObserver.prototype.startTimerLoop = function () { |
| 52 |
this.polling = true; |
| 53 |
this.timerLoop( true ); |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ve.ce.SurfaceObserver.prototype.timerLoop = function ( firstTime ) { |
| 62 |
if ( this.timeoutId ) { |
| 63 |
|
| 64 |
clearTimeout( this.timeoutId ); |
| 65 |
this.timeoutId = null; |
| 66 |
} |
| 67 |
if ( !firstTime ) { |
| 68 |
this.pollOnce(); |
| 69 |
} |
| 70 |
|
| 71 |
if ( this.pollInterval !== null ) { |
| 72 |
this.timeoutId = this.setTimeout( |
| 73 |
this.timerLoop.bind( this ), |
| 74 |
this.pollInterval |
| 75 |
); |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
ve.ce.SurfaceObserver.prototype.stopTimerLoop = function () { |
| 83 |
if ( this.polling === true ) { |
| 84 |
this.polling = false; |
| 85 |
clearTimeout( this.timeoutId ); |
| 86 |
this.timeoutId = null; |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
ve.ce.SurfaceObserver.prototype.disable = function () { |
| 94 |
this.disabled = true; |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
ve.ce.SurfaceObserver.prototype.enable = function () { |
| 101 |
this.disabled = false; |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
ve.ce.SurfaceObserver.prototype.pollOnce = function () { |
| 108 |
this.pollOnceInternal( true ); |
| 109 |
}; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
ve.ce.SurfaceObserver.prototype.pollOnceNoCallback = function () { |
| 115 |
this.pollOnceInternal( false ); |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
ve.ce.SurfaceObserver.prototype.pollOnceSelection = function () { |
| 124 |
this.pollOnceInternal( true, true ); |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
ve.ce.SurfaceObserver.prototype.pollOnceInternal = function ( signalChanges, selectionOnly ) { |
| 135 |
if ( !this.domDocument || this.disabled ) { |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
const oldState = this.rangeState; |
| 140 |
const newState = new ve.ce.RangeState( |
| 141 |
oldState, |
| 142 |
this.surface.attachedRoot, |
| 143 |
selectionOnly |
| 144 |
); |
| 145 |
this.rangeState = newState; |
| 146 |
|
| 147 |
if ( signalChanges && ( |
| 148 |
newState.contentChanged || |
| 149 |
newState.branchNodeChanged || |
| 150 |
newState.selectionChanged |
| 151 |
) ) { |
| 152 |
this.surface.handleObservedChanges( oldState, newState ); |
| 153 |
} |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
ve.ce.SurfaceObserver.prototype.setTimeout = function ( callback, timeout ) { |
| 164 |
return setTimeout( callback, timeout ); |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
ve.ce.SurfaceObserver.prototype.getRange = function () { |
| 175 |
if ( !this.rangeState ) { |
| 176 |
return null; |
| 177 |
} |
| 178 |
return this.rangeState.veRange; |
| 179 |
}; |