summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java')
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java b/mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java
new file mode 100644
index 000000000..0b6a30d7a
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java
@@ -0,0 +1,70 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.tabs;
+
+import android.graphics.Path;
+
+/**
+ * Utility methods to draws Firefox's tab curve shape.
+ */
+public class TabCurve {
+
+ public enum Direction {
+ LEFT(-1),
+ RIGHT(1);
+
+ private final int value;
+
+ private Direction(int value) {
+ this.value = value;
+ }
+ }
+
+ // Curve's aspect ratio
+ private static final float ASPECT_RATIO = 0.729f;
+
+ // Width multipliers
+ private static final float W_M1 = 0.343f;
+ private static final float W_M2 = 0.514f;
+ private static final float W_M3 = 0.49f;
+ private static final float W_M4 = 0.545f;
+ private static final float W_M5 = 0.723f;
+
+ // Height multipliers
+ private static final float H_M1 = 0.25f;
+ private static final float H_M2 = 0.5f;
+ private static final float H_M3 = 0.72f;
+ private static final float H_M4 = 0.961f;
+
+ private TabCurve() {
+ }
+
+ public static float getWidthForHeight(float height) {
+ return (int) (height * ASPECT_RATIO);
+ }
+
+ public static void drawFromTop(Path path, float from, float height, Direction dir) {
+ final float width = getWidthForHeight(height);
+
+ path.cubicTo(from + width * W_M1 * dir.value, 0.0f,
+ from + width * W_M3 * dir.value, height * H_M1,
+ from + width * W_M2 * dir.value, height * H_M2);
+ path.cubicTo(from + width * W_M4 * dir.value, height * H_M3,
+ from + width * W_M5 * dir.value, height * H_M4,
+ from + width * dir.value, height);
+ }
+
+ public static void drawFromBottom(Path path, float from, float height, Direction dir) {
+ final float width = getWidthForHeight(height);
+
+ path.cubicTo(from + width * (1f - W_M5) * dir.value, height * H_M4,
+ from + width * (1f - W_M4) * dir.value, height * H_M3,
+ from + width * (1f - W_M2) * dir.value, height * H_M2);
+ path.cubicTo(from + width * (1f - W_M3) * dir.value, height * H_M1,
+ from + width * (1f - W_M1) * dir.value, 0.0f,
+ from + width * dir.value, 0.0f);
+ }
+}