From e5eac7d28e7cc98b96cdd9844cda93d3bbcf2c05 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Tue, 27 Aug 2019 12:26:25 +0200 Subject: [PATCH] Set the minimum resize size to 0.5x (#1666) --- .../org/mozilla/vrbrowser/VRBrowserActivity.java | 6 +++--- .../vrbrowser/ui/widgets/NavigationBarWidget.java | 11 +++++++---- .../vrbrowser/ui/widgets/WidgetManagerDelegate.java | 2 +- app/src/main/cpp/BrowserWorld.cpp | 9 +++++---- app/src/main/cpp/BrowserWorld.h | 2 +- app/src/main/cpp/Widget.cpp | 4 ++-- app/src/main/cpp/Widget.h | 2 +- app/src/main/cpp/WidgetResizer.cpp | 9 ++++++--- app/src/main/cpp/WidgetResizer.h | 2 +- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index d2d6022c3..30c4b2eed 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -1057,9 +1057,9 @@ public void updateVisibleWidgets() { } @Override - public void startWidgetResize(final Widget aWidget, float aMaxWidth, float aMaxHeight) { + public void startWidgetResize(final Widget aWidget, float aMaxWidth, float aMaxHeight, float minWidth, float minHeight) { mWindows.enterResizeMode(); - queueRunnable(() -> startWidgetResizeNative(aWidget.getHandle(), aMaxWidth, aMaxHeight)); + queueRunnable(() -> startWidgetResizeNative(aWidget.getHandle(), aMaxWidth, aMaxHeight, minWidth, minHeight)); } @Override @@ -1300,7 +1300,7 @@ public WindowWidget getFocusedWindow() { private native void updateWidgetNative(int aHandle, WidgetPlacement aPlacement); private native void updateVisibleWidgetsNative(); private native void removeWidgetNative(int aHandle); - private native void startWidgetResizeNative(int aHandle, float maxWidth, float maxHeight); + private native void startWidgetResizeNative(int aHandle, float maxWidth, float maxHeight, float minWidth, float minHeight); private native void finishWidgetResizeNative(int aHandle); private native void startWidgetMoveNative(int aHandle, int aMoveBehaviour); private native void finishWidgetMoveNative(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java index 3946b567d..a7a7678ac 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java @@ -850,8 +850,10 @@ public void onWidgetUpdate(Widget aWidget) { // Browser window may have been resized, adjust the navigation bar float targetWidth = aWidget.getPlacement().worldWidth; float defaultWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width); - targetWidth = Math.max(defaultWidth, targetWidth); - targetWidth = Math.min(targetWidth, defaultWidth * 1.5f); + float maxWidth = defaultWidth * 1.5f; + float minWidth = defaultWidth * 0.5f; + targetWidth = Math.max(targetWidth, minWidth); + targetWidth = Math.min(targetWidth, maxWidth); float ratio = targetWidth / defaultWidth; mWidgetPlacement.worldWidth = targetWidth; @@ -1019,8 +1021,9 @@ private void finishWidgetResize() { private void startWidgetResize() { if (mAttachedWindow != null) { - Pair targetSize = mAttachedWindow.getSizeForScale(mAttachedWindow.getMaxWindowScale()); - mWidgetManager.startWidgetResize(mAttachedWindow, targetSize.first, 4.5f); + Pair maxSize = mAttachedWindow.getSizeForScale(mAttachedWindow.getMaxWindowScale()); + Pair minSize = mAttachedWindow.getSizeForScale(0.5f); + mWidgetManager.startWidgetResize(mAttachedWindow, maxSize.first, 4.5f, minSize.first, minSize.second); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java index c406bb5da..88e2204d3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java @@ -46,7 +46,7 @@ interface WorldClickListener { void updateWidget(@NonNull Widget aWidget); void removeWidget(@NonNull Widget aWidget); void updateVisibleWidgets(); - void startWidgetResize(@NonNull Widget aWidget, float maxWidth, float maxHeight); + void startWidgetResize(@NonNull Widget aWidget, float maxWidth, float maxHeight, float minWidth, float minHeight); void finishWidgetResize(@NonNull Widget aWidget); void startWidgetMove(@NonNull Widget aWidget, @WidgetMoveBehaviourFlags int aMoveBehaviour); void finishWidgetMove(); diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index 58cccc97d..f1fe20d5d 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -933,11 +933,11 @@ BrowserWorld::RemoveWidget(int32_t aHandle) { } void -BrowserWorld::StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize) { +BrowserWorld::StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize) { ASSERT_ON_RENDER_THREAD(); WidgetPtr widget = m.GetWidget(aHandle); if (widget) { - widget->StartResize(aMaxSize); + widget->StartResize(aMaxSize, aMinSize); } } @@ -1440,8 +1440,9 @@ JNI_METHOD(void, removeWidgetNative) } JNI_METHOD(void, startWidgetResizeNative) -(JNIEnv*, jobject, jint aHandle, jfloat aMaxWidth, jfloat aMaxHeight) { - crow::BrowserWorld::Instance().StartWidgetResize(aHandle, vrb::Vector(aMaxWidth, aMaxHeight, 0.0f)); +(JNIEnv*, jobject, jint aHandle, jfloat aMaxWidth, jfloat aMaxHeight, jfloat aMinWidth, jfloat aMinHeight) { + crow::BrowserWorld::Instance().StartWidgetResize(aHandle, + vrb::Vector(aMaxWidth, aMaxHeight, 0.0f), vrb::Vector(aMinWidth, aMinHeight, 0.0f)); } JNI_METHOD(void, finishWidgetResizeNative) diff --git a/app/src/main/cpp/BrowserWorld.h b/app/src/main/cpp/BrowserWorld.h index ded48860d..ecf46d329 100644 --- a/app/src/main/cpp/BrowserWorld.h +++ b/app/src/main/cpp/BrowserWorld.h @@ -46,7 +46,7 @@ class BrowserWorld { void AddWidget(int32_t aHandle, const WidgetPlacementPtr& placement); void UpdateWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement); void RemoveWidget(int32_t aHandle); - void StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize); + void StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize); void FinishWidgetResize(int32_t aHandle); void StartWidgetMove(int32_t aHandle, const int32_t aMoveBehavour); void FinishWidgetMove(); diff --git a/app/src/main/cpp/Widget.cpp b/app/src/main/cpp/Widget.cpp index b06839151..5b1f666e2 100644 --- a/app/src/main/cpp/Widget.cpp +++ b/app/src/main/cpp/Widget.cpp @@ -444,7 +444,7 @@ Widget::SetPlacement(const WidgetPlacementPtr& aPlacement) { } void -Widget::StartResize(const vrb::Vector& aMaxSize) { +Widget::StartResize(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize) { vrb::Vector worldMin, worldMax; GetWidgetMinAndMax(worldMin, worldMax); if (m.resizer) { @@ -458,7 +458,7 @@ Widget::StartResize(const vrb::Vector& aMaxSize) { m.resizer = WidgetResizer::Create(create, this); m.transform->InsertNode(m.resizer->GetRoot(), 0); } - m.resizer->SetMaxSize(aMaxSize); + m.resizer->SetResizeLimits(aMaxSize, aMinSize); m.resizing = true; m.resizer->ToggleVisible(true); if (m.quad) { diff --git a/app/src/main/cpp/Widget.h b/app/src/main/cpp/Widget.h index c5724d43a..3b77815db 100644 --- a/app/src/main/cpp/Widget.h +++ b/app/src/main/cpp/Widget.h @@ -66,7 +66,7 @@ class Widget { vrb::TransformPtr GetTransformNode() const; const WidgetPlacementPtr& GetPlacement() const; void SetPlacement(const WidgetPlacementPtr& aPlacement); - void StartResize(const vrb::Vector& aMaxSize); + void StartResize(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize); void FinishResize(); bool IsResizing() const; bool IsResizingActive() const; diff --git a/app/src/main/cpp/WidgetResizer.cpp b/app/src/main/cpp/WidgetResizer.cpp index b6fdf9125..cf2b0e3c9 100644 --- a/app/src/main/cpp/WidgetResizer.cpp +++ b/app/src/main/cpp/WidgetResizer.cpp @@ -252,6 +252,7 @@ struct WidgetResizer::State { vrb::Vector currentMax; vrb::Vector pointerOffset; vrb::Vector maxSize; + vrb::Vector minSize; bool resizing; vrb::TogglePtr root; std::vector resizeHandles; @@ -274,6 +275,7 @@ struct WidgetResizer::State { currentMin = min; currentMax = max; maxSize = kDefaultMaxResize; + minSize = kDefaultMinResize; vrb::Vector horizontalSize(0.0f, 0.5f, 0.0f); vrb::Vector verticalSize(0.5f, 0.0f, 0.0f); @@ -485,8 +487,8 @@ struct WidgetResizer::State { } // Clamp to max and min resize sizes - width = fmaxf(fminf(width, maxSize.x()), kDefaultMinResize.x()); - height = fmaxf(fminf(height, maxSize.y()), kDefaultMinResize.y()); + width = fmaxf(fminf(width, maxSize.x()), minSize.x()); + height = fmaxf(fminf(height, maxSize.y()), minSize.y()); if (keepAspect) { height = width / originalAspect; } @@ -529,8 +531,9 @@ WidgetResizer::SetSize(const vrb::Vector& aMin, const vrb::Vector& aMax) { } void -WidgetResizer::SetMaxSize(const vrb::Vector& aMaxSize) { +WidgetResizer::SetResizeLimits(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize) { m.maxSize = aMaxSize; + m.minSize = aMinSize; } void diff --git a/app/src/main/cpp/WidgetResizer.h b/app/src/main/cpp/WidgetResizer.h index 76b42eab1..bf7cb193f 100644 --- a/app/src/main/cpp/WidgetResizer.h +++ b/app/src/main/cpp/WidgetResizer.h @@ -25,7 +25,7 @@ class WidgetResizer { static WidgetResizerPtr Create(vrb::CreationContextPtr& aContext, Widget * aWidget); vrb::NodePtr GetRoot() const; void SetSize(const vrb::Vector& aMin, const vrb::Vector& aMax); - void SetMaxSize(const vrb::Vector& aMaxSize); + void SetResizeLimits(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize); void ToggleVisible(bool aVisible); bool TestIntersection(const vrb::Vector& point) const; void HandleResizeGestures(const vrb::Vector& aPoint, bool aPressed, bool& aResized, bool &aResizeEnded);