Chromium Code Reviews| 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 cr.define('chrome.vrShellUi', function() { | 5 cr.define('chrome.vrShellUi', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 var scene = new ui.Scene(); | 8 var scene = new ui.Scene(); |
| 9 var uiElements = []; | 9 var state; |
| 10 | 10 |
| 11 class DomUiElement { | 11 class DomUiElement { |
| 12 constructor(domId) { | 12 constructor(domId) { |
| 13 var domElement = document.querySelector(domId); | 13 var domElement = document.querySelector(domId); |
| 14 var style = window.getComputedStyle(domElement); | 14 var style = window.getComputedStyle(domElement); |
| 15 | 15 |
| 16 // Pull copy rectangle from DOM element properties. | 16 // Pull copy rectangle from DOM element properties. |
| 17 var pixelX = domElement.offsetLeft; | 17 var pixelX = domElement.offsetLeft; |
| 18 var pixelY = domElement.offsetTop; | 18 var pixelY = domElement.offsetTop; |
| 19 var pixelWidth = parseInt(style.getPropertyValue('width')); | 19 var pixelWidth = parseInt(style.getPropertyValue('width')); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 54 |
| 55 onMouseEnter() { | 55 onMouseEnter() { |
| 56 this.configure(1, 1, 0.015); | 56 this.configure(1, 1, 0.015); |
| 57 } | 57 } |
| 58 | 58 |
| 59 onMouseLeave() { | 59 onMouseLeave() { |
| 60 this.configure(0.8, 0, 0); | 60 this.configure(0.8, 0, 0); |
| 61 } | 61 } |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class UiState { | |
| 65 constructor() { | |
| 66 this.mode = -1; | |
| 67 this.createMenuButtons(); | |
| 68 scene.flush(); | |
| 69 } | |
| 70 | |
| 71 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.
| |
| 72 this.menuButtons = []; | |
| 73 var buttons = [ | |
| 74 ['#back', function() { | |
| 75 api.doAction(api.Action.HISTORY_BACK); | |
| 76 }], | |
| 77 ['#reload', function() { | |
| 78 api.doAction(api.Action.RELOAD); | |
| 79 }], | |
| 80 ['#forward', function() { | |
| 81 api.doAction(api.Action.HISTORY_FORWARD); | |
| 82 }], | |
| 83 ]; | |
| 84 | |
| 85 var buttonSpacing = 0.3; | |
| 86 var buttonStartPosition = -buttonSpacing * (buttons.length / 2.0 - 0.5); | |
| 87 | |
| 88 for (var i = 0; i < buttons.length; i++) { | |
| 89 // Use an invisible parent to simplify Z-axis movement on hover. | |
| 90 var position = new api.UiElement(0, 0, 0, 0); | |
| 91 position.setParentId(api.getContentElementId()); | |
| 92 position.setVisible(false); | |
| 93 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); | |
| 94 position.setTranslation( | |
| 95 buttonStartPosition + i * buttonSpacing, -0.3, 0.3); | |
| 96 var id = scene.addElement(position); | |
| 97 | |
| 98 var domId = buttons[i][0]; | |
| 99 var callback = buttons[i][1]; | |
| 100 var element = new RoundButton(domId, callback); | |
| 101 this.menuButtons.push(element); | |
| 102 | |
| 103 var update = new api.UiElementUpdate(); | |
| 104 update.setParentId(id); | |
| 105 update.setVisible(false); | |
| 106 update.setScale(2.2, 2.2, 1); | |
| 107 scene.updateElement(element.uiElementId, update); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 showMenuButtons(visible) { | |
| 112 for (var i = 0; i < this.menuButtons.length; i++) { | |
| 113 var update = new api.UiElementUpdate(); | |
| 114 update.setVisible(visible); | |
| 115 scene.updateElement(this.menuButtons[i].uiElementId, update); | |
| 116 } | |
| 117 scene.flush(); | |
| 118 } | |
| 119 | |
| 120 setMode(mode) { | |
| 121 this.showMenuButtons(mode == api.Mode.STANDARD); | |
| 122 } | |
| 123 }; | |
| 124 | |
| 64 function initialize() { | 125 function initialize() { |
| 65 | 126 |
| 66 domLoaded(); | |
| 67 | |
| 68 // Change the body background so that the transparency applies. | 127 // Change the body background so that the transparency applies. |
| 69 window.setTimeout(function() { | 128 window.setTimeout(function() { |
| 70 document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)'; | 129 document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)'; |
| 71 }, 100); | 130 }, 100); |
| 72 | 131 |
| 73 addControlButtons(); | 132 state = new UiState(); |
| 74 } | |
| 75 | 133 |
| 76 // Build a row of control buttons. | |
| 77 function addControlButtons() { | |
| 78 var buttons = [ | |
| 79 ['#back', function() { api.doAction(api.Action.HISTORY_BACK); }], | |
| 80 ['#reload', function() { api.doAction(api.Action.RELOAD); }], | |
| 81 ['#forward', function() { api.doAction(api.Action.HISTORY_FORWARD); }], | |
| 82 ]; | |
| 83 | |
| 84 var buttonSpacing = 0.3; | |
| 85 var buttonStartPosition = -buttonSpacing * (buttons.length / 2.0 - 0.5); | |
| 86 | |
| 87 for (var i = 0; i < buttons.length; i++) { | |
| 88 // Use an invisible parent to simplify Z-axis movement on hover. | |
| 89 var position = new api.UiElement(0, 0, 0, 0); | |
| 90 position.setParentId(api.getContentElementId()); | |
| 91 position.setVisible(false); | |
| 92 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); | |
| 93 position.setTranslation( | |
| 94 buttonStartPosition + i * buttonSpacing, -0.3, 0.3); | |
| 95 var id = scene.addElement(position); | |
| 96 | |
| 97 var domId = buttons[i][0]; | |
| 98 var callback = buttons[i][1]; | |
| 99 var element = new RoundButton(domId, callback); | |
| 100 uiElements.push(element); | |
| 101 | |
| 102 var update = new api.UiElementUpdate(); | |
| 103 update.setParentId(id); | |
| 104 update.setScale(2.2, 2.2, 1); | |
| 105 scene.updateElement(element.uiElementId, update); | |
| 106 } | |
| 107 | |
| 108 scene.flush(); | |
| 109 } | |
| 110 | |
| 111 function domLoaded() { | |
| 112 api.domLoaded(); | 134 api.domLoaded(); |
| 113 } | 135 } |
| 114 | 136 |
| 115 function command(dict) { | 137 function command(dict) { |
| 138 if ('mode' in dict) { | |
| 139 state.setMode(dict['mode']); | |
| 140 } | |
| 116 } | 141 } |
| 117 | 142 |
| 118 return { | 143 return { |
| 119 initialize: initialize, | 144 initialize: initialize, |
| 120 command: command, | 145 command: command, |
| 121 }; | 146 }; |
| 122 }); | 147 }); |
| 123 | 148 |
| 124 document.addEventListener('DOMContentLoaded', chrome.vrShellUi.initialize); | 149 document.addEventListener('DOMContentLoaded', chrome.vrShellUi.initialize); |
| OLD | NEW |