Changeset 8264

Show
Ignore:
Timestamp:
04/24/07 05:01:03 (19 months ago)
Author:
sjmiles
Message:

Event.js: all browsers: set keyCode to 0 when charCode has a value, norm CTRL-BREAK to CTRL-c where possible, IE: use native keypress for ESC and ENTER
refs #2641

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/_base/event.js

    r8235 r8264  
    117117        // Constants 
    118118 
    119         // FIXME: alex: why is this public now? 
     119        // Public: client code must test 
     120        // keyCode against these named constants, as the 
     121        // actual codes can vary by browser. 
    120122        dojo.keys = { 
    121123                BACKSPACE: 8, 
     
    179181        }; 
    180182 
    181         // NOTE: alex: can't find a public usage of this function. making it private. 
    182         dojo._isAsciiPrintable = function(charCode){ 
    183                 return (charCode>31&&charCode<128)||(charCode>127&&charCode<255); 
    184         } 
    185  
    186183        // IE event normalization 
    187184        if(dojo.isIE){  
     
    286283                                // Generally, eventName should be lower case, unless it is 
    287284                                // special somehow (e.g. a Mozilla event) 
    288  
    289285                                // ensure 'on' 
    290286                                return (eventName.slice(0,2)!="on" ? "on"+eventName : eventName); 
     
    315311                                // avoid dependency on that entire module. Now that HTML is in 
    316312                                // Base, we should convert back to something similar there. 
    317  
    318313                                var se = evt.srcElement, doc = (se && se.ownerDocument) || document; 
    319314                                // DO NOT replace the following to use dojo.body(), in IE, document.documentElement should be used 
    320315                                // here rather than document.body 
    321                                 //var docBody = ((dojo.render.html.ie55)||(doc["compatMode"] == "BackCompat")) ? doc.body : doc.documentElement; 
    322                                 var docBody = doc.documentElement; 
     316                                var docBody = ((dojo.isIE<6)||(doc["compatMode"]=="BackCompat")) ? doc.body : doc.documentElement; 
    323317                                evt.pageX = evt.clientX + (docBody.scrollLeft || 0); 
    324318                                evt.pageY = evt.clientY + (docBody.scrollTop || 0); 
     
    337331                                        case "keypress": 
    338332                                                var c = ("charCode" in evt ? evt.charCode : evt.keyCode); 
     333                                                if (c==13||c==27){ 
     334                                                        c=0; // Mozilla considers ENTER and ESC non-printable 
     335                                                }else if(c==3){ 
     336                                                        c=99; // Mozilla maps CTRL-BREAK to CTRL-c 
     337                                                } 
    339338                                                evt.charCode = c; 
     339                                                evt.keyCode = (c ? 0 : evt.keyCode); 
    340340                                                de._fixKey(evt); 
    341341                                                break; 
     
    369369                                                // These are Windows Virtual Key Codes 
    370370                                                // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp 
    371                                                 var unprintable = (c!=32)&&(c<48||c>90)&&(c<96||c>111)&&(c<186||c>192)&&(c<219||c>222); 
     371                                                var unprintable = (c!=13)&&(c!=32)&&(c!=27)&&(c<48||c>90)&&(c<96||c>111)&&(c<186||c>192)&&(c<219||c>222); 
    372372                                                if(unprintable||evt.ctrlKey){ 
    373373                                                        c = (unprintable ? 0 : c); 
    374374                                                        if(evt.ctrlKey){ 
    375                                                                 if(c>95 && c<106){  
     375                                                                if(evt.keyCode==3){ 
     376                                                                        break; // IE will post CTRL-BREAK as keypress natively                                                                   
     377                                                                }else if(c>95 && c<106){  
    376378                                                                        c -= 48; // map CTRL-[numpad 0-9] to ASCII 
    377379                                                                }else if((!evt.shiftKey)&&(c>=65&&c<=90)){  
     
    393395                                                                evt.keyCode = faux.keyCode; 
    394396                                                        }catch(e){};  
    395                                                 }else{ 
    396                                                         evt.charCode = evt.keyCode; 
    397                                                         de._fixKey(evt); 
    398397                                                } 
    399398                                                break; 
     
    418417        } 
    419418 
     419        de._synthesizeEvent = function(evt, keyCode, charCode, shiftKey) { 
     420                        var faux = {  
     421                                type: evt.type,  
     422                                shiftKey: shiftKey,  
     423                                ctrlKey: evt.ctrlKey,  
     424                                altKey: evt.altKey,  
     425                                keyCode: (charCode ? 0 : keyCode),  
     426                                charCode: charCode 
     427                        }; 
     428                        de._fixKey(faux, charCode); 
     429                        // FIXME: would prefer to use dojo.hitch: dojo.hitch(evt, evt.preventDefault);  
     430                        // but it throws an error when preventDefault is invoked on Safari 
     431                        // does Event.preventDefault not support "apply" on Safari? 
     432                        faux.preventDefault = function(){ evt.preventDefault(); };  
     433                        faux.stopPropagation = function(){ evt.stopPropagation(); };  
     434                        return faux; 
     435        } 
     436         
    420437        // Opera event normalization 
    421438        if(dojo.isOpera){ 
     
    425442                                        case "keypress": 
    426443                                                var c = evt.which; 
     444                                                if(c==3){ 
     445                                                        c=99; // Mozilla maps CTRL-BREAK to CTRL-c 
     446                                                } 
    427447                                                // can't trap some keys at all, like INSERT and DELETE 
    428448                                                // there is no differentiating info between DELETE and ".", or INSERT and "-" 
     
    432452                                                        c += 32; 
    433453                                                } 
    434                                                 evt.charCode = c; 
    435                                                 de._fixKey(evt, c); 
    436                                                 break; 
     454                                                return de._synthesizeEvent(evt, evt.keyCode, c, evt.shiftKey); 
    437455                                } 
    438456                                return evt; 
     
    443461        // Safari event normalization 
    444462        if(dojo.isSafari){  
    445                 //alert("mixing in Safari event fix"); 
    446463                dojo.mixin(de, { 
    447464                        _fixEvent: function(evt, sender){ 
     
    459476                                                        c = (c>=32 && c<63232 ? c : 0); // avoid generating keyChar for non-printables 
    460477                                                } 
    461                                                 // We have to create a faux event to control shiftKey on Safari 
    462                                                 var faux = {  
    463                                                         type: evt.type,  
    464                                                         shiftKey: s,  
    465                                                         ctrlKey: evt.ctrlKey,  
    466                                                         altKey: evt.altKey,  
    467                                                         keyCode: evt.keyCode,  
    468                                                         charCode: c 
    469                                                 }; 
    470                                                 de._fixKey(faux, c); 
    471                                                 // FIXME: would prefer to use dojo.hitch: dojo.hitch(evt, evt.preventDefault);  
    472                                                 // but it throws an error when preventDefault is invoked 
    473                                                 // does Event.preventDefault not support "apply" on Safari? 
    474                                                 faux.preventDefault = function(){ evt.preventDefault(); };  
    475                                                 faux.stopPropagation = function(){ evt.stopPropagation(); };  
    476                                                 return faux; 
     478                                                return de._synthesizeEvent(evt, keyCode, c, s); 
    477479                                } 
    478480                                return evt;