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 Runnable 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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. |
446 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_D EV) | 449 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_D EV) |
447 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { | 450 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
448 nativeOnTriggerEvent(mNativeVrShell); | 451 nativeOnTriggerEvent(mNativeVrShell); |
mthiesse
2017/03/28 18:08:01
Don't we also want to make sure this wasn't called
bsheedy
2017/03/28 20:50:35
Done.
| |
449 } | 452 } |
450 return super.dispatchTouchEvent(event); | 453 boolean parentHandled = super.dispatchTouchEvent(event); |
454 if (mOnDispatchTouchEventForTesting != null && parentHandled) { | |
455 mOnDispatchTouchEventForTesting.run(); | |
456 } | |
457 return parentHandled; | |
451 } | 458 } |
452 | 459 |
453 @Override | 460 @Override |
454 public void onResume() { | 461 public void onResume() { |
455 super.onResume(); | 462 super.onResume(); |
456 if (mNativeVrShell != 0) { | 463 if (mNativeVrShell != 0) { |
457 // Refreshing the viewer profile accesses disk, so we need to tempor arily allow disk | 464 // 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. | 465 // reads. The GVR team promises this will be fixed when they launch. |
459 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); | 466 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); |
460 try { | 467 try { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 public WindowAndroid getWindowAndroid() { | 628 public WindowAndroid getWindowAndroid() { |
622 return mContentVrWindowAndroid; | 629 return mContentVrWindowAndroid; |
623 } | 630 } |
624 | 631 |
625 @Override | 632 @Override |
626 public void addWindowAndroidChangedObserver(WindowAndroidChangedObserver obs erver) {} | 633 public void addWindowAndroidChangedObserver(WindowAndroidChangedObserver obs erver) {} |
627 | 634 |
628 @Override | 635 @Override |
629 public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver observer) {} | 636 public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver observer) {} |
630 | 637 |
638 /** | |
639 * Sets the runnable that will be run when VrShellImpl's dispatchTouchEvent | |
640 * is run and the parent consumed the event. | |
641 * @param runnable The Runnable that will be run | |
642 */ | |
643 @VisibleForTesting | |
644 public void setOnDispatchTouchEventForTesting(Runnable runnable) { | |
645 mOnDispatchTouchEventForTesting = runnable; | |
646 } | |
647 | |
631 private native long nativeInit(WebContents uiWebContents, long nativeContent WindowAndroid, | 648 private native long nativeInit(WebContents uiWebContents, long nativeContent WindowAndroid, |
632 long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delega te, long gvrApi, | 649 long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delega te, long gvrApi, |
633 boolean reprojectedRendering); | 650 boolean reprojectedRendering); |
634 private native void nativeSetSurface(long nativeVrShell, Surface surface); | 651 private native void nativeSetSurface(long nativeVrShell, Surface surface); |
635 private native void nativeSwapContents( | 652 private native void nativeSwapContents( |
636 long nativeVrShell, WebContents webContents, MotionEventSynthesizer eventSynthesizer); | 653 long nativeVrShell, WebContents webContents, MotionEventSynthesizer eventSynthesizer); |
637 private native void nativeLoadUIContent(long nativeVrShell); | 654 private native void nativeLoadUIContent(long nativeVrShell); |
638 private native void nativeDestroy(long nativeVrShell); | 655 private native void nativeDestroy(long nativeVrShell); |
639 private native void nativeOnTriggerEvent(long nativeVrShell); | 656 private native void nativeOnTriggerEvent(long nativeVrShell); |
640 private native void nativeOnPause(long nativeVrShell); | 657 private native void nativeOnPause(long nativeVrShell); |
641 private native void nativeOnResume(long nativeVrShell); | 658 private native void nativeOnResume(long nativeVrShell); |
642 private native void nativeOnLoadProgressChanged(long nativeVrShell, double p rogress); | 659 private native void nativeOnLoadProgressChanged(long nativeVrShell, double p rogress); |
643 private native void nativeContentPhysicalBoundsChanged(long nativeVrShell, i nt width, | 660 private native void nativeContentPhysicalBoundsChanged(long nativeVrShell, i nt width, |
644 int height, float dpr); | 661 int height, float dpr); |
645 private native void nativeUIPhysicalBoundsChanged(long nativeVrShell, int wi dth, int height, | 662 private native void nativeUIPhysicalBoundsChanged(long nativeVrShell, int wi dth, int height, |
646 float dpr); | 663 float dpr); |
647 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); | 664 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); |
648 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab s, | 665 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab s, |
649 Tab[] incognitoTabs); | 666 Tab[] incognitoTabs); |
650 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito , int id, | 667 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito , int id, |
651 String title); | 668 String title); |
652 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito , int id); | 669 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito , int id); |
653 private native Surface nativeTakeContentSurface(long nativeVrShell); | 670 private native Surface nativeTakeContentSurface(long nativeVrShell); |
654 private native void nativeRestoreContentSurface(long nativeVrShell); | 671 private native void nativeRestoreContentSurface(long nativeVrShell); |
655 private native void nativeSetHistoryButtonsEnabled( | 672 private native void nativeSetHistoryButtonsEnabled( |
656 long nativeVrShell, boolean canGoBack, boolean canGoForward); | 673 long nativeVrShell, boolean canGoBack, boolean canGoForward); |
657 } | 674 } |
OLD | NEW |