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

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

Issue 2784303002: Adds button to VRShell menu mode, which lets the user manually exit WebVR presentation. (Closed)
Patch Set: Fixed closure compiler error Created 3 years, 8 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;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 ui.addAnimation(anim); 384 ui.addAnimation(anim);
385 anim = new api.Animation(this.element.id, this.ANIM_DURATION * 2); 385 anim = new api.Animation(this.element.id, this.ANIM_DURATION * 2);
386 anim.setScale(1, 1, 1); 386 anim.setScale(1, 1, 1);
387 ui.addAnimation(anim); 387 ui.addAnimation(anim);
388 } 388 }
389 } 389 }
390 390
391 class Controls { 391 class Controls {
392 constructor(contentQuadId) { 392 constructor(contentQuadId) {
393 this.enabled = false; 393 this.enabled = false;
394 this.exitPresentButtonVisible = false;
394 395
395 this.buttons = { 396 this.buttons = {
396 backButton: null, 397 backButton: null,
397 reloadButton: null, 398 reloadButton: null,
398 forwardButton: null 399 forwardButton: null
399 }; 400 };
400 let descriptors = [ 401 let descriptors = [
401 [ 402 [
402 'backButton', '#back-button', 403 0, 'backButton', '#back-button',
403 function() { 404 function() {
404 api.doAction(api.Action.HISTORY_BACK, {}); 405 api.doAction(api.Action.HISTORY_BACK, {});
405 } 406 }
406 ], 407 ],
407 [ 408 [
408 'reloadButton', '#reload-button', 409 1, 'reloadButton', '#reload-button',
409 function() { 410 function() {
410 api.doAction(api.Action.RELOAD, {}); 411 api.doAction(api.Action.RELOAD, {});
411 } 412 }
412 ], 413 ],
413 [ 414 [
414 'forwardButton', '#forward-button', 415 2, 'forwardButton', '#forward-button',
415 function() { 416 function() {
416 api.doAction(api.Action.HISTORY_FORWARD, {}); 417 api.doAction(api.Action.HISTORY_FORWARD, {});
417 } 418 }
418 ], 419 ],
420 [
421 0, 'exitPresentButton', '#exit-present-button',
422 function() {
423 api.doAction(api.Action.EXIT_PRESENT, {});
424 }
425 ],
419 ]; 426 ];
420 427
421 /** @const */ var BUTTON_Y = -0.53; 428 /** @const */ var BUTTON_Y = -0.53;
422 /** @const */ var BUTTON_Z = -2; 429 /** @const */ var BUTTON_Z = -2;
423 /** @const */ var BUTTON_SPACING = 0.14; 430 /** @const */ var BUTTON_SPACING = 0.14;
424 431
425 let controls = new api.UiElement(0, 0, 0, 0); 432 let controls = new api.UiElement(0, 0, 0, 0);
426 controls.setName('Controls'); 433 controls.setName('Controls');
427 controls.setVisible(false); 434 controls.setVisible(false);
428 controls.setTranslation(0, BUTTON_Y, BUTTON_Z); 435 controls.setTranslation(0, BUTTON_Y, BUTTON_Z);
429 this.controlsId = ui.addElement(controls); 436 this.controlsId = ui.addElement(controls);
430 437
431 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 438 let slotCount = 0;
439 descriptors.forEach(function(descriptor) {
440 slotCount = Math.max(descriptor[0] + 1, slotCount);
441 });
442 let startPosition = -BUTTON_SPACING * (slotCount / 2.0 - 0.5);
432 443
433 for (let i = 0; i < descriptors.length; i++) { 444 for (let i = 0; i < descriptors.length; i++) {
434 let name = descriptors[i][0]; 445 let slot = descriptors[i][0];
435 let domId = descriptors[i][1]; 446 let name = descriptors[i][1];
436 let callback = descriptors[i][2]; 447 let domId = descriptors[i][2];
448 let callback = descriptors[i][3];
437 let button = new Button(domId, callback, this.controlsId); 449 let button = new Button(domId, callback, this.controlsId);
438 button.setTranslation(startPosition + i * BUTTON_SPACING, 0, 0); 450 button.setTranslation(startPosition + slot * BUTTON_SPACING, 0, 0);
439 this.buttons[name] = button; 451 this.buttons[name] = button;
440 } 452 }
441 } 453 }
442 454
443 setEnabled(enabled) { 455 setEnabled(enabled) {
444 this.enabled = enabled; 456 this.enabled = enabled;
445 this.configure(); 457 this.configure();
446 } 458 }
447 459
448 configure() { 460 configure() {
449 for (let key in this.buttons) { 461 for (let key in this.buttons) {
450 this.buttons[key].setVisible(this.enabled); 462 this.buttons[key].setVisible(this.enabled);
451 } 463 }
464 if (this.enabled) {
465 this.buttons['exitPresentButton'].setVisible(
466 this.exitPresentButtonVisible);
467 this.buttons['backButton'].setVisible(!this.exitPresentButtonVisible);
468 }
452 } 469 }
453 470
454 setBackButtonEnabled(enabled) { 471 setBackButtonEnabled(enabled) {
455 this.buttons.backButton.setEnabled(enabled); 472 this.buttons.backButton.setEnabled(enabled);
456 } 473 }
457 474
458 setForwardButtonEnabled(enabled) { 475 setForwardButtonEnabled(enabled) {
459 this.buttons.forwardButton.setEnabled(enabled); 476 this.buttons.forwardButton.setEnabled(enabled);
460 } 477 }
478
479 /** If true shows the exit present button instead of the back button. */
480 setExitPresentButtonVisible(visible) {
481 this.exitPresentButtonVisible = visible;
482 this.configure();
483 }
461 }; 484 };
462 485
463 /** 486 /**
464 * A button to trigger a reload of the HTML UI for development purposes. 487 * A button to trigger a reload of the HTML UI for development purposes.
465 */ 488 */
466 class ReloadUiButton { 489 class ReloadUiButton {
467 constructor() { 490 constructor() {
468 this.enabled = false; 491 this.enabled = false;
469 this.devMode = false; 492 this.devMode = false;
470 493
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 1226
1204 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); 1227 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode});
1205 ui.setWebVrRenderingModeEnabled(mode == api.Mode.WEB_VR && !menuMode); 1228 ui.setWebVrRenderingModeEnabled(mode == api.Mode.WEB_VR && !menuMode);
1206 1229
1207 this.contentQuad.setEnabled(mode == api.Mode.STANDARD || menuMode); 1230 this.contentQuad.setEnabled(mode == api.Mode.STANDARD || menuMode);
1208 this.contentQuad.setFullscreen(fullscreen); 1231 this.contentQuad.setFullscreen(fullscreen);
1209 this.contentQuad.setMenuMode(menuMode); 1232 this.contentQuad.setMenuMode(menuMode);
1210 // TODO(crbug/643815): Set aspect ratio on content quad when available. 1233 // TODO(crbug/643815): Set aspect ratio on content quad when available.
1211 this.controls.setEnabled(menuMode); 1234 this.controls.setEnabled(menuMode);
1212 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen); 1235 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen);
1236 // TODO(crbug/689139): Don't show exit present button if the page
1237 // autopresented.
1238 this.controls.setExitPresentButtonVisible(mode == api.Mode.WEB_VR);
1213 let enabledIndicators = {} 1239 let enabledIndicators = {}
1214 enabledIndicators[api.Direction.LEFT] = this.canGoBack || this.fullscreen; 1240 enabledIndicators[api.Direction.LEFT] = this.canGoBack || this.fullscreen;
1215 this.gestureHandlers.setEnabled(enabledIndicators); 1241 this.gestureHandlers.setEnabled(enabledIndicators);
1216 this.omnibox.setEnabled(menuMode); 1242 this.omnibox.setEnabled(menuMode);
1217 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); 1243 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode);
1218 this.urlIndicator.setVisibilityTimeout( 1244 this.urlIndicator.setVisibilityTimeout(
1219 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); 1245 URL_INDICATOR_VISIBILITY_TIMEOUT_MS);
1220 this.secureOriginWarnings.setEnabled( 1246 this.secureOriginWarnings.setEnabled(
1221 mode == api.Mode.WEB_VR && !menuMode); 1247 mode == api.Mode.WEB_VR && !menuMode);
1222 this.background.setState(mode, menuMode, fullscreen); 1248 this.background.setState(mode, menuMode, fullscreen);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 nativeCommandHandler.handleCommand(dict); 1371 nativeCommandHandler.handleCommand(dict);
1346 } 1372 }
1347 1373
1348 return { 1374 return {
1349 initialize: initialize, 1375 initialize: initialize,
1350 command: command, 1376 command: command,
1351 }; 1377 };
1352 })(); 1378 })();
1353 1379
1354 window.addEventListener('load', vrShellUi.initialize); 1380 window.addEventListener('load', vrShellUi.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.html ('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