Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Unified Diff: chrome/browser/resources/vr_shell/vr_shell_ui.js

Issue 2500283003: Allow the VR omnibox to be transient. (Closed)
Patch Set: Address some nits; explain others. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/vr_shell/vr_shell_ui.js
diff --git a/chrome/browser/resources/vr_shell/vr_shell_ui.js b/chrome/browser/resources/vr_shell/vr_shell_ui.js
index 1d363bf4f1a3a2326baa0090b98e60a1de821e9b..ee7a3cf0caedd2f563a87d663396797e2d7a8692 100644
--- a/chrome/browser/resources/vr_shell/vr_shell_ui.js
+++ b/chrome/browser/resources/vr_shell/vr_shell_ui.js
@@ -30,9 +30,9 @@ var vrShellUi = (function() {
this.elementId = scene.addElement(element);
}
- show(visible) {
+ setEnabled(enabled) {
let update = new api.UiElementUpdate();
- update.setVisible(visible);
+ update.setVisible(enabled);
scene.updateElement(this.elementId, update);
}
@@ -153,8 +153,8 @@ var vrShellUi = (function() {
scene.updateElement(this.reloadUiButton.uiElementId, update);
}
- show(visible) {
- this.enabled = visible;
+ setEnabled(enabled) {
+ this.enabled = enabled;
this.configure();
}
@@ -206,8 +206,8 @@ var vrShellUi = (function() {
scene.updateElement(this.transientWarning.uiElementId, update);
}
- show(visible) {
- this.enabled = visible;
+ setEnabled(enabled) {
+ this.enabled = enabled;
this.updateState();
}
@@ -251,34 +251,114 @@ var vrShellUi = (function() {
class Omnibox {
constructor(contentQuadId) {
- this.setSecureOrigin(false);
- this.domUiElement = new DomUiElement('#omni');
+ /** @const */ var VISIBILITY_TIMEOUT_MS = 3000;
amp 2016/11/17 21:00:35 Not affecting the review (which looks like it's al
cjgrant 2016/11/17 21:13:12 It keeps the presubmit style checker happy - no ot
+
+ this.domUiElement = new DomUiElement('#omni-container');
+ this.enabled = false;
+ this.secure = false;
+ this.visibilityTimeout = VISIBILITY_TIMEOUT_MS;
+ this.visibilityTimer = null;
+ this.nativeState = {};
+
+ // Initially invisible.
let update = new api.UiElementUpdate();
update.setVisible(false);
scene.updateElement(this.domUiElement.uiElementId, update);
+ this.nativeState.visible = false;
+
+ // Listen to the end of transitions, so that the box can be natively
+ // hidden after it finishes hiding itself.
+ document.querySelector('#omni').addEventListener('transitionend',
+ this.onAnimationDone.bind(this));
}
- show(visible) {
- let update = new api.UiElementUpdate();
- update.setVisible(visible);
- scene.updateElement(this.domUiElement.uiElementId, update);
+ setEnabled(enabled) {
+ this.enabled = enabled;
+ this.resetVisibilityTimer();
+ this.updateState();
}
setLoading(loading) {
- this.domUiElement.domElement.className = loading ? 'loading' : 'idle';
+ this.loading = loading;
+ this.resetVisibilityTimer();
+ this.updateState();
}
setURL(host, path) {
let omnibox = this.domUiElement.domElement;
omnibox.querySelector('#domain').innerHTML = host;
omnibox.querySelector('#path').innerHTML = path;
+ this.resetVisibilityTimer();
+ this.updateState();
}
setSecureOrigin(secure) {
+ this.secure = secure;
+ this.resetVisibilityTimer();
+ this.updateState();
+ }
+
+ setVisibilityTimeout(milliseconds) {
+ this.visibilityTimeout = milliseconds;
+ this.resetVisibilityTimer();
+ this.updateState();
+ }
+
+ resetVisibilityTimer() {
+ if (this.visibilityTimer) {
+ clearInterval(this.visibilityTimer);
+ this.visibilityTimer = null;
+ }
+ if (this.enabled && this.visibilityTimeout > 0) {
+ this.visibilityTimer = setTimeout(
+ this.onVisibilityTimer.bind(this), this.visibilityTimeout);
+ }
+ }
+
+ onVisibilityTimer() {
+ this.visibilityTimer = null;
+ this.updateState();
+ }
+
+ onAnimationDone(e) {
+ if (e.propertyName == 'opacity' && !this.visibleAfterTransition) {
+ this.setNativeVisibility(false);
+ }
+ }
+
+ updateState() {
+ if (!this.enabled) {
+ this.setNativeVisibility(false);
+ return;
+ }
+
document.querySelector('#omni-secure-icon').style.display =
- (secure ? 'block' : 'none');
+ (this.secure ? 'block' : 'none');
document.querySelector('#omni-insecure-icon').style.display =
- (!secure ? 'block' : 'none');
+ (this.secure ? 'none' : 'block');
+
+ let state = 'idle';
+ this.visibleAfterTransition = true;
+ if (this.visibilityTimeout > 0 && !this.visibilityTimer) {
+ state = 'hide';
+ this.visibleAfterTransition = false;
+ } else if (this.loading) {
+ state = 'loading';
+ }
+ document.querySelector('#omni').className = state;
+
+ this.setNativeVisibility(true);
+ }
+
+ setNativeVisibility(visible) {
+ if (visible == this.nativeState.visible) {
+ return;
+ }
+ this.nativeState.visible = visible;
+ let update = new api.UiElementUpdate();
+ update.setVisible(visible);
+ scene.updateElement(this.domUiElement.uiElementId, update);
+ scene.flush();
}
};
@@ -296,10 +376,10 @@ var vrShellUi = (function() {
setMode(mode) {
this.mode = mode;
- this.contentQuad.show(mode == api.Mode.STANDARD);
- this.controls.show(mode == api.Mode.STANDARD);
- this.omnibox.show(mode == api.Mode.STANDARD);
- this.secureOriginWarnings.show(mode == api.Mode.WEB_VR);
+ this.contentQuad.setEnabled(mode == api.Mode.STANDARD);
+ this.controls.setEnabled(mode == api.Mode.STANDARD);
+ this.omnibox.setEnabled(mode == api.Mode.STANDARD);
+ this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR);
}
setSecureOrigin(secure) {
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698