Skip to content

Commit

Permalink
Apply border and brightness effects
Browse files Browse the repository at this point in the history
This patch applies border and brightness effects to OverlayContentWidget.

The border will overlap 2px on the left/right/top/bottom of
WebContents because the browser's compositor implementation doesn't
consider the x, y coordinates when setting up the surface. It's same
with Widget for Tab, and we maybe consider to have the inner Widget
to avoid this issue later. Having a border effect will bring about
a better UX even if it loses 2 pixels.
  • Loading branch information
MyidShin authored and svillar committed Feb 5, 2025
1 parent 6773a46 commit 57d2dc8
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
Expand All @@ -15,6 +13,7 @@
import com.igalia.wolvic.VRBrowserApplication;
import com.igalia.wolvic.browser.api.WDisplay;
import com.igalia.wolvic.browser.api.WSession;
import com.igalia.wolvic.utils.ViewUtils;

import java.util.concurrent.Executor;

Expand All @@ -27,7 +26,6 @@ public class OverlayContentWidget extends UIWidget implements WidgetManagerDeleg
private WDisplay mDisplay;
private WSession.ContentDelegate.OnPaymentHandlerCallback mCallback;
private Executor mUIThreadExecutor;
private Handler mHandler;

public OverlayContentWidget(Context aContext) {
super(aContext);
Expand All @@ -53,6 +51,7 @@ public void setDelegates(@NonNull WSession session, @NonNull WDisplay display,

@Override
public void releaseWidget() {
mWidgetManager.popWorldBrightness(OverlayContentWidget.this);
mWidgetManager.removeWorldClickListener(this);
mCallback.onDismiss();

Expand All @@ -62,16 +61,17 @@ public void releaseWidget() {
@Override
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.visible = false;
aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.tabs_width);
aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.tabs_height);

aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.tabs_width) + mBorderWidth * 2;
aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.tabs_height) + mBorderWidth * 2;
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.5f;
aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y) -
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
updatePlacementTranslationZ();

mWidgetPlacement.borderColor = ViewUtils.ARGBtoRGBA(getContext().getColor(R.color.rhino_blur));
}

@Override
Expand All @@ -82,9 +82,11 @@ public void updatePlacementTranslationZ() {

private void initialize(Context aContext) {
mUIThreadExecutor = ((VRBrowserApplication)aContext.getApplicationContext()).getExecutors().mainThread();
mHandler = new Handler(Looper.getMainLooper());

mWidgetManager.addWorldClickListener(this);
mWidgetManager.pushWorldBrightness(OverlayContentWidget.this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);

// TODO: Fix the compositor in the browser engine to support correct border offset
mBorderWidth = 0;
}

@Override
Expand Down Expand Up @@ -198,7 +200,8 @@ public void setSurface(Surface aSurface, final int aWidth, final int aHeight, Ru

private void callSurfaceChanged() {
if (mSurface != null) {
mDisplay.surfaceChanged(mSurface, 0, 0, mSurfaceWidth, mSurfaceHeight);
int borderWidth = WidgetPlacement.convertDpToPixel(getContext(), mBorderWidth);
mDisplay.surfaceChanged(mSurface, borderWidth, borderWidth, mSurfaceWidth - borderWidth * 2, mSurfaceHeight - borderWidth * 2);
}
}

Expand Down

0 comments on commit 57d2dc8

Please sign in to comment.