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 13:52  |
Eclipse User |
|
|
|
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 #1235107 is a reply to message #1234996] |
Thu, 23 January 2014 10:32   |
Eclipse User |
|
|
|
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 08:26   |
Eclipse User |
|
|
|
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 05:18   |
Eclipse User |
|
|
|
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 07:17  |
Eclipse User |
|
|
|
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!
|
|
|
Goto Forum:
Current Time: Wed Jul 23 14:49:02 EDT 2025
Powered by FUDForum. Page generated in 0.05432 seconds
|