Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Revert "Bug 474486 - Dynamic (realtime) menu access needed for MenuAP…
Browse files Browse the repository at this point in the history
…I. r=harth"

This reverts commit 855b364.
  • Loading branch information
whimboo committed Jul 13, 2010
1 parent 6749565 commit 97a10eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
78 changes: 37 additions & 41 deletions mozmill/mozmill/extension/resource/modules/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,44 +148,45 @@ function waitForElement(elem, timeout, interval) {
return waitForEval('subject.exists()', timeout, interval, elem);
}

/**
* Dynamically create hierarchy of available menu entries
*
* @param object aWindow
* Browser window to use
* @param object aElements
* Array of menu or menuitem elements
*/
var Menu = function (aWindow, aElements) {
for each (var node in aElements) {
var entry = null;

switch (node.tagName) {
case "menu":
var popup = node.getElementsByTagName("menupopup")[0];

// Fake a click onto the menu to add dynamic entries
if (popup) {
events.fakeOpenPopup(aWindow, popup);
entry = new Menu(aWindow, popup.childNodes);
}
break;
case "menuitem":
entry = node;
break;
default:
continue;
var Menu = function (elements, doc, window) {
this.doc = doc;
this.window = window;
for each(node in elements) {
if (node.tagName){
if (node.tagName == "menu") {
var label = node.getAttribute("label");
var id = node.id;
this[label] = new Menu(node.getElementsByTagName("menupopup")[0].childNodes);
this[id] = this[label];
} else if (node.tagName == "menuitem") {
this[node.getAttribute("label")] = node;
this[node.id] = node;
}
}
}
};

if (entry) {
var label = node.getAttribute("label");
this[label] = entry;

if (node.id)
this[node.id] = this[label];
Menu.prototype.reload = function () {
var utils = this.window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.forceUpdateNativeMenuAt("4");
utils.activateNativeMenuItemAt("4|10");

var elements = this.doc.getElementsByTagName('menubar')[0].childNodes;
for each(node in elements) {
if (node.tagName){
if (node.tagName == "menu") {
var label = node.getAttribute("label");
var id = node.id;
this[label] = new Menu(node.getElementsByTagName("menupopup")[0].childNodes);
this[id] = this[label];
} else if (node.tagName == "menuitem") {
this[node.getAttribute("label")] = node;
this[node.id] = node;
}
}
}
};
}

var MozMillController = function (window) {
// TODO: Check if window is loaded and block until it has if it hasn't.
Expand Down Expand Up @@ -514,13 +515,8 @@ MozMillController.prototype.__defineGetter__("waitForEvents", function() {
});

MozMillController.prototype.__defineGetter__("menus", function() {
var menu = null;

var menubar = this.window.document.getElementsByTagName('menubar');
if(menubar && menubar.length > 0)
menu = new Menu(this.window, menubar[0].childNodes);

return menu;
if(this.window.document.getElementsByTagName('menubar').length > 0)
return new Menu(this.window.document.getElementsByTagName('menubar')[0].childNodes, this.window.document, this.window);
});

MozMillController.prototype.waitForImage = function (elem, timeout, interval) {
Expand Down
17 changes: 1 addition & 16 deletions mozmill/mozmill/extension/resource/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// ***** END LICENSE BLOCK *****

var EXPORTED_SYMBOLS = ["createEventObject", "triggerEvent", "getKeyCodeFromKeySequence",
"triggerKeyEvent", "triggerMouseEvent", "fakeOpenPopup"];
"triggerKeyEvent", "triggerMouseEvent"];

var EventUtils = {}; Components.utils.import('resource://mozmill/stdlib/EventUtils.js', EventUtils);

Expand All @@ -57,21 +57,6 @@ var createEventObject = function(element, controlKeyDown, altKeyDown, shiftKeyDo
return evt;
};

/**
* Fakes a click on a menupopup
*
* @param window aWindow
* Browser window to use
* @param menupopup aPopup
* Popup to fake the click for
*/
function fakeOpenPopup(aWindow, aPopup) {
var popupEvent = aWindow.document.createEvent("MouseEvent");
popupEvent.initMouseEvent("popupshowing", true, true, aWindow, 0,
0, 0, 0, 0, false, false, false, false,
0, null);
aPopup.dispatchEvent(popupEvent);
}

/* Fire an event in a browser-compatible manner */
var triggerEvent = function(element, eventType, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
Expand Down

0 comments on commit 97a10eb

Please sign in to comment.