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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 // Pull some CSS properties so that Javascript can reconfigure the omnibox | 309 // Pull some CSS properties so that Javascript can reconfigure the omnibox |
310 // programmatically. | 310 // programmatically. |
311 let border = | 311 let border = |
312 this.domUiElement.domElement.querySelector('#omnibox-border'); | 312 this.domUiElement.domElement.querySelector('#omnibox-border'); |
313 let style = window.getComputedStyle(border); | 313 let style = window.getComputedStyle(border); |
314 this.statusBarColor = getStyleString(style, '--statusBarColor'); | 314 this.statusBarColor = getStyleString(style, '--statusBarColor'); |
315 this.backgroundColor = style.backgroundColor; | 315 this.backgroundColor = style.backgroundColor; |
316 this.fadeTimeMs = getStyleFloat(style, '--fadeTimeMs'); | 316 this.fadeTimeMs = getStyleFloat(style, '--fadeTimeMs'); |
317 this.fadeYOffset = getStyleFloat(style, '--fadeYOffset'); | 317 this.fadeYOffset = getStyleFloat(style, '--fadeYOffset'); |
318 | 318 this.opacity = getStyleFloat(style, '--opacity'); |
319 // Listen to the end of transitions, so that the box can be natively | |
320 // hidden after it finishes hiding itself. | |
321 document.querySelector('#omnibox') | |
322 .addEventListener('transitionend', this.onAnimationDone.bind(this)); | |
323 } | 319 } |
324 | 320 |
325 getSecurityIconElementId(level) { | 321 getSecurityIconElementId(level) { |
326 // See security_state.h and getSecurityIconResource() for this mapping. | 322 // See security_state.h and getSecurityIconResource() for this mapping. |
327 switch (level) { | 323 switch (level) { |
328 case 0: // NONE | 324 case 0: // NONE |
329 case 1: // HTTP_SHOW_WARNING | 325 case 1: // HTTP_SHOW_WARNING |
330 case 4: // SECURITY_WARNING | 326 case 4: // SECURITY_WARNING |
331 return '#omnibox-info-icon'; | 327 return '#omnibox-info-icon'; |
332 case 2: // SECURE: | 328 case 2: // SECURE: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 this.visibilityTimer = setTimeout( | 387 this.visibilityTimer = setTimeout( |
392 this.onVisibilityTimer.bind(this), this.visibilityTimeout); | 388 this.onVisibilityTimer.bind(this), this.visibilityTimeout); |
393 } | 389 } |
394 } | 390 } |
395 | 391 |
396 onVisibilityTimer() { | 392 onVisibilityTimer() { |
397 this.visibilityTimer = null; | 393 this.visibilityTimer = null; |
398 this.updateState(); | 394 this.updateState(); |
399 } | 395 } |
400 | 396 |
401 onAnimationDone(e) { | 397 updateState() { |
402 if (e.propertyName == 'opacity' && this.hidden) { | 398 this.setNativeVisibility(this.enabled); |
403 this.setNativeVisibility(false); | |
404 } | |
405 } | |
406 | 399 |
407 updateState() { | |
408 if (!this.enabled) { | 400 if (!this.enabled) { |
409 this.setNativeVisibility(false); | |
410 return; | 401 return; |
411 } | 402 } |
412 | 403 |
413 let indicator = document.querySelector('#omnibox-border'); | 404 let indicator = document.querySelector('#omnibox-border'); |
414 if (this.loading) { | 405 if (this.loading) { |
415 // Remap load progress range 0-100 as 5-95 percent, to avoid the | 406 // Remap load progress range 0-100 as 5-95 percent, to avoid the |
416 // extremities of the rounded ends of the omnibox. | 407 // extremities of the rounded ends of the omnibox. |
417 let percent = Math.round((this.loadingProgress * 0.9 + 0.05) * 100); | 408 let percent = Math.round((this.loadingProgress * 0.9 + 0.05) * 100); |
418 let gradient = 'linear-gradient(to right, ' + this.statusBarColor + | 409 let gradient = 'linear-gradient(to right, ' + this.statusBarColor + |
419 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + | 410 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + |
420 this.backgroundColor + ' ' + percent + '%, ' + | 411 this.backgroundColor + ' ' + percent + '%, ' + |
421 this.backgroundColor + ' 100%)'; | 412 this.backgroundColor + ' 100%)'; |
422 indicator.style.background = gradient; | 413 indicator.style.background = gradient; |
423 } else { | 414 } else { |
424 indicator.style.background = this.backgroundColor; | 415 indicator.style.background = this.backgroundColor; |
425 } | 416 } |
426 | 417 |
427 let shouldBeHidden = | 418 let shouldBeHidden = |
428 !this.loading && this.visibilityTimeout > 0 && !this.visibilityTimer; | 419 !this.loading && this.visibilityTimeout > 0 && !this.visibilityTimer; |
429 if (shouldBeHidden != this.hidden) { | 420 if (shouldBeHidden != this.hidden) { |
430 // Make the box fade away if it's disappearing. | 421 // Make the box fade away if it's disappearing. |
431 this.hidden = shouldBeHidden; | 422 this.hidden = shouldBeHidden; |
432 document.querySelector('#omnibox-border').className = | 423 |
433 this.hidden ? 'hidden' : ''; | 424 // Fade-out or fade-in the box. |
| 425 let opacityAnimation = |
| 426 new api.Animation(this.domUiElement.uiElementId, this.fadeTimeMs); |
| 427 opacityAnimation.setOpacity(this.hidden ? 0.0 : this.opacity); |
| 428 ui.addAnimation(opacityAnimation); |
434 | 429 |
435 // Drop the position as it fades, or raise the position if appearing. | 430 // Drop the position as it fades, or raise the position if appearing. |
436 let yOffset = this.hidden ? this.fadeYOffset : 0; | 431 let yOffset = this.hidden ? this.fadeYOffset : 0; |
437 let animation = | 432 let positionAnimation = |
438 new api.Animation(this.domUiElement.uiElementId, this.fadeTimeMs); | 433 new api.Animation(this.domUiElement.uiElementId, this.fadeTimeMs); |
439 animation.setTranslation( | 434 positionAnimation.setTranslation( |
440 this.domUiElement.translationX, | 435 this.domUiElement.translationX, |
441 this.domUiElement.translationY + yOffset, | 436 this.domUiElement.translationY + yOffset, |
442 this.domUiElement.translationZ); | 437 this.domUiElement.translationZ); |
443 ui.addAnimation(animation); | 438 ui.addAnimation(positionAnimation); |
444 ui.flush(); | |
445 } | 439 } |
446 | 440 |
447 this.setNativeVisibility(true); | 441 ui.flush(); |
448 } | 442 } |
449 | 443 |
450 setNativeVisibility(visible) { | 444 setNativeVisibility(visible) { |
451 if (visible == this.nativeState.visible) { | 445 if (visible == this.nativeState.visible) { |
452 return; | 446 return; |
453 } | 447 } |
454 this.nativeState.visible = visible; | 448 this.nativeState.visible = visible; |
455 let update = new api.UiElementUpdate(); | 449 let update = new api.UiElementUpdate(); |
456 update.setVisible(visible); | 450 update.setVisible(visible); |
457 ui.updateElement(this.domUiElement.uiElementId, update); | 451 ui.updateElement(this.domUiElement.uiElementId, update); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 ui.flush(); | 537 ui.flush(); |
544 } | 538 } |
545 | 539 |
546 return { | 540 return { |
547 initialize: initialize, | 541 initialize: initialize, |
548 command: command, | 542 command: command, |
549 }; | 543 }; |
550 })(); | 544 })(); |
551 | 545 |
552 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); | 546 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); |
OLD | NEW |