WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
200297
[GTK] Cannot disable drag-and-drop functionality with gtk_drag_source_set()/gtk_drag_source_unset() inside a WebKitWebView
https://bugs.webkit.org/show_bug.cgi?id=200297
Summary
[GTK] Cannot disable drag-and-drop functionality with gtk_drag_source_set()/g...
Jussi
Reported
2019-07-31 01:11:45 PDT
Hello, I'm trying to disable drag-and-drop functionality in a gtkmm project where I'm using WebKitGTK to render HTML pages. After creating the webview and creating a gtkmm widget out of it, as shown here: mWebView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(mWebContext)); auto webWidget = Gtk::manage(Glib::wrap(GTK_WIDGET(mWebView))); mBrowserContainer.pack_start(*webWidget, Gtk::PACK_EXPAND_WIDGET); I try to disable the drag-and-drop functionality with the respective gtkmm widget class member functions: webWidget->drag_source_unset(); webWidget->drag_dest_unset(); The "drag_dest_unset()" works as expected (
https://developer.gnome.org/gtkmm/stable/classGtk_1_1Widget.html#a0940c95059601a152db59a2fc99a2ed3
), but the "drag_source_unset()" doesn't seem to have any effect; I can still drag links and text out from the WebView. I also tried to disable the dragging with a more "hacky" way, by calling drag_source_set() webWidget->drag_source_set(std::vector<Gtk::TargetEntry>({ Gtk::TargetEntry("STRING", Gtk::TargetFlags::TARGET_SAME_WIDGET, 0) })); This should create a custom Gtk::TargetEntry list which is allowed to copy data from the widget. However, after setting this drag_source_set(), the program aborts because an assert fails in the webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context) function inside WebKitWebViewBase.cpp (
https://trac.webkit.org/browser/webkit/releases/WebKitGTK/webkit-2.25.1/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp#L1281
). Seems like calling "drag_source_set()" on a WebView nullifies some internal structure (WebKitWebViewBasePrivate->dragAndDropHandler). I also tried to connect the webWidget->signal_drag_begin() signal to a function where I would call gdk_drag_abort() for the Gdk::DragContext, but it does not seem to work on all systems. What is the proper way to disable WebView's DnD functionality from the code, if I don't compile the whole WebKitGTK library from source without the "ENABLE(DRAG_SUPPORT)" macro?
Attachments
Add attachment
proposed patch, testcase, etc.
Jussi
Comment 1
2019-07-31 03:51:55 PDT
It seems like the same thing has been asked before, and the resolution to the "bug" last time was to make WebView widget honour the gtk-dnd-drag-threshold setting which can be set inside the widget's GtkSettings struct. The old bug can be found from:
https://bugs.webkit.org/show_bug.cgi?id=64459
At least I cannot get it working with following code: Glib::RefPtr<Gtk::Settings> settings = webWidget->get_settings(); settings->property_gtk_dnd_drag_threshold() = 100000;
Michael Catanzaro
Comment 2
2019-07-31 08:52:31 PDT
(In reply to Jussi from
comment #0
)
> This should create a custom Gtk::TargetEntry list which is allowed to copy > data from the widget. However, after setting this drag_source_set(), the > program aborts because an assert fails in the > webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context) > function inside WebKitWebViewBase.cpp > (
https://trac.webkit.org/browser/webkit/releases/WebKitGTK/webkit-2.25.1/
> Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp#L1281). Seems like > calling "drag_source_set()" on a WebView nullifies some internal structure > (WebKitWebViewBasePrivate->dragAndDropHandler).
Good bug report... I guess we didn't consider that applications could use these functions. Of course using GTK public APIs shouldn't cause WebKit to crash, so we'll need to reconsider these assertions. (In reply to Jussi from
comment #1
)
> It seems like the same thing has been asked before, and the resolution to > the "bug" last time was to make WebView widget honour the > gtk-dnd-drag-threshold setting which can be set inside the widget's > GtkSettings struct. > > The old bug can be found from:
https://bugs.webkit.org/show_bug.cgi?id=64459
> > At least I cannot get it working with following code: > > Glib::RefPtr<Gtk::Settings> settings = webWidget->get_settings(); > settings->property_gtk_dnd_drag_threshold() = 100000;
Well that old patch was never committed. The bug is still open.
Jussi
Comment 3
2019-08-01 04:05:22 PDT
(In reply to Michael Catanzaro from
comment #2
)
> (In reply to Jussi from
comment #0
) > > This should create a custom Gtk::TargetEntry list which is allowed to copy > > data from the widget. However, after setting this drag_source_set(), the > > program aborts because an assert fails in the > > webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context) > > function inside WebKitWebViewBase.cpp > > (
https://trac.webkit.org/browser/webkit/releases/WebKitGTK/webkit-2.25.1/
> > Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp#L1281). Seems like > > calling "drag_source_set()" on a WebView nullifies some internal structure > > (WebKitWebViewBasePrivate->dragAndDropHandler). > > Good bug report... I guess we didn't consider that applications could use > these functions. Of course using GTK public APIs shouldn't cause WebKit to > crash, so we'll need to reconsider these assertions. >
Thanks, I was wondering whether this is a bug at all.. :-) Well, meanwhile I've come around the problem by just running the javascript code "document.addEventListener(\"dragstart\", function(evt) { evt.preventDefault(); });" after a page has loaded inside a WebView. But I would like to have a "proper" solution for the dragging issue.
> (In reply to Jussi from
comment #1
) > > It seems like the same thing has been asked before, and the resolution to > > the "bug" last time was to make WebView widget honour the > > gtk-dnd-drag-threshold setting which can be set inside the widget's > > GtkSettings struct. > > > > The old bug can be found from:
https://bugs.webkit.org/show_bug.cgi?id=64459
> > > > At least I cannot get it working with following code: > > > > Glib::RefPtr<Gtk::Settings> settings = webWidget->get_settings(); > > settings->property_gtk_dnd_drag_threshold() = 100000; > > Well that old patch was never committed. The bug is still open.
Oh, my bad. It just came up when I was searching web for others having similar problems.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug