reworked the key handler a bit...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2012-09-10 04:23:48 +04:00
parent f4ff9adcba
commit 4f8ebda91c
2 changed files with 60 additions and 43 deletions

View File

@ -1483,13 +1483,17 @@ function makeKeyboardHandler(keybindings, unhandled){
unhandled = function(){return false} unhandled = function(){return false}
} }
return function(evt){ return function(evt){
var did_handling = false
var res = null
for(var mode in keybindings){ for(var mode in keybindings){
if($(mode).length > 0){ if($(mode).length > 0){
var bindings = keybindings[mode] var bindings = keybindings[mode]
var key = evt.keyCode var key = evt.keyCode
if(bindings.ignore != null && bindings.ignore.indexOf(key) != -1){ if(bindings.ignore != null && bindings.ignore.indexOf(key) != -1){
return true // return true
did_handling = true
continue
} }
// XXX ugly... // XXX ugly...
var modifers = evt.ctrlKey ? 'ctrl' : '' var modifers = evt.ctrlKey ? 'ctrl' : ''
@ -1504,7 +1508,7 @@ function makeKeyboardHandler(keybindings, unhandled){
} }
// no handler... // no handler...
if(handler == null){ if(handler == null){
return unhandled(key) continue
} }
// Array, lisp style with docs... // Array, lisp style with docs...
// XXX for some odd reason in chrome typeof([]) == typeof({})!!! // XXX for some odd reason in chrome typeof([]) == typeof({})!!!
@ -1519,17 +1523,25 @@ function makeKeyboardHandler(keybindings, unhandled){
callback = handler['default'] callback = handler['default']
} }
if(callback != null){ if(callback != null){
var res = callback() res = callback()
return KEYBOARD_HANDLER_PROPAGATE&&res?true:false did_handling = true
continue
} }
} else { } else {
// simple callback... // simple callback...
var res = handler() res = handler()
return KEYBOARD_HANDLER_PROPAGATE&&res?true:false did_handling = true
continue
} }
return unhandled(key)
} }
} }
if(!did_handling){
// key is unhandled by any modes...
return unhandled(key)
} else {
// XXX should we handle multiple hits???
return KEYBOARD_HANDLER_PROPAGATE&&res?true:false
}
} }
} }

View File

@ -2,31 +2,11 @@
// NOTE: use String.fromCharCode(code)... // NOTE: use String.fromCharCode(code)...
// list of keys to be ignored by handler but still handled by the browser... // list of keys to be ignored by handler but still handled by the browser...
var keybindings = { var keybindings = {
'.overlay-mode': { // global bindings...
title: 'Overlay mode', '*': {
doc: 'overlay mode key bindings.', title: 'Global',
doc: '',
ignore: [
37, // Left
39, // Right
36, // Home
32, // Space
35, // End
38, // Up
40, // Down
],
27: ImageGrid.closeOverlay, // Esc
},
//'*': {
// everything except overlays...
'.viewer *:not(.overlay-mode *)': {
title: 'ALL',
doc: 'global key bindings.',
ignore: [ ignore: [
116, // F5 116, // F5
@ -53,6 +33,43 @@ var keybindings = {
27: ImageGrid.closeOverlay, // Esc 27: ImageGrid.closeOverlay, // Esc
// ignore the modifiers (shift, alt, ctrl, caps)...
16: function(){},
17: 16,
18: 16,
20: 16, // Caps Lock
// refresh...
// XXX make this into a real action...
116: function(){ return DEBUG?true:false }, // F5
112: 116, // F12
},
// overlay...
'.overlay-mode': {
title: 'Overlay mode',
doc: 'Overlay mode key bindings.',
ignore: [
33, // PgUp
34, // PgDown
37, // Left
39, // Right
36, // Home
32, // Space
35, // End
38, // Up
40, // Down
],
},
// everything except overlays...
'.viewer *:not(.overlay-mode *)': {
title: 'Ribbon and Viewer',
doc: '',
// zooming... // zooming...
187: ImageGrid.scaleContainerUp, // + 187: ImageGrid.scaleContainerUp, // +
189: ImageGrid.scaleContainerDown, // - 189: ImageGrid.scaleContainerDown, // -
@ -118,18 +135,6 @@ var keybindings = {
// misc actions... // misc actions...
82: ImageGrid.reverseImageOrder, // r 82: ImageGrid.reverseImageOrder, // r
// ignore the modifiers (shift, alt, ctrl, caps)...
16: function(){},
17: 16,
18: 16,
20: 16, // Caps Lock
// refresh...
// XXX make this into a real action...
116: function(){ return DEBUG?true:false }, // F5
112: 116, // F12
} }
} }