Bug 695032 - [GTK/X11] selecting text in scratchpad doesn't place it on the X primary selection; r=rcampbell

This commit is contained in:
Mihai Sucan 2011-12-12 20:32:35 +02:00
Родитель b0f38fdada
Коммит 1b30837b8c
2 изменённых файлов: 51 добавлений и 4 удалений

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

@ -42,6 +42,11 @@ const Cu = Components.utils;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "clipboardHelper",
"@mozilla.org/widget/clipboardhelper;1",
"nsIClipboardHelper");
const ORION_SCRIPT = "chrome://browser/content/orion.js";
const ORION_IFRAME = "data:text/html;charset=utf8,<!DOCTYPE html>" +
@ -96,6 +101,8 @@ function SourceEditor() {
Services.prefs.getIntPref(SourceEditor.PREFS.TAB_SIZE);
SourceEditor.DEFAULTS.EXPAND_TAB =
Services.prefs.getBoolPref(SourceEditor.PREFS.EXPAND_TAB);
this._onOrionSelection = this._onOrionSelection.bind(this);
}
SourceEditor.prototype = {
@ -215,6 +222,9 @@ SourceEditor.prototype = {
}.bind(this);
this._view.addEventListener("Load", onOrionLoad);
if (Services.appinfo.OS == "Linux") {
this._view.addEventListener("Selection", this._onOrionSelection);
}
let KeyBinding = window.require("orion/textview/keyBinding").KeyBinding;
let TextDND = window.require("orion/textview/textDND").TextDND;
@ -411,6 +421,25 @@ SourceEditor.prototype = {
return true;
},
/**
* Orion Selection event handler for the X Window System users. This allows
* one to select text and have it copied into the X11 PRIMARY.
*
* @private
* @param object aEvent
* The Orion Selection event object.
*/
_onOrionSelection: function SE__onOrionSelection(aEvent)
{
let text = this.getText(aEvent.newValue.start, aEvent.newValue.end);
if (!text) {
return;
}
clipboardHelper.copyStringToClipboard(text,
Ci.nsIClipboard.kSelectionClipboard);
},
/**
* Get the editor element.
*
@ -817,6 +846,11 @@ SourceEditor.prototype = {
*/
destroy: function SE_destroy()
{
if (Services.appinfo.OS == "Linux") {
this._view.removeEventListener("Selection", this._onOrionSelection);
}
this._onOrionSelection = null;
this._view.destroy();
this.parentElement.removeChild(this._iframe);
this.parentElement = null;

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

@ -58,16 +58,29 @@ function editorLoaded()
let onCopy = function() {
editor.addEventListener(SourceEditor.EVENTS.TEXT_CHANGED, onPaste);
EventUtils.synthesizeMouse(editor.editorElement, 2, 2, {}, testWin);
EventUtils.synthesizeMouse(editor.editorElement, 3, 3, {button: 1}, testWin);
EventUtils.synthesizeMouse(editor.editorElement, 10, 10, {}, testWin);
EventUtils.synthesizeMouse(editor.editorElement, 11, 11, {button: 1}, testWin);
};
let onPaste = function() {
editor.removeEventListener(SourceEditor.EVENTS.TEXT_CHANGED, onPaste);
is(editor.getText(), expectedString + initialText, "middle-click paste works");
let text = editor.getText();
isnot(text.indexOf(expectedString), -1, "middle-click paste works");
isnot(text, initialText, "middle-click paste works (confirmed)");
executeSoon(testEnd);
executeSoon(doTestBug695032);
};
let doTestBug695032 = function() {
info("test for bug 695032 - editor selection should be placed in the X11 primary selection buffer");
let text = "foobarBug695032 test me, test me!";
editor.setText(text);
waitForSelection(text, function() {
EventUtils.synthesizeKey("a", {accelKey: true}, testWin);
}, testEnd, testEnd);
};
waitForSelection(expectedString, doCopy, onCopy, testEnd);