Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

277 wiersze
9.2KB

  1. /*
  2. * DebuggingSupport.js
  3. * Keynote HTML Player
  4. *
  5. * Responsibility: Tungwei Cheng
  6. * Copyright (c) 2009-2013 Apple Inc. All rights reserved.
  7. */
  8. // Set this to "false" to disable ALL debugging logic
  9. var gDebug = false;
  10. // Set this to "false" to disable debug messages when running on the iPhone or iPad
  11. var gDebugOnMobile = false;
  12. // Globals:
  13. // ===============================================================
  14. var gNumDebugMessagesSent = 0;
  15. var gNumDebugMessagesQueued = 0;
  16. var gDebugMessageQueue = new Array();
  17. var gDebugMessageRequest = null;
  18. var gDebugLastClassName = "";
  19. var gDebugLastMethodName = "";
  20. // Enable these constants to simulate various conditions/errors:
  21. var gDebugSimulateSlowTextureDownload = false;
  22. var gDebugSimulateTextureLoadFailure = false;
  23. var gDebugSimulateScriptDownloadFailure = false;
  24. // Constants:
  25. // ===============================================================
  26. var kDebugFunction = "function";
  27. var kDebugSurpressMessage = "!NoOp_!NoOp";
  28. //----------------------------------------------------------------------
  29. var kDebugSetupShowController = kDebugFunction + "_" + "setupShowController";
  30. //----------------------------------------------------------------------
  31. var kDebugShowController = "!ShowController";
  32. var kDebugShowController_AdvanceToNextBuild = kDebugShowController + "_" + "!advanceToNextBuild";
  33. var kDebugShowController_AdvanceToNextSlide = kDebugShowController + "_" + "!advanceToNextSlide";
  34. var kDebugShowController_DoIdleProcessing = kDebugShowController + "_" + "!doIdleProcessing";
  35. var kDebugShowController_GoBackToPreviousBuild = kDebugShowController + "_" + "!goBackToPreviousBuild";
  36. var kDebugShowController_GoBackToPreviousSlide = kDebugShowController + "_" + "!goBackToPreviousSlide";
  37. var kDebugShowController_HandleScriptDidDownloadEvent = kDebugShowController + "_" + "!handleScriptDidDownloadEvent";
  38. var kDebugShowController_HandleScriptDidNotDownloadEvent = kDebugShowController + "_" + "!handleScriptDidNotDownloadEvent";
  39. var kDebugShowController_JumpToScene = kDebugShowController + "_" + "!jumpToScene";
  40. var kDebugShowController_OnKeyPress = kDebugShowController + "_" + "!onKeyPress";
  41. //----------------------------------------------------------------------
  42. var kDebugTouchController = "!TouchController";
  43. var kDebugTouchController_HandleGestureEndEvent = kDebugTouchController + "_" + "!handleGestureEndEvent";
  44. var kDebugTouchController_HandleGestureStartEvent = kDebugTouchController + "_" + "!handleGestureStartEvent";
  45. var kDebugTouchController_HandleTouchCancelEvent = kDebugTouchController + "_" + "!handleTouchCancelEvent";
  46. var kDebugTouchController_HandleTouchCancelEvent = kDebugTouchController + "_" + "!handleTouchMoveEvent";
  47. var kDebugTouchController_HandleTouchEndEvent = kDebugTouchController + "_" + "!handleTouchEndEvent";
  48. var kDebugTouchController_HandleTouchStartEvent = kDebugTouchController + "_" + "!handleTouchStartEvent";
  49. var kDebugTouchController_Initialize = kDebugTouchController + "_" + "!initialize";
  50. var kDebugTouchController_IsTouchWithinTrackArea = kDebugTouchController + "_" + "!isTouchWithinTrackArea";
  51. var kDebugTouchController_SetTrackArea = kDebugTouchController + "_" + "!setTrackArea";
  52. //----------------------------------------------------------------------
  53. var kDebugScriptMangaer = "!ScriptManager";
  54. var kDebugScriptMangaer_DownloadScript = kDebugScriptMangaer + "_" + "!downloadScript";
  55. //----------------------------------------------------------------------
  56. var kDebugTimer = "DebugTimer";
  57. var kDebugTimer_AdvanceToNextBuild = kDebugTimer + "_" + "!advanceToNextBuild";
  58. var kDebugTimer_CreateAnimationsForScene = kDebugTimer + "_" + "!createAnimationsForScene";
  59. var kDebugTimer_ApplyAnimationsForScene = kDebugTimer + "_" + "!applyAnimationsForScene";
  60. var kDebugTimer_PreProcessSceneAnimations = kDebugTimer + "_" + "!preProcessSceneAnimations";
  61. var kDebugTimer_AdvanceToNextBuild_to_ApplyAnimations = kDebugTimer + "_" + "!preProcessSceneAnimations_to_ApplyAnimations";
  62. var kDebugTimer_JumpToScene = kDebugTimer + "_" + "!jumpToScene";
  63. var kDebugTimer_DisplayScene = kDebugTimer + "_" + "!displayScene";
  64. // Functions:
  65. // ===============================================================
  66. function debugWarning(sender, messageText) {
  67. if (gDebug === false) {
  68. return;
  69. }
  70. debugSendMessage(sender, "WARNING: " + messageText, true);
  71. }
  72. function debugMessageAlways(sender, messageText) {
  73. debugSendMessage(sender, messageText, true);
  74. }
  75. function debugMessage(sender, messageText) {
  76. if (gDebug == false) {
  77. return;
  78. }
  79. if ((gDevice == kDeviceMobile) && (gDebugOnMobile == false)) {
  80. return;
  81. }
  82. debugSendMessage(sender, messageText, false);
  83. }
  84. function debugSendMessage(sender, messageText, always) {
  85. var indexOfUnderscore = sender.indexOf("_");
  86. var className = sender.substring(0, indexOfUnderscore);
  87. var methodName = sender.substring(indexOfUnderscore + 1);
  88. var suppress = false;
  89. if (className[0] == "!") {
  90. className = className.substring(1);
  91. suppress = true;
  92. }
  93. if (methodName[0] == "!") {
  94. methodName = methodName.substring(1);
  95. suppress = true;
  96. }
  97. if (methodName[0] == "+") {
  98. methodName = methodName.substring(1);
  99. always = true;
  100. }
  101. if ((suppress == true) && (always == false)) {
  102. return;
  103. }
  104. var prefix = "";
  105. if (messageText == null) {
  106. messageText = "";
  107. }
  108. if (messageText[0] != "-" || className != gDebugLastClassName || methodName != gDebugLastMethodName) {
  109. if (className == kDebugTimer) {
  110. prefix = sender + ": ";
  111. }
  112. else if (className == kDebugFunction) {
  113. prefix = methodName + "() ";
  114. }
  115. else {
  116. prefix = className + "." + methodName + "() ";
  117. }
  118. } else {
  119. prefix = "";
  120. }
  121. gDebugLastClassName = className;
  122. gDebugLastMethodName = methodName;
  123. if (gDevice == kDeviceMobile) {
  124. gNumDebugMessagesSent++;
  125. var formattedMessageText = escape(gNumDebugMessagesSent + ": " + prefix + messageText);
  126. gDebugMessageQueue[gNumDebugMessagesQueued] = formattedMessageText;
  127. gNumDebugMessagesQueued++;
  128. if (gNumDebugMessagesQueued == 1) {
  129. debugCheckMessageQueue();
  130. }
  131. } else {
  132. if (window.console) {
  133. window.console.log( prefix + messageText );
  134. }
  135. }
  136. }
  137. function debugSendNextMessageInQueue() {
  138. var formattedMessageText = gDebugMessageQueue[0];
  139. gNumDebugMessagesQueued--;
  140. gDebugMessageQueue.splice(0,1);
  141. var messageUrl = '/debugMessage.rhtml?message="' + formattedMessageText + '"';
  142. new Ajax.Request( messageUrl, {
  143. method: "get",
  144. onSuccess: function(transport) {debugMessageWasSent(transport);},
  145. onFailure: function(transport) {debugMessageWasNotSent(transport);}
  146. });
  147. }
  148. function debugMessageWasSent(transport) {
  149. debugCheckMessageQueue();
  150. }
  151. function debugMessageWasNotSent(transport) {
  152. debugCheckMessageQueue();
  153. }
  154. function debugCheckMessageQueue() {
  155. if (gNumDebugMessagesQueued > 0) {
  156. setTimeout(debugSendNextMessageInQueue, 10);
  157. }
  158. }
  159. var DebugTimer = Class.create({
  160. initialize: function(timerId) {
  161. var indexOfUnderscore = timerId.indexOf("_");
  162. var timerName = timerId.substring( indexOfUnderscore + 1 );
  163. if (timerName[0] != "!") {
  164. this.id = timerId;
  165. this.startTime = new Date();
  166. debugMessageAlways(timerId, "Start");
  167. } else {
  168. this.startTime = null;
  169. }
  170. },
  171. stop: function() {
  172. if (this.startTime != null) {
  173. var endTime = new Date();
  174. var elapsedTime = endTime - this.startTime;
  175. debugMessageAlways(this.id , "Stop - Elapsed Time: " + elapsedTime);
  176. }
  177. }
  178. });
  179. function debugStopTimer(timer) {
  180. if (timer) {
  181. timer.stop();
  182. }
  183. }
  184. var debugDomDumpLineNumber = 0;
  185. function debugDumpDomFrom(rootObject, context) {
  186. var kDebugDumpDomFrom = kDebugFunction + "_" + "debugDumpDomFrom";
  187. debugDomDumpLineNumber = 0;
  188. debugMessageAlways(kDebugDumpDomFrom, "------------------ S T A R T O F D O M D U M P --- Context: " + context);
  189. debugRecursivelyDumpDomFrom(rootObject, "");
  190. debugMessageAlways(kDebugDumpDomFrom, "------------------ E N D O F D O M D U M P");
  191. }
  192. function debugRecursivelyDumpDomFrom(object, indentPadding) {
  193. var kDebugRecursivelyDumpDomFrom = kDebugFunction + "_" + "recursivelyDumpDomFrom";
  194. var objectId = object.id;
  195. var objectTag = object.nodeName.toLowerCase();
  196. if (objectTag == "#text") {
  197. return;
  198. }
  199. debugMessageAlways( kDebugRecursivelyDumpDomFrom, "-" + (debugDomDumpLineNumber++) + indentPadding + "<" + objectTag + " id='" + objectId + "'>");
  200. var iChild;
  201. for (iChild = 0; iChild < object.childNodes.length; iChild++) {
  202. var child = object.childNodes[iChild];
  203. recursivelyDumpDomFrom(child, indentPadding + " ");
  204. }
  205. if (objectTag == "img") {
  206. return;
  207. }
  208. debugMessageAlways(kDebugRecursivelyDumpDomFrom, "-" + (debugDomDumpLineNumber++) + indentPadding + "</" + objectTag + ">");
  209. }