Bug 817138: Private browsing support for Back/Forward buttons. [r=mfinkle]

--HG--
rename : mobile/android/base/resources/drawable/address_bar_back_button.xml => mobile/android/base/resources/drawable/address_bar_nav_button.xml.in
extra : rebase_source : 402a8d8202172a3480b8a10bd1e36ba107b9340b
This commit is contained in:
Sriram Ramasubramanian 2012-11-30 13:22:49 -08:00
parent 9e45a4e900
commit 6a35499ad9
6 changed files with 39 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import android.util.AttributeSet;
public class BackButton extends ShapedButton {
private Path mBorderPath;
private Paint mBorderPaint;
private Paint mBorderPrivatePaint;
public BackButton(Context context, AttributeSet attrs) {
super(context, attrs);
@ -29,6 +30,8 @@ public class BackButton extends ShapedButton {
mBorderPaint.setColor(0xFF000000);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPrivatePaint = new Paint(mBorderPaint);
// Path is masked.
mPath = new Path();
mBorderPath = new Path();
@ -44,6 +47,7 @@ public class BackButton extends ShapedButton {
float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
mBorderPaint.setStrokeWidth(borderWidth);
mBorderPrivatePaint.setStrokeWidth(borderWidth);
mBorderPath.reset();
mBorderPath.addCircle(width/2, height/2, (width/2) - borderWidth, Path.Direction.CW);
@ -52,6 +56,11 @@ public class BackButton extends ShapedButton {
0, height,
0xFF898D8F, 0xFFFEFEFE,
Shader.TileMode.CLAMP));
mBorderPrivatePaint.setShader(new LinearGradient(0, 0,
0, height,
0xCC06090D, 0xFF616569,
Shader.TileMode.CLAMP));
}
@Override
@ -59,7 +68,7 @@ public class BackButton extends ShapedButton {
mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
// Draw the border on top.
canvas.drawPath(mBorderPath, mBorderPaint);
canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
}
// The drawable is constructed as per @drawable/address_bar_nav_button.
@ -73,6 +82,7 @@ public class BackButton extends ShapedButton {
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
stateList.addState(new int[] { R.attr.state_private }, resources.getDrawable(R.drawable.address_bar_bg_private));
stateList.addState(new int[] {}, drawable);
setBackgroundDrawable(stateList);

View File

@ -996,6 +996,12 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
((GeckoTextView) mTabsCount.getCurrentView()).setPrivateMode(tab.isPrivate());
mTitle.setPrivateMode(tab.isPrivate());
mMenu.setPrivateMode(tab.isPrivate());
if (mBack instanceof BackButton)
((BackButton) mBack).setPrivateMode(tab.isPrivate());
if (mForward instanceof ForwardButton)
((ForwardButton) mForward).setPrivateMode(tab.isPrivate());
}
}

View File

@ -19,6 +19,7 @@ import android.util.AttributeSet;
public class ForwardButton extends ShapedButton {
private Path mBorderPath;
private Paint mBorderPaint;
private Paint mBorderPrivatePaint;
public ForwardButton(Context context, AttributeSet attrs) {
super(context, attrs);
@ -29,6 +30,8 @@ public class ForwardButton extends ShapedButton {
mBorderPaint.setColor(0xFF000000);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPrivatePaint = new Paint(mBorderPaint);
mBorderPath = new Path();
}
@ -38,6 +41,7 @@ public class ForwardButton extends ShapedButton {
float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
mBorderPaint.setStrokeWidth(borderWidth);
mBorderPrivatePaint.setStrokeWidth(borderWidth);
mBorderPath.reset();
mBorderPath.moveTo(width - borderWidth, 0);
@ -47,6 +51,11 @@ public class ForwardButton extends ShapedButton {
0, height,
0xFF898D8F, 0xFFFEFEFE,
Shader.TileMode.CLAMP));
mBorderPrivatePaint.setShader(new LinearGradient(0, 0,
0, height,
0xCC06090D, 0xFF616569,
Shader.TileMode.CLAMP));
}
@Override
@ -54,7 +63,7 @@ public class ForwardButton extends ShapedButton {
super.draw(canvas);
// Draw the border on top.
canvas.drawPath(mBorderPath, mBorderPaint);
canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
}
// The drawable is constructed as per @drawable/address_bar_nav_button.
@ -68,6 +77,7 @@ public class ForwardButton extends ShapedButton {
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
stateList.addState(new int[] { R.attr.state_private }, resources.getDrawable(R.drawable.address_bar_bg_private));
stateList.addState(new int[] {}, drawable);
setBackgroundDrawable(stateList);

View File

@ -27,6 +27,10 @@ public class Gecko@VIEWTYPE@ extends @VIEWTYPE@ {
return drawableState;
}
public boolean isPrivateMode() {
return mIsPrivate;
}
public void setPrivateMode(boolean isPrivate) {
if (mIsPrivate != isPrivate) {
mIsPrivate = isPrivate;

View File

@ -228,6 +228,7 @@ FENNEC_PP_XML_FILES = \
res/color/awesome_bar_title_hint.xml \
res/color/tabs_counter_color.xml \
res/drawable/address_bar_bg.xml \
res/drawable/address_bar_nav_button.xml \
res/drawable/address_bar_url.xml \
res/drawable/awesomebar_tabs_bg.xml \
res/drawable/menu_level.xml \
@ -1034,7 +1035,6 @@ MOZ_ANDROID_DRAWABLES += \
mobile/android/base/resources/drawable/address_bar_bg_normal.xml \
mobile/android/base/resources/drawable/address_bar_bg_private.xml \
mobile/android/base/resources/drawable/address_bar_bg_shadow_repeat.xml \
mobile/android/base/resources/drawable/address_bar_nav_button.xml \
mobile/android/base/resources/drawable/autocomplete_list_bg.9.png \
mobile/android/base/resources/drawable/awesomebar_tab_indicator.xml \
mobile/android/base/resources/drawable/awesomebar_tab_selected.xml \

View File

@ -1,13 +1,18 @@
#filter substitution
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res/@ANDROID_PACKAGE_NAME@">
<!-- pressed state -->
<item android:state_pressed="true" android:drawable="@drawable/highlight"/>
<!-- private browsing mode -->
<item gecko:state_private="true" android:drawable="@drawable/address_bar_bg_private"/>
<!-- normal mode -->
<item android:drawable="@drawable/address_bar_bg_normal"/>