Merge remote-tracking branch 'origin/master' into custom

This commit is contained in:
Roy Tam 2020-01-11 06:48:56 +08:00
commit f9aa123602
4 changed files with 33 additions and 26 deletions

View file

@ -21,7 +21,7 @@ ifeq ($(USE_PTHREADS),1)
endif endif
DEFAULT_COMPILER = gcc DEFAULT_COMPILER = gcc
DEFINES += -D_DEFAULT_SOURCE -D_BSD_SOURCE DEFINES += -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE
ifeq ($(OS_TARGET),Android) ifeq ($(OS_TARGET),Android)
ifndef ANDROID_NDK ifndef ANDROID_NDK

View file

@ -357,6 +357,7 @@
'linux', 'linux',
'_DEFAULT_SOURCE', # for <endian.h> functions, strdup, realpath, and getentropy '_DEFAULT_SOURCE', # for <endian.h> functions, strdup, realpath, and getentropy
'_BSD_SOURCE', # for the above in glibc <= 2.19 '_BSD_SOURCE', # for the above in glibc <= 2.19
'_POSIX_SOURCE', # for <signal.h>
], ],
}], }],
[ 'OS=="dragonfly" or OS=="freebsd"', { [ 'OS=="dragonfly" or OS=="freebsd"', {

View file

@ -120,24 +120,13 @@ NS_IMETHODIMP
nsClipboard::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) nsClipboard::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData)
{ {
if (strcmp(aTopic, "quit-application") == 0) { if (strcmp(aTopic, "quit-application") == 0) {
// application is going to quit, save clipboard content // Application is going to quit, save clipboard content
Store(); gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
gdk_window_remove_filter(nullptr, selection_request_filter, nullptr); gdk_window_remove_filter(nullptr, selection_request_filter, nullptr);
} }
return NS_OK; return NS_OK;
} }
nsresult
nsClipboard::Store(void)
{
// Ask the clipboard manager to store the current clipboard content
if (mGlobalTransferable) {
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_store(clipboard);
}
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsClipboard::SetData(nsITransferable *aTransferable, nsClipboard::SetData(nsITransferable *aTransferable,
nsIClipboardOwner *aOwner, int32_t aWhichClipboard) nsIClipboardOwner *aOwner, int32_t aWhichClipboard)
@ -152,9 +141,6 @@ nsClipboard::SetData(nsITransferable *aTransferable,
return NS_OK; return NS_OK;
} }
// Clear out the clipboard in order to set the new data
EmptyClipboard(aWhichClipboard);
// List of suported targets // List of suported targets
GtkTargetList *list = gtk_target_list_new(nullptr, 0); GtkTargetList *list = gtk_target_list_new(nullptr, 0);
@ -163,8 +149,12 @@ nsClipboard::SetData(nsITransferable *aTransferable,
nsresult rv = nsresult rv =
aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors)); aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors));
if (!flavors || NS_FAILED(rv)) if (!flavors || NS_FAILED(rv)) {
// Clear references to the any old data and let GTK know that it is no
// longer available.
EmptyClipboard(aWhichClipboard);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
}
// Add all the flavors to this widget's supported type. // Add all the flavors to this widget's supported type.
bool imagesAdded = false; bool imagesAdded = false;
@ -232,8 +222,10 @@ nsClipboard::SetData(nsITransferable *aTransferable,
} }
rv = NS_OK; rv = NS_OK;
} } else {
else { // Clear references to the any old data and let GTK know that it is no
// longer available.
EmptyClipboard(aWhichClipboard);
rv = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE;
} }
@ -373,6 +365,23 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
NS_IMETHODIMP NS_IMETHODIMP
nsClipboard::EmptyClipboard(int32_t aWhichClipboard) nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
{ {
if (aWhichClipboard == kSelectionClipboard) {
if (mSelectionTransferable) {
gtk_clipboard_clear(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
MOZ_ASSERT(!mSelectionTransferable);
}
} else {
if (mGlobalTransferable) {
gtk_clipboard_clear(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
MOZ_ASSERT(!mGlobalTransferable);
}
}
return NS_OK;
}
void
nsClipboard::ClearTransferable(int32_t aWhichClipboard) {
if (aWhichClipboard == kSelectionClipboard) { if (aWhichClipboard == kSelectionClipboard) {
if (mSelectionOwner) { if (mSelectionOwner) {
mSelectionOwner->LosingOwnership(mSelectionTransferable); mSelectionOwner->LosingOwnership(mSelectionTransferable);
@ -387,8 +396,6 @@ nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
} }
mGlobalTransferable = nullptr; mGlobalTransferable = nullptr;
} }
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -652,7 +659,7 @@ nsClipboard::SelectionClearEvent(GtkClipboard *aGtkClipboard)
else else
return; // THAT AIN'T NO CLIPBOARD I EVER HEARD OF return; // THAT AIN'T NO CLIPBOARD I EVER HEARD OF
EmptyClipboard(whichClipboard); ClearTransferable(whichClipboard);
} }
void void

View file

@ -39,13 +39,12 @@ private:
static GdkAtom GetSelectionAtom (int32_t aWhichClipboard); static GdkAtom GetSelectionAtom (int32_t aWhichClipboard);
static GtkSelectionData *GetTargets (GdkAtom aWhichClipboard); static GtkSelectionData *GetTargets (GdkAtom aWhichClipboard);
// Save global clipboard content to gtk
nsresult Store (void);
// Get our hands on the correct transferable, given a specific // Get our hands on the correct transferable, given a specific
// clipboard // clipboard
nsITransferable *GetTransferable (int32_t aWhichClipboard); nsITransferable *GetTransferable (int32_t aWhichClipboard);
void ClearTransferable(int32_t aWhichClipboard);
// Hang on to our owners and transferables so we can transfer data // Hang on to our owners and transferables so we can transfer data
// when asked. // when asked.
nsCOMPtr<nsIClipboardOwner> mSelectionOwner; nsCOMPtr<nsIClipboardOwner> mSelectionOwner;