@awayjs/scene 0.13.239 → 0.13.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import { Vector3D } from '@awayjs/core';
2
2
  import { Stage } from '@awayjs/stage';
3
3
 
4
4
  import { PickingCollision, RaycastPicker, ContainerNode, IPartitionContainer, EntityNode } from '@awayjs/view';
5
+ import { FocusEvent } from '../events/FocusEvent';
5
6
 
6
7
  import { KeyboardEvent } from '../events/KeyboardEvent';
7
8
  import { MouseEvent as AwayMouseEvent } from '../events/MouseEvent';
@@ -26,7 +27,7 @@ export class MouseManager {
26
27
 
27
28
  private _mouseDragCollision: PickingCollision; // entity hit on mouse-down
28
29
  private _mouseDragging: boolean; // true while mosue is dragged
29
- private _focusContainer: IPartitionContainer; // entity currently in focus
30
+ private _focusNode: ContainerNode; // entity currently in focus
30
31
 
31
32
  public allowKeyInput: boolean=true;
32
33
 
@@ -60,6 +61,9 @@ export class MouseManager {
60
61
  private _dragStart: AwayMouseEvent = new AwayMouseEvent(AwayMouseEvent.DRAG_START);
61
62
  private _dragStop: AwayMouseEvent = new AwayMouseEvent(AwayMouseEvent.DRAG_STOP);
62
63
 
64
+ private _focusIn: FocusEvent = new FocusEvent(FocusEvent.FOCUS_IN);
65
+ private _focusOut: FocusEvent = new FocusEvent(FocusEvent.FOCUS_OUT);
66
+
63
67
  private _useSoftkeyboard: boolean = false;
64
68
 
65
69
  public buttonEnabledDirty: boolean;
@@ -219,29 +223,35 @@ export class MouseManager {
219
223
 
220
224
  }
221
225
 
222
- public setFocus(obj: IPartitionContainer) {
223
- if (this._focusContainer == obj) {
226
+ public setFocus(node: ContainerNode) {
227
+ if (this._focusNode == node)
224
228
  return;
225
- }
226
- if (this._focusContainer) {
227
- this._focusContainer.setFocus(false, false);
228
- }
229
- this._focusContainer = obj;
230
229
 
231
- if (this._focusContainer) {
232
- this._focusContainer.setFocus(true, false);
230
+ // in FP6, a mouseclick on non focus-able object still steal the focus
231
+ // in newer FP they only steal the focus if the the new hit is focusable
232
+ if (this._allowFocusOnUnfocusable || this._focusNode.container.tabEnabled) {
233
+ if (this._focusNode) {
234
+ this.dispatchEvent(this._focusOut, this._focusNode);
235
+ this._focusNode.container.setFocus(false, true);
236
+ }
237
+
238
+ this._focusNode = node;
239
+
240
+ if (this._focusNode) {
241
+ this.dispatchEvent(this._focusIn, this._focusNode);
242
+ this._focusNode.container.setFocus(true, true);
243
+ }
233
244
  }
234
245
  }
235
246
 
236
247
  public getFocus() {
237
- return this._focusContainer;
248
+ return this._focusNode;
238
249
  }
239
250
 
240
- private dispatchEvent(event: AwayMouseEvent, dispatcher: ContainerNode) {
251
+ private dispatchEvent(event: AwayMouseEvent | FocusEvent, dispatcher: ContainerNode) {
241
252
  if (!this._eventBubbling) {
242
253
  if (dispatcher) {
243
- dispatcher.container.dispatchEvent(event);
244
- FrameScriptManager.execute_queue();
254
+ event._dispatchEvent(dispatcher);
245
255
  }
246
256
  return;
247
257
  }
@@ -250,10 +260,8 @@ export class MouseManager {
250
260
  if (event.commonAncestor && dispatcher == event.commonAncestor) {
251
261
  return;
252
262
  }
253
- if (!dispatcher.isMouseDisabled()) {
254
- dispatcher.container.dispatchEvent(event);
255
- FrameScriptManager.execute_queue();
256
- }
263
+ event._dispatchEvent(dispatcher);
264
+
257
265
  if (!event._iAllowedToPropagate) {
258
266
  dispatcher = null;
259
267
  } else {
@@ -324,20 +332,10 @@ export class MouseManager {
324
332
  } else if (this._eventBubbling)
325
333
  this._stage.dispatchEvent(event);
326
334
 
327
- // in FP6, a mouseclick on non focus-able object still steal the focus
328
- // in newer FP they only steal the focus if the the new hit is focusable
329
- if (this._allowFocusOnUnfocusable || this._mouseDragCollision?.rootNode.container.tabEnabled) {
330
- if (this._focusContainer)
331
- this._focusContainer.setFocus(false, true);
332
-
333
- this._focusContainer = this._mouseDragCollision?.rootNode?.container;
334
-
335
- if (this._focusContainer)
336
- this._focusContainer.setFocus(true, true);
337
- }
338
-
339
- if (this._mouseDragCollision)
335
+ if (this._mouseDragCollision) {
336
+ this.setFocus(this._mouseDragCollision?.rootNode);
340
337
  this.setupAndDispatchEvent(this._dragStart, event, this._mouseDragCollision);
338
+ }
341
339
 
342
340
  } else if (event.type == AwayMouseEvent.MOUSE_UP) {
343
341
 
@@ -746,15 +744,15 @@ export class MouseManager {
746
744
  default:
747
745
  break;
748
746
  }
749
- if (this._focusContainer || this._stage) {
750
- //console.log("dispatch keydown on ", this._focusContainer);
747
+ if (this._focusNode || this._stage) {
748
+ //console.log("dispatch keydown on ", this._focusNode);
751
749
  const newEvent: KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEYDOWN, event.key, event.code);
752
750
  newEvent.isShift = event.shiftKey;
753
751
  newEvent.isCTRL = event.ctrlKey;
754
752
  newEvent.isAlt = event.altKey;
755
753
  (<any>newEvent).keyCode = event.keyCode;
756
- if (this._focusContainer)
757
- this._focusContainer.dispatchEvent(newEvent);
754
+ if (this._focusNode)
755
+ this._focusNode.container.dispatchEvent(newEvent);
758
756
  if (this._stage)
759
757
  this._stage.dispatchEvent(newEvent);
760
758
  }
@@ -778,15 +776,15 @@ export class MouseManager {
778
776
  break;
779
777
  }
780
778
 
781
- if (this._focusContainer || this._stage) {
782
- //console.log("dispatch keydown on ", this._focusContainer);
779
+ if (this._focusNode || this._stage) {
780
+ //console.log("dispatch keydown on ", this._focusNode);
783
781
  const newEvent: KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEYUP, event.key, event.code);
784
782
  newEvent.isShift = event.shiftKey;
785
783
  newEvent.isCTRL = event.ctrlKey;
786
784
  newEvent.isAlt = event.altKey;
787
785
  (<any>newEvent).keyCode = event.keyCode;
788
- if (this._focusContainer)
789
- this._focusContainer.dispatchEvent(newEvent);
786
+ if (this._focusNode)
787
+ this._focusNode.container.dispatchEvent(newEvent);
790
788
  if (this._stage)
791
789
  this._stage.dispatchEvent(newEvent);
792
790
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.239",
3
+ "version": "0.13.240",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",