Skip to content

Commit 23fe916

Browse files
authored
Merge pull request #869 from pharo-graphics/TolerateRaceConditions
Take care to tolerate some race conditions
2 parents ccb2ab3 + 00f495e commit 23fe916

7 files changed

Lines changed: 41 additions & 16 deletions

File tree

src/Bloc-Layout/BlFrameLayout.class.st

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,41 @@ BlFrameLayout >> measureParentNode: aParentNode [
186186
{ #category : #private }
187187
BlFrameLayout >> measurementSpecFor: aChildNode parentExtent: aParentExtent [
188188

189-
| aParentWidth aParentHeight childWidthMeasureSpec childHeightMeasureSpec |
189+
| aParentWidth aParentHeight childWidthMeasureSpec childHeightMeasureSpec aParentPadding aParentWidthSpec aParentHeightSpec |
190190
aParentWidth := aParentExtent x.
191191
aParentHeight := aParentExtent y.
192+
aParentPadding := aChildNode parent
193+
ifNil: [ BlInsets empty ]
194+
ifNotNil: [ :p | p padding ].
195+
aParentWidthSpec := aChildNode parent
196+
ifNil: [ BlMeasurementSpec unspecified ]
197+
ifNotNil: [ :p | p widthSpec ].
198+
aParentHeightSpec := aChildNode parent
199+
ifNil: [ BlMeasurementSpec unspecified ]
200+
ifNotNil: [ :p | p heightSpec ].
192201

193202
aChildNode isHorizontalMatchParent
194203
ifTrue: [
195204
| weight width |
196205
weight := (aChildNode constraints frame horizontal weight max: 0.0).
197-
width := ((aParentWidth - aChildNode parent padding width - aChildNode margin width) * weight) max: aChildNode constraints minWidth.
206+
width := ((aParentWidth - aParentPadding width - aChildNode margin width) * weight) max: aChildNode constraints minWidth.
198207
childWidthMeasureSpec := BlMeasurementSpec exact: width ]
199208
ifFalse: [
200209
childWidthMeasureSpec := self
201-
measurementSpecFor: aChildNode parent widthSpec
202-
usedSize: aChildNode parent padding width + aChildNode padding width
210+
measurementSpecFor: aParentWidthSpec
211+
usedSize: aParentPadding width + aChildNode padding width
203212
resizer: aChildNode horizontalResizer ].
204213

205214
aChildNode isVerticalMatchParent
206215
ifTrue: [
207216
| weight height |
208217
weight := (aChildNode constraints frame vertical weight max: 0.0).
209-
height := ((aParentHeight - aChildNode parent padding height - aChildNode margin height) * weight) max: aChildNode constraints minHeight.
218+
height := ((aParentHeight - aParentPadding height - aChildNode margin height) * weight) max: aChildNode constraints minHeight.
210219
childHeightMeasureSpec := BlMeasurementSpec exact: height ]
211220
ifFalse: [
212221
childHeightMeasureSpec := self
213-
measurementSpecFor: aChildNode parent heightSpec
214-
usedSize: aChildNode parent padding height + aChildNode margin height
222+
measurementSpecFor: aParentHeightSpec
223+
usedSize: aParentPadding height + aChildNode margin height
215224
resizer: aChildNode verticalResizer ].
216225

217226
^ childWidthMeasureSpec @ childHeightMeasureSpec

src/Bloc-Layout/BlRelativeLayout.class.st

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ BlRelativeLayout >> measureRelativePositions: aParentLayoutNode [
5353
{ #category : #measure }
5454
BlRelativeLayout >> measurementSpecFor: aChildNode parentSpec: aParentSpec [
5555

56-
| childWidthMeasureSpec childHeightMeasureSpec |
56+
| childWidthMeasureSpec childHeightMeasureSpec aParentPadding |
57+
aParentPadding := aChildNode parent
58+
ifNil: [ BlInsets empty ]
59+
ifNotNil: [ :p | p padding ].
5760

5861
childWidthMeasureSpec := self
5962
measurementSpecFor: aParentSpec widthSpec
60-
usedSize: aChildNode parent padding width + aChildNode padding width
63+
usedSize: aParentPadding width + aChildNode padding width
6164
resizer: aChildNode horizontalResizer.
6265

6366
childHeightMeasureSpec := self
6467
measurementSpecFor: aParentSpec heightSpec
65-
usedSize: aChildNode parent padding height + aChildNode margin height
68+
usedSize: aParentPadding height + aChildNode margin height
6669
resizer: aChildNode verticalResizer.
6770

6871
^ childWidthMeasureSpec @ childHeightMeasureSpec

src/Bloc-Text-Elements/BlTextElement.class.st

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,15 @@ BlTextElement >> onPostMeasure: anExtentMeasurementSpec [
440440
"If I am executed it means that measurement specification changed.
441441
We have to recreate a text layout with new parameters"
442442

443-
| measuredWidth measuredHeight maxWidth maxHeight widthSpec heightSpec padding paragraphBounds |
443+
| measuredWidth measuredHeight maxWidth maxHeight widthSpec heightSpec padding paragraphBounds localParagraph |
444+
localParagraph := paragraph.
445+
localParagraph ifNil: [
446+
self measuredExtent: 0@0.
447+
^ self ].
448+
444449
widthSpec := anExtentMeasurementSpec widthSpec.
445450
heightSpec := anExtentMeasurementSpec heightSpec.
446-
paragraphBounds := measurement boundsOf: paragraph.
451+
paragraphBounds := measurement boundsOf: localParagraph.
447452

448453
"If measurement spec is exact I must ignore size measured by textLayout"
449454
widthSpec isExact

src/Bloc/BlLayout.class.st

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,17 @@ BlLayout >> measureChildWithMargins: anElement parentSpec: parentSpec [
281281
BlLayout >> measureChildWithMargins: anElement parentSpec: parentSpec widthUsed: widthUsed heightUsed: heightUsed [
282282
"Measure anElement based on provided parent's extent measurement specification and used width and height
283283
taking into account element's margin and parent's padding."
284-
284+
285+
| aParentPadding |
286+
aParentPadding := anElement parent
287+
ifNil: [ BlInsets empty ]
288+
ifNotNil: [ :aParent | aParent padding ].
289+
285290
self
286291
measureChild: anElement
287292
parentSpec: parentSpec
288-
widthUsed: anElement parent padding width + anElement margin width + widthUsed
289-
heightUsed: anElement parent padding height + anElement margin height + heightUsed
293+
widthUsed: aParentPadding width + anElement margin width + widthUsed
294+
heightUsed: aParentPadding height + anElement margin height + heightUsed
290295
]
291296

292297
{ #category : #'private - measurement' }

src/BlocHost-Morphic/BlMorphicWindow.class.st

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ BlMorphicWindow >> spaceExtent [
7878

7979
| aDelta |
8080
"we compute decorations extent first"
81+
spaceHostMorph extent isZero ifTrue: [ ^ self extent ].
8182
aDelta := self fullBounds extent - spaceHostMorph extent.
8283
^ self extent - aDelta
8384
]

src/BlocHost-OSWindow-SDL2/BlOSWindowSDL2HostSpace.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ BlOSWindowSDL2HostSpace >> position [
261261
"Return window's position in screen coordinates"
262262
<return: #Point>
263263

264-
^ window position
264+
^ window ifNotNil: [ :w | w position ] ifNil: [ 0@0 ]
265265
]
266266

267267
{ #category : #'host space - geometry' }

src/BlocHost-OSWindow/BlOSWindowEventHandler.class.st

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ BlOSWindowEventHandler >> enqueueSpaceResized: aBlSpaceResizedEvent extent: aPoi
6969

7070
{ #category : #events }
7171
BlOSWindowEventHandler >> handleEvent: anEvent [
72+
73+
window isValid ifFalse: [ ^ self ].
7274
anEvent accept: self
7375
]
7476

0 commit comments

Comments
 (0)