Bug 86894, make context menu and metadata dialog work with non-default namespaces. r=blake,sicking@bigfoot.com, sr=jst.

This commit is contained in:
heikki%netscape.com 2001-06-26 22:11:52 +00:00
Родитель 57c9888bde
Коммит 8c494134a0
2 изменённых файлов: 55 добавлений и 50 удалений

Просмотреть файл

@ -20,6 +20,7 @@
* Contributor(s):
* Jonas Sicking <sicking@bigfoot.com> (Original Author)
* Gervase Markham <gerv@gerv.net>
* Heikki Toivonen <heikki@netscape.com>
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
@ -79,31 +80,31 @@ function showMetadataFor(elem)
if (elem.ownerDocument.getElementsByName && !elem.ownerDocument.namespaceURI)
htmlMode = true;
// htmltagname is "" if it's not an html tag, or the name of the tag if it is.
var htmltagname = "";
// htmllocalname is "" if it's not an html tag, or the name of the tag if it is.
var htmllocalname = "";
if (isHTMLElement(elem,"")) {
htmltagname = elem.tagName.toLowerCase();
htmllocalname = elem.localName.toLowerCase();
}
// We only look for images once
checkForImage(elem, htmltagname);
checkForImage(elem, htmllocalname);
// Walk up the tree, looking for elements of interest.
// Each of them could be at a different level in the tree, so they each
// need their own boolean to tell us to stop looking.
while (elem && elem.nodeType == Node.ELEMENT_NODE) {
if (!onLink) checkForLink(elem, htmltagname);
if (!onInsDel) checkForInsDel(elem, htmltagname);
if (!onQuote) checkForQuote(elem, htmltagname);
if (!onTable) checkForTable(elem, htmltagname);
if (!onTitle) checkForTitle(elem, htmltagname);
if (!onLang) checkForLang(elem, htmltagname);
if (!onLink) checkForLink(elem, htmllocalname);
if (!onInsDel) checkForInsDel(elem, htmllocalname);
if (!onQuote) checkForQuote(elem, htmllocalname);
if (!onTable) checkForTable(elem, htmllocalname);
if (!onTitle) checkForTitle(elem, htmllocalname);
if (!onLang) checkForLang(elem, htmllocalname);
elem = elem.parentNode;
htmltagname = "";
htmllocalname = "";
if (isHTMLElement(elem,"")) {
htmltagname = elem.tagName.toLowerCase();
htmllocalname = elem.localName.toLowerCase();
}
}
@ -130,7 +131,7 @@ function showMetadataFor(elem)
}
function checkForImage(elem, htmltagname)
function checkForImage(elem, htmllocalname)
{
var img;
var imgType; // "img" = <img>
@ -138,22 +139,22 @@ function checkForImage(elem, htmltagname)
// "input" = <input type=image>
// "background" = css background (to be added later)
if (htmltagname === "img") {
if (htmllocalname === "img") {
img = elem;
imgType = "img";
} else if (htmltagname === "object" &&
} else if (htmllocalname === "object" &&
elem.type.substring(0,6) == "image/" &&
elem.data) {
img = elem;
imgType = "object";
} else if (htmltagname === "input" &&
} else if (htmllocalname === "input" &&
elem.type.toUpperCase() == "IMAGE") {
img = elem;
imgType = "input";
} else if (htmltagname === "area" || htmltagname === "a") {
} else if (htmllocalname === "area" || htmllocalname === "a") {
// Clicked in image map?
var map = elem;
@ -176,10 +177,10 @@ function checkForImage(elem, htmltagname)
}
}
function checkForLink(elem, htmltagname)
function checkForLink(elem, htmllocalname)
{
if ((htmltagname === "a" && elem.href != "") ||
htmltagname === "area") {
if ((htmllocalname === "a" && elem.href != "") ||
htmllocalname === "area") {
setInfo("link-lang", convertLanguageCode(elem.getAttribute("hreflang")));
setInfo("link-url", elem.href);
@ -243,9 +244,9 @@ function checkForLink(elem, htmltagname)
}
}
function checkForInsDel(elem, htmltagname)
function checkForInsDel(elem, htmllocalname)
{
if ((htmltagname === "ins" || htmltagname === "del") &&
if ((htmllocalname === "ins" || htmllocalname === "del") &&
(elem.cite || elem.dateTime)) {
setInfo("insdel-cite", getAbsoluteURL(elem.cite, elem));
setInfo("insdel-date", elem.dateTime);
@ -254,27 +255,27 @@ function checkForInsDel(elem, htmltagname)
}
function checkForQuote(elem, htmltagname)
function checkForQuote(elem, htmllocalname)
{
if ((htmltagname === "q" || htmltagname === "blockquote") && elem.cite) {
if ((htmllocalname === "q" || htmllocalname === "blockquote") && elem.cite) {
setInfo("quote-cite", getAbsoluteURL(elem.cite, elem));
onQuote = true;
}
}
function checkForTable(elem, htmltagname)
function checkForTable(elem, htmllocalname)
{
if (htmltagname === "table" && elem.summary) {
if (htmllocalname === "table" && elem.summary) {
setInfo("misc-tblsummary", elem.summary);
onTable = true;
}
}
function checkForLang(elem, htmltagname)
function checkForLang(elem, htmllocalname)
{
if ((htmltagname && elem.lang) || elem.getAttributeNS(XMLNS, "lang")) {
if ((htmllocalname && elem.lang) || elem.getAttributeNS(XMLNS, "lang")) {
var abbr;
if (htmltagname && elem.lang)
if (htmllocalname && elem.lang)
abbr = elem.lang;
else
abbr = elem.getAttributeNS(XMLNS, "lang");
@ -284,9 +285,9 @@ function checkForLang(elem, htmltagname)
}
}
function checkForTitle(elem, htmltagname)
function checkForTitle(elem, htmllocalname)
{
if (htmltagname && elem.title) {
if (htmllocalname && elem.title) {
setInfo("misc-title", elem.title);
onTitle = true;
}
@ -439,7 +440,7 @@ function isHTMLElement(node, name)
return false;
if (htmlMode)
return !name || node.tagName.toLowerCase() == name;
return !name || node.localName.toLowerCase() == name;
return (!name || node.localName == name) && node.namespaceURI == XHTMLNS;
}

Просмотреть файл

@ -207,8 +207,8 @@ nsContextMenu.prototype = {
this.target = node;
// See if the user clicked on an image.
if ( this.target.nodeType == 1 ) {
if ( this.target.tagName.toUpperCase() == "IMG" ) {
if ( this.target.nodeType == Node.ELEMENT_NODE ) {
if ( this.target.localName.toUpperCase() == "IMG" ) {
this.onImage = true;
this.imageURL = this.target.src;
// Look for image map.
@ -223,9 +223,9 @@ nsContextMenu.prototype = {
areas.length = 0;
for ( var i = 0; i < areas.length && !this.onLink; i++ ) {
var area = areas[i];
if ( area.nodeType == 1
if ( area.nodeType == Node.ELEMENT_NODE
&&
area.tagName.toUpperCase() == "AREA" ) {
area.localName.toUpperCase() == "AREA" ) {
// Get type (rect/circle/polygon/default).
var type = area.getAttribute( "type" );
var coords = this.parseCoords( area );
@ -250,7 +250,7 @@ nsContextMenu.prototype = {
}
}
}
} else if ( this.target.tagName.toUpperCase() == "OBJECT"
} else if ( this.target.localName.toUpperCase() == "OBJECT"
&&
// See if object tag is for an image.
this.objectIsImage( this.target ) ) {
@ -258,7 +258,7 @@ nsContextMenu.prototype = {
this.onImage = true;
// URL must be constructed.
this.imageURL = this.objectImageURL( this.target );
} else if ( this.target.tagName.toUpperCase() == "INPUT") {
} else if ( this.target.localName.toUpperCase() == "INPUT") {
if(this.target.getAttribute( "type" ).toUpperCase() == "IMAGE") {
this.onImage = true;
// Convert src attribute to absolute URL.
@ -267,7 +267,7 @@ nsContextMenu.prototype = {
} else /* if (this.target.getAttribute( "type" ).toUpperCase() == "TEXT") */ {
this.onTextInput = this.isTargetATextBox(this.target);
}
} else if ( this.target.tagName.toUpperCase() == "TEXTAREA" ) {
} else if ( this.target.localName.toUpperCase() == "TEXTAREA" ) {
this.onTextInput = true;
} else if ( this.target.getAttribute( "background" ) ) {
this.hasBGImage = true;
@ -334,13 +334,13 @@ nsContextMenu.prototype = {
// Bubble out, looking for items of interest
elem = this.target;
while ( elem ) {
if ( elem.nodeType == 1 ) {
var tagname = elem.tagName.toUpperCase();
if ( elem.nodeType == Node.ELEMENT_NODE ) {
var localname = elem.localName.toUpperCase();
// Link?
if ( !this.onLink &&
( tagname === "A" ||
tagname === "AREA" ||
( localname === "A" ||
localname === "AREA" ||
elem.getAttributeNS( "http://www.w3.org/1999/xlink", "type") == "simple" ) ) {
// Clicked on a link.
this.onLink = true;
@ -362,10 +362,10 @@ nsContextMenu.prototype = {
if ( !this.onMetaDataItem ) {
// We currently display metadata on anything which fits
// the below test.
if ( ( tagname === "BLOCKQUOTE" && elem.cite ) ||
( tagname === "Q" && elem.cite ) ||
( tagname === "TABLE" && elem.summary ) ||
( ( tagname === "INS" || tagname === "DEL" ) &&
if ( ( localname === "BLOCKQUOTE" && elem.cite ) ||
( localname === "Q" && elem.cite ) ||
( localname === "TABLE" && elem.summary ) ||
( ( localname === "INS" || localname === "DEL" ) &&
( elem.cite || elem.dateTime ) ) ||
elem.title ||
elem.lang ) {
@ -614,7 +614,8 @@ nsContextMenu.prototype = {
if ( node.nodeName == "#text" ) {
// Add this text to our collection.
text += " " + node.data;
} else if ( node.tagName == "IMG" ) {
} else if ( node.nodeType == Node.ELEMENT_NODE
&& node.localName.ToUpperCase() == "IMG" ) {
// If it has an alt= attribute, use that.
altText = node.getAttribute( "alt" );
if ( altText && altText != "" ) {
@ -720,7 +721,10 @@ nsContextMenu.prototype = {
},
isTargetATextBox : function ( node )
{
if (node.tagName.toUpperCase() == "INPUT") {
if (node.nodeType != Node.ELEMENT_NODE)
return false;
if (node.localName.toUpperCase() == "INPUT") {
var attrib = node.getAttribute("type").toUpperCase();
return( (attrib != "IMAGE") &&
(attrib != "PASSWORD") &&
@ -733,7 +737,7 @@ nsContextMenu.prototype = {
(attrib != "RESET") &&
(attrib != "BUTTON") );
} else {
return(node.tagName.toUpperCase() == "TEXTAREA");
return(node.localName.toUpperCase() == "TEXTAREA");
}
}
};