Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
targetWidth = Math.max(defaultWidth, targetWidth);
targetWidth = Math.min(targetWidth, defaultWidth * 1.5f);
Expand All @@ -857,6 +860,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
Original file line number Diff line number Diff line change
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