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

Commit

Permalink
Resize navbar on window focus change. Fix resizing glitches.
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Aug 22, 2019
1 parent 0222baf commit ab5728b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
updateServoButton();
handleSessionState();
}
handleWindowResize();
}

@Override
Expand Down Expand Up @@ -830,12 +831,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 @@ -844,6 +847,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
6 changes: 5 additions & 1 deletion app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
vrb::RenderContextWeak contextWeak;
JNIEnv * jniEnv = nullptr;
OculusLayer::BindDelegate bindDelegate;
bool resizing = false;

void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) override {
this->jniEnv = aEnv;
Expand Down Expand Up @@ -291,6 +292,7 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
this->layer->SetSurface(newSurface);

SurfaceChangedTargetWeakPtr weakTarget = this->surfaceChangedTarget;
this->resizing = true;
this->layer->NotifySurfaceChanged(VRLayer::SurfaceChange::Create, [=]() {
SurfaceChangedTargetPtr target = weakTarget.lock();
if (target && target->layer) {
Expand All @@ -310,6 +312,7 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
this->surface = newSurface;
this->fbo = newFBO;
this->composited = true;
this->resizing = false;
}

void Destroy() override {
Expand Down Expand Up @@ -431,7 +434,7 @@ class OculusLayerQuad: public OculusLayerSurface<VRLayerQuadPtr, ovrLayerProject
ovrLayer.Textures[i].TextureRect.height = textureRect.mHeight;
clip = clip || !textureRect.IsDefault();
}
SetClipEnabled(clip);
SetClipEnabled(clip || resizing);

ovrLayer.HeadPose = aTracking.HeadPose;
}
Expand Down Expand Up @@ -484,6 +487,7 @@ class OculusLayerCylinder: public OculusLayerSurface<VRLayerCylinderPtr, ovrLaye
ovrLayer.Textures[i].TextureRect.width = 1.0f;
ovrLayer.Textures[i].TextureRect.height = 1.0f;
}
SetClipEnabled(resizing);
}
};

Expand Down

0 comments on commit ab5728b

Please sign in to comment.