/
BlSpace.class.st
1811 lines (1397 loc) · 45.8 KB
/
BlSpace.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
I'm a replacement for `BlSpace`. The idea is to simplify and to remove complex computations that are implemented in `BlSpace`.
For now
- I don't use layout resizing propagation rules at all (compare `BlSpace>>#doStyle` and `ToSpace>>#doStyle`)
- I bring a different toplevel structure. I'm made of a `layerHolder` with owns all top level holders which are layouted on top of each other, with the same extent (`rootLayer`, `contextMenuLayer` and `popupLayer`)
## Comments from `BlSpace`
I am the logical representation of a window in Bloc regardless of the current Host in use.
Here are some of the important objects I use and talk to:
- `BlTime`
- Various `BlBaseEventProcessor` subclasses broker `BlEvent` types
- `BlSpaceFrame`
## Gracefully closing the image when a space is closed
A common use case is to quit the application when some particular space is closed. To do this, we provide `BlSpaceShutdownOnCloseListener` which can be added to any space as an event handler. It listens for a `BlSpaceClosedEvent`, which is sent after a space is closed. See the listener class for configuration options.
"
Class {
#name : #BlSpace,
#superclass : #Object,
#traits : 'TBlEventTarget + TBlSpaceProperties + TBlDebug',
#classTraits : 'TBlEventTarget classTrait + TBlSpaceProperties classTrait + TBlDebug classTrait',
#instVars : [
'id',
'host',
'hostSpace',
'extent',
'position',
'resizable',
'borderless',
'eventDispatcher',
'eventListener',
'eventRecorder',
'mouseProcessor',
'focusProcessor',
'keyboardProcessor',
'focusChain',
'dragboard',
'nextPulseRequested',
'currentCursor',
'session',
'focused',
'title',
'fullscreen',
'fullsize',
'layoutError',
'tasks',
'time',
'frame',
'elementsNeedingPaint',
'elementsNeedingLayout',
'reference',
'iconStencil',
'rootElement',
'userData'
],
#classVars : [
'UniqueIdGenerator'
],
#category : #'Bloc-Space'
}
{ #category : #'private - change' }
BlSpace class >> extractRoots: aSetOfElements [
| roots |
" feenk version 2022-02-01 that eliminate recursion from allParentsDo: "
roots := IdentitySet withAll: aSetOfElements.
aSetOfElements
do:
[ :each |
| current |
current := each parent.
[ current isNil ]
whileFalse:
[ (roots includes: current)
ifTrue:
[ roots remove: each ifAbsent: [ ].
current := nil ]
ifFalse: [ current := current parent ] ] ].
^ roots
]
{ #category : #'class initialization' }
BlSpace class >> initialize [
UniqueIdGenerator := BlUniqueIdGenerator new
]
{ #category : #'debug - simulation' }
BlSpace class >> locationInside: anElement [
"Return a random space location outside of element bounds"
| theBounds aPosition |
anElement topMostParent forceLayout.
theBounds := anElement bounds inSpace bounds.
aPosition := theBounds atRandom.
self
assert: [ theBounds containsPoint: aPosition ]
description: [ 'Point({1}) must be inside of the bounds({2})' format: { aPosition . theBounds } ].
^ aPosition
]
{ #category : #'debug - simulation' }
BlSpace class >> locationOutside: anElement [
"Return a random space location outside of element bounds"
| theBounds aPosition |
anElement topMostParent forceLayout.
theBounds := anElement bounds inSpace bounds.
aPosition := {
theBounds topRight - (theBounds width asInteger atRandom @ 100 atRandom).
theBounds topRight + (100 atRandom @ theBounds height asInteger atRandom).
theBounds bottomLeft + (theBounds width asInteger atRandom @ 100 atRandom).
theBounds bottomLeft - (100 atRandom @ theBounds height asInteger atRandom).
} atRandom.
self
assert: [ (theBounds containsPoint: aPosition) not ]
description: [ 'Point must be outside of the bounds' ].
^ aPosition
]
{ #category : #'debug - simulation' }
BlSpace class >> pulseUntilEmptyTaskQueue: aSpace timeout: aDuration [
"Wait until a BlSpace doesn't have available tasks to execute.
Inspired on BlDevScripterWaitStep>>#forEmptySpaceTaskQueueTimeout:"
| deadline |
deadline := aSpace time now + aDuration.
aSpace time
every: 5 milliSeconds
while: [
(aSpace taskQueue isEmpty or: [
aSpace time now >= deadline ]) not ]
do: [ aSpace pulse ].
aSpace pulse.
^ aSpace taskQueue isEmpty
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateClickOn: anElement [
"Simulate a click event in the middle of a given element by
performing mouse down and mouse up events in a sequence"
^ self simulateClickOn: anElement button: BlMouseButton primary
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateClickOn: anElement button: aButton [
"Simulate a click event in the middle of a given element by
performing mouse down and mouse up events in a sequence."
| aPosition |
"we never know if an element was already layered out"
anElement topMostParent forceLayout.
aPosition := anElement bounds inSpace center.
"we simulate a click with a sequence of low level mouse down/up events"
self
simulateEvents: {
(BlMouseDownEvent button: aButton) position: aPosition; yourself.
(BlMouseUpEvent button: aButton) position: aPosition; yourself }
on: anElement.
^ aPosition
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateClickOutside: anElement [
"Simulate a click event in outside of a given element by
performing mouse down and mouse up events in a sequence"
| aPosition |
aPosition := self locationOutside: anElement.
"we simulate a click with a sequence of low level mouse down/up events"
self
simulateEvents: {
BlMouseDownEvent primary position: aPosition.
BlMouseUpEvent primary position: aPosition }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateDoubleClickOn: anElement [
"Simulate a double click event in the middle of a given element by
performing mouse down and mouse up events in a sequence"
| aPosition |
"we never know if an element was already layered out"
anElement topMostParent forceLayout.
aPosition := anElement bounds inSpace center.
"we simulate a double click with a sequence of low level mouse down/up events"
self
simulateEvents: {
BlMouseDownEvent primary position: aPosition.
BlMouseUpEvent primary position: aPosition.
BlMouseDownEvent primary position: aPosition.
BlMouseUpEvent primary position: aPosition. }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateDragOn: anElement by: aBlVector [
"Simulate a click event in the middle of a given element by
performing mouse down and mouse up events in a sequence"
| aPosition aDelta |
"we never know if an element was already layered out"
anElement topMostParent forceLayout.
aPosition := anElement bounds inSpace center.
aDelta := (anElement localBoundsToGlobal: (BlBounds origin: 0.0@0.0 extent: aBlVector)) extent.
"we simulate a click with a sequence of low level mouse down/up events"
self
simulateEvents: {
BlMouseDownEvent primary position: aPosition; yourself.
BlMouseMoveEvent primary position: aPosition + aDelta; delta: aDelta; yourself.
BlMouseUpEvent primary position: aPosition + aDelta; yourself }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateDragOn: anElement byAll: aSequenceOfBlVectors [
"Simulate a drag in the center of a given element by
performing mouse down, mouse move, and mouse up events."
| aPosition aDelta |
anElement forceLayout.
aPosition := anElement bounds inSpace center.
self
simulateEvent:
(BlMouseDownEvent primary
position: aPosition;
yourself)
on: anElement.
aSequenceOfBlVectors do: [ :each |
aDelta := (anElement localBoundsToGlobal:
(BlBounds origin: 0.0@0.0 extent: each)) extent.
aPosition := aPosition + aDelta.
self
simulateEvent:
(BlMouseMoveEvent primary
position: aPosition "+ aDelta";
delta: aDelta;
yourself)
on: anElement ].
self
simulateEvent:
(BlMouseUpEvent primary
position: aPosition "+ aDelta";
delta: aDelta;
yourself)
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateEvent: anEvent on: anElement [
"I simulate a given low level space UI event such as MouseUp/MouseDown or keyboard.
If you would like to simulate a higher level event you could directly fire or dispatch them
by asking any element to #fireEvent: or #dispatchEvent:
Note: UI mouse events require to set #position: given in space coordinates or in root most parent
coordinates of the provided element.
Note: I create a temporary space if provided element does not have one. if you need to simulate
a sequence of dependent events it is better to use #simulateEvents:on: directy"
self simulateEvents: { anEvent } on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateEvents: aCollectionOfEvents on: anElement [
"I simulate a given sequence of low level space UI events such as MouseUp/MouseDown or keyboard.
If you would like to simulate a higher level event you could directly fire or dispatch them
by asking any element to #fireEvent: or #dispatchEvent:
Note: UI mouse events require to set #position: given in space coordinates or in root most parent
coordinates of the provided element"
"we should update timestamps"
aCollectionOfEvents do: [ :anEvent | anEvent timestamp: DateAndTime now ].
anElement isAttachedToSceneGraph
ifTrue: [
| aSpace |
"element may be removed from the space."
aSpace := anElement space.
aSpace pulse.
aCollectionOfEvents do: [ :anEvent | aSpace dispatchEvent: anEvent ].
aSpace dispatchEvent: BlSpaceEventsProcessedEvent new.
aSpace pulse ]
ifFalse: [
| temporarySpace topMostElement |
topMostElement := anElement topMostParent.
[
temporarySpace := self new.
temporarySpace root addChild: topMostElement.
temporarySpace pulse.
aCollectionOfEvents do: [ :anEvent | temporarySpace dispatchEvent: anEvent ].
temporarySpace dispatchEvent: BlSpaceEventsProcessedEvent new.
temporarySpace pulse
] ensure: [ topMostElement removeFromParent ] ]
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateKeyDownOn: anElement key: aBlKeyboardKey [
"Simulate a key down event"
self
simulateEvents: { BlKeyDownEvent new key: aBlKeyboardKey; yourself }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateKeyUpOn: anElement key: aBlKeyboardKey [
"Simulate a key up event"
self
simulateEvents: { BlKeyUpEvent new key: aBlKeyboardKey; yourself }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseDownOn: anElement [
"Simulate a mouse down event in the middle of a given element"
| aPosition |
"we never know if an element was already layered out"
anElement topMostParent forceLayout.
aPosition := anElement bounds inSpace center.
self
simulateEvents: { BlMouseDownEvent primary position: aPosition }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseDownOn: anElement at: aPoint [
"Simulate a mouse down event at a given location in the space of the element"
self
simulateEvents: { BlMouseDownEvent primary position: aPoint }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseMoveInside: anElement [
"Simulate a mouse move event at a random location within element's bounds"
| aPosition |
aPosition := self locationInside: anElement.
self
simulateEvents: { BlMouseMoveEvent primary position: aPosition }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseMoveOn: anElement at: aPoint [
"Simulate a mouse move event at a given location in the space of the element"
self
simulateEvents: { BlMouseMoveEvent primary position: aPoint }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseMoveOn: anElement from: aFromPoint to: aToPoint [
"Simulate a mouse move event at a given location in the space of the element"
self
simulateEvents: { BlMouseMoveEvent primary
position: aToPoint;
delta: (aToPoint - aFromPoint) }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseMoveOutside: anElement [
"Simulate a mouse move event at a random location outside of element's bounds"
| aPosition |
"we never know if an element was already layered out"
aPosition := self locationOutside: anElement.
self
simulateEvents: { BlMouseMoveEvent primary position: aPosition }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseUpOn: anElement [
"Simulate a mouse up event in the middle of a given element"
| aPosition |
"we never know if an element was already layered out"
anElement topMostParent forceLayout.
aPosition := anElement bounds inSpace center.
self
simulateEvents: { BlMouseUpEvent primary position: aPosition }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseUpOn: anElement at: aPoint [
"Simulate a mouse up event at a given location in the space of the element"
self
simulateEvents: { BlMouseUpEvent primary position: aPoint }
on: anElement
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateMouseWheelOn: anElement by: aBlVector [
"Simulate a mouse wheel event in the middle of a given element"
| aPosition aBlocEvent |
"we never know if an element was already layered out"
anElement topMostParent forceLayout.
aPosition := anElement bounds inSpace center.
"Bloc event"
aBlocEvent := BlMouseWheelEvent new
isTouch: false;
vector: aBlVector asBlocVector;
position: aPosition.
self
simulateEvent: aBlocEvent
on: anElement.
^ aPosition
]
{ #category : #'debug - simulation' }
BlSpace class >> simulateSecondaryClickOn: anElement [
"Simulate a secondary click event in the middle of a given element by
performing mouse down and mouse up events in a sequence"
^ self simulateClickOn: anElement button: BlMouseButton secondary
]
{ #category : #'class initialization' }
BlSpace class >> spaceWithId: aSpaceId do: aBlock [
^ self allSubInstances
detect: [ :eachSpace | eachSpace id = aSpaceId ]
ifFound: aBlock
ifNone: [ nil ]
]
{ #category : #accessing }
BlSpace >> asReference [
<return: #BlSpaceReference>
^ reference ifNil: [ reference := BlAttachedCachedSpaceReference forSpace: self ]
]
{ #category : #'api - displaying' }
BlSpace >> becomeVisible [
"Notify root element that it is now visible to the user"
self root space: self
]
{ #category : #'window - properties' }
BlSpace >> borderless [
self
deprecated: 'Use isBorderless instead of current one'
transformWith: '`@rcv borderless' -> '`@rcv isBorderless'.
^ self isBorderless
]
{ #category : #'window - properties' }
BlSpace >> borderless: aBoolean [
borderless := aBoolean.
self hostSpaceDo: [ :aHostSpace | aHostSpace borderless: aBoolean ]
]
{ #category : #accessing }
BlSpace >> bounds [
^ BlBounds origin: self position extent: self extent
]
{ #category : #'api - displaying' }
BlSpace >> center [
"Tell host to change my position to be centered. Do nothing if host space is not present (e.g. not shown)."
self hostSpace ifNotNil: [ :hw | hw center ]
]
{ #category : #'children - accessing' }
BlSpace >> children [
self
deprecated: 'Talk directly to root'
transformWith: '`@rcv children' -> '`@rcv root children'.
^ self root children
]
{ #category : #'change - rendering' }
BlSpace >> clearDirtyElements [
"Clear dirty elements collection, which means there are no pending graphic operations."
elementsNeedingPaint removeAll
]
{ #category : #'api - displaying' }
BlSpace >> close [
"Delegate closing work to the Universe"
(BlParallelUniverse forHost: self host class) closeSpace: self
]
{ #category : #'composition layer' }
BlSpace >> compositionLayer [
"Return my composition layer if I have one or nil otherwise"
self
deprecated: 'Talk directly to root'
transformWith: '`@rcv compositionLayer' -> '`@rcv root compositionLayer'.
^ self root compositionLayer
]
{ #category : #'cursor managing' }
BlSpace >> currentCursor [
^ currentCursor
]
{ #category : #'cursor managing' }
BlSpace >> currentCursor: aCursor [
currentCursor := aCursor.
currentCursor ifNil: [ ^ self updateCursor: Cursor normal ].
self updateCursor: aCursor
]
{ #category : #initialization }
BlSpace >> defaultEventDispatcher [
^ BlDirectEventDispatcher on: self
]
{ #category : #initialization }
BlSpace >> defaultEventListener [
^ BlSpaceEventListener space: self
]
{ #category : #initialization }
BlSpace >> defaultExtent [
^ 800@600
]
{ #category : #initialization }
BlSpace >> defaultRoot [
^ BlElement new
background: self defaultRootBackground;
constraintsDo: [ :c |
c horizontal matchParent.
c vertical matchParent ];
elevation: (BlRelativeElevation elevation: self defaultRootElevation);
labeled: self defaultRootLabel;
yourself
]
{ #category : #initialization }
BlSpace >> defaultRootBackground [
^ Color white
]
{ #category : #initialization }
BlSpace >> defaultRootElevation [
^ 0
]
{ #category : #initialization }
BlSpace >> defaultRootLabel [
^ #'space-root'
]
{ #category : #initialization }
BlSpace >> defaultTitle [
^ ''
]
{ #category : #'window - properties' }
BlSpace >> densityDpi [
"Return the screen density expressed as dots-per-inch (a float)"
^ self
hostSpaceDo: [ :aHostSpace | aHostSpace densityDpi ]
"Without an actual window we can only guess"
ifAbsent: [ 96.0 ]
]
{ #category : #'api - tasks' }
BlSpace >> dequeueTask: aBlTask [
self taskQueue dequeue: aBlTask.
self requestNextPulse
]
{ #category : #'host space - accessing' }
BlSpace >> detachHostSpace [
"Detach my current host space if I have one"
hostSpace := nil
]
{ #category : #'children dispatching' }
BlSpace >> dispatchAddedToSceneGraph [
"Sent after any of my parents or I was added to scene graph.
I dispatch or fire all necessary events, clean internal caches and send a corresponding hooks"
self root dispatchAddedToSceneGraph
]
{ #category : #'event handling' }
BlSpace >> dispatchMousePickedOutside: aMouseOutsideEvent [
self root dispatchMousePickedOutside: aMouseOutsideEvent
]
{ #category : #'children dispatching' }
BlSpace >> dispatchRemovedFromSceneGraph [
"Sent after topFrame was removed from scene graph.
I dispatch or fire all necessary events, clean internal caches and send a corresponding hooks"
self root dispatchRemovedFromSceneGraph
]
{ #category : #pulse }
BlSpace >> dispatchTimeEvent: aSpaceStepEventClass during: aBlock [
| aStartTime |
aStartTime := self time now.
aBlock cull: self.
self eventDispatcher dispatchEvent:
(aSpaceStepEventClass new
start: aStartTime;
end: self time now;
yourself)
]
{ #category : #'change - layout' }
BlSpace >> doLayout [
self isLayoutRequested ifFalse: [ ^ self ].
[
| layoutCounter maxLayoutCount |
layoutCounter := 0.
maxLayoutCount := 100.
[
self hasLayoutError not and: [
self isLayoutRequested and: [ layoutCounter < maxLayoutCount ] ] ]
whileTrue: [
self doUpdateLayout.
layoutCounter := layoutCounter + 1.
layoutCounter = 50 ifTrue: [
'Warning: Layout was performed 50 times per frame!' traceCr ] ].
self root dispatchLayoutDone
"I prevent infinite spawn of debuggers" ]
on: Error
do: [ :anError |
layoutError := anError.
[ layoutError debug ] ensure: [ layoutError := nil ] ]
]
{ #category : #'focus managing' }
BlSpace >> doUpdateFocus [
(self focusOwner notNil and: [ self focusOwner isAttachedToSceneGraph not ])
ifTrue: [
focusChain
deepestAttachedElementDo: [ :aNewFocusOwner |
aNewFocusOwner requestFocusDueTo: BlFocusDueToRemovedFromSpaceReason uniqueInstance ]
ifAbsent: [ self focusProcessor focusOwner: nil ] ].
self focusOwner
ifNil: [ self initializeFocus ]
]
{ #category : #'change - layout' }
BlSpace >> doUpdateLayout [
| elementsToLayout aBlElementBoundsUpdater |
self elementsNeedingLayout copy do: [ :eachElement |
eachElement privatePreviousMeasurementSpec ifNil: [
self elementsNeedingLayout remove: eachElement.
eachElement requestLayout ] ].
elementsToLayout :=
self elementsNeedingLayout reject: [ :eachElement |
| shouldIgnore |
shouldIgnore := false.
self elementsNeedingLayout do: [ :eachPotentialParent |
(eachElement hasParent: eachPotentialParent)
ifTrue: [
eachElement
allParentsTo: eachPotentialParent
do: [ :eachParent |
eachParent privateRequestingLayout: true ].
shouldIgnore := true ] ].
shouldIgnore ].
"we should clear the elements needing layout before we compute layout
to support multiple layout passes"
self elementsNeedingLayout removeAll.
elementsToLayout :=
elementsToLayout
collect: [ :eachElement | eachElement -> eachElement compositionDepth ]
as: Array.
elementsToLayout :=
(elementsToLayout
sort: [ :a :b | a value > b value ])
collect: [ :each | each key ].
aBlElementBoundsUpdater := BlElementBoundsUpdater new.
elementsToLayout do: [ :eachElement |
self
doUpdateLayoutBoundary: eachElement
context: aBlElementBoundsUpdater ].
self root isLayoutRequested ifTrue: [
self
doUpdateLayout: self root
context: aBlElementBoundsUpdater ].
aBlElementBoundsUpdater commitChanges
]
{ #category : #'change - layout' }
BlSpace >> doUpdateLayout: anElement context: aBlElementBoundsUpdater [
"Perform layout of a given element (e.g. root or glass)"
| currentExtent |
"First, we measure..."
currentExtent := self extent.
anElement measure: (BlExtentMeasurementSpec new
widthSpec: (anElement layout
measurementSpecFor: (BlMeasurementSpec exact: currentExtent x)
usedSize: 0.0
resizer: BlLayoutResizer matchParent);
heightSpec: (anElement layout
measurementSpecFor: (BlMeasurementSpec exact: currentExtent y)
usedSize: 0.0
resizer: BlLayoutResizer matchParent)).
"...then, we layout in measured during previous step bounds"
anElement
applyLayoutIn: anElement measuredBounds asRectangle
context: aBlElementBoundsUpdater
]
{ #category : #'change - layout' }
BlSpace >> doUpdateLayoutBoundary: anElement context: aBlElementBoundsUpdater [
"Perform layout of a given element (e.g. root or glass)"
"first we measure.."
anElement measure: anElement privatePreviousMeasurementSpec.
"...then we layout in measured during previous step bounds"
anElement applyLayoutIn: (anElement position extent: anElement measuredBounds extent) context: aBlElementBoundsUpdater
]
{ #category : #accessing }
BlSpace >> dragboard [
^ dragboard
]
{ #category : #accessing }
BlSpace >> dragboard: anObject [
dragboard := anObject
]
{ #category : #'change - layout' }
BlSpace >> elementsNeedingLayout [
^ elementsNeedingLayout
]
{ #category : #'change - rendering' }
BlSpace >> elementsNeedingPaint [
^ elementsNeedingPaint
]
{ #category : #'api - tasks' }
BlSpace >> enqueueTask: aBlTask [
aBlTask onEnqueued: self.
self taskQueue enqueue: aBlTask.
self requestNextPulse
]
{ #category : #'api - tasks' }
BlSpace >> enqueueTasksFrom: aTaskQueue [
aTaskQueue isEmpty ifTrue: [ ^ self ].
aTaskQueue tasks do: [ :eachTask | eachTask onEnqueued: self ].
self taskQueue enqueueFrom: aTaskQueue.
self requestNextPulse
]
{ #category : #pulse }
BlSpace >> ensureSession [
"Check current session and perform required operations if it changed since last frame"
session == Smalltalk session
ifTrue: [ ^ self ].
self onSessionChanged: Smalltalk session
]
{ #category : #'event management accessing' }
BlSpace >> eventDispatcher [
^ eventDispatcher
]
{ #category : #accessing }
BlSpace >> eventListener [
^ eventListener
]
{ #category : #accessing }
BlSpace >> eventListener: anEventListener [
eventListener := anEventListener
]
{ #category : #'window - properties' }
BlSpace >> extent [
<return: #Point>
^ self windowExtent
]
{ #category : #'window - properties' }
BlSpace >> extent: aNewExtent [
self windowExtent: aNewExtent
]
{ #category : #'NOT-USED-private-change' }
BlSpace >> extractAttachedElements: aSetOfElements [
^ aSetOfElements select: [ :eachElement |
eachElement isAttachedToSceneGraph
and: [ eachElement space == self ] ]
]
{ #category : #'NOT-USED-private-change' }
BlSpace >> extractParents: aSetOfElements suchThat: aConditionBlock [
| theElementToProcess |
theElementToProcess := Set new.
aSetOfElements do: [ :eachElement |
eachElement
topMostParentSuchThat: aConditionBlock
ifFound: [ :aNotYetResolvedParent | theElementToProcess add: aNotYetResolvedParent ]
ifNone: [ theElementToProcess add: eachElement ] ].
^ theElementToProcess
]
{ #category : #'private - change' }
BlSpace >> extractRoots: aSetOfElements [
^ self class extractRoots: aSetOfElements
]
{ #category : #'event handling' }
BlSpace >> findMouseEventTargetAt: aPoint [
"Return the deepest child element starting from root that may be a target for mouse event at provided location.
The coordinate point is given in space coordinates.
I may return nil if no such child is found and if I can not be event target either"
<return: #BlElement or: nil>
^ self root findMouseEventTargetAt: aPoint
]
{ #category : #'event handling' }
BlSpace >> findMousePickTargetFromEvent: anEvent [
"Return the deepest child element among all my children or myself that may be a target for mouse event at provided location.
The coordinate point is given in space coordinates.
I may return nil if no such child is found and if I can not be event target either"
<return: #BlElement or: nil>
(self findMouseEventTargetAt: anEvent position) ifNotNil: [ :found | " test found because if the result is the root then it means that no element has been found "
found ~~ self root ifTrue: [ " dispatch the mouse outside event to all alements of the scene graph "
self mouseProcessor isDragging ifFalse: [
self dispatchMousePickedOutside:
((anEvent newCopyFor: found) asMouseOutsideEvent
lastMouseDownEvent: self mouseProcessor lastMouseDownEvent;
yourself) ].
^ found ] ].
" no element found at all: all elements receive a outside event"
self mouseProcessor isDragging ifFalse: [
self dispatchMousePickedOutside: (anEvent clone asMouseOutsideEvent
lastMouseDownEvent: self mouseProcessor lastMouseDownEvent;
yourself) ].
^ nil
]
{ #category : #'focus managing' }
BlSpace >> focusOwner [
<return: #BlElement>
^ focusChain ifNotNil: [ :aFocusChain | aFocusChain last ]
]
{ #category : #'focus managing' }
BlSpace >> focusOwner: anElement [
focusChain := anElement ifNotNil: [ BlFocusChain of: anElement ]
]
{ #category : #'accessing - processors' }
BlSpace >> focusProcessor [
<return: #BlFocusProcessor>
^ focusProcessor
]
{ #category : #'accessing - processors' }
BlSpace >> focusProcessor: aFocusProcessor [
focusProcessor := aFocusProcessor
]
{ #category : #'window - properties' }
BlSpace >> focused [
self
deprecated: 'Use isFocused instead of current one'
transformWith: '`@rcv focused' -> '`@rcv isFocused'.
^ focused
]
{ #category : #'window - properties' }
BlSpace >> focused: aBoolean [
focused := aBoolean
]
{ #category : #accessing }
BlSpace >> frame [
<return: #BlSpaceFrame>
^ frame
]
{ #category : #'window - properties' }
BlSpace >> fullscreen [
self
deprecated: 'Use isFullscreen instead of current one'
transformWith: '`@rcv fullscreen' -> '`@rcv isFullscreen'.
^ self isFullscreen
]
{ #category : #'window - properties' }
BlSpace >> fullscreen: aBoolean [
"Switch underlying window to fullscreen if true is given
and exit fullscreen mode if false is given"
fullscreen := aBoolean.
self hostSpaceDo: [ :aHostSpace | aHostSpace fullscreen: aBoolean ]
]
{ #category : #'window - properties' }
BlSpace >> fullsize [