[squeak-dev] The Trunk: Morphic-mt.1675.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Aug 26 13:49:10 UTC 2020


Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.1675.mcz

==================== Summary ====================

Name: Morphic-mt.1675
Author: mt
Time: 26 August 2020, 3:49:04.632388 pm
UUID: ed707aec-b6db-fc49-9e76-56f61780e8a4
Ancestors: Morphic-mt.1674

Refactors #needsClickToFocus to #handlesKeyboardOnlyOnFocus to be useful for all kinds of morphs.

For backwards compatibility, preserves the simple override "handlesKeyboard:evt \ ^true" without breaking this mechanism.

So, this guard is exactly at the same place, where auto-focus is implemented: Morph >> #handleKeystroke:.

Thanks to Christoph (ct)!

=============== Diff against Morphic-mt.1674 ===============

Item was changed:
  ----- Method: DialogWindow>>createMessage: (in category 'initialization') -----
  createMessage: aString 
  	
  	messageMorph := aString asText asMorph.
  	messageMorph
  		name: 'Message';
  		readOnly: true;
  		setProperty: #indicateKeyboardFocus toValue: #never;
+ 		handlesKeyboardOnlyOnFocus: true. "If user presses enter while only hovering the text, we want to process the stroke to close the dialog."
- 		setProperty: #needsClickToFocus toValue: true.
  	self setMessageParameters.	
  	^ messageMorph!

Item was changed:
  ----- Method: Morph>>handleKeyDown: (in category 'events-processing') -----
  handleKeyDown: anEvent
  	"System level event handling."
+ 	anEvent wasHandled ifTrue: [^ self].
+ 	(self handlesKeyboard: anEvent) ifFalse: [^ self].
+ 	(anEvent hand keyboardFocus ~~ self
+ 		and: [self handlesKeyboardOnlyOnFocus])
+ 			ifTrue: [^ self].
+ 	
- 	anEvent wasHandled ifTrue:[^self].
- 	(self handlesKeyboard: anEvent) ifFalse:[^self].
  	anEvent wasHandled: true.
+ 	^ self keyDown: anEvent!
- 	^self keyDown: anEvent!

Item was changed:
  ----- Method: Morph>>handleKeyUp: (in category 'events-processing') -----
  handleKeyUp: anEvent
  	"System level event handling."
+ 	anEvent wasHandled ifTrue: [^ self].
+ 	(self handlesKeyboard: anEvent) ifFalse: [^ self].
+ 	(anEvent hand keyboardFocus ~~ self
+ 		and: [self handlesKeyboardOnlyOnFocus])
+ 			ifTrue: [^ self].
+ 	
- 	anEvent wasHandled ifTrue:[^self].
- 	(self handlesKeyboard: anEvent) ifFalse:[^self].
  	anEvent wasHandled: true.
+ 	^ self keyUp: anEvent!
- 	^self keyUp: anEvent!

Item was changed:
  ----- Method: Morph>>handleKeystroke: (in category 'events-processing') -----
  handleKeystroke: anEvent 
  	"System level event handling. Has support for automatically grabbing the keyboard focus considering the keyboard focus delegate. See #newKeyboardFocus:"
  	
  	| handler |
  	anEvent wasHandled ifTrue: [^ self].
  	(self handlesKeyboard: anEvent) ifFalse: [^ self].
+ 	(anEvent hand keyboardFocus ~~ self
+ 		and: [self handlesKeyboardOnlyOnFocus])
+ 			ifTrue: [^ self].
  	
  	handler := self wantsKeyboardFocus
  		ifFalse: [self]
  		ifTrue: [(anEvent hand newKeyboardFocus: self) ifNil: [self]].
  	anEvent handler: handler.
  	
  	anEvent wasHandled: true.
  	^ handler keyStroke: anEvent!

Item was added:
+ ----- Method: Morph>>handlesKeyboardOnlyOnFocus (in category 'event handling') -----
+ handlesKeyboardOnlyOnFocus
+ 	"If set, reject every keyboard event until the receiver has received the keyboard focus in another way, i.e. a mouse click (see #mouseDown:) or programmatic focusing (see HandMorph >> #newKeyboardFocus:). This allows sending keyboard events to any owner of the receiver while the receiver is hovered by the hand. See senders.
+ 	A particular user is DialogWindow which looks for Enter and Escape presses and should not loose these events to the content morph unless it is explicitly focused. For the full discussion, see http://forum.world.st/The-Inbox-Morphic-cbc-1665-mcz-td5117905.html."
+ 
+ 	^ self valueOfProperty: #handlesKeyboardOnlyOnFocus ifAbsent: [false]!

Item was added:
+ ----- Method: Morph>>handlesKeyboardOnlyOnFocus: (in category 'event handling') -----
+ handlesKeyboardOnlyOnFocus: aBoolean
+ 
+ 	^ self setProperty: #handlesKeyboardOnlyOnFocus toValue: aBoolean!

Item was changed:
  ----- Method: PluggableTextMorph>>mouseEnter: (in category 'event handling') -----
  mouseEnter: event
  	"Restore the selection in the text morph if there was a selection."
  
  	super mouseEnter: event.
  	
  	selectionInterval ifNotNil: [:interval |
  		textMorph editor
  			selectInterval: selectionInterval;
  			setEmphasisHere].
  		
  	Preferences mouseOverForKeyboardFocus
+ 		ifTrue: [event hand newKeyboardFocus: self].!
- 		ifTrue:[event hand newKeyboardFocus: self]!

Item was changed:
  ----- Method: TextMorph>>handleKeystroke: (in category 'events-processing') -----
  handleKeystroke: anEvent
  	"Overwritten to support tab-among-fields preference."
  
  	| pasteUp |
  	anEvent wasHandled ifTrue:[^self].
  	(self handlesKeyboard: anEvent) ifFalse: [^ self].
+ 	(anEvent hand keyboardFocus ~~ self
+ 		and: [self handlesKeyboardOnlyOnFocus])
+ 			ifTrue: [^ self].
  
  	anEvent keyCharacter = Character tab ifTrue: [
  		"Allow passing through text morph inside pasteups"
  		(self wouldAcceptKeyboardFocusUponTab
  			and: [(pasteUp := self pasteUpMorphHandlingTabAmongFields) notNil])
  				ifTrue: [
  					anEvent wasHandled: true.
  					^ pasteUp tabHitWithEvent: anEvent]].
  	
  	^ super handleKeystroke: anEvent!

Item was changed:
  ----- Method: TextMorph>>handlesKeyboard: (in category 'event handling') -----
+ handlesKeyboard: evt
+ 	^true!
- handlesKeyboard: anEvent
- 
- 	^ ((self valueOfProperty: #needsClickToFocus ifAbsent: [false]) ==> [
- 		anEvent hand keyboardFocus = self])!



More information about the Squeak-dev mailing list