зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1338094 - [Mortar] Support keyboard copy. f=lchang, r=evelyn
MozReview-Commit-ID: KvLR3Ajio1n --HG-- extra : rebase_source : 3eb74758d258e928f6ed25284ecf69d8bef462c4
This commit is contained in:
Родитель
cfc5212d03
Коммит
6aa1497673
|
@ -4,6 +4,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
||||
|
||||
class Viewport {
|
||||
constructor() {
|
||||
this._viewerContainer = document.getElementById('viewerContainer');
|
||||
|
@ -39,6 +41,7 @@ class Viewport {
|
|||
this.onPasswordRequest = null;
|
||||
|
||||
this._viewportController.addEventListener('scroll', this);
|
||||
this._viewportController.addEventListener('copy', this);
|
||||
window.addEventListener('resize', this);
|
||||
}
|
||||
|
||||
|
@ -475,6 +478,15 @@ class Viewport {
|
|||
}
|
||||
}
|
||||
|
||||
_copyToClipboard(text) {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
const gClipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"]
|
||||
.getService(Ci.nsIClipboardHelper);
|
||||
gClipboardHelper.copyString(text);
|
||||
}
|
||||
|
||||
verifyPassword(password) {
|
||||
this._doAction({
|
||||
type: 'getPasswordComplete',
|
||||
|
@ -495,6 +507,12 @@ class Viewport {
|
|||
this._refresh();
|
||||
}
|
||||
break;
|
||||
case 'copy':
|
||||
this._doAction({
|
||||
type: 'getSelectedText'
|
||||
})
|
||||
evt.preventDefault();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -608,6 +626,11 @@ class Viewport {
|
|||
case 'getPassword':
|
||||
this.onPasswordRequest && this.onPasswordRequest();
|
||||
break;
|
||||
case 'getSelectedTextReply':
|
||||
// For now this message is used only by text copy so we handle just
|
||||
// that case.
|
||||
this._copyToClipboard(message.selectedText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче