Home | History | Annotate | Download | only in browse
      1 package com.android.mail.browse;
      2 
      3 import android.content.Context;
      4 import android.util.AttributeSet;
      5 import android.webkit.WebView;
      6 
      7 public class MailWebView extends WebView {
      8 
      9     // NARROW_COLUMNS reflow can trigger the document to change size, so notify interested parties.
     10     // This is also a good trigger to know when to alter scroll position.
     11     public interface ContentSizeChangeListener {
     12         void onHeightChange(int h);
     13     }
     14 
     15     private int mCachedContentHeight;
     16 
     17     private ContentSizeChangeListener mSizeChangeListener;
     18 
     19     public MailWebView(Context c) {
     20         this(c, null);
     21     }
     22 
     23     public MailWebView(Context c, AttributeSet attrs) {
     24         super(c, attrs);
     25     }
     26 
     27     @Override
     28     public int computeVerticalScrollRange() {
     29         return super.computeVerticalScrollRange();
     30     }
     31 
     32     @Override
     33     public int computeVerticalScrollOffset() {
     34         return super.computeVerticalScrollOffset();
     35     }
     36 
     37     @Override
     38     public int computeVerticalScrollExtent() {
     39         return super.computeVerticalScrollExtent();
     40     }
     41 
     42     @Override
     43     public int computeHorizontalScrollRange() {
     44         return super.computeHorizontalScrollRange();
     45     }
     46 
     47     @Override
     48     public int computeHorizontalScrollOffset() {
     49         return super.computeHorizontalScrollOffset();
     50     }
     51 
     52     @Override
     53     public int computeHorizontalScrollExtent() {
     54         return super.computeHorizontalScrollExtent();
     55     }
     56 
     57     public void setContentSizeChangeListener(ContentSizeChangeListener l) {
     58         mSizeChangeListener = l;
     59     }
     60 
     61     @Override
     62     public void invalidate() {
     63         super.invalidate();
     64 
     65         if (mSizeChangeListener != null) {
     66             final int contentHeight = getContentHeight();
     67             if (contentHeight != mCachedContentHeight) {
     68                 mCachedContentHeight = contentHeight;
     69                 mSizeChangeListener.onHeightChange(contentHeight);
     70             }
     71         }
     72     }
     73 
     74 }
     75