@@ -684,37 +684,10 @@ Utils.getClickablePoint = function(element) {
684
684
var rect = bot . dom . getClientRect ( element ) ;
685
685
686
686
var rects = goog . array . filter ( element . getClientRects ( ) , function ( r ) {
687
- return r . width != 0 && r . height != 0 ;
687
+ return r . width != 0 && r . height != 0 ;
688
688
} ) ;
689
689
690
- if ( rects . length > 0 ) {
691
- for ( var i = 0 ; i < rects . length ; i ++ ) {
692
- var candidate = rects [ i ] ;
693
- if ( clickable_point = findClickablePoint ( candidate ) ) {
694
- return clickable_point ;
695
- }
696
- }
697
- rect = rects [ 0 ] ;
698
- }
699
-
700
- // Fallback to the main rect - expected to return a point so if no clickable point return middle
701
- return findClickablePoint ( rect ) || { x : Math . floor ( rect . width / 2 ) , y : Math . floor ( rect . height / 2 ) } ;
702
-
703
- function findClickablePoint ( rect ) {
704
- var offsets = [
705
- { x : Math . floor ( rect . width / 2 ) , y : Math . floor ( rect . height / 2 ) } ,
706
- { x : 0 , y : 0 } ,
707
- { x : rect . width , y : 0 } ,
708
- { x : 0 , y : rect . height } ,
709
- { x : rect . width , y : rect . height }
710
- ]
711
-
712
- return goog . array . find ( offsets , function ( offset ) {
713
- return isClickableAt ( { x : rect . left + offset . x , y : rect . top + offset . y } ) ;
714
- } )
715
- }
716
-
717
- function isClickableAt ( coord ) {
690
+ var isClickableAt = function ( coord ) {
718
691
// get the outermost ancestor of the element. This will be either the document
719
692
// or a shadow root.
720
693
var owner = element ;
@@ -741,7 +714,49 @@ Utils.getClickablePoint = function(element) {
741
714
}
742
715
parentElemIter = parentElemIter . parentNode ;
743
716
}
717
+ } ;
718
+
719
+ var rectPointRelativeToView = function ( x , y , r ) {
720
+ return { x : r . left + x , y : r . top + y }
721
+ } ;
722
+
723
+ var rectPointRelativeToMainRect = function ( x , y , r ) {
724
+ return { x : r . left - rect . left + x , y : r . top - rect . top + y }
725
+ } ;
726
+
727
+ var findClickablePoint = function ( r ) {
728
+ var offsets = [
729
+ { x : Math . floor ( r . width / 2 ) , y : Math . floor ( r . height / 2 ) } ,
730
+ { x : 0 , y : 0 } ,
731
+ { x : r . width , y : 0 } ,
732
+ { x : 0 , y : r . height } ,
733
+ { x : r . width , y : r . height }
734
+ ]
735
+
736
+ return goog . array . find ( offsets , function ( offset ) {
737
+ return isClickableAt ( rectPointRelativeToView ( offset . x , offset . y , r ) ) ;
738
+ } )
739
+ } ;
740
+
741
+ if ( rects . length > 1 ) {
742
+ goog . log . warning ( Utils . LOG_ , 'Multirect element ' , rects . length ) ;
743
+ for ( var i = 0 ; i < rects . length ; i ++ ) {
744
+ var p = findClickablePoint ( rects [ i ] ) ;
745
+ if ( p ) {
746
+ goog . log . warning ( Utils . LOG_ , 'Found clickable point in rect ' + rects [ i ] ) ;
747
+ return rectPointRelativeToMainRect ( p . x , p . y , rects [ i ] ) ;
748
+ }
749
+ }
750
+ }
751
+
752
+ // Fallback to the main rect
753
+ var p = findClickablePoint ( rect ) ;
754
+ if ( p ) {
755
+ return p ;
744
756
}
757
+
758
+ // Expected to return a point so if there is no clickable point return middle
759
+ return { x : Math . floor ( rect . width / 2 ) , y : Math . floor ( rect . height / 2 ) } ;
745
760
} ;
746
761
747
762
0 commit comments