mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Clipboard copy and paste for text unicode.
This commit is contained in:
parent
5b6275e573
commit
a08d7d1306
@ -339,25 +339,38 @@ function BrowserResetZoomMinus() {
|
||||
getBrowser().selectedBrowser.markupDocumentViewer.textZoom-= .25;
|
||||
}
|
||||
|
||||
/*
|
||||
Testing the SMS and Call Services
|
||||
*/
|
||||
function BrowserTestSendCall(toCall) {
|
||||
var phoneInterface= Components.classes["@mozilla.org/phone/support;1"].createInstance(Components.interfaces.nsIPhoneSupport);
|
||||
phoneInterface.makeCall(toCall,"");
|
||||
}
|
||||
|
||||
/*
|
||||
We want to intercept before it shows,
|
||||
to evaluate when the selected content area is a phone number,
|
||||
thus mutate the popup menu to the right make call item
|
||||
*/
|
||||
function BrowserPopupShowing () {
|
||||
var selectedRange=getBrowser().selectedBrowser.contentDocument.getSelection();
|
||||
document.getElementById("item_call").label="Call \""+ selectedRange + " \"";
|
||||
document.getElementById("item_call").setAttribute("oncommand","BrowserTestSendCall("+selectedRange+")");
|
||||
var selectedRange=getBrowser().selectedBrowser.contentDocument.getSelection();
|
||||
document.getElementById("item-call").label="Call \""+ selectedRange + " \"";
|
||||
document.getElementById("item-call").setAttribute("oncommand","DoTestSendCall("+selectedRange+")");
|
||||
|
||||
/* Enable Copy */
|
||||
if(selectedRange.toString()) {
|
||||
document.getElementById("item-copy").style.display="block";
|
||||
}
|
||||
|
||||
/* Enable Paste - Can paste only if the focused element has a value attribute. :)
|
||||
THis may affect XHTML nodes. Users may be able to paste things within XML nodes.
|
||||
*/
|
||||
if(document.commandDispatcher.focusedElement.nodeName=="INPUT"||document.commandDispatcher.focusedElement.nodeName=="TEXTAREA") {
|
||||
if(DoClipCheckPaste()) {
|
||||
document.getElementById("item-paste").style.display="block";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Testing the SMS and Call Services
|
||||
*/
|
||||
function DoTestSendCall(toCall) {
|
||||
var phoneInterface= Components.classes["@mozilla.org/phone/support;1"].createInstance(Components.interfaces.nsIPhoneSupport);
|
||||
phoneInterface.makeCall(toCall,"");
|
||||
}
|
||||
|
||||
function DoFullScreen()
|
||||
{
|
||||
@ -370,7 +383,61 @@ function DoFullScreen()
|
||||
window.fullScreen = gFullScreen;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
function DoClipCopy()
|
||||
{
|
||||
var copytext=getBrowser().selectedBrowser.contentDocument.getSelection().toString();
|
||||
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
|
||||
if (!str) return false;
|
||||
str.data = copytext;
|
||||
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
|
||||
if (!trans) return false;
|
||||
trans.addDataFlavor("text/unicode");
|
||||
trans.setTransferData("text/unicode",str,copytext.length * 2);
|
||||
var clipid = Components.interfaces.nsIClipboard;
|
||||
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
|
||||
if (!clip) return false;
|
||||
clip.setData(trans,null,clipid.kGlobalClipboard);
|
||||
}
|
||||
|
||||
/*
|
||||
Currently supports text/unicode.
|
||||
*/
|
||||
function DoClipCheckPaste()
|
||||
{
|
||||
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
|
||||
if (!clip) return false;
|
||||
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
|
||||
if (!trans) return false;
|
||||
trans.addDataFlavor("text/unicode");
|
||||
clip.getData(trans,clip.kGlobalClipboard);
|
||||
var str = new Object();
|
||||
var strLength = new Object();
|
||||
var pastetext = null;
|
||||
trans.getTransferData("text/unicode",str,strLength);
|
||||
if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
|
||||
if (str) pastetext = str.data.substring(0,strLength.value / 2);
|
||||
if(pastetext) {
|
||||
return pastetext;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Currently supports pasting text/unicode within INPUT and TEXTAREA
|
||||
*/
|
||||
function DoClipPaste()
|
||||
{
|
||||
|
||||
var pasteTxt=DoClipCheckPaste();
|
||||
|
||||
/* With 007 does not fail. Maybe now focus is on the context menu */
|
||||
if(document.commandDispatcher.focusedElement) {
|
||||
|
||||
document.commandDispatcher.focusedElement.value=pasteTxt;
|
||||
}
|
||||
}
|
||||
|
||||
function addToUrlbarHistory()
|
||||
{
|
||||
@ -436,3 +503,4 @@ function BrowserToogleSiteSSR()
|
||||
|
||||
BrowserReload(); // hack until this is done by ssr itself
|
||||
}
|
||||
|
||||
|
@ -151,11 +151,15 @@
|
||||
<!-- place holder for our app popups and hook to the overlay -->
|
||||
<popupset>
|
||||
<popup id="contentAreaContextMenu" onpopupshowing="BrowserPopupShowing()">
|
||||
<menuitem id="item_call" insertbefore="context-sep-view" label="" oncommand=""/>
|
||||
<menuitem id="full_screen" label="Toggle FullScreen" oncommand="DoFullScreen()"/>
|
||||
<menuitem id="item-call" label="" insertbefore="context-sep-view" oncommand=""/>
|
||||
<menuitem id="full_screen" label="Toggle FullScreen" oncommand="DoFullScreen()"/>
|
||||
<menuitem id="item-copy" label="Copy" oncommand="DoClipCopy()" />
|
||||
<menuitem id="item-paste" label="Paste" oncommand="DoClipPaste()"/>
|
||||
</popup>
|
||||
<popup id="menu_FilePopup">
|
||||
<menuitem id="menu_close"/>
|
||||
|
||||
<!-- somehow tabbedbrowser needs this. Have to check its implementation and eliminate -->
|
||||
<popup id="menu_FilePopup">
|
||||
<menuitem id="menu_close"/>
|
||||
<menuitem id="menu_closeWindow" command="cmd_closeWindow" key="key_closeWindow" label="about" />
|
||||
</popup>
|
||||
</popupset>
|
||||
|
@ -97,3 +97,17 @@ toolbar *, #appcontent * {
|
||||
list-style-image : url("chrome://minimo/skin/reload.gif");
|
||||
}
|
||||
|
||||
#item-call
|
||||
{
|
||||
display:none;
|
||||
}
|
||||
|
||||
#item-copy
|
||||
{
|
||||
display:none;
|
||||
}
|
||||
|
||||
#item-paste
|
||||
{
|
||||
display:none;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user