Skip to content

Commit c070db9

Browse files
author
Chris K
committed
Code cleanup.
1 parent 10ab6e5 commit c070db9

File tree

5 files changed

+114
-93
lines changed

5 files changed

+114
-93
lines changed

src/ecma-debugger/eventlisteners/evlisteners.js

Lines changed: 83 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,64 @@ cls.EventName = function(name)
1515
this.obj_id = 0;
1616
};
1717

18+
cls.EventName.prototype = new function()
19+
{
20+
var SEARCH_TYPE_EVENT = 5;
21+
22+
this.search_dom = function(rt_id, obj_id, ev_name, cb)
23+
{
24+
this.rt_id = rt_id;
25+
this.obj_id = obj_id;
26+
this.model = new cls.InspectableDOMNode(rt_id, obj_id);
27+
this.model.search(ev_name, SEARCH_TYPE_EVENT, 0, 0, cb);
28+
};
29+
};
30+
31+
cls.RTListUpdateCTX = function(rt_id_list, cb)
32+
{
33+
this._init(rt_id_list, cb);
34+
};
35+
36+
cls.RTListUpdateCTX.prototype = new function()
37+
{
38+
this._handle_expand_listener = function(ev_name_obj)
39+
{
40+
var list = this.expanded_map[ev_name_obj.rt_id];
41+
var index = list.indexOf(ev_name_obj.name);
42+
if (index > -1)
43+
list.splice(index, 1);
44+
else
45+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
46+
"_handle_expand_listener failed in cls.EvenetListeners.")
47+
48+
this.check_is_updated();
49+
};
50+
51+
this._check_rt = function(rt_id)
52+
{
53+
return this.rt_map.hasOwnProperty(rt_id) &&
54+
(!this.rt_map[rt_id] || (this.expanded_map[rt_id] &&
55+
this.expanded_map[rt_id].length === 0));
56+
};
57+
58+
this.check_is_updated = function()
59+
{
60+
if (this.rt_id_list.every(this._check_rt))
61+
this._cb(this);
62+
};
63+
64+
this._init = function(rt_id_list, cb)
65+
{
66+
this.rt_id_list = rt_id_list;
67+
this.rt_map = {};
68+
this.win_id_map = {};
69+
this.expanded_map = {};
70+
this.handle_expand_listener = this._handle_expand_listener.bind(this);
71+
this._check_rt = this._check_rt.bind(this);
72+
this._cb = cb;
73+
};
74+
};
75+
1876
cls.EvenetListeners = function(view)
1977
{
2078
this._init(view);
@@ -33,31 +91,17 @@ cls.EvenetListeners.prototype = new function()
3391

3492
var SUCCESS = 0;
3593
var SEARCH_TYPE_EVENT = 5;
94+
var DELAY = 150;
95+
var GET_RT_ID = function(rt) { return rt.rt_id };
3696

3797
/*
38-
data structure
98+
data structure:
3999
40-
this._rts =
41-
[
42-
{
43-
rt_id: <rt-id>,
44-
obj_id: <obj-id>,
45-
event_names:
46-
[
47-
{
48-
name: <name>,
49-
is_expanded: <boolean>,
50-
},
51-
...
52-
]
53-
},
54-
...
55-
]
56-
100+
this._rts = [{rt_id: <rt-id>,
101+
obj_id: <obj-id>,
102+
event_names: [<EventName>, ...]}, ...]
57103
*/
58104

59-
var DELAY = 150;
60-
61105
this._on_new_rts = function()
62106
{
63107
if (!this._on_new_rts_timeout)
@@ -67,7 +111,7 @@ cls.EvenetListeners.prototype = new function()
67111
this._handle_new_rts = function()
68112
{
69113
var rt_ids = window.runtimes.get_dom_runtime_ids();
70-
var cur_rt_ids = this._rts.map(this._get_rt_id);
114+
var cur_rt_ids = this._rts.map(GET_RT_ID);
71115
var new_rt_ids = rt_ids.filter(function(id) { return !cur_rt_ids.contains(id); });
72116
var live_rts = this._rts.filter(function(rt) { return rt_ids.contains(rt.rt_id); });
73117
if (live_rts.length != this._rts.length)
@@ -81,15 +125,21 @@ cls.EvenetListeners.prototype = new function()
81125
this._on_new_rts_timeout = 0;
82126
};
83127

84-
this._get_rt_id = function(rt) { return rt.rt_id };
85-
86128
this._update_rt_list = function(rt_id_list)
87129
{
88-
var ctx = {rt_id_list: rt_id_list, rt_map: {}, win_id_map: {}, expanded_map: {}};
89-
ctx.handle_expand_listener = this._handle_expand_listener_on_update.bind(this, ctx);
130+
var ctx = new cls.RTListUpdateCTX(rt_id_list, this.on_rt_list_update_bound);
90131
rt_id_list.forEach(this._get_window_ids.bind(this, ctx));
91132
};
92133

134+
this._on_rt_list_update = function(ctx)
135+
{
136+
for (var i = 0, id; id = ctx.rt_id_list[i]; i++)
137+
{
138+
this._rts[this._get_rt_index(id)] = ctx.rt_map[id];
139+
}
140+
this._view.update();
141+
};
142+
93143
this._get_window_ids = function(ctx, rt_id)
94144
{
95145
var sel_rt_id = window.runtimes.getSelectedRuntimeId();
@@ -110,7 +160,7 @@ cls.EvenetListeners.prototype = new function()
110160
var STATUS = 0;
111161
var OBJECT_VALUE = 3;
112162
var OBJECT_ID = 0;
113-
if (status === SUCCESS && message[STATUS] == "completed" && message[OBJECT_VALUE])
163+
if (status === SUCCESS && message[STATUS] === "completed" && message[OBJECT_VALUE])
114164
{
115165
this._win_id_map[rt_id] = ctx.win_id_map[rt_id] = message[OBJECT_VALUE][OBJECT_ID];
116166
if (ctx.rt_id_list.every(function(rt_id) { return ctx.win_id_map[rt_id]; }))
@@ -150,13 +200,10 @@ cls.EvenetListeners.prototype = new function()
150200
if (this.is_expanded(rt_id, name))
151201
{
152202
ctx.expanded_map[rt_id].push(name);
153-
ev_n_obj.rt_id = rt_id;
154-
ev_n_obj.obj_id = obj_id;
155-
ev_n_obj.model = new cls.InspectableDOMNode(rt_id, obj_id);
156203
var search_cb = this._handle_dom_search.bind(this,
157204
ev_n_obj,
158205
ctx.handle_expand_listener);
159-
ev_n_obj.model.search(name, SEARCH_TYPE_EVENT, 0, 0, search_cb);
206+
ev_n_obj.search_dom(rt_id, obj_id, name, search_cb);
160207
}
161208
return ev_n_obj;
162209
}, this);
@@ -165,44 +212,13 @@ cls.EvenetListeners.prototype = new function()
165212
rt_listeners.event_names = [];
166213

167214
ctx.rt_map[rt_id] = rt_listeners;
168-
this._check_update_ctx(ctx);
215+
ctx.check_is_updated();
169216
}
170217
else
171218
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
172219
"failed to retrieve the event names in cls.EvenetListeners.")
173220
};
174221

175-
this._handle_expand_listener_on_update = function(ctx, ev_name_obj)
176-
{
177-
var list = ctx.expanded_map[ev_name_obj.rt_id];
178-
var index = list.indexOf(ev_name_obj.name);
179-
if (index > -1)
180-
list.splice(index, 1);
181-
else
182-
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
183-
"_handle_expand_listener_on_update failed in cls.EvenetListeners.")
184-
185-
this._check_update_ctx(ctx);
186-
};
187-
188-
this._check_update_ctx = function(ctx)
189-
{
190-
var check_rt = function(rt_id)
191-
{
192-
return ctx.rt_map.hasOwnProperty(rt_id) &&
193-
(!ctx.rt_map[rt_id] || (ctx.expanded_map[rt_id] &&
194-
ctx.expanded_map[rt_id].length === 0));
195-
};
196-
if (ctx.rt_id_list.every(check_rt))
197-
{
198-
for (var i = 0, id; id = ctx.rt_id_list[i]; i++)
199-
{
200-
this._rts[this._get_rt_index(id)] = ctx.rt_map[id];
201-
}
202-
this._view.update();
203-
}
204-
};
205-
206222
this._handle_dom_search = function(ev_name_obj, cb)
207223
{
208224
var tag = this._tagman.set_callback(this, this._handle_obj_search, [ev_name_obj, cb]);
@@ -295,14 +311,11 @@ cls.EvenetListeners.prototype = new function()
295311

296312
this.expand_listeners = function(rt_id, obj_id, ev_name, cb)
297313
{
298-
var ev_n = this._get_ev_name_obj(rt_id, ev_name);
299-
if (ev_n)
314+
var ev_n_obj = this._get_ev_name_obj(rt_id, ev_name);
315+
if (ev_n_obj)
300316
{
301-
ev_n.rt_id = rt_id;
302-
ev_n.obj_id = obj_id;
303-
ev_n.model = new cls.InspectableDOMNode(rt_id, obj_id);
304-
var search_cb = this._handle_dom_search.bind(this, ev_n, cb);
305-
ev_n.model.search(ev_name, SEARCH_TYPE_EVENT, 0, 0, search_cb);
317+
var search_cb = this._handle_dom_search.bind(this, ev_n_obj, cb);
318+
ev_n_obj.search_dom(rt_id, obj_id, ev_name, search_cb);
306319
}
307320
else
308321
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
@@ -335,6 +348,7 @@ cls.EvenetListeners.prototype = new function()
335348
{
336349
this._on_new_rts_timeout = 0;
337350
this._handle_new_rts_bound = this._handle_new_rts.bind(this);
351+
this.on_rt_list_update_bound = this._on_rt_list_update.bind(this);
338352
this._rts = [];
339353
this._win_id_map = {};
340354
this._expand_tree = {};
@@ -344,5 +358,4 @@ cls.EvenetListeners.prototype = new function()
344358
window.messages.add_listener("active-tab", this._on_new_rts.bind(this));
345359
};
346360

347-
348361
};

src/ecma-debugger/eventlisteners/evlistenersview.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ cls.EventListenersView = function(id, name, container_class)
4949
{
5050
// TODO testing
5151
target.get_ancestor("container").innerHTML = "";
52-
5352
this._data.update();
5453
};
5554

src/ecma-debugger/eventlisteners/evlistenertemplates.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
(function()
22
{
3-
// TODO clean up the order an the names
3+
var HAS_LISTENERS = function(rt_l) { return rt_l.event_names.length; };
4+
5+
/* Event listener view */
6+
47
this.main_ev_listener_view = function(data)
58
{
6-
var data_with_ls = data.filter(function(rt_l) { return rt_l.event_names.length; });
9+
var data_with_ls = data.filter(HAS_LISTENERS);
710
return (
811
["div",
912
["div",
1013
["span",
11-
["span", "Update all"], // TODO ui string
14+
["span", ui_strings.S_LABEL_STORAGE_UPDATE],
1215
"class" , "ui-button",
1316
"unselectable", "on",
1417
"tabindex", "1",
@@ -38,23 +41,26 @@
3841

3942
this._ev_name_item = function(ev_name_obj)
4043
{
44+
var bg_pos = ev_name_obj.is_expanded ? "0 -11px" : "0 0";
45+
4146
return (
4247
["li",
4348
["h3",
4449
["input", "type", "button",
45-
"class", "folder-key"],
50+
"class", "folder-key",
51+
"style", "background-position: " + bg_pos],
4652
ev_name_obj.name,
4753
"handler", "toggle-ev-listeners",
4854
"data-ev-name", ev_name_obj.name,
4955
"class", "ev-listener-type"],
50-
ev_name_obj.is_expanded ? this.ev_all_listeners(ev_name_obj) : []
51-
]);
56+
ev_name_obj.is_expanded ? this.ev_all_listeners(ev_name_obj) : []]);
5257
};
5358

54-
this.ev_listeners_tooltip = function(listener_list, rt_id)
59+
this.ev_all_listeners = function(ev_name_obj)
5560
{
56-
return ["dl", listener_list.map(this._ev_listener_tooltip.bind(this, rt_id)),
57-
"class", "ev-listener mono"];
61+
var tmpl_obj_l = window.templates.ev_window_listeners(ev_name_obj);
62+
var tmpl_node_l = window.templates.dom_search(ev_name_obj.model);
63+
return["div", tmpl_obj_l, [tmpl_node_l], "class", "ev-all-listeners"];
5864
};
5965

6066
this.ev_window_listeners = function(ev_name_object)
@@ -83,15 +89,12 @@
8389
return ret;
8490
};
8591

86-
this.ev_all_listeners = function(ev_name_obj)
92+
/* Event listener tooltip */
93+
94+
this.ev_listeners_tooltip = function(listener_list, rt_id)
8795
{
88-
var tmpl_obj_l = window.templates.ev_window_listeners(ev_name_obj);
89-
var tmpl_node_l = window.templates.dom_search(ev_name_obj.model);
90-
return (
91-
["div",
92-
tmpl_obj_l,
93-
[tmpl_node_l],
94-
"class", "ev-all-listeners"]);
96+
return ["dl", listener_list.map(this._ev_listener_tooltip.bind(this, rt_id)),
97+
"class", "ev-listener mono"];
9598
};
9699

97100
this._ev_listener_tooltip = function(rt_id, listener)
@@ -137,9 +140,9 @@
137140
var script = window.runtimes.getScript(script_id);
138141
if (script)
139142
{
140-
var sc_link = this.script_link_with_file_number(script,
143+
var sc_link = this.script_link_with_line_number(script,
141144
position[LINE_NUMBER],
142-
"added in %s"); //TODO ui string
145+
ui_strings.S_EVENT_LISTENER_ADDED_IN);
143146
if (sc_link.length)
144147
{
145148
sc_link.push("handler", "show-log-entry-source",
@@ -150,12 +153,12 @@
150153
}
151154
}
152155
else
153-
ret.push(["dd", "<missing JavaScript source file>"]); // TODO ui string
156+
ret.push(["dd", ui_strings.S_INFO_MISSING_JS_SOURCE_FILE]);
154157

155158
return ret;
156159
};
157160

158-
this.script_link_with_file_number = function(script, line_number, str)
161+
this.script_link_with_line_number = function(script, line_number, str)
159162
{
160163
str || (str = "%s");
161164
var ret = [];

src/ecma-debugger/objectinspection.6.0/prettyprinter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ cls.PrettyPrinter.types[cls.PrettyPrinter.FUNCTION] =
124124
var line_numbers = ["ul"];
125125
var lines = ["div"];
126126
var head = [];
127-
var sc_link = window.templates.script_link_with_file_number(script, start_line);
127+
var sc_link = window.templates.script_link_with_line_number(script, start_line);
128128
if (sc_link)
129129
{
130130
sc_link.push("handler", "show-log-entry-source",

src/ui-strings/ui_strings-en.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,3 +1496,9 @@ ui_strings.S_TOGGLE_DOM_MODEBAR_HEADER = "Breadcrumb Trail";
14961496

14971497
/* DESC: Label on button to pause/unpause updates of the network graph view */
14981498
ui_strings.S_TOGGLE_PAUSED_UPDATING_NETWORK_VIEW = "Pause updating network activity";
1499+
1500+
/* DESC: Link in an event listener tooltip to the source position where the listener is added. */
1501+
ui_strings.S_EVENT_LISTENER_ADDED_IN = "added in %s";
1502+
1503+
/* DESC: Info in an event listener tooltip that the according source file is missing. */
1504+
ui_strings.S_INFO_MISSING_JS_SOURCE_FILE = "<missing JavaScript source file>"

0 commit comments

Comments
 (0)