Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » keybindings and mouse events with a browser widget
keybindings and mouse events with a browser widget [message #991210] Mon, 17 December 2012 18:52 Go to next message
hanspeter hofer is currently offline hanspeter hoferFriend
Messages: 8
Registered: December 2012
Junior Member
I created a custom editor widget containing a browser widget. The problem is that I can't figure out how to get mouse or keydown events to the workbench. I want to be able to bind the save-funktion of the editor to a keydown event.

I tried to use the org.eclipse.ui.binding extension point
problem: it does not work if I have the focus on the browser widget.

I tried BrowserFunctions
problem: to save the content I have to call another BrowserFunction to fetch the content of the editor. It seems that it's not possible to call a BrowserFunction in another BrowserFunction.

I thought of firing an event via qooxdoo to force the workbench to save the open file via the command org.eclipse.ui.file.save, but I'm not sure how to do it. I can't access the the rap functions, because the browser widget is encapsulated by an iframe.

Another Problem which may be related to the iframe is the fact that the workbench doesn't receive clicks on the iframe(browser widget). For example if I create a menu via a BrowserFunction the menu does not close until I click an the menu or outside the iframe.

I would be very happy if someone could show me a solution.
Re: keybindings and mouse events with a browser widget [message #991287 is a reply to message #991210] Tue, 18 December 2012 11:00 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hi.

> I tried BrowserFunctions
> problem: to save the content I have to call another BrowserFunction to
> fetch the content of the editor. It seems that it's not possible to call
> a BrowserFunction in another BrowserFunction.

I'm not exactly sure how your custom widget works, but calling a
BrowserFunction within a BrowserFunction shouldn't be necessary. Either
send all the data you need within the first BrowserFunction (they take
multiple arguments), or (much less optimal) use Browser#evaluate to get it.

Greetings,
Tim

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: keybindings and mouse events with a browser widget [message #992440 is a reply to message #991287] Fri, 21 December 2012 16:31 Go to previous messageGo to next message
hanspeter hofer is currently offline hanspeter hoferFriend
Messages: 8
Registered: December 2012
Junior Member
Thx, I created a Browserfunction with an argument for the content of the editor and it works, but I have to specify the keybinding twice(editor + workbench).

I could not solve the menu problem though. If I create a Menu it does not close when I click on the browserwidget. Any ideas on this problem?
Re: keybindings and mouse events with a browser widget [message #997625 is a reply to message #992440] Mon, 07 January 2013 10:16 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hi.

> I could not solve the menu problem though. If I create a Menu it does
> not close when I click on the browserwidget. Any ideas on this problem?

Assuming you mean a SWT popup Menu, this is a problem that can currently
not be worked around. However, we are aware that Browser and custom
widgets may cause such issues and plan to fix this in the near future.

Greetings,
Tim


--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: keybindings and mouse events with a browser widget [message #1017304 is a reply to message #997625] Mon, 11 March 2013 14:51 Go to previous messageGo to next message
hanspeter hofer is currently offline hanspeter hoferFriend
Messages: 8
Registered: December 2012
Junior Member
As an workaround I created a BrowserFunction to set the focus as well as closing the menu if the Browser is already focused.

editorNode.addEventListener('mousedown', function(e) {
  if( e.button != 2 ){
    setFocusFunction();
  }
}, false); 
Re: keybindings and mouse events with a browser widget [message #1234589 is a reply to message #997625] Wed, 22 January 2014 10:16 Go to previous messageGo to next message
Martin Domig is currently offline Martin DomigFriend
Messages: 12
Registered: August 2010
Junior Member
I am currently having the same problem with a context menu on a browser based widget:

The workbench doesn't receive clicks on the browser widget, I have to send mouse clicks via a browser function to my widget to get the context menu to open. However, depending on the mouse position, the menu can sometimes open outside the iframe, and it won't close until I either click on the menu or outside the widget.

I cannot find a way to programmatically close the menu, or to ensure that the entire menu remains visible within the iframe. A year ago you wrote that you are planning to fix this in the near future. Is there a solution or a viable workaround available?

Thanks!
Re: keybindings and mouse events with a browser widget [message #1234668 is a reply to message #1234589] Wed, 22 January 2014 14:20 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hi.

>
> I cannot find a way to programmatically close the menu, or to ensure
> that the entire menu remains visible within the iframe. A year ago you
> wrote that you are planning to fix this in the near future. Is there a
> solution or a viable workaround available?

Sadly, no. The issue isn't as easy to resolve as I hoped, and with the
new Custom Widget API browser widgets aren't as high a priority anymore.
I think it should be possible to write a small script that catches mouse
event in an iFrame and re-dispatches them in the parent frame, but it
probably wouldn't work in all browser. The alternative would be to
disable the browser widget while the menu is open, mouse events should
then be forwarded to the parent. That's untested though.

Greetings,
Tim

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: keybindings and mouse events with a browser widget [message #1234996 is a reply to message #1234668] Thu, 23 January 2014 09:58 Go to previous messageGo to next message
Martin Domig is currently offline Martin DomigFriend
Messages: 12
Registered: August 2010
Junior Member
Im trying to do this, but don't know how to dispatch a mouse click event in javascript to the parent frame. Can you give me a hint as how to accomplish this? How can I send a mouse event?
Re: keybindings and mouse events with a browser widget [message #1235107 is a reply to message #1234996] Thu, 23 January 2014 15:32 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
In modern browser you can do it like this:

var event = document.createEvent( "MouseEvent" );
event.initMouseEvent( type,
true, // bubbles
true, //cancelable
window, //view
0, // detail
coordiantes[ 0 ], //screenX
coordiantes[ 1 ], //screenY
coordiantes[ 0 ], //clientX
coordiantes[ 1 ], //clientY
false, //ctrlKey
false, //altKey
false, //shiftKey
false, //metaKey
button, //0 = left
null );
target.dispatchEvent( event );



Am 23.01.2014 10:58, schrieb Martin Domig:
> Im trying to do this, but don't know how to dispatch a mouse click event
> in javascript to the parent frame. Can you give me a hint as how to
> accomplish this? How can I send a mouse event?

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: keybindings and mouse events with a browser widget [message #1235480 is a reply to message #1235107] Fri, 24 January 2014 13:26 Go to previous messageGo to next message
Martin Domig is currently offline Martin DomigFriend
Messages: 12
Registered: August 2010
Junior Member
I had some progress, but still some problems. dispatchEvent seems to do something to the focus, but does not actually send a mouse event.

I have this in the HTML containing my custom browser based widget:
	function dispatchToOuter(event) {
		// this code is running inside an iframe of the browser based widget.
		// window.parent.document is the container of that iframe, the
		// document that contains the browser showing our custom widget.
		// we here try to dispatch mouse events to that browser, so that we
		// can "see" them server side in java, as normal SWT mouse events.
		
		console.log('dispatching ' + event.type);
		
		// In java, the custom browser based widget sends it's ID
		// (WidgetUtil.getId(this)) to us so that we can find our browser
		// element within the parent document.

		var entry = window.parent.rwt.remote.ObjectRegistry.getEntry(widgetId);
		
		// entry is a wrapper, but we can get to the wrapped object
		// and to the div containing our browser:
		
		var target = entry.object._element.children[0];
		
		// target now is the div that contains the iframe of our custom widget.
		
		var mouseEvent = document.createEvent("MouseEvent");
		mouseEvent.initMouseEvent(event.type, true, true, target, event.detail,
				event.screenX, event.screenY, event.clientX, event.clientY,
				event.ctrlKey, event.altKey, event.shiftKey, event.metaKey,
				event.which, null);
		
		target.dispatchEvent(mouseEvent);
	}

	document.addEventListener('mousedown', function(event) {
		console.log('inner mouseDown');
		dispatchToOuter(event);
	}, true);


Now, what happens is this:

1. The click is seen by the custom widget, "inner mouseDown" is printed to the console and the event is dispatched to the target.
2. The next click is seen server side as a normal SWT mouse event, but ONLY by the server and NOT by the inner widget.
3. Goto 1

When i set the target as follows:

var target = entry.object._element; // don't use the first child (no .children[0])


I see the same behaviour, but in addition the SWT browser of my widget gets focus events:

1. First click is seen by the custom widget, "inner mouseDown" is printed to the console and the event is dispatched to the target.
2. At the next click, the SWT browser gains focus and then sees the mouse event, but no "inner mouseDown".
3. At the next click, the browser looses focus, and the "inner mouseDown" is back again.
4. Goto 2

I am thoroughly dazed and confused, and now know more about javascript than i ever cared to know (which probably is in no small part the cause of my confusion). But I seem to be able to do something that makes the SAME mouse click visible to the custom widget AND the server side SWT at the same time. I think it's very close to the solution, but I just can't see it.

Help? Please?
Re: keybindings and mouse events with a browser widget [message #1236481 is a reply to message #1235480] Mon, 27 January 2014 10:18 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Oh boy, it's also more complicated than I would have envisioned.

Okay, first of all: I'm not really comfortable with using internals. I
found a solution on stackoverflow to get the parent iframe element that
works on DOM level only:

http://stackoverflow.com/questions/935127/how-to-access-parent-iframe-from-javascript

var arrFrames = parent.document.getElementsByTagName("IFRAME");
for (var i = 0; i < arrFrames.length; i++) {
if (arrFrames[i].contentWindow === window) alert("yay!");
}

That would be the iframe itself (.children[0]), the parent is the div
you want.

It's also advisable (though probably not required) to forward not just
mousedown but also mouseup. Otherwise the framwork might get confused
about the missing event.

To me it sounds like dispatching mousedown on the parent frame takes
focus away from the iframes document, and the next click gives it back,
but is seen as a mouse event on the outer frame, not the inner. If
that's it then the solution could be to take back the focus immediately
after sending the fake mousedown. It's only a question on which element
to set the focus, either the iframe element itself or on the iframes
body (i.e. document.body.focus()) or both.

I hope this works, otherwise the solutions I could come up with would
get even more hacky.

I know it's a lot of stuff, but if we manage to get it working the
solution can be put into a small js file to be used by anyone having the
problem.

Greetings,
Tim

Am 24.01.2014 14:26, schrieb Martin Domig:
> I had some progress, but still some problems. dispatchEvent seems to do
> something to the focus, but does not actually send a mouse event.
>
> I have this in the HTML containing my custom browser based widget:
>
> function dispatchToOuter(event) {
> // this code is running inside an iframe of the browser based
> widget.
> // window.parent.document is the container of that iframe, the
> // document that contains the browser showing our custom widget.
> // we here try to dispatch mouse events to that browser, so
> that we
> // can "see" them server side in java, as normal SWT mouse events.
>
> console.log('dispatching ' + event.type);
>
> // In java, the custom browser based widget sends it's ID
> // (WidgetUtil.getId(this)) to us so that we can find our browser
> // element within the parent document.
>
> var entry =
> window.parent.rwt.remote.ObjectRegistry.getEntry(widgetId);
>
> // entry is a wrapper, but we can get to the wrapped object
> // and to the div containing our browser:
>
> var target = entry.object._element.children[0];
>
> // target now is the div that contains the iframe of our custom
> widget.
>
> var mouseEvent = document.createEvent("MouseEvent");
> mouseEvent.initMouseEvent(event.type, true, true, target,
> event.detail,
> event.screenX, event.screenY, event.clientX,
> event.clientY,
> event.ctrlKey, event.altKey, event.shiftKey,
> event.metaKey,
> event.which, null);
>
> target.dispatchEvent(mouseEvent);
> }
>
> document.addEventListener('mousedown', function(event) {
> console.log('inner mouseDown');
> dispatchToOuter(event);
> }, true);
>
>
> Now, what happens is this:
>
> 1. The click is seen by the custom widget, "inner mouseDown" is printed
> to the console and the event is dispatched to the target.
> 2. The next click is seen server side as a normal SWT mouse event, but
> ONLY by the server and NOT by the inner widget.
> 3. Goto 1
>
> When i set the target as follows:
>
>
> var target = entry.object._element; // don't use the first child (no
> .children[0])
>
>
> I see the same behaviour, but in addition the SWT browser of my widget
> gets focus events:
>
> 1. First click is seen by the custom widget, "inner mouseDown" is
> printed to the console and the event is dispatched to the target.
> 2. At the next click, the SWT browser gains focus and then sees the
> mouse event, but no "inner mouseDown".
> 3. At the next click, the browser looses focus, and the "inner
> mouseDown" is back again.
> 4. Goto 2
>
> I am thoroughly dazed and confused, and now know more about javascript
> than i ever cared to know (which probably is in no small part the cause
> of my confusion). But I seem to be able to do something that makes the
> SAME mouse click visible to the custom widget AND the server side SWT at
> the same time. I think it's very close to the solution, but I just can't
> see it.
>
> Help? Please?

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: keybindings and mouse events with a browser widget [message #1240422 is a reply to message #1236481] Thu, 06 February 2014 12:17 Go to previous message
Martin Domig is currently offline Martin DomigFriend
Messages: 12
Registered: August 2010
Junior Member
Just for your information (and anyone finding this on google): I've given up on the browser based widget and created a custom widget with the remote API. For the time being, I guess that having both a browser based widget /and/ SWT mouse events doesn't really work.

Thank you for your help!
Previous Topic:Application beforeDestroy() never gets called during browser close
Next Topic:Overlays via custom widget?
Goto Forum:
  


Current Time: Fri Apr 19 10:13:38 GMT 2024

Powered by FUDForum. Page generated in 0.03150 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top