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 21 matching lines...) Expand all Loading... | |
| 32 /** @const */ this.SCREEN_RATIO = 16 / 9; | 32 /** @const */ this.SCREEN_RATIO = 16 / 9; |
| 33 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; | 33 /** @const */ this.BROWSING_SCREEN_DISTANCE = 2.0; |
| 34 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; | 34 /** @const */ this.FULLSCREEN_DISTANCE = 3.0; |
| 35 /** @const */ this.CSS_WIDTH_PIXELS = 960.0; | 35 /** @const */ this.CSS_WIDTH_PIXELS = 960.0; |
| 36 /** @const */ this.CSS_HEIGHT_PIXELS = 640.0; | 36 /** @const */ this.CSS_HEIGHT_PIXELS = 640.0; |
| 37 /** @const */ this.DPR = 1.2; | 37 /** @const */ this.DPR = 1.2; |
| 38 /** @const */ this.MENU_MODE_SCREEN_DISTANCE = 2.0; | 38 /** @const */ this.MENU_MODE_SCREEN_DISTANCE = 2.0; |
| 39 /** @const */ this.MENU_MODE_SCREEN_HEIGHT = 0.8; | 39 /** @const */ this.MENU_MODE_SCREEN_HEIGHT = 0.8; |
| 40 /** @const */ this.MENU_MODE_SCREEN_ELEVATION = 0.2; | 40 /** @const */ this.MENU_MODE_SCREEN_ELEVATION = 0.2; |
| 41 /** @const */ this.BACKGROUND_DISTANCE_MULTIPLIER = 1.414; | 41 /** @const */ this.BACKGROUND_DISTANCE_MULTIPLIER = 1.414; |
| 42 /** @const */ this.DOM_INTERCEPTOR_SELECTOR = '#content-interceptor'; | |
| 43 /** @const */ this.DOM_INTERCEPTOR_ELEVATION = 0.1; | |
|
cjgrant
2017/03/09 20:03:00
10 cm seems big, since this quad is like a skin ov
acondor_
2017/03/09 20:40:37
Done.
| |
| 42 | 44 |
| 43 this.menuMode = false; | 45 this.menuMode = false; |
| 44 this.fullscreen = false; | 46 this.fullscreen = false; |
| 45 | 47 |
| 46 let element = new api.UiElement(0, 0, 0, 0); | 48 let element = new api.UiElement(0, 0, 0, 0); |
| 47 element.setFill(new api.Content()); | 49 element.setFill(new api.Content()); |
| 48 element.setVisible(false); | 50 element.setVisible(false); |
| 49 element.setSize( | 51 element.setSize( |
| 50 this.SCREEN_HEIGHT * this.SCREEN_RATIO, this.SCREEN_HEIGHT); | 52 this.SCREEN_HEIGHT * this.SCREEN_RATIO, this.SCREEN_HEIGHT); |
| 51 element.setTranslation(0, 0, -this.BROWSING_SCREEN_DISTANCE); | 53 element.setTranslation(0, 0, -this.BROWSING_SCREEN_DISTANCE); |
| 52 this.elementId = ui.addElement(element); | 54 this.elementId = ui.addElement(element); |
| 53 | 55 |
| 54 // Place an invisible (fill none) but hittable plane behind the content | 56 // Place an invisible (fill none) but hittable plane behind the content |
| 55 // quad, to keep the reticle roughly planar with the content if near | 57 // quad, to keep the reticle roughly planar with the content if near |
| 56 // content. | 58 // content. |
| 57 let backPlane = new api.UiElement(0, 0, 0, 0); | 59 let backPlane = new api.UiElement(0, 0, 0, 0); |
| 58 backPlane.setSize(1000, 1000); | 60 backPlane.setSize(1000, 1000); |
| 59 backPlane.setTranslation(0, 0, -0.01); | 61 backPlane.setTranslation(0, 0, -0.01); |
| 60 backPlane.setParentId(this.elementId); | 62 backPlane.setParentId(this.elementId); |
| 61 backPlane.setFill(new api.NoFill()); | 63 backPlane.setFill(new api.NoFill()); |
| 62 ui.addElement(backPlane); | 64 ui.addElement(backPlane); |
| 63 | 65 |
| 66 // Place invisible plane on top of content quad, to intercept the clicks | |
| 67 // while on menu mode in order to exit it. | |
|
cjgrant
2017/03/09 20:03:00
optional: 'in order to exit it' - you could leave
acondor_
2017/03/09 20:40:38
Done.
| |
| 68 this.interceptor = new DomUiElement(this.DOM_INTERCEPTOR_SELECTOR); | |
| 69 let interceptorUpdate = new api.UiElementUpdate(); | |
|
cjgrant
2017/03/09 20:03:00
'let update' = is sufficient, or you could reuse a
acondor_
2017/03/09 20:40:37
Done.
| |
| 70 interceptorUpdate.setTranslation(0, 0, this.DOM_INTERCEPTOR_ELEVATION); | |
| 71 interceptorUpdate.setVisible(false); | |
| 72 interceptorUpdate.setParentId(this.elementId); | |
| 73 interceptorUpdate.setSize( | |
| 74 this.MENU_MODE_SCREEN_HEIGHT * this.SCREEN_RATIO, | |
| 75 this.MENU_MODE_SCREEN_HEIGHT); | |
| 76 ui.updateElement(this.interceptor.id, interceptorUpdate); | |
| 77 let interceptorButton = | |
| 78 document.querySelector(this.DOM_INTERCEPTOR_SELECTOR); | |
| 79 interceptorButton.addEventListener('click', function() { | |
| 80 uiManager.exitMenuMode(); | |
| 81 ui.flush(); | |
| 82 }); | |
| 83 | |
| 64 this.updateState(); | 84 this.updateState(); |
| 65 } | 85 } |
| 66 | 86 |
| 67 setEnabled(enabled) { | 87 setEnabled(enabled) { |
| 68 let update = new api.UiElementUpdate(); | 88 let update = new api.UiElementUpdate(); |
| 69 update.setVisible(enabled); | 89 update.setVisible(enabled); |
| 70 ui.updateElement(this.elementId, update); | 90 ui.updateElement(this.elementId, update); |
| 71 if (enabled) { | 91 if (enabled) { |
| 72 api.setContentCssSize( | 92 api.setContentCssSize( |
| 73 this.CSS_WIDTH_PIXELS, this.CSS_HEIGHT_PIXELS, this.DPR); | 93 this.CSS_WIDTH_PIXELS, this.CSS_HEIGHT_PIXELS, this.DPR); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 99 | 119 |
| 100 // Mode-specific overrides. | 120 // Mode-specific overrides. |
| 101 if (this.menuMode) { | 121 if (this.menuMode) { |
| 102 y = this.MENU_MODE_SCREEN_ELEVATION; | 122 y = this.MENU_MODE_SCREEN_ELEVATION; |
| 103 distance = this.MENU_MODE_SCREEN_DISTANCE; | 123 distance = this.MENU_MODE_SCREEN_DISTANCE; |
| 104 height = this.MENU_MODE_SCREEN_HEIGHT; | 124 height = this.MENU_MODE_SCREEN_HEIGHT; |
| 105 } else if (this.fullscreen) { | 125 } else if (this.fullscreen) { |
| 106 distance = this.FULLSCREEN_DISTANCE; | 126 distance = this.FULLSCREEN_DISTANCE; |
| 107 } | 127 } |
| 108 | 128 |
| 129 // show/hide the interceptor. | |
|
cjgrant
2017/03/09 20:03:00
Comments should always be full sentences, ie "// S
acondor_
2017/03/09 20:40:38
Done.
| |
| 130 let interceptorUpdate = new api.UiElementUpdate(); | |
|
cjgrant
2017/03/09 20:03:00
'let update' = or 'update =' is cool here too (m
acondor_
2017/03/09 20:40:37
Done.
| |
| 131 interceptorUpdate.setVisible(this.menuMode); | |
| 132 ui.updateElement(this.interceptor.id, interceptorUpdate); | |
| 133 | |
| 109 let anim; | 134 let anim; |
| 110 anim = new api.Animation(this.elementId, ANIM_DURATION); | 135 anim = new api.Animation(this.elementId, ANIM_DURATION); |
| 111 anim.setTranslation(0, y, -distance); | 136 anim.setTranslation(0, y, -distance); |
| 112 anim.setEasing(new api.InOutEasing()); | 137 anim.setEasing(new api.InOutEasing()); |
| 113 ui.addAnimation(anim); | 138 ui.addAnimation(anim); |
| 114 anim = new api.Animation(this.elementId, ANIM_DURATION); | 139 anim = new api.Animation(this.elementId, ANIM_DURATION); |
| 115 anim.setSize(height * this.SCREEN_RATIO, height); | 140 anim.setSize(height * this.SCREEN_RATIO, height); |
| 116 anim.setEasing(new api.InOutEasing()); | 141 anim.setEasing(new api.InOutEasing()); |
| 117 ui.addAnimation(anim); | 142 ui.addAnimation(anim); |
| 118 | 143 |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 931 setFullscreen(fullscreen) { | 956 setFullscreen(fullscreen) { |
| 932 this.fullscreen = fullscreen; | 957 this.fullscreen = fullscreen; |
| 933 this.updateState(); | 958 this.updateState(); |
| 934 } | 959 } |
| 935 | 960 |
| 936 handleAppButtonClicked() { | 961 handleAppButtonClicked() { |
| 937 this.menuMode = !this.menuMode; | 962 this.menuMode = !this.menuMode; |
| 938 this.updateState(); | 963 this.updateState(); |
| 939 } | 964 } |
| 940 | 965 |
| 966 exitMenuMode() { | |
| 967 if (this.menuMode) { | |
| 968 this.menuMode = false; | |
| 969 this.updateState(); | |
| 970 } | |
| 971 } | |
| 972 | |
| 941 updateState() { | 973 updateState() { |
| 942 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; | 974 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; |
| 943 | 975 |
| 944 let mode = this.mode; | 976 let mode = this.mode; |
| 945 let menuMode = this.menuMode; | 977 let menuMode = this.menuMode; |
| 946 let fullscreen = this.fullscreen; | 978 let fullscreen = this.fullscreen; |
| 947 | 979 |
| 948 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); | 980 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); |
| 949 | 981 |
| 950 this.contentQuad.setEnabled(mode == api.Mode.STANDARD); | 982 this.contentQuad.setEnabled(mode == api.Mode.STANDARD); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 nativeCommandHandler.handleCommand(dict); | 1103 nativeCommandHandler.handleCommand(dict); |
| 1072 } | 1104 } |
| 1073 | 1105 |
| 1074 return { | 1106 return { |
| 1075 initialize: initialize, | 1107 initialize: initialize, |
| 1076 command: command, | 1108 command: command, |
| 1077 }; | 1109 }; |
| 1078 })(); | 1110 })(); |
| 1079 | 1111 |
| 1080 window.addEventListener('load', vrShellUi.initialize); | 1112 window.addEventListener('load', vrShellUi.initialize); |
| OLD | NEW |