OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.vr_shell; | 5 package org.chromium.chrome.browser.vr_shell; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.graphics.Canvas; | 8 import android.graphics.Canvas; |
9 import android.graphics.Point; | 9 import android.graphics.Point; |
10 import android.os.StrictMode; | 10 import android.os.StrictMode; |
11 import android.view.MotionEvent; | 11 import android.view.MotionEvent; |
12 import android.view.Surface; | 12 import android.view.Surface; |
13 import android.view.SurfaceHolder; | 13 import android.view.SurfaceHolder; |
14 import android.view.SurfaceView; | 14 import android.view.SurfaceView; |
15 import android.view.View; | 15 import android.view.View; |
16 import android.view.ViewTreeObserver.OnPreDrawListener; | 16 import android.view.ViewTreeObserver.OnPreDrawListener; |
17 import android.widget.FrameLayout; | 17 import android.widget.FrameLayout; |
18 import android.widget.FrameLayout.LayoutParams; | 18 import android.widget.FrameLayout.LayoutParams; |
19 | 19 |
20 import com.google.vr.ndk.base.AndroidCompat; | 20 import com.google.vr.ndk.base.AndroidCompat; |
21 import com.google.vr.ndk.base.GvrLayout; | 21 import com.google.vr.ndk.base.GvrLayout; |
22 | 22 |
23 import org.chromium.base.CommandLine; | 23 import org.chromium.base.CommandLine; |
24 import org.chromium.base.Log; | 24 import org.chromium.base.Log; |
25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
| 26 import org.chromium.base.VisibleForTesting; |
26 import org.chromium.base.annotations.CalledByNative; | 27 import org.chromium.base.annotations.CalledByNative; |
27 import org.chromium.base.annotations.JNINamespace; | 28 import org.chromium.base.annotations.JNINamespace; |
28 import org.chromium.chrome.browser.ChromeActivity; | 29 import org.chromium.chrome.browser.ChromeActivity; |
29 import org.chromium.chrome.browser.ChromeSwitches; | 30 import org.chromium.chrome.browser.ChromeSwitches; |
30 import org.chromium.chrome.browser.ChromeVersionInfo; | 31 import org.chromium.chrome.browser.ChromeVersionInfo; |
31 import org.chromium.chrome.browser.NativePage; | 32 import org.chromium.chrome.browser.NativePage; |
32 import org.chromium.chrome.browser.UrlConstants; | 33 import org.chromium.chrome.browser.UrlConstants; |
33 import org.chromium.chrome.browser.WebContentsFactory; | 34 import org.chromium.chrome.browser.WebContentsFactory; |
34 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 35 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
35 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 36 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 private boolean mReprojectedRendering; | 112 private boolean mReprojectedRendering; |
112 | 113 |
113 private TabRedirectHandler mNonVrTabRedirectHandler; | 114 private TabRedirectHandler mNonVrTabRedirectHandler; |
114 private TabModelSelector mTabModelSelector; | 115 private TabModelSelector mTabModelSelector; |
115 private float mLastContentWidth; | 116 private float mLastContentWidth; |
116 private float mLastContentHeight; | 117 private float mLastContentHeight; |
117 private float mLastContentDpr; | 118 private float mLastContentDpr; |
118 | 119 |
119 private MotionEventSynthesizer mMotionEventSynthesizer; | 120 private MotionEventSynthesizer mMotionEventSynthesizer; |
120 | 121 |
| 122 private OnDispatchTouchEventCallback mOnDispatchTouchEventForTesting; |
| 123 |
121 public VrShellImpl( | 124 public VrShellImpl( |
122 ChromeActivity activity, VrShellDelegate delegate, TabModelSelector
tabModelSelector) { | 125 ChromeActivity activity, VrShellDelegate delegate, TabModelSelector
tabModelSelector) { |
123 super(activity); | 126 super(activity); |
124 mActivity = activity; | 127 mActivity = activity; |
125 mDelegate = delegate; | 128 mDelegate = delegate; |
126 mTabModelSelector = tabModelSelector; | 129 mTabModelSelector = tabModelSelector; |
127 mUiCVCContainer = new FrameLayout(getContext()) { | 130 mUiCVCContainer = new FrameLayout(getContext()) { |
128 @Override | 131 @Override |
129 public boolean dispatchTouchEvent(MotionEvent event) { | 132 public boolean dispatchTouchEvent(MotionEvent event) { |
130 return true; | 133 return true; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 if (mSurface != null || mNativePage == null) return; | 439 if (mSurface != null || mNativePage == null) return; |
437 mSurface = nativeTakeContentSurface(mNativeVrShell); | 440 mSurface = nativeTakeContentSurface(mNativeVrShell); |
438 mNativePage.getView().invalidate(); | 441 mNativePage.getView().invalidate(); |
439 } | 442 } |
440 | 443 |
441 @Override | 444 @Override |
442 public boolean dispatchTouchEvent(MotionEvent event) { | 445 public boolean dispatchTouchEvent(MotionEvent event) { |
443 // Normally, touch event is dispatched to presentation view only if the
phone is paired with | 446 // Normally, touch event is dispatched to presentation view only if the
phone is paired with |
444 // a Cardboard viewer. This is annoying when we just want to quickly ver
ify a Cardboard | 447 // a Cardboard viewer. This is annoying when we just want to quickly ver
ify a Cardboard |
445 // behavior. This allows us to trigger cardboard trigger event without p
air to a Cardboard. | 448 // behavior. This allows us to trigger cardboard trigger event without p
air to a Cardboard. |
| 449 boolean cardboardTriggered = false; |
446 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_D
EV) | 450 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_D
EV) |
447 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { | 451 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
448 nativeOnTriggerEvent(mNativeVrShell); | 452 nativeOnTriggerEvent(mNativeVrShell); |
| 453 cardboardTriggered = true; |
449 } | 454 } |
450 return super.dispatchTouchEvent(event); | 455 boolean parentConsumed = super.dispatchTouchEvent(event); |
| 456 if (mOnDispatchTouchEventForTesting != null) { |
| 457 mOnDispatchTouchEventForTesting.onDispatchTouchEvent( |
| 458 parentConsumed, cardboardTriggered); |
| 459 } |
| 460 return parentConsumed; |
451 } | 461 } |
452 | 462 |
453 @Override | 463 @Override |
454 public void onResume() { | 464 public void onResume() { |
455 super.onResume(); | 465 super.onResume(); |
456 if (mNativeVrShell != 0) { | 466 if (mNativeVrShell != 0) { |
457 // Refreshing the viewer profile accesses disk, so we need to tempor
arily allow disk | 467 // Refreshing the viewer profile accesses disk, so we need to tempor
arily allow disk |
458 // reads. The GVR team promises this will be fixed when they launch. | 468 // reads. The GVR team promises this will be fixed when they launch. |
459 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); | 469 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); |
460 try { | 470 try { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 public WindowAndroid getWindowAndroid() { | 631 public WindowAndroid getWindowAndroid() { |
622 return mContentVrWindowAndroid; | 632 return mContentVrWindowAndroid; |
623 } | 633 } |
624 | 634 |
625 @Override | 635 @Override |
626 public void addWindowAndroidChangedObserver(WindowAndroidChangedObserver obs
erver) {} | 636 public void addWindowAndroidChangedObserver(WindowAndroidChangedObserver obs
erver) {} |
627 | 637 |
628 @Override | 638 @Override |
629 public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver
observer) {} | 639 public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver
observer) {} |
630 | 640 |
| 641 /** |
| 642 * Sets the runnable that will be run when VrShellImpl's dispatchTouchEvent |
| 643 * is run and the parent consumed the event. |
| 644 * @param runnable The Runnable that will be run |
| 645 */ |
| 646 @VisibleForTesting |
| 647 public void setOnDispatchTouchEventForTesting(OnDispatchTouchEventCallback c
allback) { |
| 648 mOnDispatchTouchEventForTesting = callback; |
| 649 } |
| 650 |
631 private native long nativeInit(WebContents uiWebContents, long nativeContent
WindowAndroid, | 651 private native long nativeInit(WebContents uiWebContents, long nativeContent
WindowAndroid, |
632 long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delega
te, long gvrApi, | 652 long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delega
te, long gvrApi, |
633 boolean reprojectedRendering); | 653 boolean reprojectedRendering); |
634 private native void nativeSetSurface(long nativeVrShell, Surface surface); | 654 private native void nativeSetSurface(long nativeVrShell, Surface surface); |
635 private native void nativeSwapContents( | 655 private native void nativeSwapContents( |
636 long nativeVrShell, WebContents webContents, MotionEventSynthesizer
eventSynthesizer); | 656 long nativeVrShell, WebContents webContents, MotionEventSynthesizer
eventSynthesizer); |
637 private native void nativeLoadUIContent(long nativeVrShell); | 657 private native void nativeLoadUIContent(long nativeVrShell); |
638 private native void nativeDestroy(long nativeVrShell); | 658 private native void nativeDestroy(long nativeVrShell); |
639 private native void nativeOnTriggerEvent(long nativeVrShell); | 659 private native void nativeOnTriggerEvent(long nativeVrShell); |
640 private native void nativeOnPause(long nativeVrShell); | 660 private native void nativeOnPause(long nativeVrShell); |
641 private native void nativeOnResume(long nativeVrShell); | 661 private native void nativeOnResume(long nativeVrShell); |
642 private native void nativeOnLoadProgressChanged(long nativeVrShell, double p
rogress); | 662 private native void nativeOnLoadProgressChanged(long nativeVrShell, double p
rogress); |
643 private native void nativeContentPhysicalBoundsChanged(long nativeVrShell, i
nt width, | 663 private native void nativeContentPhysicalBoundsChanged(long nativeVrShell, i
nt width, |
644 int height, float dpr); | 664 int height, float dpr); |
645 private native void nativeUIPhysicalBoundsChanged(long nativeVrShell, int wi
dth, int height, | 665 private native void nativeUIPhysicalBoundsChanged(long nativeVrShell, int wi
dth, int height, |
646 float dpr); | 666 float dpr); |
647 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); | 667 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); |
648 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab
s, | 668 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab
s, |
649 Tab[] incognitoTabs); | 669 Tab[] incognitoTabs); |
650 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito
, int id, | 670 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito
, int id, |
651 String title); | 671 String title); |
652 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito
, int id); | 672 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito
, int id); |
653 private native Surface nativeTakeContentSurface(long nativeVrShell); | 673 private native Surface nativeTakeContentSurface(long nativeVrShell); |
654 private native void nativeRestoreContentSurface(long nativeVrShell); | 674 private native void nativeRestoreContentSurface(long nativeVrShell); |
655 private native void nativeSetHistoryButtonsEnabled( | 675 private native void nativeSetHistoryButtonsEnabled( |
656 long nativeVrShell, boolean canGoBack, boolean canGoForward); | 676 long nativeVrShell, boolean canGoBack, boolean canGoForward); |
657 } | 677 } |
OLD | NEW |