Bug 1055576 - Factor out code to draw tab curves (r=mcomella)

This commit is contained in:
Lucas Rocha 2014-08-21 17:14:28 +01:00
parent c288e10874
commit e847d2234b
3 changed files with 71 additions and 6 deletions

View File

@ -388,6 +388,7 @@ gbjar.sources += [
'tabs/RemoteTabsPanel.java',
'tabs/RemoteTabsSetupPanel.java',
'tabs/RemoteTabsVerificationPanel.java',
'tabs/TabCurve.java',
'tabs/TabsPanel.java',
'tabs/TabsTray.java',
'TabsAccessor.java',

View File

@ -0,0 +1,68 @@
/* -*- 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.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 int getWidthForHeight(int height) {
return (int) (height * ASPECT_RATIO);
}
public static void drawFromTop(Path path, int from, int height, Direction dir) {
final int width = getWidthForHeight(height);
path.cubicTo(from + width * W_M1 * dir.value, 0.0f,
from + width * W_M2 * dir.value, height * H_M1,
from + width * W_M2 * dir.value, height * H_M2);
path.cubicTo(from + width * W_M2 * dir.value, height * H_M3,
from + width * W_M3 * dir.value, height * H_M4,
from + width * dir.value, height);
}
public static void drawFromBottom(Path path, int from, int height, Direction dir) {
final int width = getWidthForHeight(height);
path.cubicTo(from + width * (1f - W_M3) * dir.value, height * H_M4,
from + width * (1f - W_M2) * dir.value, height * H_M3,
from + width * (1f - W_M2) * dir.value, height * H_M2);
path.cubicTo(from + width * (1f - W_M2) * dir.value, height * H_M1,
from + width * (1f - W_M1) * dir.value, 0.0f,
from + width * dir.value, 0.0f);
}
}

View File

@ -8,6 +8,7 @@ import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.LightweightTheme;
import org.mozilla.gecko.LightweightThemeDrawable;
import org.mozilla.gecko.R;
import org.mozilla.gecko.tabs.TabCurve;
import org.mozilla.gecko.widget.ThemedImageButton;
import android.content.Context;
@ -63,12 +64,7 @@ public class ShapedButton extends ThemedImageButton
if (mSide == CurveTowards.RIGHT) {
mPath.moveTo(0, 0);
mPath.cubicTo(height * 0.25f, 0.0f,
height * 0.375f, height * 0.25f,
height * 0.375f, height * 0.5f);
mPath.cubicTo(height * 0.375f, height * 0.72f,
height * 0.527f, height * 0.961f,
height * 0.729f, height);
TabCurve.drawFromTop(mPath, 0, height, TabCurve.Direction.RIGHT);
mPath.lineTo(width, height);
mPath.lineTo(width, 0);
mPath.lineTo(0, 0);