diff options
author | John Reck <jreck@google.com> | 2011-06-16 17:12:08 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-06-17 09:39:39 -0700 |
commit | ff56bcde857c1ea15a9d4bc7fc10653c409b89bd (patch) | |
tree | 7fd127d5b5136112b374e5c477c5f16a0f29f343 /core/java/android/webkit/WebSettings.java | |
parent | 179cfcf65499e0da07d44b38cbb657a4ca898e63 (diff) | |
download | frameworks_base-ff56bcde857c1ea15a9d4bc7fc10653c409b89bd.zip frameworks_base-ff56bcde857c1ea15a9d4bc7fc10653c409b89bd.tar.gz frameworks_base-ff56bcde857c1ea15a9d4bc7fc10653c409b89bd.tar.bz2 |
Add textZoom setting
Replaces the limited textSize (enum) with a more flexible
textZoom (percent)
Change-Id: I443757841910f5cbe1c9078166361d1686005f14
Diffstat (limited to 'core/java/android/webkit/WebSettings.java')
-rw-r--r-- | core/java/android/webkit/WebSettings.java | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java index c361a4a..9802990 100644 --- a/core/java/android/webkit/WebSettings.java +++ b/core/java/android/webkit/WebSettings.java @@ -158,7 +158,7 @@ public class WebSettings { // know what they are. private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; private Context mContext; - private TextSize mTextSize = TextSize.NORMAL; + private int mTextSize = 100; private String mStandardFontFamily = "sans-serif"; private String mFixedFontFamily = "monospace"; private String mSansSerifFontFamily = "sans-serif"; @@ -709,17 +709,38 @@ public class WebSettings { } /** + * Set the text zoom of the page in percent. Default is 100. + * @param textZoom A percent value for increasing or decreasing the text. + * @hide + */ + public synchronized void setTextZoom(int textZoom) { + if (mTextSize != textZoom) { + if (WebView.mLogEvent) { + EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE, + mTextSize, textZoom); + } + mTextSize = textZoom; + postSync(); + } + } + + /** + * Get the text zoom of the page in percent. + * @return A percent value describing the text zoom. + * @see setTextSizeZoom + * @hide + */ + public synchronized int getTextZoom() { + return mTextSize; + } + + /** * Set the text size of the page. * @param t A TextSize value for increasing or decreasing the text. * @see WebSettings.TextSize */ public synchronized void setTextSize(TextSize t) { - if (WebView.mLogEvent && mTextSize != t ) { - EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE, - mTextSize.value, t.value); - } - mTextSize = t; - postSync(); + setTextZoom(t.value); } /** @@ -728,7 +749,19 @@ public class WebSettings { * @see WebSettings.TextSize */ public synchronized TextSize getTextSize() { - return mTextSize; + TextSize closestSize = null; + int smallestDelta = Integer.MAX_VALUE; + for (TextSize size : TextSize.values()) { + int delta = Math.abs(mTextSize - size.value); + if (delta == 0) { + return size; + } + if (delta < smallestDelta) { + smallestDelta = delta; + closestSize = size; + } + } + return closestSize != null ? closestSize : TextSize.NORMAL; } /** |