@@ -11,9 +11,10 @@ define( function( require ) {
11
11
'use strict' ;
12
12
13
13
// modules
14
+ var Bounds2 = require ( 'DOT/Bounds2' ) ;
14
15
var ButtonListener = require ( 'SCENERY/input/ButtonListener' ) ;
15
16
var Dimension2 = require ( 'DOT/Dimension2' ) ;
16
- var FocusOverlay = require ( 'SCENERY/overlays/FocusOverlay ' ) ;
17
+ var FocusHighlightPath = require ( 'SCENERY/accessibility/FocusHighlightPath ' ) ;
17
18
var HSlider = require ( 'SUN/HSlider' ) ;
18
19
var inherit = require ( 'PHET_CORE/inherit' ) ;
19
20
var LinearGradient = require ( 'SCENERY/util/LinearGradient' ) ;
@@ -29,6 +30,8 @@ define( function( require ) {
29
30
// constants
30
31
var THUMB_SIZE = new Dimension2 ( 10 , 18 ) ; // size of the slider thumb
31
32
var TRACK_SIZE = new Dimension2 ( 50 , 0.25 ) ; // size of the slider track
33
+ var THUMB_RECTANGLE_WIDTH = 30 ; // a background rectangle behind the thumb, made visible when the slider has focus
34
+ var THUMB_RECTANGLE_HEIGHT = 45 ; // a background rectangle behind the thumb, made visible when the slider has focus
32
35
33
36
/**
34
37
* Constructor for an emission rate control slider.
@@ -50,31 +53,31 @@ define( function( require ) {
50
53
// Create the slider. Frequency mapped from 0 to 1 so that there is a direct map to PhotonEmitterNode 'on' image
51
54
// opacity.
52
55
var sliderRange = new Range ( 0 , 1 ) ;
56
+ var sliderThumb = new EmissionRateThumbNode ( ) ;
53
57
this . emissionRateControlSlider = new HSlider ( model . emissionFrequencyProperty , sliderRange , {
54
58
trackSize : TRACK_SIZE ,
55
59
thumbFillEnabled : 'rgb(0, 203, 230)' ,
56
- thumbNode : new EmissionRateThumbNode ( ) ,
60
+ thumbNode : sliderThumb ,
57
61
tandem : tandem ,
58
62
numberDecimalPlaces : 1 ,
59
63
keyboardStep : sliderRange . getLength ( ) / 10 ,
60
64
shiftKeyboardStep : sliderRange . getLength ( ) / 20 ,
61
65
pageKeyboardStep : sliderRange . getLength ( ) / 5
62
66
} ) ; // @private
63
67
64
- // a11y
65
- // create custom focus highlight with gray bg and thumb on top
66
- var customFocusHighlight = Rectangle . bounds ( this . emissionRateControlSlider . focusHighlight . bounds . dilated ( 2 ) , {
67
- fill : '#ababab' ,
68
- stroke : FocusOverlay . innerFocusColor ,
69
- lineWidth : 4
70
- // children: [ customFocusHighlightThumb ]
71
- } ) ;
68
+ var sliderBounds = sliderThumb . backgroundRectangle . bounds ;
69
+ var parentBounds = sliderThumb . localToParentBounds ( sliderBounds ) ;
70
+ this . emissionRateControlSlider . focusHighlight = new FocusHighlightPath ( Shape . bounds ( parentBounds ) ) ;
72
71
73
- var customFocusHighlightThumb = new EmissionRateThumbNode ( ) ;
74
- customFocusHighlightThumb . center = customFocusHighlight . center ;
75
- customFocusHighlight . addChild ( customFocusHighlightThumb ) ;
76
-
77
- this . emissionRateControlSlider . setFocusHighlight ( customFocusHighlight ) ;
72
+ // a11y
73
+ this . emissionRateControlSlider . addAccessibleInputListener ( {
74
+ focus : function ( ) {
75
+ sliderThumb . backgroundRectangle . visible = true ;
76
+ } ,
77
+ blur : function ( ) {
78
+ sliderThumb . backgroundRectangle . visible = false ;
79
+ }
80
+ } ) ;
78
81
79
82
// width of the background rectangle is larger than the slider to accentuate the thumb.
80
83
var backgroundOffset = 4 ;
@@ -163,7 +166,7 @@ define( function( require ) {
163
166
*/
164
167
function EmissionRateThumbNode ( ) {
165
168
166
- var self = this ;
169
+ Node . call ( this ) ;
167
170
168
171
// draw the partial octagon shape of the slider.
169
172
var thumbShape = new Shape ( ) ;
@@ -175,17 +178,28 @@ define( function( require ) {
175
178
thumbShape . horizontalLineTo ( 0 ) ;
176
179
thumbShape . close ( ) ;
177
180
181
+ // @public (a11y) - so it can be made invisible, helps focus highlight stand out
182
+ this . backgroundRectangle = Rectangle . bounds ( new Bounds2 ( 0 , 0 , THUMB_RECTANGLE_WIDTH , THUMB_RECTANGLE_HEIGHT ) , {
183
+ fill : '#ababab' ,
184
+ visible : false // not visible until slider is focused
185
+ } ) ;
186
+
178
187
// supertype constructor
179
- Path . call ( this , thumbShape , {
188
+ var thumbPath = new Path ( thumbShape , {
180
189
lineWidth : 1 ,
181
190
lineJoin : 'bevel' ,
182
191
stroke : 'black' ,
183
192
fill : 'rgb(0, 203, 230)'
184
193
} ) ;
185
194
195
+ thumbPath . center = this . backgroundRectangle . center ;
196
+
197
+ this . addChild ( this . backgroundRectangle ) ;
198
+ this . addChild ( thumbPath ) ;
199
+
186
200
// draw three lines along the vertical of the thumbNode.
187
201
for ( var n = 1 ; n < 4 ; n ++ ) {
188
- self . addChild ( new Path (
202
+ thumbPath . addChild ( new Path (
189
203
Shape . lineSegment (
190
204
n * THUMB_SIZE . width / 5 ,
191
205
THUMB_SIZE . height / 5 ,
@@ -200,25 +214,25 @@ define( function( require ) {
200
214
// highlight thumb on pointer over
201
215
var buttonListener = new ButtonListener ( {
202
216
over : function ( event ) {
203
- self . fill = 'rgb(80,250,255)' ;
217
+ thumbPath . fill = 'rgb(80,250,255)' ;
204
218
} ,
205
219
up : function ( event ) {
206
- self . fill = 'rgb(0, 203, 230)' ;
220
+ thumbPath . fill = 'rgb(0, 203, 230)' ;
207
221
}
208
222
} ) ;
209
- self . addInputListener ( buttonListener ) ;
223
+ thumbPath . addInputListener ( buttonListener ) ;
210
224
211
225
// make this easier to grab in touch environments
212
- this . touchArea = this . localBounds . dilatedXY ( 20 , 20 ) ;
226
+ this . touchArea = thumbPath . bounds . dilatedXY ( 20 , 20 ) ;
213
227
214
228
this . disposeEmissionRateThumbNode = function ( ) {
215
- self . removeInputListener ( buttonListener ) ;
229
+ thumbPath . removeInputListener ( buttonListener ) ;
216
230
} ;
217
231
}
218
232
219
233
moleculesAndLight . register ( 'EmissionRateThumbNode' , EmissionRateThumbNode ) ;
220
234
221
- inherit ( Path , EmissionRateThumbNode , {
235
+ inherit ( Node , EmissionRateThumbNode , {
222
236
dispose : function ( ) {
223
237
this . disposeEmissionRateThumbNode ( ) ;
224
238
Path . prototype . dispose . call ( this ) ;
0 commit comments