@@ -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
@@ -5574,9 +5578,76 @@ public void onSizeChanged(int w, int h, int ow, int oh) {
55745578 // However, do not update the base layer as that hasn't changed
55755579 setNewPicture (mLoadedPicture , false );
55765580 }
5581+ if (mIsEditingText ) {
5582+ scrollEditIntoView ();
5583+ }
55775584 relocateAutoCompletePopup ();
55785585 }
55795586
5587+ /**
5588+ * Scrolls the edit field into view using the minimum scrolling necessary.
5589+ * If the edit field is too large to fit in the visible window, the caret
5590+ * dimensions are used so that at least the caret is visible.
5591+ * A buffer of EDIT_RECT_BUFFER in view pixels is used to offset the
5592+ * edit rectangle to ensure a margin with the edge of the screen.
5593+ */
5594+ private void scrollEditIntoView () {
5595+ Rect visibleRect = new Rect (viewToContentX (getScrollX ()),
5596+ viewToContentY (getScrollY ()),
5597+ viewToContentX (getScrollX () + getWidth ()),
5598+ viewToContentY (getScrollY () + getViewHeightWithTitle ()));
5599+ if (visibleRect .contains (mEditTextContentBounds )) {
5600+ return ; // no need to scroll
5601+ }
5602+ syncSelectionCursors ();
5603+ final int buffer = Math .max (1 , viewToContentDimension (EDIT_RECT_BUFFER ));
5604+ Rect showRect = new Rect (
5605+ Math .max (0 , mEditTextContentBounds .left - buffer ),
5606+ Math .max (0 , mEditTextContentBounds .top - buffer ),
5607+ mEditTextContentBounds .right + buffer ,
5608+ mEditTextContentBounds .bottom + buffer );
5609+ Point caretTop = calculateCaretTop ();
5610+ if (visibleRect .width () < mEditTextContentBounds .width ()) {
5611+ // The whole edit won't fit in the width, so use the caret rect
5612+ if (mSelectCursorBase .x < caretTop .x ) {
5613+ showRect .left = Math .max (0 , mSelectCursorBase .x - buffer );
5614+ showRect .right = caretTop .x + buffer ;
5615+ } else {
5616+ showRect .left = Math .max (0 , caretTop .x - buffer );
5617+ showRect .right = mSelectCursorBase .x + buffer ;
5618+ }
5619+ }
5620+ if (visibleRect .height () < mEditTextContentBounds .height ()) {
5621+ // The whole edit won't fit in the height, so use the caret rect
5622+ if (mSelectCursorBase .y > caretTop .y ) {
5623+ showRect .top = Math .max (0 , caretTop .y - buffer );
5624+ showRect .bottom = mSelectCursorBase .y + buffer ;
5625+ } else {
5626+ showRect .top = Math .max (0 , mSelectCursorBase .y - buffer );
5627+ showRect .bottom = caretTop .y + buffer ;
5628+ }
5629+ }
5630+
5631+ if (visibleRect .contains (showRect )) {
5632+ return ; // no need to scroll
5633+ }
5634+
5635+ int scrollX = visibleRect .left ;
5636+ if (visibleRect .left > showRect .left ) {
5637+ scrollX = showRect .left ;
5638+ } else if (visibleRect .right < showRect .right ) {
5639+ scrollX = Math .max (0 , showRect .right - visibleRect .width ());
5640+ }
5641+ int scrollY = visibleRect .top ;
5642+ if (visibleRect .top > showRect .top ) {
5643+ scrollY = showRect .top ;
5644+ } else if (visibleRect .bottom < showRect .bottom ) {
5645+ scrollY = Math .max (0 , showRect .bottom - visibleRect .height ());
5646+ }
5647+
5648+ contentScrollTo (scrollX , scrollY , false );
5649+ }
5650+
55805651 @ Override
55815652 public void onScrollChanged (int l , int t , int oldl , int oldt ) {
55825653 if (!mInOverScrollMode ) {
0 commit comments