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(); 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( mozilla::ipc::IPCResult BrowserChild::RecvSuppressDisplayport(
const bool& aEnabled) { const bool& aEnabled) {
if (RefPtr<PresShell> presShell = GetTopLevelPresShell()) { if (RefPtr<PresShell> presShell = GetTopLevelPresShell()) {

View File

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

View File

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

View File

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

View File

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

View File

@ -10418,6 +10418,10 @@ static void SetPluginIsActive(nsISupports* aSupports, void* aClosure) {
nsresult PresShell::SetIsActive(bool aIsActive) { nsresult PresShell::SetIsActive(bool aIsActive) {
MOZ_ASSERT(mDocument, "should only be called with a document"); MOZ_ASSERT(mDocument, "should only be called with a document");
#if defined(MOZ_WIDGET_ANDROID)
const bool changed = mIsActive != aIsActive;
#endif
mIsActive = aIsActive; mIsActive = aIsActive;
nsPresContext* presContext = GetPresContext(); nsPresContext* presContext = GetPresContext();
@ -10439,6 +10443,17 @@ nsresult PresShell::SetIsActive(bool aIsActive) {
} }
} }
#endif // #ifdef ACCESSIBILITY #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; return rv;
} }

View File

@ -2535,6 +2535,19 @@ void nsPresContext::AdjustSizeForViewportUnits() {
NSIntPixelsToAppUnits(mDynamicToolbarMaxHeight, mCurAppUnitsPerDevPixel); 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 #ifdef DEBUG
void nsPresContext::ValidatePresShellAndDocumentReleation() const { void nsPresContext::ValidatePresShellAndDocumentReleation() const {

View File

@ -392,6 +392,11 @@ class nsPresContext : public nsISupports,
return mDynamicToolbarMaxHeight > 0; 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 * Return true if this presentation context is a paginated
* context. * context.

View File

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

View File

@ -999,6 +999,43 @@ void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
nsContentUtils::CallOnAllRemoteChildren( nsContentUtils::CallOnAllRemoteChildren(
window, NotifyDynamicToolbarMaxHeightChanged, &aHeight); 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 #endif
bool nsView::RequestWindowClose(nsIWidget* aWidget) { bool nsView::RequestWindowClose(nsIWidget* aWidget) {

View File

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

View File

@ -1090,11 +1090,18 @@ class nsWindow::LayerViewSupport final
} }
void SetFixedBottomOffset(int32_t aOffset) { void SetFixedBottomOffset(int32_t aOffset) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread()); if (mWindow) {
mWindow->UpdateDynamicToolbarOffset(ScreenIntCoord(aOffset));
}
if (RefPtr<UiCompositorControllerChild> child = if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
GetUiCompositorControllerChild()) { uiThread->Dispatch(NS_NewRunnableFunction(
child->SetFixedBottomOffset(aOffset); "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) { nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) {
nsXPLookAndFeel::GetInstance()->SetPrefersReducedMotionOverrideForTest( nsXPLookAndFeel::GetInstance()->SetPrefersReducedMotionOverrideForTest(
aValue); aValue);

View File

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

View File

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

View File

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