| 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 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 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 class ContentQuad { | 28 class ContentQuad { |
| 29 constructor() { | 29 constructor() { |
| 30 /** @const */ this.SCREEN_HEIGHT = 1.6; | 30 /** @const */ this.SCREEN_HEIGHT = 1.6; |
| 31 /** @const */ this.SCREEN_RATIO = 16 / 9; | 31 /** @const */ this.SCREEN_RATIO = 16 / 9; |
| 32 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; | 32 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; |
| 33 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; | 33 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; |
| 34 | 34 |
| 35 let element = new api.UiElement(0, 0, 0, 0); | 35 let element = new api.UiElement(0, 0, 0, 0); |
| 36 element.setIsContentQuad(); | 36 element.setFill(new api.Content()); |
| 37 element.setVisible(false); | 37 element.setVisible(false); |
| 38 element.setSize( | 38 element.setSize( |
| 39 this.SCREEN_HEIGHT * this.SCREEN_RATIO, this.SCREEN_HEIGHT); | 39 this.SCREEN_HEIGHT * this.SCREEN_RATIO, this.SCREEN_HEIGHT); |
| 40 element.setTranslation(0, 0, -this.BROWSING_SCREEN_DISTANCE); | 40 element.setTranslation(0, 0, -this.BROWSING_SCREEN_DISTANCE); |
| 41 this.elementId = ui.addElement(element); | 41 this.elementId = ui.addElement(element); |
| 42 } | 42 } |
| 43 | 43 |
| 44 setEnabled(enabled) { | 44 setEnabled(enabled) { |
| 45 let update = new api.UiElementUpdate(); | 45 let update = new api.UiElementUpdate(); |
| 46 update.setVisible(enabled); | 46 update.setVisible(enabled); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 if (visible == this.nativeState.visible) { | 446 if (visible == this.nativeState.visible) { |
| 447 return; | 447 return; |
| 448 } | 448 } |
| 449 this.nativeState.visible = visible; | 449 this.nativeState.visible = visible; |
| 450 let update = new api.UiElementUpdate(); | 450 let update = new api.UiElementUpdate(); |
| 451 update.setVisible(visible); | 451 update.setVisible(visible); |
| 452 ui.updateElement(this.domUiElement.uiElementId, update); | 452 ui.updateElement(this.domUiElement.uiElementId, update); |
| 453 ui.flush(); | 453 ui.flush(); |
| 454 } | 454 } |
| 455 }; | 455 }; |
| 456 |
| 457 class Background { |
| 458 constructor() { |
| 459 /** @const */ var GRADIENT_LIGHER_GRAY = |
| 460 {r: 0.57, g: 0.57, b: 0.57, a:1.0}; |
| 461 /** @const */ var GRADIENT_DARKER_GRAY = |
| 462 {r: 0.48, g: 0.48, b: 0.48, a:1.0}; |
| 463 /** @const */ var SCENE_GROUND_SIZE = 25.0; |
| 464 /** @const */ var SCENE_HEIGHT = 4.0; |
| 465 /** @const */ var TILE_NUMBER = 10; |
| 466 |
| 467 // Make ground plane. |
| 468 let groundPlane = new api.UiElementUpdate(); |
| 469 groundPlane.setVisible(true); |
| 470 groundPlane.setSize(SCENE_GROUND_SIZE, SCENE_GROUND_SIZE); |
| 471 groundPlane.setFill(new api.OpaqueGradient(GRADIENT_LIGHER_GRAY, |
| 472 GRADIENT_DARKER_GRAY)); |
| 473 groundPlane.setTranslation(0, -SCENE_HEIGHT/2, 0); |
| 474 groundPlane.setRotation(1.0, 0.0, 0.0, -Math.PI/2); |
| 475 this.groundPlaneId = ui.addElement(groundPlane); |
| 476 |
| 477 // Make ceiling plane. |
| 478 let ceilingPlane = new api.UiElementUpdate(); |
| 479 ceilingPlane.setVisible(true); |
| 480 ceilingPlane.setSize(SCENE_GROUND_SIZE, SCENE_GROUND_SIZE); |
| 481 ceilingPlane.setFill(new api.OpaqueGradient(GRADIENT_LIGHER_GRAY, |
| 482 GRADIENT_DARKER_GRAY)); |
| 483 ceilingPlane.setTranslation(0, SCENE_HEIGHT/2, 0); |
| 484 ceilingPlane.setRotation(1.0, 0.0, 0.0, Math.PI/2); |
| 485 this.ceilingPlaneId = ui.addElement(ceilingPlane); |
| 486 |
| 487 // Ground grid. |
| 488 let groundGrid = new api.UiElementUpdate(); |
| 489 groundGrid.setVisible(true); |
| 490 groundGrid.setSize(SCENE_GROUND_SIZE, SCENE_GROUND_SIZE); |
| 491 groundGrid.setFill(new api.GridGradient(GRADIENT_LIGHER_GRAY, |
| 492 GRADIENT_LIGHER_GRAY, TILE_NUMBER)); |
| 493 groundGrid.setTranslation(0, -SCENE_HEIGHT/2 + 0.01, 0); |
| 494 groundGrid.setRotation(1.0, 0.0, 0.0, -Math.PI/2); |
| 495 this.groundGridId = ui.addElement(groundGrid); |
| 496 } |
| 497 |
| 498 setEnabled(enabled) { |
| 499 let groundPlaneUpdate = new api.UiElementUpdate(); |
| 500 groundPlaneUpdate.setVisible(enabled); |
| 501 ui.updateElement(this.groundPlaneId, groundPlaneUpdate); |
| 502 let ceilingPlaneUpdate = new api.UiElementUpdate(); |
| 503 ceilingPlaneUpdate.setVisible(enabled); |
| 504 ui.updateElement(this.ceilingPlaneId, ceilingPlaneUpdate); |
| 505 let groundGridUpdate = new api.UiElementUpdate(); |
| 506 groundGridUpdate.setVisible(enabled); |
| 507 ui.updateElement(this.groundGridId, groundGridUpdate); |
| 508 } |
| 509 }; |
| 456 | 510 |
| 457 class UiManager { | 511 class UiManager { |
| 458 constructor() { | 512 constructor() { |
| 459 this.mode = api.Mode.UNKNOWN; | 513 this.mode = api.Mode.UNKNOWN; |
| 460 this.menuMode = false; | 514 this.menuMode = false; |
| 461 this.fullscreen = false; | 515 this.fullscreen = false; |
| 462 | 516 |
| 517 this.background = new Background(); |
| 463 this.contentQuad = new ContentQuad(); | 518 this.contentQuad = new ContentQuad(); |
| 464 let contentId = this.contentQuad.getElementId(); | 519 let contentId = this.contentQuad.getElementId(); |
| 465 | 520 |
| 466 this.controls = new Controls(contentId); | 521 this.controls = new Controls(contentId); |
| 467 this.secureOriginWarnings = new SecureOriginWarnings(); | 522 this.secureOriginWarnings = new SecureOriginWarnings(); |
| 468 this.urlIndicator = new UrlIndicator(); | 523 this.urlIndicator = new UrlIndicator(); |
| 469 } | 524 } |
| 470 | 525 |
| 471 setMode(mode, menuMode, fullscreen) { | 526 setMode(mode, menuMode, fullscreen) { |
| 472 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; | 527 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; |
| 473 | 528 |
| 474 this.mode = mode; | 529 this.mode = mode; |
| 475 this.menuMode = menuMode; | 530 this.menuMode = menuMode; |
| 476 this.fullscreen = fullscreen; | 531 this.fullscreen = fullscreen; |
| 477 | 532 |
| 478 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 533 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 479 this.contentQuad.setFullscreen(fullscreen); | 534 this.contentQuad.setFullscreen(fullscreen); |
| 480 // TODO(crbug/643815): Set aspect ratio on content quad when available. | 535 // TODO(crbug/643815): Set aspect ratio on content quad when available. |
| 481 // TODO(amp): Don't show controls in fullscreen once MENU mode lands. | 536 // TODO(amp): Don't show controls in fullscreen once MENU mode lands. |
| 482 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 537 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 483 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 538 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 484 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. | 539 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. |
| 485 this.urlIndicator.setVisibilityTimeout( | 540 this.urlIndicator.setVisibilityTimeout( |
| 486 mode == api.Mode.STANDARD && !menuMode ? | 541 mode == api.Mode.STANDARD && !menuMode ? |
| 487 0 : | 542 0 : |
| 488 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); | 543 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); |
| 489 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); | 544 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); |
| 545 this.background.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 490 | 546 |
| 491 api.setUiCssSize( | 547 api.setUiCssSize( |
| 492 uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR); | 548 uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR); |
| 493 } | 549 } |
| 494 | 550 |
| 495 setSecurityLevel(level) { | 551 setSecurityLevel(level) { |
| 496 this.urlIndicator.setSecurityLevel(level); | 552 this.urlIndicator.setSecurityLevel(level); |
| 497 } | 553 } |
| 498 | 554 |
| 499 setWebVRSecureOrigin(secure) { | 555 setWebVRSecureOrigin(secure) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 ui.flush(); | 594 ui.flush(); |
| 539 } | 595 } |
| 540 | 596 |
| 541 return { | 597 return { |
| 542 initialize: initialize, | 598 initialize: initialize, |
| 543 command: command, | 599 command: command, |
| 544 }; | 600 }; |
| 545 })(); | 601 })(); |
| 546 | 602 |
| 547 window.addEventListener('load', vrShellUi.initialize); | 603 window.addEventListener('load', vrShellUi.initialize); |
| OLD | NEW |