Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support vertical videos #1195

Merged
merged 3 commits into from
Jan 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ private void exitVRVideo() {
}

private void setResizePreset(float aMultiplier) {
final float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
final float aspect = (float) mAttachedWindow.getWindowWidth() / (float) mAttachedWindow.getWindowHeight();
mAttachedWindow.resizeByMultiplier(aspect, aMultiplier);
}

Expand Down Expand Up @@ -1307,9 +1307,10 @@ private void finishWidgetResize() {

private void startWidgetResize() {
if (mAttachedWindow != null) {
Pair<Float, Float> maxSize = mAttachedWindow.getSizeForScale(mAttachedWindow.getMaxWindowScale());
Pair<Float, Float> minSize = mAttachedWindow.getSizeForScale(0.5f);
mWidgetManager.startWidgetResize(mAttachedWindow, maxSize.first, 4.5f, minSize.first, minSize.second);
final float aspect = (float) mAttachedWindow.getWindowWidth() / (float) mAttachedWindow.getWindowHeight();
Pair<Float, Float> maxSize = mAttachedWindow.getSizeForScale(mAttachedWindow.getMaxWindowScale(), aspect);
Pair<Float, Float> minSize = mAttachedWindow.getSizeForScale(0.5f, aspect);
mWidgetManager.startWidgetResize(mAttachedWindow, maxSize.first, maxSize.second, minSize.first, minSize.second);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1540,29 +1540,35 @@ public float getMaxWindowScale() {
}

public @NonNull Pair<Float, Float> getSizeForScale(float aScale, float aAspect) {
final float defaultWorldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
final float maxWidthWorld = SettingsStore.MAX_WINDOW_WIDTH_DEFAULT * (defaultWorldWidth/SettingsStore.WINDOW_WIDTH_DEFAULT);
float targetWidth;
float defaultWorldSize = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float maxWorldSize = SettingsStore.MAX_WINDOW_WIDTH_DEFAULT * (defaultWorldSize/SettingsStore.WINDOW_WIDTH_DEFAULT);
float targetSize;

boolean isHorizontal = aAspect >= 1.0;
if (!isHorizontal) {
defaultWorldSize = defaultWorldSize * aAspect;
maxWorldSize = SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT * (defaultWorldSize/SettingsStore.WINDOW_HEIGHT_DEFAULT);
}

if (aScale < DEFAULT_SCALE) {
// Reduce the area of the window according to the desired scale.
float worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float worldHeight = worldWidth / aAspect;
float targetArea = worldWidth * worldHeight * aScale;
targetWidth = (float) Math.sqrt(targetArea * aAspect);
float worldSize = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float worldOrthogonalSize = isHorizontal ? worldSize / aAspect : worldSize * aAspect;
float targetArea = worldSize * worldOrthogonalSize * aScale;
targetSize = (float) Math.sqrt(targetArea * aAspect);
} else if (aScale == DEFAULT_SCALE) {
// Default window size.
targetWidth = defaultWorldWidth;
targetSize = defaultWorldSize;
} else if (aScale >= MAX_SCALE) {
// Maximum window size.
targetWidth = maxWidthWorld;
targetSize = maxWorldSize;
} else {
// Proportional between the default and maximum sizes.
targetWidth = defaultWorldWidth + (maxWidthWorld - defaultWorldWidth) * (aScale - DEFAULT_SCALE) / (MAX_SCALE - DEFAULT_SCALE);
targetSize = defaultWorldSize + (maxWorldSize - defaultWorldSize) * (aScale - DEFAULT_SCALE) / (MAX_SCALE - DEFAULT_SCALE);
}

float targetHeight = targetWidth / aAspect;
return Pair.create(targetWidth, targetHeight);
float targetOrthogonalSize = isHorizontal ? targetSize / aAspect : targetSize * aAspect;
return isHorizontal ? Pair.create(targetSize, targetOrthogonalSize) : Pair.create(targetOrthogonalSize, targetSize);
}

private int getWindowWidth(float aWorldWidth) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.igalia.wolvic.browser.Services;
import com.igalia.wolvic.browser.SettingsStore;
import com.igalia.wolvic.browser.adapter.ComponentsAdapter;
import com.igalia.wolvic.browser.api.WMediaSession;
import com.igalia.wolvic.browser.api.WSession;
import com.igalia.wolvic.browser.components.WolvicEngineSession;
import com.igalia.wolvic.browser.engine.Session;
Expand Down Expand Up @@ -1327,6 +1328,15 @@ public void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
}
}

@Override
public void onMediaFullScreen(@NonNull WMediaSession mediaSession, boolean aFullScreen) {
if (!aFullScreen)
return;

assert mFullscreenWindow != null;
setFullScreenSize(mFullscreenWindow);
}

@Override
public void onContentFullScreen(@NonNull WindowWidget aWindow, boolean aFullScreen) {
if (aFullScreen) {
Expand Down
Loading