Bug 1586986 - Deliver 'fixed-bottom' offset to the top of the pres context on the foreground tab. r=geckoview-reviewers,tnikkel,snorp

The dynamic toolbar transition doesn't affect on background tabs since to
switch tabs the dynamic toolbar should be restored to its original state (i.e.,
completely visible state).

Differential Revision: https://phabricator.services.mozilla.com/D52336

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-11-21 21:15:46 +00:00
parent 6aae1c4aaa
commit 9b165804d8
15 changed files with 125 additions and 5 deletions

View File

@ -1349,6 +1349,21 @@ mozilla::ipc::IPCResult BrowserChild::RecvDynamicToolbarMaxHeightChanged(
return IPC_OK();
}
mozilla::ipc::IPCResult BrowserChild::RecvDynamicToolbarOffsetChanged(
const ScreenIntCoord& aOffset) {
#if defined(MOZ_WIDGET_ANDROID)
RefPtr<Document> document = GetTopLevelDocument();
if (!document) {
return IPC_OK();
}
if (nsPresContext* presContext = document->GetPresContext()) {
presContext->UpdateDynamicToolbarOffset(aOffset);
}
#endif
return IPC_OK();
}
mozilla::ipc::IPCResult BrowserChild::RecvSuppressDisplayport(
const bool& aEnabled) {
if (RefPtr<PresShell> presShell = GetTopLevelPresShell()) {

View File

@ -293,6 +293,9 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
mozilla::ipc::IPCResult RecvDynamicToolbarMaxHeightChanged(
const mozilla::ScreenIntCoord& aHeight);
mozilla::ipc::IPCResult RecvDynamicToolbarOffsetChanged(
const mozilla::ScreenIntCoord& aOffset);
mozilla::ipc::IPCResult RecvActivate();
mozilla::ipc::IPCResult RecvDeactivate();

View File

@ -1097,6 +1097,12 @@ void BrowserParent::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
Unused << SendDynamicToolbarMaxHeightChanged(aHeight);
}
}
void BrowserParent::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
if (!mIsDestroyed) {
Unused << SendDynamicToolbarOffsetChanged(aOffset);
}
}
#endif
void BrowserParent::HandleAccessKey(const WidgetKeyboardEvent& aEvent,

View File

@ -535,6 +535,7 @@ class BrowserParent final : public PBrowserParent,
#if defined(MOZ_WIDGET_ANDROID)
void DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight);
void DynamicToolbarOffsetChanged(ScreenIntCoord aOffset);
#endif
void Activate();

View File

@ -753,6 +753,8 @@ child:
async DynamicToolbarMaxHeightChanged(ScreenIntCoord height);
async DynamicToolbarOffsetChanged(ScreenIntCoord height);
async ParentActivated(bool aActivated);
async SetKeyboardIndicators(UIStateChangeType showFocusRings);

View File

@ -10418,6 +10418,10 @@ static void SetPluginIsActive(nsISupports* aSupports, void* aClosure) {
nsresult PresShell::SetIsActive(bool aIsActive) {
MOZ_ASSERT(mDocument, "should only be called with a document");
#if defined(MOZ_WIDGET_ANDROID)
const bool changed = mIsActive != aIsActive;
#endif
mIsActive = aIsActive;
nsPresContext* presContext = GetPresContext();
@ -10439,6 +10443,17 @@ nsresult PresShell::SetIsActive(bool aIsActive) {
}
}
#endif // #ifdef ACCESSIBILITY
#if defined(MOZ_WIDGET_ANDROID)
if (changed && !aIsActive && presContext &&
presContext->IsRootContentDocumentCrossProcess()) {
if (BrowserChild* browserChild = BrowserChild::GetFrom(this)) {
// Reset the dynamic toolbar offset state.
presContext->UpdateDynamicToolbarOffset(0);
}
}
#endif
return rv;
}

View File

@ -2535,6 +2535,19 @@ void nsPresContext::AdjustSizeForViewportUnits() {
NSIntPixelsToAppUnits(mDynamicToolbarMaxHeight, mCurAppUnitsPerDevPixel);
}
void nsPresContext::UpdateDynamicToolbarOffset(ScreenIntCoord aOffset) {
MOZ_ASSERT(IsRootContentDocumentCrossProcess());
if (!mPresShell) {
return;
}
if (!HasDynamicToolbar()) {
return;
}
MOZ_ASSERT(-mDynamicToolbarMaxHeight <= aOffset && aOffset <= 0);
}
#ifdef DEBUG
void nsPresContext::ValidatePresShellAndDocumentReleation() const {

View File

@ -392,6 +392,11 @@ class nsPresContext : public nsISupports,
return mDynamicToolbarMaxHeight > 0;
}
/*
* |aOffset| must be offset from the bottom edge of the ICB and it's negative.
*/
void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
/**
* Return true if this presentation context is a paginated
* context.

View File

@ -222,7 +222,7 @@ public class GeckoSession implements Parcelable {
@WrapForJNI(calledFrom = "ui", dispatchTo = "current")
public native void setMaxToolbarHeight(int height);
@WrapForJNI(calledFrom = "ui", dispatchTo = "current")
@WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
public native void setFixedBottomOffset(int offset);
@WrapForJNI(calledFrom = "ui", dispatchTo = "current")

View File

@ -999,6 +999,43 @@ void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
nsContentUtils::CallOnAllRemoteChildren(
window, NotifyDynamicToolbarMaxHeightChanged, &aHeight);
}
static bool NotifyDynamicToolbarOffsetChanged(
dom::BrowserParent* aBrowserParent, void* aArg) {
// Skip background tabs.
if (!aBrowserParent->GetDocShellIsActive()) {
return false;
}
ScreenIntCoord* offset = static_cast<ScreenIntCoord*>(aArg);
aBrowserParent->DynamicToolbarOffsetChanged(*offset);
return true;
}
void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
MOZ_ASSERT(XRE_IsParentProcess(),
"Should be only called for the browser parent process");
MOZ_ASSERT(this == mViewManager->GetRootView(),
"Should be called for the root view");
PresShell* presShell = mViewManager->GetPresShell();
if (!presShell) {
return;
}
dom::Document* document = presShell->GetDocument();
if (!document) {
return;
}
nsPIDOMWindowOuter* window = document->GetWindow();
if (!window) {
return;
}
nsContentUtils::CallOnAllRemoteChildren(
window, NotifyDynamicToolbarOffsetChanged, &aOffset);
}
#endif
bool nsView::RequestWindowClose(nsIWidget* aWidget) {

View File

@ -452,6 +452,8 @@ class nsView final : public nsIWidgetListener {
#if defined(MOZ_WIDGET_ANDROID)
virtual void DynamicToolbarMaxHeightChanged(
mozilla::ScreenIntCoord aHeight) override;
virtual void DynamicToolbarOffsetChanged(
mozilla::ScreenIntCoord aOffset) override;
#endif
virtual bool RequestWindowClose(nsIWidget* aWidget) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY

View File

@ -1090,11 +1090,18 @@ class nsWindow::LayerViewSupport final
}
void SetFixedBottomOffset(int32_t aOffset) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
if (mWindow) {
mWindow->UpdateDynamicToolbarOffset(ScreenIntCoord(aOffset));
}
if (RefPtr<UiCompositorControllerChild> child =
GetUiCompositorControllerChild()) {
child->SetFixedBottomOffset(aOffset);
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
uiThread->Dispatch(NS_NewRunnableFunction(
"LayerViewSupport::SetFixedBottomOffset", [this, offset = aOffset] {
if (RefPtr<UiCompositorControllerChild> child =
GetUiCompositorControllerChild()) {
child->SetFixedBottomOffset(offset);
}
}));
}
}
@ -2326,6 +2333,16 @@ void nsWindow::UpdateDynamicToolbarMaxHeight(ScreenIntCoord aHeight) {
}
}
void nsWindow::UpdateDynamicToolbarOffset(ScreenIntCoord aOffset) {
if (mWidgetListener) {
mWidgetListener->DynamicToolbarOffsetChanged(aOffset);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->DynamicToolbarOffsetChanged(aOffset);
}
}
nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) {
nsXPLookAndFeel::GetInstance()->SetPrefersReducedMotionOverrideForTest(
aValue);

View File

@ -330,6 +330,8 @@ class nsWindow final : public nsBaseWidget {
nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) override;
nsresult ResetPrefersReducedMotionOverrideForTest() override;
void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
protected:
void BringToFront();
nsWindow* FindTopLevel();

View File

@ -38,6 +38,7 @@ void nsIWidgetListener::UIResolutionChanged() {}
#if defined(MOZ_WIDGET_ANDROID)
void nsIWidgetListener::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
}
void nsIWidgetListener::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {}
#endif
void nsIWidgetListener::FullscreenWillChange(bool aInFullscreen) {}

View File

@ -87,6 +87,7 @@ class nsIWidgetListener {
#if defined(MOZ_WIDGET_ANDROID)
virtual void DynamicToolbarMaxHeightChanged(mozilla::ScreenIntCoord aHeight);
virtual void DynamicToolbarOffsetChanged(mozilla::ScreenIntCoord aOffset);
#endif
/**