OSDN Git Service

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