X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F03_XDomEvent.js;h=7c94b060a6138254cf344b2254d6e94bb347fe4e;hb=512e08f4d38eab417f9651277e8a50c08535cb07;hp=4ab70ddece30528c412a2bf5564426c3291d707f;hpb=86c591d2888cf7b24365c1950646fb1f6190efd1;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/03_XDomEvent.js b/0.6.x/js/02_dom/03_XDomEvent.js index 4ab70dd..7c94b06 100644 --- a/0.6.x/js/02_dom/03_XDomEvent.js +++ b/0.6.x/js/02_dom/03_XDomEvent.js @@ -11,8 +11,10 @@ */ // http://msdn.microsoft.com/ja-jp/library/ie/dn255104%28v=vs.85%29.aspx -var X_Dom_Event_devicePixelRatio = window.devicePixelRatio || ( window.screen.deviceXDPI / window.screen.logicalXDPI ), - X_Dom_Event_convertMSPointerType = window.MSPointerEvent && [ 0, 0, 'touch', 'pen', 'mouse' ],/*{ +var X_Dom_Event_devicePixelRatio = window.devicePixelRatio || ( window.screen.deviceXDPI / window.screen.logicalXDPI ) || 1, + + X_Dom_Event_convertMSPointerType = ( !window.PointerEvent && window.MSPointerEvent ) && [ 0, 0, 'touch', 'pen', 'mouse' ], // WP8.1 は PointerEvent と MSPointerEvent 両方ある + /*{ '2' : 'touch', '3' : 'pen', '4' : 'mouse' @@ -20,6 +22,12 @@ var X_Dom_Event_devicePixelRatio = window.devicePixelRatio || ( window.screen.de X_Dom_Event_CANCEL_MOUSE = {}, X_DomEvent; +if( X_Dom_Event_devicePixelRatio !== 1 ){ + X_UA_classNameForHTML += ' dpr' + X_Dom_Event_devicePixelRatio; + + X_UA[ 'dpr' ] = X_Dom_Event_devicePixelRatio; +}; + if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ X_DomEvent = function( e, xnode ){ var originalType = e.type, @@ -62,7 +70,7 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ this[ 'pressure' ] = e.pressure || ( e.button !== -1 ? 0.5 : 0 ); // ポインターの接触形状の スクリーン ピクセル単位の幅と高さ なので変換。(多分、、、) this[ 'width' ] = e.width / X_Dom_Event_devicePixelRatio; - this[ 'height' ] = e.height / X_Dom_Event_devicePixelRatio; + this[ 'height' ] = e.height / X_Dom_Event_devicePixelRatio; } else { this[ 'pointerType' ] = e.pointerType; this[ 'pressure' ] = e.pressure; @@ -163,7 +171,7 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ 'width' : touch.width || 0, 'height' : touch.height || 0 }; - console.log( 'e.pointerId = ' + touch.identifier ); + //console.log( 'e.pointerId = ' + touch.identifier ); }; return events.length === 1 ? events[ 0 ] : events; } else { @@ -177,15 +185,14 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ this[ 'type' ] = pointerEventType; this[ 'pointerType' ] = 'mouse'; - this[ 'button' ] = e.button !== undefined ? e.button : - e.which !== undefined ? e.which - 1 : -1; + this[ 'button' ] = e.button !== undefined ? e.button : e.which !== undefined ? e.which - 1 : -1; this[ 'buttons' ] = e.buttons !== undefined ? e.buttons : this[ 'button' ] === 0 ? 1 : this[ 'button' ] === 1 ? 2 : this[ 'button' ] === 2 ? 4 : 0; this[ 'pressure' ] = ( this[ 'button' ] !== -1 ? 0.5 : 0 ); elm = e.target; this[ 'target' ] = X_Node_getXNode( elm.nodeType === 3 ? elm.parentNode : elm );// defeat Safari bug // xnodetouch.target; this[ 'isPrimary' ] = true; - this[ 'hwTimestamp' ] = this[ 'timestamp' ] = X_Timer_now(); + this[ 'hwTimestamp' ] = this[ 'timestamp' ] = X_Timer_now(); this[ 'altKey' ] = e.altKey; this[ 'ctrlKey' ] = e.ctrlKey; this[ 'metaKey' ] = e.metaKey; @@ -205,7 +212,7 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ // http://www.programming-magic.com/20090127231544/ // Opera で button==2の場合、コンテキストメニューイベントを発火 「ツール」->「設定」->「詳細設定」->「コンテンツ」->「Javascriptオプション」で「右クリックを制御するスクリプトを許可する」 if( originalType === 'mousedown' && this[ 'button' ] === 2 && X_UA[ 'Opera' ] ){ - events = [ X_Object_clone( this ), X_Object_clone( this ) ]; + events = [ X_Object_copy( this ), X_Object_copy( this ) ]; events[ 1 ].type = 'contextmenu'; return events; }; @@ -213,11 +220,12 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ } else { // Other - this[ 'keyCode' ] = e.keyCode || e.which; - this[ 'altKey' ] = e.altKey; - this[ 'ctrlKey' ] = e.ctrlKey; - this[ 'shiftKey' ] = e.shiftKey; - this[ 'metaKey' ] = e.metaKey; + this[ 'keyCode' ] = X_Type_isFinite( e.keyCode ) ? e.keyCode : X_Type_isFinite( e.charCode ) ? e.charCode : e.which; + this[ 'charCode' ] = X_Type_isFinite( e.charCode ) ? e.charCode : e.which; + this[ 'altKey' ] = e.altKey || !!( e.modifiers & 1 ); + this[ 'ctrlKey' ] = e.ctrlKey || !!( e.modifiers & 2 ); + this[ 'shiftKey' ] = e.shiftKey || !!( e.modifiers & 4 ); + this[ 'metaKey' ] = e.metaKey || !!( e.modifiers & 8 );; this[ 'button' ] = e.button !== undefined ? e.button : e.which !== undefined ? e.which - 1 : -1; @@ -272,9 +280,11 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ if( this[ 'target' ] && !this[ 'target' ][ '_tag' ] ) this[ 'target' ] = this[ 'target' ].parent; // ie4 の fake Textnode がヒットしていないか? this[ 'currentTarget' ] = xnode; // xnode this[ 'relatedTarget' ] = X_Node_getXNode( e.formElement || e.toElement ); // xnode + this[ 'relatedTarget' ] && console.dir( 'relatide...' ); this[ 'eventPhase' ] = e.srcElement === element ? 2: 3; this[ 'keyCode' ] = e.keyCode; + this[ 'charCode' ] = e.keyCode; this[ 'altKey' ] = e.altKey; this[ 'ctrlKey' ] = e.ctrlKey; this[ 'shiftKey' ] = e.shiftKey; @@ -317,6 +327,7 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ if( type = X_Event_toPointer[ originalType ] ){ this[ 'type' ] = type; + this[ 'pointerType' ] = 'mouse'; this[ 'clientX' ] = e.clientX; this[ 'clientY' ] = e.clientY; //this[ 'screenX' ] = e.screenX; @@ -338,7 +349,9 @@ if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ // this[ 'offsetX' ] = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。 // this[ 'offsetY' ] = e.y - e.srcElement.offsetTop; //}; - + this[ 'pressure' ] = ( this[ 'button' ] !== -1 ? 0.5 : 0 ); + this[ 'isPrimary' ] = true; + this[ 'hwTimestamp' ] = this[ 'timestamp' ] = X_Timer_now(); this[ 'pointerId' ] = 1; this[ 'radiusX' ] = 0; this[ 'radiusY' ] = 0; @@ -431,6 +444,8 @@ if( !navigator.pointerEnabled ){ X_Event_Rename[ 'pointerup' ] = 'MSPointerUp'; X_Event_Rename[ 'pointermove' ] = [ 'MSPointerMove', 'MSPointerHover' ];// ie10 と ie11 でペンのhoverevent の値が異なる X_Event_Rename[ 'pointercancel' ] = 'MSPointerCancel'; + X_Event_Rename[ 'pointerout' ] = 'MSPointerOut'; + X_Event_Rename[ 'pointerleave' ] = 'MSPointerLeave'; // http://msdn.microsoft.com/ja-jp/library/ie/dn304886%28v=vs.85%29.aspx } else if( X_UA_HID.TOUCH ){ @@ -439,12 +454,16 @@ if( !navigator.pointerEnabled ){ X_Event_Rename[ 'pointerup' ] = [ 'touchend', 'mouseup' ]; X_Event_Rename[ 'pointermove' ] = [ 'touchmove', 'mousemove' ]; X_Event_Rename[ 'pointercancel' ] = 'touchcancel'; + //X_Event_Rename[ 'pointerout' ] = + X_Event_Rename[ 'pointerleave' ] = 'touchleave'; // X_Event_Rename[ 'click' ] = [ 'touchstart', 'touchmove', 'touchend' ]; // ループになってしまう!直した!直ってない! } else { X_Event_Rename[ 'pointerdown' ] = 'mousedown'; X_Event_Rename[ 'pointerup' ] = 'mouseup'; X_Event_Rename[ 'pointermove' ] = 'mousemove'; - X_Event_Rename[ 'pointercancel' ] = document.documentElement.onmouseleave !== undefined ? 'mouseleave' : 'mouseout';//?? + //X_Event_Rename[ 'pointercancel' ] = + //X_Event_Rename[ 'pointerout' ] = + X_Event_Rename[ 'pointerleave' ] = X_elmHtml.onmouseleave !== undefined ? 'mouseleave' : 'mouseout'; // Opera は ブラウザ設定から右クリックの通知を許可すると mousedown で e.button==2 が返る,キャンセルは可能?? X_UA[ 'Opera' ] && ( X_Event_Rename[ 'contextmenu' ] = 'mousedown' );