Bug 716403 - Hide dynamic toolbar hiding behind a pref. r=kats

Disable dynamic toolbar hiding on Android by default, with pref
browser.chrome.dynamictoolbar available to enable it.
This commit is contained in:
Chris Lord 2013-03-07 10:17:34 +00:00
parent 8e1fe3f64f
commit 6f9b717288
5 changed files with 118 additions and 27 deletions

View File

@ -682,6 +682,9 @@ pref("memory.free_dirty_pages", true);
pref("layout.imagevisibility.enabled", false);
// Disable the dynamic toolbar
pref("browser.chrome.dynamictoolbar", false);
#ifdef MOZ_PKG_SPECIAL
// Disable webgl on ARMv6 because running the reftests takes
// too long for some reason (bug 843738)

View File

@ -59,6 +59,8 @@ abstract public class BrowserApp extends GeckoApp
PropertyAnimator.PropertyAnimationListener {
private static final String LOGTAG = "GeckoBrowserApp";
private static final String PREF_CHROME_DYNAMICTOOLBAR = "browser.chrome.dynamictoolbar";
public static BrowserToolbar mBrowserToolbar;
private AboutHomeContent mAboutHomeContent;
private Boolean mAboutHomeShowing = null;
@ -95,6 +97,8 @@ abstract public class BrowserApp extends GeckoApp
// Variables used for scrolling the toolbar on/off the page.
private static final int TOOLBAR_ONLOAD_HIDE_DELAY = 2000;
private boolean mDynamicToolbarEnabled = false;
private View mToolbarSpacer = null;
private float mLastTouchY = 0.0f;
private float mToolbarSubpixelAccumulation = 0.0f;
private boolean mToolbarLocked = true;
@ -112,9 +116,11 @@ abstract public class BrowserApp extends GeckoApp
if ("about:home".equals(tab.getURL())) {
showAboutHome();
// Show the toolbar immediately.
mBrowserToolbar.animateVisibility(true, 0);
mToolbarLocked = true;
if (mDynamicToolbarEnabled) {
// Show the toolbar immediately.
mBrowserToolbar.animateVisibility(true, 0);
mToolbarLocked = true;
}
} else {
hideAboutHome();
}
@ -140,16 +146,20 @@ abstract public class BrowserApp extends GeckoApp
if (Tabs.getInstance().isSelectedTab(tab)) {
invalidateOptionsMenu();
// Show the toolbar.
mBrowserToolbar.animateVisibility(true, 0);
if (mDynamicToolbarEnabled) {
// Show the toolbar.
mBrowserToolbar.animateVisibility(true, 0);
}
}
break;
case LOAD_ERROR:
case STOP:
if (Tabs.getInstance().isSelectedTab(tab)) {
if (!mAboutHomeShowing) {
// Hide the toolbar after a delay.
mBrowserToolbar.animateVisibility(false, TOOLBAR_ONLOAD_HIDE_DELAY);
if (mDynamicToolbarEnabled) {
// Hide the toolbar after a delay.
mBrowserToolbar.animateVisibility(false, TOOLBAR_ONLOAD_HIDE_DELAY);
}
}
}
// fall through
@ -182,6 +192,10 @@ abstract public class BrowserApp extends GeckoApp
@Override
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
if (!mDynamicToolbarEnabled) {
return super.onInterceptTouchEvent(view, event);
}
int action = event.getActionMasked();
int pointerCount = event.getPointerCount();
@ -319,8 +333,10 @@ abstract public class BrowserApp extends GeckoApp
super.onCreate(savedInstanceState);
mToolbarSpacer = findViewById(R.id.toolbar_spacer);
LinearLayout actionBar = (LinearLayout) getActionBarLayout();
mMainLayout.addView(actionBar, 1);
mMainLayout.addView(actionBar, 2);
((GeckoApp.MainLayout) mMainLayout).setOnInterceptTouchListener(new HideTabsTouchListener());
@ -359,6 +375,35 @@ abstract public class BrowserApp extends GeckoApp
}, this);
}
}
// Load the dynamic toolbar pref
PrefsHelper.getPref(PREF_CHROME_DYNAMICTOOLBAR, new PrefsHelper.PrefHandlerBase() {
@Override
public void prefValue(String pref, boolean value) {
if (value == mDynamicToolbarEnabled) {
return;
}
mDynamicToolbarEnabled = value;
mMainHandler.post(new Runnable() {
@Override
public void run() {
if (mDynamicToolbarEnabled) {
mToolbarSpacer.setPadding(0, 0, 0, 0);
} else {
// Immediately show the toolbar when disabling the dynamic
// toolbar.
mBrowserToolbar.cancelVisibilityAnimation();
mBrowserToolbar.getLayout().scrollTo(0, 0);
}
// Refresh the margins to reset the padding on the spacer and
// make sure that Gecko is in sync.
((BrowserToolbarLayout)mBrowserToolbar.getLayout()).refreshMargins();
}
});
}
});
}
@Override
@ -431,6 +476,36 @@ abstract public class BrowserApp extends GeckoApp
}
}
public void setToolbarHeight(int aHeight, int aVisibleHeight) {
if (!mDynamicToolbarEnabled || Boolean.TRUE.equals(mAboutHomeShowing)) {
// Use aVisibleHeight here so that when the dynamic toolbar is
// enabled, the padding will animate with the toolbar becoming
// visible.
if (mDynamicToolbarEnabled) {
// When the dynamic toolbar is enabled, set the padding on the
// about:home widget directly - this is to avoid resizing the
// LayerView, which can cause visible artifacts.
mAboutHomeContent.setPadding(0, aVisibleHeight, 0, 0);
} else {
mToolbarSpacer.setPadding(0, aVisibleHeight, 0, 0);
}
aHeight = aVisibleHeight = 0;
} else {
mToolbarSpacer.setPadding(0, 0, 0, 0);
}
// In the current UI, this is the only place we have need of
// viewport margins (to stop the toolbar from obscuring fixed-pos
// content).
GeckoAppShell.sendEventToGecko(
GeckoEvent.createBroadcastEvent("Viewport:FixedMarginsChanged",
"{ \"top\" : " + aHeight + ", \"right\" : 0, \"bottom\" : 0, \"left\" : 0 }"));
if (mLayerView != null) {
mLayerView.getLayerClient().setFixedLayerMargins(0, aVisibleHeight, 0, 0);
}
}
@Override
void toggleChrome(final boolean aShow) {
mMainHandler.post(new Runnable() {
@ -473,10 +548,6 @@ abstract public class BrowserApp extends GeckoApp
mBrowserToolbar.from(actionBar);
mBrowserToolbar.refresh();
if (mAboutHomeContent != null) {
mAboutHomeContent.setPadding(0, mBrowserToolbar.getLayout().getHeight(), 0, 0);
}
// The favicon view is different now, so we need to update the DoorHangerPopup anchor view.
if (mDoorHangerPopup != null)
mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);
@ -889,6 +960,9 @@ abstract public class BrowserApp extends GeckoApp
mAboutHomeShowing = true;
Runnable r = new AboutHomeRunnable(true);
mMainHandler.postAtFrontOfQueue(r);
// Refresh margins to possibly remove the toolbar padding
((BrowserToolbarLayout)mBrowserToolbar.getLayout()).refreshMargins();
}
private void hideAboutHome() {
@ -901,6 +975,9 @@ abstract public class BrowserApp extends GeckoApp
mAboutHomeShowing = false;
Runnable r = new AboutHomeRunnable(false);
mMainHandler.postAtFrontOfQueue(r);
// Refresh margins to possibly restore the toolbar padding
((BrowserToolbarLayout)mBrowserToolbar.getLayout()).refreshMargins();
}
private class AboutHomeRunnable implements Runnable {
@ -929,7 +1006,6 @@ abstract public class BrowserApp extends GeckoApp
mAboutHomeStartupTimer.stop();
}
});
mAboutHomeContent.setPadding(0, mBrowserToolbar.getLayout().getHeight(), 0, 0);
} else {
mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES,
AboutHomeContent.UpdateFlags.REMOTE_TABS));

View File

@ -45,22 +45,21 @@ public class BrowserToolbarLayout extends LinearLayout {
super.onSizeChanged(w, h, oldw, oldh);
if (h != oldh) {
// In the current UI, this is the only place we have need of
// viewport margins (to stop the toolbar from obscuring fixed-pos
// content).
GeckoAppShell.sendEventToGecko(
GeckoEvent.createBroadcastEvent("Viewport:FixedMarginsChanged",
"{ \"top\" : " + h + ", \"right\" : 0, \"bottom\" : 0, \"left\" : 0 }"));
refreshMargins();
// Post this to happen outside of onSizeChanged, as this may cause
// a layout change and relayouts within a layout change don't work.
post(new Runnable() {
@Override
public void run() {
refreshMargins();
}
});
}
}
public void refreshMargins() {
LayerView view = GeckoApp.mAppContext.getLayerView();
if (view != null) {
view.getLayerClient().setFixedLayerMargins(0, getHeight() - getScrollY(), 0, 0);
}
int height = getHeight();
int visibleHeight = height - getScrollY();
((BrowserApp)GeckoApp.mAppContext).setToolbarHeight(height, visibleHeight);
}
}

View File

@ -371,6 +371,14 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
*/
public void setFixedLayerMargins(float left, float top, float right, float bottom) {
ImmutableViewportMetrics oldMetrics = getViewportMetrics();
if (oldMetrics.fixedLayerMarginLeft == left &&
oldMetrics.fixedLayerMarginTop == top &&
oldMetrics.fixedLayerMarginRight == right &&
oldMetrics.fixedLayerMarginBottom == bottom) {
// Do nothing if the margins haven't changed.
return;
}
ImmutableViewportMetrics newMetrics = oldMetrics.setFixedLayerMargins(left, top, right, bottom);
if (mClampOnMarginChange) {

View File

@ -17,13 +17,18 @@
<view class="org.mozilla.gecko.GeckoApp$MainLayout"
android:id="@+id/main_layout"
style="@style/Screen.Transparent">
<!-- BrowserToolbar will be added dynamically -->
<FrameLayout android:id="@+id/toolbar_spacer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout android:id="@+id/gecko_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
android:layout_weight="1"
android:layout_below="@+id/toolbar_spacer">
<include layout="@layout/shared_ui_components"/>