Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule SyntheticMouseEvent
10
* @typechecks static-only
11
*/
12
13
"use strict";
14
15
var SyntheticUIEvent = require('SyntheticUIEvent');
16
var ViewportMetrics = require('ViewportMetrics');
17
18
var getEventModifierState = require('getEventModifierState');
19
20
/**
21
* @interface MouseEvent
22
* @see http://www.w3.org/TR/DOM-Level-3-Events/
23
*/
24
var MouseEventInterface = {
25
screenX: null,
26
screenY: null,
27
clientX: null,
28
clientY: null,
29
ctrlKey: null,
30
shiftKey: null,
31
altKey: null,
32
metaKey: null,
33
getModifierState: getEventModifierState,
34
button: function(event) {
35
// Webkit, Firefox, IE9+
36
// which: 1 2 3
37
// button: 0 1 2 (standard)
38
var button = event.button;
39
if ('which' in event) {
40
return button;
41
}
42
// IE<9
43
// which: undefined
44
// button: 0 0 0
45
// button: 1 4 2 (onmouseup)
46
return button === 2 ? 2 : button === 4 ? 1 : 0;
47
},
48
buttons: null,
49
relatedTarget: function(event) {
50
return event.relatedTarget || (
51
event.fromElement === event.srcElement ?
52
event.toElement :
53
event.fromElement
54
);
55
},
56
// "Proprietary" Interface.
57
pageX: function(event) {
58
return 'pageX' in event ?
59
event.pageX :
60
event.clientX + ViewportMetrics.currentScrollLeft;
61
},
62
pageY: function(event) {
63
return 'pageY' in event ?
64
event.pageY :
65
event.clientY + ViewportMetrics.currentScrollTop;
66
}
67
};
68
69
/**
70
* @param {object} dispatchConfig Configuration used to dispatch this event.
71
* @param {string} dispatchMarker Marker identifying the event target.
72
* @param {object} nativeEvent Native browser event.
73
* @extends {SyntheticUIEvent}
74
*/
75
function SyntheticMouseEvent(dispatchConfig, dispatchMarker, nativeEvent) {
76
SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent);
77
}
78
79
SyntheticUIEvent.augmentClass(SyntheticMouseEvent, MouseEventInterface);
80
81
module.exports = SyntheticMouseEvent;
82
83