@@ -609,6 +609,10 @@ protected void measureContent() {
609609 // The presumed scroll rate for the first scroll of edit text
610610 static private final long TEXT_SCROLL_FIRST_SCROLL_MS = 16 ;
611611
612+ // Buffer pixels of the caret rectangle when moving edit text into view
613+ // after resize.
614+ static private final int EDIT_RECT_BUFFER = 10 ;
615+
612616 // true means redraw the screen all-the-time. Only with AUTO_REDRAW_HACK
613617 private boolean mAutoRedraw ;
614618
@@ -5581,9 +5585,76 @@ public void onSizeChanged(int w, int h, int ow, int oh) {
55815585 // However, do not update the base layer as that hasn't changed
55825586 setNewPicture (mLoadedPicture , false );
55835587 }
5588+ if (mIsEditingText ) {
5589+ scrollEditIntoView ();
5590+ }
55845591 relocateAutoCompletePopup ();
55855592 }
55865593
5594+ /**
5595+ * Scrolls the edit field into view using the minimum scrolling necessary.
5596+ * If the edit field is too large to fit in the visible window, the caret
5597+ * dimensions are used so that at least the caret is visible.
5598+ * A buffer of EDIT_RECT_BUFFER in view pixels is used to offset the
5599+ * edit rectangle to ensure a margin with the edge of the screen.
5600+ */
5601+ private void scrollEditIntoView () {
5602+ Rect visibleRect = new Rect (viewToContentX (getScrollX ()),
5603+ viewToContentY (getScrollY ()),
5604+ viewToContentX (getScrollX () + getWidth ()),
5605+ viewToContentY (getScrollY () + getViewHeightWithTitle ()));
5606+ if (visibleRect .contains (mEditTextContentBounds )) {
5607+ return ; // no need to scroll
5608+ }
5609+ syncSelectionCursors ();
5610+ final int buffer = Math .max (1 , viewToContentDimension (EDIT_RECT_BUFFER ));
5611+ Rect showRect = new Rect (
5612+ Math .max (0 , mEditTextContentBounds .left - buffer ),
5613+ Math .max (0 , mEditTextContentBounds .top - buffer ),
5614+ mEditTextContentBounds .right + buffer ,
5615+ mEditTextContentBounds .bottom + buffer );
5616+ Point caretTop = calculateCaretTop ();
5617+ if (visibleRect .width () < mEditTextContentBounds .width ()) {
5618+ // The whole edit won't fit in the width, so use the caret rect
5619+ if (mSelectCursorBase .x < caretTop .x ) {
5620+ showRect .left = Math .max (0 , mSelectCursorBase .x - buffer );
5621+ showRect .right = caretTop .x + buffer ;
5622+ } else {
5623+ showRect .left = Math .max (0 , caretTop .x - buffer );
5624+ showRect .right = mSelectCursorBase .x + buffer ;
5625+ }
5626+ }
5627+ if (visibleRect .height () < mEditTextContentBounds .height ()) {
5628+ // The whole edit won't fit in the height, so use the caret rect
5629+ if (mSelectCursorBase .y > caretTop .y ) {
5630+ showRect .top = Math .max (0 , caretTop .y - buffer );
5631+ showRect .bottom = mSelectCursorBase .y + buffer ;
5632+ } else {
5633+ showRect .top = Math .max (0 , mSelectCursorBase .y - buffer );
5634+ showRect .bottom = caretTop .y + buffer ;
5635+ }
5636+ }
5637+
5638+ if (visibleRect .contains (showRect )) {
5639+ return ; // no need to scroll
5640+ }
5641+
5642+ int scrollX = visibleRect .left ;
5643+ if (visibleRect .left > showRect .left ) {
5644+ scrollX = showRect .left ;
5645+ } else if (visibleRect .right < showRect .right ) {
5646+ scrollX = Math .max (0 , showRect .right - visibleRect .width ());
5647+ }
5648+ int scrollY = visibleRect .top ;
5649+ if (visibleRect .top > showRect .top ) {
5650+ scrollY = showRect .top ;
5651+ } else if (visibleRect .bottom < showRect .bottom ) {
5652+ scrollY = Math .max (0 , showRect .bottom - visibleRect .height ());
5653+ }
5654+
5655+ contentScrollTo (scrollX , scrollY , false );
5656+ }
5657+
55875658 @ Override
55885659 public void onScrollChanged (int l , int t , int oldl , int oldt ) {
55895660 if (!mInOverScrollMode ) {
0 commit comments