зеркало из https://github.com/mozilla/gecko-dev.git
Bug 800977 - implement copy image to clipboard context action. r=mbrubeck
This commit is contained in:
Родитель
0c07b574dc
Коммит
5b9c784325
|
@ -20,6 +20,8 @@ const BrowserTouchHandler = {
|
|||
|
||||
// Content forwarding the contextmenu command
|
||||
onContentContextMenu: function onContentContextMenu(aMessage) {
|
||||
// Note, target here is the target of the message manager message,
|
||||
// usually the browser.
|
||||
let contextInfo = { name: aMessage.name,
|
||||
json: aMessage.json,
|
||||
target: aMessage.target };
|
||||
|
|
|
@ -147,9 +147,8 @@ var ContextCommands = {
|
|||
this.docRef);
|
||||
},
|
||||
|
||||
copyImageLocation: function cc_copyImageLocation() {
|
||||
this.clipboard.copyString(ContextMenuUI.popupState.mediaURL,
|
||||
this.docRef);
|
||||
copyImage: function cc_copyImage() {
|
||||
this.sendCommand("copy-image-contents");
|
||||
},
|
||||
|
||||
bookmarkLink: function cc_bookmarkLink() {
|
||||
|
@ -169,6 +168,7 @@ var ContextCommands = {
|
|||
},
|
||||
|
||||
sendCommand: function cc_playVideo(aCommand) {
|
||||
// Send via message manager over to ContextMenuHandler
|
||||
let browser = ContextMenuUI.popupState.target;
|
||||
browser.messageManager.sendAsyncMessage("Browser:ContextCommand", { command: aCommand });
|
||||
},
|
||||
|
@ -189,12 +189,10 @@ var ContextCommands = {
|
|||
},
|
||||
|
||||
findInPage: function cc_findInPage() {
|
||||
dump('ContextCommand: findInPage');
|
||||
FindHelperUI.show();
|
||||
},
|
||||
|
||||
viewOnDesktop: function cc_viewOnDesktop() {
|
||||
dump('ContextCommand: viewOnDesktop');
|
||||
Appbar.onViewOnDesktop();
|
||||
},
|
||||
|
||||
|
|
|
@ -339,6 +339,28 @@ let Util = {
|
|||
image.src = aIconURL ? "chrome://browser/skin/images/homescreen-blank-hdpi.png"
|
||||
: "chrome://browser/skin/images/homescreen-default-hdpi.png";
|
||||
},
|
||||
|
||||
copyImageToClipboard: function Util_copyImageToClipboard(aImageLoadingContent) {
|
||||
let image = aImageLoadingContent.QueryInterface(Ci.nsIImageLoadingContent);
|
||||
if (!image) {
|
||||
Util.dumpLn("copyImageToClipboard error: image is not an nsIImageLoadingContent");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
|
||||
xferable.init(null);
|
||||
let imgRequest = aImageLoadingContent.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
let mimeType = imgRequest.mimeType;
|
||||
let imgContainer = imgRequest.image;
|
||||
let imgPtr = Cc["@mozilla.org/supports-interface-pointer;1"].createInstance(Ci.nsISupportsInterfacePointer);
|
||||
imgPtr.data = imgContainer;
|
||||
xferable.setTransferData(mimeType, imgPtr, null);
|
||||
let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
|
||||
clip.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
|
||||
} catch (e) {
|
||||
Util.dumpLn(e.message);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -587,15 +587,15 @@
|
|||
<richlistitem id="context-viewinnewtab" type="image" onclick="ContextCommands.openInNewTab();">
|
||||
<label value="&contextViewInNewTab.label;"/>
|
||||
</richlistitem>
|
||||
<richlistitem id="context-saveimage" type="image-loaded" onclick="ContextCommands.saveImage();">
|
||||
<richlistitem id="context-copy-image" type="image-loaded" onclick="ContextCommands.copyImage();">
|
||||
<label value="&contextCopyImage.label;"/>
|
||||
</richlistitem>
|
||||
<richlistitem id="context-save-image" type="image-loaded" onclick="ContextCommands.saveImage();">
|
||||
<label value="&contextSaveImage.label;"/>
|
||||
</richlistitem>
|
||||
<richlistitem id="context-saveimage" type="image-loaded" onclick="ContextCommands.saveImageTo();">
|
||||
<richlistitem id="context-save-image-to" type="image-loaded" onclick="ContextCommands.saveImageTo();">
|
||||
<label value="&contextSaveImageTo.label;"/>
|
||||
</richlistitem>
|
||||
<richlistitem id="context-copy-image-location" type="image" onclick="ContextCommands.copyImageLocation();">
|
||||
<label value="&contextCopyImageLocation.label;"/>
|
||||
</richlistitem>
|
||||
|
||||
<!-- Link related -->
|
||||
<richlistitem id="context-openinnewtab" type="link-openable" onclick="ContextCommands.openInNewTab();">
|
||||
|
@ -627,7 +627,7 @@
|
|||
<richlistitem id="context-save-video" type="video" onclick="ContextCommands.saveVideo();">
|
||||
<label value="&contextSaveVideo.label;"/>
|
||||
</richlistitem>
|
||||
<richlistitem id="context-save-video" type="video" onclick="ContextCommands.saveVideoTo();">
|
||||
<richlistitem id="context-save-video-to" type="video" onclick="ContextCommands.saveVideoTo();">
|
||||
<label value="&contextSaveVideoTo.label;"/>
|
||||
</richlistitem>
|
||||
|
||||
|
|
|
@ -90,6 +90,10 @@ var ContextMenuHandler = {
|
|||
case "paste":
|
||||
this._onPaste();
|
||||
break;
|
||||
|
||||
case "copy-image-contents":
|
||||
this._onCopyImage();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -132,6 +136,7 @@ var ContextMenuHandler = {
|
|||
state.types.push("image");
|
||||
state.label = state.mediaURL = popupNode.currentURI.spec;
|
||||
imageUrl = state.mediaURL;
|
||||
this._target = popupNode;
|
||||
|
||||
// Retrieve the type of image from the cache since the url can fail to
|
||||
// provide valuable informations
|
||||
|
@ -230,16 +235,16 @@ var ContextMenuHandler = {
|
|||
state.string = content.getSelection().toString();
|
||||
state.types.push("copy");
|
||||
state.types.push("selected-text");
|
||||
} else {
|
||||
// Add general content text if this isn't anything specific
|
||||
if (state.types.indexOf("image") == -1 &&
|
||||
state.types.indexOf("media") == -1 &&
|
||||
state.types.indexOf("video") == -1 &&
|
||||
state.types.indexOf("link") == -1 &&
|
||||
state.types.indexOf("input-text") == -1) {
|
||||
state.types.push("content-text");
|
||||
}
|
||||
} else {
|
||||
// Add general content text if this isn't anything specific
|
||||
if (state.types.indexOf("image") == -1 &&
|
||||
state.types.indexOf("media") == -1 &&
|
||||
state.types.indexOf("video") == -1 &&
|
||||
state.types.indexOf("link") == -1 &&
|
||||
state.types.indexOf("input-text") == -1) {
|
||||
state.types.push("content-text");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// populate position and event source
|
||||
|
@ -278,6 +283,10 @@ var ContextMenuHandler = {
|
|||
this.reset();
|
||||
},
|
||||
|
||||
_onCopyImage: function _onCopyImage() {
|
||||
Util.copyImageToClipboard(this._target);
|
||||
},
|
||||
|
||||
/*
|
||||
* Utility routines used in testing for various
|
||||
* HTML element types.
|
||||
|
|
|
@ -116,7 +116,6 @@ var ContextMenuUI = {
|
|||
showContextMenu: function ch_showContextMenu(aMessage) {
|
||||
this._popupState = aMessage.json;
|
||||
this._popupState.target = aMessage.target;
|
||||
|
||||
let contentTypes = this._popupState.types;
|
||||
|
||||
let optionsAvailable = false;
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
<!ENTITY contextCopyLink.label "Copy Link">
|
||||
<!ENTITY contextCopyEmail.label "Copy Email Address">
|
||||
<!ENTITY contextCopyPhone.label "Copy Phone Number">
|
||||
<!ENTITY contextCopyImageLocation.label "Copy Image Location">
|
||||
<!ENTITY contextCopyImage.label "Copy Image">
|
||||
<!ENTITY contextShareLink.label "Share Link">
|
||||
<!ENTITY contextShareImage.label "Share Image">
|
||||
<!ENTITY contextBookmarkLink.label "Bookmark Link">
|
||||
|
|
Загрузка…
Ссылка в новой задаче