OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). |
5 * Copyright (C) 2009 Joseph Pecoraro | 5 * Copyright (C) 2009 Joseph Pecoraro |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * | 10 * |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 } | 972 } |
973 | 973 |
974 function cancelAnimation() | 974 function cancelAnimation() |
975 { | 975 { |
976 window.cancelAnimationFrame(raf); | 976 window.cancelAnimationFrame(raf); |
977 } | 977 } |
978 | 978 |
979 return cancelAnimation; | 979 return cancelAnimation; |
980 } | 980 } |
981 | 981 |
| 982 /** |
| 983 * @constructor |
| 984 * @extends {WebInspector.Object} |
| 985 * @param {!Element} element |
| 986 */ |
| 987 WebInspector.LongClickController = function(element) |
| 988 { |
| 989 this._element = element; |
| 990 } |
| 991 |
| 992 /** |
| 993 * @enum {string} |
| 994 */ |
| 995 WebInspector.LongClickController.Events = { |
| 996 LongClick: "LongClick", |
| 997 LongPress: "LongPress" |
| 998 }; |
| 999 |
| 1000 WebInspector.LongClickController.prototype = { |
| 1001 reset: function() |
| 1002 { |
| 1003 if (this._longClickInterval) { |
| 1004 clearInterval(this._longClickInterval); |
| 1005 delete this._longClickInterval; |
| 1006 } |
| 1007 }, |
| 1008 |
| 1009 enable: function() |
| 1010 { |
| 1011 if (this._longClickData) |
| 1012 return; |
| 1013 var boundMouseDown = mouseDown.bind(this); |
| 1014 var boundMouseUp = mouseUp.bind(this); |
| 1015 var boundReset = this.reset.bind(this); |
| 1016 |
| 1017 this._element.addEventListener("mousedown", boundMouseDown, false); |
| 1018 this._element.addEventListener("mouseout", boundReset, false); |
| 1019 this._element.addEventListener("mouseup", boundMouseUp, false); |
| 1020 this._element.addEventListener("click", boundReset, true); |
| 1021 |
| 1022 var longClicks = 0; |
| 1023 |
| 1024 this._longClickData = { mouseUp: boundMouseUp, mouseDown: boundMouseDown
, reset: boundReset }; |
| 1025 |
| 1026 /** |
| 1027 * @param {!Event} e |
| 1028 * @this {WebInspector.LongClickController} |
| 1029 */ |
| 1030 function mouseDown(e) |
| 1031 { |
| 1032 if (e.which !== 1) |
| 1033 return; |
| 1034 longClicks = 0; |
| 1035 this._longClickInterval = setInterval(longClicked.bind(this, e), 200
); |
| 1036 } |
| 1037 |
| 1038 /** |
| 1039 * @param {!Event} e |
| 1040 * @this {WebInspector.LongClickController} |
| 1041 */ |
| 1042 function mouseUp(e) |
| 1043 { |
| 1044 if (e.which !== 1) |
| 1045 return; |
| 1046 this.reset(); |
| 1047 } |
| 1048 |
| 1049 /** |
| 1050 * @param {!Event} e |
| 1051 * @this {WebInspector.LongClickController} |
| 1052 */ |
| 1053 function longClicked(e) |
| 1054 { |
| 1055 ++longClicks; |
| 1056 this.dispatchEventToListeners(longClicks === 1 ? WebInspector.LongCl
ickController.Events.LongClick : WebInspector.LongClickController.Events.LongPre
ss, e); |
| 1057 } |
| 1058 }, |
| 1059 |
| 1060 disable: function() |
| 1061 { |
| 1062 if (!this._longClickData) |
| 1063 return; |
| 1064 this._element.removeEventListener("mousedown", this._longClickData.mouse
Down, false); |
| 1065 this._element.removeEventListener("mouseout", this._longClickData.reset,
false); |
| 1066 this._element.removeEventListener("mouseup", this._longClickData.mouseUp
, false); |
| 1067 this._element.addEventListener("click", this._longClickData.reset, true)
; |
| 1068 delete this._longClickData; |
| 1069 }, |
| 1070 |
| 1071 __proto__: WebInspector.Object.prototype |
| 1072 } |
| 1073 |
982 ;(function() { | 1074 ;(function() { |
983 | 1075 |
984 function windowLoaded() | 1076 function windowLoaded() |
985 { | 1077 { |
986 window.addEventListener("focus", WebInspector._windowFocused, false); | 1078 window.addEventListener("focus", WebInspector._windowFocused, false); |
987 window.addEventListener("blur", WebInspector._windowBlurred, false); | 1079 window.addEventListener("blur", WebInspector._windowBlurred, false); |
988 document.addEventListener("focus", WebInspector._focusChanged, true); | 1080 document.addEventListener("focus", WebInspector._focusChanged, true); |
989 document.addEventListener("blur", WebInspector._documentBlurred, true); | 1081 document.addEventListener("blur", WebInspector._documentBlurred, true); |
990 window.removeEventListener("DOMContentLoaded", windowLoaded, false); | 1082 window.removeEventListener("DOMContentLoaded", windowLoaded, false); |
991 } | 1083 } |
992 | 1084 |
993 window.addEventListener("DOMContentLoaded", windowLoaded, false); | 1085 window.addEventListener("DOMContentLoaded", windowLoaded, false); |
994 | 1086 |
995 })(); | 1087 })(); |
OLD | NEW |