149149@ SuppressWarnings ("deprecation" )
150150public final class WebViewClassic implements WebViewProvider , WebViewProvider .ScrollDelegate ,
151151 WebViewProvider .ViewDelegate {
152- private class InnerGlobalLayoutListener implements ViewTreeObserver .OnGlobalLayoutListener {
153- @ Override
154- public void onGlobalLayout () {
155- if (mWebView .isShown ()) {
156- setInvScreenRect ();
157- }
158- }
159- }
160-
161- private class InnerScrollChangedListener implements ViewTreeObserver .OnScrollChangedListener {
162- @ Override
163- public void onScrollChanged () {
164- if (mWebView .isShown ()) {
165- setInvScreenRect ();
166- }
167- }
168- }
169-
170152 /**
171153 * InputConnection used for ContentEditable. This captures changes
172154 * to the text and sends them either as key strokes or text changes.
@@ -617,12 +599,6 @@ protected void measureContent() {
617599 }
618600 }
619601
620- // The listener to capture global layout change event.
621- private InnerGlobalLayoutListener mGlobalLayoutListener = null ;
622-
623- // The listener to capture scroll event.
624- private InnerScrollChangedListener mScrollChangedListener = null ;
625-
626602 // if AUTO_REDRAW_HACK is true, then the CALL key will toggle redrawing
627603 // the screen all-the-time. Good for profiling our drawing code
628604 static private final boolean AUTO_REDRAW_HACK = false ;
@@ -647,7 +623,7 @@ protected void measureContent() {
647623 private final Rect mInvScreenRect = new Rect ();
648624 private final Rect mScreenRect = new Rect ();
649625 private final RectF mVisibleContentRect = new RectF ();
650- private boolean mGLViewportEmpty = false ;
626+ private boolean mIsWebViewVisible = true ;
651627 WebViewInputConnection mInputConnection = null ;
652628 private int mFieldPointer ;
653629 private PastePopupWindow mPasteWindow ;
@@ -3053,21 +3029,14 @@ private void calcOurContentVisibleRect(Rect r) {
30533029 r .bottom = viewToContentY (r .bottom );
30543030 }
30553031
3056- private Rect mContentVisibleRect = new Rect ();
3032+ private final Rect mTempContentVisibleRect = new Rect ();
30573033 // Sets r to be our visible rectangle in content coordinates. We use this
30583034 // method on the native side to compute the position of the fixed layers.
30593035 // Uses floating coordinates (necessary to correctly place elements when
30603036 // the scale factor is not 1)
30613037 private void calcOurContentVisibleRectF (RectF r ) {
3062- calcOurVisibleRect (mContentVisibleRect );
3063- r .left = viewToContentXf (mContentVisibleRect .left ) / mWebView .getScaleX ();
3064- // viewToContentY will remove the total height of the title bar. Add
3065- // the visible height back in to account for the fact that if the title
3066- // bar is partially visible, the part of the visible rect which is
3067- // displaying our content is displaced by that amount.
3068- r .top = viewToContentYf (mContentVisibleRect .top + getVisibleTitleHeightImpl ()) / mWebView .getScaleY ();
3069- r .right = viewToContentXf (mContentVisibleRect .right ) / mWebView .getScaleX ();
3070- r .bottom = viewToContentYf (mContentVisibleRect .bottom ) / mWebView .getScaleY ();
3038+ calcOurVisibleRect (mTempContentVisibleRect );
3039+ viewToContentVisibleRect (r , mTempContentVisibleRect );
30713040 }
30723041
30733042 static class ViewSizeData {
@@ -4227,8 +4196,8 @@ && nativeEvaluateLayersAnimations(mNativeClass)) {
42274196
42284197 calcOurContentVisibleRectF (mVisibleContentRect );
42294198 if (canvas .isHardwareAccelerated ()) {
4230- Rect invScreenRect = mGLViewportEmpty ? null : mInvScreenRect ;
4231- Rect screenRect = mGLViewportEmpty ? null : mScreenRect ;
4199+ Rect invScreenRect = mIsWebViewVisible ? mInvScreenRect : null ;
4200+ Rect screenRect = mIsWebViewVisible ? mScreenRect : null ;
42324201
42334202 int functor = nativeCreateDrawGLFunction (mNativeClass , invScreenRect ,
42344203 screenRect , mVisibleContentRect , getScale (), extras );
@@ -5408,15 +5377,6 @@ String getSelection() {
54085377 @ Override
54095378 public void onAttachedToWindow () {
54105379 if (mWebView .hasWindowFocus ()) setActive (true );
5411- final ViewTreeObserver treeObserver = mWebView .getViewTreeObserver ();
5412- if (mGlobalLayoutListener == null ) {
5413- mGlobalLayoutListener = new InnerGlobalLayoutListener ();
5414- treeObserver .addOnGlobalLayoutListener (mGlobalLayoutListener );
5415- }
5416- if (mScrollChangedListener == null ) {
5417- mScrollChangedListener = new InnerScrollChangedListener ();
5418- treeObserver .addOnScrollChangedListener (mScrollChangedListener );
5419- }
54205380
54215381 addAccessibilityApisToJavaScript ();
54225382
@@ -5429,16 +5389,6 @@ public void onDetachedFromWindow() {
54295389 mZoomManager .dismissZoomPicker ();
54305390 if (mWebView .hasWindowFocus ()) setActive (false );
54315391
5432- final ViewTreeObserver treeObserver = mWebView .getViewTreeObserver ();
5433- if (mGlobalLayoutListener != null ) {
5434- treeObserver .removeGlobalOnLayoutListener (mGlobalLayoutListener );
5435- mGlobalLayoutListener = null ;
5436- }
5437- if (mScrollChangedListener != null ) {
5438- treeObserver .removeOnScrollChangedListener (mScrollChangedListener );
5439- mScrollChangedListener = null ;
5440- }
5441-
54425392 removeAccessibilityApisFromJavaScript ();
54435393 updateHwAccelerated ();
54445394
@@ -5550,11 +5500,18 @@ public void onFocusChanged(boolean focused, int direction,
55505500 }
55515501 }
55525502
5553- void setInvScreenRect () {
5503+ // updateRectsForGL() happens almost every draw call, in order to avoid creating
5504+ // any object in this code path, we move the local variable out to be a private
5505+ // final member, and we marked them as mTemp*.
5506+ private final Point mTempVisibleRectOffset = new Point ();
5507+ private final Rect mTempVisibleRect = new Rect ();
5508+
5509+ void updateRectsForGL () {
55545510 // Use the getGlobalVisibleRect() to get the intersection among the parents
55555511 // visible == false means we're clipped - send a null rect down to indicate that
55565512 // we should not draw
5557- boolean visible = mWebView .getGlobalVisibleRect (mInvScreenRect );
5513+ boolean visible = mWebView .getGlobalVisibleRect (mTempVisibleRect , mTempVisibleRectOffset );
5514+ mInvScreenRect .set (mTempVisibleRect );
55585515 if (visible ) {
55595516 // Then need to invert the Y axis, just for GL
55605517 View rootView = mWebView .getRootView ();
@@ -5563,16 +5520,33 @@ void setInvScreenRect() {
55635520 int savedWebViewBottom = mInvScreenRect .bottom ;
55645521 mInvScreenRect .bottom = rootViewHeight - mInvScreenRect .top - getVisibleTitleHeightImpl ();
55655522 mInvScreenRect .top = rootViewHeight - savedWebViewBottom ;
5566- mGLViewportEmpty = false ;
5523+ mIsWebViewVisible = true ;
55675524 } else {
5568- mGLViewportEmpty = true ;
5525+ mIsWebViewVisible = false ;
55695526 }
5570- calcOurContentVisibleRectF (mVisibleContentRect );
5571- nativeUpdateDrawGLFunction (mNativeClass , mGLViewportEmpty ? null : mInvScreenRect ,
5572- mGLViewportEmpty ? null : mScreenRect ,
5527+
5528+ mTempVisibleRect .offset (-mTempVisibleRectOffset .x , -mTempVisibleRectOffset .y );
5529+ viewToContentVisibleRect (mVisibleContentRect , mTempVisibleRect );
5530+
5531+ nativeUpdateDrawGLFunction (mNativeClass , mIsWebViewVisible ? mInvScreenRect : null ,
5532+ mIsWebViewVisible ? mScreenRect : null ,
55735533 mVisibleContentRect , getScale ());
55745534 }
55755535
5536+ // Input : viewRect, rect in view/screen coordinate.
5537+ // Output: contentRect, rect in content/document coordinate.
5538+ private void viewToContentVisibleRect (RectF contentRect , Rect viewRect ) {
5539+ contentRect .left = viewToContentXf (viewRect .left ) / mWebView .getScaleX ();
5540+ // viewToContentY will remove the total height of the title bar. Add
5541+ // the visible height back in to account for the fact that if the title
5542+ // bar is partially visible, the part of the visible rect which is
5543+ // displaying our content is displaced by that amount.
5544+ contentRect .top = viewToContentYf (viewRect .top + getVisibleTitleHeightImpl ())
5545+ / mWebView .getScaleY ();
5546+ contentRect .right = viewToContentXf (viewRect .right ) / mWebView .getScaleX ();
5547+ contentRect .bottom = viewToContentYf (viewRect .bottom ) / mWebView .getScaleY ();
5548+ }
5549+
55765550 @ Override
55775551 public boolean setFrame (int left , int top , int right , int bottom ) {
55785552 boolean changed = mWebViewPrivate .super_setFrame (left , top , right , bottom );
@@ -5585,7 +5559,7 @@ public boolean setFrame(int left, int top, int right, int bottom) {
55855559 // notify the WebKit about the new dimensions.
55865560 sendViewSizeZoom (false );
55875561 }
5588- setInvScreenRect ();
5562+ updateRectsForGL ();
55895563 return changed ;
55905564 }
55915565
0 commit comments