home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 July / CAG7.ISO / Internetas / SafariSetup.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_ScriptView.js < prev    next >
Encoding:
Text File  |  2010-06-03  |  4.6 KB  |  110 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.ScriptView = function(script)
  27. {
  28.     WebInspector.View.call(this);
  29.  
  30.     this.element.addStyleClass("script-view");
  31.  
  32.     this.script = script;
  33.  
  34.     this._frameNeedsSetup = true;
  35.     this._sourceFrameSetup = false;
  36.     var canEditScripts = WebInspector.panels.scripts.canEditScripts();
  37.     this.sourceFrame = new WebInspector.SourceFrame(this.element, this._addBreakpoint.bind(this), this._removeBreakpoint.bind(this), canEditScripts ? this._editLine.bind(this) : null);
  38. }
  39.  
  40. WebInspector.ScriptView.prototype = {
  41.     show: function(parentElement)
  42.     {
  43.         WebInspector.View.prototype.show.call(this, parentElement);
  44.         this.setupSourceFrameIfNeeded();
  45.         this.sourceFrame.visible = true;
  46.         this.resize();
  47.     },
  48.  
  49.     setupSourceFrameIfNeeded: function()
  50.     {
  51.         if (!this._frameNeedsSetup)
  52.             return;
  53.  
  54.         this.attach();
  55.  
  56.         this.sourceFrame.setContent("text/javascript", this._prependWhitespace(this.script.source));
  57.         this._sourceFrameSetup = true;
  58.         delete this._frameNeedsSetup;
  59.     },
  60.  
  61.     _prependWhitespace: function(content) {
  62.         var prefix = "";
  63.         for (var i = 0; i < this.script.startingLine - 1; ++i)
  64.             prefix += "\n";
  65.         return prefix + content;
  66.     },
  67.  
  68.     attach: function()
  69.     {
  70.         if (!this.element.parentNode)
  71.             document.getElementById("script-resource-views").appendChild(this.element);
  72.     },
  73.  
  74.     _addBreakpoint: function(line)
  75.     {
  76.         var breakpoint = new WebInspector.Breakpoint(this.script.sourceURL, line, this.script.sourceID);
  77.         WebInspector.panels.scripts.addBreakpoint(breakpoint);
  78.     },
  79.  
  80.     _editLineComplete: function(newBody)
  81.     {
  82.         this.script.source = newBody;
  83.         this.sourceFrame.updateContent(this._prependWhitespace(newBody));
  84.     },
  85.  
  86.     // The follow methods are pulled from SourceView, since they are
  87.     // generic and work with ScriptView just fine.
  88.  
  89.     hide: WebInspector.SourceView.prototype.hide,
  90.     revealLine: WebInspector.SourceView.prototype.revealLine,
  91.     highlightLine: WebInspector.SourceView.prototype.highlightLine,
  92.     addMessage: WebInspector.SourceView.prototype.addMessage,
  93.     clearMessages: WebInspector.SourceView.prototype.clearMessages,
  94.     searchCanceled: WebInspector.SourceView.prototype.searchCanceled,
  95.     performSearch: WebInspector.SourceView.prototype.performSearch,
  96.     jumpToFirstSearchResult: WebInspector.SourceView.prototype.jumpToFirstSearchResult,
  97.     jumpToLastSearchResult: WebInspector.SourceView.prototype.jumpToLastSearchResult,
  98.     jumpToNextSearchResult: WebInspector.SourceView.prototype.jumpToNextSearchResult,
  99.     jumpToPreviousSearchResult: WebInspector.SourceView.prototype.jumpToPreviousSearchResult,
  100.     showingFirstSearchResult: WebInspector.SourceView.prototype.showingFirstSearchResult,
  101.     showingLastSearchResult: WebInspector.SourceView.prototype.showingLastSearchResult,
  102.     _jumpToSearchResult: WebInspector.SourceView.prototype._jumpToSearchResult,
  103.     _sourceFrameSetupFinished: WebInspector.SourceView.prototype._sourceFrameSetupFinished,
  104.     _removeBreakpoint: WebInspector.SourceView.prototype._removeBreakpoint,
  105.     _editLine: WebInspector.SourceView.prototype._editLine,
  106.     resize: WebInspector.SourceView.prototype.resize
  107. }
  108.  
  109. WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
  110.