Skip to content
Browse files

Merge branch 'issue229' of github.com:firebug/firebug

  • Loading branch information...
2 parents 1f1316e + 25b1e62 commit e184b8543b1c09c638f514a7da824cb3538ea9e8 @janodvarko janodvarko committed
View
11 extension/content/firebug/chrome/menu.js
@@ -95,9 +95,6 @@ Menu.setItemIntoElement = function(element, item)
if (item.type == "checkbox" && !item.closemenu)
element.setAttribute("closemenu", "none");
- if (item.checked)
- element.setAttribute("checked", "true");
-
if (item.disabled)
element.setAttribute("disabled", "true");
@@ -134,7 +131,15 @@ Menu.setItemIntoElement = function(element, item)
element.setAttribute("name", item.name);
if (item.items && (item.command || item.commandID))
+ {
element.setAttribute("type", "splitmenu");
+ element.setAttribute("iconic", "true");
+ }
+
+ // xxxHonza: must be done after 'type' == 'splitmenu' otherwise the menu-item
+ // is not checked (the check icon is not displayed from some reason).
+ if (item.checked)
+ element.setAttribute("checked", "true");
return element;
};
View
65 extension/content/firebug/chrome/reps.js
@@ -23,14 +23,13 @@ define([
"firebug/lib/string",
"firebug/lib/xml",
"firebug/dom/toggleBranch",
- "firebug/console/eventMonitor",
"firebug/console/closureInspector",
"firebug/chrome/menu",
"arch/compilationunit",
],
function(Obj, Arr, Firebug, Domplate, Firefox, Xpcom, Locale, HTMLLib, Events, Wrapper, Options,
Url, SourceLink, StackFrame, Css, Dom, Win, System, Xpath, Str, Xml, ToggleBranch,
- EventMonitor, ClosureInspector, Menu, CompilationUnit) {
+ ClosureInspector, Menu, CompilationUnit) {
with (Domplate) {
@@ -1477,23 +1476,10 @@ FirebugReps.Element = domplate(Firebug.Rep,
}
]);
}
-
+
items = items.concat([
"-",
{
- label: "ShowEventsInConsole",
- tooltiptext: "html.tip.Show_Events_In_Console",
- id: "fbShowEventsInConsole",
- type: "checkbox",
- checked: EventMonitor.areEventsMonitored(elt, null, context),
- command: function()
- {
- var checked = this.hasAttribute("checked");
- EventMonitor.toggleMonitorEvents(elt, null, !checked, context);
- }
- },
- "-",
- {
label: "ScrollIntoView",
tooltiptext: "html.tip.Scroll_Into_View",
id: "fbScrollIntoView",
@@ -1972,52 +1958,6 @@ FirebugReps.Event = domplate(Firebug.Rep,
// ********************************************************************************************* //
-FirebugReps.EventLog = domplate(FirebugReps.Event,
-{
- className: "eventLog",
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
- tag:
- TAG("$copyEventTag", {object: "$object|copyEvent"}),
-
- copyEventTag:
- SPAN(
- OBJECTLINK("$object|summarizeEvent"),
- SPAN("&nbsp"),
- SPAN("»"),
- SPAN("&nbsp"),
- TAG("$object|getTargetTag", {object: "$object|getTarget"})
- ),
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
- copyEvent: function(log)
- {
- return new Dom.EventCopy(log.event);
- },
-
- getTarget: function(event)
- {
- return event.target;
- },
-
- getTargetTag: function(event)
- {
- var rep = Firebug.getRep(event.target);
- return rep.shortTag ? rep.shortTag : rep.tag;
- },
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
- supportsObject: function(object, type)
- {
- return object instanceof EventMonitor.EventLog;
- },
-});
-
-// ********************************************************************************************* //
-
FirebugReps.SourceLink = domplate(Firebug.Rep,
{
tag:
@@ -3542,7 +3482,6 @@ Firebug.registerRep(
FirebugReps.Date,
FirebugReps.NamedNodeMap,
FirebugReps.Reference,
- FirebugReps.EventLog,
FirebugReps.ClosureScope,
FirebugReps.OptimizedAway
);
View
1 extension/content/firebug/console/console.js
@@ -14,6 +14,7 @@ define([
"firebug/console/consolePanel",
"firebug/console/commandEditor",
"firebug/console/functionMonitor",
+ "firebug/console/eventMonitor",
"firebug/console/performanceTiming",
],
function(Obj, Firebug, Firefox, Events, Win, Search, Xml, Options) {
View
258 extension/content/firebug/console/eventMonitor.js
@@ -6,8 +6,12 @@ define([
"firebug/lib/trace",
"firebug/lib/events",
"firebug/lib/locale",
+ "firebug/lib/dom",
+ "firebug/lib/domplate",
+ "firebug/chrome/reps",
+ "firebug/chrome/menu",
],
-function(Obj, Firebug, FBTrace, Events, Locale) {
+function(Obj, Firebug, FBTrace, Events, Locale, Dom, Domplate, FirebugReps, Menu) {
// ********************************************************************************************* //
// EventMonitor Module
@@ -19,15 +23,27 @@ var EventMonitor = Obj.extend(Firebug.Module,
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Module
+ initialize: function()
+ {
+ Firebug.Module.initialize.apply(this, arguments);
+ Firebug.registerUIListener(this);
+ },
+
+ shutdown: function()
+ {
+ Firebug.unregisterUIListener(this);
+ Firebug.Module.shutdown.apply(this, arguments);
+ },
+
destroyContext: function(context, persistedState)
{
// Clean up all existing monitors.
- var eventsMonitored = context.eventsMonitored;
- if (eventsMonitored)
+ var monitoredEvents = context.monitoredEvents;
+ if (monitoredEvents)
{
- for (var i=0; i<eventsMonitored.length; ++i)
+ for (var i=0; i<monitoredEvents.length; ++i)
{
- var m = eventsMonitored[i];
+ var m = monitoredEvents[i];
if (!m.type)
Events.detachAllListeners(m.object, context.onMonitorEvent, context);
@@ -40,12 +56,12 @@ var EventMonitor = Obj.extend(Firebug.Module,
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Event Monitor
- toggleMonitorEvents: function(object, types, state, context)
+ toggleMonitorEvents: function(object, types, monitor, context)
{
- if (state)
- this.unmonitorEvents(object, types, context);
- else
+ if (monitor)
this.monitorEvents(object, types, context);
+ else
+ this.unmonitorEvents(object, types, context);
},
monitorEvents: function(object, types, context)
@@ -60,20 +76,25 @@ var EventMonitor = Obj.extend(Firebug.Module,
};
}
- if (!context.eventsMonitored)
- context.eventsMonitored = [];
+ if (!context.monitoredEvents)
+ context.monitoredEvents = new Map();
+ var monitoredEvents = context.monitoredEvents;
var eventTypes = getMonitoredEventTypes(types);
if (FBTrace.DBG_EVENTS)
FBTrace.sysout("EventMonitor.monitorEvents", eventTypes);
- for (var i = 0; i < eventTypes.length; ++i)
+ if (!context.monitoredEvents.has(object))
+ context.monitoredEvents.set(object, new Set());
+
+ var monitoredEventTypes = monitoredEvents.get(object);
+ for (var i = 0, len = eventTypes.length; i < len; ++i)
{
if (!this.areEventsMonitored(object, eventTypes[i], context))
{
Events.addEventListener(object, eventTypes[i], context.onMonitorEvent, false);
- context.eventsMonitored.push({object: object, type: eventTypes[i]});
+ monitoredEventTypes.add(eventTypes[i]);
}
}
}
@@ -81,31 +102,38 @@ var EventMonitor = Obj.extend(Firebug.Module,
unmonitorEvents: function(object, types, context)
{
- var eventsMonitored = context.eventsMonitored;
+ var monitoredEvents = context.monitoredEvents;
+
+ if (!monitoredEvents)
+ return;
+
var eventTypes = getMonitoredEventTypes(types);
if (FBTrace.DBG_EVENTS)
FBTrace.sysout("EventMonitor.unmonitorEvents", eventTypes);
- for (var i = 0; i < eventTypes.length; ++i)
+ if (object)
{
- for (var j = 0; j < eventsMonitored.length; ++j)
+ if (monitoredEvents.has(object))
{
- if (eventsMonitored[j].object == object && eventsMonitored[j].type == eventTypes[i])
+ var monitoredObjectEvents = monitoredEvents.get(object);
+ for (var i = 0, len = eventTypes.length; i < len; ++i)
{
- eventsMonitored.splice(j, 1);
-
- Events.removeEventListener(object, eventTypes[i], context.onMonitorEvent, false);
- break;
+ if (monitoredObjectEvents.has(eventTypes[i]))
+ {
+ Events.removeEventListener(object, eventTypes[i],
+ context.onMonitorEvent, false);
+ monitoredObjectEvents["delete"](eventTypes[i]);
+ }
}
}
}
},
- areEventsMonitored: function(object, types, context)
+ areEventsMonitored: function(object, types, context, allMonitored)
{
- var eventsMonitored = context.eventsMonitored;
- if (!eventsMonitored)
+ var monitoredEvents = context.monitoredEvents;
+ if (!monitoredEvents)
{
if (FBTrace.DBG_EVENTS)
FBTrace.sysout("EventMonitor.areEventsMonitored - No events monitored", object);
@@ -113,23 +141,17 @@ var EventMonitor = Obj.extend(Firebug.Module,
return false;
}
- var eventTypes = [];
- if (!types)
- eventTypes = Events.getEventTypes();
- else
- eventTypes = typeof types == "string" ? [types] : types;
+ var eventTypes = getMonitoredEventTypes(types);
+ var monitoredObjectEvents = monitoredEvents.get(object);
+ if (!monitoredObjectEvents)
+ return;
+
+ if (typeof allMonitored == "undefined")
+ allMonitored = true;
- for (var i = 0; i < eventTypes.length; ++i)
+ for (var i = 0, len = eventTypes.length; i < len; ++i)
{
- var monitored = false;
- for (var j = 0; j < eventsMonitored.length; ++j)
- {
- if (eventsMonitored[j].object == object && eventsMonitored[j].type == eventTypes[i])
- {
- monitored = true;
- break;
- }
- }
+ var monitored = monitoredObjectEvents.has(eventTypes[i]);
if (!monitored)
{
@@ -139,7 +161,8 @@ var EventMonitor = Obj.extend(Firebug.Module,
eventTypes[i] + "'");
}
- return false;
+ if (allMonitored)
+ return false;
}
else
{
@@ -148,10 +171,13 @@ var EventMonitor = Obj.extend(Firebug.Module,
FBTrace.sysout("EventMonitor.areEventsMonitored - Events monitored for '" +
eventTypes[i] + "'");
}
+
+ if (!allMonitored)
+ return true;
}
}
- return true;
+ return allMonitored;
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -159,17 +185,94 @@ var EventMonitor = Obj.extend(Firebug.Module,
onMonitorEvent: function(event, context)
{
- var obj = new EventMonitor.EventLog(event);
+ var obj = new EventLog(event);
Firebug.Console.log(obj, context);
- }
-});
+ },
-// ********************************************************************************************* //
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+ // UI Listener
-EventMonitor.EventLog = function(event)
-{
- this.event = event;
-};
+ onContextMenu: function(items, object, target, context, panel, popup)
+ {
+ if (panel.name != "html")
+ return items;
+
+ var before = popup.querySelector("#fbScrollIntoView");
+ if (!before)
+ return items;
+
+ var elt = object;
+
+ // Create sub-menu-items for "Log Event"
+ var logEventItems = [];
+ var eventFamilies = Events.getEventFamilies();
+ for (var i=0, count=eventFamilies.length; i<count; ++i)
+ {
+ var family = eventFamilies[i];
+
+ // Compose a tooltip for the menu item.
+ var tooltipText = "Monitor " + eventFamilies[i] + " events:";
+ var types = Events.getEventTypes(family);
+ tooltipText += "\n" + types.join(", ");
+
+ // xxxHonza: there could be a helper for getting the CSS selector
+ var Element = FirebugReps.Element;
+ var selector = Element.getSelectorTag(elt) +
+ Element.getSelectorId(elt) +
+ Element.getSelectorClass(elt);
+
+ // xxxHonza: localization?
+ tooltipText += "\n\nCommand Line Example:\n" +
+ "monitorEvents($('" + selector + "'), '" + family + "')";
+
+ logEventItems.push({
+ nol10n: true,
+ label: Locale.$STR(family),
+ tooltiptext: tooltipText,
+ id: "monitor" + family + "Events",
+ type: "checkbox",
+ checked: this.areEventsMonitored(elt, family, context),
+ command: Obj.bind(this.onToggleMonitorEvents, this, elt, family, context)
+ });
+ }
+
+ function onCommand(event)
+ {
+ Events.cancelEvent(event);
+
+ var checked = this.areEventsMonitored(elt, null, context, false);
+ this.toggleMonitorEvents(elt, null, !checked, context);
+ }
+
+ var item = {
+ label: "ShowEventsInConsole",
+ tooltiptext: "html.tip.Show_Events_In_Console",
+ id: "fbShowEventsInConsole",
+ type: "checkbox",
+ checked: this.areEventsMonitored(elt, null, context, false),
+ command: onCommand.bind(this),
+ items: logEventItems
+ };
+
+ var logEventsItem = Menu.createMenuItem(popup, item, before);
+ var separator = Menu.createMenuItem(popup, "-", before);
+
+ return items;
+ },
+
+ onToggleMonitorEvents: function(event, elt, type, context)
+ {
+ var checked = event.target.getAttribute("checked") == "true";
+ this.toggleMonitorEvents(elt, type, checked, context);
+
+ Events.cancelEvent(event);
+
+ // Toggle the main "Log Events" option depending on whether all events are monitored.
+ var doc = event.target.ownerDocument;
+ var logEvents = doc.getElementById("fbShowEventsInConsole");
+ logEvents.setAttribute("checked", this.areEventsMonitored(elt, null, context, false));
+ },
+});
// ********************************************************************************************* //
// Helpers
@@ -209,6 +312,62 @@ function getMonitoredEventTypes(types)
}
// ********************************************************************************************* //
+// Rep Object
+
+var EventLog = function(event)
+{
+ this.event = event;
+};
+
+// ********************************************************************************************* //
+// Rep Template
+
+with (Domplate) {
+var EventLogRep = domplate(FirebugReps.Event,
+{
+ className: "eventLog",
+
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+ tag:
+ TAG("$copyEventTag", {object: "$object|copyEvent"}),
+
+ copyEventTag:
+ SPAN(
+ FirebugReps.OBJECTLINK("$object|summarizeEvent"),
+ SPAN("&nbsp"),
+ SPAN("&#187;"),
+ SPAN("&nbsp"),
+ TAG("$object|getTargetTag", {object: "$object|getTarget"})
+ ),
+
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+ copyEvent: function(log)
+ {
+ return new Dom.EventCopy(log.event);
+ },
+
+ getTarget: function(event)
+ {
+ return event.target;
+ },
+
+ getTargetTag: function(event)
+ {
+ var rep = Firebug.getRep(event.target);
+ return rep.shortTag ? rep.shortTag : rep.tag;
+ },
+
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+ supportsObject: function(object, type)
+ {
+ return object instanceof EventLog;
+ },
+})};
+
+// ********************************************************************************************* //
// CommandLine Support
function monitorEvents(context, args)
@@ -233,6 +392,7 @@ function unmonitorEvents(context, args)
// Registration
Firebug.registerModule(EventMonitor);
+Firebug.registerRep(EventLogRep);
Firebug.registerCommand("monitorEvents", {
handler: monitorEvents.bind(this),
View
3 extension/content/firebug/editor/editor.js
@@ -670,7 +670,10 @@ Firebug.InlineEditor.prototype = domplate(Firebug.BaseEditor,
panel.panelNode.appendChild(this.box);
this.input.select();
if (selectionData) // transfer selection to input element
+ {
+ FBTrace.sysout("selectionData", selectionData);
this.setSelection(selectionData);
+ }
// Insert the "expander" to cover the target element with white space
if (!this.fixedWidth)
View
1 extension/content/firebug/firebug.css
@@ -383,6 +383,7 @@ panelBarTabList {
/************************************************************************************************/
/* splitmenu */
+
menuitem.split-menuitem-item[_moz-menuactive="true"], .split-menu-right-image[_moz-menuactive="true"] {
background-color: -moz-menuhover;
color: -moz-menuhovertext;
View
2 extension/content/firebug/firefox/bindings.xml
@@ -1906,7 +1906,7 @@
<content align="stretch">
<xul:menuitem anonid="item" flex="1"
class="menuitem-tooltip split-menuitem-item"
- xbl:inherits="label,key,image,value" allowevents="true"/>
+ xbl:inherits="label,key,image,value,checked" allowevents="true"/>
<xul:hbox class="split-menu-right-image" xbl:inherits="_moz-menuactive" >
<xul:hbox align="center" class="menu-right" xbl:inherits="_moz-menuactive,disabled">
<xul:image/>
View
8 extension/content/firebug/lib/events.js
@@ -338,6 +338,14 @@ const eventTypes =
]
};
+Events.getEventFamilies = function()
+{
+ var families = [];
+ for (var eventFamily in eventTypes)
+ families.push(eventFamily);
+ return families;
+};
+
Events.getEventTypes = function(family)
{
var types = [];

0 comments on commit e184b85

Please sign in to comment.
Something went wrong with that request. Please try again.