зеркало из https://github.com/mozilla/gecko-dev.git
Bug 742115 - Make the java panning constants preffable; original patch stolen from :joe. r=Cwiiis
This commit is contained in:
Родитель
e9c06e926a
Коммит
988a84b229
|
@ -724,3 +724,21 @@ pref("gfx.show_checkerboard_pattern", false);
|
|||
|
||||
pref("remote-debugger.enabled", false);
|
||||
pref("remote-debugger.port", 6000);
|
||||
|
||||
// This fraction in 1000ths of velocity remains after every animation frame when the velocity is low.
|
||||
pref("ui.scrolling.friction_slow", -1);
|
||||
// This fraction in 1000ths of velocity remains after every animation frame when the velocity is high.
|
||||
pref("ui.scrolling.friction_fast", -1);
|
||||
// Below this velocity (in pixels per frame), the friction starts increasing from friction_fast
|
||||
// to friction_slow.
|
||||
pref("ui.scrolling.velocity_threshold", -1);
|
||||
// The maximum velocity change factor between events, per ms, in 1000ths.
|
||||
// Direction changes are excluded.
|
||||
pref("ui.scrolling.max_event_acceleration", -1);
|
||||
// The rate of deceleration when the surface has overscrolled, in 1000ths.
|
||||
pref("ui.scrolling.overscroll_decel_rate", -1);
|
||||
// The fraction of the surface which can be overscrolled before it must snap back, in 1000ths.
|
||||
pref("ui.scrolling.overscroll_snap_limit", -1);
|
||||
// The minimum amount of space that must be present for an axis to be considered scrollable,
|
||||
// in 1/1000ths of pixels.
|
||||
pref("ui.scrolling.min_scrollable_distance", -1);
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.mozilla.gecko.GeckoApp;
|
|||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import org.mozilla.gecko.GeckoEventResponder;
|
||||
import org.mozilla.gecko.ui.Axis;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -123,6 +124,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
|
|||
|
||||
JSONArray prefs = new JSONArray();
|
||||
DisplayPortCalculator.addPrefNames(prefs);
|
||||
Axis.addPrefNames(prefs);
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Preferences:Get", prefs.toString()));
|
||||
}
|
||||
|
||||
|
@ -261,7 +263,11 @@ public class GeckoLayerClient implements GeckoEventResponder,
|
|||
JSONObject pref = jsonPrefs.getJSONObject(i);
|
||||
prefValues.put(pref.getString("name"), pref.getInt("value"));
|
||||
}
|
||||
// check return value from setStrategy to make sure that this is the
|
||||
// right batch of prefs, since other java code may also have sent requests
|
||||
// for prefs.
|
||||
if (DisplayPortCalculator.setStrategy(prefValues)) {
|
||||
Axis.setPrefs(prefValues);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
|
||||
package org.mozilla.gecko.ui;
|
||||
|
||||
import java.util.Map;
|
||||
import android.util.Log;
|
||||
import org.json.JSONArray;
|
||||
import org.mozilla.gecko.FloatUtils;
|
||||
|
||||
/**
|
||||
|
@ -46,26 +49,74 @@ import org.mozilla.gecko.FloatUtils;
|
|||
* like displacement, velocity, viewport dimensions, etc. pertaining to
|
||||
* a particular axis.
|
||||
*/
|
||||
abstract class Axis {
|
||||
public abstract class Axis {
|
||||
private static final String LOGTAG = "GeckoAxis";
|
||||
|
||||
private static final String PREF_SCROLLING_FRICTION_SLOW = "ui.scrolling.friction_slow";
|
||||
private static final String PREF_SCROLLING_FRICTION_FAST = "ui.scrolling.friction_fast";
|
||||
private static final String PREF_SCROLLING_VELOCITY_THRESHOLD = "ui.scrolling.velocity_threshold";
|
||||
private static final String PREF_SCROLLING_MAX_EVENT_ACCELERATION = "ui.scrolling.max_event_acceleration";
|
||||
private static final String PREF_SCROLLING_OVERSCROLL_DECEL_RATE = "ui.scrolling.overscroll_decel_rate";
|
||||
private static final String PREF_SCROLLING_OVERSCROLL_SNAP_LIMIT = "ui.scrolling.overscroll_snap_limit";
|
||||
private static final String PREF_SCROLLING_MIN_SCROLLABLE_DISTANCE = "ui.scrolling.min_scrollable_distance";
|
||||
|
||||
// This fraction of velocity remains after every animation frame when the velocity is low.
|
||||
private static final float FRICTION_SLOW = 0.85f;
|
||||
private static float FRICTION_SLOW;
|
||||
// This fraction of velocity remains after every animation frame when the velocity is high.
|
||||
private static final float FRICTION_FAST = 0.97f;
|
||||
private static float FRICTION_FAST;
|
||||
// Below this velocity (in pixels per frame), the friction starts increasing from FRICTION_FAST
|
||||
// to FRICTION_SLOW.
|
||||
private static final float VELOCITY_THRESHOLD = 10.0f;
|
||||
private static float VELOCITY_THRESHOLD;
|
||||
// The maximum velocity change factor between events, per ms, in %.
|
||||
// Direction changes are excluded.
|
||||
private static final float MAX_EVENT_ACCELERATION = 0.012f;
|
||||
private static float MAX_EVENT_ACCELERATION;
|
||||
|
||||
// The rate of deceleration when the surface has overscrolled.
|
||||
private static final float OVERSCROLL_DECEL_RATE = 0.04f;
|
||||
private static float OVERSCROLL_DECEL_RATE;
|
||||
// The percentage of the surface which can be overscrolled before it must snap back.
|
||||
private static final float SNAP_LIMIT = 0.3f;
|
||||
private static float SNAP_LIMIT;
|
||||
|
||||
// The minimum amount of space that must be present for an axis to be considered scrollable,
|
||||
// in pixels.
|
||||
private static final float MIN_SCROLLABLE_DISTANCE = 0.5f;
|
||||
private static float MIN_SCROLLABLE_DISTANCE;
|
||||
|
||||
private static float getFloatPref(Map<String, Integer> prefs, String prefName, int defaultValue) {
|
||||
Integer value = (prefs == null ? null : prefs.get(prefName));
|
||||
return (float)(value == null || value < 0 ? defaultValue : value) / 1000f;
|
||||
}
|
||||
|
||||
private static int getIntPref(Map<String, Integer> prefs, String prefName, int defaultValue) {
|
||||
Integer value = (prefs == null ? null : prefs.get(prefName));
|
||||
return (value == null || value < 0 ? defaultValue : value);
|
||||
}
|
||||
|
||||
public static void addPrefNames(JSONArray prefs) {
|
||||
prefs.put(PREF_SCROLLING_FRICTION_FAST);
|
||||
prefs.put(PREF_SCROLLING_FRICTION_SLOW);
|
||||
prefs.put(PREF_SCROLLING_VELOCITY_THRESHOLD);
|
||||
prefs.put(PREF_SCROLLING_MAX_EVENT_ACCELERATION);
|
||||
prefs.put(PREF_SCROLLING_OVERSCROLL_DECEL_RATE);
|
||||
prefs.put(PREF_SCROLLING_OVERSCROLL_SNAP_LIMIT);
|
||||
prefs.put(PREF_SCROLLING_MIN_SCROLLABLE_DISTANCE);
|
||||
}
|
||||
|
||||
public static void setPrefs(Map<String, Integer> prefs) {
|
||||
FRICTION_SLOW = getFloatPref(prefs, PREF_SCROLLING_FRICTION_SLOW, 850);
|
||||
FRICTION_FAST = getFloatPref(prefs, PREF_SCROLLING_FRICTION_FAST, 970);
|
||||
VELOCITY_THRESHOLD = getIntPref(prefs, PREF_SCROLLING_VELOCITY_THRESHOLD, 10);
|
||||
MAX_EVENT_ACCELERATION = getFloatPref(prefs, PREF_SCROLLING_MAX_EVENT_ACCELERATION, 12);
|
||||
OVERSCROLL_DECEL_RATE = getFloatPref(prefs, PREF_SCROLLING_OVERSCROLL_DECEL_RATE, 40);
|
||||
SNAP_LIMIT = getFloatPref(prefs, PREF_SCROLLING_OVERSCROLL_SNAP_LIMIT, 300);
|
||||
MIN_SCROLLABLE_DISTANCE = getFloatPref(prefs, PREF_SCROLLING_MIN_SCROLLABLE_DISTANCE, 500);
|
||||
Log.i(LOGTAG, "Prefs: " + FRICTION_SLOW + "," + FRICTION_FAST + "," + VELOCITY_THRESHOLD + ","
|
||||
+ MAX_EVENT_ACCELERATION + "," + OVERSCROLL_DECEL_RATE + "," + SNAP_LIMIT + "," + MIN_SCROLLABLE_DISTANCE);
|
||||
}
|
||||
|
||||
static {
|
||||
// set the scrolling parameters to default values on startup
|
||||
setPrefs(null);
|
||||
}
|
||||
|
||||
// The number of milliseconds per frame assuming 60 fps
|
||||
private static final float MS_PER_FRAME = 1000.0f / 60.0f;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче