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

Side by Side Diff: chrome/browser/resources/vr_shell/vr_shell_ui.js

Issue 2773903003: Add way to get native VR UI information from Java (Closed)
Patch Set: Cleanup Created 3 years, 9 months 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 unified diff | Download patch
OLDNEW
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 var vrShellUi = (function() { 5 var vrShellUi = (function() {
6 'use strict'; 6 'use strict';
7 7
8 let ui = new scene.Scene(); 8 let ui = new scene.Scene();
9 let uiManager; 9 let uiManager;
10 let nativeCommandHandler; 10 let nativeCommandHandler;
11 11
12 let uiRootElement = document.querySelector('#ui'); 12 let uiRootElement = document.querySelector('#ui');
13 let uiStyle = window.getComputedStyle(uiRootElement); 13 let uiStyle = window.getComputedStyle(uiRootElement);
14 /** @const */ var ANIM_DURATION = 150; 14 /** @const */ var ANIM_DURATION = 150;
15 15
16 // This value should match the one in VrShellImpl.java 16 // This value should match the one in VrShellImpl.java
17 /** @const */ var UI_DPR = 1.2; 17 /** @const */ var UI_DPR = 1.2;
18 18
19 var domIdToUiElementIdMap = {};
20
19 function getStyleFloat(style, property, defaultValue) { 21 function getStyleFloat(style, property, defaultValue) {
20 let value = parseFloat(style.getPropertyValue(property)); 22 let value = parseFloat(style.getPropertyValue(property));
21 return isNaN(value) ? defaultValue : value; 23 return isNaN(value) ? defaultValue : value;
22 } 24 }
23 25
24 function getStyleString(style, property) { 26 function getStyleString(style, property) {
25 let str = style.getPropertyValue(property); 27 let str = style.getPropertyValue(property);
26 return !str || 0 === str.length ? '' : str; 28 return !str || 0 === str.length ? '' : str;
27 } 29 }
28 30
29 // Generate a two-color progress bar style background using a gradient. 31 // Generate a two-color progress bar style background using a gradient.
30 function makeProgressBackground(loading, percentage, color, background) { 32 function makeProgressBackground(loading, percentage, color, background) {
31 if (!loading) { 33 if (!loading) {
32 return background; 34 return background;
33 } 35 }
34 return 'linear-gradient(to right, ' + color + ' 0%, ' + color + ' ' + 36 return 'linear-gradient(to right, ' + color + ' 0%, ' + color + ' ' +
35 percentage * 100.0 + '%, ' + background + ' ' + percentage * 100 + 37 percentage * 100.0 + '%, ' + background + ' ' + percentage * 100 +
36 '%, ' + background + ' 100%)'; 38 '%, ' + background + ' 100%)';
37 } 39 }
38 40
41 function getUiElementId(domId) {
42 return domId in domIdToUiElementIdMap ? domIdToUiElementIdMap[domId] : -1;
43 }
44
39 class ContentQuad { 45 class ContentQuad {
40 constructor() { 46 constructor() {
41 /** @const */ this.SCREEN_HEIGHT = 1.375; 47 /** @const */ this.SCREEN_HEIGHT = 1.375;
42 /** @const */ this.SCREEN_RATIO = 9.6 / 6.4; 48 /** @const */ this.SCREEN_RATIO = 9.6 / 6.4;
43 /** @const */ this.BROWSING_SCREEN_ELEVATION = -0.15; 49 /** @const */ this.BROWSING_SCREEN_ELEVATION = -0.15;
44 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; 50 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0;
45 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; 51 /** @const */ this.FULLSCREEN_DISTANCE = 3.0;
46 /** @const */ this.CSS_WIDTH_PIXELS = 960.0; 52 /** @const */ this.CSS_WIDTH_PIXELS = 960.0;
47 /** @const */ this.CSS_HEIGHT_PIXELS = 640.0; 53 /** @const */ this.CSS_HEIGHT_PIXELS = 640.0;
48 /** @const */ this.DPR = 1.2; 54 /** @const */ this.DPR = 1.2;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 this.rotationX = getStyleFloat(style, '--rotX', 0); 205 this.rotationX = getStyleFloat(style, '--rotX', 0);
200 this.rotationY = getStyleFloat(style, '--rotY', 0); 206 this.rotationY = getStyleFloat(style, '--rotY', 0);
201 this.rotationZ = getStyleFloat(style, '--rotZ', 0); 207 this.rotationZ = getStyleFloat(style, '--rotZ', 0);
202 if (this.rotationX != 0 || this.rotationY != 0 || this.rotationZ != 0) { 208 if (this.rotationX != 0 || this.rotationY != 0 || this.rotationZ != 0) {
203 element.setRotation( 209 element.setRotation(
204 this.rotationX, this.rotationY, this.rotationZ, 2 * Math.PI); 210 this.rotationX, this.rotationY, this.rotationZ, 2 * Math.PI);
205 } 211 }
206 212
207 this.id = ui.addElement(element); 213 this.id = ui.addElement(element);
208 this.domElement = domElement; 214 this.domElement = domElement;
215 domIdToUiElementIdMap[domId] = this.id;
tiborg 2017/03/27 15:14:33 cjgrant@: is this a good workaround until the name
cjgrant 2017/03/27 15:41:32 Brian said he'd wait on using element names, as th
bsheedy 2017/03/27 17:49:09 Do we really need a map since we're removing all t
cjgrant 2017/03/27 19:49:43 That works if test will only ever check native sta
tiborg 2017/03/27 19:59:59 +1 to add the map once we need it.
209 } 216 }
210 }; 217 };
211 218
212 class Button { 219 class Button {
213 constructor(domId, callback, parentId) { 220 constructor(domId, callback, parentId) {
214 let captionId = domId + '-caption'; 221 let captionId = domId + '-caption';
215 this.button = document.querySelector(domId); 222 this.button = document.querySelector(domId);
216 this.caption = document.querySelector(captionId); 223 this.caption = document.querySelector(captionId);
217 this.callback = callback; 224 this.callback = callback;
218 this.enabled = true; 225 this.enabled = true;
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 } 1339 }
1333 } 1340 }
1334 1341
1335 function command(dict) { 1342 function command(dict) {
1336 nativeCommandHandler.handleCommand(dict); 1343 nativeCommandHandler.handleCommand(dict);
1337 } 1344 }
1338 1345
1339 return { 1346 return {
1340 initialize: initialize, 1347 initialize: initialize,
1341 command: command, 1348 command: command,
1349 getUiElementId: getUiElementId,
1342 }; 1350 };
1343 })(); 1351 })();
1344 1352
1345 window.addEventListener('load', vrShellUi.initialize); 1353 window.addEventListener('load', vrShellUi.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698