Community
Participate
Working Groups
I'm not sure if the native browsers support this, but a LinkListener would be appreciated. It should support: - link clicked - mouse hover in - mouse hover out The corresponding event would have the URL (or URL as String) as one of its fields.
Are you referring to the HTML widget?
Yes. Something along the lines: public interface LinkListener extends SWTEventListener { void hoverIn(LinkEvent e); void hoverOut(LinkEvent e); void clicked(LinkEvent e); } public class LinkEvent extends TypedEvent { public String url; //the href part public String label; //the text contained in <a ...>Text</a> LinkEvent(Widget w) { super(w); } } @@@@ Browser browser = new Browser(parent, SWT.NONE); fBrowser.addLinkListener(new LinkListener() { public void hoverIn(LinkEvent e) { System.out.println("now hovering over " + e.label + "with the URL " + e.url); } public void hoverOut(LinkEvent e) { System.out.println("not hovering over " + e.label + " anymore"); } public void clicked(LinkEvent e) { System.out.println("link " e.label + "with the URL " + e.url + " clicked"); } }
Hi, I am eagerly awaiting this feature. Any chance of getting it into the next Milestone 9? Best regards, Ben
I need this too - I'm having to use FormText for now since it has HyperLinkListener support. I will not be able to use the SWT Browser if it doesn't allow me to manage the hyperlinks myself. Channing
Hi, For 3.0, the first release of the SWT Browser widget provides a means to handle hyperlink activation but not the hover in/hover out detection on the java side (you can use javascript on the html side to detect it). The API you request is similar to what the DOM event API provides, and I have opened bug 57477 relative to DOM support. As you know, the Browser widget provides the LocationListener notification. This notification is meant to refresh the Address field in a Browser and provides some basic URL filtering. It can be used to detect and capture (cancel/redirect) a URL loading triggered when the user activates a hyperlink. If you need more details on how to do this let me know (also check the javadoc for LocationListener). That's the level of functionality you can expect for 3.0. If you want to experiment, you can try the code below. It is a hack, using taking advantage of javascript to access the DOM and then fire custom LocationListener.changing events your application can catch. See the HTML file attached. import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.browser.*; public class PR55351 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Main Window"); shell.setLayout(new FillLayout()); Browser browser = new Browser(shell, SWT.NONE); browser.addLocationListener(new LocationListener() { public void changed(LocationEvent event) { } public void changing(LocationEvent event) { System.out.println ("LocationListener.changing "+event.location); event.doit = event.location.indexOf("onMouse") == -1; } }); shell.open(); browser.setUrl("D:/workspace/java_chris/src/html/55351.html"); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
Created attachment 9223 [details] experiment - use javascript to catch DOM events and emit fake SWT LocationEvent's
Hi Christophe, talking from my side, the most important thing is to be able to catch the click on a link and to perform an action before the browser is loading the clicked link. This includes stopping the loading and for example passing the URL to an external browser to have the link opened outside the SWT application. I was already playing around with the LocationListener to catch the selection of a link. This works as it should, but I was not able to stop() the browser, once the the link was selected. Ben
Hi Benjamin, You are almost there. Simply set the LocationEvent.doit field to false if you decide not to load this new location - inside the LocationListener.changing notification.
Thanks Christophe, that is exactly what I was searching for! Nevertheless a LinkListener would also be very usefull :).
Tried the code from comment 5. It might be useful for clients having full control of their HTML (e.g. if one does not use Eclipse based help). But it doesn't do for "general" browsing.
Hi, I believe there may be a bug with events sent to LocationListener.changing(LocationEvent) (on OS X at least). An event is sent for the URL about to be loaded and each of the resources the url requires (images etc). e.g. when setting the url to http://www.google.com/ three events are fired with locations: http://www.google.com/ http://www.google.com/images/logo.gif http://www.google.com/favicon.ico
Hi, On OS X, I've found that if LocationEvent.doit is set to false, the browser's cursor is left as a busy cursor but I think it should be reset to the pointer. Channing
Perhaps this project might help: http://justthe.net/jrex/ While I should probably make a feature request to get something like this fully supported, it might give some ideas about how to handle events when dealing with an embedded browser. BTW, the URL for the main project is jrex.mozdev.org. This is duplicated at bug #49696. David
We need to provide rich hovers for our links. For this we need some sort of hover event as outlined in comment 2. We know we can use the TITLE attribute but this is not enough since we want to provide more than just text hovers and we'd like to compute the hover information lazy and not upfront. The Javascript path is also not a good idea because if a users has this turned off our hovers won't work.
Moving report to triage, see http://www.eclipse.org/swt/triage.php for swt bug handling process.
The closest thing to linkListener at the moment is the statusText listener, which fires when you hover a mouse over a link. But it would be nice to have a dedicated LinkListener also.