• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
26WebInspector.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    this.sourceFrame = new WebInspector.SourceFrame(this.element, this._addBreakpoint.bind(this), this._removeBreakpoint.bind(this));
37}
38
39WebInspector.ScriptView.prototype = {
40    show: function(parentElement)
41    {
42        WebInspector.View.prototype.show.call(this, parentElement);
43        this.setupSourceFrameIfNeeded();
44        this.sourceFrame.visible = true;
45        this.resize();
46    },
47
48    setupSourceFrameIfNeeded: function()
49    {
50        if (!this._frameNeedsSetup)
51            return;
52
53        this.attach();
54
55        this.sourceFrame.setContent("text/javascript", this.script.source);
56        this._sourceFrameSetup = true;
57        delete this._frameNeedsSetup;
58    },
59
60    attach: function()
61    {
62        if (!this.element.parentNode)
63            document.getElementById("script-resource-views").appendChild(this.element);
64    },
65
66    _addBreakpoint: function(line)
67    {
68        var breakpoint = new WebInspector.Breakpoint(this.script.sourceURL, line, this.script.sourceID);
69        WebInspector.panels.scripts.addBreakpoint(breakpoint);
70    },
71
72    // The follow methods are pulled from SourceView, since they are
73    // generic and work with ScriptView just fine.
74
75    hide: WebInspector.SourceView.prototype.hide,
76    revealLine: WebInspector.SourceView.prototype.revealLine,
77    highlightLine: WebInspector.SourceView.prototype.highlightLine,
78    addMessage: WebInspector.SourceView.prototype.addMessage,
79    clearMessages: WebInspector.SourceView.prototype.clearMessages,
80    searchCanceled: WebInspector.SourceView.prototype.searchCanceled,
81    performSearch: WebInspector.SourceView.prototype.performSearch,
82    jumpToFirstSearchResult: WebInspector.SourceView.prototype.jumpToFirstSearchResult,
83    jumpToLastSearchResult: WebInspector.SourceView.prototype.jumpToLastSearchResult,
84    jumpToNextSearchResult: WebInspector.SourceView.prototype.jumpToNextSearchResult,
85    jumpToPreviousSearchResult: WebInspector.SourceView.prototype.jumpToPreviousSearchResult,
86    showingFirstSearchResult: WebInspector.SourceView.prototype.showingFirstSearchResult,
87    showingLastSearchResult: WebInspector.SourceView.prototype.showingLastSearchResult,
88    _jumpToSearchResult: WebInspector.SourceView.prototype._jumpToSearchResult,
89    _sourceFrameSetupFinished: WebInspector.SourceView.prototype._sourceFrameSetupFinished,
90    _removeBreakpoint: WebInspector.SourceView.prototype._removeBreakpoint,
91    resize: WebInspector.SourceView.prototype.resize
92}
93
94WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
95