Bug 55351 - [browser] link hover listener
Summary: [browser] link hover listener
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC All
: P3 enhancement with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact: Grant Gayed CLA
URL:
Whiteboard:
Keywords: helpwanted, triaged
Depends on:
Blocks:
 
Reported: 2004-03-19 07:25 EST by Sebastian Davids CLA
Modified: 2018-07-10 14:12 EDT (History)
10 users (show)

See Also:


Attachments
experiment - use javascript to catch DOM events and emit fake SWT LocationEvent's (418 bytes, text/html)
2004-04-05 13:10 EDT, Christophe Cornu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Davids CLA 2004-03-19 07:25:47 EST
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.
Comment 1 Tod Creasey CLA 2004-03-19 11:37:46 EST
Are you referring to the HTML widget?
Comment 2 Sebastian Davids CLA 2004-03-19 12:03:34 EST
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");
	}
}
Comment 3 Benjamin Pasero CLA 2004-04-03 05:01:34 EST
Hi,
I am eagerly awaiting this feature.
Any chance of getting it into the next Milestone 9?
Best regards,
Ben 
Comment 4 Channing Walton CLA 2004-04-04 07:31:56 EDT
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
Comment 5 Christophe Cornu CLA 2004-04-05 13:09:41 EDT
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();
	}

}


Comment 6 Christophe Cornu CLA 2004-04-05 13:10:44 EDT
Created attachment 9223 [details]
experiment - use javascript to catch DOM events and emit fake SWT LocationEvent's
Comment 7 Benjamin Pasero CLA 2004-04-05 14:21:29 EDT
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 
Comment 8 Christophe Cornu CLA 2004-04-05 15:36:49 EDT
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.
Comment 9 Benjamin Pasero CLA 2004-04-06 02:14:37 EDT
Thanks Christophe, that is exactly what I was searching for!
Nevertheless a LinkListener would also be very usefull :).
Comment 10 Sebastian Davids CLA 2004-04-06 05:18:09 EDT
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.
Comment 11 Channing Walton CLA 2004-08-30 17:28:16 EDT
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
Comment 12 Channing Walton CLA 2004-09-25 16:45:13 EDT
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
Comment 13 David Thomson CLA 2005-04-11 18:08:14 EDT
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
Comment 14 Dani Megert CLA 2006-06-29 03:56:12 EDT
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.
Comment 15 Grant Gayed CLA 2009-08-27 14:43:31 EDT
Moving report to triage, see http://www.eclipse.org/swt/triage.php
for swt bug handling process.
Comment 16 Leo Ufimtsev CLA 2017-06-27 10:14:22 EDT
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.