| 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 /** @const */ var ANIM_DURATION = 150; | 13 /** @const */ var ANIM_DURATION = 150; |
| 14 | 14 |
| 15 // This value should match the one in VrShellImpl.java | 15 // This value should match the one in VrShellImpl.java |
| 16 /** @const */ var UI_DPR = 1.2; | 16 /** @const */ var UI_DPR = 1.2; |
| 17 | 17 |
| 18 function getStyleFloat(style, property) { | 18 function getStyleFloat(style, property) { |
| 19 let value = parseFloat(style.getPropertyValue(property)); | 19 let value = parseFloat(style.getPropertyValue(property)); |
| 20 return isNaN(value) ? 0 : value; | 20 return isNaN(value) ? 0 : value; |
| 21 } | 21 } |
| 22 | 22 |
| 23 function getStyleString(style, property) { |
| 24 let str = style.getPropertyValue(property); |
| 25 return !str || 0 === str.length ? '' : str; |
| 26 } |
| 27 |
| 23 class ContentQuad { | 28 class ContentQuad { |
| 24 constructor() { | 29 constructor() { |
| 25 /** @const */ this.SCREEN_HEIGHT = 1.6; | 30 /** @const */ this.SCREEN_HEIGHT = 1.6; |
| 26 /** @const */ this.SCREEN_RATIO = 16 / 9; | 31 /** @const */ this.SCREEN_RATIO = 16 / 9; |
| 27 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; | 32 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; |
| 28 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; | 33 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; |
| 29 | 34 |
| 30 let element = new api.UiElement(0, 0, 0, 0); | 35 let element = new api.UiElement(0, 0, 0, 0); |
| 31 element.setIsContentQuad(); | 36 element.setIsContentQuad(); |
| 32 element.setVisible(false); | 37 element.setVisible(false); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 let update = new api.UiElementUpdate(); | 281 let update = new api.UiElementUpdate(); |
| 277 update.setVisible(false); | 282 update.setVisible(false); |
| 278 scene.updateElement(this.transientWarning.uiElementId, update); | 283 scene.updateElement(this.transientWarning.uiElementId, update); |
| 279 this.secureOriginTimer = null; | 284 this.secureOriginTimer = null; |
| 280 scene.flush(); | 285 scene.flush(); |
| 281 } | 286 } |
| 282 }; | 287 }; |
| 283 | 288 |
| 284 class Omnibox { | 289 class Omnibox { |
| 285 constructor(contentQuadId) { | 290 constructor(contentQuadId) { |
| 286 this.domUiElement = new DomUiElement('#omni-container'); | 291 this.domUiElement = new DomUiElement('#omnibox-container'); |
| 287 this.enabled = false; | 292 this.enabled = false; |
| 288 this.loading = false; | 293 this.loading = false; |
| 294 this.loadingProgress = 0; |
| 289 this.level = 0; | 295 this.level = 0; |
| 290 this.visibilityTimeout = 0; | 296 this.visibilityTimeout = 0; |
| 291 this.visibilityTimer = null; | 297 this.visibilityTimer = null; |
| 292 this.visibleAfterTransition = false; | 298 this.visibleAfterTransition = false; |
| 293 this.nativeState = {}; | 299 this.nativeState = {}; |
| 294 | 300 |
| 295 // Initially invisible. | 301 // Initially invisible. |
| 296 let update = new api.UiElementUpdate(); | 302 let update = new api.UiElementUpdate(); |
| 297 update.setVisible(false); | 303 update.setVisible(false); |
| 298 scene.updateElement(this.domUiElement.uiElementId, update); | 304 scene.updateElement(this.domUiElement.uiElementId, update); |
| 299 this.nativeState.visible = false; | 305 this.nativeState.visible = false; |
| 300 | 306 |
| 307 // Pull colors from CSS so that Javascript can set the progress indicator |
| 308 // gradient programmatically. |
| 309 let border = |
| 310 this.domUiElement.domElement.querySelector('#omnibox-border'); |
| 311 let style = window.getComputedStyle(border); |
| 312 this.statusBarColor = getStyleString(style, '--statusBarColor'); |
| 313 this.backgroundColor = style.backgroundColor; |
| 314 |
| 301 // Listen to the end of transitions, so that the box can be natively | 315 // Listen to the end of transitions, so that the box can be natively |
| 302 // hidden after it finishes hiding itself. | 316 // hidden after it finishes hiding itself. |
| 303 document.querySelector('#omni').addEventListener( | 317 document.querySelector('#omnibox') |
| 304 'transitionend', this.onAnimationDone.bind(this)); | 318 .addEventListener('transitionend', this.onAnimationDone.bind(this)); |
| 305 } | 319 } |
| 306 | 320 |
| 307 getSecurityIconElementId(level) { | 321 getSecurityIconElementId(level) { |
| 308 // See security_state.h and getSecurityIconResource() for this mapping. | 322 // See security_state.h and getSecurityIconResource() for this mapping. |
| 309 switch (level) { | 323 switch (level) { |
| 310 case 0: // NONE | 324 case 0: // NONE |
| 311 case 1: // HTTP_SHOW_WARNING | 325 case 1: // HTTP_SHOW_WARNING |
| 312 case 4: // SECURITY_WARNING | 326 case 4: // SECURITY_WARNING |
| 313 return '#omni-info-icon'; | 327 return '#omnibox-info-icon'; |
| 314 case 2: // SECURE: | 328 case 2: // SECURE: |
| 315 case 3: // EV_SECURE: | 329 case 3: // EV_SECURE: |
| 316 return '#omni-lock-icon'; | 330 return '#omnibox-lock-icon'; |
| 317 case 5: // SECURE_WITH_POLICY_INSTALLED_CERT (ChromeOS only) | 331 case 5: // SECURE_WITH_POLICY_INSTALLED_CERT (ChromeOS only) |
| 318 case 6: // DANGEROUS | 332 case 6: // DANGEROUS |
| 319 default: | 333 default: |
| 320 return '#omni-warning-icon'; | 334 return '#omnibox-warning-icon'; |
| 321 } | 335 } |
| 322 } | 336 } |
| 323 | 337 |
| 324 setEnabled(enabled) { | 338 setEnabled(enabled) { |
| 325 this.enabled = enabled; | 339 this.enabled = enabled; |
| 326 this.resetVisibilityTimer(); | 340 this.resetVisibilityTimer(); |
| 327 this.updateState(); | 341 this.updateState(); |
| 328 } | 342 } |
| 329 | 343 |
| 330 setLoading(loading) { | 344 setLoading(loading) { |
| 331 this.loading = loading; | 345 this.loading = loading; |
| 346 this.loadingProgress = 0; |
| 332 this.resetVisibilityTimer(); | 347 this.resetVisibilityTimer(); |
| 333 this.updateState(); | 348 this.updateState(); |
| 334 } | 349 } |
| 335 | 350 |
| 351 setLoadingProgress(progress) { |
| 352 this.loadingProgress = progress; |
| 353 this.updateState(); |
| 354 } |
| 355 |
| 336 setURL(host, path) { | 356 setURL(host, path) { |
| 337 let omnibox = this.domUiElement.domElement; | 357 let omnibox = this.domUiElement.domElement; |
| 338 omnibox.querySelector('#domain').innerHTML = host; | 358 omnibox.querySelector('#domain').innerHTML = host; |
| 339 omnibox.querySelector('#path').innerHTML = path; | 359 omnibox.querySelector('#path').innerHTML = path; |
| 340 this.resetVisibilityTimer(); | 360 this.resetVisibilityTimer(); |
| 341 this.updateState(); | 361 this.updateState(); |
| 342 } | 362 } |
| 343 | 363 |
| 344 setSecurityLevel(level) { | 364 setSecurityLevel(level) { |
| 345 this.level = level; | 365 document.querySelector('#omnibox-warning-icon').style.display = 'none'; |
| 366 document.querySelector('#omnibox-info-icon').style.display = 'none'; |
| 367 document.querySelector('#omnibox-lock-icon').style.display = 'none'; |
| 368 let icon = this.getSecurityIconElementId(level); |
| 369 document.querySelector(icon).style.display = 'block'; |
| 370 |
| 346 this.resetVisibilityTimer(); | 371 this.resetVisibilityTimer(); |
| 347 this.updateState(); | 372 this.updateState(); |
| 348 } | 373 } |
| 349 | 374 |
| 350 setVisibilityTimeout(milliseconds) { | 375 setVisibilityTimeout(milliseconds) { |
| 351 this.visibilityTimeout = milliseconds; | 376 this.visibilityTimeout = milliseconds; |
| 352 this.resetVisibilityTimer(); | 377 this.resetVisibilityTimer(); |
| 353 this.updateState(); | 378 this.updateState(); |
| 354 } | 379 } |
| 355 | 380 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 374 this.setNativeVisibility(false); | 399 this.setNativeVisibility(false); |
| 375 } | 400 } |
| 376 } | 401 } |
| 377 | 402 |
| 378 updateState() { | 403 updateState() { |
| 379 if (!this.enabled) { | 404 if (!this.enabled) { |
| 380 this.setNativeVisibility(false); | 405 this.setNativeVisibility(false); |
| 381 return; | 406 return; |
| 382 } | 407 } |
| 383 | 408 |
| 384 document.querySelector('#omni-warning-icon').style.display = 'none'; | 409 let indicator = document.querySelector('#omnibox-border'); |
| 385 document.querySelector('#omni-info-icon').style.display = 'none'; | 410 if (this.loading) { |
| 386 document.querySelector('#omni-lock-icon').style.display = 'none'; | 411 // Remap load progress range 0-100 as 5-95 percent, to avoid the |
| 387 let icon = this.getSecurityIconElementId(this.level); | 412 // extremities of the rounded ends of the omnibox. |
| 388 document.querySelector(icon).style.display = 'block'; | 413 let percent = Math.round((this.loadingProgress * 0.9 + 0.05) * 100); |
| 414 let gradient = 'linear-gradient(to right, ' + this.statusBarColor + |
| 415 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + |
| 416 this.backgroundColor + ' ' + percent + '%, ' + |
| 417 this.backgroundColor + ' 100%)'; |
| 418 indicator.style.background = gradient; |
| 419 } else { |
| 420 indicator.style.background = this.backgroundColor; |
| 421 } |
| 389 | 422 |
| 390 let state = 'idle'; | 423 // Make the box fade away if it's disappearing. |
| 391 this.visibleAfterTransition = true; | 424 if (!this.loading && this.visibilityTimeout > 0 && |
| 392 if (this.loading) { | 425 !this.visibilityTimer) { |
| 393 state = 'loading'; | 426 document.querySelector('#omnibox-border').className = 'hidden'; |
| 394 } else if (this.visibilityTimeout > 0 && !this.visibilityTimer) { | |
| 395 state = 'hide'; | |
| 396 this.visibleAfterTransition = false; | 427 this.visibleAfterTransition = false; |
| 428 } else { |
| 429 document.querySelector('#omnibox-border').className = ''; |
| 430 this.visibleAfterTransition = true; |
| 397 } | 431 } |
| 398 document.querySelector('#omni').className = state; | |
| 399 | 432 |
| 400 this.setNativeVisibility(true); | 433 this.setNativeVisibility(true); |
| 401 } | 434 } |
| 402 | 435 |
| 403 setNativeVisibility(visible) { | 436 setNativeVisibility(visible) { |
| 404 if (visible == this.nativeState.visible) { | 437 if (visible == this.nativeState.visible) { |
| 405 return; | 438 return; |
| 406 } | 439 } |
| 407 this.nativeState.visible = visible; | 440 this.nativeState.visible = visible; |
| 408 let update = new api.UiElementUpdate(); | 441 let update = new api.UiElementUpdate(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 if ('enableReloadUi' in dict) { | 516 if ('enableReloadUi' in dict) { |
| 484 sceneManager.setReloadUiEnabled(dict['enableReloadUi']); | 517 sceneManager.setReloadUiEnabled(dict['enableReloadUi']); |
| 485 } | 518 } |
| 486 if ('url' in dict) { | 519 if ('url' in dict) { |
| 487 let url = dict['url']; | 520 let url = dict['url']; |
| 488 sceneManager.omnibox.setURL(url['host'], url['path']); | 521 sceneManager.omnibox.setURL(url['host'], url['path']); |
| 489 } | 522 } |
| 490 if ('loading' in dict) { | 523 if ('loading' in dict) { |
| 491 sceneManager.omnibox.setLoading(dict['loading']); | 524 sceneManager.omnibox.setLoading(dict['loading']); |
| 492 } | 525 } |
| 526 if ('loadingProgress' in dict) { |
| 527 sceneManager.omnibox.setLoadingProgress(dict['loadingProgress']); |
| 528 } |
| 493 scene.flush(); | 529 scene.flush(); |
| 494 } | 530 } |
| 495 | 531 |
| 496 return { | 532 return { |
| 497 initialize: initialize, | 533 initialize: initialize, |
| 498 command: command, | 534 command: command, |
| 499 }; | 535 }; |
| 500 })(); | 536 })(); |
| 501 | 537 |
| 502 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); | 538 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); |
| OLD | NEW |