Loading core/java/android/widget/TextView.java +48 −30 Original line number Original line Diff line number Diff line Loading @@ -9367,42 +9367,59 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mPositionY = mTempCoords[1]; mPositionY = mTempCoords[1]; } } public boolean isVisible(int positionX, int positionY) { public void onScrollChanged() { final TextView textView = TextView.this; mScrollHasChanged = true; } } if (mTempRect == null) mTempRect = new Rect(); public boolean isPositionVisible(int positionX, int positionY) { final Rect clip = mTempRect; synchronized (sTmpPosition) { clip.left = getCompoundPaddingLeft(); final float[] position = sTmpPosition; clip.top = getExtendedPaddingTop(); position[0] = positionX; clip.right = textView.getWidth() - getCompoundPaddingRight(); position[1] = positionY; clip.bottom = textView.getHeight() - getExtendedPaddingBottom(); View view = this; final ViewParent parent = textView.getParent(); while (view != null) { if (parent == null || !parent.getChildVisibleRect(textView, clip, null)) { if (view != this) { // Local scroll is already taken into account in positionX/Y position[0] -= view.getScrollX(); position[1] -= view.getScrollY(); } if (position[0] < 0 || position[1] < 0 || position[0] > view.getWidth() || position[1] > view.getHeight()) { return false; return false; } } int posX = mPositionX + positionX; if (!view.getMatrix().isIdentity()) { int posY = mPositionY + positionY; view.getMatrix().mapPoints(position); } // Offset by 1 to take into account 0.5 and int rounding around getPrimaryHorizontal. position[0] += view.getLeft(); return posX >= clip.left - 1 && posX <= clip.right + 1 && position[1] += view.getTop(); posY >= clip.top && posY <= clip.bottom; final ViewParent parent = view.getParent(); if (parent instanceof View) { view = (View) parent; } else { // We've reached the ViewRoot, stop iterating view = null; } } } // We've been able to walk up the view hierarchy and the position was never clipped return true; } } public boolean isOffsetVisible(int offset) { public boolean isOffsetVisible(int offset) { final int line = mLayout.getLineForOffset(offset); final int line = mLayout.getLineForOffset(offset); final int lineBottom = mLayout.getLineBottom(line); final int lineBottom = mLayout.getLineBottom(line); final int primaryHorizontal = (int) mLayout.getPrimaryHorizontal(offset); final int primaryHorizontal = (int) mLayout.getPrimaryHorizontal(offset); return isVisible(primaryHorizontal + viewportToContentHorizontalOffset(), return isPositionVisible(primaryHorizontal + viewportToContentHorizontalOffset(), lineBottom + viewportToContentVerticalOffset()); lineBottom + viewportToContentVerticalOffset()); } } public void onScrollChanged() { mScrollHasChanged = true; } } @Override @Override protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { super.onScrollChanged(horiz, vert, oldHoriz, oldVert); super.onScrollChanged(horiz, vert, oldHoriz, oldVert); Loading Loading @@ -9501,7 +9518,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public void updatePosition(int parentPositionX, int parentPositionY, public void updatePosition(int parentPositionX, int parentPositionY, boolean parentPositionChanged, boolean parentScrolled) { boolean parentPositionChanged, boolean parentScrolled) { // Either parentPositionChanged or parentScrolled is true, check if still visible // Either parentPositionChanged or parentScrolled is true, check if still visible if (isShowing() && getPositionListener().isOffsetVisible(getTextOffset())) { if (isShowing() && isOffsetVisible(getTextOffset())) { if (parentScrolled) computeLocalPosition(); if (parentScrolled) computeLocalPosition(); updatePosition(parentPositionX, parentPositionY); updatePosition(parentPositionX, parentPositionY); } else { } else { Loading Loading @@ -10525,7 +10542,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return false; return false; } } return getPositionListener().isVisible(mPositionX + mHotspotX, mPositionY); return TextView.this.isPositionVisible(mPositionX + mHotspotX, mPositionY); } } public abstract int getCurrentCursorOffset(); public abstract int getCurrentCursorOffset(); Loading Loading @@ -11507,6 +11524,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private Path mHighlightPath; private Path mHighlightPath; private boolean mHighlightPathBogus = true; private boolean mHighlightPathBogus = true; private static final RectF sTempRect = new RectF(); private static final RectF sTempRect = new RectF(); private static final float[] sTmpPosition = new float[2]; // XXX should be much larger // XXX should be much larger private static final int VERY_WIDE = 1024*1024; private static final int VERY_WIDE = 1024*1024; Loading Loading
core/java/android/widget/TextView.java +48 −30 Original line number Original line Diff line number Diff line Loading @@ -9367,42 +9367,59 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mPositionY = mTempCoords[1]; mPositionY = mTempCoords[1]; } } public boolean isVisible(int positionX, int positionY) { public void onScrollChanged() { final TextView textView = TextView.this; mScrollHasChanged = true; } } if (mTempRect == null) mTempRect = new Rect(); public boolean isPositionVisible(int positionX, int positionY) { final Rect clip = mTempRect; synchronized (sTmpPosition) { clip.left = getCompoundPaddingLeft(); final float[] position = sTmpPosition; clip.top = getExtendedPaddingTop(); position[0] = positionX; clip.right = textView.getWidth() - getCompoundPaddingRight(); position[1] = positionY; clip.bottom = textView.getHeight() - getExtendedPaddingBottom(); View view = this; final ViewParent parent = textView.getParent(); while (view != null) { if (parent == null || !parent.getChildVisibleRect(textView, clip, null)) { if (view != this) { // Local scroll is already taken into account in positionX/Y position[0] -= view.getScrollX(); position[1] -= view.getScrollY(); } if (position[0] < 0 || position[1] < 0 || position[0] > view.getWidth() || position[1] > view.getHeight()) { return false; return false; } } int posX = mPositionX + positionX; if (!view.getMatrix().isIdentity()) { int posY = mPositionY + positionY; view.getMatrix().mapPoints(position); } // Offset by 1 to take into account 0.5 and int rounding around getPrimaryHorizontal. position[0] += view.getLeft(); return posX >= clip.left - 1 && posX <= clip.right + 1 && position[1] += view.getTop(); posY >= clip.top && posY <= clip.bottom; final ViewParent parent = view.getParent(); if (parent instanceof View) { view = (View) parent; } else { // We've reached the ViewRoot, stop iterating view = null; } } } // We've been able to walk up the view hierarchy and the position was never clipped return true; } } public boolean isOffsetVisible(int offset) { public boolean isOffsetVisible(int offset) { final int line = mLayout.getLineForOffset(offset); final int line = mLayout.getLineForOffset(offset); final int lineBottom = mLayout.getLineBottom(line); final int lineBottom = mLayout.getLineBottom(line); final int primaryHorizontal = (int) mLayout.getPrimaryHorizontal(offset); final int primaryHorizontal = (int) mLayout.getPrimaryHorizontal(offset); return isVisible(primaryHorizontal + viewportToContentHorizontalOffset(), return isPositionVisible(primaryHorizontal + viewportToContentHorizontalOffset(), lineBottom + viewportToContentVerticalOffset()); lineBottom + viewportToContentVerticalOffset()); } } public void onScrollChanged() { mScrollHasChanged = true; } } @Override @Override protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { super.onScrollChanged(horiz, vert, oldHoriz, oldVert); super.onScrollChanged(horiz, vert, oldHoriz, oldVert); Loading Loading @@ -9501,7 +9518,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public void updatePosition(int parentPositionX, int parentPositionY, public void updatePosition(int parentPositionX, int parentPositionY, boolean parentPositionChanged, boolean parentScrolled) { boolean parentPositionChanged, boolean parentScrolled) { // Either parentPositionChanged or parentScrolled is true, check if still visible // Either parentPositionChanged or parentScrolled is true, check if still visible if (isShowing() && getPositionListener().isOffsetVisible(getTextOffset())) { if (isShowing() && isOffsetVisible(getTextOffset())) { if (parentScrolled) computeLocalPosition(); if (parentScrolled) computeLocalPosition(); updatePosition(parentPositionX, parentPositionY); updatePosition(parentPositionX, parentPositionY); } else { } else { Loading Loading @@ -10525,7 +10542,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return false; return false; } } return getPositionListener().isVisible(mPositionX + mHotspotX, mPositionY); return TextView.this.isPositionVisible(mPositionX + mHotspotX, mPositionY); } } public abstract int getCurrentCursorOffset(); public abstract int getCurrentCursorOffset(); Loading Loading @@ -11507,6 +11524,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private Path mHighlightPath; private Path mHighlightPath; private boolean mHighlightPathBogus = true; private boolean mHighlightPathBogus = true; private static final RectF sTempRect = new RectF(); private static final RectF sTempRect = new RectF(); private static final float[] sTmpPosition = new float[2]; // XXX should be much larger // XXX should be much larger private static final int VERY_WIDE = 1024*1024; private static final int VERY_WIDE = 1024*1024; Loading