=== modified file 'src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java' --- src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java 2015-12-08 16:52:30 +0000 @@ -28,6 +28,8 @@ ** 014 CA 20150821 Added raiseMouseEvent, setWindowLocation, windowActivated - no-ops. ** 015 CA 20150925 Fixed mouse entry/exit: explicit source is passed to the MouseEvt. ** 016 CA 20151013 Added support for window resize for the GUI web client. +** 017 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and +** a mouse modifiers mask for all mouse events. */ package com.goldencode.p2j.ui.client.chui.driver.web; @@ -163,21 +165,26 @@ * The button which was pressed. * @param clickCount * The click count. - * @param wheelRotation - * The wheel rotation, if this is a wheel event. + * @param modifiersMask + * The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds + * to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and + * the 3-bit to the alt key. + * @param wheelParameters + * The array that represents the wheel rotation amount and its unit. * @param widgetId * The explicit widget ID to which this event needs to be posted. */ @Override - public void raiseMouseEvent(int windowId, - int mouseOp, - long tstamp, - int mouseX, - int mouseY, - int button, - int clickCount, - int wheelRotation, - int widgetId) + public void raiseMouseEvent(int windowId, + int mouseOp, + long tstamp, + int mouseX, + int mouseY, + int button, + int clickCount, + int modifiersMask, + int[] wheelParameters, + int widgetId) { // no-op } === modified file 'src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java' --- src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java 2015-12-08 16:51:53 +0000 @@ -13,6 +13,8 @@ ** 002 CA 20150821 Added raiseMouseEvent, setWindowLocation, windowActivated. ** 003 CA 20150925 Fixed mouse entry/exit: explicit source is passed to the MouseEvt. ** 004 CA 20151013 Added support for window resize for the GUI web client. +** 005 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and +** a mouse modifiers mask for all mouse events. */ package com.goldencode.p2j.ui.client.driver.web; @@ -53,20 +55,25 @@ * The button which was pressed. * @param clickCount * The click count. - * @param wheelRotation - * The wheel rotation, if this is a wheel event. + * @param modifiersMask + * The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds + * to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and + * the 3-bit to the alt key. + * @param wheelParameters + * The array that represents the wheel rotation amount and its unit. * @param widgetId * The explicit widget ID to which this event needs to be posted. */ - public void raiseMouseEvent(int windowId, - int mouseOp, - long tstamp, - int mouseX, - int mouseY, - int button, - int clickCount, - int wheelRotation, - int widgetId); + public void raiseMouseEvent(int windowId, + int mouseOp, + long tstamp, + int mouseX, + int mouseY, + int button, + int clickCount, + int mofifiersMask, + int[] wheelParameters, + int widgetId); /** * Set the location for the specified window. === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2015-12-01 13:37:14 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2015-12-08 16:49:19 +0000 @@ -36,6 +36,8 @@ ** SBI 20151201 Changed to provide processMouseWidgets with calculated widgets bounds, added ** the special EditorGuiImpl case to consider its dimension as its viewport size ** in order to fix a mouse cursor type over its scroll bars. +** 011 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and +** a mouse modifiers mask for all mouse events. */ package com.goldencode.p2j.ui.client.gui.driver.web; @@ -698,30 +700,39 @@ * The button which was pressed. * @param clickCount * The click count. - * @param wheelRotation - * The wheel rotation, if this is a wheel event. + * @param modifiersMask + * The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds + * to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and + * the 3-bit to the alt key. + * @param wheelParameters + * The array that represents the wheel rotation amount and its unit. * @param widgetId * The explicit widget ID to which this event needs to be posted. */ @Override - public void raiseMouseEvent(int windowId, - int mouseOp, - long tstamp, - int mouseX, - int mouseY, - int button, - int clickCount, - int wheelRotation, - int widgetId) + public void raiseMouseEvent(int windowId, + int mouseOp, + long tstamp, + int mouseX, + int mouseY, + int button, + int clickCount, + int modifiersMask, + int[] wheelParameters, + int widgetId) { MouseOps mop = MouseOps.fromCode(mouseOp); - int modifiers = 0; + int modifiers = getMouseModifiers(button, modifiersMask); MouseEvent event; if (mop.isWheel()) { - // TODO: do modifiers ever need to be non-zero here? + int unit = MouseWheelEvent.WHEEL_UNIT_SCROLL; + if (wheelParameters[1] == 2) + { + unit = MouseWheelEvent.WHEEL_BLOCK_SCROLL; + } event = new MouseWheelEvent(BOGUS_AWT_COMPONENT, mop.awtEventCode, tstamp, @@ -732,31 +743,12 @@ mouseY, clickCount, false, - MouseWheelEvent.WHEEL_BLOCK_SCROLL, - 0, - wheelRotation); + unit, + Math.abs(wheelParameters[0]), + (wheelParameters[0] > 0) ? 1 : -1); } else { - // button codes from JS (same as from AWT) - // 0 : No button - // 1 : Left mouse button - // 2 : Wheel button or middle button (if present) - // 3 : Right mouse button - switch (button) - { - case 1: - modifiers = InputEvent.BUTTON1_MASK; - break; - case 2: - modifiers = InputEvent.BUTTON2_MASK; - break; - case 3: - modifiers = InputEvent.BUTTON3_MASK; - break; - default: - } - event = new MouseEvent(BOGUS_AWT_COMPONENT, mop.awtEventCode, tstamp, @@ -773,6 +765,59 @@ EmulatedWindowState window = direct.getWindowEmulator(windowId); ((WebMouseHandler) window.getMouseHandler()).raiseMouseEvent(event, widgetId); } + + /** + * Gets the mouse modifiers mask for this event. + * + * @param button + * The mouse button that is currently pressed + * @param modifiersMask + * The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds + * to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and + * the 3-bit to the alt key. + * + * @return The key's modifiers bit mask for this mouse event. + */ + private int getMouseModifiers(int button, int modifiersMask) + { + int modifiers = 0; + // button codes from JS (same as from AWT) + // 0 : No button + // 1 : Left mouse button + // 2 : Wheel button or middle button (if present) + // 3 : Right mouse button + switch (button) + { + case 1: + modifiers = InputEvent.BUTTON1_MASK; + break; + case 2: + modifiers = InputEvent.BUTTON2_MASK; + break; + case 3: + modifiers = InputEvent.BUTTON3_MASK; + break; + default: + } + if ((modifiersMask & MouseEvent.SHIFT_MASK) != 0) + { + modifiers |= MouseEvent.SHIFT_DOWN_MASK; + } + if ((modifiersMask & MouseEvent.CTRL_MASK) != 0) + { + modifiers |= MouseEvent.CTRL_DOWN_MASK; + } + if ((modifiersMask & MouseEvent.META_MASK) != 0) + { + modifiers |= MouseEvent.META_DOWN_MASK; + } + if ((modifiersMask & MouseEvent.ALT_MASK) != 0) + { + modifiers |= MouseEvent.ALT_DOWN_MASK; + } + + return modifiers; + } /** * Set the location for the specified window. === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2015-12-01 13:37:14 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2015-12-08 16:50:48 +0000 @@ -31,6 +31,8 @@ ** the same batch more than once, it will collide and it will not preserve the ** message result. ** SBI 20151201 Changed to provide processMouseWidgets with calculated widgets bounds. +** 010 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and +** a mouse modifiers mask for all mouse events. */ package com.goldencode.p2j.ui.client.gui.driver.web; @@ -1117,7 +1119,8 @@ receiveResult(msgId, new Object()); handled = true; } - else if ((length == 21 || length == 25) && message[offset] == MSG_MOUSE_EVENT) + else if ((length == 21 || length == 25 || length == 23 || length == 27) && + message[offset] == MSG_MOUSE_EVENT) { int idx = offset + 1; @@ -1142,11 +1145,21 @@ int button = message[idx]; idx = idx + 1; - int wheelRotation = message[idx]; + int modifiersMask = message[idx]; idx = idx + 1; + + int[] wheelParameters = null; + if (length == 23 || length == 27) + { + int delta = message[idx]; + idx = idx + 1; + int unit = message[idx]; + idx = idx + 1; + wheelParameters = new int[] { delta, unit}; + } int wid = -1; - if (length == 25) + if (length == 25 || length == 27) { wid = readMessageInt32(message, idx); idx = idx + 4; @@ -1159,7 +1172,8 @@ mouseY, button, clickCount, - wheelRotation, + modifiersMask, + wheelParameters, wid); handled = true; === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2015-12-01 22:44:33 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2015-12-08 16:49:50 +0000 @@ -30,6 +30,8 @@ ** sendMouseEvent invocations. ** 008 SBI 20151124 Fixed cleanup() to remove the corresponding window canvas from DOM. ** SBI 20151201 Fixed two times clicks for menus. +** 009 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and +** a mouse modifiers mask for all mouse events. */ "use strict"; @@ -1265,8 +1267,8 @@ Window.prototype.sendMouseEvent = function(evt, mousePos, wThis, opCode, wid) { var widLength = (wid == undefined ? 0 : 4); - // TODO: CA: ALT/SHIFT modifiers? - var message = new Uint8Array(21 + widLength); + var wheelEvent = (evt.deltaMode !== undefined); + var message = new Uint8Array(21 + widLength + (wheelEvent ? 2 : 0)); var offset = 0; @@ -1301,19 +1303,20 @@ message[offset] = evt.which; offset = offset + 1; - // 6. wheel rotation (neg/poz, depending on direction): TODO: CA - var direction = 0; -// if (evt.deltaX !== undefined && evt.deltaX != 0) -// { -// direction = evt.deltaX; -// } -// else if (evt.deltaY !== undefined && evt.deltaY != 0) -// { -// direction = evt.deltaY; -// } - message[offset] = direction; + // 6. modifier bitmask + message[offset] = getModifiersBitMask(evt); offset = offset + 1; + if (wheelEvent) + { + // 7. wheel rotation (neg/poz, depending on direction) + message[offset] = getScrollAmountDelta(evt); + offset = offset + 1; + // 8. amount unit + message[offset] = getScrollAmountUnit(evt); + offset = offset + 1; + } + if (wid != undefined) { p2j.socket.writeInt32BinaryMessage(message, offset, wid); @@ -1329,6 +1332,85 @@ } /** + * Returns the bit mask that represents the current modifier keys are pressed during this + * mouse event occured. + * + * @param {Event} evt + * The mouse event. + * + * @return The keys modifier mask that represents which of the modifier keys are down. + * If 0, 1, 2, or 3-bit is set, then respectivelly the shift, the ctrl, the meta or + * the alt key is pressed. + */ + function getModifiersBitMask(evt) + { + var modifiers = 0; + if (evt.shiftKey !== undefined && evt.shiftKey) + { + modifiers |= 1; + } + if (evt.ctrlKey !== undefined && evt.ctrlKey) + { + modifiers |= 2; + } + if (evt.metaKey !== undefined && evt.metaKey) + { + modifiers |= 4; + } + if (evt.altKey !== undefined && evt.altKey) + { + modifiers |= 8; + } + + return modifiers; + } + + /** + * Returns the scroll amount unit given by deltaMode. The valid values are 0x00, 0x01 and 0x02. + * 0x00 deltaMode indicates that the delta values are specified in pixels. + * 0x01 deltaMode indicates that the delta values are specified in lines. + * 0x02 deltaMode indicates that the delta values are specified in pages. + * + * @param {Event} evt + * The mouse event. + * + * @return The scroll amount unit. + */ + function getScrollAmountUnit(evt) + { + var unit = 0; + if (evt.deltaMode !== undefined) + { + unit = evt.deltaMode; + } + + return unit; + } + + /** + * Returns the scroll amount along the direction axis. + * + * @param {Event} evt + * The mouse event. + * + * @return The scroll amount. + */ + function getScrollAmountDelta(evt) + { + var direction = 0; + if (evt.deltaX !== undefined && evt.deltaX != 0) + { + direction = evt.deltaX; + } + else if (evt.deltaY !== undefined && evt.deltaY != 0) + { + direction = evt.deltaY; + } + + return direction; + } + + /** * Move the window to top, in z-order. */ Window.prototype.moveToTop = function()