summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/WebTextView.java
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2010-11-10 08:59:05 -0500
committerLeon Scroggins <scroggo@google.com>2010-11-12 10:41:14 -0500
commitc35f4ac3090e7bc875d84d1f8a655a4ea8baef1b (patch)
treec959f674c27bef623333fbbd07dcd1c0b90f95e1 /core/java/android/webkit/WebTextView.java
parentbdd19bc338286e1042f59808545665a061e73ffc (diff)
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
Diffstat (limited to 'core/java/android/webkit/WebTextView.java')
-rw-r--r--core/java/android/webkit/WebTextView.java40
1 files changed, 30 insertions, 10 deletions
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
@@ -928,6 +934,20 @@ import java.util.ArrayList;
}
/**
+ * 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.
* @param text The new text to place in the textfield.