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

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

Issue 2592143002: First cut of JS closure compiler use for VR HTML UI. (Closed)
Patch Set: Run clang-format so that dbeam@ doesn't have to fix our files; remove the third-party change to exp… Created 3 years, 11 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 scene = new ui.Scene(); 8 let scene = new ui.Scene();
9 let sceneManager; 9 let sceneManager;
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 let pixelY = Math.floor(rect.top); 70 let pixelY = Math.floor(rect.top);
71 let pixelWidth = Math.ceil(rect.right) - pixelX; 71 let pixelWidth = Math.ceil(rect.right) - pixelX;
72 let pixelHeight = Math.ceil(rect.bottom) - pixelY; 72 let pixelHeight = Math.ceil(rect.bottom) - pixelY;
73 73
74 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); 74 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight);
75 element.setSize(pixelWidth / 1000, pixelHeight / 1000); 75 element.setSize(pixelWidth / 1000, pixelHeight / 1000);
76 76
77 // Pull additional custom properties from CSS. 77 // Pull additional custom properties from CSS.
78 let style = window.getComputedStyle(domElement); 78 let style = window.getComputedStyle(domElement);
79 element.setTranslation( 79 element.setTranslation(
80 getStyleFloat(style, '--tranX'), 80 getStyleFloat(style, '--tranX'), getStyleFloat(style, '--tranY'),
81 getStyleFloat(style, '--tranY'),
82 getStyleFloat(style, '--tranZ')); 81 getStyleFloat(style, '--tranZ'));
83 82
84 this.uiElementId = scene.addElement(element); 83 this.uiElementId = scene.addElement(element);
85 this.uiAnimationId = -1; 84 this.uiAnimationId = -1;
86 this.domElement = domElement; 85 this.domElement = domElement;
87 } 86 }
88 }; 87 };
89 88
90 class RoundButton extends DomUiElement { 89 class RoundButton extends DomUiElement {
91 constructor(domId, callback) { 90 constructor(domId, callback) {
(...skipping 23 matching lines...) Expand all
115 this.configure(1, 1, 0.015); 114 this.configure(1, 1, 0.015);
116 } 115 }
117 116
118 onMouseLeave() { 117 onMouseLeave() {
119 this.configure(0.8, 0, 0); 118 this.configure(0.8, 0, 0);
120 } 119 }
121 }; 120 };
122 121
123 class Controls { 122 class Controls {
124 constructor(contentQuadId) { 123 constructor(contentQuadId) {
124 this.enabled = false;
125 this.reloadUiEnabled = false;
126
125 this.buttons = []; 127 this.buttons = [];
126 let descriptors = [ 128 let descriptors = [
127 ['#back', function() { 129 [
130 '#back',
131 function() {
128 api.doAction(api.Action.HISTORY_BACK); 132 api.doAction(api.Action.HISTORY_BACK);
129 }], 133 }
130 ['#reload', function() { 134 ],
135 [
136 '#reload',
137 function() {
131 api.doAction(api.Action.RELOAD); 138 api.doAction(api.Action.RELOAD);
132 }], 139 }
133 ['#forward', function() { 140 ],
141 [
142 '#forward',
143 function() {
134 api.doAction(api.Action.HISTORY_FORWARD); 144 api.doAction(api.Action.HISTORY_FORWARD);
135 }], 145 }
146 ],
136 ]; 147 ];
137 148
138 /** @const */ var BUTTON_SPACING = 0.136; 149 /** @const */ var BUTTON_SPACING = 0.136;
139 150
140 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 151 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5);
141 for (let i = 0; i < descriptors.length; i++) { 152 for (let i = 0; i < descriptors.length; i++) {
142 // Use an invisible parent to simplify Z-axis movement on hover. 153 // Use an invisible parent to simplify Z-axis movement on hover.
143 let position = new api.UiElement(0, 0, 0, 0); 154 let position = new api.UiElement(0, 0, 0, 0);
144 position.setVisible(false); 155 position.setVisible(false);
145 position.setTranslation(startPosition + i * BUTTON_SPACING, -0.68, -1); 156 position.setTranslation(startPosition + i * BUTTON_SPACING, -0.68, -1);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 update.setVisible(this.enabled && this.reloadUiEnabled); 202 update.setVisible(this.enabled && this.reloadUiEnabled);
192 scene.updateElement(this.reloadUiButton.uiElementId, update); 203 scene.updateElement(this.reloadUiButton.uiElementId, update);
193 } 204 }
194 }; 205 };
195 206
196 class SecureOriginWarnings { 207 class SecureOriginWarnings {
197 constructor() { 208 constructor() {
198 /** @const */ var DISTANCE = 0.7; 209 /** @const */ var DISTANCE = 0.7;
199 /** @const */ var ANGLE_UP = 16.3 * Math.PI / 180.0; 210 /** @const */ var ANGLE_UP = 16.3 * Math.PI / 180.0;
200 211
212 this.enabled = false;
213 this.secure = false;
214 this.secureOriginTimer = null;
215
201 // Permanent WebVR security warning. This warning is shown near the top of 216 // Permanent WebVR security warning. This warning is shown near the top of
202 // the field of view. 217 // the field of view.
203 this.webVrSecureWarning = new DomUiElement('#webvr-not-secure-permanent'); 218 this.webVrSecureWarning = new DomUiElement('#webvr-not-secure-permanent');
204 let update = new api.UiElementUpdate(); 219 let update = new api.UiElementUpdate();
205 update.setScale(DISTANCE, DISTANCE, 1); 220 update.setScale(DISTANCE, DISTANCE, 1);
206 update.setTranslation(0, DISTANCE * Math.sin(ANGLE_UP), 221 update.setTranslation(
207 -DISTANCE * Math.cos(ANGLE_UP)); 222 0, DISTANCE * Math.sin(ANGLE_UP), -DISTANCE * Math.cos(ANGLE_UP));
208 update.setRotation(1.0, 0.0, 0.0, ANGLE_UP); 223 update.setRotation(1.0, 0.0, 0.0, ANGLE_UP);
209 update.setHitTestable(false); 224 update.setHitTestable(false);
210 update.setVisible(false); 225 update.setVisible(false);
211 update.setLockToFieldOfView(true); 226 update.setLockToFieldOfView(true);
212 scene.updateElement(this.webVrSecureWarning.uiElementId, update); 227 scene.updateElement(this.webVrSecureWarning.uiElementId, update);
213 228
214 // Temporary WebVR security warning. This warning is shown in the center 229 // Temporary WebVR security warning. This warning is shown in the center
215 // of the field of view, for a limited period of time. 230 // of the field of view, for a limited period of time.
216 this.transientWarning = new DomUiElement( 231 this.transientWarning = new DomUiElement('#webvr-not-secure-transient');
217 '#webvr-not-secure-transient');
218 update = new api.UiElementUpdate(); 232 update = new api.UiElementUpdate();
219 update.setScale(DISTANCE, DISTANCE, 1); 233 update.setScale(DISTANCE, DISTANCE, 1);
220 update.setTranslation(0, 0, -DISTANCE); 234 update.setTranslation(0, 0, -DISTANCE);
221 update.setHitTestable(false); 235 update.setHitTestable(false);
222 update.setVisible(false); 236 update.setVisible(false);
223 update.setLockToFieldOfView(true); 237 update.setLockToFieldOfView(true);
224 scene.updateElement(this.transientWarning.uiElementId, update); 238 scene.updateElement(this.transientWarning.uiElementId, update);
225 } 239 }
226 240
227 setEnabled(enabled) { 241 setEnabled(enabled) {
228 this.enabled = enabled; 242 this.enabled = enabled;
229 this.updateState(); 243 this.updateState();
230 } 244 }
231 245
232 setSecure(secure) { 246 setSecure(secure) {
233 this.secure = secure; 247 this.secure = secure;
234 this.updateState(); 248 this.updateState();
235 } 249 }
236 250
237 updateState() { 251 updateState() {
238 /** @const */ var TRANSIENT_TIMEOUT_MS = 30000; 252 /** @const */ var TRANSIENT_TIMEOUT_MS = 30000;
239 253
240 let visible = (this.enabled && !this.secure); 254 let visible = (this.enabled && !this.secure);
241 if (this.secureOriginTimer) { 255 if (this.secureOriginTimer) {
242 clearInterval(this.secureOriginTimer); 256 clearInterval(this.secureOriginTimer);
243 this.secureOriginTimer = null; 257 this.secureOriginTimer = null;
244 } 258 }
245 if (visible) { 259 if (visible) {
246 this.secureOriginTimer = setTimeout( 260 this.secureOriginTimer =
247 this.onTransientTimer.bind(this), TRANSIENT_TIMEOUT_MS); 261 setTimeout(this.onTransientTimer.bind(this), TRANSIENT_TIMEOUT_MS);
248 } 262 }
249 this.showOrHideWarnings(visible); 263 this.showOrHideWarnings(visible);
250 } 264 }
251 265
252 showOrHideWarnings(visible) { 266 showOrHideWarnings(visible) {
253 let update = new api.UiElementUpdate(); 267 let update = new api.UiElementUpdate();
254 update.setVisible(visible); 268 update.setVisible(visible);
255 scene.updateElement(this.webVrSecureWarning.uiElementId, update); 269 scene.updateElement(this.webVrSecureWarning.uiElementId, update);
256 update = new api.UiElementUpdate(); 270 update = new api.UiElementUpdate();
257 update.setVisible(visible); 271 update.setVisible(visible);
258 scene.updateElement(this.transientWarning.uiElementId, update); 272 scene.updateElement(this.transientWarning.uiElementId, update);
259 } 273 }
260 274
261 onTransientTimer() { 275 onTransientTimer() {
262 let update = new api.UiElementUpdate(); 276 let update = new api.UiElementUpdate();
263 update.setVisible(false); 277 update.setVisible(false);
264 scene.updateElement(this.transientWarning.uiElementId, update); 278 scene.updateElement(this.transientWarning.uiElementId, update);
265 this.secureOriginTimer = null; 279 this.secureOriginTimer = null;
266 scene.flush(); 280 scene.flush();
267 } 281 }
268 }; 282 };
269 283
270 class Omnibox { 284 class Omnibox {
271 constructor(contentQuadId) { 285 constructor(contentQuadId) {
272 this.domUiElement = new DomUiElement('#omni-container'); 286 this.domUiElement = new DomUiElement('#omni-container');
273 this.enabled = false; 287 this.enabled = false;
288 this.loading = false;
274 this.level = 0; 289 this.level = 0;
275 this.visibilityTimeout = 0; 290 this.visibilityTimeout = 0;
276 this.visibilityTimer = null; 291 this.visibilityTimer = null;
292 this.visibleAfterTransition = false;
277 this.nativeState = {}; 293 this.nativeState = {};
278 294
279 // Initially invisible. 295 // Initially invisible.
280 let update = new api.UiElementUpdate(); 296 let update = new api.UiElementUpdate();
281 update.setVisible(false); 297 update.setVisible(false);
282 scene.updateElement(this.domUiElement.uiElementId, update); 298 scene.updateElement(this.domUiElement.uiElementId, update);
283 this.nativeState.visible = false; 299 this.nativeState.visible = false;
284 300
285 // Listen to the end of transitions, so that the box can be natively 301 // Listen to the end of transitions, so that the box can be natively
286 // hidden after it finishes hiding itself. 302 // hidden after it finishes hiding itself.
287 document.querySelector('#omni').addEventListener('transitionend', 303 document.querySelector('#omni').addEventListener(
288 this.onAnimationDone.bind(this)); 304 'transitionend', this.onAnimationDone.bind(this));
289 } 305 }
290 306
291 getSecurityIconElementId(level) { 307 getSecurityIconElementId(level) {
292 // See security_state.h and getSecurityIconResource() for this mapping. 308 // See security_state.h and getSecurityIconResource() for this mapping.
293 switch (level) { 309 switch (level) {
294 case 0: // NONE 310 case 0: // NONE
295 case 1: // HTTP_SHOW_WARNING 311 case 1: // HTTP_SHOW_WARNING
296 case 4: // SECURITY_WARNING 312 case 4: // SECURITY_WARNING
297 return '#omni-info-icon'; 313 return '#omni-info-icon';
298 case 2: // SECURE: 314 case 2: // SECURE:
299 case 3: // EV_SECURE: 315 case 3: // EV_SECURE:
300 return '#omni-lock-icon'; 316 return '#omni-lock-icon';
301 case 5: // SECURE_WITH_POLICY_INSTALLED_CERT (ChromeOS only) 317 case 5: // SECURE_WITH_POLICY_INSTALLED_CERT (ChromeOS only)
302 case 6: // DANGEROUS 318 case 6: // DANGEROUS
303 default: 319 default:
304 return '#omni-warning-icon'; 320 return '#omni-warning-icon';
305 } 321 }
306 } 322 }
307 323
308 setEnabled(enabled) { 324 setEnabled(enabled) {
309 this.enabled = enabled; 325 this.enabled = enabled;
310 this.resetVisibilityTimer(); 326 this.resetVisibilityTimer();
311 this.updateState(); 327 this.updateState();
312 } 328 }
(...skipping 24 matching lines...) Expand all
337 this.updateState(); 353 this.updateState();
338 } 354 }
339 355
340 resetVisibilityTimer() { 356 resetVisibilityTimer() {
341 if (this.visibilityTimer) { 357 if (this.visibilityTimer) {
342 clearInterval(this.visibilityTimer); 358 clearInterval(this.visibilityTimer);
343 this.visibilityTimer = null; 359 this.visibilityTimer = null;
344 } 360 }
345 if (this.enabled && this.visibilityTimeout > 0 && !this.loading) { 361 if (this.enabled && this.visibilityTimeout > 0 && !this.loading) {
346 this.visibilityTimer = setTimeout( 362 this.visibilityTimer = setTimeout(
347 this.onVisibilityTimer.bind(this), this.visibilityTimeout); 363 this.onVisibilityTimer.bind(this), this.visibilityTimeout);
348 } 364 }
349 } 365 }
350 366
351 onVisibilityTimer() { 367 onVisibilityTimer() {
352 this.visibilityTimer = null; 368 this.visibilityTimer = null;
353 this.updateState(); 369 this.updateState();
354 } 370 }
355 371
356 onAnimationDone(e) { 372 onAnimationDone(e) {
357 if (e.propertyName == 'opacity' && !this.visibleAfterTransition) { 373 if (e.propertyName == 'opacity' && !this.visibleAfterTransition) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 435
420 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); 436 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode);
421 this.contentQuad.setFullscreen(fullscreen); 437 this.contentQuad.setFullscreen(fullscreen);
422 // TODO(crbug/643815): Set aspect ratio on content quad when available. 438 // TODO(crbug/643815): Set aspect ratio on content quad when available.
423 // TODO(amp): Don't show controls in fullscreen once MENU mode lands. 439 // TODO(amp): Don't show controls in fullscreen once MENU mode lands.
424 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); 440 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode);
425 this.omnibox.setEnabled(mode == api.Mode.STANDARD && !menuMode); 441 this.omnibox.setEnabled(mode == api.Mode.STANDARD && !menuMode);
426 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. 442 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands.
427 this.omnibox.setVisibilityTimeout( 443 this.omnibox.setVisibilityTimeout(
428 mode == api.Mode.STANDARD && !menuMode ? 444 mode == api.Mode.STANDARD && !menuMode ?
429 0 : OMNIBOX_VISIBILITY_TIMEOUT_MS); 445 0 :
446 OMNIBOX_VISIBILITY_TIMEOUT_MS);
430 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); 447 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR);
431 448
432 api.setUiCssSize(uiRootElement.clientWidth, uiRootElement.clientHeight, 449 api.setUiCssSize(
433 UI_DPR); 450 uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR);
434 } 451 }
435 452
436 setSecurityLevel(level) { 453 setSecurityLevel(level) {
437 this.omnibox.setSecurityLevel(level); 454 this.omnibox.setSecurityLevel(level);
438 } 455 }
439 456
440 setWebVRSecureOrigin(secure) { 457 setWebVRSecureOrigin(secure) {
441 this.secureOriginWarnings.setSecure(secure); 458 this.secureOriginWarnings.setSecure(secure);
442 } 459 }
443 460
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 scene.flush(); 493 scene.flush();
477 } 494 }
478 495
479 return { 496 return {
480 initialize: initialize, 497 initialize: initialize,
481 command: command, 498 command: command,
482 }; 499 };
483 })(); 500 })();
484 501
485 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); 502 document.addEventListener('DOMContentLoaded', vrShellUi.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/vr_shell/compiled_resources2.gyp ('k') | chrome/browser/resources/vr_shell/vr_shell_ui_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698