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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73730 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 39078312
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):
2010-12-10 Andreas Kling <kling@webkit.org>
Reviewed by Eric Seidel.
......
......@@ -66,7 +66,7 @@ WebInspector.DebuggerModel.prototype = {
this._setBreakpoint(sourceID, url, line, enabled, condition);
},
findBreakpoints: function(filter)
queryBreakpoints: function(filter)
{
var breakpoints = [];
for (var id in this._breakpoints) {
......
......@@ -90,4 +90,3 @@ WebInspector.Script.prototype = {
}
WebInspector.Script.prototype.__proto__ = WebInspector.Object.prototype;
......@@ -30,13 +30,11 @@ WebInspector.ScriptView = function(script)
this.element.addStyleClass("script-view");
this.script = script;
this.script.addEventListener(WebInspector.Script.Events.SourceChanged, this._scriptSourceChanged, this);
this._frameNeedsSetup = true;
this._sourceFrameSetup = false;
var delegate = new WebInspector.ScriptFrameDelegateImpl(this.script);
this.sourceFrame = new WebInspector.SourceFrame(this.element, delegate);
this.script.addEventListener(WebInspector.Script.Events.SourceChanged, this._scriptSourceChanged, this);
this.sourceFrame = new WebInspector.SourceFrame(this.element, [script], WebInspector.panels.scripts.canEditScripts());
}
WebInspector.ScriptView.prototype = {
......@@ -113,28 +111,3 @@ WebInspector.ScriptView.prototype = {
}
WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.ScriptFrameDelegateImpl = function(script)
{
WebInspector.SourceFrameDelegate.call(this);
this._script = script;
}
WebInspector.ScriptFrameDelegateImpl.prototype = {
canEditScripts: function()
{
return WebInspector.panels.scripts.canEditScripts();
},
editLineComplete: function(revertEditLineCallback, newContent)
{
this._script.source = newContent;
},
scripts: function()
{
return [this._script];
}
}
WebInspector.ScriptFrameDelegateImpl.prototype.__proto__ = WebInspector.SourceFrameDelegate.prototype;
......@@ -293,7 +293,7 @@ WebInspector.ScriptsPanel.prototype = {
return;
// Need to clear breakpoints and re-create them later when editing source.
var breakpoints = WebInspector.debuggerModel.findBreakpoints(function(b) { return b.sourceID === editData.sourceID });
var breakpoints = WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID === editData.sourceID });
for (var i = 0; i < breakpoints.length; ++i)
breakpoints[i].remove();
......@@ -433,8 +433,10 @@ WebInspector.ScriptsPanel.prototype = {
if (this._sourceIDMap) {
for (var sourceID in this._sourceIDMap) {
var object = this._sourceIDMap[sourceID];
if (object instanceof WebInspector.Resource)
if (object instanceof WebInspector.Resource) {
object.removeAllScripts();
delete object._resourcesView;
}
}
}
......
......@@ -28,10 +28,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.SourceFrame = function(parentElement, delegate)
WebInspector.SourceFrame = function(parentElement, scripts, canEditScripts)
{
this._parentElement = parentElement;
this._delegate = delegate;
this._scripts = {};
for (var i = 0; i < scripts.length; ++i)
this._scripts[scripts[i].sourceID] = scripts[i];
this._canEditScripts = canEditScripts;
this._textModel = new WebInspector.TextEditorModel();
this._textModel.replaceTabsWithSpaces = true;
......@@ -221,7 +224,7 @@ WebInspector.SourceFrame.prototype = {
this._textViewer.endUpdates();
if (this._delegate.canEditScripts())
if (this._canEditScripts)
this._textViewer.editCallback = this._editLine.bind(this);
},
......@@ -415,7 +418,7 @@ WebInspector.SourceFrame.prototype = {
{
var breakpoint = event.data;
if (this._shouldDisplayBreakpoint(breakpoint))
if (breakpoint.sourceID in this._scripts)
this._addBreakpoint(breakpoint);
},
......@@ -797,10 +800,18 @@ WebInspector.SourceFrame.prototype = {
_doEditLine: function(editData, cancelEditingCallback)
{
var revertEditingCallback = this._revertEditLine.bind(this, editData);
var commitEditingCallback = this._delegate.editLineComplete.bind(this._delegate, revertEditingCallback);
var commitEditingCallback = this._commitEditLine.bind(this, editData, revertEditingCallback);
WebInspector.panels.scripts.editScriptSource(editData, commitEditingCallback, cancelEditingCallback);
},
_commitEditLine: function(editData, revertEditLineCallback, newContent)
{
var script = this._scripts[editData.sourceID];
script.source = newContent;
if (script.resource)
script.resource.setContent(newContent, revertEditLineCallback);
},
_setBreakpoint: function(lineNumber)
{
var sourceID = this._sourceIDForLine(lineNumber);
......@@ -811,15 +822,8 @@ WebInspector.SourceFrame.prototype = {
_breakpoints: function()
{
var sourceIDs = {};
var scripts = this._delegate.scripts();
for (var i = 0; i < scripts.length; ++i)
sourceIDs[scripts[i].sourceID] = true;
function filter(breakpoint)
{
return breakpoint.sourceID in sourceIDs;
}
return WebInspector.debuggerModel.findBreakpoints(filter);
var scripts = this._scripts;
return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in scripts; });
},
_findBreakpoint: function(lineNumber)
......@@ -828,51 +832,19 @@ WebInspector.SourceFrame.prototype = {
return WebInspector.debuggerModel.findBreakpoint(sourceID, lineNumber);
},
_shouldDisplayBreakpoint: function(breakpoint)
{
var scripts = this._delegate.scripts();
for (var i = 0; i < scripts.length; ++i) {
if (breakpoint.sourceID === scripts[i].sourceID)
return true;
}
return false;
},
_sourceIDForLine: function(lineNumber)
{
var sourceID = null;
var scripts = this._delegate.scripts();
var sourceIDForLine = null;
var closestStartingLine = 0;
for (var i = 0; i < scripts.length; ++i) {
var script = scripts[i];
for (var sourceID in this._scripts) {
var script = this._scripts[sourceID];
if (script.startingLine <= lineNumber && script.startingLine >= closestStartingLine) {
closestStartingLine = script.startingLine;
sourceID = script.sourceID;
sourceIDForLine = sourceID;
}
}
return sourceID;
return sourceIDForLine;
}
}
WebInspector.SourceFrame.prototype.__proto__ = WebInspector.Object.prototype;
WebInspector.SourceFrameDelegate = function()
{
}
WebInspector.SourceFrameDelegate.prototype = {
canEditScripts: function()
{
// Implemented by subclasses.
},
editLineComplete: function(revertEditLineCallback, newContent)
{
// Implemented by subclasses.
},
scripts: function()
{
// Implemented by subclasses.
}
}
......@@ -32,8 +32,8 @@ WebInspector.SourceView = function(resource)
this.element.addStyleClass("source");
var delegate = new WebInspector.ResourceFrameDelegateImpl(this.resource);
this.sourceFrame = new WebInspector.SourceFrame(this.element, delegate);
var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
this.sourceFrame = new WebInspector.SourceFrame(this.element, resource.scripts, canEditScripts);
resource.addEventListener("finished", this._resourceLoadingFinished, this);
this._frameNeedsSetup = true;
}
......@@ -238,28 +238,3 @@ WebInspector.SourceView.prototype = {
}
WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
WebInspector.ResourceFrameDelegateImpl = function(resource)
{
WebInspector.SourceFrameDelegate.call(this);
this._resource = resource;
}
WebInspector.ResourceFrameDelegateImpl.prototype = {
canEditScripts: function()
{
return WebInspector.panels.scripts.canEditScripts() && this._resource.type === WebInspector.Resource.Type.Script;
},
editLineComplete: function(revertEditLineCallback, newContent)
{
this._resource.setContent(newContent, revertEditLineCallback);
},
scripts: function()
{
return this._resource.scripts;
}
}
WebInspector.ResourceFrameDelegateImpl.prototype.__proto__ = WebInspector.SourceFrameDelegate.prototype;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment