4545import org .mozilla .vrbrowser .ui .widgets .prompts .ConfirmPromptWidget ;
4646import org .mozilla .vrbrowser .ui .widgets .prompts .PromptWidget ;
4747import org .mozilla .vrbrowser .ui .widgets .prompts .TextPromptWidget ;
48+ import org .mozilla .vrbrowser .utils .InternalPages ;
49+ import org .mozilla .vrbrowser .utils .ViewUtils ;
4850
4951import java .util .ArrayList ;
5052
@@ -90,7 +92,15 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
9092 private Windows .WindowPlacement mWindowPlacement = Windows .WindowPlacement .FRONT ;
9193 private float mMaxWindowScale = 3 ;
9294 private boolean mIsRestored = false ;
95+ private WindowDelegate mWindowDelegate ;
9396 boolean mActive = false ;
97+ boolean mHovered = false ;
98+ boolean mClickedAfterFocus = false ;
99+
100+ public interface WindowDelegate {
101+ void onFocusRequest (@ NonNull WindowWidget aWindow );
102+ void onBorderChanged (@ NonNull WindowWidget aWindow );
103+ }
94104
95105 public WindowWidget (Context aContext , int windowId , boolean privateMode ) {
96106 super (aContext );
@@ -387,6 +397,7 @@ public void setActiveWindow(boolean active) {
387397 }
388398
389399 TelemetryWrapper .activePlacementEvent (mWindowPlacement .getValue (), mActive );
400+ updateBorder ();
390401 }
391402
392403 public SessionStack getSessionStack () {
@@ -488,6 +499,26 @@ public WidgetPlacement getPlacement() {
488499 @ Override
489500 public void handleTouchEvent (MotionEvent aEvent ) {
490501 mLastMouseClickPos = new Point ((int )aEvent .getX (), (int )aEvent .getY ());
502+ if (aEvent .getAction () == MotionEvent .ACTION_DOWN ) {
503+ if (!mActive ) {
504+ mClickedAfterFocus = true ;
505+ updateBorder ();
506+ if (mWindowDelegate != null ) {
507+ // Focus this window
508+ mWindowDelegate .onFocusRequest (this );
509+ }
510+ // Return to discard first click after focus
511+ return ;
512+ }
513+ } else if (aEvent .getAction () == MotionEvent .ACTION_UP || aEvent .getAction () == MotionEvent .ACTION_CANCEL ) {
514+ mClickedAfterFocus = false ;
515+ updateBorder ();
516+ }
517+
518+ if (!mActive ) {
519+ // Do not send touch events to not focused windows.
520+ return ;
521+ }
491522
492523 if (mView != null ) {
493524 super .handleTouchEvent (aEvent );
@@ -507,6 +538,19 @@ public void handleTouchEvent(MotionEvent aEvent) {
507538
508539 @ Override
509540 public void handleHoverEvent (MotionEvent aEvent ) {
541+ if (aEvent .getAction () == MotionEvent .ACTION_HOVER_ENTER ) {
542+ mHovered = true ;
543+ updateBorder ();
544+ } else if (aEvent .getAction () == MotionEvent .ACTION_HOVER_EXIT ) {
545+ mHovered = false ;
546+ updateBorder ();
547+ }
548+
549+ if (!mActive ) {
550+ // Do not send touch events to not focused windows.
551+ return ;
552+ }
553+
510554 if (mView != null ) {
511555 super .handleHoverEvent (aEvent );
512556
@@ -520,6 +564,26 @@ public void handleHoverEvent(MotionEvent aEvent) {
520564 }
521565 }
522566
567+ protected void updateBorder () {
568+ int color = 0 ;
569+ if (!mActive && !mClickedAfterFocus && mHovered ) {
570+ color = ViewUtils .ARGBtoRGBA (getContext ().getColor (R .color .window_border_hover ));
571+ } else if (mClickedAfterFocus ) {
572+ color = ViewUtils .ARGBtoRGBA (getContext ().getColor (R .color .window_border_click ));
573+ }
574+ if (mWidgetPlacement .borderColor != color ) {
575+ mWidgetPlacement .borderColor = color ;
576+ mWidgetManager .updateWidget (this );
577+ if (mWindowDelegate != null ) {
578+ mWindowDelegate .onBorderChanged (this );
579+ }
580+ }
581+ }
582+
583+ public void setWindowDelegate (WindowDelegate aDelegate ) {
584+ mWindowDelegate = aDelegate ;
585+ }
586+
523587 @ Override
524588 public void handleResizeEvent (float aWorldWidth , float aWorldHeight ) {
525589 int width = getWindowWidth (aWorldWidth );
@@ -975,5 +1039,4 @@ public GeckoResult<AllowOrDeny> onLoadRequest(@NonNull GeckoSession session, @No
9751039
9761040 return GeckoResult .ALLOW ;
9771041 }
978-
9791042}
0 commit comments