Skip to content

Commit b3de9f8

Browse files
author
Chris K
committed
Expand listener types in Listeners.
1 parent 34308ec commit b3de9f8

File tree

11 files changed

+420
-27
lines changed

11 files changed

+420
-27
lines changed

src/build-application/build_ecmascript_debugger_6_0.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ window.app.builders.EcmascriptDebugger["6.0"] = function(service)
184184
/* Listeners */
185185
if (service_interface.satisfies_version(6, 11))
186186
{
187-
cls.Listeners.prototype = ViewBase;
188-
new cls.Listeners("ev-listeners", "Listeners", "ev-listeners");
187+
cls.EventListenersView.prototype = ViewBase;
188+
new cls.EventListenersView("ev-listeners", "Listeners", "ev-listeners scroll mono");
189189
}
190190

191191
/* adjust the base class */

src/ecma-debugger/dominspection/templates.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
const PSEUDO_ELEMENT_FIRST_LINE = 4;
3636
const EVENT_LISTENER_LIST = 15;
3737

38+
var EV_LISTENER_MARKUP = "<span class=\"node-with-ev-listener\" "+
39+
"data-tooltip=\"event-listener\" " +
40+
"></span>"
41+
3842
this._pseudo_element_map = {};
3943
this._pseudo_element_map[PSEUDO_ELEMENT_BEFORE] = "before";
4044
this._pseudo_element_map[PSEUDO_ELEMENT_AFTER] = "after";
@@ -186,6 +190,7 @@
186190
var disregard_force_lower_case_depth = 0;
187191
var open_tag = is_tree_style ? "" : "&lt;";
188192
var close_tag = is_tree_style ? "" : "&gt;";
193+
var ev_listener = "";
189194

190195
for (var i = 0, node; node = data[i]; i++)
191196
{
@@ -210,6 +215,9 @@
210215
{
211216
node_name = node_name.toLowerCase();
212217
}
218+
ev_listener = node[EVENT_LISTENER_LIST] && node[EVENT_LISTENER_LIST].length
219+
? EV_LISTENER_MARKUP
220+
: "";
213221
switch (node[TYPE])
214222
{
215223
case PSEUDO_NODE:
@@ -236,7 +244,7 @@
236244
{
237245
tree += "</node>";
238246
}
239-
tree += "</div>";
247+
tree += ev_listener + "</div>";
240248
break;
241249
}
242250
case PROCESSING_INSTRUCTION_NODE:
@@ -329,9 +337,7 @@
329337
var depth_first_ele = model.get_depth_of_first_element();
330338
var show_pseudo_elements = window.settings.dom.get("show-pseudo-elements");
331339
var is_expandable = false;
332-
var ev_listener_markup = "<span class=\"node-with-ev-listener\" "+
333-
"data-tooltip=\"event-listener\" " +
334-
"></span>"
340+
335341

336342
for ( ; node = data[i]; i += 1)
337343
{
@@ -381,7 +387,7 @@
381387
var node_name = (node[NAMESPACE] ? node[NAMESPACE] + ':' : '') + node[NAME];
382388
node_name = helpers.escapeTextHtml(node_name);
383389
var ev_listener = node[EVENT_LISTENER_LIST] && node[EVENT_LISTENER_LIST].length
384-
? ev_listener_markup
390+
? EV_LISTENER_MARKUP
385391
: "";
386392

387393
if (force_lower_case)
@@ -532,7 +538,7 @@
532538

533539
case DOCUMENT_NODE:
534540
var ev_listener = node[EVENT_LISTENER_LIST] && node[EVENT_LISTENER_LIST].length
535-
? ev_listener_markup
541+
? EV_LISTENER_MARKUP
536542
: "";
537543
if (ev_listener)
538544
{
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
window.cls || (window.cls = {});
2+
3+
/**
4+
* @constructor
5+
* @extends ViewBase
6+
*/
7+
8+
cls.EventName = function(name)
9+
{
10+
this.name = name;
11+
this.model = null;
12+
this.rt_listeners = null,
13+
this.expanded = null;
14+
this.rt_id = 0;
15+
this.obj_id = 0;
16+
};
17+
18+
cls.EvenetListeners = function(view)
19+
{
20+
/* interface */
21+
22+
this.update = function() {};
23+
this.get_data = function() {};
24+
this.expand_listeners = function(rt_id, obj_id, ev_name, cb) {};
25+
26+
var SUCCESS = 0;
27+
var SEARCH_TYPE_EVENT = 5;
28+
29+
/*
30+
data structure
31+
32+
this._rts =
33+
[
34+
{
35+
rt_id: <rt-id>,
36+
obj_id: <obj-id>,
37+
event_names:
38+
[
39+
{
40+
name: <name>,
41+
expanded: <boolean>,
42+
},
43+
...
44+
]
45+
},
46+
...
47+
]
48+
49+
*/
50+
51+
this._update_rt_list = function(rt_id_list)
52+
{
53+
var ctx = {rt_id_list: rt_id_list, rt_map: {}, win_id_map: {}};
54+
rt_id_list.forEach(this._get_window_ids.bind(this, ctx));
55+
};
56+
57+
this._get_window_ids = function(ctx, rt_id)
58+
{
59+
var sel_rt_id = window.runtimes.getSelectedRuntimeId();
60+
var thread_id = window.stop_at.getThreadId();
61+
var frame_index = window.stop_at.getSelectedFrameIndex();
62+
if (sel_rt_id != rt_id || frame_index == -1)
63+
{
64+
thread_id = 0;
65+
frame_index = 0;
66+
}
67+
var tag = this._tagman.set_callback(this, this._handle_window_ids, [ctx, rt_id]);
68+
var msg = [rt_id, thread_id, frame_index, "window"];
69+
this._esdb.requestEval(tag, msg);
70+
};
71+
72+
this._handle_window_ids = function(status, message, ctx, rt_id)
73+
{
74+
var STATUS = 0;
75+
var OBJECT_VALUE = 3;
76+
var OBJECT_ID = 0;
77+
if (status === SUCCESS && message[STATUS] == "completed" && message[OBJECT_VALUE])
78+
{
79+
this._win_id_map[rt_id] = ctx.win_id_map[rt_id] = message[OBJECT_VALUE][OBJECT_ID];
80+
if (ctx.rt_id_list.every(function(rt_id) { return ctx.win_id_map[rt_id]; }))
81+
ctx.rt_id_list.map(this._get_event_names.bind(this, ctx));
82+
}
83+
else
84+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
85+
"failed to get the window object in cls.EvenetListeners.")
86+
};
87+
88+
this._get_event_names = function(ctx, rt_id)
89+
{
90+
var tag = this._tagman.set_callback(this, this._handle_get_event_names, [ctx, rt_id]);
91+
var msg = [rt_id];
92+
this._esdb.requestGetEventNames(tag, msg);
93+
};
94+
95+
this._handle_get_event_names = function(status, message, ctx, rt_id)
96+
{
97+
if (status === SUCCESS)
98+
{
99+
var RUNTIME_ID = 0;
100+
var OBJECT_ID = 1;
101+
var EVENT_NAMES = 2;
102+
ctx.rt_map[message[RUNTIME_ID]] = null;
103+
if (message[EVENT_NAMES] && message[EVENT_NAMES].length)
104+
{
105+
ctx.rt_map[message[RUNTIME_ID]] =
106+
{
107+
rt_id: message[RUNTIME_ID],
108+
obj_id: message[OBJECT_ID],
109+
window_id: ctx.win_id_map[rt_id],
110+
event_names: message[EVENT_NAMES].map(function(name)
111+
{
112+
return new cls.EventName(name);
113+
}),
114+
};
115+
}
116+
117+
if (ctx.rt_id_list.every(function(rt_id) {return ctx.rt_map.hasOwnProperty(rt_id); }))
118+
{
119+
for (var i = 0, id; id = ctx.rt_id_list[i]; i++)
120+
{
121+
this._rts[this._get_rt_index(id)] = ctx.rt_map[id];
122+
}
123+
this._view.update();
124+
}
125+
}
126+
else
127+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
128+
"failed to retrieve the event names in cls.EvenetListeners.")
129+
};
130+
131+
this._handle_dom_search = function(ev_name_obj, cb)
132+
{
133+
var tag = this._tagman.set_callback(this, this._handle_obj_search, [ev_name_obj, cb]);
134+
var msg = [ev_name_obj.rt_id, [this._win_id_map[ev_name_obj.rt_id]]];
135+
this._esdb.requestGetEventListeners(tag, msg);
136+
};
137+
138+
this._handle_obj_search = function(status, message, ev_name_obj, cb)
139+
{
140+
if (status === SUCCESS)
141+
{
142+
var TARGET_LIST = 1;
143+
var OBJECT_ID = 0;
144+
var EVENT_LISTENERS = 1;
145+
var ev_target = message[TARGET_LIST] && message[TARGET_LIST][0];
146+
ev_name_obj.model.window_listeners = ev_target
147+
? {win_id: ev_target[OBJECT_ID],
148+
listeners: ev_target[EVENT_LISTENERS]}
149+
: null;
150+
ev_name_obj.expanded = true;
151+
if (cb)
152+
cb(ev_name_obj);
153+
else
154+
this._view.update();
155+
}
156+
else
157+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
158+
"requestGetEventListeners failed in cls.EvenetListeners.")
159+
};
160+
161+
this._get_ev_name_obj = function(rt_id, ev_name)
162+
{
163+
var rt = this._get_rt(rt_id);
164+
if (rt)
165+
{
166+
for (var i = 0, ev_n; ev_n = rt.event_names[i]; i++)
167+
{
168+
if (ev_n.name == ev_name)
169+
return ev_n;
170+
}
171+
}
172+
return null;
173+
};
174+
175+
this._get_rt = function(rt_id)
176+
{
177+
if (this._rts)
178+
{
179+
for (var i = 0, rt; rt = this._rts[i]; i++)
180+
{
181+
if (rt.rt_id == rt_id)
182+
return rt;
183+
}
184+
}
185+
return null;
186+
};
187+
188+
this._get_rt_index = function(rt_id)
189+
{
190+
for (var i = 0; i < this._rts.length && this._rts[i].rt_id !== rt_id; i++);
191+
return i;
192+
};
193+
194+
/* implementation */
195+
196+
this.update = function()
197+
{
198+
this._rts = [];
199+
this._win_id_map = {};
200+
var rt_id_list = window.runtimes.get_runtime_ids();
201+
if (rt_id_list.length)
202+
{
203+
window.messages.remove_listener('new-top-runtime', this._update_bound);
204+
this._update_rt_list(rt_id_list);
205+
}
206+
else
207+
window.messages.add_listener('new-top-runtime', this._update_bound);
208+
};
209+
210+
this.get_data = function()
211+
{
212+
if (this._rts)
213+
return this._rts;
214+
215+
this.update();
216+
return null;
217+
};
218+
219+
this.expand_listeners = function(rt_id, obj_id, ev_name, cb)
220+
{
221+
var ev_n = this._get_ev_name_obj(rt_id, ev_name);
222+
if (ev_n)
223+
{
224+
ev_n.rt_id = rt_id;
225+
ev_n.obj_id = obj_id;
226+
ev_n.model = new cls.InspectableDOMNode(rt_id, obj_id);
227+
var cb = this._handle_dom_search.bind(this, ev_n, cb);
228+
ev_n.model.search(ev_name, SEARCH_TYPE_EVENT, 0, 0, cb);
229+
}
230+
else
231+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
232+
"failed to find event names object in cls.EvenetListeners.")
233+
234+
};
235+
236+
this._init = function(view)
237+
{
238+
this._view = view;
239+
this._tagman = window.tag_manager;
240+
this._esdb = window.services["ecmascript-debugger"];
241+
this._update_bound = this.update.bind(this);
242+
}
243+
244+
this._init(view);
245+
};

0 commit comments

Comments
 (0)