Commit 104b4257 authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb50185' into 'master'

Improve context menu media handling

See merge request mer-core/embedlite-components!61
parents 4a680905 1aaa1bf3
......@@ -4,6 +4,8 @@
const kXLinkNamespace = "http://www.w3.org/1999/xlink";
let Node = Ci.nsIDOMNode;
Logger.debug("JSScript: ContextMenuHandler.js loaded");
var ContextMenuHandler = {
......@@ -190,7 +192,7 @@ var ContextMenuHandler = {
};
// Do checks for nodes that never have children.
if (popupNode.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) {
if (popupNode.nodeType == Node.ELEMENT_NODE) {
// See if the user clicked on an image.
if (popupNode instanceof Ci.nsIImageLoadingContent && popupNode.currentURI) {
state.types.push("image");
......@@ -220,8 +222,9 @@ var ContextMenuHandler = {
let elem = popupNode;
let isText = false;
while (elem) {
if (elem.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) {
if (elem.nodeType == Node.ELEMENT_NODE) {
// is the target a link or a descendant of a link?
if (Util.isLink(elem)) {
// If this is an image that links to itself, don't include both link and
......@@ -272,16 +275,17 @@ var ContextMenuHandler = {
state.types.push("paste");
}
break;
} else if (Util.isText(elem)) {
isText = true;
} else if (elem instanceof Ci.nsIDOMHTMLMediaElement ||
elem instanceof targetWindow.HTMLVideoElement) {
} else if (Util.isMedia(elem)) {
state.label = state.mediaURL = (elem.currentSrc || elem.src);
state.types.push((elem.paused || elem.ended) ?
"media-paused" : "media-playing");
if (elem instanceof targetWindow.HTMLVideoElement) {
state.types.push("video");
}
isText = false;
break;
} else if (Util.isText(elem)) {
isText = true;
}
}
......
......@@ -188,9 +188,8 @@ let Util = {
// If a body element is editable and the body is the child of an
// iframe or div we can assume this is an advanced HTML editor
if ((aElement instanceof Ci.nsIDOMHTMLIFrameElement) &&
// ||
// aElement instanceof HTMLDivElement) &&
if ((aElement instanceof Ci.nsIDOMHTMLIFrameElement ||
this.isTypeOf(aElement, "HTMLDivElement")) &&
aElement.contentDocument &&
this.isEditableContent(aElement.contentDocument.body)) {
return true;
......@@ -222,11 +221,21 @@ let Util = {
return (aElement instanceof Ci.nsIDOMHTMLParagraphElement ||
aElement instanceof Ci.nsIDOMHTMLLIElement ||
aElement instanceof Ci.nsIDOMHTMLPreElement ||
aElement instanceof Ci.nsIDOMHTMLBodyElement);
// Test agaist webidl of HTMLDivElement
// aElement instanceof HTMLDivElement ||
// aElement instanceof HTMLHeadingElement ||
// aElement instanceof HTMLTableCellElement ||
aElement instanceof Ci.nsIDOMHTMLBodyElement ||
this.isTypeOf(aElement, "HTMLDivElement") ||
this.isTypeOf(aElement, "HTMLHeadingElement") ||
this.isTypeOf(aElement, "HTMLTableCellElement"));
},
isMedia: function isMedia(aElement) {
return (aElement instanceof Ci.nsIDOMHTMLMediaElement ||
this.isTypeOf(aElement, "HTMLVideoElement") ||
aElement.getAttribute("playable") == "true")
},
isTypeOf: function isTypeOf(aElement, type) {
let protoType = Object.prototype.toString.call(aElement);
return protoType === "[object " + type + "]";
},
/*
......@@ -492,6 +501,78 @@ let Util = {
Logger.log(e.message);
}
},
// ----------------------
// DumpDOM(node)
//
// Call this function to dump the contents of the DOM starting at the specified node.
// Use node = document.documentElement to dump every element of the current document.
// Use node = top.window.document.documentElement to dump every element.
//
// 8-13-99 Updated to dump almost all attributes of every node. There are still some attributes
// that are purposely skipped to make it more readable.
// ----------------------
dumpDOM: function(node) {
Logger.warn("--------------------- DumpDOM ---------------------");
this.dumpNodeAndChildren(node, "");
Logger.warn("------------------- End DumpDOM -------------------");
},
// This function does the work of DumpDOM by recursively calling itself to explore the tree
dumpNodeAndChildren: function(node, prefix) {
dump(prefix + "<" + node.nodeName);
var attributes = node.attributes;
if (attributes && attributes.length) {
var item, name, value;
for (var index = 0; index < attributes.length; index++) {
item = attributes.item(index);
name = item.nodeName;
value = item.nodeValue;
if ((name == 'lazycontent' && value == 'true') ||
(name == 'xulcontentsgenerated' && value == 'true') ||
(name == 'id') ||
(name == 'instanceOf')) {
// ignore these
} else {
dump(" " + name + "=\"" + value + "\"");
}
}
}
if (node.nodeType == 1) {
// id
var text = node.getAttribute('id');
if ( text && text[0] != '$' )
dump(" id=\"" + text + "\"");
}
if (node.nodeType == Node.TEXT_NODE)
dump(" = \"" + node.data + "\"");
dump(">\n");
// dump IFRAME && FRAME DOM
if (node.nodeName == "IFRAME" || node.nodeName == "FRAME") {
if (node.name) {
var wind = top.frames[node.name];
if ( wind && wind.document && wind.document.documentElement )
{
dump(prefix + "----------- " + node.nodeName + " -----------\n");
this.dumpNodeAndChildren(wind.document.documentElement, prefix + " ");
dump(prefix + "--------- End " + node.nodeName + " ---------\n");
}
}
}
// children of nodes (other than frames)
else if ( node.childNodes ) {
for ( var child = 0; child < node.childNodes.length; child++ )
this.dumpNodeAndChildren(node.childNodes[child], prefix + " ");
}
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment