Detect when mouse is over a URL?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Detect when mouse is over a URL?

Postby rjxray » Tue Jun 21, 2022 3:28 am

Is it possible to know when the mouse is hovered over a URL link, and to get the text of the URL?
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Detect when mouse is over a URL?

Postby Staxcelrom » Tue Jun 21, 2022 3:36 am

rjxray wrote:Is it possible to know when the mouse is hovered over a URL link, and to get the text of the URL?


Theoretically, you can request an HTML file and parse it by finding the required URL address.

HTML can be queried through the GetSource() function: https://github.com/chromiumembedded/cef/blob/master/include/cef_frame.h
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: Detect when mouse is over a URL?

Postby rjxray » Tue Jun 21, 2022 4:26 am

Thanks for the suggestion, I might be able to make it work although it would be a bit cumbersome.

The background to my question is that we have an off screen canvas with multiple browsers.
We want to allow the user to click and drag any URL link on a browser's render to our widget which will create a new browser by splitting or replacing an existing one
I do see the cursor type changing to CT_HAND when moving over a link.
So I guess I could grab and somehow check the HTML for the current cursor position when I get the mouse button down event if the current cursor is CT_HAND
It would be good if there was an easier way though!
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Detect when mouse is over a URL?

Postby Staxcelrom » Tue Jun 21, 2022 4:47 am

rjxray wrote:Thanks for the suggestion, I might be able to make it work although it would be a bit cumbersome.

The background to my question is that we have an off screen canvas with multiple browsers.
We want to allow the user to click and drag any URL link on a browser's render to our widget which will create a new browser by splitting or replacing an existing one
I do see the cursor type changing to CT_HAND when moving over a link.
So I guess I could grab and somehow check the HTML for the current cursor position when I get the mouse button down event if the current cursor is CT_HAND
It would be good if there was an easier way though!


I'm not exactly sure, I haven't tried it, but maybe you need this: https://github.com/chromiumembedded/cef/blob/master/include/cef_drag_data.h

//Return the link URL that is being dragged.
virtual CefString GetLinkURL() = 0;
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: Detect when mouse is over a URL?

Postby rjxray » Tue Jun 21, 2022 4:50 am

Looks ideal, I'll try it out. Thanks
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Detect when mouse is over a URL?

Postby rjxray » Wed Jun 22, 2022 3:19 am

After looking through cefclient I added this method to my OSR render handler
Code: Select all
bool CEFRenderHandler::StartDragging(CefRefPtr<CefBrowser> browser,
   CefRefPtr<CefDragData> drag_data,
   CefRenderHandler::DragOperationsMask allowed_ops,
   int x,
   int y) {
   current_drag_data_ = drag_data->Clone();
   cout << "OnDragEnter called" << endl;
   if (current_drag_data_->IsLink()) {
      cout << "data is a link to " << current_drag_data_->GetLinkURL() << endl;
   }
   return DRAG_OPERATION_NONE;
}

Now when I start dragging a link on the page I see OnDragEnter being called with the link address.
That's all I need from CEF and I can take it from there.
Thanks again
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 27 guests