OSDN Git Service

Implement WebSettings.{get|set}TextSize via {get|set}TextZoom. DO NOT MERGE
authorMikhail Naganov <mnaganov@google.com>
Tue, 7 Aug 2012 17:26:52 +0000 (18:26 +0100)
committerSelim Gurun <sgurun@google.com>
Tue, 21 Aug 2012 22:52:40 +0000 (15:52 -0700)
TextSize is deprecated, so we wouldn't expect from WebViewProvider
implementations to re-implement it in some other way than Android WebView does
it. This also makes recently added TextSize.getValue method redundant.

Clean cherry pick: 1202d66f78fb24850b997e37f0ce3cb3b36e4bbf

Change-Id: Ib6aecb187f10ac3ec5d12cb839cb814ec0c564fe

core/java/android/webkit/WebSettings.java
core/java/android/webkit/WebSettingsClassic.java

index 074f910..02c144f 100644 (file)
@@ -423,7 +423,7 @@ public abstract class WebSettings {
      * Gets the text zoom of the page in percent.
      *
      * @return the text zoom of the page in percent
-     * @see #setTextSizeZoom
+     * @see #setTextZoom
      */
     public synchronized int getTextZoom() {
         throw new MustOverrideException();
@@ -436,7 +436,7 @@ public abstract class WebSettings {
      * @deprecated Use {@link #setTextZoom} instead.
      */
     public synchronized void setTextSize(TextSize t) {
-        throw new MustOverrideException();
+        setTextZoom(t.value);
     }
 
     /**
@@ -449,7 +449,20 @@ public abstract class WebSettings {
      * @deprecated Use {@link #getTextZoom} instead.
      */
     public synchronized TextSize getTextSize() {
-        throw new MustOverrideException();
+        TextSize closestSize = null;
+        int smallestDelta = Integer.MAX_VALUE;
+        int textSize = getTextZoom();
+        for (TextSize size : TextSize.values()) {
+            int delta = Math.abs(textSize - size.value);
+            if (delta == 0) {
+                return size;
+            }
+            if (delta < smallestDelta) {
+                smallestDelta = delta;
+                closestSize = size;
+            }
+        }
+        return closestSize != null ? closestSize : TextSize.NORMAL;
     }
 
     /**
index eac1141..d1f8b4b 100644 (file)
@@ -665,34 +665,6 @@ public class WebSettingsClassic extends WebSettings {
     }
 
     /**
-     * @see android.webkit.WebSettings#setTextSize(android.webkit.WebSettingsClassic.TextSize)
-     */
-    @Override
-    public synchronized void setTextSize(TextSize t) {
-        setTextZoom(t.value);
-    }
-
-    /**
-     * @see android.webkit.WebSettings#getTextSize()
-     */
-    @Override
-    public synchronized TextSize getTextSize() {
-        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;
-    }
-
-    /**
      * Set the double-tap zoom of the page in percent. Default is 100.
      * @param doubleTapZoom A percent value for increasing or decreasing the double-tap zoom.
      */