Chromium Code Reviews| 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 update.setTranslation(0, elem.sizeY * (i + 0.5), 0); | |
|
mthiesse
2017/03/09 20:02:34
nit: add a comment explaining 0.5
cjgrant
2017/03/09 20:15:16
Done.
| |
| 716 ui.updateElement(elem.id, update); | |
| 706 } | 717 } |
| 718 this.setSuggestions([]); | |
| 707 } | 719 } |
| 708 | 720 |
| 709 setEnabled(enabled) { | 721 setEnabled(enabled) { |
| 710 this.enabled = enabled; | 722 this.enabled = enabled; |
| 711 let update = new api.UiElementUpdate(); | 723 let update = new api.UiElementUpdate(); |
| 712 update.setVisible(enabled); | 724 update.setVisible(enabled); |
| 713 ui.updateElement(this.domUiElement.id, update); | 725 ui.updateElement(this.domUiElement.id, update); |
| 726 this.updateSuggestions(); | |
| 714 } | 727 } |
| 715 | 728 |
| 716 setURL(url) { | 729 setURL(url) { |
| 717 this.inputField.value = url; | 730 this.inputField.value = url; |
| 718 } | 731 } |
| 719 | 732 |
| 720 setSuggestions(suggestions) { | 733 setSuggestions(suggestions) { |
| 734 this.suggestions = suggestions; | |
| 735 this.updateSuggestions(); | |
| 736 } | |
| 737 | |
| 738 updateSuggestions() { | |
| 721 for (var i = 0; i < this.maxSuggestions; i++) { | 739 for (var i = 0; i < this.maxSuggestions; i++) { |
| 722 let element = document.querySelector('#suggestion-' + i); | 740 let element = document.querySelector('#suggestion-' + i); |
| 723 if (i >= suggestions.length) { | 741 let update = new api.UiElementUpdate(); |
| 742 if (this.enabled && i < this.suggestions.length) { | |
| 743 element.textContent = this.suggestions[i].description; | |
| 744 element.url = this.suggestions[i].url; | |
| 745 update.setVisible(true); | |
| 746 } else { | |
| 724 element.textContent = ''; | 747 element.textContent = ''; |
| 725 element.style.visibility = 'hidden'; | |
| 726 element.url = null; | 748 element.url = null; |
| 727 } else { | 749 update.setVisible(false); |
| 728 element.textContent = suggestions[i].description; | |
| 729 element.style.visibility = 'visible'; | |
| 730 element.url = suggestions[i].url; | |
| 731 } | 750 } |
| 751 ui.updateElement(this.suggestionUiElements[i].id, update); | |
| 732 } | 752 } |
| 733 } | 753 } |
| 734 }; | 754 }; |
| 735 | 755 |
| 736 // Shows the open tabs. | 756 // Shows the open tabs. |
| 737 // | 757 // |
| 738 // The tab container is made of three <div> nesting levels. The first is the | 758 // 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 | 759 // 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 | 760 // 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 | 761 // 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); | 1091 nativeCommandHandler.handleCommand(dict); |
| 1072 } | 1092 } |
| 1073 | 1093 |
| 1074 return { | 1094 return { |
| 1075 initialize: initialize, | 1095 initialize: initialize, |
| 1076 command: command, | 1096 command: command, |
| 1077 }; | 1097 }; |
| 1078 })(); | 1098 })(); |
| 1079 | 1099 |
| 1080 window.addEventListener('load', vrShellUi.initialize); | 1100 window.addEventListener('load', vrShellUi.initialize); |
| OLD | NEW |