@@ -9367,40 +9367,57 @@ private void updatePosition() {
93679367 mPositionY = mTempCoords [1 ];
93689368 }
93699369
9370- public boolean isVisible (int positionX , int positionY ) {
9371- final TextView textView = TextView .this ;
9370+ public void onScrollChanged () {
9371+ mScrollHasChanged = true ;
9372+ }
9373+ }
93729374
9373- if (mTempRect == null ) mTempRect = new Rect ();
9374- final Rect clip = mTempRect ;
9375- clip .left = getCompoundPaddingLeft ();
9376- clip .top = getExtendedPaddingTop ();
9377- clip .right = textView .getWidth () - getCompoundPaddingRight ();
9378- clip .bottom = textView .getHeight () - getExtendedPaddingBottom ();
9379-
9380- final ViewParent parent = textView .getParent ();
9381- if (parent == null || !parent .getChildVisibleRect (textView , clip , null )) {
9382- return false ;
9383- }
9375+ public boolean isPositionVisible (int positionX , int positionY ) {
9376+ synchronized (sTmpPosition ) {
9377+ final float [] position = sTmpPosition ;
9378+ position [0 ] = positionX ;
9379+ position [1 ] = positionY ;
9380+ View view = this ;
93849381
9385- int posX = mPositionX + positionX ;
9386- int posY = mPositionY + positionY ;
9382+ while (view != null ) {
9383+ if (view != this ) {
9384+ // Local scroll is already taken into account in positionX/Y
9385+ position [0 ] -= view .getScrollX ();
9386+ position [1 ] -= view .getScrollY ();
9387+ }
93879388
9388- // Offset by 1 to take into account 0.5 and int rounding around getPrimaryHorizontal.
9389- return posX >= clip . left - 1 && posX <= clip . right + 1 &&
9390- posY >= clip . top && posY <= clip . bottom ;
9391- }
9389+ if ( position [ 0 ] < 0 || position [ 1 ] < 0 ||
9390+ position [ 0 ] > view . getWidth () || position [ 1 ] > view . getHeight ()) {
9391+ return false ;
9392+ }
93929393
9393- public boolean isOffsetVisible (int offset ) {
9394- final int line = mLayout .getLineForOffset (offset );
9395- final int lineBottom = mLayout .getLineBottom (line );
9396- final int primaryHorizontal = (int ) mLayout .getPrimaryHorizontal (offset );
9397- return isVisible (primaryHorizontal + viewportToContentHorizontalOffset (),
9398- lineBottom + viewportToContentVerticalOffset ());
9399- }
9394+ if (!view .getMatrix ().isIdentity ()) {
9395+ view .getMatrix ().mapPoints (position );
9396+ }
94009397
9401- public void onScrollChanged () {
9402- mScrollHasChanged = true ;
9398+ position [0 ] += view .getLeft ();
9399+ position [1 ] += view .getTop ();
9400+
9401+ final ViewParent parent = view .getParent ();
9402+ if (parent instanceof View ) {
9403+ view = (View ) parent ;
9404+ } else {
9405+ // We've reached the ViewRoot, stop iterating
9406+ view = null ;
9407+ }
9408+ }
94039409 }
9410+
9411+ // We've been able to walk up the view hierarchy and the position was never clipped
9412+ return true ;
9413+ }
9414+
9415+ public boolean isOffsetVisible (int offset ) {
9416+ final int line = mLayout .getLineForOffset (offset );
9417+ final int lineBottom = mLayout .getLineBottom (line );
9418+ final int primaryHorizontal = (int ) mLayout .getPrimaryHorizontal (offset );
9419+ return isPositionVisible (primaryHorizontal + viewportToContentHorizontalOffset (),
9420+ lineBottom + viewportToContentVerticalOffset ());
94049421 }
94059422
94069423 @ Override
@@ -9501,7 +9518,7 @@ public void hide() {
95019518 public void updatePosition (int parentPositionX , int parentPositionY ,
95029519 boolean parentPositionChanged , boolean parentScrolled ) {
95039520 // Either parentPositionChanged or parentScrolled is true, check if still visible
9504- if (isShowing () && getPositionListener (). isOffsetVisible (getTextOffset ())) {
9521+ if (isShowing () && isOffsetVisible (getTextOffset ())) {
95059522 if (parentScrolled ) computeLocalPosition ();
95069523 updatePosition (parentPositionX , parentPositionY );
95079524 } else {
@@ -10525,7 +10542,7 @@ private boolean isVisible() {
1052510542 return false ;
1052610543 }
1052710544
10528- return getPositionListener (). isVisible (mPositionX + mHotspotX , mPositionY );
10545+ return TextView . this . isPositionVisible (mPositionX + mHotspotX , mPositionY );
1052910546 }
1053010547
1053110548 public abstract int getCurrentCursorOffset ();
@@ -11507,6 +11524,7 @@ protected void replaceText_internal(int start, int end, CharSequence text) {
1150711524 private Path mHighlightPath ;
1150811525 private boolean mHighlightPathBogus = true ;
1150911526 private static final RectF sTempRect = new RectF ();
11527+ private static final float [] sTmpPosition = new float [2 ];
1151011528
1151111529 // XXX should be much larger
1151211530 private static final int VERY_WIDE = 1024 *1024 ;
0 commit comments