Commit cb6d69f2 authored by cjgrant's avatar cjgrant Committed by Commit bot

Let HTML UI fully manage menu mode.

- Have native pass app button presses up to the UI.
- The UI decides whether or not to be in menu mode.
- The UI may call back down to native to pause content, if desired.

BUG=644565
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2664973002
Cr-Commit-Position: refs/heads/master@{#448017}
parent 5f067c6f
...@@ -27,11 +27,6 @@ void UiInterface::SetMode(Mode mode) { ...@@ -27,11 +27,6 @@ void UiInterface::SetMode(Mode mode) {
FlushModeState(); FlushModeState();
} }
void UiInterface::SetMenuMode(bool enabled) {
menu_mode_ = enabled;
FlushModeState();
}
void UiInterface::SetFullscreen(bool enabled) { void UiInterface::SetFullscreen(bool enabled) {
fullscreen_ = enabled; fullscreen_ = enabled;
FlushModeState(); FlushModeState();
...@@ -49,7 +44,6 @@ void UiInterface::SetOmniboxSuggestions( ...@@ -49,7 +44,6 @@ void UiInterface::SetOmniboxSuggestions(
void UiInterface::FlushModeState() { void UiInterface::FlushModeState() {
updates_.SetInteger("mode", static_cast<int>(mode_)); updates_.SetInteger("mode", static_cast<int>(mode_));
updates_.SetBoolean("menuMode", menu_mode_);
updates_.SetBoolean("fullscreen", fullscreen_); updates_.SetBoolean("fullscreen", fullscreen_);
FlushUpdates(); FlushUpdates();
} }
...@@ -117,6 +111,11 @@ void UiInterface::SetURL(const GURL& url) { ...@@ -117,6 +111,11 @@ void UiInterface::SetURL(const GURL& url) {
FlushUpdates(); FlushUpdates();
} }
void UiInterface::HandleAppButtonClicked() {
updates_.SetBoolean("appButtonClicked", true);
FlushUpdates();
}
void UiInterface::OnDomContentsLoaded() { void UiInterface::OnDomContentsLoaded() {
loaded_ = true; loaded_ = true;
#if defined(ENABLE_VR_SHELL_UI_DEV) #if defined(ENABLE_VR_SHELL_UI_DEV)
......
...@@ -33,12 +33,9 @@ class UiInterface { ...@@ -33,12 +33,9 @@ class UiInterface {
explicit UiInterface(Mode initial_mode, bool fullscreen); explicit UiInterface(Mode initial_mode, bool fullscreen);
virtual ~UiInterface(); virtual ~UiInterface();
// Set HTML UI state or pass events.
void SetMode(Mode mode); void SetMode(Mode mode);
Mode GetMode() { return mode_; }
void SetMenuMode(bool enabled);
bool GetMenuMode() { return menu_mode_; }
void SetFullscreen(bool enabled); void SetFullscreen(bool enabled);
bool GetFullscreen() { return fullscreen_; }
void SetSecurityLevel(int level); void SetSecurityLevel(int level);
void SetWebVRSecureOrigin(bool secure); void SetWebVRSecureOrigin(bool secure);
void SetLoading(bool loading); void SetLoading(bool loading);
...@@ -49,13 +46,13 @@ class UiInterface { ...@@ -49,13 +46,13 @@ class UiInterface {
void UpdateTab(bool incognito, int id, const std::string& title); void UpdateTab(bool incognito, int id, const std::string& title);
void RemoveTab(bool incognito, int id); void RemoveTab(bool incognito, int id);
void SetURL(const GURL& url); void SetURL(const GURL& url);
// Omnibox input and output handling.
void HandleOmniboxInput(const base::DictionaryValue& input);
void SetOmniboxSuggestions(std::unique_ptr<base::Value> suggestions); void SetOmniboxSuggestions(std::unique_ptr<base::Value> suggestions);
void HandleAppButtonClicked();
// Called by WebUI when starting VR. // Handlers for HTML UI commands and notifications.
void OnDomContentsLoaded(); void OnDomContentsLoaded();
void HandleOmniboxInput(const base::DictionaryValue& input);
void SetUiCommandHandler(UiCommandHandler* handler); void SetUiCommandHandler(UiCommandHandler* handler);
private: private:
...@@ -63,7 +60,6 @@ class UiInterface { ...@@ -63,7 +60,6 @@ class UiInterface {
void FlushModeState(); void FlushModeState();
Mode mode_; Mode mode_;
bool menu_mode_ = false;
bool fullscreen_ = false; bool fullscreen_ = false;
UiCommandHandler* handler_; UiCommandHandler* handler_;
bool loaded_ = false; bool loaded_ = false;
......
...@@ -132,8 +132,7 @@ void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj, ...@@ -132,8 +132,7 @@ void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj,
// tabs. crbug.com/684661 // tabs. crbug.com/684661
metrics_helper_ = base::MakeUnique<VrMetricsHelper>(main_contents_); metrics_helper_ = base::MakeUnique<VrMetricsHelper>(main_contents_);
metrics_helper_->SetVRActive(true); metrics_helper_->SetVRActive(true);
metrics_helper_->SetWebVREnabled( metrics_helper_->SetWebVREnabled(webvr_mode_);
html_interface_->GetMode() == UiInterface::Mode::WEB_VR);
} }
void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) {
...@@ -174,6 +173,23 @@ void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { ...@@ -174,6 +173,23 @@ void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
gl_thread_->task_runner()->PostTask(FROM_HERE, task); gl_thread_->task_runner()->PostTask(FROM_HERE, task);
} }
void VrShell::SetContentPaused(bool paused) {
if (content_paused_ == paused)
return;
content_paused_ = paused;
if (!delegate_provider_->device_provider())
return;
// TODO(mthiesse): The page is no longer visible when in menu mode. We
// should unfocus or otherwise let it know it's hidden.
if (paused) {
delegate_provider_->device_provider()->Device()->OnBlur();
} else {
delegate_provider_->device_provider()->Device()->OnFocus();
}
}
void VrShell::OnTriggerEvent(JNIEnv* env, void VrShell::OnTriggerEvent(JNIEnv* env,
const JavaParamRef<jobject>& obj) { const JavaParamRef<jobject>& obj) {
gl_thread_->task_runner()->PostTask( gl_thread_->task_runner()->PostTask(
...@@ -227,14 +243,12 @@ void VrShell::OnDomContentsLoaded() { ...@@ -227,14 +243,12 @@ void VrShell::OnDomContentsLoaded() {
void VrShell::SetWebVrMode(JNIEnv* env, void VrShell::SetWebVrMode(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
bool enabled) { bool enabled) {
webvr_mode_ = enabled;
metrics_helper_->SetWebVREnabled(enabled); metrics_helper_->SetWebVREnabled(enabled);
PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
gl_thread_->GetVrShellGl(), enabled)); gl_thread_->GetVrShellGl(), enabled));
if (enabled) { html_interface_->SetMode(
html_interface_->SetMode(UiInterface::Mode::WEB_VR); enabled ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD);
} else {
html_interface_->SetMode(UiInterface::Mode::STANDARD);
}
} }
void VrShell::OnLoadProgressChanged(JNIEnv* env, void VrShell::OnLoadProgressChanged(JNIEnv* env,
...@@ -321,19 +335,7 @@ void VrShell::GvrDelegateReady() { ...@@ -321,19 +335,7 @@ void VrShell::GvrDelegateReady() {
void VrShell::AppButtonPressed() { void VrShell::AppButtonPressed() {
#if defined(ENABLE_VR_SHELL) #if defined(ENABLE_VR_SHELL)
html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); html_interface_->HandleAppButtonClicked();
// TODO(mthiesse): The page is no longer visible when in menu mode. We
// should unfocus or otherwise let it know it's hidden.
if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
if (delegate_provider_->device_provider()) {
if (html_interface_->GetMenuMode()) {
delegate_provider_->device_provider()->Device()->OnBlur();
} else {
delegate_provider_->device_provider()->Device()->OnFocus();
}
}
}
#endif #endif
} }
...@@ -399,6 +401,12 @@ void VrShell::DoUiAction(const UiAction action, ...@@ -399,6 +401,12 @@ void VrShell::DoUiAction(const UiAction action,
case OMNIBOX_CONTENT: case OMNIBOX_CONTENT:
html_interface_->HandleOmniboxInput(*arguments); html_interface_->HandleOmniboxInput(*arguments);
break; break;
case SET_CONTENT_PAUSED: {
bool paused;
CHECK(arguments->GetBoolean("paused", &paused));
SetContentPaused(paused);
break;
}
#if defined(ENABLE_VR_SHELL_UI_DEV) #if defined(ENABLE_VR_SHELL_UI_DEV)
case RELOAD_UI: case RELOAD_UI:
ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false); ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false);
......
...@@ -55,6 +55,7 @@ enum UiAction { ...@@ -55,6 +55,7 @@ enum UiAction {
RELOAD_UI, RELOAD_UI,
LOAD_URL, LOAD_URL,
OMNIBOX_CONTENT, OMNIBOX_CONTENT,
SET_CONTENT_PAUSED,
}; };
class VrMetricsHelper; class VrMetricsHelper;
...@@ -156,6 +157,7 @@ class VrShell : public device::GvrDelegate, content::WebContentsObserver { ...@@ -156,6 +157,7 @@ class VrShell : public device::GvrDelegate, content::WebContentsObserver {
private: private:
~VrShell() override; ~VrShell() override;
void PostToGlThreadWhenReady(const base::Closure& task); void PostToGlThreadWhenReady(const base::Closure& task);
void SetContentPaused(bool paused);
// content::WebContentsObserver implementation. // content::WebContentsObserver implementation.
void RenderViewHostChanged(content::RenderViewHost* old_host, void RenderViewHostChanged(content::RenderViewHost* old_host,
...@@ -182,6 +184,8 @@ class VrShell : public device::GvrDelegate, content::WebContentsObserver { ...@@ -182,6 +184,8 @@ class VrShell : public device::GvrDelegate, content::WebContentsObserver {
void ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito); void ProcessTabArray(JNIEnv* env, jobjectArray tabs, bool incognito);
std::unique_ptr<UiInterface> html_interface_; std::unique_ptr<UiInterface> html_interface_;
bool content_paused_ = false;
bool webvr_mode_ = false;
content::WebContents* main_contents_; content::WebContents* main_contents_;
std::unique_ptr<VrCompositor> content_compositor_; std::unique_ptr<VrCompositor> content_compositor_;
......
...@@ -573,27 +573,37 @@ var vrShellUi = (function() { ...@@ -573,27 +573,37 @@ var vrShellUi = (function() {
this.reloadUiButton = new ReloadUiButton(); this.reloadUiButton = new ReloadUiButton();
} }
setMode(mode, menuMode, fullscreen) { setMode(mode, fullscreen) {
/** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000;
this.mode = mode; this.mode = mode;
this.menuMode = menuMode;
this.fullscreen = fullscreen; this.fullscreen = fullscreen;
this.updateState();
}
handleAppButtonClicked() {
this.menuMode = !this.menuMode;
this.updateState();
}
updateState() {
/** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000;
let mode = this.mode;
let menuMode = this.menuMode;
api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode});
this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD);
this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode);
this.contentQuad.setFullscreen(fullscreen); this.contentQuad.setFullscreen(this.fullscreen);
// TODO(crbug/643815): Set aspect ratio on content quad when available. // TODO(crbug/643815): Set aspect ratio on content quad when available.
// TODO(amp): Don't show controls in fullscreen once MENU mode lands. this.controls.setEnabled(menuMode);
this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); this.omnibox.setEnabled(menuMode);
this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode);
// TODO(amp): Don't show controls in CINEMA mode once MENU mode lands.
this.urlIndicator.setVisibilityTimeout( this.urlIndicator.setVisibilityTimeout(
mode == api.Mode.STANDARD && !menuMode ? URL_INDICATOR_VISIBILITY_TIMEOUT_MS);
0 : this.secureOriginWarnings.setEnabled(
URL_INDICATOR_VISIBILITY_TIMEOUT_MS); mode == api.Mode.WEB_VR && !menuMode);
this.omnibox.setEnabled(false);
this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD);
api.setUiCssSize( api.setUiCssSize(
uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR); uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR);
...@@ -617,7 +627,10 @@ var vrShellUi = (function() { ...@@ -617,7 +627,10 @@ var vrShellUi = (function() {
function command(dict) { function command(dict) {
if ('mode' in dict) { if ('mode' in dict) {
uiManager.setMode(dict['mode'], dict['menuMode'], dict['fullscreen']); uiManager.setMode(dict['mode'], dict['fullscreen']);
}
if ('appButtonClicked' in dict) {
uiManager.handleAppButtonClicked();
} }
if ('securityLevel' in dict) { if ('securityLevel' in dict) {
uiManager.setSecurityLevel(dict['securityLevel']); uiManager.setSecurityLevel(dict['securityLevel']);
......
...@@ -68,6 +68,7 @@ api.Action = { ...@@ -68,6 +68,7 @@ api.Action = {
'RELOAD_UI': 5, 'RELOAD_UI': 5,
'LOAD_URL': 6, 'LOAD_URL': 6,
'OMNIBOX_CONTENT': 7, 'OMNIBOX_CONTENT': 7,
'SET_CONTENT_PAUSED': 8,
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment