| 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; |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 } | 655 } |
| 656 break; | 656 break; |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 }; | 659 }; |
| 660 | 660 |
| 661 class Omnibox { | 661 class Omnibox { |
| 662 constructor() { | 662 constructor() { |
| 663 this.enabled = false; | 663 this.enabled = false; |
| 664 | 664 |
| 665 this.domUiElement = new DomUiElement('#omnibox-ui-element'); | 665 let root = document.querySelector('#omnibox-ui-element'); |
| 666 let root = this.domUiElement.domElement; | 666 this.domUiElement = new DomUiElement('#omnibox-url-element'); |
| 667 this.inputField = root.querySelector('#omnibox-input-field'); | 667 this.inputField = root.querySelector('#omnibox-input-field'); |
| 668 | 668 |
| 669 // Initially invisible. | 669 // Initially invisible. |
| 670 let update = new api.UiElementUpdate(); | 670 let update = new api.UiElementUpdate(); |
| 671 update.setVisible(true); | 671 update.setVisible(false); |
| 672 ui.updateElement(this.domUiElement.id, update); | 672 ui.updateElement(this.domUiElement.id, update); |
| 673 | 673 |
| 674 // Field-clearing button. | 674 // Field-clearing button. |
| 675 let clearButton = root.querySelector('#omnibox-clear-button'); | 675 let clearButton = root.querySelector('#omnibox-clear-button'); |
| 676 clearButton.addEventListener('click', function() { | 676 clearButton.addEventListener('click', function() { |
| 677 this.inputField.value = ''; | 677 this.inputField.value = ''; |
| 678 api.doAction(api.Action.OMNIBOX_CONTENT, {'text': ''}); | 678 api.doAction(api.Action.OMNIBOX_CONTENT, {'text': ''}); |
| 679 }.bind(this)); | 679 }.bind(this)); |
| 680 | 680 |
| 681 // Watch for the enter key to trigger navigation. | 681 // Watch for the enter key to trigger navigation. |
| 682 this.inputField.addEventListener('keypress', function(e) { | 682 this.inputField.addEventListener('keypress', function(e) { |
| 683 if (e.keyCode == 13) { | 683 if (e.keyCode == 13) { |
| 684 this.setSuggestions([]); | 684 this.setSuggestions([]); |
| 685 api.doAction( | 685 api.doAction( |
| 686 // TODO(crbug.com/683344): Properly choose prefix. | 686 // TODO(crbug.com/683344): Properly choose prefix. |
| 687 api.Action.LOAD_URL, {'url': 'http://' + e.target.value}); | 687 api.Action.LOAD_URL, {'url': 'http://' + e.target.value}); |
| 688 } | 688 } |
| 689 }); | 689 }); |
| 690 | 690 |
| 691 // Watch for field input to generate suggestions. | 691 // Watch for field input to generate suggestions. |
| 692 this.inputField.addEventListener('input', function(e) { | 692 this.inputField.addEventListener('input', function(e) { |
| 693 api.doAction(api.Action.OMNIBOX_CONTENT, {'text': e.target.value}); | 693 api.doAction(api.Action.OMNIBOX_CONTENT, {'text': e.target.value}); |
| 694 }); | 694 }); |
| 695 | 695 |
| 696 // Clicking on suggestions triggers navigation. | 696 // Clicking on suggestions triggers navigation. |
| 697 let elements = root.querySelectorAll('.suggestion'); | 697 let elements = root.querySelectorAll('.suggestion'); |
| 698 this.maxSuggestions = elements.length; | 698 this.maxSuggestions = elements.length; |
| 699 this.suggestions = []; |
| 700 this.suggestionUiElements = []; |
| 699 for (var i = 0; i < elements.length; i++) { | 701 for (var i = 0; i < elements.length; i++) { |
| 700 elements[i].addEventListener('click', function(index, e) { | 702 elements[i].addEventListener('click', function(index, e) { |
| 701 if (e.target.url) { | 703 if (e.target.url) { |
| 702 api.doAction(api.Action.LOAD_URL, {'url': e.target.url}); | 704 api.doAction(api.Action.LOAD_URL, {'url': e.target.url}); |
| 703 this.setSuggestions([]); | 705 this.setSuggestions([]); |
| 704 } | 706 } |
| 705 }.bind(this, i)); | 707 }.bind(this, i)); |
| 708 |
| 709 let elem = new DomUiElement('#suggestion-' + i); |
| 710 this.suggestionUiElements.push(elem); |
| 711 let update = new api.UiElementUpdate(); |
| 712 update.setVisible(false); |
| 713 update.setParentId(this.domUiElement.id); |
| 714 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YTOP); |
| 715 // Vertically offset suggestions to stack on top of the omnibox. The 0.5 |
| 716 // offset moves each anchor point from center to edge. |
| 717 update.setTranslation(0, elem.sizeY * (i + 0.5), 0); |
| 718 ui.updateElement(elem.id, update); |
| 706 } | 719 } |
| 720 this.setSuggestions([]); |
| 707 } | 721 } |
| 708 | 722 |
| 709 setEnabled(enabled) { | 723 setEnabled(enabled) { |
| 710 this.enabled = enabled; | 724 this.enabled = enabled; |
| 711 let update = new api.UiElementUpdate(); | 725 let update = new api.UiElementUpdate(); |
| 712 update.setVisible(enabled); | 726 update.setVisible(enabled); |
| 713 ui.updateElement(this.domUiElement.id, update); | 727 ui.updateElement(this.domUiElement.id, update); |
| 728 this.updateSuggestions(); |
| 714 } | 729 } |
| 715 | 730 |
| 716 setURL(url) { | 731 setURL(url) { |
| 717 this.inputField.value = url; | 732 this.inputField.value = url; |
| 718 } | 733 } |
| 719 | 734 |
| 720 setSuggestions(suggestions) { | 735 setSuggestions(suggestions) { |
| 736 this.suggestions = suggestions; |
| 737 this.updateSuggestions(); |
| 738 } |
| 739 |
| 740 updateSuggestions() { |
| 721 for (var i = 0; i < this.maxSuggestions; i++) { | 741 for (var i = 0; i < this.maxSuggestions; i++) { |
| 722 let element = document.querySelector('#suggestion-' + i); | 742 let element = document.querySelector('#suggestion-' + i); |
| 723 if (i >= suggestions.length) { | 743 let update = new api.UiElementUpdate(); |
| 744 if (this.enabled && i < this.suggestions.length) { |
| 745 element.textContent = this.suggestions[i].description; |
| 746 element.url = this.suggestions[i].url; |
| 747 update.setVisible(true); |
| 748 } else { |
| 724 element.textContent = ''; | 749 element.textContent = ''; |
| 725 element.style.visibility = 'hidden'; | |
| 726 element.url = null; | 750 element.url = null; |
| 727 } else { | 751 update.setVisible(false); |
| 728 element.textContent = suggestions[i].description; | |
| 729 element.style.visibility = 'visible'; | |
| 730 element.url = suggestions[i].url; | |
| 731 } | 752 } |
| 753 ui.updateElement(this.suggestionUiElements[i].id, update); |
| 732 } | 754 } |
| 733 } | 755 } |
| 734 }; | 756 }; |
| 735 | 757 |
| 736 // Shows the open tabs. | 758 // Shows the open tabs. |
| 737 // | 759 // |
| 738 // The tab container is made of three <div> nesting levels. The first is the | 760 // The tab container is made of three <div> nesting levels. The first is the |
| 739 // tab container element, which acts like a scroll view. It has a fixed size | 761 // tab container element, which acts like a scroll view. It has a fixed size |
| 740 // and corresponds to a UI element in the scene. The second level is the clip | 762 // and corresponds to a UI element in the scene. The second level is the clip |
| 741 // element, which is programmatically set to the total width of all it's | 763 // element, which is programmatically set to the total width of all it's |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 nativeCommandHandler.handleCommand(dict); | 1093 nativeCommandHandler.handleCommand(dict); |
| 1072 } | 1094 } |
| 1073 | 1095 |
| 1074 return { | 1096 return { |
| 1075 initialize: initialize, | 1097 initialize: initialize, |
| 1076 command: command, | 1098 command: command, |
| 1077 }; | 1099 }; |
| 1078 })(); | 1100 })(); |
| 1079 | 1101 |
| 1080 window.addEventListener('load', vrShellUi.initialize); | 1102 window.addEventListener('load', vrShellUi.initialize); |
| OLD | NEW |