From c35f4ac3090e7bc875d84d1f8a655a4ea8baef1b Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Wed, 10 Nov 2010 08:59:05 -0500 Subject: Work on lining up the TextView and web page text. Bug:3085564 Do not round the text size when applying it to the WebTextView, so that it will better line up with the text shown on the web page. Modify the WebTextView paint to better match the paint used by webkit. Update the padding when the zoom level changes. Change-Id: I284a6febcba2be21dc1ab3f74c6ab5751e1b19b6 --- core/java/android/webkit/WebTextView.java | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'core/java/android/webkit/WebTextView.java') diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index 1538bd0e647e..a58d648c5ffd 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -36,6 +36,7 @@ import android.text.TextUtils; import android.text.method.MovementMethod; import android.text.method.Touch; import android.util.Log; +import android.util.TypedValue; import android.view.Gravity; import android.view.KeyCharacterMap; import android.view.KeyEvent; @@ -54,6 +55,8 @@ import android.widget.TextView; import java.util.ArrayList; +import junit.framework.Assert; + /** * WebTextView is a specialized version of EditText used by WebView * to overlay html textfields (and textareas) to use our standard @@ -144,6 +147,19 @@ import java.util.ArrayList; mWebView = webView; mMaxLength = -1; setAutoFillable(autoFillQueryId); + // Turn on subpixel text, and turn off kerning, so it better matches + // the text in webkit. + TextPaint paint = getPaint(); + int flags = paint.getFlags() & ~Paint.DEV_KERN_TEXT_FLAG + | Paint.SUBPIXEL_TEXT_FLAG | Paint.DITHER_FLAG; + paint.setFlags(flags); + + // Set the text color to black, regardless of the theme. This ensures + // that other applications that use embedded WebViews will properly + // display the text in password textfields. + setTextColor(Color.BLACK); + // This helps to align the text better with the text in the web page. + setIncludeFontPadding(false); } public void setAutoFillable(int queryId) { @@ -845,16 +861,6 @@ import java.util.ArrayList; mBackground = new OutlineDrawable(); setGravity(Gravity.CENTER_VERTICAL); - // Turn on subpixel text, and turn off kerning, so it better matches - // the text in webkit. - TextPaint paint = getPaint(); - int flags = paint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG | - Paint.ANTI_ALIAS_FLAG & ~Paint.DEV_KERN_TEXT_FLAG; - paint.setFlags(flags); - // Set the text color to black, regardless of the theme. This ensures - // that other applications that use embedded WebViews will properly - // display the text in password textfields. - setTextColor(Color.BLACK); } @Override @@ -927,6 +933,20 @@ import java.util.ArrayList; mFromWebKit = false; } + /** + * Update the text size according to the size of the focus candidate's text + * size in mWebView. Should only be called from mWebView. + */ + /* package */ void updateTextSize() { + Assert.assertNotNull("updateTextSize should only be called from " + + "mWebView, so mWebView should never be null!", mWebView); + // Note that this is approximately WebView.contentToViewDimension, + // without being rounded. + float size = mWebView.nativeFocusCandidateTextSize() + * mWebView.getScale(); + setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + } + /** * Set the text to the new string, but use the old selection, making sure * to keep it within the new string. -- cgit v1.2.3