home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 July / CAG7.ISO / Internetas / SafariSetup.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_BreakpointsSidebarPane.js < prev    next >
Encoding:
Text File  |  2010-06-03  |  6.3 KB  |  164 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.BreakpointsSidebarPane = function()
  27. {
  28.     WebInspector.SidebarPane.call(this, WebInspector.UIString("Breakpoints"));
  29.  
  30.     this.breakpoints = {};
  31.  
  32.     this.listElement = document.createElement("ol");
  33.     this.listElement.className = "breakpoint-list";
  34.  
  35.     this.emptyElement = document.createElement("div");
  36.     this.emptyElement.className = "info";
  37.     this.emptyElement.textContent = WebInspector.UIString("No Breakpoints");
  38.  
  39.     this.bodyElement.appendChild(this.emptyElement);
  40. }
  41.  
  42. WebInspector.BreakpointsSidebarPane.prototype = {
  43.     reset: function()
  44.     {
  45.         this.breakpoints = {};
  46.         this.listElement.removeChildren();
  47.         if (this.listElement.parentElement) {
  48.             this.bodyElement.removeChild(this.listElement);
  49.             this.bodyElement.appendChild(this.emptyElement);
  50.         }
  51.     },
  52.  
  53.     addBreakpoint: function(breakpoint)
  54.     {
  55.         if (this.breakpoints[breakpoint.id])
  56.             return;
  57.  
  58.         this.breakpoints[breakpoint.id] = breakpoint;
  59.  
  60.         breakpoint.addEventListener("enabled", this._breakpointEnableChanged, this);
  61.         breakpoint.addEventListener("disabled", this._breakpointEnableChanged, this);
  62.         breakpoint.addEventListener("text-changed", this._breakpointTextChanged, this);
  63.  
  64.         this._appendBreakpointElement(breakpoint);
  65.  
  66.         if (this.emptyElement.parentElement) {
  67.             this.bodyElement.removeChild(this.emptyElement);
  68.             this.bodyElement.appendChild(this.listElement);
  69.         }
  70.  
  71.         InspectorBackend.setBreakpoint(breakpoint.sourceID, breakpoint.line, breakpoint.enabled, breakpoint.condition);
  72.     },
  73.  
  74.     _appendBreakpointElement: function(breakpoint)
  75.     {
  76.         function checkboxClicked(event)
  77.         {
  78.             breakpoint.enabled = !breakpoint.enabled;
  79.  
  80.             // without this, we'd switch to the source of the clicked breakpoint
  81.             event.stopPropagation();
  82.         }
  83.  
  84.         function breakpointClicked()
  85.         {
  86.             WebInspector.panels.scripts.showSourceLine(breakpoint.url, breakpoint.line);
  87.         }
  88.  
  89.         var breakpointElement = document.createElement("li");
  90.         breakpoint._breakpointListElement = breakpointElement;
  91.         breakpointElement._breakpointObject = breakpoint;
  92.         breakpointElement.addEventListener("click", breakpointClicked, false);
  93.  
  94.         var checkboxElement = document.createElement("input");
  95.         checkboxElement.className = "checkbox-elem";
  96.         checkboxElement.type = "checkbox";
  97.         checkboxElement.checked = breakpoint.enabled;
  98.         checkboxElement.addEventListener("click", checkboxClicked, false);
  99.         breakpointElement.appendChild(checkboxElement);
  100.  
  101.         var labelElement = document.createTextNode(breakpoint.label);
  102.         breakpointElement.appendChild(labelElement);
  103.  
  104.         var sourceTextElement = document.createElement("div");
  105.         sourceTextElement.textContent = breakpoint.sourceText;
  106.         sourceTextElement.className = "source-text monospace";
  107.         breakpointElement.appendChild(sourceTextElement);
  108.  
  109.         var currentElement = this.listElement.firstChild;
  110.         while (currentElement) {
  111.             var currentBreak = currentElement._breakpointObject;
  112.             if (currentBreak.url > breakpoint.url) {
  113.                 this.listElement.insertBefore(breakpointElement, currentElement);
  114.                 return;
  115.             } else if (currentBreak.url == breakpoint.url && currentBreak.line > breakpoint.line) {
  116.                 this.listElement.insertBefore(breakpointElement, currentElement);
  117.                 return;
  118.             }
  119.             currentElement = currentElement.nextSibling;
  120.         }
  121.         this.listElement.appendChild(breakpointElement);
  122.     },
  123.  
  124.     removeBreakpoint: function(breakpoint)
  125.     {
  126.         if (!this.breakpoints[breakpoint.id])
  127.             return;
  128.         delete this.breakpoints[breakpoint.id];
  129.  
  130.         breakpoint.removeEventListener("enabled", null, this);
  131.         breakpoint.removeEventListener("disabled", null, this);
  132.         breakpoint.removeEventListener("text-changed", null, this);
  133.  
  134.         var element = breakpoint._breakpointListElement;
  135.         element.parentElement.removeChild(element);
  136.  
  137.         if (!this.listElement.firstChild) {
  138.             this.bodyElement.removeChild(this.listElement);
  139.             this.bodyElement.appendChild(this.emptyElement);
  140.         }
  141.  
  142.         InspectorBackend.removeBreakpoint(breakpoint.sourceID, breakpoint.line);
  143.     },
  144.  
  145.     _breakpointEnableChanged: function(event)
  146.     {
  147.         var breakpoint = event.target;
  148.  
  149.         var checkbox = breakpoint._breakpointListElement.firstChild;
  150.         checkbox.checked = breakpoint.enabled;
  151.         InspectorBackend.setBreakpoint(breakpoint.sourceID, breakpoint.line, breakpoint.enabled, breakpoint.condition);
  152.     },
  153.  
  154.     _breakpointTextChanged: function(event)
  155.     {
  156.         var breakpoint = event.target;
  157.  
  158.         var sourceTextElement = breakpoint._breakpointListElement.firstChild.nextSibling.nextSibling;
  159.         sourceTextElement.textContent = breakpoint.sourceText;
  160.     }
  161. }
  162.  
  163. WebInspector.BreakpointsSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
  164.