home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 July / CA07.iso / Multimedija / QuickTimeInstaller.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_CallStackSidebarPane.js < prev    next >
Encoding:
Text File  |  2010-03-15  |  5.7 KB  |  168 lines

  1. /*
  2.  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 1. Redistributions of source code must retain the above copyright
  8.  *    notice, this list of conditions and the following disclaimer.
  9.  * 2. Redistributions in binary form must reproduce the above copyright
  10.  *    notice, this list of conditions and the following disclaimer in the
  11.  *    documentation and/or other materials provided with the distribution.
  12.  *
  13.  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
  17.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24.  */
  25.  
  26. WebInspector.CallStackSidebarPane = function()
  27. {
  28.     WebInspector.SidebarPane.call(this, WebInspector.UIString("Call Stack"));
  29.     
  30.     this._shortcuts = {};
  31.  
  32.     var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.KeyCodes.Period,
  33.                                                          WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  34.     this._shortcuts[shortcut] = this._selectNextCallFrameOnStack.bind(this);
  35.  
  36.     var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.KeyCodes.Comma,
  37.                                                          WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  38.     this._shortcuts[shortcut] = this._selectPreviousCallFrameOnStack.bind(this);
  39. }
  40.  
  41. WebInspector.CallStackSidebarPane.prototype = {
  42.     update: function(callFrame, sourceIDMap)
  43.     {
  44.         this.bodyElement.removeChildren();
  45.  
  46.         this.placards = [];
  47.         delete this._selectedCallFrame;
  48.  
  49.         if (!callFrame) {
  50.             var infoElement = document.createElement("div");
  51.             infoElement.className = "info";
  52.             infoElement.textContent = WebInspector.UIString("Not Paused");
  53.             this.bodyElement.appendChild(infoElement);
  54.             return;
  55.         }
  56.  
  57.         var title;
  58.         var subtitle;
  59.         var scriptOrResource;
  60.  
  61.         do {
  62.             switch (callFrame.type) {
  63.             case "function":
  64.                 title = callFrame.functionName || WebInspector.UIString("(anonymous function)");
  65.                 break;
  66.             case "program":
  67.                 title = WebInspector.UIString("(program)");
  68.                 break;
  69.             }
  70.  
  71.             scriptOrResource = sourceIDMap[callFrame.sourceID];
  72.             subtitle = WebInspector.displayNameForURL(scriptOrResource.sourceURL || scriptOrResource.url);
  73.  
  74.             if (callFrame.line > 0) {
  75.                 if (subtitle)
  76.                     subtitle += ":" + callFrame.line;
  77.                 else
  78.                     subtitle = WebInspector.UIString("line %d", callFrame.line);
  79.             }
  80.  
  81.             var placard = new WebInspector.Placard(title, subtitle);
  82.             placard.callFrame = callFrame;
  83.  
  84.             placard.element.addEventListener("click", this._placardSelected.bind(this), false);
  85.  
  86.             this.placards.push(placard);
  87.             this.bodyElement.appendChild(placard.element);
  88.  
  89.             callFrame = callFrame.caller;
  90.         } while (callFrame);
  91.     },
  92.  
  93.     get selectedCallFrame()
  94.     {
  95.         return this._selectedCallFrame;
  96.     },
  97.  
  98.     set selectedCallFrame(x)
  99.     {
  100.         if (this._selectedCallFrame === x)
  101.             return;
  102.  
  103.         this._selectedCallFrame = x;
  104.  
  105.         for (var i = 0; i < this.placards.length; ++i) {
  106.             var placard = this.placards[i];
  107.             placard.selected = (placard.callFrame === this._selectedCallFrame);
  108.         }
  109.  
  110.         this.dispatchEventToListeners("call frame selected");
  111.     },
  112.  
  113.     handleKeyEvent: function(event)
  114.     {
  115.         var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
  116.         var handler = this._shortcuts[shortcut];
  117.         if (handler) {
  118.             handler(event);
  119.             event.preventDefault();
  120.             event.handled = true;
  121.         }
  122.     },
  123.  
  124.     _selectNextCallFrameOnStack: function()
  125.     {
  126.         var index = this._selectedCallFrameIndex();
  127.         if (index == -1)
  128.             return;
  129.         this._selectedPlacardByIndex(index + 1);
  130.     },
  131.  
  132.     _selectPreviousCallFrameOnStack: function()
  133.     {
  134.         var index = this._selectedCallFrameIndex();
  135.         if (index == -1)
  136.             return;
  137.         this._selectedPlacardByIndex(index - 1);
  138.     },
  139.  
  140.     _selectedPlacardByIndex: function(index)
  141.     {
  142.         if (index < 0 || index >= this.placards.length)
  143.             return;
  144.         var placard = this.placards[index];
  145.         this.selectedCallFrame = placard.callFrame
  146.     },
  147.  
  148.     _selectedCallFrameIndex: function()
  149.     {
  150.         if (!this._selectedCallFrame)
  151.             return -1;
  152.         for (var i = 0; i < this.placards.length; ++i) {
  153.             var placard = this.placards[i];
  154.             if (placard.callFrame === this._selectedCallFrame)
  155.                 return i;
  156.         }
  157.         return -1;
  158.     },
  159.  
  160.     _placardSelected: function(event)
  161.     {
  162.         var placardElement = event.target.enclosingNodeOrSelfWithClass("placard");
  163.         this.selectedCallFrame = placardElement.placard.callFrame;
  164.     }
  165. }
  166.  
  167. WebInspector.CallStackSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
  168.