Project

General

Profile

mouse_wheel_1.txt

Sergey Ivanovskiy, 12/08/2015 11:56 AM

Download (17.4 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java'
2
--- src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java	2015-10-13 17:07:58 +0000
3
+++ src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java	2015-12-08 16:52:30 +0000
4
@@ -28,6 +28,8 @@
5
 ** 014 CA  20150821 Added raiseMouseEvent, setWindowLocation, windowActivated - no-ops.
6
 ** 015 CA  20150925 Fixed mouse entry/exit: explicit source is passed to the MouseEvt.
7
 ** 016 CA  20151013 Added support for window resize for the GUI web client.
8
+** 017 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and
9
+**                  a mouse modifiers mask for all mouse events.
10
 */
11
 
12
 package com.goldencode.p2j.ui.client.chui.driver.web;
13
@@ -163,21 +165,26 @@
14
     *           The button which was pressed.
15
     * @param    clickCount
16
     *           The click count.
17
-    * @param    wheelRotation
18
-    *           The wheel rotation, if this is a wheel event.
19
+    * @param    modifiersMask
20
+    *           The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds
21
+    *           to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and
22
+    *           the 3-bit to the alt key.
23
+    * @param    wheelParameters
24
+    *           The array that represents the wheel rotation amount and its unit.
25
     * @param    widgetId
26
     *           The explicit widget ID to which this event needs to be posted.
27
     */
28
    @Override
29
-   public void raiseMouseEvent(int  windowId,
30
-                               int  mouseOp, 
31
-                               long tstamp, 
32
-                               int  mouseX, 
33
-                               int  mouseY,
34
-                               int  button, 
35
-                               int  clickCount, 
36
-                               int  wheelRotation,
37
-                               int  widgetId)
38
+   public void raiseMouseEvent(int   windowId,
39
+                               int   mouseOp, 
40
+                               long  tstamp, 
41
+                               int   mouseX, 
42
+                               int   mouseY,
43
+                               int   button, 
44
+                               int   clickCount, 
45
+                               int   modifiersMask,
46
+                               int[] wheelParameters,
47
+                               int   widgetId)
48
    {
49
       // no-op
50
    }
51

    
52
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java'
53
--- src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java	2015-10-13 17:07:58 +0000
54
+++ src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java	2015-12-08 16:51:53 +0000
55
@@ -13,6 +13,8 @@
56
 ** 002 CA  20150821 Added raiseMouseEvent, setWindowLocation, windowActivated.
57
 ** 003 CA  20150925 Fixed mouse entry/exit: explicit source is passed to the MouseEvt.
58
 ** 004 CA  20151013 Added support for window resize for the GUI web client.
59
+** 005 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and
60
+**                  a mouse modifiers mask for all mouse events.
61
 */
62
 
63
 package com.goldencode.p2j.ui.client.driver.web;
64
@@ -53,20 +55,25 @@
65
     *           The button which was pressed.
66
     * @param    clickCount
67
     *           The click count.
68
-    * @param    wheelRotation
69
-    *           The wheel rotation, if this is a wheel event.
70
+    * @param    modifiersMask
71
+    *           The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds
72
+    *           to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and
73
+    *           the 3-bit to the alt key.
74
+    * @param    wheelParameters
75
+    *           The array that represents the wheel rotation amount and its unit.
76
     * @param    widgetId
77
     *           The explicit widget ID to which this event needs to be posted.
78
     */
79
-   public void raiseMouseEvent(int  windowId,
80
-                               int  mouseOp, 
81
-                               long tstamp, 
82
-                               int  mouseX, 
83
-                               int  mouseY,
84
-                               int  button,
85
-                               int  clickCount, 
86
-                               int  wheelRotation,
87
-                               int  widgetId);
88
+   public void raiseMouseEvent(int   windowId,
89
+                               int   mouseOp, 
90
+                               long  tstamp, 
91
+                               int   mouseX, 
92
+                               int   mouseY,
93
+                               int   button,
94
+                               int   clickCount, 
95
+                               int   mofifiersMask,
96
+                               int[] wheelParameters,
97
+                               int   widgetId);
98
 
99
    /**
100
     * Set the location for the specified window.
101

    
102
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java'
103
--- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java	2015-12-01 13:37:14 +0000
104
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java	2015-12-08 16:49:19 +0000
105
@@ -36,6 +36,8 @@
106
 **     SBI 20151201 Changed to provide processMouseWidgets with calculated widgets bounds, added
107
 **                  the special EditorGuiImpl case to consider its dimension as its viewport size
108
 **                  in order to fix a mouse cursor type over its scroll bars.
109
+** 011 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and
110
+**                  a mouse modifiers mask for all mouse events.
111
 */
112
 
113
 package com.goldencode.p2j.ui.client.gui.driver.web;
114
@@ -698,30 +700,39 @@
115
     *           The button which was pressed.
116
     * @param    clickCount
117
     *           The click count.
118
-    * @param    wheelRotation
119
-    *           The wheel rotation, if this is a wheel event.
120
+    * @param    modifiersMask
121
+    *           The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds
122
+    *           to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and
123
+    *           the 3-bit to the alt key.
124
+    * @param    wheelParameters
125
+    *           The array that represents the wheel rotation amount and its unit.
126
     * @param    widgetId
127
     *           The explicit widget ID to which this event needs to be posted.
128
     */
129
    @Override
130
-   public void raiseMouseEvent(int  windowId,
131
-                               int  mouseOp, 
132
-                               long tstamp, 
133
-                               int  mouseX, 
134
-                               int  mouseY, 
135
-                               int  button,
136
-                               int  clickCount, 
137
-                               int  wheelRotation,
138
-                               int  widgetId)
139
+   public void raiseMouseEvent(int   windowId,
140
+                               int   mouseOp, 
141
+                               long  tstamp, 
142
+                               int   mouseX, 
143
+                               int   mouseY, 
144
+                               int   button,
145
+                               int   clickCount, 
146
+                               int   modifiersMask,
147
+                               int[] wheelParameters,
148
+                               int   widgetId)
149
    {
150
       MouseOps mop = MouseOps.fromCode(mouseOp);
151
       
152
-      int modifiers = 0;
153
+      int modifiers = getMouseModifiers(button, modifiersMask);
154
       
155
       MouseEvent event;
156
       if (mop.isWheel())
157
       {
158
-         // TODO: do modifiers ever need to be non-zero here?
159
+         int unit = MouseWheelEvent.WHEEL_UNIT_SCROLL;
160
+         if (wheelParameters[1] == 2)
161
+         {
162
+            unit = MouseWheelEvent.WHEEL_BLOCK_SCROLL;
163
+         }
164
          event = new MouseWheelEvent(BOGUS_AWT_COMPONENT, 
165
                                      mop.awtEventCode, 
166
                                      tstamp, 
167
@@ -732,31 +743,12 @@
168
                                      mouseY, 
169
                                      clickCount, 
170
                                      false, 
171
-                                     MouseWheelEvent.WHEEL_BLOCK_SCROLL, 
172
-                                     0, 
173
-                                     wheelRotation);
174
+                                     unit, 
175
+                                     Math.abs(wheelParameters[0]), 
176
+                                     (wheelParameters[0] > 0) ? 1 : -1);
177
       }
178
       else
179
       {
180
-         // button codes from JS (same as from AWT) 
181
-         // 0 : No button
182
-         // 1 : Left mouse button
183
-         // 2 : Wheel button or middle button (if present)
184
-         // 3 : Right mouse button
185
-         switch (button)
186
-         {
187
-            case 1:
188
-               modifiers = InputEvent.BUTTON1_MASK;
189
-               break;
190
-            case 2:
191
-               modifiers = InputEvent.BUTTON2_MASK;
192
-               break;
193
-            case 3:
194
-               modifiers = InputEvent.BUTTON3_MASK;
195
-               break;
196
-            default:
197
-         }
198
-         
199
          event = new MouseEvent(BOGUS_AWT_COMPONENT, 
200
                                 mop.awtEventCode, 
201
                                 tstamp, 
202
@@ -773,6 +765,59 @@
203
       EmulatedWindowState window = direct.getWindowEmulator(windowId);
204
       ((WebMouseHandler) window.getMouseHandler()).raiseMouseEvent(event, widgetId);
205
    }
206
+
207
+   /**
208
+    * Gets the mouse modifiers mask for this event.
209
+    * 
210
+    * @param    button
211
+    *           The mouse button that is currently pressed
212
+    * @param    modifiersMask
213
+    *           The bit mask that represents the modifiers keys are pressed. The 0-bit corresponds
214
+    *           to the shift key, the 1-bit to the ctrl key, the 2-bit to the meta key and
215
+    *           the 3-bit to the alt key.
216
+    * 
217
+    * @return   The key's modifiers bit mask for this mouse event.
218
+    */
219
+   private int getMouseModifiers(int button, int modifiersMask)
220
+   {
221
+      int modifiers = 0;
222
+      // button codes from JS (same as from AWT) 
223
+      // 0 : No button
224
+      // 1 : Left mouse button
225
+      // 2 : Wheel button or middle button (if present)
226
+      // 3 : Right mouse button
227
+      switch (button)
228
+      {
229
+         case 1:
230
+            modifiers = InputEvent.BUTTON1_MASK;
231
+            break;
232
+         case 2:
233
+            modifiers = InputEvent.BUTTON2_MASK;
234
+            break;
235
+         case 3:
236
+            modifiers = InputEvent.BUTTON3_MASK;
237
+            break;
238
+         default:
239
+      }
240
+      if ((modifiersMask & MouseEvent.SHIFT_MASK) != 0)
241
+      {
242
+         modifiers |= MouseEvent.SHIFT_DOWN_MASK; 
243
+      }
244
+      if ((modifiersMask & MouseEvent.CTRL_MASK) != 0)
245
+      {
246
+         modifiers |= MouseEvent.CTRL_DOWN_MASK; 
247
+      }
248
+      if ((modifiersMask & MouseEvent.META_MASK) != 0)
249
+      {
250
+         modifiers |= MouseEvent.META_DOWN_MASK; 
251
+      }
252
+      if ((modifiersMask & MouseEvent.ALT_MASK) != 0)
253
+      {
254
+         modifiers |= MouseEvent.ALT_DOWN_MASK; 
255
+      }
256
+      
257
+      return modifiers;
258
+   }
259
    
260
    /**
261
     * Set the location for the specified window.
262

    
263
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java'
264
--- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java	2015-12-01 13:37:14 +0000
265
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java	2015-12-08 16:50:48 +0000
266
@@ -31,6 +31,8 @@
267
 **                  the same batch more than once, it will collide and it will not preserve the
268
 **                  message result.
269
 **     SBI 20151201 Changed to provide processMouseWidgets with calculated widgets bounds.
270
+** 010 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and
271
+**                  a mouse modifiers mask for all mouse events.
272
 */
273
 
274
 package com.goldencode.p2j.ui.client.gui.driver.web;
275
@@ -1117,7 +1119,8 @@
276
          receiveResult(msgId, new Object());
277
          handled = true;
278
       }
279
-      else if ((length == 21 || length == 25) && message[offset] == MSG_MOUSE_EVENT)
280
+      else if ((length == 21 || length == 25 || length == 23 || length == 27) &&
281
+               message[offset] == MSG_MOUSE_EVENT)
282
       {
283
          int idx = offset + 1;
284
          
285
@@ -1142,11 +1145,21 @@
286
          int button = message[idx];
287
          idx = idx + 1;
288
          
289
-         int wheelRotation = message[idx];
290
+         int modifiersMask = message[idx];
291
          idx = idx + 1;
292
+
293
+         int[] wheelParameters = null;
294
+         if (length == 23 || length == 27)
295
+         {
296
+            int delta = message[idx];
297
+            idx = idx + 1;
298
+            int unit  = message[idx];
299
+            idx = idx + 1;
300
+            wheelParameters = new int[] { delta, unit};
301
+         }
302
          
303
          int wid = -1;
304
-         if (length == 25)
305
+         if (length == 25 || length == 27)
306
          {
307
             wid = readMessageInt32(message, idx);
308
             idx = idx + 4;
309
@@ -1159,7 +1172,8 @@
310
                                         mouseY,
311
                                         button,
312
                                         clickCount, 
313
-                                        wheelRotation,
314
+                                        modifiersMask,
315
+                                        wheelParameters,
316
                                         wid);
317
          
318
          handled = true;
319

    
320
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js'
321
--- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js	2015-12-01 22:44:33 +0000
322
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js	2015-12-08 16:49:50 +0000
323
@@ -30,6 +30,8 @@
324
 **                  sendMouseEvent invocations.
325
 ** 008 SBI 20151124 Fixed cleanup() to remove the corresponding window canvas from DOM.
326
 **     SBI 20151201 Fixed two times clicks for menus.
327
+** 009 SBI 20151208 Added new parameters, scroll amount and scroll unit for wheel events and
328
+**                  a mouse modifiers mask for all mouse events.
329
 */
330
 
331
 "use strict";
332
@@ -1265,8 +1267,8 @@
333
    Window.prototype.sendMouseEvent = function(evt, mousePos, wThis, opCode, wid)
334
    {
335
       var widLength = (wid == undefined ? 0 : 4);
336
-      // TODO: CA: ALT/SHIFT modifiers?
337
-      var message = new Uint8Array(21 + widLength);
338
+      var wheelEvent = (evt.deltaMode !== undefined);
339
+      var message = new Uint8Array(21 + widLength + (wheelEvent ? 2 : 0));
340
       
341
       var offset = 0;
342
       
343
@@ -1301,19 +1303,20 @@
344
       message[offset] = evt.which;
345
       offset = offset + 1;
346
 
347
-      // 6. wheel rotation (neg/poz, depending on direction): TODO: CA
348
-      var direction = 0;
349
-//      if (evt.deltaX !== undefined && evt.deltaX != 0)
350
-//      {
351
-//         direction = evt.deltaX;
352
-//      }
353
-//      else if (evt.deltaY !== undefined && evt.deltaY != 0)
354
-//      {
355
-//         direction = evt.deltaY;
356
-//      }
357
-      message[offset] = direction;
358
+      // 6. modifier bitmask
359
+      message[offset] = getModifiersBitMask(evt);
360
       offset = offset + 1;
361
       
362
+      if (wheelEvent)
363
+      {
364
+         // 7. wheel rotation (neg/poz, depending on direction)
365
+         message[offset] = getScrollAmountDelta(evt);
366
+         offset = offset + 1;
367
+         // 8. amount unit
368
+         message[offset] = getScrollAmountUnit(evt);
369
+         offset = offset + 1;
370
+      }
371
+
372
       if (wid != undefined)
373
       {
374
          p2j.socket.writeInt32BinaryMessage(message, offset, wid);
375
@@ -1329,6 +1332,85 @@
376
    }
377
    
378
    /**
379
+    * Returns the bit mask that represents the current modifier keys are pressed during this
380
+    * mouse event occured.
381
+    * 
382
+    * @param    {Event} evt
383
+    *           The mouse event.
384
+    * 
385
+    * @return   The keys modifier mask that represents which of the modifier keys are down.
386
+    *           If 0, 1, 2, or 3-bit is set, then respectivelly the shift, the ctrl, the meta or
387
+    *           the alt key is pressed.
388
+    */
389
+   function getModifiersBitMask(evt)
390
+   {
391
+      var modifiers = 0;
392
+      if (evt.shiftKey !== undefined && evt.shiftKey)
393
+      {
394
+         modifiers |= 1;
395
+      }
396
+      if (evt.ctrlKey !== undefined && evt.ctrlKey)
397
+      {
398
+         modifiers |= 2;
399
+      }
400
+      if (evt.metaKey !== undefined && evt.metaKey)
401
+      {
402
+         modifiers |= 4;
403
+      }
404
+      if (evt.altKey !== undefined && evt.altKey)
405
+      {
406
+         modifiers |= 8;
407
+      }
408
+      
409
+      return modifiers;
410
+   }
411
+   
412
+   /**
413
+    * Returns the scroll amount unit given by deltaMode. The valid values are 0x00, 0x01 and 0x02.
414
+    * 0x00 deltaMode indicates that the delta values are specified in pixels.
415
+    * 0x01 deltaMode indicates that the delta values are specified in lines.
416
+    * 0x02 deltaMode indicates that the delta values are specified in pages.
417
+    * 
418
+    * @param    {Event} evt
419
+    *           The mouse event.
420
+    * 
421
+    * @return   The scroll amount unit.
422
+    */
423
+   function getScrollAmountUnit(evt)
424
+   {
425
+      var unit = 0;
426
+      if (evt.deltaMode !== undefined)
427
+      {
428
+         unit = evt.deltaMode;
429
+      }
430
+      
431
+      return unit;
432
+   }
433
+   
434
+   /**
435
+    * Returns the scroll amount along the direction axis.
436
+    * 
437
+    * @param    {Event} evt
438
+    *           The mouse event.
439
+    * 
440
+    * @return   The scroll amount.
441
+    */
442
+   function getScrollAmountDelta(evt)
443
+   {
444
+      var direction = 0;
445
+      if (evt.deltaX !== undefined && evt.deltaX != 0)
446
+      {
447
+         direction = evt.deltaX;
448
+      }
449
+      else if (evt.deltaY !== undefined && evt.deltaY != 0)
450
+      {
451
+         direction = evt.deltaY;
452
+      }
453
+      
454
+      return direction;
455
+   }
456
+   
457
+   /**
458
     * Move the window to top, in z-order.
459
     */
460
    Window.prototype.moveToTop = function()
461