Skip to content

Commit 56a2fb3

Browse files
committedJul 18, 2024
Bug 1831649 - Propagate the software keyboard height change into nsPresContext. r=botond,geckoview-reviewers,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D204166
1 parent a1b5fad commit 56a2fb3

File tree

14 files changed

+145
-54
lines changed

14 files changed

+145
-54
lines changed
 

‎dom/ipc/BrowserChild.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ BrowserChild::BrowserChild(ContentChild* aManager, const TabId& aTabId,
278278
mLayersId{0},
279279
mEffectsInfo{EffectsInfo::FullyHidden()},
280280
mDynamicToolbarMaxHeight(0),
281+
mKeyboardHeight(0),
281282
mUniqueId(aTabId),
282283
mDidFakeShow(false),
283284
mTriedBrowserInit(false),
@@ -1237,6 +1238,23 @@ mozilla::ipc::IPCResult BrowserChild::RecvDynamicToolbarOffsetChanged(
12371238
return IPC_OK();
12381239
}
12391240

1241+
mozilla::ipc::IPCResult BrowserChild::RecvKeyboardHeightChanged(
1242+
const ScreenIntCoord& aHeight) {
1243+
#if defined(MOZ_WIDGET_ANDROID)
1244+
mKeyboardHeight = aHeight;
1245+
1246+
RefPtr<Document> document = GetTopLevelDocument();
1247+
if (!document) {
1248+
return IPC_OK();
1249+
}
1250+
1251+
if (nsPresContext* presContext = document->GetPresContext()) {
1252+
presContext->UpdateKeyboardHeight(aHeight);
1253+
}
1254+
#endif
1255+
return IPC_OK();
1256+
}
1257+
12401258
mozilla::ipc::IPCResult BrowserChild::RecvSuppressDisplayport(
12411259
const bool& aEnabled) {
12421260
if (RefPtr<PresShell> presShell = GetTopLevelPresShell()) {

‎dom/ipc/BrowserChild.h

+6
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
284284
mozilla::ipc::IPCResult RecvDynamicToolbarOffsetChanged(
285285
const mozilla::ScreenIntCoord& aOffset);
286286

287+
mozilla::ipc::IPCResult RecvKeyboardHeightChanged(
288+
const mozilla::ScreenIntCoord& aHeight);
289+
287290
mozilla::ipc::IPCResult RecvActivate(uint64_t aActionId);
288291

289292
mozilla::ipc::IPCResult RecvDeactivate(uint64_t aActionId);
@@ -543,6 +546,7 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
543546
ScreenIntCoord GetDynamicToolbarMaxHeight() const {
544547
return mDynamicToolbarMaxHeight;
545548
};
549+
mozilla::ScreenIntCoord GetKeyboardHeight() const { return mKeyboardHeight; }
546550

547551
bool IPCOpen() const { return mIPCOpen; }
548552

@@ -804,6 +808,8 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
804808
// NOTE: This value is valuable only for the top level browser.
805809
LayoutDeviceIntPoint mChromeOffset;
806810
ScreenIntCoord mDynamicToolbarMaxHeight;
811+
// The software keyboard height.
812+
ScreenIntCoord mKeyboardHeight;
807813
TabId mUniqueId;
808814

809815
bool mDidFakeShow : 1;

‎dom/ipc/BrowserParent.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,12 @@ void BrowserParent::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
12131213
Unused << SendDynamicToolbarOffsetChanged(aOffset);
12141214
}
12151215
}
1216+
1217+
void BrowserParent::KeyboardHeightChanged(ScreenIntCoord aHeight) {
1218+
if (!mIsDestroyed) {
1219+
Unused << SendKeyboardHeightChanged(aHeight);
1220+
}
1221+
}
12161222
#endif
12171223

12181224
void BrowserParent::HandleAccessKey(const WidgetKeyboardEvent& aEvent,

‎dom/ipc/BrowserParent.h

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ class BrowserParent final : public PBrowserParent,
487487
#if defined(MOZ_WIDGET_ANDROID)
488488
void DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight);
489489
void DynamicToolbarOffsetChanged(ScreenIntCoord aOffset);
490+
void KeyboardHeightChanged(ScreenIntCoord aHeight);
490491
#endif
491492

492493
void Activate(uint64_t aActionId);

‎dom/ipc/PBrowser.ipdl

+3-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,9 @@ child:
697697

698698
async DynamicToolbarMaxHeightChanged(ScreenIntCoord height);
699699

700-
async DynamicToolbarOffsetChanged(ScreenIntCoord height);
700+
async DynamicToolbarOffsetChanged(ScreenIntCoord offset);
701+
702+
async KeyboardHeightChanged(ScreenIntCoord height);
701703

702704
/**
703705
* StopIMEStateManagement() is called when the process loses focus and

‎layout/base/nsPresContext.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
246246
mCurAppUnitsPerDevPixel(0),
247247
mDynamicToolbarMaxHeight(0),
248248
mDynamicToolbarHeight(0),
249+
mKeyboardHeight(0),
249250
mPageSize(-1, -1),
250251
mPageScale(0.0),
251252
mPPScale(1.0f),
@@ -716,13 +717,15 @@ nsresult nsPresContext::Init(nsDeviceContext* aDeviceContext) {
716717
mEventManager->SetPresContext(this);
717718

718719
#if defined(MOZ_WIDGET_ANDROID)
719-
if (IsRootContentDocumentCrossProcess() &&
720-
MOZ_LIKELY(
721-
!Preferences::HasUserValue("layout.dynamic-toolbar-max-height"))) {
722-
if (BrowserChild* browserChild =
723-
BrowserChild::GetFrom(mDocument->GetDocShell())) {
724-
mDynamicToolbarMaxHeight = browserChild->GetDynamicToolbarMaxHeight();
725-
mDynamicToolbarHeight = mDynamicToolbarMaxHeight;
720+
if (IsRootContentDocumentCrossProcess()) {
721+
if (BrowserChild* browserChild = BrowserChild::GetFrom(GetDocShell())) {
722+
mKeyboardHeight = browserChild->GetKeyboardHeight();
723+
724+
if (MOZ_LIKELY(!Preferences::HasUserValue(
725+
"layout.dynamic-toolbar-max-height"))) {
726+
mDynamicToolbarMaxHeight = browserChild->GetDynamicToolbarMaxHeight();
727+
mDynamicToolbarHeight = mDynamicToolbarMaxHeight;
728+
}
726729
}
727730
}
728731
#endif
@@ -3054,6 +3057,11 @@ void nsPresContext::UpdateDynamicToolbarOffset(ScreenIntCoord aOffset) {
30543057
ServoStyleSet::OnlyDynamic::Yes);
30553058
}
30563059

3060+
void nsPresContext::UpdateKeyboardHeight(ScreenIntCoord aHeight) {
3061+
MOZ_ASSERT(IsRootContentDocumentCrossProcess());
3062+
mKeyboardHeight = aHeight;
3063+
}
3064+
30573065
DynamicToolbarState nsPresContext::GetDynamicToolbarState() const {
30583066
if (!IsRootContentDocumentCrossProcess() || !HasDynamicToolbar()) {
30593067
return DynamicToolbarState::None;

‎layout/base/nsPresContext.h

+4
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
433433
return mDynamicToolbarHeight;
434434
}
435435

436+
void UpdateKeyboardHeight(mozilla::ScreenIntCoord aHeight);
437+
436438
/**
437439
* Returns the state of the dynamic toolbar.
438440
*/
@@ -1219,6 +1221,8 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
12191221
// The maximum height of the dynamic toolbar on mobile.
12201222
mozilla::ScreenIntCoord mDynamicToolbarMaxHeight;
12211223
mozilla::ScreenIntCoord mDynamicToolbarHeight;
1224+
// The software keyboard height.
1225+
mozilla::ScreenIntCoord mKeyboardHeight;
12221226
// Safe area insets support
12231227
mozilla::ScreenIntMargin mSafeAreaInsets;
12241228
nsSize mPageSize;

‎mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java

+11
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ private void updateOverscrollOffset(final float x, final float y) {
411411
@WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
412412
public native void onSafeAreaInsetsChanged(int top, int right, int bottom, int left);
413413

414+
@WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
415+
public native void onKeyboardHeightChanged(int height);
416+
414417
@WrapForJNI(calledFrom = "ui")
415418
public void setPointerIcon(
416419
final int defaultCursor, final Bitmap customCursor, final float x, final float y) {
@@ -2639,6 +2642,10 @@ public void setActive(final boolean active) {
26392642
} else {
26402643
// Delete any pending memory pressure events since we're active again.
26412644
ThreadUtils.removeUiThreadCallbacks(mNotifyMemoryPressure);
2645+
2646+
if (mAttachedCompositor) {
2647+
mCompositor.onKeyboardHeightChanged(mKeyboardHeight);
2648+
}
26422649
}
26432650

26442651
ThreadUtils.runOnUiThread(() -> getAutofillSupport().onActiveChanged(active));
@@ -7905,6 +7912,10 @@ default void updateCursorAnchorInfo(
79057912
}
79067913

79077914
mKeyboardHeight = height;
7915+
7916+
if (mAttachedCompositor) {
7917+
mCompositor.onKeyboardHeightChanged(mKeyboardHeight);
7918+
}
79087919
}
79097920

79107921
/* package */ void setPointerIcon(

‎view/nsView.cpp

+39-46
Original file line numberDiff line numberDiff line change
@@ -921,23 +921,8 @@ void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
921921
MOZ_ASSERT(this == mViewManager->GetRootView(),
922922
"Should be called for the root view");
923923

924-
PresShell* presShell = mViewManager->GetPresShell();
925-
if (!presShell) {
926-
return;
927-
}
928-
929-
dom::Document* document = presShell->GetDocument();
930-
if (!document) {
931-
return;
932-
}
933-
934-
nsPIDOMWindowOuter* window = document->GetWindow();
935-
if (!window) {
936-
return;
937-
}
938-
939-
nsContentUtils::CallOnAllRemoteChildren(
940-
window, [&aHeight](dom::BrowserParent* aBrowserParent) -> CallState {
924+
CallOnAllRemoteChildren(
925+
[aHeight](dom::BrowserParent* aBrowserParent) -> CallState {
941926
aBrowserParent->DynamicToolbarMaxHeightChanged(aHeight);
942927
return CallState::Continue;
943928
});
@@ -948,30 +933,31 @@ void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
948933
"Should be only called for the browser parent process");
949934
MOZ_ASSERT(this == mViewManager->GetRootView(),
950935
"Should be called for the root view");
936+
CallOnAllRemoteChildren(
937+
[aOffset](dom::BrowserParent* aBrowserParent) -> CallState {
938+
// Skip background tabs.
939+
if (!aBrowserParent->GetDocShellIsActive()) {
940+
return CallState::Continue;
941+
}
951942

952-
PresShell* presShell = mViewManager->GetPresShell();
953-
if (!presShell) {
954-
return;
955-
}
956-
957-
dom::Document* document = presShell->GetDocument();
958-
if (!document) {
959-
return;
960-
}
961-
962-
nsPIDOMWindowOuter* window = document->GetWindow();
963-
if (!window) {
964-
return;
965-
}
943+
aBrowserParent->DynamicToolbarOffsetChanged(aOffset);
944+
return CallState::Stop;
945+
});
946+
}
966947

967-
nsContentUtils::CallOnAllRemoteChildren(
968-
window, [&aOffset](dom::BrowserParent* aBrowserParent) -> CallState {
948+
void nsView::KeyboardHeightChanged(ScreenIntCoord aHeight) {
949+
MOZ_ASSERT(XRE_IsParentProcess(),
950+
"Should be only called for the browser parent process");
951+
MOZ_ASSERT(this == mViewManager->GetRootView(),
952+
"Should be called for the root view");
953+
CallOnAllRemoteChildren(
954+
[aHeight](dom::BrowserParent* aBrowserParent) -> CallState {
969955
// Skip background tabs.
970956
if (!aBrowserParent->GetDocShellIsActive()) {
971957
return CallState::Continue;
972958
}
973959

974-
aBrowserParent->DynamicToolbarOffsetChanged(aOffset);
960+
aBrowserParent->KeyboardHeightChanged(aHeight);
975961
return CallState::Stop;
976962
});
977963
}
@@ -1092,6 +1078,24 @@ void nsView::SafeAreaInsetsChanged(const ScreenIntMargin& aSafeAreaInsets) {
10921078
// https://github.com/w3c/csswg-drafts/issues/4670
10931079
// Actually we don't set this value on sub document. This behaviour is
10941080
// same as Blink.
1081+
CallOnAllRemoteChildren([windowSafeAreaInsets](
1082+
dom::BrowserParent* aBrowserParent) -> CallState {
1083+
Unused << aBrowserParent->SendSafeAreaInsetsChanged(windowSafeAreaInsets);
1084+
return CallState::Continue;
1085+
});
1086+
}
1087+
1088+
bool nsView::IsPrimaryFramePaintSuppressed() {
1089+
return StaticPrefs::layout_show_previous_page() && mFrame &&
1090+
mFrame->PresShell()->IsPaintingSuppressed();
1091+
}
1092+
1093+
void nsView::CallOnAllRemoteChildren(
1094+
const std::function<CallState(dom::BrowserParent*)>& aCallback) {
1095+
PresShell* presShell = mViewManager->GetPresShell();
1096+
if (!presShell) {
1097+
return;
1098+
}
10951099

10961100
dom::Document* document = presShell->GetDocument();
10971101
if (!document) {
@@ -1103,16 +1107,5 @@ void nsView::SafeAreaInsetsChanged(const ScreenIntMargin& aSafeAreaInsets) {
11031107
return;
11041108
}
11051109

1106-
nsContentUtils::CallOnAllRemoteChildren(
1107-
window,
1108-
[windowSafeAreaInsets](dom::BrowserParent* aBrowserParent) -> CallState {
1109-
Unused << aBrowserParent->SendSafeAreaInsetsChanged(
1110-
windowSafeAreaInsets);
1111-
return CallState::Continue;
1112-
});
1113-
}
1114-
1115-
bool nsView::IsPrimaryFramePaintSuppressed() {
1116-
return StaticPrefs::layout_show_previous_page() && mFrame &&
1117-
mFrame->PresShell()->IsPaintingSuppressed();
1110+
nsContentUtils::CallOnAllRemoteChildren(window, aCallback);
11181111
}

‎view/nsView.h

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "nsIWidgetListener.h"
1616
#include "Units.h"
1717
#include "mozilla/Attributes.h"
18+
#include "mozilla/CallState.h"
1819
#include "mozilla/EventForwards.h"
1920
#include "mozilla/UniquePtr.h"
2021

@@ -24,6 +25,9 @@ class nsIFrame;
2425

2526
namespace mozilla {
2627
class PresShell;
28+
namespace dom {
29+
class BrowserParent;
30+
} // namespace dom
2731
namespace widget {
2832
struct InitData;
2933
enum class TransparencyMode : uint8_t;
@@ -429,6 +433,7 @@ class nsView final : public nsIWidgetListener {
429433
mozilla::ScreenIntCoord aHeight) override;
430434
virtual void DynamicToolbarOffsetChanged(
431435
mozilla::ScreenIntCoord aOffset) override;
436+
virtual void KeyboardHeightChanged(mozilla::ScreenIntCoord aHeight) override;
432437
#endif
433438
virtual bool RequestWindowClose(nsIWidget* aWidget) override;
434439
MOZ_CAN_RUN_SCRIPT_BOUNDARY
@@ -514,6 +519,10 @@ class nsView final : public nsIWidgetListener {
514519
// Update the cached RootViewManager for all view manager descendents.
515520
void InvalidateHierarchy();
516521

522+
void CallOnAllRemoteChildren(
523+
const std::function<mozilla::CallState(mozilla::dom::BrowserParent*)>&
524+
aCallback);
525+
517526
nsViewManager* mViewManager;
518527
nsView* mParent;
519528
nsCOMPtr<nsIWidget> mWindow;

‎widget/android/nsWindow.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,21 @@ class LayerViewSupport final
13151315
gkWindow->UpdateDynamicToolbarMaxHeight(ScreenIntCoord(aHeight));
13161316
}
13171317

1318+
void OnKeyboardHeightChanged(int32_t aHeight) {
1319+
MOZ_ASSERT(NS_IsMainThread());
1320+
auto win(mWindow.Access());
1321+
if (!win) {
1322+
return; // Already shut down.
1323+
}
1324+
1325+
nsWindow* gkWindow = win->GetNsWindow();
1326+
if (!gkWindow) {
1327+
return;
1328+
}
1329+
1330+
gkWindow->KeyboardHeightChanged(ScreenIntCoord(aHeight));
1331+
}
1332+
13181333
void SyncPauseCompositor() {
13191334
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
13201335

@@ -3259,6 +3274,16 @@ void nsWindow::UpdateDynamicToolbarOffset(ScreenIntCoord aOffset) {
32593274
}
32603275
}
32613276

3277+
void nsWindow::KeyboardHeightChanged(ScreenIntCoord aHeight) {
3278+
if (mWidgetListener) {
3279+
mWidgetListener->KeyboardHeightChanged(aHeight);
3280+
}
3281+
3282+
if (mAttachedWidgetListener) {
3283+
mAttachedWidgetListener->KeyboardHeightChanged(aHeight);
3284+
}
3285+
}
3286+
32623287
ScreenIntMargin nsWindow::GetSafeAreaInsets() const { return mSafeAreaInsets; }
32633288

32643289
void nsWindow::UpdateSafeAreaInsets(const ScreenIntMargin& aSafeAreaInsets) {

‎widget/android/nsWindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class nsWindow final : public nsBaseWidget {
245245
mozilla::ScreenIntMargin GetSafeAreaInsets() const override;
246246
void UpdateSafeAreaInsets(const mozilla::ScreenIntMargin& aSafeAreaInsets);
247247

248+
void KeyboardHeightChanged(mozilla::ScreenIntCoord aHeight);
249+
248250
mozilla::jni::NativeWeakPtr<mozilla::widget::NPZCSupport>
249251
GetNPZCSupportWeakPtr();
250252

‎widget/nsIWidgetListener.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void nsIWidgetListener::SafeAreaInsetsChanged(const mozilla::ScreenIntMargin&) {
4040
void nsIWidgetListener::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
4141
}
4242
void nsIWidgetListener::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {}
43+
void nsIWidgetListener::KeyboardHeightChanged(ScreenIntCoord aHeight) {}
4344
#endif
4445

4546
void nsIWidgetListener::MacFullscreenMenubarOverlapChanged(

0 commit comments

Comments
 (0)
Failed to load comments.