@@ -436,6 +436,7 @@ goog.ui.SliderBase.prototype.enterDocument = function() {
436
436
this . keyHandler_ = new goog . events . KeyHandler ( this . getElement ( ) ) ;
437
437
this . enableEventHandlers_ ( true ) ;
438
438
439
+ this . getElement ( ) . tabIndex = 0 ;
439
440
this . updateUi_ ( ) ;
440
441
} ;
441
442
@@ -586,49 +587,45 @@ goog.ui.SliderBase.prototype.handleThumbDragStartEnd_ = function(e) {
586
587
*/
587
588
goog . ui . SliderBase . prototype . handleKeyDown_ = function ( e ) {
588
589
var handled = true ;
589
- var thumb ;
590
- if ( e . target == this . valueThumb || e . target == this . extentThumb ) {
591
- thumb = goog . asserts . assertElement ( e . target ) ;
592
- }
593
- var delta ;
594
590
switch ( e . keyCode ) {
595
591
case goog . events . KeyCodes . HOME :
596
- this . animateThumbToStart_ ( thumb ) ;
592
+ this . animatedSetValue ( this . getMinimum ( ) ) ;
597
593
break ;
598
594
case goog . events . KeyCodes . END :
599
- this . animateThumbToEnd_ ( thumb ) ;
595
+ this . animatedSetValue ( this . getMaximum ( ) ) ;
600
596
break ;
601
597
case goog . events . KeyCodes . PAGE_UP :
602
- delta = this . getBlockIncrement ( ) ;
598
+ this . moveThumbs ( this . getBlockIncrement ( ) ) ;
603
599
break ;
604
600
case goog . events . KeyCodes . PAGE_DOWN :
605
- delta = - this . getBlockIncrement ( ) ;
601
+ this . moveThumbs ( - this . getBlockIncrement ( ) ) ;
606
602
break ;
607
603
case goog . events . KeyCodes . LEFT :
608
604
var sign = this . flipForRtl_ && this . isRightToLeft ( ) ? 1 : - 1 ;
609
- delta = e . shiftKey ? sign * this . getBlockIncrement ( ) :
610
- sign * this . getUnitIncrement ( ) ;
605
+ this . moveThumbs (
606
+ e . shiftKey ? sign * this . getBlockIncrement ( ) :
607
+ sign * this . getUnitIncrement ( ) ) ;
611
608
break ;
612
609
case goog . events . KeyCodes . DOWN :
613
- delta = e . shiftKey ? - this . getBlockIncrement ( ) : - this . getUnitIncrement ( ) ;
610
+ this . moveThumbs (
611
+ e . shiftKey ? - this . getBlockIncrement ( ) : - this . getUnitIncrement ( ) ) ;
614
612
break ;
615
613
case goog . events . KeyCodes . RIGHT :
616
614
var sign = this . flipForRtl_ && this . isRightToLeft ( ) ? - 1 : 1 ;
617
- delta = e . shiftKey ? sign * this . getBlockIncrement ( ) :
618
- sign * this . getUnitIncrement ( ) ;
615
+ this . moveThumbs (
616
+ e . shiftKey ? sign * this . getBlockIncrement ( ) :
617
+ sign * this . getUnitIncrement ( ) ) ;
619
618
break ;
620
619
case goog . events . KeyCodes . UP :
621
- delta = e . shiftKey ? this . getBlockIncrement ( ) : this . getUnitIncrement ( ) ;
620
+ this . moveThumbs (
621
+ e . shiftKey ? this . getBlockIncrement ( ) : this . getUnitIncrement ( ) ) ;
622
622
break ;
623
623
624
624
default :
625
625
handled = false ;
626
626
}
627
627
628
628
if ( handled ) {
629
- if ( delta ) {
630
- thumb ? this . moveThumb_ ( delta , thumb ) : this . moveThumbs ( delta ) ;
631
- }
632
629
e . preventDefault ( ) ;
633
630
}
634
631
} ;
@@ -854,54 +851,6 @@ goog.ui.SliderBase.prototype.getThumbPosition_ = function(thumb) {
854
851
} ;
855
852
856
853
857
- /**
858
- * Animates the given thumb (or the handle if thumb is not specified) towards
859
- * the minimum value position.
860
- * @param {!Element= } opt_thumb
861
- * @private
862
- */
863
- goog . ui . SliderBase . prototype . animateThumbToStart_ = function ( opt_thumb ) {
864
- if ( opt_thumb ) {
865
- if ( opt_thumb == this . valueThumb ) {
866
- if ( this . getValue ( ) != this . getMinimum ( ) ) {
867
- this . animatedSetValue ( this . getMinimum ( ) , this . valueThumb ) ;
868
- }
869
- } else if ( opt_thumb == this . extentThumb ) {
870
- var newExtentValue = this . getValue ( ) + this . minExtent_ ;
871
- if ( this . getValue ( ) + this . getExtent ( ) != newExtentValue ) {
872
- this . animatedSetValue ( newExtentValue , this . extentThumb ) ;
873
- }
874
- }
875
- } else {
876
- this . animatedSetValue ( this . getMinimum ( ) ) ;
877
- }
878
- } ;
879
-
880
-
881
- /**
882
- * Animates the given thumb (or the handle if thumb is not specified) towards
883
- * the maximum value position.
884
- * @param {!Element= } opt_thumb
885
- * @private
886
- */
887
- goog . ui . SliderBase . prototype . animateThumbToEnd_ = function ( opt_thumb ) {
888
- if ( opt_thumb ) {
889
- if ( opt_thumb == this . extentThumb ) {
890
- if ( this . getValue ( ) + this . getExtent ( ) != this . getMaximum ( ) ) {
891
- this . animatedSetValue ( this . getMaximum ( ) , this . extentThumb ) ;
892
- }
893
- } else if ( opt_thumb == this . valueThumb ) {
894
- var newValue = this . getValue ( ) + this . getExtent ( ) - this . minExtent_ ;
895
- if ( this . getValue ( ) != newValue ) {
896
- this . animatedSetValue ( newValue , this . valueThumb ) ;
897
- }
898
- }
899
- } else {
900
- this . animatedSetValue ( this . getMaximum ( ) ) ;
901
- }
902
- } ;
903
-
904
-
905
854
/**
906
855
* Returns whether a thumb is currently being dragged with the mouse (or via
907
856
* touch). Note that changing the value with keyboard, mouswheel, or via
@@ -941,44 +890,6 @@ goog.ui.SliderBase.prototype.moveThumbs = function(delta) {
941
890
} ;
942
891
943
892
944
- /**
945
- * Moves the given thumb by the the specified delta as follows:
946
- * - The thumb is moved as long as it stays within its [min,max].
947
- * - Once it reaches or exceeds min (or max), it stays at min (or max).
948
- * In case the thumb has reached min (or max), no change event will fire.
949
- * If the specified delta is smaller than the step size, it will be rounded
950
- * to the step size.
951
- * @param {number } delta The delta by which to move the selected range.
952
- * @param {!Element } thumb The thumb to move if given.
953
- * @private
954
- */
955
- goog . ui . SliderBase . prototype . moveThumb_ = function ( delta , thumb ) {
956
- // Assume that a small delta is supposed to be at least a step.
957
- if ( Math . abs ( delta ) < this . getStep ( ) ) {
958
- delta = goog . math . sign ( delta ) * this . getStep ( ) ;
959
- }
960
- var currentMinPos = this . getValue ( ) ;
961
- var currentMaxPos = this . getValue ( ) + this . getExtent ( ) ;
962
- if ( thumb == this . valueThumb ) {
963
- var newMinPos = this . getThumbPosition_ ( this . valueThumb ) + delta ;
964
- newMinPos = goog . math . clamp (
965
- newMinPos , this . getMinimum ( ) , this . getMaximum ( ) - this . minExtent_ ) ;
966
- // Change the extent value to keep the present extentThumb position while
967
- // move the valueThumb to newMinPos.
968
- var newExtent = currentMaxPos - newMinPos ;
969
- this . setValueAndExtent ( newMinPos , newExtent >= 0 ? newExtent : 0 ) ;
970
- } else if ( thumb == this . extentThumb ) {
971
- var newMaxPos = this . getThumbPosition_ ( this . extentThumb ) + delta ;
972
- newMaxPos = goog . math . clamp (
973
- newMaxPos , this . getMinimum ( ) + this . minExtent_ , this . getMaximum ( ) ) ;
974
- // Change the extent value to keep the present valueThumb position while
975
- // move the extentThumb to newMaxPos.
976
- var newExtent = newMaxPos - currentMinPos ;
977
- this . setValueAndExtent ( currentMinPos , newExtent >= 0 ? newExtent : 0 ) ;
978
- }
979
- } ;
980
-
981
-
982
893
/**
983
894
* Sets the position of the given thumb. The set is ignored and no CHANGE event
984
895
* fires if it violates the constraint minimum <= value (valueThumb position) <=
@@ -1208,9 +1119,8 @@ goog.ui.SliderBase.prototype.getThumbCoordinateForValue = function(val) {
1208
1119
/**
1209
1120
* Sets the value and starts animating the handle towards that position.
1210
1121
* @param {number } v Value to set and animate to.
1211
- * @param {!HTMLDivElement= } opt_thumb The thumb to move if given.
1212
1122
*/
1213
- goog . ui . SliderBase . prototype . animatedSetValue = function ( v , opt_thumb ) {
1123
+ goog . ui . SliderBase . prototype . animatedSetValue = function ( v ) {
1214
1124
// the value might be out of bounds
1215
1125
v = goog . math . clamp ( v , this . getMinimum ( ) , this . getMaximum ( ) ) ;
1216
1126
@@ -1221,7 +1131,7 @@ goog.ui.SliderBase.prototype.animatedSetValue = function(v, opt_thumb) {
1221
1131
var animations = new goog . fx . AnimationParallelQueue ( ) ;
1222
1132
var end ;
1223
1133
1224
- var thumb = opt_thumb || this . getClosestThumb_ ( v ) ;
1134
+ var thumb = this . getClosestThumb_ ( v ) ;
1225
1135
var previousValue = this . getValue ( ) ;
1226
1136
var previousExtent = this . getExtent ( ) ;
1227
1137
var previousThumbValue = this . getThumbPosition_ ( thumb ) ;
@@ -1609,17 +1519,10 @@ goog.ui.SliderBase.prototype.setVisible = function(visible) {
1609
1519
* @protected
1610
1520
*/
1611
1521
goog . ui . SliderBase . prototype . setAriaRoles = function ( ) {
1612
- if ( ! this . valueThumb ) {
1613
- return ;
1614
- }
1615
-
1616
- var valueThumb = goog . asserts . assertElement ( this . valueThumb ) ;
1617
- goog . a11y . aria . setRole ( valueThumb , goog . a11y . aria . Role . SLIDER ) ;
1618
- valueThumb . tabIndex = 0 ;
1619
- var extentThumb = goog . asserts . assertElement ( this . extentThumb ) ;
1620
- goog . a11y . aria . setRole ( extentThumb , goog . a11y . aria . Role . SLIDER ) ;
1621
- extentThumb . tabIndex = 0 ;
1622
-
1522
+ var el = this . getElement ( ) ;
1523
+ goog . asserts . assert (
1524
+ el , 'The DOM element for the slider base cannot be null.' ) ;
1525
+ goog . a11y . aria . setRole ( el , goog . a11y . aria . Role . SLIDER ) ;
1623
1526
this . updateAriaStates ( ) ;
1624
1527
} ;
1625
1528
@@ -1629,48 +1532,18 @@ goog.ui.SliderBase.prototype.setAriaRoles = function() {
1629
1532
* @protected
1630
1533
*/
1631
1534
goog . ui . SliderBase . prototype . updateAriaStates = function ( ) {
1632
- if ( ! this . valueThumb ) {
1633
- return ;
1535
+ var element = this . getElement ( ) ;
1536
+ if ( element ) {
1537
+ goog . a11y . aria . setState (
1538
+ element , goog . a11y . aria . State . VALUEMIN , this . getMinimum ( ) ) ;
1539
+ goog . a11y . aria . setState (
1540
+ element , goog . a11y . aria . State . VALUEMAX , this . getMaximum ( ) ) ;
1541
+ goog . a11y . aria . setState (
1542
+ element , goog . a11y . aria . State . VALUENOW , this . getValue ( ) ) ;
1543
+ // Passing an empty value to setState will restore the default.
1544
+ goog . a11y . aria . setState (
1545
+ element , goog . a11y . aria . State . VALUETEXT , this . getTextValue ( ) || '' ) ;
1634
1546
}
1635
-
1636
- var valueThumb = goog . asserts . assertElement ( this . valueThumb ) ;
1637
- var extentThumb = goog . asserts . assertElement ( this . extentThumb ) ;
1638
-
1639
- goog . a11y . aria . setState (
1640
- extentThumb , goog . a11y . aria . State . VALUEMIN ,
1641
- this . getValue ( ) + this . minExtent_ ) ;
1642
- goog . a11y . aria . setState (
1643
- valueThumb , goog . a11y . aria . State . VALUEMIN , this . getMinimum ( ) ) ;
1644
-
1645
- goog . a11y . aria . setState (
1646
- extentThumb , goog . a11y . aria . State . VALUENOW ,
1647
- this . getValue ( ) + this . getExtent ( ) ) ;
1648
- goog . a11y . aria . setState (
1649
- valueThumb , goog . a11y . aria . State . VALUENOW , this . getValue ( ) ) ;
1650
-
1651
- goog . a11y . aria . setState (
1652
- valueThumb , goog . a11y . aria . State . VALUEMAX ,
1653
- this . getValue ( ) + this . getExtent ( ) - this . minExtent_ ) ;
1654
- goog . a11y . aria . setState (
1655
- extentThumb , goog . a11y . aria . State . VALUEMAX , this . getMaximum ( ) ) ;
1656
-
1657
- this . updateAriaValueText_ ( ) ;
1658
- } ;
1659
-
1660
-
1661
- /**
1662
- * Updates the 'aria-valuetext' property for the slider thumbs.
1663
- * @private
1664
- */
1665
- goog . ui . SliderBase . prototype . updateAriaValueText_ = function ( ) {
1666
- // Passing an empty value to setState will restore the default.
1667
- goog . a11y . aria . setState (
1668
- goog . asserts . assertElement ( this . extentThumb ) ,
1669
- goog . a11y . aria . State . VALUETEXT ,
1670
- this . getTextValue ( this . getValue ( ) + this . getExtent ( ) ) || '' ) ;
1671
- goog . a11y . aria . setState (
1672
- goog . asserts . assertElement ( this . valueThumb ) ,
1673
- goog . a11y . aria . State . VALUETEXT , this . getTextValue ( this . getValue ( ) ) || '' ) ;
1674
1547
} ;
1675
1548
1676
1549
@@ -1732,20 +1605,6 @@ goog.ui.SliderBase.prototype.setEnabled = function(enable) {
1732
1605
return ;
1733
1606
}
1734
1607
1735
- if ( enable ) {
1736
- this . valueThumb . tabIndex = 0 ;
1737
- goog . a11y . aria . removeState ( this . valueThumb , goog . a11y . aria . State . DISABLED ) ;
1738
- this . extentThumb . tabIndex = 0 ;
1739
- goog . a11y . aria . removeState ( this . extentThumb , goog . a11y . aria . State . DISABLED ) ;
1740
- } else {
1741
- this . valueThumb . tabIndex = - 1 ;
1742
- goog . a11y . aria . setState (
1743
- this . valueThumb , goog . a11y . aria . State . DISABLED , 'true' ) ;
1744
- this . extentThumb . tabIndex = - 1 ;
1745
- goog . a11y . aria . setState (
1746
- this . extentThumb , goog . a11y . aria . State . DISABLED , 'true' ) ;
1747
- }
1748
-
1749
1608
var eventType = enable ? goog . ui . Component . EventType . ENABLE :
1750
1609
goog . ui . Component . EventType . DISABLE ;
1751
1610
if ( this . dispatchEvent ( eventType ) ) {
@@ -1785,25 +1644,14 @@ goog.ui.SliderBase.prototype.getOffsetStart_ = function(element) {
1785
1644
1786
1645
1787
1646
/**
1788
- * @param {number= } opt_value
1789
1647
* @return {?string } The text value for the slider's current value, or null if
1790
1648
* unavailable.
1791
1649
*/
1792
- goog . ui . SliderBase . prototype . getTextValue = function ( opt_value ) {
1793
- var value = opt_value || this . getValue ( ) ;
1794
- return this . labelFn_ ( value ) ;
1650
+ goog . ui . SliderBase . prototype . getTextValue = function ( ) {
1651
+ return this . labelFn_ ( this . getValue ( ) ) ;
1795
1652
} ;
1796
1653
1797
1654
1798
- /**
1799
- * Sets the function to map slider values to text description.
1800
- * @param {!function(number): string } labelFn
1801
- */
1802
- goog . ui . SliderBase . prototype . setLabelFn = function ( labelFn ) {
1803
- this . labelFn_ = labelFn ;
1804
- this . updateAriaValueText_ ( ) ;
1805
- } ;
1806
-
1807
1655
1808
1656
/**
1809
1657
* The factory for creating additional animations to be played when animating to
0 commit comments