HTMLViewer to NOT accept file drop?

Is there a way to get HTMLViewer to not accept a file drop?
I’ve checked the docs and even AcceptFileDrop but there doesn’t seem to be a way to turn it off.

I’ve made a project, with zero code, that shows the HTML Viewer just wants to eat anything you drop on it.

Solved by returning true in DragEnter.

Now is this by design that the HTML Viewer defaults to accepting file drops?

EDIT: Not solved in my main project, only in the demonstration project…

This is a longstanding bug:
<https://xojo.com/issue/16087>
<https://xojo.com/issue/33226>

The latter bug report has a JavaScript workaround (courtesy of Shao Shen) that may work for you, depending on what you’re using an HTMLViewer for:

[quote]Place this code in the DocumentComplete event and it will disable drop, but keep in mind that this will also disable and drop feature in the site…

me.ExecuteJavaScript "document.addEventListener('dragover', function(event){event.preventDefault();}, false);" me.ExecuteJavaScript "document.addEventListener('dragenter', function(event){event.preventDefault();}, false);" me.ExecuteJavaScript "document.addEventListener('drop', function(event){event.preventDefault();}, false);" [/quote]

Seems to be by design : all browsers accept file drop.

[quote=108868:@Walter Purvis]This is a longstanding bug:
<https://xojo.com/issue/16087>
<https://xojo.com/issue/33226>

The latter bug report has a JavaScript workaround (courtesy of Shao Shen) that may work for you, depending on what you’re using an HTMLViewer for:[/quote]

It works fine.

Another trick that works on Mac is to lay a canvas over the HTMLViewer, with in the open event of the canvas Me.FileDrop("").

It’s a preview, not a web browser - so file drops are not desired.
If allowing them by default is a thing, then there needs to be a way to disable it.

There are plenty of workarounds that seem to work, but my main problem now is that I can’t get the cursor to behave and stay StandardPointer.

[quote=108882:@Tim Parnell]my main problem now is that I can’t get the cursor to behave and stay StandardPointer.

[/quote]

The canvas overlay does just that.

Return ‘True’ on the CancelLoad event if it looks like ‘file://’ or similar.

Phillip, I was already doing (a modified version of) that because it’s a preview of files rather than being a web browser. I tried modifying (or rather preventing from changing) the mousecursor with the DragEnter on the HTMLViewer, but had no success.

Michel’s method of overlaying a canvas to intercept worked perfectly, thank you Michel.

So the overlay was working great until I noticed it interrupts whatever internals work for :hover events on the html page.
I looked at MouseMove but it doesn’t return true or false, so I can’t pass it through by that method.

Is there a method to work with that?
I’m near the point of not even bothering with covering up the copy cursor.

Declares may be useful
Will depend on native or not and which platform but they can be helpful
Not sure any will let you say which mouse pointer to use or block drag & drop but …….

[quote=109261:@Tim Parnell]So the overlay was working great until I noticed it interrupts whatever internals work for :hover events on the html page.
I looked at MouseMove but it doesn’t return true or false, so I can’t pass it through by that method.

Is there a method to work with that?
I’m near the point of not even bothering with covering up the copy cursor.[/quote]

I suspect the overlay indeed blocks the MouseOver from the HTMLViewer, which is why the cursor does not change.

If you can live with the finger pointer, blocking the drop through JavaScript is a good method.

Do you need this cross-platform or for just a single platform? Are you using “native” or “WebKit” as the renderer?

Mac and Windows. I’m using native because the extra 20mb isn’t really worth it for how little of a role the HTML Viewer plays in this app. I’m okay with just ignoring the drop, there’s too much needed to make it go away.

Does this behavior affect Windows too?

Also, I thought I’d be clever and send the drop action to the proper place just in case, but there’s no drop for HTMLViewer >_>

[quote=109830:@Tim Parnell]Mac and Windows. I’m using native because the extra 20mb isn’t really worth it for how little of a role the HTML Viewer plays in this app. I’m okay with just ignoring the drop, there’s too much needed to make it go away.

Does this behavior affect Windows too?
[/quote]

The overlay does not work in Windows, it blocks all events. The best course of action is the JavaScript, which works fine on both platforms. Not that long ago a member wanted to prevent drop as well and did that successfully for Windows. Unfortunately, I could not find the thread.

You can always just inject in JavaScript and handle the drop in there, which is what I do in my app which makes heavy use of HTMLViewer (WebKit renderer though)…