[VR] Javascript Dialogs in VR
This CL enables the Chrome's Javascript Dialog in VR behind a flag.
The View from the 2D dialog is converted into a texture and is
shown in VR on a quad. The events from the controller are translated
to MotionEvents and are sent back to the 2D dialog.
It is made possible to replace ModalDialogManager in ChromeActivity. The
ModalDialogManager is replaced with a new one when going in VR mode, and is
replaced with the old ModalDialogManager when leaving VR.
The ModalDialogManager that is used in VR uses VrModalDialogPresenter that
shows dialogs on a quad in 3D space in front of the main content.
The view from 2D Javascript dialog is attached to the DecorView to
make sure that the View will receive all the event.
The close button will be added to this dialogs in the follow up CLs.
Bug:779126
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Iaae0147d1711297cc7dd992fe3986642669bc102
Reviewed-on: https://chromium-review.googlesource.com/868552
Commit-Queue: Amirhossein Simjour <[email protected]>
Reviewed-by: Michael Thiessen <[email protected]>
Reviewed-by: Ian Vollick <[email protected]>
Reviewed-by: Ted Choc <[email protected]>
Cr-Commit-Position: refs/heads/master@{#534068}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 104e7b0..03c8b7b 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -1929,6 +1929,10 @@
flag_descriptions::kTabModalJsDialogName,
flag_descriptions::kTabModalJsDialogDescription, kOsAndroid,
FEATURE_VALUE_TYPE(chrome::android::kTabModalJsDialog)},
+ {"vr-browsing-native-android-ui",
+ flag_descriptions::kVrBrowsingNativeAndroidUiName,
+ flag_descriptions::kVrBrowsingNativeAndroidUiDescription, kOsAndroid,
+ FEATURE_VALUE_TYPE(chrome::android::kVrBrowsingNativeAndroidUi)},
#endif // OS_ANDROID
{"in-product-help-demo-mode-choice",
flag_descriptions::kInProductHelpDemoModeChoiceName,
diff --git a/chrome/browser/android/chrome_feature_list.cc b/chrome/browser/android/chrome_feature_list.cc
index 1c1c9e3..a2408e6 100644
--- a/chrome/browser/android/chrome_feature_list.cc
+++ b/chrome/browser/android/chrome_feature_list.cc
@@ -120,6 +120,7 @@
&kVideoPersistence,
&kVrBrowsingFeedback,
&kVrBrowsingInCustomTab,
+ &kVrBrowsingNativeAndroidUi,
&kVrIconInDaydreamHome,
&kVrLaunchIntents,
&payments::features::kWebPaymentsMethodSectionOrderV2,
@@ -370,6 +371,9 @@
const base::Feature kVrBrowsingInCustomTab{"VrBrowsingInCustomTab",
base::FEATURE_DISABLED_BY_DEFAULT};
+const base::Feature kVrBrowsingNativeAndroidUi{
+ "VrBrowsingNativeAndroidUi", base::FEATURE_DISABLED_BY_DEFAULT};
+
const base::Feature kVrIconInDaydreamHome{"VrIconInDaydreamHome",
base::FEATURE_DISABLED_BY_DEFAULT};
diff --git a/chrome/browser/android/chrome_feature_list.h b/chrome/browser/android/chrome_feature_list.h
index 0431379..3b60c2a 100644
--- a/chrome/browser/android/chrome_feature_list.h
+++ b/chrome/browser/android/chrome_feature_list.h
@@ -82,6 +82,7 @@
extern const base::Feature kVideoPersistence;
extern const base::Feature kVrBrowsingFeedback;
extern const base::Feature kVrBrowsingInCustomTab;
+extern const base::Feature kVrBrowsingNativeAndroidUi;
extern const base::Feature kVrIconInDaydreamHome;
extern const base::Feature kVrLaunchIntents;
extern const base::Feature kWebPaymentsSingleAppUiSkip;
diff --git a/chrome/browser/android/tab_web_contents_delegate_android.cc b/chrome/browser/android/tab_web_contents_delegate_android.cc
index 1f00f60..3281947 100644
--- a/chrome/browser/android/tab_web_contents_delegate_android.cc
+++ b/chrome/browser/android/tab_web_contents_delegate_android.cc
@@ -273,7 +273,10 @@
content::JavaScriptDialogManager*
TabWebContentsDelegateAndroid::GetJavaScriptDialogManager(
WebContents* source) {
- if (vr::VrTabHelper::IsInVr(source)) {
+ if (vr::VrTabHelper::IsInVr(source) &&
+ (!base::FeatureList::IsEnabled(
+ chrome::android::kVrBrowsingNativeAndroidUi) ||
+ !base::FeatureList::IsEnabled(chrome::android::kTabModalJsDialog))) {
vr::VrTabHelper::UISuppressed(vr::UiSuppressedElement::kJavascriptDialog);
return nullptr;
}
diff --git a/chrome/browser/android/vr_shell/BUILD.gn b/chrome/browser/android/vr_shell/BUILD.gn
index 9af9848..2a02773 100644
--- a/chrome/browser/android/vr_shell/BUILD.gn
+++ b/chrome/browser/android/vr_shell/BUILD.gn
@@ -31,6 +31,8 @@
"vr_controller.h",
"vr_core_info.cc",
"vr_core_info.h",
+ "vr_dialog.cc",
+ "vr_dialog.h",
"vr_gl_thread.cc",
"vr_gl_thread.h",
"vr_metrics_util.cc",
diff --git a/chrome/browser/android/vr_shell/gl_browser_interface.h b/chrome/browser/android/vr_shell/gl_browser_interface.h
index 4ddcb979..b3fc4c13 100644
--- a/chrome/browser/android/vr_shell/gl_browser_interface.h
+++ b/chrome/browser/android/vr_shell/gl_browser_interface.h
@@ -33,6 +33,8 @@
virtual void GvrDelegateReady(
gvr::ViewerType viewer_type,
device::mojom::VRDisplayFrameTransportOptionsPtr) = 0;
+ virtual void DialogSurfaceCreated(jobject surface,
+ gl::SurfaceTexture* texture) = 0;
virtual void UpdateGamepadData(device::GvrGamepadData) = 0;
virtual void ForceExitVr() = 0;
virtual void OnContentPaused(bool enabled) = 0;
diff --git a/chrome/browser/android/vr_shell/vr_dialog.cc b/chrome/browser/android/vr_shell/vr_dialog.cc
new file mode 100644
index 0000000..4d89831
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_dialog.cc
@@ -0,0 +1,98 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/vr_dialog.h"
+
+#include <utility>
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/callback_helpers.h"
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
+
+#include "third_party/WebKit/public/platform/WebMouseEvent.h"
+
+using base::android::JavaParamRef;
+
+namespace vr_shell {
+
+VrDialog::VrDialog(int width, int height) {
+ width_ = width;
+ height_ = height;
+}
+
+VrDialog::~VrDialog() {
+ DVLOG(1) << __FUNCTION__ << "=" << this;
+}
+
+void VrDialog::SetSize(int width, int height) {
+ width_ = width;
+ height_ = height;
+}
+void VrDialog::OnContentEnter(const gfx::PointF& normalized_hit_point) {}
+
+void VrDialog::OnContentLeave() {}
+
+void VrDialog::OnContentMove(const gfx::PointF& normalized_hit_point) {
+ SendGestureToDialog(
+ MakeMouseEvent(blink::WebInputEvent::kMouseMove, normalized_hit_point));
+}
+
+void VrDialog::OnContentDown(const gfx::PointF& normalized_hit_point) {
+ SendGestureToDialog(
+ MakeMouseEvent(blink::WebInputEvent::kMouseDown, normalized_hit_point));
+}
+
+void VrDialog::OnContentUp(const gfx::PointF& normalized_hit_point) {
+ SendGestureToDialog(
+ MakeMouseEvent(blink::WebInputEvent::kMouseUp, normalized_hit_point));
+}
+
+void VrDialog::OnContentFlingStart(
+ std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) {}
+void VrDialog::OnContentFlingCancel(
+ std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) {}
+void VrDialog::OnContentScrollBegin(
+ std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) {}
+void VrDialog::OnContentScrollUpdate(
+ std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) {}
+void VrDialog::OnContentScrollEnd(
+ std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) {}
+
+void VrDialog::SendGestureToDialog(
+ std::unique_ptr<blink::WebInputEvent> event) {
+ if (!event || !dialog_)
+ return;
+ // TODO(asimjour): support switching between dialogs.
+ dialog_->ForwardDialogEvent(std::move(event));
+}
+
+void VrDialog::SetEventForwarder(vr::ContentInputForwarder* dialog) {
+ dialog_ = dialog;
+}
+
+std::unique_ptr<blink::WebMouseEvent> VrDialog::MakeMouseEvent(
+ blink::WebInputEvent::Type type,
+ const gfx::PointF& normalized_web_content_location) {
+ gfx::Point location(width_ * normalized_web_content_location.x(),
+ height_ * normalized_web_content_location.y());
+ blink::WebInputEvent::Modifiers modifiers =
+ blink::WebInputEvent::kNoModifiers;
+
+ // timestamp is not used
+ auto mouse_event = std::make_unique<blink::WebMouseEvent>(type, modifiers, 0);
+ mouse_event->pointer_type = blink::WebPointerProperties::PointerType::kMouse;
+ mouse_event->button = blink::WebPointerProperties::Button::kLeft;
+ mouse_event->SetPositionInWidget(location.x(), location.y());
+ mouse_event->click_count = 1;
+ return mouse_event;
+}
+
+} // namespace vr_shell
diff --git a/chrome/browser/android/vr_shell/vr_dialog.h b/chrome/browser/android/vr_shell/vr_dialog.h
new file mode 100644
index 0000000..4fbc7d5
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_dialog.h
@@ -0,0 +1,67 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_DIALOG_H_
+#define CHROME_BROWSER_ANDROID_VR_SHELL_VR_DIALOG_H_
+
+#include <jni.h>
+
+#include <map>
+#include <memory>
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_weak_ref.h"
+#include "base/callback.h"
+#include "base/cancelable_callback.h"
+#include "base/macros.h"
+#include "chrome/browser/vr/content_input_delegate.h"
+#include "ui/gfx/geometry/quaternion.h"
+#include "ui/gfx/geometry/rect_f.h"
+#include "ui/gfx/geometry/size_f.h"
+#include "ui/gfx/native_widget_types.h"
+
+using base::android::JavaParamRef;
+
+namespace vr_shell {
+class VrDialog : public vr::ContentInputDelegate {
+ public:
+ VrDialog(int width, int height);
+ ~VrDialog() override;
+
+ void SetEventForwarder(vr::ContentInputForwarder* dialog);
+ void SetSize(int width, int height);
+
+ private:
+ vr::ContentInputForwarder* dialog_ = nullptr;
+
+ // vr::ContentInputDelegate.
+ void OnContentEnter(const gfx::PointF& normalized_hit_point) override;
+ void OnContentLeave() override;
+ void OnContentMove(const gfx::PointF& normalized_hit_point) override;
+ void OnContentDown(const gfx::PointF& normalized_hit_point) override;
+ void OnContentUp(const gfx::PointF& normalized_hit_point) override;
+ void OnContentFlingStart(std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) override;
+ void OnContentFlingCancel(std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) override;
+ void OnContentScrollBegin(std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) override;
+ void OnContentScrollUpdate(std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) override;
+ void OnContentScrollEnd(std::unique_ptr<blink::WebGestureEvent> gesture,
+ const gfx::PointF& normalized_hit_point) override;
+ void SendGestureToDialog(std::unique_ptr<blink::WebInputEvent> event);
+
+ std::unique_ptr<blink::WebMouseEvent> MakeMouseEvent(
+ blink::WebInputEvent::Type type,
+ const gfx::PointF& normalized_web_content_location);
+ int width_;
+ int height_;
+
+ DISALLOW_COPY_AND_ASSIGN(VrDialog);
+};
+
+} // namespace vr_shell
+
+#endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_DIALOG_H_
diff --git a/chrome/browser/android/vr_shell/vr_gl_thread.cc b/chrome/browser/android/vr_shell/vr_gl_thread.cc
index 4ea25ea..9b778dfa 100644
--- a/chrome/browser/android/vr_shell/vr_gl_thread.cc
+++ b/chrome/browser/android/vr_shell/vr_gl_thread.cc
@@ -97,12 +97,21 @@
void VrGLThread::ContentOverlaySurfaceCreated(jobject surface,
gl::SurfaceTexture* texture) {
+ DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&VrShell::ContentOverlaySurfaceCreated, weak_vr_shell_,
surface, base::Unretained(texture)));
}
+void VrGLThread::DialogSurfaceCreated(jobject surface,
+ gl::SurfaceTexture* texture) {
+ DCHECK(OnGlThread());
+ main_thread_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&VrShell::DialogSurfaceCreated, weak_vr_shell_,
+ surface, base::Unretained(texture)));
+}
+
void VrGLThread::GvrDelegateReady(
gvr::ViewerType viewer_type,
device::mojom::VRDisplayFrameTransportOptionsPtr transport_options) {
@@ -133,6 +142,14 @@
base::BindOnce(&VrShell::OnWebInputEdited, weak_vr_shell_, info, commit));
}
+void VrGLThread::ForwardDialogEvent(
+ std::unique_ptr<blink::WebInputEvent> event) {
+ DCHECK(OnGlThread());
+ main_thread_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&VrShell::ProcessDialogGesture, weak_vr_shell_,
+ base::Passed(std::move(event))));
+}
+
void VrGLThread::ForceExitVr() {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
diff --git a/chrome/browser/android/vr_shell/vr_gl_thread.h b/chrome/browser/android/vr_shell/vr_gl_thread.h
index 9e347a6d..eb5e31f 100644
--- a/chrome/browser/android/vr_shell/vr_gl_thread.h
+++ b/chrome/browser/android/vr_shell/vr_gl_thread.h
@@ -55,6 +55,8 @@
void GvrDelegateReady(
gvr::ViewerType viewer_type,
device::mojom::VRDisplayFrameTransportOptionsPtr) override;
+ void DialogSurfaceCreated(jobject surface,
+ gl::SurfaceTexture* texture) override;
void UpdateGamepadData(device::GvrGamepadData) override;
void ForceExitVr() override;
void OnContentPaused(bool enabled) override;
@@ -64,6 +66,7 @@
void ForwardEvent(std::unique_ptr<blink::WebInputEvent> event,
int content_id) override;
void OnWebInputEdited(const vr::TextInputInfo& info, bool commit) override;
+ void ForwardDialogEvent(std::unique_ptr<blink::WebInputEvent> event) override;
// vr::UiBrowserInterface implementation (UI calling to VrShell).
void ExitPresent() override;
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc
index 1d1f5b2..a05d19e6 100644
--- a/chrome/browser/android/vr_shell/vr_shell.cc
+++ b/chrome/browser/android/vr_shell/vr_shell.cc
@@ -223,6 +223,14 @@
AndroidUiGestureTarget::FromJavaObject(android_ui_gesture_target));
}
+void VrShell::SetDialogGestureTarget(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ const JavaParamRef<jobject>& dialog_gesture_target) {
+ dialog_gesture_target_.reset(
+ AndroidUiGestureTarget::FromJavaObject(dialog_gesture_target));
+}
+
void VrShell::SetUiState() {
toolbar_->Update();
@@ -484,6 +492,34 @@
ui_->RemoveTab(incognito, id);
}
+void VrShell::SetAlertDialog(JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj,
+ int width,
+ int height) {
+ PostToGlThread(FROM_HERE, base::BindOnce(&VrShellGl::EnableAlertDialog,
+ gl_thread_->GetVrShellGl(),
+ gl_thread_.get(), width, height));
+}
+
+void VrShell::CloseAlertDialog(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj) {
+ PostToGlThread(FROM_HERE, base::BindOnce(&VrShellGl::DisableAlertDialog,
+ gl_thread_->GetVrShellGl()));
+}
+
+void VrShell::SetAlertDialogSize(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj,
+ int width,
+ int height) {
+ if (ui_surface_texture_)
+ ui_surface_texture_->SetDefaultBufferSize(width, height);
+ PostToGlThread(FROM_HERE,
+ base::BindOnce(&VrShellGl::SetAlertDialogSize,
+ gl_thread_->GetVrShellGl(), width, height));
+}
+
void VrShell::ConnectPresentingService(
device::mojom::VRSubmitFrameClientPtr submit_client,
device::mojom::VRPresentationProviderRequest request,
@@ -526,6 +562,14 @@
Java_VrShellImpl_contentOverlaySurfaceCreated(env, j_vr_shell_, ref);
}
+void VrShell::DialogSurfaceCreated(jobject surface,
+ gl::SurfaceTexture* texture) {
+ ui_surface_texture_ = texture;
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::ScopedJavaGlobalRef<jobject> ref(env, surface);
+ Java_VrShellImpl_dialogSurfaceCreated(env, j_vr_shell_, ref);
+}
+
void VrShell::GvrDelegateReady(
gvr::ViewerType viewer_type,
device::mojom::VRDisplayFrameTransportOptionsPtr transport_options) {
@@ -861,6 +905,14 @@
android_ui_gesture_target_->DispatchWebInputEvent(std::move(event));
}
+void VrShell::ProcessDialogGesture(
+ std::unique_ptr<blink::WebInputEvent> event) {
+ if (!dialog_gesture_target_)
+ return;
+
+ dialog_gesture_target_->DispatchWebInputEvent(std::move(event));
+}
+
void VrShell::UpdateGamepadData(device::GvrGamepadData pad) {
if (gvr_gamepad_source_active_ != pad.connected)
ToggleGvrGamepad(pad.connected);
diff --git a/chrome/browser/android/vr_shell/vr_shell.h b/chrome/browser/android/vr_shell/vr_shell.h
index 0880050..5eb1591 100644
--- a/chrome/browser/android/vr_shell/vr_shell.h
+++ b/chrome/browser/android/vr_shell/vr_shell.h
@@ -17,6 +17,7 @@
#include "base/strings/string16.h"
#include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h"
#include "chrome/browser/vr/assets_load_status.h"
+#include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/exit_vr_prompt_choice.h"
#include "chrome/browser/vr/speech_recognizer.h"
#include "chrome/browser/vr/ui.h"
@@ -91,6 +92,10 @@
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& android_ui_gesture_target);
+ void SetDialogGestureTarget(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj,
+ const base::android::JavaParamRef<jobject>& dialog_gesture_target);
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
void OnTriggerEvent(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
@@ -155,6 +160,7 @@
device::mojom::VRDisplayFrameTransportOptionsPtr
GetVRDisplayFrameTransportOptions();
+ void DialogSurfaceCreated(jobject surface, gl::SurfaceTexture* texture);
void BufferBoundsChanged(JNIEnv* env,
const base::android::JavaParamRef<jobject>& object,
@@ -185,6 +191,19 @@
void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent> event,
int content_id);
+ void ProcessDialogGesture(std::unique_ptr<blink::WebInputEvent> event);
+
+ void SetAlertDialog(JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj,
+ int width,
+ int height);
+ void CloseAlertDialog(JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj);
+ void SetAlertDialogSize(JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj,
+ int width,
+ int height);
+
void ConnectPresentingService(
device::mojom::VRSubmitFrameClientPtr submit_client,
device::mojom::VRPresentationProviderRequest request,
@@ -240,6 +259,7 @@
base::android::ScopedJavaGlobalRef<jobject> j_vr_shell_;
std::unique_ptr<AndroidUiGestureTarget> android_ui_gesture_target_;
+ std::unique_ptr<AndroidUiGestureTarget> dialog_gesture_target_;
std::unique_ptr<VrMetricsHelper> metrics_helper_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
@@ -286,6 +306,7 @@
gl::SurfaceTexture* content_surface_texture_ = nullptr;
gl::SurfaceTexture* overlay_surface_texture_ = nullptr;
+ gl::SurfaceTexture* ui_surface_texture_ = nullptr;
base::WeakPtrFactory<VrShell> weak_ptr_factory_;
diff --git a/chrome/browser/android/vr_shell/vr_shell_delegate.h b/chrome/browser/android/vr_shell/vr_shell_delegate.h
index c4f1028..8d13667 100644
--- a/chrome/browser/android/vr_shell/vr_shell_delegate.h
+++ b/chrome/browser/android/vr_shell/vr_shell_delegate.h
@@ -15,6 +15,7 @@
#include "base/cancelable_callback.h"
#include "base/macros.h"
#include "chrome/browser/android/vr_shell/vr_core_info.h"
+#include "chrome/browser/vr/content_input_delegate.h"
#include "device/vr/android/gvr/gvr_delegate_provider.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
diff --git a/chrome/browser/android/vr_shell/vr_shell_gl.cc b/chrome/browser/android/vr_shell/vr_shell_gl.cc
index 7c41afda..ba2e2ad 100644
--- a/chrome/browser/android/vr_shell/vr_shell_gl.cc
+++ b/chrome/browser/android/vr_shell/vr_shell_gl.cc
@@ -245,15 +245,17 @@
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
- unsigned int textures[3];
- glGenTextures(3, textures);
+ unsigned int textures[4];
+ glGenTextures(4, textures);
webvr_texture_id_ = textures[0];
unsigned int content_texture_id = textures[1];
unsigned int content_overlay_texture_id = textures[2];
+ unsigned int ui_texture_id = textures[3];
content_surface_texture_ = gl::SurfaceTexture::Create(content_texture_id);
content_overlay_surface_texture_ =
gl::SurfaceTexture::Create(content_overlay_texture_id);
+ ui_surface_texture_ = gl::SurfaceTexture::Create(ui_texture_id);
webvr_surface_texture_ = gl::SurfaceTexture::Create(webvr_texture_id_);
content_surface_ =
@@ -266,17 +268,25 @@
content_overlay_surface_->j_surface().obj(),
content_overlay_surface_texture_.get());
+ ui_surface_ =
+ base::MakeUnique<gl::ScopedJavaSurface>(ui_surface_texture_.get());
+ browser_->DialogSurfaceCreated(ui_surface_->j_surface().obj(),
+ ui_surface_texture_.get());
+
content_surface_texture_->SetFrameAvailableCallback(base::Bind(
&VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
content_overlay_surface_texture_->SetFrameAvailableCallback(
base::BindRepeating(&VrShellGl::OnContentOverlayFrameAvailable,
weak_ptr_factory_.GetWeakPtr()));
- webvr_surface_texture_->SetFrameAvailableCallback(base::BindRepeating(
- &VrShellGl::OnWebVRFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
+ ui_surface_texture_->SetFrameAvailableCallback(base::Bind(
+ &VrShellGl::OnUiFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
+
content_surface_texture_->SetDefaultBufferSize(
content_tex_buffer_size_.width(), content_tex_buffer_size_.height());
content_overlay_surface_texture_->SetDefaultBufferSize(
content_tex_buffer_size_.width(), content_tex_buffer_size_.height());
+ ui_surface_texture_->SetDefaultBufferSize(content_tex_buffer_size_.width(),
+ content_tex_buffer_size_.height());
webvr_vsync_align_ = base::FeatureList::IsEnabled(features::kWebVrVsyncAlign);
@@ -302,10 +312,10 @@
if (!reinitializing)
InitializeRenderer();
- ui_->OnGlInitialized(content_texture_id,
- vr::UiElementRenderer::kTextureLocationExternal,
- content_overlay_texture_id,
- vr::UiElementRenderer::kTextureLocationExternal, true);
+ ui_->OnGlInitialized(
+ content_texture_id, vr::UiElementRenderer::kTextureLocationExternal,
+ content_overlay_texture_id,
+ vr::UiElementRenderer::kTextureLocationExternal, ui_texture_id, true);
webvr_vsync_align_ = base::FeatureList::IsEnabled(features::kWebVrVsyncAlign);
@@ -450,6 +460,25 @@
ui_->OnAssetsLoaded(status, std::move(assets), component_version);
}
+void VrShellGl::EnableAlertDialog(vr::ContentInputForwarder* input_forwarder,
+ int width,
+ int height) {
+ vr_dialog_.reset(new VrDialog(width, height));
+ vr_dialog_->SetEventForwarder(input_forwarder);
+ ui_->SetAlertDialogEnabled(true, vr_dialog_.get(), width, height);
+}
+
+void VrShellGl::DisableAlertDialog() {
+ ui_->SetAlertDialogEnabled(false, nullptr, 0, 0);
+ vr_dialog_ = nullptr;
+}
+
+void VrShellGl::SetAlertDialogSize(int width, int height) {
+ if (vr_dialog_)
+ vr_dialog_->SetSize(width, height);
+ ui_->SetAlertDialogSize(width, height);
+}
+
void VrShellGl::OnContentFrameAvailable() {
content_surface_texture_->UpdateTexImage();
content_frame_available_ = true;
@@ -459,6 +488,10 @@
content_overlay_surface_texture_->UpdateTexImage();
}
+void VrShellGl::OnUiFrameAvailable() {
+ ui_surface_texture_->UpdateTexImage();
+}
+
void VrShellGl::OnWebVRFrameAvailable() {
// A "while" loop here is a bad idea. It's legal to call
// UpdateTexImage repeatedly even if no frames are available, but
diff --git a/chrome/browser/android/vr_shell/vr_shell_gl.h b/chrome/browser/android/vr_shell/vr_shell_gl.h
index ecc4387..68d3a21 100644
--- a/chrome/browser/android/vr_shell/vr_shell_gl.h
+++ b/chrome/browser/android/vr_shell/vr_shell_gl.h
@@ -17,6 +17,7 @@
#include "base/single_thread_task_runner.h"
#include "chrome/browser/android/vr_shell/android_vsync_helper.h"
#include "chrome/browser/android/vr_shell/vr_controller.h"
+#include "chrome/browser/android/vr_shell/vr_dialog.h"
#include "chrome/browser/vr/assets_load_status.h"
#include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/controller_mesh.h"
@@ -106,6 +107,8 @@
void ContentBoundsChanged(int width, int height);
void BufferBoundsChanged(const gfx::Size& content_buffer_size,
const gfx::Size& overlay_buffer_size);
+ void UIBoundsChanged(int width, int height);
+
base::WeakPtr<VrShellGl> GetWeakPtr();
void SetControllerMesh(std::unique_ptr<vr::ControllerMesh> mesh);
@@ -124,6 +127,13 @@
std::unique_ptr<vr::Assets> assets,
const base::Version& component_version);
+ void EnableAlertDialog(vr::ContentInputForwarder* input_forwarder,
+ int width,
+ int height);
+ void DisableAlertDialog();
+
+ void SetAlertDialogSize(int width, int height);
+
private:
void GvrInit(gvr_context* gvr_api);
device::mojom::VRDisplayFrameTransportOptionsPtr
@@ -158,6 +168,7 @@
void OnContentFrameAvailable();
void OnContentOverlayFrameAvailable();
+ void OnUiFrameAvailable();
void OnWebVRFrameAvailable();
void ScheduleOrCancelWebVrFrameTimeout();
void OnWebVrTimeoutImminent();
@@ -199,9 +210,10 @@
scoped_refptr<gl::GLContext> context_;
scoped_refptr<gl::SurfaceTexture> content_surface_texture_;
scoped_refptr<gl::SurfaceTexture> content_overlay_surface_texture_;
+ scoped_refptr<gl::SurfaceTexture> ui_surface_texture_;
scoped_refptr<gl::SurfaceTexture> webvr_surface_texture_;
-
std::unique_ptr<gl::ScopedJavaSurface> content_surface_;
+ std::unique_ptr<gl::ScopedJavaSurface> ui_surface_;
std::unique_ptr<gl::ScopedJavaSurface> content_overlay_surface_;
std::unique_ptr<gvr::GvrApi> gvr_api_;
@@ -319,6 +331,8 @@
vr::ControllerModel controller_model_;
+ std::unique_ptr<VrDialog> vr_dialog_;
+
base::WeakPtrFactory<VrShellGl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(VrShellGl);
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index 56dab6ce..e9f3f522 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -2218,6 +2218,10 @@
R"*(When enabled, an "Update Chrome" item will be shown in the app )*"
R"*(menu.)*";
+const char kVrBrowsingNativeAndroidUiName[] = "VR browsing native android ui";
+const char kVrBrowsingNativeAndroidUiDescription[] =
+ "Enable Android UI elements in VR.";
+
const char kThirdPartyDoodlesName[] =
"Enable Doodles for third-party search engines";
const char kThirdPartyDoodlesDescription[] =
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
index 607ecd2..0598ddca 100644
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -1348,6 +1348,9 @@
extern const char kUpdateMenuItemName[];
extern const char kUpdateMenuItemDescription[];
+extern const char kVrBrowsingNativeAndroidUiName[];
+extern const char kVrBrowsingNativeAndroidUiDescription[];
+
extern const char kThirdPartyDoodlesName[];
extern const char kThirdPartyDoodlesDescription[];
diff --git a/chrome/browser/vr/BUILD.gn b/chrome/browser/vr/BUILD.gn
index 73a74e3..e8e7a6fb 100644
--- a/chrome/browser/vr/BUILD.gn
+++ b/chrome/browser/vr/BUILD.gn
@@ -146,6 +146,7 @@
"model/modal_prompt_type.h",
"model/model.cc",
"model/model.h",
+ "model/native_ui_model.h",
"model/omnibox_suggestions.cc",
"model/omnibox_suggestions.h",
"model/reticle_model.h",
diff --git a/chrome/browser/vr/content_input_delegate.h b/chrome/browser/vr/content_input_delegate.h
index 59af844..2505d0c 100644
--- a/chrome/browser/vr/content_input_delegate.h
+++ b/chrome/browser/vr/content_input_delegate.h
@@ -31,6 +31,8 @@
int content_id) = 0;
// Text input specific.
virtual void OnWebInputEdited(const TextInputInfo& info, bool commit) = 0;
+ virtual void ForwardDialogEvent(
+ std::unique_ptr<blink::WebInputEvent> event) = 0;
};
class PlatformController;
@@ -38,14 +40,15 @@
// Receives interaction events with the web content.
class ContentInputDelegate {
public:
+ ContentInputDelegate() {}
explicit ContentInputDelegate(ContentInputForwarder* content);
virtual ~ContentInputDelegate();
- void OnContentEnter(const gfx::PointF& normalized_hit_point);
- void OnContentLeave();
- void OnContentMove(const gfx::PointF& normalized_hit_point);
- void OnContentDown(const gfx::PointF& normalized_hit_point);
- void OnContentUp(const gfx::PointF& normalized_hit_point);
+ virtual void OnContentEnter(const gfx::PointF& normalized_hit_point);
+ virtual void OnContentLeave();
+ virtual void OnContentMove(const gfx::PointF& normalized_hit_point);
+ virtual void OnContentDown(const gfx::PointF& normalized_hit_point);
+ virtual void OnContentUp(const gfx::PointF& normalized_hit_point);
// Text Input specific.
void OnWebInputEdited(const TextInputInfo& info, bool commit);
diff --git a/chrome/browser/vr/elements/content_element.cc b/chrome/browser/vr/elements/content_element.cc
index ec46aeb..d6340eb 100644
--- a/chrome/browser/vr/elements/content_element.cc
+++ b/chrome/browser/vr/elements/content_element.cc
@@ -77,53 +77,64 @@
}
void ContentElement::OnHoverEnter(const gfx::PointF& position) {
- delegate_->OnContentEnter(position);
+ if (delegate_)
+ delegate_->OnContentEnter(position);
}
void ContentElement::OnHoverLeave() {
- delegate_->OnContentLeave();
+ if (delegate_)
+
+ delegate_->OnContentLeave();
}
void ContentElement::OnMove(const gfx::PointF& position) {
- delegate_->OnContentMove(position);
+ if (delegate_)
+ delegate_->OnContentMove(position);
}
void ContentElement::OnButtonDown(const gfx::PointF& position) {
- delegate_->OnContentDown(position);
+ if (delegate_)
+ delegate_->OnContentDown(position);
}
void ContentElement::OnButtonUp(const gfx::PointF& position) {
- delegate_->OnContentUp(position);
+ if (delegate_)
+ delegate_->OnContentUp(position);
}
void ContentElement::OnFlingStart(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
- delegate_->OnContentFlingStart(std::move(gesture), position);
+ if (delegate_)
+ delegate_->OnContentFlingStart(std::move(gesture), position);
}
void ContentElement::OnFlingCancel(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
- delegate_->OnContentFlingCancel(std::move(gesture), position);
+ if (delegate_)
+ delegate_->OnContentFlingCancel(std::move(gesture), position);
}
void ContentElement::OnScrollBegin(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
- delegate_->OnContentScrollBegin(std::move(gesture), position);
+ if (delegate_)
+ delegate_->OnContentScrollBegin(std::move(gesture), position);
}
void ContentElement::OnScrollUpdate(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
- delegate_->OnContentScrollUpdate(std::move(gesture), position);
+ if (delegate_)
+ delegate_->OnContentScrollUpdate(std::move(gesture), position);
}
void ContentElement::OnScrollEnd(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
- delegate_->OnContentScrollEnd(std::move(gesture), position);
+ if (delegate_)
+ delegate_->OnContentScrollEnd(std::move(gesture), position);
}
void ContentElement::SetTextureId(unsigned int texture_id) {
@@ -229,4 +240,8 @@
return false;
}
+void ContentElement::SetDelegate(ContentInputDelegate* delegate) {
+ delegate_ = delegate;
+}
+
} // namespace vr
diff --git a/chrome/browser/vr/elements/content_element.h b/chrome/browser/vr/elements/content_element.h
index 069941f..e883a6b 100644
--- a/chrome/browser/vr/elements/content_element.h
+++ b/chrome/browser/vr/elements/content_element.h
@@ -54,6 +54,7 @@
void SetOverlayTextureLocation(UiElementRenderer::TextureLocation location);
void SetProjectionMatrix(const gfx::Transform& matrix);
void SetTextInputDelegate(TextInputDelegate* text_input_delegate);
+ void SetDelegate(ContentInputDelegate* delegate);
private:
ContentInputDelegate* delegate_ = nullptr;
diff --git a/chrome/browser/vr/elements/ui_element_name.cc b/chrome/browser/vr/elements/ui_element_name.cc
index d4cce872c..a5f236e 100644
--- a/chrome/browser/vr/elements/ui_element_name.cc
+++ b/chrome/browser/vr/elements/ui_element_name.cc
@@ -82,6 +82,9 @@
"kAudioPermissionPrompt",
"kAudioPermissionPromptShadow",
"kAudioPermissionPromptBackplane",
+ "kPermissionDialogBackplane",
+ "kHostedUi",
+ "kHostedUiBackplane",
"kWebVrUrlToastTransientParent",
"kWebVrUrlToast",
"kExclusiveScreenToastTransientParent",
diff --git a/chrome/browser/vr/elements/ui_element_name.h b/chrome/browser/vr/elements/ui_element_name.h
index 9d52a29da..dc222fba 100644
--- a/chrome/browser/vr/elements/ui_element_name.h
+++ b/chrome/browser/vr/elements/ui_element_name.h
@@ -81,6 +81,9 @@
kAudioPermissionPrompt,
kAudioPermissionPromptShadow,
kAudioPermissionPromptBackplane,
+ kPermissionDialogBackplane,
+ kHostedUi,
+ kHostedUiBackplane,
kWebVrUrlToastTransientParent,
kWebVrUrlToast,
kExclusiveScreenToastTransientParent,
diff --git a/chrome/browser/vr/model/model.h b/chrome/browser/vr/model/model.h
index 3dc67b7b..c6c35c60 100644
--- a/chrome/browser/vr/model/model.h
+++ b/chrome/browser/vr/model/model.h
@@ -9,6 +9,7 @@
#include "chrome/browser/vr/model/color_scheme.h"
#include "chrome/browser/vr/model/controller_model.h"
#include "chrome/browser/vr/model/modal_prompt_type.h"
+#include "chrome/browser/vr/model/native_ui_model.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/reticle_model.h"
#include "chrome/browser/vr/model/speech_recognition_model.h"
@@ -88,6 +89,7 @@
bool experimental_features_enabled = false;
bool skips_redraw_when_not_dirty = false;
bool exiting_vr = false;
+ NativeUiModel native_ui;
};
} // namespace vr
diff --git a/chrome/browser/vr/model/native_ui_model.h b/chrome/browser/vr/model/native_ui_model.h
new file mode 100644
index 0000000..0d61afe
--- /dev/null
+++ b/chrome/browser/vr/model/native_ui_model.h
@@ -0,0 +1,21 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_VR_MODEL_NATIVE_UI_MODEL_H_
+#define CHROME_BROWSER_VR_MODEL_NATIVE_UI_MODEL_H_
+
+#include "chrome/browser/vr/content_input_delegate.h"
+
+namespace vr {
+typedef ContentInputDelegate* ContentInputDelegatePtr;
+struct NativeUiModel {
+ bool hosted_ui_enabled = false;
+ float size_ratio = 0;
+ ContentInputDelegatePtr delegate = nullptr;
+ unsigned int texture_id = 0;
+};
+
+} // namespace vr
+
+#endif // CHROME_BROWSER_VR_MODEL_NATIVE_UI_MODEL_H_
diff --git a/chrome/browser/vr/test/ui_pixel_test.cc b/chrome/browser/vr/test/ui_pixel_test.cc
index 189b9d9..785d82a 100644
--- a/chrome/browser/vr/test/ui_pixel_test.cc
+++ b/chrome/browser/vr/test/ui_pixel_test.cc
@@ -62,7 +62,7 @@
ui_->OnGlInitialized(content_texture_,
vr::UiElementRenderer::kTextureLocationLocal,
content_overlay_texture_,
- vr::UiElementRenderer::kTextureLocationLocal, true);
+ vr::UiElementRenderer::kTextureLocationLocal, 0, true);
ui_->GetBrowserUiWeakPtr()->SetToolbarState(toolbar_state);
}
diff --git a/chrome/browser/vr/testapp/vr_test_context.cc b/chrome/browser/vr/testapp/vr_test_context.cc
index e123c99..a5a1eed 100644
--- a/chrome/browser/vr/testapp/vr_test_context.cc
+++ b/chrome/browser/vr/testapp/vr_test_context.cc
@@ -361,7 +361,7 @@
ui_->OnGlInitialized(
content_texture_id, UiElementRenderer::kTextureLocationLocal,
- content_texture_id, UiElementRenderer::kTextureLocationLocal, false);
+ content_texture_id, UiElementRenderer::kTextureLocationLocal, 0, false);
keyboard_delegate_->Initialize(ui_->scene()->SurfaceProviderForTesting(),
ui_->ui_element_renderer());
diff --git a/chrome/browser/vr/ui.cc b/chrome/browser/vr/ui.cc
index 1839a272..90c605b 100644
--- a/chrome/browser/vr/ui.cc
+++ b/chrome/browser/vr/ui.cc
@@ -226,6 +226,21 @@
model_->web_input_text_field_info.text = text;
}
+void Ui::SetAlertDialogEnabled(bool enabled,
+ ContentInputDelegate* delegate,
+ int width,
+ int height) {
+ model_->native_ui.hosted_ui_enabled = enabled;
+ model_->native_ui.size_ratio =
+ static_cast<float>(height) / static_cast<float>(width);
+ model_->native_ui.delegate = delegate;
+}
+
+void Ui::SetAlertDialogSize(int width, int height) {
+ model_->native_ui.size_ratio =
+ static_cast<float>(height) / static_cast<float>(width);
+}
+
bool Ui::ShouldRenderWebVr() {
return model_->web_vr.has_produced_frames();
}
@@ -235,6 +250,7 @@
UiElementRenderer::TextureLocation content_location,
unsigned int content_overlay_texture_id,
UiElementRenderer::TextureLocation content_overlay_location,
+ unsigned int ui_texture_id,
bool use_ganesh) {
ui_element_renderer_ = std::make_unique<UiElementRenderer>();
ui_renderer_ =
@@ -249,6 +265,7 @@
model_->content_overlay_texture_id = content_overlay_texture_id;
model_->content_location = content_location;
model_->content_overlay_location = content_overlay_location;
+ model_->native_ui.texture_id = ui_texture_id;
}
void Ui::RequestFocus(int element_id) {
diff --git a/chrome/browser/vr/ui.h b/chrome/browser/vr/ui.h
index 46b6935..ab6737d 100644
--- a/chrome/browser/vr/ui.h
+++ b/chrome/browser/vr/ui.h
@@ -111,6 +111,11 @@
int composition_end) override;
void UpdateWebInputText(const base::string16& text) override;
+ void SetAlertDialogEnabled(bool enabled,
+ ContentInputDelegate* delegate,
+ int width,
+ int height);
+ void SetAlertDialogSize(int width, int height);
bool ShouldRenderWebVr();
void OnGlInitialized(
@@ -118,6 +123,7 @@
UiElementRenderer::TextureLocation content_location,
unsigned int content_overlay_texture_id,
UiElementRenderer::TextureLocation content_overlay_location,
+ unsigned int ui_texture_id,
bool use_ganesh);
void OnAppButtonClicked();
diff --git a/chrome/browser/vr/ui_scene_constants.h b/chrome/browser/vr/ui_scene_constants.h
index 750eead5..a2a6ab9 100644
--- a/chrome/browser/vr/ui_scene_constants.h
+++ b/chrome/browser/vr/ui_scene_constants.h
@@ -201,6 +201,10 @@
static constexpr float kTimeoutButtonTextHeightDMM = 0.024f;
static constexpr float kTimeoutButtonTextVerticalOffsetDMM = 0.024f;
+static constexpr float kHostedUiHeightRatio = 0.6f;
+static constexpr float kHostedUiWidthRatio = 0.6f;
+static constexpr float kHostedUiDepthOffset = 0.3f;
+
static constexpr float kScreenDimmerOpacity = 0.9f;
static constexpr gfx::Point3F kOrigin = {0.0f, 0.0f, 0.0f};
diff --git a/chrome/browser/vr/ui_scene_creator.cc b/chrome/browser/vr/ui_scene_creator.cc
index edf027d..93dab4c 100644
--- a/chrome/browser/vr/ui_scene_creator.cc
+++ b/chrome/browser/vr/ui_scene_creator.cc
@@ -586,6 +586,7 @@
CreateBackground();
CreateViewportAwareRoot();
CreateContentQuad();
+ CreateHostedUi();
CreateExitPrompt();
CreateAudioPermissionPrompt();
CreateSystemIndicators();
@@ -606,6 +607,58 @@
CreateController();
}
+void UiSceneCreator::CreateHostedUi() {
+ auto backplane = std::make_unique<InvisibleHitTarget>();
+ backplane->SetDrawPhase(kPhaseForeground);
+ backplane->SetName(kHostedUiBackplane);
+ backplane->SetSize(kPromptBackplaneSize, kPromptBackplaneSize);
+ backplane->SetTranslate(0.0,
+ kContentVerticalOffset + kExitPromptVerticalOffset,
+ -kContentDistance);
+ VR_BIND_VISIBILITY(backplane, model->native_ui.hosted_ui_enabled);
+
+ std::unique_ptr<ContentElement> hosted_ui = std::make_unique<ContentElement>(
+ content_input_delegate_, base::Bind([](const gfx::SizeF&) {}));
+ hosted_ui->SetName(kHostedUi);
+ hosted_ui->SetDrawPhase(kPhaseForeground);
+ hosted_ui->SetSize(kContentWidth * kHostedUiWidthRatio,
+ kContentHeight * kHostedUiHeightRatio);
+ hosted_ui->SetVisible(false);
+ hosted_ui->set_requires_layout(false);
+ hosted_ui->set_corner_radius(kContentCornerRadius);
+ hosted_ui->SetTransitionedProperties({BOUNDS});
+ hosted_ui->SetTranslate(0, 0, kHostedUiDepthOffset);
+
+ hosted_ui->AddBinding(VR_BIND_FUNC(ContentInputDelegatePtr, Model, model_,
+ model->native_ui.delegate, ContentElement,
+ hosted_ui.get(), SetDelegate));
+ hosted_ui->AddBinding(
+ VR_BIND_FUNC(unsigned int, Model, model_, model->native_ui.texture_id,
+ ContentElement, hosted_ui.get(), SetTextureId));
+ hosted_ui->AddBinding(std::make_unique<Binding<bool>>(
+ base::Bind([](Model* m) { return m->native_ui.hosted_ui_enabled; },
+ base::Unretained(model_)),
+ base::Bind(
+ [](ContentElement* dialog, const bool& enabled) {
+ dialog->SetVisible(enabled);
+ dialog->set_requires_layout(enabled);
+ dialog->set_hit_testable(enabled);
+ },
+ base::Unretained(hosted_ui.get()))));
+
+ hosted_ui->AddBinding(std::make_unique<Binding<float>>(
+ base::Bind([](Model* m) { return m->native_ui.size_ratio; },
+ base::Unretained(model_)),
+ base::Bind(
+ [](ContentElement* dialog, const float& value) {
+ dialog->SetSize(kContentWidth * kHostedUiWidthRatio,
+ kContentWidth * kHostedUiWidthRatio * value);
+ },
+ base::Unretained(hosted_ui.get()))));
+ backplane->AddChild(std::move(hosted_ui));
+ scene_->AddUiElement(k2dBrowsingRoot, std::move(backplane));
+}
+
void UiSceneCreator::Create2dBrowsingSubtreeRoots() {
auto element = Create<UiElement>(k2dBrowsingRoot, kPhaseNone);
element->set_hit_testable(false);
diff --git a/chrome/browser/vr/ui_scene_creator.h b/chrome/browser/vr/ui_scene_creator.h
index 3a08ff6..fbcfdc5 100644
--- a/chrome/browser/vr/ui_scene_creator.h
+++ b/chrome/browser/vr/ui_scene_creator.h
@@ -6,9 +6,11 @@
#define CHROME_BROWSER_VR_UI_SCENE_CREATOR_H_
#include "base/macros.h"
+#include "chrome/browser/vr/elements/content_element.h"
#include "chrome/browser/vr/elements/text_input.h"
#include "chrome/browser/vr/elements/ui_element_name.h"
#include "chrome/browser/vr/keyboard_delegate.h"
+#include "ui/gfx/geometry/size_f.h"
namespace vr {
@@ -63,6 +65,7 @@
void CreateWebVrTimeoutScreen();
void CreateController();
void CreateKeyboard();
+ void CreateHostedUi();
UiBrowserInterface* browser_;
UiScene* scene_;