| 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 let nativeCommandHandler; | 10 let nativeCommandHandler; |
| 11 | 11 |
| 12 let uiRootElement = document.querySelector('#ui'); | 12 let uiRootElement = document.querySelector('#ui'); |
| 13 let uiStyle = window.getComputedStyle(uiRootElement); | 13 let uiStyle = window.getComputedStyle(uiRootElement); |
| 14 /** @const */ var ANIM_DURATION = 150; | 14 /** @const */ var ANIM_DURATION = 150; |
| 15 | 15 |
| 16 // This value should match the one in VrShellImpl.java | 16 // This value should match the one in VrShellImpl.java |
| 17 /** @const */ var UI_DPR = 1.2; | 17 /** @const */ var UI_DPR = 1.2; |
| 18 | 18 |
| 19 function getStyleFloat(style, property, defaultValue) { | 19 function getStyleFloat(style, property, defaultValue) { |
| 20 let value = parseFloat(style.getPropertyValue(property)); | 20 let value = parseFloat(style.getPropertyValue(property)); |
| 21 return isNaN(value) ? defaultValue : value; | 21 return isNaN(value) ? defaultValue : value; |
| 22 } | 22 } |
| 23 | 23 |
| 24 function getStyleString(style, property) { | 24 function getStyleString(style, property) { |
| 25 let str = style.getPropertyValue(property); | 25 let str = style.getPropertyValue(property); |
| 26 return !str || 0 === str.length ? '' : str; | 26 return !str || 0 === str.length ? '' : str; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Generate a two-color progress bar style background using a gradient. |
| 30 function makeProgressBackground(loading, percentage, color, background) { |
| 31 if (!loading) { |
| 32 return background; |
| 33 } |
| 34 return 'linear-gradient(to right, ' + color + ' 0%, ' + color + ' ' + |
| 35 percentage * 100.0 + '%, ' + background + ' ' + percentage * 100 + |
| 36 '%, ' + background + ' 100%)'; |
| 37 } |
| 38 |
| 29 class ContentQuad { | 39 class ContentQuad { |
| 30 constructor() { | 40 constructor() { |
| 31 /** @const */ this.SCREEN_HEIGHT = 1.375; | 41 /** @const */ this.SCREEN_HEIGHT = 1.375; |
| 32 /** @const */ this.SCREEN_RATIO = 9.6 / 6.4; | 42 /** @const */ this.SCREEN_RATIO = 9.6 / 6.4; |
| 33 /** @const */ this.BROWSING_SCREEN_ELEVATION = -0.15; | 43 /** @const */ this.BROWSING_SCREEN_ELEVATION = -0.15; |
| 34 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; | 44 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; |
| 35 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; | 45 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; |
| 36 /** @const */ this.CSS_WIDTH_PIXELS = 960.0; | 46 /** @const */ this.CSS_WIDTH_PIXELS = 960.0; |
| 37 /** @const */ this.CSS_HEIGHT_PIXELS = 640.0; | 47 /** @const */ this.CSS_HEIGHT_PIXELS = 640.0; |
| 38 /** @const */ this.DPR = 1.2; | 48 /** @const */ this.DPR = 1.2; |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 } | 675 } |
| 666 | 676 |
| 667 updateState() { | 677 updateState() { |
| 668 this.setNativeVisibility(this.enabled); | 678 this.setNativeVisibility(this.enabled); |
| 669 | 679 |
| 670 if (!this.enabled) { | 680 if (!this.enabled) { |
| 671 return; | 681 return; |
| 672 } | 682 } |
| 673 | 683 |
| 674 let indicator = document.querySelector('#url-indicator-border'); | 684 let indicator = document.querySelector('#url-indicator-border'); |
| 675 if (this.loading) { | 685 indicator.style.background = makeProgressBackground( |
| 676 // Remap load progress range 0-100 as 5-95 percent, to avoid the | 686 this.loading, this.loadProgress, this.statusBarColor, |
| 677 // extremities of the rounded ends of the indicator. | 687 this.backgroundColor); |
| 678 let percent = Math.round((this.loadProgress * 0.9 + 0.05) * 100); | |
| 679 let gradient = 'linear-gradient(to right, ' + this.statusBarColor + | |
| 680 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + | |
| 681 this.backgroundColor + ' ' + percent + '%, ' + | |
| 682 this.backgroundColor + ' 100%)'; | |
| 683 indicator.style.background = gradient; | |
| 684 } else { | |
| 685 indicator.style.background = this.backgroundColor; | |
| 686 } | |
| 687 | 688 |
| 688 let shouldBeHidden = | 689 let shouldBeHidden = |
| 689 !this.loading && this.visibilityTimeout > 0 && !this.visibilityTimer; | 690 !this.loading && this.visibilityTimeout > 0 && !this.visibilityTimer; |
| 690 if (shouldBeHidden != this.hidden) { | 691 if (shouldBeHidden != this.hidden) { |
| 691 // Make the box fade away if it's disappearing. | 692 // Make the box fade away if it's disappearing. |
| 692 this.hidden = shouldBeHidden; | 693 this.hidden = shouldBeHidden; |
| 693 | 694 |
| 694 // Fade-out or fade-in the box. | 695 // Fade-out or fade-in the box. |
| 695 let opacityAnimation = | 696 let opacityAnimation = |
| 696 new api.Animation(this.domUiElement.id, this.fadeTimeMs); | 697 new api.Animation(this.domUiElement.id, this.fadeTimeMs); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 825 |
| 825 class Omnibox { | 826 class Omnibox { |
| 826 constructor() { | 827 constructor() { |
| 827 /** @const */ this.ELEVATION = -0.7; | 828 /** @const */ this.ELEVATION = -0.7; |
| 828 /** @const */ this.DISTANCE = -1.99; | 829 /** @const */ this.DISTANCE = -1.99; |
| 829 /** @const */ this.SCALE = -this.DISTANCE; | 830 /** @const */ this.SCALE = -this.DISTANCE; |
| 830 | 831 |
| 831 this.enabled = false; | 832 this.enabled = false; |
| 832 | 833 |
| 833 let root = document.querySelector('#omnibox-ui-element'); | 834 let root = document.querySelector('#omnibox-ui-element'); |
| 834 this.domUiElement = new DomUiElement('#omnibox-url-element'); | 835 this.domUiElement = new DomUiElement('#omnibox-border'); |
| 835 this.inputField = root.querySelector('#omnibox-input-field'); | 836 this.inputField = root.querySelector('#omnibox-input-field'); |
| 836 | 837 |
| 838 let style = window.getComputedStyle(this.domUiElement.domElement); |
| 839 this.statusBarColor = getStyleString(style, '--statusBarColor'); |
| 840 this.backgroundColor = style.backgroundColor; |
| 841 this.loading = false; |
| 842 this.loadProgress = 0; |
| 843 this.updateLoadingState(); |
| 844 |
| 837 // Initially invisible. | 845 // Initially invisible. |
| 838 let update = new api.UiElementUpdate(); | 846 let update = new api.UiElementUpdate(); |
| 839 update.setVisible(false); | 847 update.setVisible(false); |
| 840 update.setTranslation(0, this.ELEVATION, this.DISTANCE); | 848 update.setTranslation(0, this.ELEVATION, this.DISTANCE); |
| 841 update.setScale(this.SCALE, this.SCALE, this.SCALE); | 849 update.setScale(this.SCALE, this.SCALE, this.SCALE); |
| 842 ui.updateElement(this.domUiElement.id, update); | 850 ui.updateElement(this.domUiElement.id, update); |
| 843 | 851 |
| 844 // Field-clearing button. | 852 // Field-clearing button. |
| 845 let clearButton = root.querySelector('#omnibox-clear-button'); | 853 let clearButton = root.querySelector('#omnibox-clear-button'); |
| 846 clearButton.addEventListener('click', function() { | 854 clearButton.addEventListener('click', function() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 | 908 |
| 901 setURL(url) { | 909 setURL(url) { |
| 902 this.inputField.value = url; | 910 this.inputField.value = url; |
| 903 } | 911 } |
| 904 | 912 |
| 905 setSuggestions(suggestions) { | 913 setSuggestions(suggestions) { |
| 906 this.suggestions = suggestions; | 914 this.suggestions = suggestions; |
| 907 this.updateSuggestions(); | 915 this.updateSuggestions(); |
| 908 } | 916 } |
| 909 | 917 |
| 918 setLoading(loading) { |
| 919 this.loading = loading; |
| 920 this.loadProgress = 0; |
| 921 this.updateLoadingState(); |
| 922 } |
| 923 |
| 924 setLoadProgress(progress) { |
| 925 this.loadProgress = progress; |
| 926 this.updateLoadingState(); |
| 927 } |
| 928 |
| 929 updateLoadingState() { |
| 930 let indicator = document.querySelector('#omnibox-border'); |
| 931 indicator.style.background = makeProgressBackground( |
| 932 this.loading, this.loadProgress, this.statusBarColor, |
| 933 this.backgroundColor); |
| 934 } |
| 935 |
| 910 updateSuggestions() { | 936 updateSuggestions() { |
| 911 for (var i = 0; i < this.maxSuggestions; i++) { | 937 for (var i = 0; i < this.maxSuggestions; i++) { |
| 912 let element = document.querySelector('#suggestion-' + i); | 938 let element = document.querySelector('#suggestion-' + i); |
| 913 let update = new api.UiElementUpdate(); | 939 let update = new api.UiElementUpdate(); |
| 914 if (this.enabled && i < this.suggestions.length) { | 940 if (this.enabled && i < this.suggestions.length) { |
| 915 element.textContent = this.suggestions[i].description; | 941 element.textContent = this.suggestions[i].description; |
| 916 element.url = this.suggestions[i].url; | 942 element.url = this.suggestions[i].url; |
| 917 update.setVisible(true); | 943 update.setVisible(true); |
| 918 } else { | 944 } else { |
| 919 element.textContent = ''; | 945 element.textContent = ''; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 | 1281 |
| 1256 /** @override */ | 1282 /** @override */ |
| 1257 onSetUrl(host, path) { | 1283 onSetUrl(host, path) { |
| 1258 this.manager.urlIndicator.setURL(host, path); | 1284 this.manager.urlIndicator.setURL(host, path); |
| 1259 this.manager.omnibox.setURL(host, path); | 1285 this.manager.omnibox.setURL(host, path); |
| 1260 } | 1286 } |
| 1261 | 1287 |
| 1262 /** @override */ | 1288 /** @override */ |
| 1263 onSetLoading(loading) { | 1289 onSetLoading(loading) { |
| 1264 this.manager.urlIndicator.setLoading(loading); | 1290 this.manager.urlIndicator.setLoading(loading); |
| 1291 this.manager.omnibox.setLoading(loading); |
| 1265 } | 1292 } |
| 1266 | 1293 |
| 1267 /** @override */ | 1294 /** @override */ |
| 1268 onSetLoadingProgress(progress) { | 1295 onSetLoadingProgress(progress) { |
| 1269 this.manager.urlIndicator.setLoadProgress(progress); | 1296 this.manager.urlIndicator.setLoadProgress(progress); |
| 1297 this.manager.omnibox.setLoadProgress(progress); |
| 1270 } | 1298 } |
| 1271 | 1299 |
| 1272 /** @override */ | 1300 /** @override */ |
| 1273 onSetOmniboxSuggestions(suggestions) { | 1301 onSetOmniboxSuggestions(suggestions) { |
| 1274 this.manager.omnibox.setSuggestions(suggestions); | 1302 this.manager.omnibox.setSuggestions(suggestions); |
| 1275 } | 1303 } |
| 1276 | 1304 |
| 1277 /** @override */ | 1305 /** @override */ |
| 1278 onSetTabs(tabs) { | 1306 onSetTabs(tabs) { |
| 1279 uiManager.tabContainer.setTabs(tabs); | 1307 uiManager.tabContainer.setTabs(tabs); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1308 nativeCommandHandler.handleCommand(dict); | 1336 nativeCommandHandler.handleCommand(dict); |
| 1309 } | 1337 } |
| 1310 | 1338 |
| 1311 return { | 1339 return { |
| 1312 initialize: initialize, | 1340 initialize: initialize, |
| 1313 command: command, | 1341 command: command, |
| 1314 }; | 1342 }; |
| 1315 })(); | 1343 })(); |
| 1316 | 1344 |
| 1317 window.addEventListener('load', vrShellUi.initialize); | 1345 window.addEventListener('load', vrShellUi.initialize); |
| OLD | NEW |