Skip to content

Commit f43682d

Browse files
author
Chris K
committed
Show an according string for markup attribute event handler.
1 parent 9554039 commit f43682d

File tree

6 files changed

+135
-90
lines changed

6 files changed

+135
-90
lines changed

src/ecma-debugger/dominspection/inspectabledomnode.js

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cls.EcmascriptDebugger || (cls.EcmascriptDebugger = {});
33
cls.EcmascriptDebugger["6.0"] || (cls.EcmascriptDebugger["6.0"] = {});
44

55
/**
6-
* @constructor
6+
* @constructor
77
*/
88

99
cls.EcmascriptDebugger["6.0"].InspectableDOMNode = function(rt_id,
@@ -33,19 +33,19 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.PSEUDO_NODE = 0;
3333

3434
cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
3535
{
36-
37-
const
36+
37+
const
3838
NODE_LIST = 0,
39-
ID = 0,
40-
TYPE = 1,
41-
NAME = 2,
39+
ID = 0,
40+
TYPE = 1,
41+
NAME = 2,
4242
DEPTH = 3,
4343

4444
ATTRS = 5,
4545
ATTR_PREFIX = 0,
46-
ATTR_KEY = 1,
46+
ATTR_KEY = 1,
4747
ATTR_VALUE = 2,
48-
CHILDREN_LENGTH = 6,
48+
CHILDREN_LENGTH = 6,
4949
PUBLIC_ID = 4,
5050
SYSTEM_ID = 5,
5151
MATCH_REASON = cls.EcmascriptDebugger["6.0"].InspectableDOMNode.MATCH_REASON,
@@ -104,14 +104,14 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
104104
this.search = function(query, type, ignore_case, object_id, cb)
105105
{
106106
this._isprocessing = true;
107-
var tag = window.tag_manager.set_callback(this,
108-
this.__handle_dom,
107+
var tag = window.tag_manager.set_callback(this,
108+
this.__handle_dom,
109109
[object_id, TRAVERSE_SEARCH, cb]);
110110
this.search_type = type;
111-
var msg = [this._data_runtime_id,
112-
query,
113-
type,
114-
object_id || null,
111+
var msg = [this._data_runtime_id,
112+
query,
113+
type,
114+
object_id || null,
115115
ignore_case || 0];
116116
services['ecmascript-debugger'].requestSearchDom(tag, msg);
117117
};
@@ -139,6 +139,16 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
139139
};
140140
};
141141

142+
this.node_has_attr = function(node_id, attr_name)
143+
{
144+
var node = this.get_node(node_id);
145+
var attrs = node && node[ATTRS];
146+
return attrs && attrs.some(function(attr)
147+
{
148+
return attr[ATTR_KEY] == attr_name;
149+
});
150+
}
151+
142152
this._get_dom = function(object_id, traverse_type, cb)
143153
{
144154
this._isprocessing = true;
@@ -149,11 +159,11 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
149159
this.__handle_dom = function(status, message, object_id, traverse_type, cb)
150160
{
151161
var
152-
_data = message[NODE_LIST] || [],
162+
_data = message[NODE_LIST] || [],
153163
error_ms = ui_strings.S_DRAGONFLY_INFO_MESSAGE + 'this.__handle_dom failed in DOMBaseData',
154164
splice_args = null,
155165
i = 0;
156-
166+
157167
if (!status)
158168
{
159169
switch (traverse_type)
@@ -163,7 +173,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
163173
case "parent-node-chain-with-children":
164174
{
165175
if (traverse_type != "search" || !object_id)
166-
{
176+
{
167177
this._data = _data;
168178
this._unfold_pseudos();
169179
break;
@@ -176,12 +186,12 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
176186
for (; this._data[i] && this._data[i][ID] != object_id; i++);
177187
if (this._data[i])
178188
{
179-
// A search with an object_id searches only in the subtree
180-
// of that node, but returns a tree with the ancestor up
189+
// A search with an object_id searches only in the subtree
190+
// of that node, but returns a tree with the ancestor up
181191
// to the document.
182-
// For the use case in Dragonfly we cut away the chain from
192+
// For the use case in Dragonfly we cut away the chain from
183193
// the object up to the document.
184-
if (traverse_type == "search")
194+
if (traverse_type == "search")
185195
{
186196
this.clear_search();
187197
for (var j = 0; _data[j] && _data[j][ID] != object_id; j++);
@@ -190,11 +200,11 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
190200
_data = _data.slice(j);
191201
}
192202
}
193-
// if object_id matches the one of the first node
203+
// if object_id matches the one of the first node
194204
// of the return data the traversal was subtree
195-
// a search can return no data
205+
// a search can return no data
196206
if (_data[0])
197-
{
207+
{
198208
if (object_id == _data[0][ID])
199209
{
200210
this.collapse(object_id);
@@ -204,7 +214,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
204214
{
205215
this._data.insert(i + 1, _data);
206216
}
207-
217+
208218
}
209219
this._unfold_pseudos(i, _data.length, traverse_type == "subtree");
210220
}
@@ -258,7 +268,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
258268
if (cur[DEPTH] > current_depth)
259269
{
260270
parent_stack.push(this._data[i + delta - 1]);
261-
delta += this._insert_pseudos(parent_stack.last,
271+
delta += this._insert_pseudos(parent_stack.last,
262272
i + delta,
263273
BEFORE_ALIKES);
264274
current_depth++;
@@ -267,15 +277,15 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
267277
{
268278
while (cur[DEPTH] < current_depth)
269279
{
270-
delta += this._insert_pseudos(parent_stack.last,
280+
delta += this._insert_pseudos(parent_stack.last,
271281
i + delta,
272282
AFTER_ALIKES);
273283
parent_stack.pop();
274284
current_depth--;
275285
}
276286
}
277287

278-
if (!cur[CHILDREN_LENGTH] &&
288+
if (!cur[CHILDREN_LENGTH] &&
279289
(force_unfold || current_depth == this._data[index][DEPTH]))
280290
{
281291
delta += this._insert_pseudos(cur, i + delta + 1, BEFORE_ALIKES);
@@ -333,7 +343,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
333343
level = this._data[i][DEPTH];
334344
i += 1;
335345
j = i;
336-
while (this._data[j] && this._data[j][DEPTH] > level)
346+
while (this._data[j] && this._data[j][DEPTH] > level)
337347
j++;
338348
if (j - i)
339349
{
@@ -342,7 +352,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
342352
}
343353
else
344354
{
345-
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
355+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
346356
'missing refrence in collapse_node in DOMBaseData');
347357
}
348358
};
@@ -356,7 +366,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
356366
{
357367
for (var attr, i = 0; attr = attrs[i]; i++)
358368
{
359-
if (attr[ATTR_KEY] == 'id')
369+
if (attr[ATTR_KEY] == 'id')
360370
id = "#" + attr[ATTR_VALUE];
361371
if (attr[ATTR_KEY] == 'class' && attr[ATTR_VALUE].trim())
362372
class_name = "." + attr[ATTR_VALUE].trim().replace(/\s+/g, ".");
@@ -374,7 +384,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
374384
if (cur)
375385
ret = cur[1] == '1';
376386
else
377-
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
387+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
378388
"failed in this._parse_parent_offset in InspectableDOMNode");
379389
}
380390
return ret;
@@ -439,7 +449,7 @@ cls.EcmascriptDebugger["6.0"].InspectableDOMNode.prototype = new function()
439449
{
440450
return Boolean(this._data && this._data.length);
441451
}
442-
452+
443453
this.get_node = function(node_id)
444454
{
445455
if (this.has_data())

src/ecma-debugger/eventlisteners/evlisteners.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,24 @@
4646

4747
.ev-listener-tooltip .ev-type
4848
{
49-
background-color: hsla(0, 0%, 0%, 0.04);
49+
background-color: hsla(0, 0%, 0%, 0.04);
5050
padding: 2px 8px;
5151
margin: 5px -8px 1px;
5252
border-width: 1px 0;
5353
}
5454

55+
.ev-phase
56+
{
57+
float: right;
58+
font-style: italic;
59+
color: hsl(0, 0%, 50%);
60+
}
61+
62+
.capturing-phase
63+
{
64+
color: hsl(0, 70%, 30%);
65+
}
66+
5567
.ev-added,
5668
.ev-origin
5769
{
@@ -81,4 +93,4 @@
8193
.position-relative
8294
{
8395
position: relative;
84-
}
96+
}

src/ecma-debugger/eventlisteners/evlistenertemplates.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
var rt = window.runtimes.getRuntime(ev_rt.rt_id);
3636
var ret = ["li"];
3737
if (ev_rt_list.length > 1)
38-
{
39-
ret.push(["h2",
38+
{
39+
ret.push(["h2",
4040
["span", rt && (rt.title || rt.host),
41-
"data-tooltip", "url-tooltip",
41+
"data-tooltip", "url-tooltip",
4242
"data-tooltip-text", rt && rt.uri],
4343
"class", "ev-rt-title"]);
4444
}
@@ -53,8 +53,8 @@
5353
{
5454
//var bg_pos = ev_type.is_expanded ? "0 -11px" : "0 0";
5555
return (
56-
["li",
57-
["h3",
56+
["li",
57+
["h3",
5858
["input", "type", "button",
5959
"class", "folder-key"],
6060
ev_type.type,
@@ -79,41 +79,45 @@
7979
return listener[EVENT_TYPE] == ev_type.type;
8080
};
8181

82-
return win_listeners && win_listeners.listeners.some(has_listener)
82+
return win_listeners && win_listeners.listeners &&
83+
win_listeners.listeners.some(has_listener)
8384
? ["div",
8485
"window",
85-
["span", "class", "ev-listener",
86+
["span", "class", "ev-listener",
8687
"data-tooltip", "event-listener"],
8788
"data-model-id", String(ev_type.id),
8889
"data-window-id", String(win_listeners.win_id),
8990
"data-rt-id", String(ev_type.rt_id),
90-
"data-obj-id", String(win_listeners.win_id),
91+
"data-obj-id", String(win_listeners.win_id),
9192
"handler", "inspect-object-link",
9293
"class", "search-match"]
9394
: [];
9495
};
9596

9697
/* Event listener tooltip */
9798

98-
this.ev_listeners_tooltip = function(listener_list, rt_id)
99+
this.ev_listeners_tooltip = function(model, rt_id, node_id, listener_list)
99100
{
100-
return ["dl", listener_list.map(this._ev_listener_tooltip.bind(this, rt_id)),
101+
return ["dl", listener_list.map(this._ev_listener_tooltip.bind(this, model, rt_id, node_id)),
101102
"class", "ev-listener-tooltip"];
102103
};
103104

104-
this._ev_listener_tooltip = function(rt_id, listener)
105+
this._ev_listener_tooltip = function(model, rt_id, node_id, listener)
105106
{
106107
var ret = [];
107108
var position = listener[POSITION];
108109

109-
ret.push(["dt", listener[EVENT_TYPE], "class", "ev-type"]);
110-
ret.push(["dd", listener[USE_CAPTURE]
111-
? ui_strings.S_LISTENER_CAPTURING_PHASE
112-
: ui_strings.S_LISTENER_BUBBLING_PHASE,
113-
"class", "ev-phase"]);
110+
ret.push(["dt", listener[EVENT_TYPE],
111+
["span", listener[USE_CAPTURE]
112+
? ui_strings.S_LISTENER_CAPTURING_PHASE
113+
: ui_strings.S_LISTENER_BUBBLING_PHASE,
114+
"class", "ev-phase " + (listener[USE_CAPTURE]
115+
? "capturing-phase"
116+
: "bubbling-phase")],
117+
"class", "ev-type"]);
114118
if (listener[LISTENER_SCRIPT_DATA])
115119
{
116-
ret.push(["dd",
120+
ret.push(["dd",
117121
["span", ui_strings.S_ATTRIBUTE_LISTENER,
118122
"data-tooltip", "js-inspection",
119123
"data-script-data", listener[LISTENER_SCRIPT_DATA],
@@ -122,7 +126,7 @@
122126
}
123127
else
124128
{
125-
ret.push(["dd",
129+
ret.push(["dd",
126130
["span", listener[ORIGIN] == ORIGIN_EVENT_TARGET
127131
? ui_strings.S_EVENT_TARGET_LISTENER
128132
: ui_strings.S_ATTRIBUTE_LISTENER,
@@ -139,7 +143,7 @@
139143
{
140144
var sc_link = this.script_link_with_line_number(script,
141145
position[LINE_NUMBER],
142-
ui_strings.S_EVENT_LISTENER_ADDED_IN);
146+
ui_strings.S_EVENT_LISTENER_ADDED_IN);
143147
if (sc_link.length)
144148
{
145149
sc_link.push("handler", "show-log-entry-source",
@@ -149,11 +153,18 @@
149153
ret.push(["dd", sc_link]);
150154
}
151155
}
156+
else if (window.runtimes.is_runtime_of_reloaded_window(rt_id) &&
157+
model.node_has_attr(node_id, "on" + listener[EVENT_TYPE]))
158+
{
159+
ret.push(["dd", ui_strings.S_EVENT_LISTENER_SET_AS_MARKUP_ATTR,
160+
"class", "ev-markup-attribute"]);
161+
}
152162
else
163+
{
153164
ret.push(["dd", ui_strings.S_INFO_MISSING_JS_SOURCE_FILE,
154-
"handler", "reload-script-dialog",
155-
"class", "ev-missing-script"]);
156-
165+
"handler", "reload-script-dialog",
166+
"class", "ev-missing-script"]);
167+
}
157168
return ret;
158169
};
159170

@@ -167,18 +178,18 @@
167178
{
168179
var is_linked = script.script_type == "linked";
169180
ret.push("span", str.replace("%s", script.filename + ":" + line_number),
170-
"data-tooltip", is_linked && "url-tooltip",
181+
"data-tooltip", is_linked && "url-tooltip",
171182
"data-tooltip-text", is_linked && script.uri);
172183
}
173184
else
174185
{
175186
var rt = window.runtimes.getRuntime(script.runtime_id);
176187
if (rt)
177188
ret.push("span", str.replace("%s", rt.filename),
178-
"data-tooltip", "url-tooltip",
189+
"data-tooltip", "url-tooltip",
179190
"data-tooltip-text", rt.uri);
180191
else
181-
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
192+
opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
182193
" missing runtime in _ev_listener template.");
183194
}
184195
return ret;

0 commit comments

Comments
 (0)