Changeset 73730 in webkit


Ignore:
Timestamp:
Dec 10, 2010 8:33:00 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2010-12-10 Pavel Podivilov <podivilov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: eliminate SourceFrameDelegate by passing scripts to SourceFrame constructor.
https://bugs.webkit.org/show_bug.cgi?id=50679

  • inspector/front-end/Script.js:
  • inspector/front-end/ScriptView.js: (WebInspector.ScriptView):
  • inspector/front-end/ScriptsPanel.js: (WebInspector.ScriptsPanel.prototype.reset):
  • inspector/front-end/SourceFrame.js: (WebInspector.SourceFrame): (WebInspector.SourceFrame.prototype._createViewerIfNeeded): (WebInspector.SourceFrame.prototype._breakpointAdded): (WebInspector.SourceFrame.prototype._doEditLine): (WebInspector.SourceFrame.prototype._commitEditLine): (WebInspector.SourceFrame.prototype._breakpoints): (WebInspector.SourceFrame.prototype._sourceIDForLine):
  • inspector/front-end/SourceView.js: (WebInspector.SourceView):
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r73729 r73730  
     12010-12-10  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: eliminate SourceFrameDelegate by passing scripts to SourceFrame constructor.
     6        https://bugs.webkit.org/show_bug.cgi?id=50679
     7
     8        * inspector/front-end/Script.js:
     9        * inspector/front-end/ScriptView.js:
     10        (WebInspector.ScriptView):
     11        * inspector/front-end/ScriptsPanel.js:
     12        (WebInspector.ScriptsPanel.prototype.reset):
     13        * inspector/front-end/SourceFrame.js:
     14        (WebInspector.SourceFrame):
     15        (WebInspector.SourceFrame.prototype._createViewerIfNeeded):
     16        (WebInspector.SourceFrame.prototype._breakpointAdded):
     17        (WebInspector.SourceFrame.prototype._doEditLine):
     18        (WebInspector.SourceFrame.prototype._commitEditLine):
     19        (WebInspector.SourceFrame.prototype._breakpoints):
     20        (WebInspector.SourceFrame.prototype._sourceIDForLine):
     21        * inspector/front-end/SourceView.js:
     22        (WebInspector.SourceView):
     23
    1242010-12-10  Andreas Kling  <kling@webkit.org>
    225
  • trunk/WebCore/inspector/front-end/DebuggerModel.js

    r73726 r73730  
    6767    },
    6868
    69     findBreakpoints: function(filter)
     69    queryBreakpoints: function(filter)
    7070    {
    7171        var breakpoints = [];
  • trunk/WebCore/inspector/front-end/Script.js

    r73499 r73730  
    9191
    9292WebInspector.Script.prototype.__proto__ = WebInspector.Object.prototype;
    93 
  • trunk/WebCore/inspector/front-end/ScriptView.js

    r73499 r73730  
    3131
    3232    this.script = script;
     33    this.script.addEventListener(WebInspector.Script.Events.SourceChanged, this._scriptSourceChanged, this);
    3334
    3435    this._frameNeedsSetup = true;
    3536    this._sourceFrameSetup = false;
    36     var delegate = new WebInspector.ScriptFrameDelegateImpl(this.script);
    37     this.sourceFrame = new WebInspector.SourceFrame(this.element, delegate);
    38 
    39     this.script.addEventListener(WebInspector.Script.Events.SourceChanged, this._scriptSourceChanged, this);
     37    this.sourceFrame = new WebInspector.SourceFrame(this.element, [script], WebInspector.panels.scripts.canEditScripts());
    4038}
    4139
     
    114112
    115113WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
    116 
    117 WebInspector.ScriptFrameDelegateImpl = function(script)
    118 {
    119     WebInspector.SourceFrameDelegate.call(this);
    120     this._script = script;
    121 }
    122 
    123 WebInspector.ScriptFrameDelegateImpl.prototype = {
    124     canEditScripts: function()
    125     {
    126         return WebInspector.panels.scripts.canEditScripts();
    127     },
    128 
    129     editLineComplete: function(revertEditLineCallback, newContent)
    130     {
    131         this._script.source = newContent;
    132     },
    133 
    134     scripts: function()
    135     {
    136         return [this._script];
    137     }
    138 }
    139 
    140 WebInspector.ScriptFrameDelegateImpl.prototype.__proto__ = WebInspector.SourceFrameDelegate.prototype;
  • trunk/WebCore/inspector/front-end/ScriptsPanel.js

    r73501 r73730  
    294294
    295295        // Need to clear breakpoints and re-create them later when editing source.
    296         var breakpoints = WebInspector.debuggerModel.findBreakpoints(function(b) { return b.sourceID === editData.sourceID });
     296        var breakpoints = WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID === editData.sourceID });
    297297        for (var i = 0; i < breakpoints.length; ++i)
    298298            breakpoints[i].remove();
     
    434434            for (var sourceID in this._sourceIDMap) {
    435435                var object = this._sourceIDMap[sourceID];
    436                 if (object instanceof WebInspector.Resource)
     436                if (object instanceof WebInspector.Resource) {
    437437                    object.removeAllScripts();
     438                    delete object._resourcesView;
     439                }
    438440            }
    439441        }
  • trunk/WebCore/inspector/front-end/SourceFrame.js

    r73504 r73730  
    2929 */
    3030
    31 WebInspector.SourceFrame = function(parentElement, delegate)
     31WebInspector.SourceFrame = function(parentElement, scripts, canEditScripts)
    3232{
    3333    this._parentElement = parentElement;
    34     this._delegate = delegate;
     34    this._scripts = {};
     35    for (var i = 0; i < scripts.length; ++i)
     36        this._scripts[scripts[i].sourceID] = scripts[i];
     37    this._canEditScripts = canEditScripts;
    3538
    3639    this._textModel = new WebInspector.TextEditorModel();
     
    222225        this._textViewer.endUpdates();
    223226
    224         if (this._delegate.canEditScripts())
     227        if (this._canEditScripts)
    225228            this._textViewer.editCallback = this._editLine.bind(this);
    226229    },
     
    416419        var breakpoint = event.data;
    417420
    418         if (this._shouldDisplayBreakpoint(breakpoint))
     421        if (breakpoint.sourceID in this._scripts)
    419422            this._addBreakpoint(breakpoint);
    420423    },
     
    798801    {
    799802        var revertEditingCallback = this._revertEditLine.bind(this, editData);
    800         var commitEditingCallback = this._delegate.editLineComplete.bind(this._delegate, revertEditingCallback);
     803        var commitEditingCallback = this._commitEditLine.bind(this, editData, revertEditingCallback);
    801804        WebInspector.panels.scripts.editScriptSource(editData, commitEditingCallback, cancelEditingCallback);
     805    },
     806
     807    _commitEditLine: function(editData, revertEditLineCallback, newContent)
     808    {
     809        var script = this._scripts[editData.sourceID];
     810        script.source = newContent;
     811        if (script.resource)
     812            script.resource.setContent(newContent, revertEditLineCallback);
    802813    },
    803814
     
    812823    _breakpoints: function()
    813824    {
    814         var sourceIDs = {};
    815         var scripts = this._delegate.scripts();
    816         for (var i = 0; i < scripts.length; ++i)
    817             sourceIDs[scripts[i].sourceID] = true;
    818         function filter(breakpoint)
    819         {
    820             return breakpoint.sourceID in sourceIDs;
    821         }
    822         return WebInspector.debuggerModel.findBreakpoints(filter);
     825        var scripts = this._scripts;
     826        return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in scripts; });
    823827    },
    824828
     
    829833    },
    830834
    831     _shouldDisplayBreakpoint: function(breakpoint)
    832     {
    833         var scripts = this._delegate.scripts();
    834         for (var i = 0; i < scripts.length; ++i) {
    835             if (breakpoint.sourceID === scripts[i].sourceID)
    836                 return true;
    837         }
    838         return false;
    839     },
    840 
    841835    _sourceIDForLine: function(lineNumber)
    842836    {
    843         var sourceID = null;
    844         var scripts = this._delegate.scripts();
     837        var sourceIDForLine = null;
    845838        var closestStartingLine = 0;
    846         for (var i = 0; i < scripts.length; ++i) {
    847             var script = scripts[i];
     839        for (var sourceID in this._scripts) {
     840            var script = this._scripts[sourceID];
    848841            if (script.startingLine <= lineNumber && script.startingLine >= closestStartingLine) {
    849842                closestStartingLine = script.startingLine;
    850                 sourceID = script.sourceID;
     843                sourceIDForLine = sourceID;
    851844            }
    852845        }
    853         return sourceID;
     846        return sourceIDForLine;
    854847    }
    855848}
    856849
    857850WebInspector.SourceFrame.prototype.__proto__ = WebInspector.Object.prototype;
    858 
    859 WebInspector.SourceFrameDelegate = function()
    860 {
    861 }
    862 
    863 WebInspector.SourceFrameDelegate.prototype = {
    864     canEditScripts: function()
    865     {
    866         // Implemented by subclasses.
    867     },
    868 
    869     editLineComplete: function(revertEditLineCallback, newContent)
    870     {
    871         // Implemented by subclasses.
    872     },
    873 
    874     scripts: function()
    875     {
    876         // Implemented by subclasses.
    877     }
    878 }
  • trunk/WebCore/inspector/front-end/SourceView.js

    r73499 r73730  
    3333    this.element.addStyleClass("source");
    3434
    35     var delegate = new WebInspector.ResourceFrameDelegateImpl(this.resource);
    36     this.sourceFrame = new WebInspector.SourceFrame(this.element, delegate);
     35    var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
     36    this.sourceFrame = new WebInspector.SourceFrame(this.element, resource.scripts, canEditScripts);
    3737    resource.addEventListener("finished", this._resourceLoadingFinished, this);
    3838    this._frameNeedsSetup = true;
     
    239239
    240240WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
    241 
    242 WebInspector.ResourceFrameDelegateImpl = function(resource)
    243 {
    244     WebInspector.SourceFrameDelegate.call(this);
    245     this._resource = resource;
    246 }
    247 
    248 WebInspector.ResourceFrameDelegateImpl.prototype = {
    249     canEditScripts: function()
    250     {
    251         return WebInspector.panels.scripts.canEditScripts() && this._resource.type === WebInspector.Resource.Type.Script;
    252     },
    253 
    254     editLineComplete: function(revertEditLineCallback, newContent)
    255     {
    256         this._resource.setContent(newContent, revertEditLineCallback);
    257     },
    258 
    259     scripts: function()
    260     {
    261         return this._resource.scripts;
    262     }
    263 }
    264 
    265 WebInspector.ResourceFrameDelegateImpl.prototype.__proto__ = WebInspector.SourceFrameDelegate.prototype;
Note: See TracChangeset for help on using the changeset viewer.