Skip to content

Commit

Permalink
Merge pull request pharo-graphics#630 from pharo-graphics/CleanUpEven…
Browse files Browse the repository at this point in the history
…tHandling

Clean up event handling
  • Loading branch information
tinchodias authored Oct 19, 2024
2 parents 931dcf0 + 8e204fd commit 7862e66
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 195 deletions.
51 changes: 24 additions & 27 deletions src/Bloc/BlBubblingEventDispatcher.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"
I'm an event dispatcher that makes events be handled by the element tree in two phases: the capturing and the bubbling phase.
When an event is dispatched, the element tree can handle it in this specific order:
1. Event Capturing starts at the root element and moves downward to the target element.
2. Event Bubbling starts at the target element and moves upward through the element tree.
"
Class {
#name : #BlBubblingEventDispatcher,
#superclass : #BlDirectEventDispatcher,
Expand All @@ -6,10 +14,10 @@ Class {

{ #category : #dispatching }
BlBubblingEventDispatcher >> dispatchArrivedEvent: anEvent [

anEvent arrivedTarget: self owner.
"handlers initialized lazily, do nothing if there are none of them"

"Pay attention at lazy initialization"
handlers ifNotNil: [ :theHandlers |
theHandlers dispatchEvent: anEvent ].

Expand All @@ -21,10 +29,10 @@ BlBubblingEventDispatcher >> dispatchArrivedEvent: anEvent [

{ #category : #dispatching }
BlBubblingEventDispatcher >> dispatchBubblingEvent: anEvent [

anEvent bubblingTarget: self owner.
"handlers initialized lazily, do nothing if there are none of them"

"Pay attention at lazy initialization"
handlers ifNotNil: [ :theHandlers |
theHandlers dispatchEvent: anEvent ].

Expand All @@ -36,43 +44,32 @@ BlBubblingEventDispatcher >> dispatchBubblingEvent: anEvent [

{ #category : #dispatching }
BlBubblingEventDispatcher >> dispatchCapturingEvent: anEvent [

anEvent capturingTarget: self owner.
"filters initialized lazily, do nothing if there are none of them"

"Pay attention at lazy initialization"
filters ifNotNil: [ :theFilters |
theFilters dispatchEvent: anEvent ]
]

{ #category : #dispatching }
BlBubblingEventDispatcher >> dispatchEvent: anEvent next: aBlEventDispatcherChain [
<return: #BlEvent>

anEvent isConsumed
ifTrue: [ ^ anEvent ].


anEvent isConsumed ifTrue: [ ^ anEvent ].

"we give filters a chance to capture this event"
self dispatchCapturingEvent: anEvent.

anEvent isConsumed
ifTrue: [ ^ anEvent ].
anEvent isConsumed ifTrue: [ ^ anEvent ].

anEvent canBePropagated
ifTrue: [ aBlEventDispatcherChain dispatchEvent: anEvent ].
anEvent canBePropagated ifTrue: [
aBlEventDispatcherChain dispatchEvent: anEvent ].

anEvent isConsumed
ifTrue: [ ^ anEvent ].
anEvent isConsumed ifTrue: [ ^ anEvent ].

self owner == anEvent target
ifTrue: [ self dispatchArrivedEvent: anEvent ]
ifFalse: [ self dispatchBubblingEvent: anEvent ].

^ anEvent
]

{ #category : #'api - accessing' }
BlBubblingEventDispatcher >> type [
<return: #String>

^ 'Bubbling'
]
Loading

0 comments on commit 7862e66

Please sign in to comment.