diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 9e1d3237a55..6d584286840 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -166,6 +166,12 @@ abstract public class BrowserApp extends GeckoApp private BrowserHealthReporter mBrowserHealthReporter; + // The animator used to toggle HomePager visibility has a race where if the HomePager is shown + // (starting the animation), the HomePager is hidden, and the HomePager animation completes, + // both the web content and the HomePager will be hidden. This flag is used to prevent the + // race by determining if the web content should be hidden at the animation's end. + private boolean mHideWebContentOnAnimationEnd = false; + private SiteIdentityPopup mSiteIdentityPopup; public SiteIdentityPopup getSiteIdentityPopup() { @@ -1573,7 +1579,38 @@ abstract public class BrowserApp extends GeckoApp final ViewStub homePagerStub = (ViewStub) findViewById(R.id.home_pager_stub); mHomePager = (HomePager) homePagerStub.inflate(); } + mHomePager.show(getSupportFragmentManager(), page, animator); + + // Hide the web content so it cannot be focused by screen readers. + hideWebContentOnPropertyAnimationEnd(animator); + } + + private void hideWebContentOnPropertyAnimationEnd(final PropertyAnimator animator) { + if (animator == null) { + hideWebContent(); + return; + } + + animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { + @Override + public void onPropertyAnimationStart() { + mHideWebContentOnAnimationEnd = true; + } + + @Override + public void onPropertyAnimationEnd() { + if (mHideWebContentOnAnimationEnd) { + hideWebContent(); + } + } + }); + } + + private void hideWebContent() { + // The view is set to INVISIBLE, rather than GONE, to avoid + // the additional requestLayout() call. + mLayerView.setVisibility(View.INVISIBLE); } private void hideHomePager() { @@ -1586,6 +1623,12 @@ abstract public class BrowserApp extends GeckoApp return; } + // Prevent race in hiding web content - see declaration for more info. + mHideWebContentOnAnimationEnd = false; + + // Display the previously hidden web content (which prevented screen reader access). + mLayerView.setVisibility(View.VISIBLE); + if (mHomePager != null) { mHomePager.hide(); }