| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
ve.ce.KeyDownHandlerFactory = function VeCeKeyDownHandlerFactory() { |
| 15 |
|
| 16 |
ve.ce.KeyDownHandlerFactory.super.apply( this, arguments ); |
| 17 |
|
| 18 |
|
| 19 |
this.handlerNamesByKeys = {}; |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ce.KeyDownHandlerFactory, OO.Factory ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
ve.ce.KeyDownHandlerFactory.prototype.register = function ( constructor ) { |
| 46 |
|
| 47 |
ve.ce.KeyDownHandlerFactory.super.prototype.register.call( this, constructor ); |
| 48 |
|
| 49 |
const keys = constructor.static.keys; |
| 50 |
const name = constructor.static.name; |
| 51 |
|
| 52 |
|
| 53 |
for ( let i = 0, ilen = keys.length; i < ilen; i++ ) { |
| 54 |
this.handlerNamesByKeys[ keys[ i ] ] = this.handlerNamesByKeys[ keys[ i ] ] || []; |
| 55 |
if ( this.handlerNamesByKeys[ keys[ i ] ].indexOf( name ) === -1 ) { |
| 56 |
this.handlerNamesByKeys[ keys[ i ] ].push( name ); |
| 57 |
} |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ve.ce.KeyDownHandlerFactory.prototype.lookupHandlersForKey = function ( key, selectionName ) { |
| 69 |
const constructors = [], |
| 70 |
names = this.handlerNamesByKeys[ key ] || []; |
| 71 |
|
| 72 |
|
| 73 |
for ( let i = 0; i < names.length; i++ ) { |
| 74 |
const constructor = this.registry[ names[ i ] ]; |
| 75 |
const supportedSelections = constructor.static.supportedSelections; |
| 76 |
if ( !supportedSelections || supportedSelections.indexOf( selectionName ) !== -1 ) { |
| 77 |
constructors.push( constructor ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
return constructors; |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
ve.ce.KeyDownHandlerFactory.prototype.executeHandlersForKey = function ( key, selectionName, surface, e ) { |
| 94 |
const handlers = this.lookupHandlersForKey( key, selectionName ); |
| 95 |
|
| 96 |
let acted = false; |
| 97 |
|
| 98 |
for ( let i = 0; i < handlers.length; i++ ) { |
| 99 |
if ( handlers[ i ].static.execute( surface, e ) ) { |
| 100 |
acted = true; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
return acted; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
ve.ce.keyDownHandlerFactory = new ve.ce.KeyDownHandlerFactory(); |