bug 25071 - add "view background image" to context menu

patch by gervase.markham@univ.ox.ac.uk
r=timeless, sr=blizzard
This commit is contained in:
bbaetz%cs.mcgill.ca 2001-05-04 20:47:50 +00:00
parent 5de2572d81
commit ca20128ff7
3 changed files with 103 additions and 73 deletions

View File

@ -97,6 +97,10 @@
<menuitem id="context-viewimage"
label="&viewImageCmd.label;"
oncommand="contextMenu.viewImage();"/>
<menuitem id="context-viewbgimage"
label="&viewBGImageCmd.label;"
accesskey="&viewBGImageCmd.accesskey;"
oncommand="contextMenu.viewBGImage();"/>
<menuseparator id="context-sep-view"/>
<!-- Misc ==================================== -->
<menuitem id="context-bookmarkpage"
@ -125,10 +129,6 @@
<menuitem id="context-saveimage"
accesskey="&saveImageCmd.accesskey;"
oncommand="contextMenu.saveImage();"/>
<menuitem id="context-savebgimage"
label="&saveBGImageCmd.label;"
accesskey="&saveBGImageCmd.accesskey;"
oncommand="contextMenu.saveBGImage();"/>
<menuseparator id="context-sep-save"/>
<!-- Clipboard =============================== -->
<menuitem id="context-selectall"
@ -159,6 +159,7 @@
<!-- Metadata ================================ -->
<menuitem id="context-metadata"
label="&metadataCmd.label;"
accesskey="&metadataCmd.accesskey;"
oncommand="contextMenu.showMetadata();"/>
</popup>
</popupset>

View File

@ -21,6 +21,7 @@
* Contributor(s):
* William A. ("PowerGUI") Law <law@netscape.com>
* Blake Ross <blakeross@telocity.com>
* Gervase Markham <gerv@gerv.net>
*/
/*------------------------------ nsContextMenu ---------------------------------
@ -33,17 +34,18 @@
| longer term, this code will be restructured to make it more reusable. |
------------------------------------------------------------------------------*/
function nsContextMenu( xulMenu ) {
this.target = null;
this.menu = null;
this.onTextInput = false;
this.onImage = false;
this.onLink = false;
this.target = null;
this.menu = null;
this.onTextInput = false;
this.onImage = false;
this.onLink = false;
this.onMailtoLink = false;
this.onSaveableLink = false;
this.link = false;
this.inFrame = false;
this.hasBGImage = false;
this.inDirList = false;
this.shouldDisplay = true;
this.link = false;
this.inFrame = false;
this.hasBGImage = false;
this.inDirList = false;
this.shouldDisplay = true;
// Initialize new menu.
this.initMenu( xulMenu );
@ -110,9 +112,6 @@ nsContextMenu.prototype = {
// Save link depends on whether we're in a link.
this.showItem( "context-savelink", this.onSaveableLink );
// Save background image depends on whether there is one.
this.showItem( "context-savebgimage", this.hasBGImage );
// Save image depends on whether there is one.
this.showItem( "context-saveimage", this.onImage );
if (this.onImage){ //if onImage, let's get the imagename into the context menu
@ -144,6 +143,9 @@ nsContextMenu.prototype = {
// View Image depends on whether an image was clicked on.
this.showItem( "context-viewimage", this.onImage );
// View background image depends on whether there is one.
this.showItem( "context-viewbgimage", this.hasBGImage && !this.onImage );
// Remove separator if all items are removed.
this.showItem( "context-sep-view", !this.inDirList || this.inFrame || this.onImage );
},
@ -182,19 +184,21 @@ nsContextMenu.prototype = {
this.showItem( "context-copyimage", this.onImage );
},
initMetadataItems : function () {
// Show unless in directory listing.
// Metadata for directory listings could ofcource be added if wanted
this.setItemAttr( "context-metadata", "disabled", this.inDirList ? "true" : null );
// Show if user clicked on something which has metadata.
this.showItem( "context-metadata", this.onMetaDataItem );
this.showItem( "context-sep-clip", this.onMetaDataItem );
},
// Set various context menu attributes based on the state of the world.
setTarget : function ( node ) {
// Initialize contextual info.
this.onImage = false;
this.onMetaDataItem = false;
this.onTextInput = false;
this.imageURL = "";
this.onLink = false;
this.inFrame = false;
this.hasBGImage = false;
this.bgImageURL = "";
// Remember the node that was clicked.
this.target = node;
@ -263,10 +267,10 @@ nsContextMenu.prototype = {
} else if ( this.target.tagName.toUpperCase() == "TEXTAREA" ) {
this.onTextInput = true;
} else if ( this.target.getAttribute( "background" ) ) {
this.onImage = true;
// Convert background attribute to absolute URL.
this.imageURL = this.makeURLAbsolute( this.target.ownerDocument,
this.target.getAttribute( "background" ) );
this.hasBGImage = true;
// Convert background attribute to absolute URL.
this.bgImageURL = this.makeURLAbsolute( this.target.baseURI,
this.target.getAttribute( "background" ) );
} else if ( "HTTPIndex" in _content &&
_content.HTTPIndex instanceof Components.interfaces.nsIHTTPIndex ) {
this.inDirList = true;
@ -316,40 +320,65 @@ nsContextMenu.prototype = {
}
}
// We have meta data on images.
this.onMetaDataItem = this.onImage;
// See if the user clicked in a frame.
if ( this.target.ownerDocument != window._content.document ) {
this.inFrame = true;
}
// Bubble up looking for an input or textarea
var elem = this.target;
while ( elem && !this.onTextInput ) {
// Test for element types of interest.
if ( elem.nodeType == 1 ) {
// Clicked on a link.
this.onTextInput = this.isTargetATextBox(elem);
}
elem = elem.parentNode;
}
// Bubble out, looking for link.
// Bubble out, looking for items of interest
elem = this.target;
while ( elem && !this.onLink ) {
// Test for element types of interest.
if ( elem.nodeType == 1 &&
( elem.tagName.toUpperCase() == "A"
||
elem.tagName.toUpperCase() == "AREA"
||
elem.getAttributeNS("http://www.w3.org/1999/xlink","type") == "simple")) {
// Clicked on a link.
this.onLink = true;
// Remember corresponding element.
this.link = elem;
// Remember if it is saveable.
this.onSaveableLink = this.isLinkSaveable( this.link );
while ( elem ) {
if ( elem.nodeType == 1 ) {
var tagname = elem.tagName.toUpperCase();
// Link?
if ( !this.onLink &&
( tagname === "A" ||
tagname === "AREA" ||
elem.getAttributeNS( "http://www.w3.org/1999/xlink", "type") == "simple" ) ) {
// Clicked on a link.
this.onLink = true;
this.onMetaDataItem = true;
// Remember corresponding element.
this.link = elem;
// Remember if it is saveable.
this.onSaveableLink = this.isLinkSaveable( this.link );
}
// Text input?
if ( !this.onTextInput ) {
// Clicked on a link.
this.onTextInput = this.isTargetATextBox(elem);
}
// Metadata item?
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" ) &&
( elem.cite || elem.dateTime ) ) ||
elem.title ||
elem.lang ) {
dump("On metadata item.\n");
this.onMetaDataItem = true;
}
}
// Background image?
if ( !this.hasBGImage && elem.background ) {
this.hasBGImage = true;
// Convert background attribute to absolute URL.
this.bgImageURL = this.makeURLAbsolute( elem.baseURI,
elem.background );
}
}
elem = elem.parentNode;
elem = elem.parentNode;
}
},
// Returns true iff clicked on link is saveable.
@ -412,10 +441,14 @@ nsContextMenu.prototype = {
viewFrameInfo : function () {
BrowserPageInfo(this.target.ownerDocument);
},
// Open new window with the URL of the image.
// Change current window to the URL of the image.
viewImage : function () {
openTopWin( this.imageURL );
},
// Change current window to the URL of the background image.
viewBGImage : function () {
openTopWin( this.bgImageURL );
},
// Save URL of clicked-on frame.
saveFrame : function () {
this.savePage( this.target.ownerDocument.location.href, true );
@ -428,11 +461,6 @@ nsContextMenu.prototype = {
saveImage : function () {
this.savePage( this.imageURL, true );
},
// Save URL of background image.
saveBGImage : function () {
this.savePage( this.bgImageURL(), true );
},
// Open Metadata window for node
showMetadata : function () {
window.openDialog( "chrome://navigator/content/metadata.xul",

View File

@ -1,21 +1,21 @@
<!-- Context Menu -->
<!-- Context Menu -->
<!ENTITY openLinkCmd.label "Open Link in New Window">
<!ENTITY openLinkCmd.accesskey "o">
<!ENTITY editLinkCmd.label "Edit Link in Composer">
<!ENTITY editLinkCmd.accesskey "e">
<!ENTITY openFrameCmd.label "Open Frame in New Window">
<!ENTITY openFrameCmd.accesskey "o">
<!ENTITY showOnlyThisFrameCmd.label "Show Only This Frame">
<!ENTITY showOnlyThisFrameCmd.accesskey "w">
<!ENTITY goBackCmd.label "Back">
<!ENTITY goBackCmd.accesskey "b">
<!ENTITY goForwardCmd.label "Forward">
<!ENTITY goForwardCmd.accesskey "f">
<!ENTITY showOnlyThisFrameCmd.label "Show Only This Frame">
<!ENTITY showOnlyThisFrameCmd.accesskey "w">
<!ENTITY goBackCmd.label "Back">
<!ENTITY goBackCmd.accesskey "b">
<!ENTITY goForwardCmd.label "Forward">
<!ENTITY goForwardCmd.accesskey "f">
<!ENTITY reloadCmd.label "Reload">
<!ENTITY reloadCmd.accesskey "r">
<!ENTITY reloadCmd.commandkey "r">
<!ENTITY stopCmd.label "Stop">
<!ENTITY stopCmd.accesskey "s">
<!ENTITY stopCmd.label "Stop">
<!ENTITY stopCmd.accesskey "s">
<!ENTITY reloadFrameCmd.label "Reload Frame">
<!ENTITY reloadFrameCmd.accesskey "r">
<!ENTITY viewPageSourceCmd.label "View Page Source">
@ -28,6 +28,8 @@
<!ENTITY viewFrameInfoCmd.accesskey "i">
<!ENTITY viewImageCmd.label "View Image">
<!ENTITY viewImageCmd.accesskey "w">
<!ENTITY viewBGImageCmd.label "View Background Image">
<!ENTITY viewBGImageCmd.accesskey "w">
<!ENTITY bookmarkPageCmd.label "Bookmark this Page">
<!ENTITY bookmarkPageCmd.accesskey "b">
<!ENTITY bookmarkLinkCmd.label "Bookmark this Link">
@ -40,8 +42,6 @@
<!ENTITY saveLinkCmd.label "Save Link As...">
<!ENTITY saveLinkCmd.accesskey "a">
<!ENTITY saveImageCmd.accesskey "a">
<!ENTITY saveBGImageCmd.label "Save Background Image As...">
<!ENTITY saveBGImageCmd.accesskey "a">
<!ENTITY copyCmd.label "Copy">
<!ENTITY copyCmd.accesskey "c">
<!ENTITY selectAllCmd.label "Select All">
@ -51,7 +51,8 @@
<!ENTITY copyImageCmd.label "Copy Image Location">
<!ENTITY copyImageCmd.accesskey "m">
<!ENTITY metadataCmd.label "Properties">
<!ENTITY pasteCmd.label "Paste">
<!ENTITY pasteCmd.accesskey "p">
<!ENTITY cutCmd.label "Cut">
<!ENTITY cutCmd.accesskey "u">
<!ENTITY metadataCmd.accesskey "">
<!ENTITY pasteCmd.label "Paste">
<!ENTITY pasteCmd.accesskey "p">
<!ENTITY cutCmd.label "Cut">
<!ENTITY cutCmd.accesskey "u">