OutSystems / WebView

Avalonia/WPF control that wraps CefGlue webview control
Apache License 2.0
310 stars 38 forks source link

Change cursor type over links #306

Closed arnirichard closed 1 year ago

arnirichard commented 1 year ago

How do I change cursor type to Hand over links, something like

private void WebView_PointerMoved(object? sender, PointerEventArgs e)
{
      Point position = e.GetPosition(webView);

      // Check if the pointer is over a link
       if (webView.InputHitTest(position) is WebViewHitTestResult result && result.ElementType == WebViewElementType.Link)
       {
          // Change the cursor to a hand pointer
           webView.Cursor = new Cursor(StandardCursorType.Hand);
       }
      else
      {
           // Reset the cursor to the default
           webView.Cursor = new Cursor(StandardCursorType.Arrow);
      }
}
joaompneves commented 1 year ago

Hi,

You better use CSS for that. Hit-testing wont work on the browser as it is a completely different environment, which Avalonia doesn't know about.

arnirichard commented 1 year ago

Ok, I tried to add cursor: pointer; style to all tags. But it does not seem to work.

joaompneves commented 1 year ago

Did you tried on this sample app?

arnirichard commented 1 year ago

Yes, it works there even on the same html file. I am on Avalonia 0.10.18 and WebViewControl-Avalonia 2.106.7. I am unable to see any major differences between the projects.

joaompneves commented 1 year ago

Set OSR = false? https://github.com/OutSystems/WebView/blob/master/SampleWebView.Avalonia/MainWindow.xaml.cs#L10

arnirichard commented 1 year ago

I am getting

System.InvalidOperationException: 'Cannot set OsrEnabled after WebView engine has been loaded'

I have added a very simple project with the html file included.

webmailtest.zip

arnirichard commented 1 year ago

Just to add, when I load the above project, the hand cursor is not visible over links. However, in the sample app it works.

joaompneves commented 1 year ago

Setting OSR need to be one of the first things you do in your app

arnirichard commented 1 year ago

Thanks, I also add to add app.manifest. It works now.

arnirichard commented 1 year ago

Closing