mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 1261299 - Add new clipboard kSelectionCache to cache the current selection for OSX service menu. Add a constructor to nsAutoCopyListener which sets the clipboard to copy to. Pass in kSelectionCache for OSX or kSelectionClipboard for linux. r=mstange
MozReview-Commit-ID: B9mzVnJxUjl --HG-- extra : rebase_source : 5329f87a958dcb372d552b6aa17442ea7f9b9762
This commit is contained in:
parent
5ab464fd77
commit
6c6d5a3ec1
@ -16,16 +16,20 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISELECTIONLISTENER
|
||||
|
||||
explicit nsAutoCopyListener(int16_t aClipboardID)
|
||||
: mCachedClipboard(aClipboardID)
|
||||
{}
|
||||
|
||||
void Listen(nsISelectionPrivate *aSelection)
|
||||
{
|
||||
NS_ASSERTION(aSelection, "Null selection passed to Listen()");
|
||||
aSelection->AddSelectionListener(this);
|
||||
}
|
||||
|
||||
static nsAutoCopyListener* GetInstance()
|
||||
static nsAutoCopyListener* GetInstance(int16_t aClipboardID)
|
||||
{
|
||||
if (!sInstance) {
|
||||
sInstance = new nsAutoCopyListener();
|
||||
sInstance = new nsAutoCopyListener(aClipboardID);
|
||||
|
||||
NS_ADDREF(sInstance);
|
||||
}
|
||||
@ -42,6 +46,7 @@ private:
|
||||
~nsAutoCopyListener() {}
|
||||
|
||||
static nsAutoCopyListener* sInstance;
|
||||
int16_t mCachedClipboard;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -549,16 +549,22 @@ nsFrameSelection::nsFrameSelection()
|
||||
mSelectingTableCellMode = 0;
|
||||
mSelectedCellIndex = 0;
|
||||
|
||||
nsAutoCopyListener *autoCopy = nullptr;
|
||||
// On macOS, cache the current selection to send to osx service menu.
|
||||
#ifdef XP_MACOSX
|
||||
autoCopy = nsAutoCopyListener::GetInstance(nsIClipboard::kSelectionCache);
|
||||
#endif
|
||||
|
||||
// Check to see if the autocopy pref is enabled
|
||||
// and add the autocopy listener if it is
|
||||
if (Preferences::GetBool("clipboard.autocopy")) {
|
||||
nsAutoCopyListener *autoCopy = nsAutoCopyListener::GetInstance();
|
||||
autoCopy = nsAutoCopyListener::GetInstance(nsIClipboard::kSelectionClipboard);
|
||||
}
|
||||
|
||||
if (autoCopy) {
|
||||
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
||||
if (mDomSelections[index]) {
|
||||
autoCopy->Listen(mDomSelections[index]);
|
||||
}
|
||||
if (autoCopy) {
|
||||
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
||||
if (mDomSelections[index]) {
|
||||
autoCopy->Listen(mDomSelections[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6467,6 +6473,11 @@ NS_IMPL_ISUPPORTS(nsAutoCopyListener, nsISelectionListener)
|
||||
* selections?
|
||||
* - maybe we should just never clear the X clipboard? That would make this
|
||||
* problem just go away, which is very tempting.
|
||||
*
|
||||
* On macOS,
|
||||
* nsIClipboard::kSelectionCache is the flag for current selection cache.
|
||||
* Set the current selection cache on the parent process in
|
||||
* widget cocoa nsClipboard whenever selection changes.
|
||||
*/
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -6493,7 +6504,7 @@ nsAutoCopyListener::NotifySelectionChanged(nsIDOMDocument *aDoc,
|
||||
|
||||
// call the copy code
|
||||
return nsCopySupport::HTMLCopy(aSel, doc,
|
||||
nsIClipboard::kSelectionClipboard, false);
|
||||
mCachedClipboard, false);
|
||||
}
|
||||
|
||||
// SelectionChangeListener
|
||||
|
@ -17,6 +17,8 @@ interface nsIClipboard : nsISupports
|
||||
const long kSelectionClipboard = 0;
|
||||
const long kGlobalClipboard = 1;
|
||||
const long kFindClipboard = 2;
|
||||
// Used to cache current selection on (nsClipboard) for macOS service menu.
|
||||
const long kSelectionCache = 3;
|
||||
|
||||
/**
|
||||
* Given a transferable, set the data on the native clipboard
|
||||
|
Loading…
x
Reference in New Issue
Block a user