Chromium Code Reviews| 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 36e1a057b962c878b1a1725874a772102cbe4e88..37e73eb7ef99b75e4dc50e5ab7b40429bbf6dc0c 100644 |
| --- a/chrome/browser/resources/vr_shell/vr_shell_ui.js |
| +++ b/chrome/browser/resources/vr_shell/vr_shell_ui.js |
| @@ -6,7 +6,7 @@ cr.define('chrome.vrShellUi', function() { |
| 'use strict'; |
| var scene = new ui.Scene(); |
| - var uiElements = []; |
| + var state; |
| class DomUiElement { |
| constructor(domId) { |
| @@ -61,58 +61,83 @@ cr.define('chrome.vrShellUi', function() { |
| } |
| }; |
| - function initialize() { |
| + class UiState { |
| + constructor() { |
| + this.mode = -1; |
| + this.createMenuButtons(); |
| + scene.flush(); |
| + } |
| + |
| + createMenuButtons() { |
|
mthiesse
2016/10/19 18:53:50
Not to be super picky about this (I'm being super
cjgrant
2016/10/19 19:37:39
Picky is good. :) I was minimizing the code chan
cjgrant
2016/10/20 20:27:30
Done.
|
| + this.menuButtons = []; |
| + var buttons = [ |
| + ['#back', function() { |
| + api.doAction(api.Action.HISTORY_BACK); |
| + }], |
| + ['#reload', function() { |
| + api.doAction(api.Action.RELOAD); |
| + }], |
| + ['#forward', function() { |
| + api.doAction(api.Action.HISTORY_FORWARD); |
| + }], |
| + ]; |
| + |
| + var buttonSpacing = 0.3; |
| + var buttonStartPosition = -buttonSpacing * (buttons.length / 2.0 - 0.5); |
| + |
| + for (var i = 0; i < buttons.length; i++) { |
| + // Use an invisible parent to simplify Z-axis movement on hover. |
| + var position = new api.UiElement(0, 0, 0, 0); |
| + position.setParentId(api.getContentElementId()); |
| + position.setVisible(false); |
| + position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); |
| + position.setTranslation( |
| + buttonStartPosition + i * buttonSpacing, -0.3, 0.3); |
| + var id = scene.addElement(position); |
| + |
| + var domId = buttons[i][0]; |
| + var callback = buttons[i][1]; |
| + var element = new RoundButton(domId, callback); |
| + this.menuButtons.push(element); |
| + |
| + var update = new api.UiElementUpdate(); |
| + update.setParentId(id); |
| + update.setVisible(false); |
| + update.setScale(2.2, 2.2, 1); |
| + scene.updateElement(element.uiElementId, update); |
| + } |
| + } |
| + |
| + showMenuButtons(visible) { |
| + for (var i = 0; i < this.menuButtons.length; i++) { |
| + var update = new api.UiElementUpdate(); |
| + update.setVisible(visible); |
| + scene.updateElement(this.menuButtons[i].uiElementId, update); |
| + } |
| + scene.flush(); |
| + } |
| - domLoaded(); |
| + setMode(mode) { |
| + this.showMenuButtons(mode == api.Mode.STANDARD); |
| + } |
| + }; |
| + |
| + function initialize() { |
| // Change the body background so that the transparency applies. |
| window.setTimeout(function() { |
| document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)'; |
| }, 100); |
| - addControlButtons(); |
| - } |
| - |
| - // Build a row of control buttons. |
| - function addControlButtons() { |
| - var buttons = [ |
| - ['#back', function() { api.doAction(api.Action.HISTORY_BACK); }], |
| - ['#reload', function() { api.doAction(api.Action.RELOAD); }], |
| - ['#forward', function() { api.doAction(api.Action.HISTORY_FORWARD); }], |
| - ]; |
| - |
| - var buttonSpacing = 0.3; |
| - var buttonStartPosition = -buttonSpacing * (buttons.length / 2.0 - 0.5); |
| - |
| - for (var i = 0; i < buttons.length; i++) { |
| - // Use an invisible parent to simplify Z-axis movement on hover. |
| - var position = new api.UiElement(0, 0, 0, 0); |
| - position.setParentId(api.getContentElementId()); |
| - position.setVisible(false); |
| - position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); |
| - position.setTranslation( |
| - buttonStartPosition + i * buttonSpacing, -0.3, 0.3); |
| - var id = scene.addElement(position); |
| - |
| - var domId = buttons[i][0]; |
| - var callback = buttons[i][1]; |
| - var element = new RoundButton(domId, callback); |
| - uiElements.push(element); |
| - |
| - var update = new api.UiElementUpdate(); |
| - update.setParentId(id); |
| - update.setScale(2.2, 2.2, 1); |
| - scene.updateElement(element.uiElementId, update); |
| - } |
| + state = new UiState(); |
| - scene.flush(); |
| - } |
| - |
| - function domLoaded() { |
| api.domLoaded(); |
| } |
| function command(dict) { |
| + if ('mode' in dict) { |
| + state.setMode(dict['mode']); |
| + } |
| } |
| return { |