Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit fd1ab0f

Browse files
MortimerGorokeianhzo
authored andcommitted
Resize navbar on window focus change. Fix resizing glitches. (#1642)
1 parent 794aab0 commit fd1ab0f

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,16 @@ void dispatchCreateWidgetLayer(final int aHandle, final Surface aSurface, final
635635
}
636636
};
637637

638-
639638
widget.setSurface(aSurface, aWidth, aHeight, aFirstDrawCallback);
640639

641-
View view = (View) widget;
640+
UIWidget view = (UIWidget) widget;
642641
// Add widget to a virtual display for invalidation
643642
if (aSurface != null && view.getParent() == null) {
644643
mWidgetContainer.addView(view, new FrameLayout.LayoutParams(widget.getPlacement().viewWidth(), widget.getPlacement().viewHeight()));
645-
} else if (aSurface == null && view.getParent() != null) {
644+
} else if (aSurface == null && view.getParent() != null) {
646645
mWidgetContainer.removeView(view);
647646
}
647+
view.setResizing(false);
648648
view.postInvalidate();
649649
});
650650
}
@@ -1021,15 +1021,22 @@ public void updateWidget(final Widget aWidget) {
10211021
// Widget not added yet
10221022
return;
10231023
}
1024+
UIWidget view = (UIWidget)aWidget;
1025+
10241026
if (params.width != viewWidth || params.height != viewHeight) {
10251027
params.width = viewWidth;
10261028
params.height = viewHeight;
1029+
if (view.isLayer()) {
1030+
// Reuse last frame and do not render while resizing surface with Layers enabled.
1031+
// Fixes resizing glitches.
1032+
view.setResizing(true);
1033+
}
10271034
((View)aWidget).setLayoutParams(params);
10281035
aWidget.resizeSurface(textureWidth, textureHeight);
10291036
}
10301037

10311038
boolean visible = aWidget.getPlacement().visible;
1032-
View view = (View)aWidget;
1039+
10331040
if (visible != (view.getVisibility() == View.VISIBLE)) {
10341041
view.setVisibility(visible ? View.VISIBLE : View.GONE);
10351042
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
423423
updateServoButton();
424424
handleSessionState();
425425
}
426+
handleWindowResize();
426427
}
427428

428429
@Override
@@ -843,12 +844,14 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
843844
// WidgetManagerDelegate.UpdateListener
844845
@Override
845846
public void onWidgetUpdate(Widget aWidget) {
846-
if (aWidget != mAttachedWindow || mIsResizing) {
847-
return;
847+
if (aWidget == mAttachedWindow && !mIsResizing) {
848+
handleWindowResize();
848849
}
850+
}
849851

852+
private void handleWindowResize() {
850853
// Browser window may have been resized, adjust the navigation bar
851-
float targetWidth = aWidget.getPlacement().worldWidth;
854+
float targetWidth = mAttachedWindow.getPlacement().worldWidth;
852855
float defaultWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
853856
float maxWidth = defaultWidth * 1.5f;
854857
float minWidth = defaultWidth * 0.5f;
@@ -859,6 +862,7 @@ public void onWidgetUpdate(Widget aWidget) {
859862
mWidgetPlacement.worldWidth = targetWidth;
860863
mWidgetPlacement.width = (int) (WidgetPlacement.dpDimension(getContext(), R.dimen.navigation_bar_width) * ratio);
861864
mWidgetManager.updateWidget(this);
865+
postInvalidate();
862866
}
863867

864868
// SessionStack.SessionChangeListener

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public interface Delegate {
4848
protected Delegate mDelegate;
4949
protected int mBorderWidth;
5050
private Runnable mFirstDrawCallback;
51+
protected boolean mResizing = false;
5152

5253
public UIWidget(Context aContext) {
5354
super(aContext);
@@ -233,6 +234,9 @@ public void draw(Canvas aCanvas) {
233234
}
234235

235236
private void draw(Canvas aCanvas, UISurfaceTextureRenderer aRenderer) {
237+
if (mResizing) {
238+
return;
239+
}
236240
Canvas textureCanvas = aRenderer.drawBegin();
237241
if(textureCanvas != null) {
238242
// set the proper scale
@@ -278,6 +282,14 @@ public void toggle() {
278282
}
279283
}
280284

285+
public void setResizing(boolean aResizing) {
286+
mResizing = aResizing;
287+
}
288+
289+
public boolean isLayer() {
290+
return mRenderer != null && mRenderer.isLayer();
291+
}
292+
281293
@IntDef(value = { REQUEST_FOCUS, CLEAR_FOCUS })
282294
public @interface ShowFlags {}
283295
public static final int REQUEST_FOCUS = 0;

0 commit comments

Comments
 (0)