[DevTools] Refactor WebInspector.EventListener

Move logic from cstor for reusing it in future CLs.

R=pfeldman@chromium.org

Review URL: https://codereview.chromium.org/1319613002

git-svn-id: svn://svn.chromium.org/blink/trunk@201165 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 19625a92
...@@ -8,7 +8,7 @@ type: scroll ...@@ -8,7 +8,7 @@ type: scroll
useCapture: true useCapture: true
location: 16, 78 location: 16, 78
handler: function foo() {} handler: function foo() {}
sourceName: domdebugger-getEventListeners.html sourceURL: domdebugger-getEventListeners.html
Running: testDivEventListeners Running: testDivEventListeners
...@@ -16,13 +16,13 @@ type: click ...@@ -16,13 +16,13 @@ type: click
useCapture: true useCapture: true
location: 16, 79 location: 16, 79
handler: function boo() {} handler: function boo() {}
sourceName: domdebugger-getEventListeners.html sourceURL: domdebugger-getEventListeners.html
type: mouseout type: mouseout
useCapture: false useCapture: false
location: 16, 78 location: 16, 78
handler: function foo() {} handler: function foo() {}
sourceName: domdebugger-getEventListeners.html sourceURL: domdebugger-getEventListeners.html
type: click type: click
useCapture: false useCapture: false
...@@ -30,7 +30,7 @@ location: 37, 75 ...@@ -30,7 +30,7 @@ location: 37, 75
handler: function onclick(event) { handler: function onclick(event) {
return 42; return 42;
} }
sourceName: domdebugger-getEventListeners.html sourceURL: domdebugger-getEventListeners.html
Running: testDivWithoutEventListeners Running: testDivWithoutEventListeners
......
...@@ -12,15 +12,15 @@ function test() ...@@ -12,15 +12,15 @@ function test()
{ {
for (var i = 0; i < listeners.length; ++i) { for (var i = 0; i < listeners.length; ++i) {
delete listeners[i]._location.scriptId; delete listeners[i]._location.scriptId;
var sourceName = listeners[i]._sourceName; var sourceURL = listeners[i]._sourceURL;
sourceName = sourceName.substr(sourceName.lastIndexOf('/') + 1); sourceURL = sourceURL.substr(sourceURL.lastIndexOf('/') + 1);
listeners[i]._sourceName = sourceName; listeners[i]._sourceURL = sourceURL;
InspectorTest.addResult("type: " + listeners[i].type()); InspectorTest.addResult("type: " + listeners[i].type());
InspectorTest.addResult("useCapture: " + listeners[i].useCapture()); InspectorTest.addResult("useCapture: " + listeners[i].useCapture());
InspectorTest.addResult("location: " + listeners[i].location().columnNumber + ", " + listeners[i].location().lineNumber); InspectorTest.addResult("location: " + listeners[i].location().columnNumber + ", " + listeners[i].location().lineNumber);
InspectorTest.addResult("handler: " + listeners[i].handler().description); InspectorTest.addResult("handler: " + listeners[i].handler().description);
InspectorTest.addResult("sourceName: " + listeners[i].sourceName()); InspectorTest.addResult("sourceURL: " + listeners[i].sourceURL());
InspectorTest.addResult(""); InspectorTest.addResult("");
} }
next(); next();
......
...@@ -170,7 +170,7 @@ WebInspector.ObjectEventListenerBar.prototype = { ...@@ -170,7 +170,7 @@ WebInspector.ObjectEventListenerBar.prototype = {
{ {
var title = this.listItemElement.createChild("span"); var title = this.listItemElement.createChild("span");
var subtitle = this.listItemElement.createChild("span", "event-listener-tree-subtitle"); var subtitle = this.listItemElement.createChild("span", "event-listener-tree-subtitle");
subtitle.appendChild(linkifier.linkifyRawLocation(this._eventListener.location(), this._eventListener.sourceName())); subtitle.appendChild(linkifier.linkifyRawLocation(this._eventListener.location(), this._eventListener.sourceURL()));
title.appendChild(WebInspector.ObjectPropertiesSection.createValueElement(object, false)); title.appendChild(WebInspector.ObjectPropertiesSection.createValueElement(object, false));
}, },
......
...@@ -555,7 +555,11 @@ WebInspector.RemoteObjectImpl.prototype = { ...@@ -555,7 +555,11 @@ WebInspector.RemoteObjectImpl.prototype = {
*/ */
function createEventListener(payload) function createEventListener(payload)
{ {
return new WebInspector.EventListener(this._debuggerModel, payload, this._objectId); return new WebInspector.EventListener(this._target,
payload.type,
payload.useCapture,
payload.handler ? this.target().runtimeModel.createRemoteObject(payload.handler) : null,
WebInspector.DebuggerModel.Location.fromPayload(this._debuggerModel, payload.location));
} }
} }
}, },
......
...@@ -493,20 +493,20 @@ WebInspector.ExecutionContext.prototype = { ...@@ -493,20 +493,20 @@ WebInspector.ExecutionContext.prototype = {
/** /**
* @constructor * @constructor
* @extends {WebInspector.SDKObject} * @extends {WebInspector.SDKObject}
* @param {!WebInspector.DebuggerModel} debuggerModel * @param {!WebInspector.Target} target
* @param {!DOMDebuggerAgent.EventListener} payload * @param {string} type
* @param {!RuntimeAgent.RemoteObjectId} objectId * @param {boolean} useCapture
* @param {?WebInspector.RemoteObject} handler
* @param {!WebInspector.DebuggerModel.Location} location
*/ */
WebInspector.EventListener = function(debuggerModel, payload, objectId) WebInspector.EventListener = function(target, type, useCapture, handler, location)
{ {
WebInspector.SDKObject.call(this, debuggerModel.target()); WebInspector.SDKObject.call(this, target);
this._type = payload.type; this._type = type;
this._useCapture = payload.useCapture; this._useCapture = useCapture;
this._location = WebInspector.DebuggerModel.Location.fromPayload(debuggerModel, payload.location); this._handler = handler;
this._handler = payload.handler ? this.target().runtimeModel.createRemoteObject(payload.handler) : null; this._location = location;
var script = debuggerModel.scriptForId(payload.location.scriptId); this._sourceURL = location.script().contentURL();
this._sourceName = script ? script.contentURL() : "";
this._objectId = objectId;
} }
WebInspector.EventListener.prototype = { WebInspector.EventListener.prototype = {
...@@ -526,14 +526,6 @@ WebInspector.EventListener.prototype = { ...@@ -526,14 +526,6 @@ WebInspector.EventListener.prototype = {
return this._useCapture; return this._useCapture;
}, },
/**
* @return {!WebInspector.DebuggerModel.Location}
*/
location: function()
{
return this._location;
},
/** /**
* @return {?WebInspector.RemoteObject} * @return {?WebInspector.RemoteObject}
*/ */
...@@ -543,20 +535,20 @@ WebInspector.EventListener.prototype = { ...@@ -543,20 +535,20 @@ WebInspector.EventListener.prototype = {
}, },
/** /**
* @return {string} * @return {!WebInspector.DebuggerModel.Location}
*/ */
sourceName: function() location: function()
{ {
return this._sourceName; return this._location;
}, },
/** /**
* @return {!RuntimeAgent.RemoteObjectId} * @return {string}
*/ */
objectId: function() sourceURL: function()
{ {
return this._objectId; return this._sourceURL;
}, },
__proto__: WebInspector.SDKObject.prototype __proto__: WebInspector.SDKObject.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