| 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 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 getElementId() { | 39 getElementId() { |
| 40 return this.elementId; | 40 return this.elementId; |
| 41 } | 41 } |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class DomUiElement { | 44 class DomUiElement { |
| 45 constructor(domId) { | 45 constructor(domId) { |
| 46 let domElement = document.querySelector(domId); | 46 let domElement = document.querySelector(domId); |
| 47 let style = window.getComputedStyle(domElement); | |
| 48 | 47 |
| 49 // Pull copy rectangle from DOM element properties. | 48 // Pull copy rectangle from the position of the element. |
| 50 let pixelX = Math.round(domElement.offsetLeft / scaleFactor); | 49 let rect = domElement.getBoundingClientRect(); |
| 51 let pixelY = Math.round(domElement.offsetTop / scaleFactor); | 50 let pixelX = Math.floor(rect.left); |
| 52 let pixelWidth = Math.round( | 51 let pixelY = Math.floor(rect.top); |
| 53 parseInt(style.getPropertyValue('width')) / scaleFactor); | 52 let pixelWidth = Math.ceil(rect.right) - pixelX; |
| 54 let pixelHeight = Math.round( | 53 let pixelHeight = Math.ceil(rect.bottom) - pixelY; |
| 55 parseInt(style.getPropertyValue('height')) / scaleFactor); | |
| 56 | 54 |
| 57 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); | 55 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); |
| 58 element.setSize(scaleFactor * pixelWidth / 1000, | 56 element.setSize(scaleFactor * pixelWidth / 1000, |
| 59 scaleFactor * pixelHeight / 1000); | 57 scaleFactor * pixelHeight / 1000); |
| 60 | 58 |
| 61 // Pull additional custom properties from CSS. | 59 // Pull additional custom properties from CSS. |
| 60 let style = window.getComputedStyle(domElement); |
| 62 element.setTranslation( | 61 element.setTranslation( |
| 63 getStyleFloat(style, '--tranX'), | 62 getStyleFloat(style, '--tranX'), |
| 64 getStyleFloat(style, '--tranY'), | 63 getStyleFloat(style, '--tranY'), |
| 65 getStyleFloat(style, '--tranZ')); | 64 getStyleFloat(style, '--tranZ')); |
| 66 | 65 |
| 67 this.uiElementId = scene.addElement(element); | 66 this.uiElementId = scene.addElement(element); |
| 68 this.uiAnimationId = -1; | 67 this.uiAnimationId = -1; |
| 69 this.domElement = domElement; | 68 this.domElement = domElement; |
| 70 } | 69 } |
| 71 }; | 70 }; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 let update = new api.UiElementUpdate(); | 244 let update = new api.UiElementUpdate(); |
| 246 update.setVisible(false); | 245 update.setVisible(false); |
| 247 scene.updateElement(this.transientWarning.uiElementId, update); | 246 scene.updateElement(this.transientWarning.uiElementId, update); |
| 248 this.secureOriginTimer = null; | 247 this.secureOriginTimer = null; |
| 249 scene.flush(); | 248 scene.flush(); |
| 250 } | 249 } |
| 251 }; | 250 }; |
| 252 | 251 |
| 253 class Omnibox { | 252 class Omnibox { |
| 254 constructor(contentQuadId) { | 253 constructor(contentQuadId) { |
| 255 this.setSecure(false); | 254 this.setSecureOrigin(false); |
| 256 this.domUiElement = new DomUiElement('#omni'); | 255 this.domUiElement = new DomUiElement('#omni'); |
| 257 let update = new api.UiElementUpdate(); | 256 let update = new api.UiElementUpdate(); |
| 258 update.setVisible(false); | 257 update.setVisible(false); |
| 259 scene.updateElement(this.domUiElement.uiElementId, update); | 258 scene.updateElement(this.domUiElement.uiElementId, update); |
| 260 } | 259 } |
| 261 | 260 |
| 262 show(visible) { | 261 show(visible) { |
| 263 let update = new api.UiElementUpdate(); | 262 let update = new api.UiElementUpdate(); |
| 264 update.setVisible(visible); | 263 update.setVisible(visible); |
| 265 scene.updateElement(this.domUiElement.uiElementId, update); | 264 scene.updateElement(this.domUiElement.uiElementId, update); |
| 266 } | 265 } |
| 267 | 266 |
| 268 setLoading(loading) { | 267 setLoading(loading) { |
| 269 this.domUiElement.domElement.className = loading ? 'loading' : 'idle'; | 268 this.domUiElement.domElement.className = loading ? 'loading' : 'idle'; |
| 270 } | 269 } |
| 271 | 270 |
| 272 setURL(host, path) { | 271 setURL(host, path) { |
| 273 let omnibox = this.domUiElement.domElement; | 272 let omnibox = this.domUiElement.domElement; |
| 274 omnibox.querySelector('#domain').innerHTML = host; | 273 omnibox.querySelector('#domain').innerHTML = host; |
| 275 omnibox.querySelector('#path').innerHTML = path; | 274 omnibox.querySelector('#path').innerHTML = path; |
| 276 } | 275 } |
| 277 | 276 |
| 278 setSecure(secure) { | 277 setSecureOrigin(secure) { |
| 279 let image = secure ? 'lock.svg' : 'i_circle.svg'; | 278 document.querySelector('#omni-secure-icon').style.display = |
| 280 let path = '../../../../ui/webui/resources/images/' + image; | 279 (secure ? 'block' : 'none'); |
| 281 document.querySelector('#connection-security').src = path; | 280 document.querySelector('#omni-insecure-icon').style.display = |
| 281 (!secure ? 'block' : 'none'); |
| 282 } | 282 } |
| 283 }; | 283 }; |
| 284 | 284 |
| 285 class SceneManager { | 285 class SceneManager { |
| 286 constructor() { | 286 constructor() { |
| 287 this.mode = api.Mode.UNKNOWN; | 287 this.mode = api.Mode.UNKNOWN; |
| 288 | 288 |
| 289 this.contentQuad = new ContentQuad(); | 289 this.contentQuad = new ContentQuad(); |
| 290 let contentId = this.contentQuad.getElementId(); | 290 let contentId = this.contentQuad.getElementId(); |
| 291 | 291 |
| 292 this.controls = new Controls(contentId); | 292 this.controls = new Controls(contentId); |
| 293 this.secureOriginWarnings = new SecureOriginWarnings(); | 293 this.secureOriginWarnings = new SecureOriginWarnings(); |
| 294 this.omnibox = new Omnibox(contentId); | 294 this.omnibox = new Omnibox(contentId); |
| 295 } | 295 } |
| 296 | 296 |
| 297 setMode(mode) { | 297 setMode(mode) { |
| 298 this.mode = mode; | 298 this.mode = mode; |
| 299 this.contentQuad.show(mode == api.Mode.STANDARD); | 299 this.contentQuad.show(mode == api.Mode.STANDARD); |
| 300 this.controls.show(mode == api.Mode.STANDARD); | 300 this.controls.show(mode == api.Mode.STANDARD); |
| 301 this.omnibox.show(mode == api.Mode.STANDARD); | 301 this.omnibox.show(mode == api.Mode.STANDARD); |
| 302 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR); | 302 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR); |
| 303 } | 303 } |
| 304 | 304 |
| 305 setSecureOrigin(secure) { | 305 setSecureOrigin(secure) { |
| 306 this.secureOriginWarnings.setSecureOrigin(secure); | 306 this.secureOriginWarnings.setSecureOrigin(secure); |
| 307 this.omnibox.setSecureOrigin(secure); |
| 307 } | 308 } |
| 308 | 309 |
| 309 setReloadUiEnabled(enabled) { | 310 setReloadUiEnabled(enabled) { |
| 310 this.controls.setReloadUiEnabled(enabled); | 311 this.controls.setReloadUiEnabled(enabled); |
| 311 } | 312 } |
| 312 }; | 313 }; |
| 313 | 314 |
| 314 function initialize() { | 315 function initialize() { |
| 315 sceneManager = new SceneManager(); | 316 sceneManager = new SceneManager(); |
| 316 scene.flush(); | 317 scene.flush(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 338 scene.flush(); | 339 scene.flush(); |
| 339 } | 340 } |
| 340 | 341 |
| 341 return { | 342 return { |
| 342 initialize: initialize, | 343 initialize: initialize, |
| 343 command: command, | 344 command: command, |
| 344 }; | 345 }; |
| 345 })(); | 346 })(); |
| 346 | 347 |
| 347 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); | 348 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); |
| OLD | NEW |