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 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 * @param {!Object} object | 909 * @param {!Object} object |
910 * @param {function()} method | 910 * @param {function()} method |
911 */ | 911 */ |
912 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) | 912 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) |
913 { | 913 { |
914 if (!WebInspector._postUpdateHandlers) | 914 if (!WebInspector._postUpdateHandlers) |
915 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(t
rue); | 915 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(t
rue); |
916 WebInspector._postUpdateHandlers.add(object, method); | 916 WebInspector._postUpdateHandlers.add(object, method); |
917 } | 917 } |
918 | 918 |
| 919 /** |
| 920 * @param {!Function} func |
| 921 * @param {!Array.<{from:number, to:number}>} params |
| 922 * @param {number} frames |
| 923 * @param {function()=} animationComplete |
| 924 * @return {function()} |
| 925 */ |
| 926 WebInspector.animateFunction = function(func, params, frames, animationComplete) |
| 927 { |
| 928 var values = new Array(params.length); |
| 929 var deltas = new Array(params.length); |
| 930 for (var i = 0; i < params.length; ++i) { |
| 931 values[i] = params[i].from; |
| 932 deltas[i] = (params[i].to - params[i].from) / frames; |
| 933 } |
| 934 |
| 935 var raf = requestAnimationFrame(animationStep); |
| 936 |
| 937 var framesLeft = frames; |
| 938 |
| 939 function animationStep() |
| 940 { |
| 941 if (--framesLeft < 0) { |
| 942 if (animationComplete) |
| 943 animationComplete(); |
| 944 return; |
| 945 } |
| 946 for (var i = 0; i < params.length; ++i) { |
| 947 if (params[i].to > params[i].from) |
| 948 values[i] = Number.constrain(values[i] + deltas[i], params[i].fr
om, params[i].to); |
| 949 else |
| 950 values[i] = Number.constrain(values[i] + deltas[i], params[i].to
, params[i].from); |
| 951 } |
| 952 func.apply(null, values); |
| 953 raf = window.requestAnimationFrame(animationStep); |
| 954 } |
| 955 |
| 956 function cancelAnimation() |
| 957 { |
| 958 window.cancelAnimationFrame(raf); |
| 959 } |
| 960 |
| 961 return cancelAnimation; |
| 962 } |
| 963 |
919 ;(function() { | 964 ;(function() { |
920 | 965 |
921 function windowLoaded() | 966 function windowLoaded() |
922 { | 967 { |
923 window.addEventListener("focus", WebInspector._windowFocused, false); | 968 window.addEventListener("focus", WebInspector._windowFocused, false); |
924 window.addEventListener("blur", WebInspector._windowBlurred, false); | 969 window.addEventListener("blur", WebInspector._windowBlurred, false); |
925 document.addEventListener("focus", WebInspector._focusChanged, true); | 970 document.addEventListener("focus", WebInspector._focusChanged, true); |
926 document.addEventListener("blur", WebInspector._documentBlurred, true); | 971 document.addEventListener("blur", WebInspector._documentBlurred, true); |
927 window.removeEventListener("DOMContentLoaded", windowLoaded, false); | 972 window.removeEventListener("DOMContentLoaded", windowLoaded, false); |
928 } | 973 } |
929 | 974 |
930 window.addEventListener("DOMContentLoaded", windowLoaded, false); | 975 window.addEventListener("DOMContentLoaded", windowLoaded, false); |
931 | 976 |
932 })(); | 977 })(); |
OLD | NEW |