| 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 scene = new ui.Scene(); | 8 let scene = new ui.Scene(); |
| 9 let sceneManager; | 9 let sceneManager; |
| 10 | 10 |
| 11 let uiRootElement = document.querySelector('#ui'); | 11 let uiRootElement = document.querySelector('#ui'); |
| 12 let uiStyle = window.getComputedStyle(uiRootElement); | 12 let uiStyle = window.getComputedStyle(uiRootElement); |
| 13 let scaleFactor = uiStyle.getPropertyValue('--scaleFactor'); | |
| 14 /** @const */ var ANIM_DURATION = 150; | 13 /** @const */ var ANIM_DURATION = 150; |
| 15 | 14 |
| 15 // This value should match the one in VrShellImpl.java |
| 16 /** @const */ var UI_DPR = 1.2; |
| 17 |
| 16 function getStyleFloat(style, property) { | 18 function getStyleFloat(style, property) { |
| 17 let value = parseFloat(style.getPropertyValue(property)); | 19 let value = parseFloat(style.getPropertyValue(property)); |
| 18 return isNaN(value) ? 0 : value; | 20 return isNaN(value) ? 0 : value; |
| 19 } | 21 } |
| 20 | 22 |
| 21 class ContentQuad { | 23 class ContentQuad { |
| 22 constructor() { | 24 constructor() { |
| 23 /** @const */ this.SCREEN_HEIGHT = 1.6; | 25 /** @const */ this.SCREEN_HEIGHT = 1.6; |
| 24 /** @const */ this.SCREEN_RATIO = 16 / 9; | 26 /** @const */ this.SCREEN_RATIO = 16 / 9; |
| 25 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; | 27 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 let domElement = document.querySelector(domId); | 65 let domElement = document.querySelector(domId); |
| 64 | 66 |
| 65 // Pull copy rectangle from the position of the element. | 67 // Pull copy rectangle from the position of the element. |
| 66 let rect = domElement.getBoundingClientRect(); | 68 let rect = domElement.getBoundingClientRect(); |
| 67 let pixelX = Math.floor(rect.left); | 69 let pixelX = Math.floor(rect.left); |
| 68 let pixelY = Math.floor(rect.top); | 70 let pixelY = Math.floor(rect.top); |
| 69 let pixelWidth = Math.ceil(rect.right) - pixelX; | 71 let pixelWidth = Math.ceil(rect.right) - pixelX; |
| 70 let pixelHeight = Math.ceil(rect.bottom) - pixelY; | 72 let pixelHeight = Math.ceil(rect.bottom) - pixelY; |
| 71 | 73 |
| 72 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); | 74 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); |
| 73 element.setSize(scaleFactor * pixelWidth / 1000, | 75 element.setSize(pixelWidth / 1000, pixelHeight / 1000); |
| 74 scaleFactor * pixelHeight / 1000); | |
| 75 | 76 |
| 76 // Pull additional custom properties from CSS. | 77 // Pull additional custom properties from CSS. |
| 77 let style = window.getComputedStyle(domElement); | 78 let style = window.getComputedStyle(domElement); |
| 78 element.setTranslation( | 79 element.setTranslation( |
| 79 getStyleFloat(style, '--tranX'), | 80 getStyleFloat(style, '--tranX'), |
| 80 getStyleFloat(style, '--tranY'), | 81 getStyleFloat(style, '--tranY'), |
| 81 getStyleFloat(style, '--tranZ')); | 82 getStyleFloat(style, '--tranZ')); |
| 82 | 83 |
| 83 this.uiElementId = scene.addElement(element); | 84 this.uiElementId = scene.addElement(element); |
| 84 this.uiAnimationId = -1; | 85 this.uiAnimationId = -1; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 this.menuMode = menuMode; | 408 this.menuMode = menuMode; |
| 408 this.cinemaMode = cinemaMode; | 409 this.cinemaMode = cinemaMode; |
| 409 | 410 |
| 410 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 411 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 411 this.contentQuad.setCinemaMode(cinemaMode); | 412 this.contentQuad.setCinemaMode(cinemaMode); |
| 412 // TODO(crbug/643815): Set aspect ratio on content quad when available. | 413 // TODO(crbug/643815): Set aspect ratio on content quad when available. |
| 413 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. | 414 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. |
| 414 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 415 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 415 this.omnibox.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 416 this.omnibox.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 416 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); | 417 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); |
| 418 |
| 419 api.setUiCssSize(uiRootElement.clientWidth, uiRootElement.clientHeight, |
| 420 UI_DPR); |
| 417 } | 421 } |
| 418 | 422 |
| 419 setSecureOrigin(secure) { | 423 setSecureOrigin(secure) { |
| 420 this.secureOriginWarnings.setSecureOrigin(secure); | 424 this.secureOriginWarnings.setSecureOrigin(secure); |
| 421 this.omnibox.setSecureOrigin(secure); | 425 this.omnibox.setSecureOrigin(secure); |
| 422 } | 426 } |
| 423 | 427 |
| 424 setReloadUiEnabled(enabled) { | 428 setReloadUiEnabled(enabled) { |
| 425 this.controls.setReloadUiEnabled(enabled); | 429 this.controls.setReloadUiEnabled(enabled); |
| 426 } | 430 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 453 scene.flush(); | 457 scene.flush(); |
| 454 } | 458 } |
| 455 | 459 |
| 456 return { | 460 return { |
| 457 initialize: initialize, | 461 initialize: initialize, |
| 458 command: command, | 462 command: command, |
| 459 }; | 463 }; |
| 460 })(); | 464 })(); |
| 461 | 465 |
| 462 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); | 466 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); |
| OLD | NEW |