Skip to content

Commit

Permalink
Resize navbar on window focus change. Fix resizing glitches. (#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and keianhzo committed Aug 27, 2019
1 parent 794aab0 commit fd1ab0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
15 changes: 11 additions & 4 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Expand Up @@ -635,16 +635,16 @@ void dispatchCreateWidgetLayer(final int aHandle, final Surface aSurface, final
}
};


widget.setSurface(aSurface, aWidth, aHeight, aFirstDrawCallback);

View view = (View) widget;
UIWidget view = (UIWidget) widget;
// Add widget to a virtual display for invalidation
if (aSurface != null && view.getParent() == null) {
mWidgetContainer.addView(view, new FrameLayout.LayoutParams(widget.getPlacement().viewWidth(), widget.getPlacement().viewHeight()));
} else if (aSurface == null && view.getParent() != null) {
} else if (aSurface == null && view.getParent() != null) {
mWidgetContainer.removeView(view);
}
view.setResizing(false);
view.postInvalidate();
});
}
Expand Down Expand Up @@ -1021,15 +1021,22 @@ public void updateWidget(final Widget aWidget) {
// Widget not added yet
return;
}
UIWidget view = (UIWidget)aWidget;

if (params.width != viewWidth || params.height != viewHeight) {
params.width = viewWidth;
params.height = viewHeight;
if (view.isLayer()) {
// Reuse last frame and do not render while resizing surface with Layers enabled.
// Fixes resizing glitches.
view.setResizing(true);
}
((View)aWidget).setLayoutParams(params);
aWidget.resizeSurface(textureWidth, textureHeight);
}

boolean visible = aWidget.getPlacement().visible;
View view = (View)aWidget;

if (visible != (view.getVisibility() == View.VISIBLE)) {
view.setVisibility(visible ? View.VISIBLE : View.GONE);
}
Expand Down
Expand Up @@ -423,6 +423,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
updateServoButton();
handleSessionState();
}
handleWindowResize();
}

@Override
Expand Down Expand Up @@ -843,12 +844,14 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
// WidgetManagerDelegate.UpdateListener
@Override
public void onWidgetUpdate(Widget aWidget) {
if (aWidget != mAttachedWindow || mIsResizing) {
return;
if (aWidget == mAttachedWindow && !mIsResizing) {
handleWindowResize();
}
}

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

// SessionStack.SessionChangeListener
Expand Down
Expand Up @@ -48,6 +48,7 @@ public interface Delegate {
protected Delegate mDelegate;
protected int mBorderWidth;
private Runnable mFirstDrawCallback;
protected boolean mResizing = false;

public UIWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -233,6 +234,9 @@ public void draw(Canvas aCanvas) {
}

private void draw(Canvas aCanvas, UISurfaceTextureRenderer aRenderer) {
if (mResizing) {
return;
}
Canvas textureCanvas = aRenderer.drawBegin();
if(textureCanvas != null) {
// set the proper scale
Expand Down Expand Up @@ -278,6 +282,14 @@ public void toggle() {
}
}

public void setResizing(boolean aResizing) {
mResizing = aResizing;
}

public boolean isLayer() {
return mRenderer != null && mRenderer.isLayer();
}

@IntDef(value = { REQUEST_FOCUS, CLEAR_FOCUS })
public @interface ShowFlags {}
public static final int REQUEST_FOCUS = 0;
Expand Down

0 comments on commit fd1ab0f

Please sign in to comment.