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

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: 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 constructor(contentQuadId) { 392 constructor(contentQuadId) {
393 this.enabled = false; 393 this.enabled = false;
394 394
395 this.buttons = { 395 this.buttons = {
396 backButton: null, 396 backButton: null,
397 reloadButton: null, 397 reloadButton: null,
398 forwardButton: null 398 forwardButton: null
399 }; 399 };
400 let descriptors = [ 400 let descriptors = [
401 [ 401 [
402 'backButton', '#back-button', 402 0, 'backButton', '#back-button',
403 function() { 403 function() {
404 api.doAction(api.Action.HISTORY_BACK, {}); 404 api.doAction(api.Action.HISTORY_BACK, {});
405 } 405 }
406 ], 406 ],
407 [ 407 [
408 'reloadButton', '#reload-button', 408 1, 'reloadButton', '#reload-button',
409 function() { 409 function() {
410 api.doAction(api.Action.RELOAD, {}); 410 api.doAction(api.Action.RELOAD, {});
411 } 411 }
412 ], 412 ],
413 [ 413 [
414 'forwardButton', '#forward-button', 414 2, 'forwardButton', '#forward-button',
415 function() { 415 function() {
416 api.doAction(api.Action.HISTORY_FORWARD, {}); 416 api.doAction(api.Action.HISTORY_FORWARD, {});
417 } 417 }
418 ], 418 ],
419 [
420 0, 'exitPresentButton', '#exit-present-button',
cjgrant 2017/03/30 15:35:28 I'm mulling why we don't just use one button, and
tiborg 2017/03/30 20:53:29 As discussed offline, let's keep separate buttons
421 function() {
422 api.doAction(api.Action.EXIT_PRESENT, {});
423 }
424 ],
419 ]; 425 ];
420 426
421 /** @const */ var BUTTON_Y = -0.53; 427 /** @const */ var BUTTON_Y = -0.53;
422 /** @const */ var BUTTON_Z = -2; 428 /** @const */ var BUTTON_Z = -2;
423 /** @const */ var BUTTON_SPACING = 0.14; 429 /** @const */ var BUTTON_SPACING = 0.14;
424 430
425 let controls = new api.UiElement(0, 0, 0, 0); 431 let controls = new api.UiElement(0, 0, 0, 0);
426 controls.setName('Controls'); 432 controls.setName('Controls');
427 controls.setVisible(false); 433 controls.setVisible(false);
428 controls.setTranslation(0, BUTTON_Y, BUTTON_Z); 434 controls.setTranslation(0, BUTTON_Y, BUTTON_Z);
429 this.controlsId = ui.addElement(controls); 435 this.controlsId = ui.addElement(controls);
430 436
431 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 437 let slotCount = 0;
438 descriptors.forEach(function(descriptor) {
439 slotCount = Math.max(descriptor[0] + 1, slotCount);
440 });
441 let startPosition = -BUTTON_SPACING * (slotCount / 2.0 - 0.5);
432 442
433 for (let i = 0; i < descriptors.length; i++) { 443 for (let i = 0; i < descriptors.length; i++) {
434 let name = descriptors[i][0]; 444 let slot = descriptors[i][0];
435 let domId = descriptors[i][1]; 445 let name = descriptors[i][1];
436 let callback = descriptors[i][2]; 446 let domId = descriptors[i][2];
447 let callback = descriptors[i][3];
437 let button = new Button(domId, callback, this.controlsId); 448 let button = new Button(domId, callback, this.controlsId);
438 button.setTranslation(startPosition + i * BUTTON_SPACING, 0, 0); 449 button.setTranslation(startPosition + slot * BUTTON_SPACING, 0, 0);
439 this.buttons[name] = button; 450 this.buttons[name] = button;
440 } 451 }
441 } 452 }
442 453
443 setEnabled(enabled) { 454 setEnabled(enabled) {
444 this.enabled = enabled; 455 this.enabled = enabled;
445 this.configure(); 456 this.configure();
446 } 457 }
447 458
448 configure() { 459 configure() {
449 for (let key in this.buttons) { 460 for (let key in this.buttons) {
450 this.buttons[key].setVisible(this.enabled); 461 this.buttons[key].setVisible(this.enabled);
451 } 462 }
463 if (this.enabled) {
464 this.buttons['exitPresentButton'].setVisible(
465 this.showExitPresentButton);
466 this.buttons['backButton'].setVisible(!this.showExitPresentButton);
467 }
452 } 468 }
453 469
454 setBackButtonEnabled(enabled) { 470 setBackButtonEnabled(enabled) {
455 this.buttons.backButton.setEnabled(enabled); 471 this.buttons.backButton.setEnabled(enabled);
456 } 472 }
457 473
458 setForwardButtonEnabled(enabled) { 474 setForwardButtonEnabled(enabled) {
459 this.buttons.forwardButton.setEnabled(enabled); 475 this.buttons.forwardButton.setEnabled(enabled);
460 } 476 }
477
478 /** If true shows the exit present button instead of the back button. */
cjgrant 2017/03/30 15:35:28 - "true" isn't the parameter name. - set and show
tiborg 2017/03/30 20:53:29 Done.
479 setShowExitPresentButton(showExitPresentButton) {
480 this.showExitPresentButton = showExitPresentButton;
481 this.configure();
482 }
461 }; 483 };
462 484
463 /** 485 /**
464 * A button to trigger a reload of the HTML UI for development purposes. 486 * A button to trigger a reload of the HTML UI for development purposes.
465 */ 487 */
466 class ReloadUiButton { 488 class ReloadUiButton {
467 constructor() { 489 constructor() {
468 this.enabled = false; 490 this.enabled = false;
469 this.devMode = false; 491 this.devMode = false;
470 492
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 1225
1204 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); 1226 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode});
1205 ui.setWebVrRenderingModeEnabled(mode == api.Mode.WEB_VR && !menuMode); 1227 ui.setWebVrRenderingModeEnabled(mode == api.Mode.WEB_VR && !menuMode);
1206 1228
1207 this.contentQuad.setEnabled(mode == api.Mode.STANDARD || menuMode); 1229 this.contentQuad.setEnabled(mode == api.Mode.STANDARD || menuMode);
1208 this.contentQuad.setFullscreen(fullscreen); 1230 this.contentQuad.setFullscreen(fullscreen);
1209 this.contentQuad.setMenuMode(menuMode); 1231 this.contentQuad.setMenuMode(menuMode);
1210 // TODO(crbug/643815): Set aspect ratio on content quad when available. 1232 // TODO(crbug/643815): Set aspect ratio on content quad when available.
1211 this.controls.setEnabled(menuMode); 1233 this.controls.setEnabled(menuMode);
1212 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen); 1234 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen);
1235 // TODO(crbug/689139): Don't show exit present button if the page
1236 // autopresented.
1237 this.controls.setShowExitPresentButton(mode == api.Mode.WEB_VR);
cjgrant 2017/03/30 15:35:28 Another thing we need to resolve with the UXEs is
tiborg 2017/03/30 20:53:29 Acknowledged. Let's discuss offline.
1213 let enabledIndicators = {} 1238 let enabledIndicators = {}
1214 enabledIndicators[api.Direction.LEFT] = this.canGoBack || this.fullscreen; 1239 enabledIndicators[api.Direction.LEFT] = this.canGoBack || this.fullscreen;
1215 this.gestureHandlers.setEnabled(enabledIndicators); 1240 this.gestureHandlers.setEnabled(enabledIndicators);
1216 this.omnibox.setEnabled(menuMode); 1241 this.omnibox.setEnabled(menuMode);
1217 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); 1242 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode);
1218 this.urlIndicator.setVisibilityTimeout( 1243 this.urlIndicator.setVisibilityTimeout(
1219 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); 1244 URL_INDICATOR_VISIBILITY_TIMEOUT_MS);
1220 this.secureOriginWarnings.setEnabled( 1245 this.secureOriginWarnings.setEnabled(
1221 mode == api.Mode.WEB_VR && !menuMode); 1246 mode == api.Mode.WEB_VR && !menuMode);
1222 this.background.setState(mode, menuMode, fullscreen); 1247 this.background.setState(mode, menuMode, fullscreen);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 nativeCommandHandler.handleCommand(dict); 1370 nativeCommandHandler.handleCommand(dict);
1346 } 1371 }
1347 1372
1348 return { 1373 return {
1349 initialize: initialize, 1374 initialize: initialize,
1350 command: command, 1375 command: command,
1351 }; 1376 };
1352 })(); 1377 })();
1353 1378
1354 window.addEventListener('load', vrShellUi.initialize); 1379 window.addEventListener('load', vrShellUi.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698