Permalink
Browse files

Set menu-iconic and menuitem-iconic classes when necessary.

  • Loading branch information...
1 parent 417008b commit 9e7315aa68d0fdafbb0b05928f691534b2b3d503 @Mossop committed Jan 17, 2013
Showing with 42 additions and 16 deletions.
  1. +30 −14 lib/sdk/context-menu.js
  2. +12 −2 test/test-context-menu.js
View
@@ -762,7 +762,7 @@ let MenuWrapper = Class({
for (let xulNode of toplevel) {
menupopup.appendChild(xulNode);
- this.setXULClass(xulNode);
+ this.updateXULClass(xulNode);
}
}
}
@@ -788,16 +788,16 @@ let MenuWrapper = Class({
},
// Sets the right class for XUL nodes
- setXULClass: function setXULClass(xulNode) {
- let cls = ITEM_CLASS;
-
+ updateXULClass: function updateXULClass(xulNode) {
if (xulNode.parentNode == this.contextMenu)
- cls += " " + TOPLEVEL_ITEM_CLASS;
+ xulNode.classList.add(TOPLEVEL_ITEM_CLASS);
+ else
+ xulNode.classList.remove(TOPLEVEL_ITEM_CLASS);
if (xulNode.parentNode == this.overflowPopup)
- cls += " " + OVERFLOW_ITEM_CLASS;
-
- xulNode.className = cls;
+ xulNode.classList.add(OVERFLOW_ITEM_CLASS);
+ else
+ xulNode.classList.remove(OVERFLOW_ITEM_CLASS);
},
// Creates a XUL node for an item
@@ -819,10 +819,16 @@ let MenuWrapper = Class({
type = "menuseparator";
let xulNode = this.window.document.createElement(type);
+ xulNode.setAttribute("class", ITEM_CLASS);
if (item instanceof LabelledItem) {
xulNode.setAttribute("label", item.label);
- if (item.image)
+ if (item.image) {
xulNode.setAttribute("image", item.image);
+ if (item instanceof Menu)
+ xulNode.classList.add("menu-iconic");
+ else
+ xulNode.classList.add("menuitem-iconic");
+ }
if (item.data)
xulNode.setAttribute("value", item.data);
@@ -837,7 +843,7 @@ let MenuWrapper = Class({
}
this.insertIntoXUL(item, xulNode, after);
- this.setXULClass(xulNode);
+ this.updateXULClass(xulNode);
xulNode.data = item.data;
if (item instanceof Menu) {
@@ -857,10 +863,20 @@ let MenuWrapper = Class({
// TODO figure out why this requires setAttribute
xulNode.setAttribute("label", item.label);
- if (item.image)
+
+ if (item.image) {
xulNode.setAttribute("image", item.image);
- else
+ if (item instanceof Menu)
+ xulNode.classList.add("menu-iconic");
+ else
+ xulNode.classList.add("menuitem-iconic");
+ }
+ else {
xulNode.removeAttribute("image");
+ xulNode.classList.remove("menu-iconic");
+ xulNode.classList.remove("menuitem-iconic");
+ }
+
if (item.data)
xulNode.setAttribute("value", item.data);
else
@@ -877,7 +893,7 @@ let MenuWrapper = Class({
let oldParent = xulNode.parentNode;
this.insertIntoXUL(item, xulNode, after);
- this.setXULClass(xulNode);
+ this.updateXULClass(xulNode);
this.onXULRemoved(oldParent);
},
@@ -926,7 +942,7 @@ let MenuWrapper = Class({
while (parent.firstChild) {
let node = parent.firstChild;
this.contextMenu.insertBefore(node, parent.parentNode);
- this.setXULClass(node);
+ this.updateXULClass(node);
}
this.contextMenu.removeChild(parent.parentNode);
}
View
@@ -2248,12 +2248,22 @@ TestHelper.prototype = {
if (itemType === "Item" || itemType === "Menu") {
this.test.assertEqual(elt.getAttribute("label"), item.label,
"Item should have correct title");
- if (typeof(item.image) === "string")
+ if (typeof(item.image) === "string") {
this.test.assertEqual(elt.getAttribute("image"), item.image,
"Item should have correct image");
- else
+ if (itemType === "Menu")
+ this.test.assert(elt.classList.contains("menu-iconic"),
+ "Menus with images should have the correct class")
+ else
+ this.test.assert(elt.classList.contains("menuitem-iconic"),
+ "Items with images should have the correct class")
+ }
+ else {
this.test.assert(!elt.getAttribute("image"),
"Item should not have image");
+ this.test.assert(!elt.classList.contains("menu-iconic") && !elt.classList.contains("menuitem-iconic"),
+ "The iconic classes should not be present")
+ }
}
},

0 comments on commit 9e7315a

Please sign in to comment.