Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Side by Side Diff: chrome/browser/resources/vr_shell/vr_shell_ui.js

Issue 2735983004: Visually disable VR Shell back/forward buttons when no history is available (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 this.id = ui.addElement(element); 154 this.id = ui.addElement(element);
155 this.domElement = domElement; 155 this.domElement = domElement;
156 } 156 }
157 }; 157 };
158 158
159 class Button { 159 class Button {
160 constructor(domId, callback, parentId) { 160 constructor(domId, callback, parentId) {
161 let captionId = domId + '-caption'; 161 let captionId = domId + '-caption';
162 this.button = document.querySelector(domId); 162 this.button = document.querySelector(domId);
163 this.caption = document.querySelector(captionId); 163 this.caption = document.querySelector(captionId);
164 this.enabled = true;
164 165
165 // Create an invisible parent, from which the button will hover. 166 // Create an invisible parent, from which the button will hover.
166 let backing = new api.UiElement(0, 0, 0, 0); 167 let backing = new api.UiElement(0, 0, 0, 0);
167 backing.setParentId(parentId); 168 backing.setParentId(parentId);
168 backing.setVisible(false); 169 backing.setVisible(false);
169 this.backingElementId = ui.addElement(backing); 170 this.backingElementId = ui.addElement(backing);
170 171
171 this.buttonElement = new DomUiElement(domId); 172 this.buttonElement = new DomUiElement(domId);
172 let update = new api.UiElementUpdate(); 173 let update = new api.UiElementUpdate();
173 update.setParentId(this.backingElementId); 174 update.setParentId(this.backingElementId);
174 ui.updateElement(this.buttonElement.id, update); 175 ui.updateElement(this.buttonElement.id, update);
175 176
176 this.captionElement = new DomUiElement(captionId); 177 this.captionElement = new DomUiElement(captionId);
177 update = new api.UiElementUpdate(); 178 update = new api.UiElementUpdate();
178 update.setParentId(this.buttonElement.id); 179 update.setParentId(this.buttonElement.id);
179 update.setTranslation(0, -this.captionElement.sizeY / 2, 0); 180 update.setTranslation(0, -this.captionElement.sizeY / 2, 0);
180 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); 181 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM);
181 ui.updateElement(this.captionElement.id, update); 182 ui.updateElement(this.captionElement.id, update);
182 183
183 this.button.addEventListener('mouseenter', this.onMouseEnter.bind(this)); 184 this.button.addEventListener('mouseenter', this.onMouseEnter.bind(this));
184 this.button.addEventListener('mouseleave', this.onMouseLeave.bind(this)); 185 this.button.addEventListener('mouseleave', this.onMouseLeave.bind(this));
185 this.button.addEventListener('click', callback); 186 this.button.addEventListener('click', callback);
mthiesse 2017/03/08 16:25:07 We should also store this callback and add/remove
mthiesse 2017/03/08 19:40:37 I think you missed this comment?
acondor_ 2017/03/08 20:21:39 Done.
186 } 187 }
187 188
188 setTranslation(x, y, z) { 189 setTranslation(x, y, z) {
189 let update = new api.UiElementUpdate(); 190 let update = new api.UiElementUpdate();
190 update.setTranslation(x, y, z); 191 update.setTranslation(x, y, z);
191 ui.updateElement(this.backingElementId, update); 192 ui.updateElement(this.backingElementId, update);
192 } 193 }
193 194
194 setVisible(visible) { 195 setVisible(visible) {
195 let update = new api.UiElementUpdate(); 196 let update = new api.UiElementUpdate();
196 update.setVisible(visible); 197 update.setVisible(visible);
197 ui.updateElement(this.buttonElement.id, update); 198 ui.updateElement(this.buttonElement.id, update);
198 update = new api.UiElementUpdate(); 199 update = new api.UiElementUpdate();
199 update.setVisible(visible); 200 update.setVisible(visible);
200 ui.updateElement(this.captionElement.id, update); 201 ui.updateElement(this.captionElement.id, update);
201 } 202 }
202 203
204 setEnabled(enabled) {
205 this.enabled = enabled;
206 if (enabled) {
207 this.button.classList.remove('disabled-button');
208 } else {
209 this.button.classList.add('disabled-button');
210 }
211 }
212
203 configure(buttonOpacity, captionOpacity, distanceForward) { 213 configure(buttonOpacity, captionOpacity, distanceForward) {
204 this.button.style.opacity = buttonOpacity; 214 this.button.style.opacity = buttonOpacity;
205 this.caption.style.opacity = captionOpacity; 215 this.caption.style.opacity = captionOpacity;
206 216
207 let anim = new api.Animation(this.buttonElement.id, ANIM_DURATION); 217 let anim = new api.Animation(this.buttonElement.id, ANIM_DURATION);
208 anim.setTranslation(0, 0, distanceForward); 218 anim.setTranslation(0, 0, distanceForward);
209 ui.addAnimation(anim); 219 ui.addAnimation(anim);
210 ui.flush(); 220 ui.flush();
211 } 221 }
212 222
213 onMouseEnter() { 223 onMouseEnter() {
214 this.configure(1, 1, 0.015); 224 if (this.enabled) {
225 this.configure(1, 1, 0.015);
226 }
215 } 227 }
216 228
217 onMouseLeave() { 229 onMouseLeave() {
218 this.configure(0.8, 0, 0); 230 this.configure(0.8, 0, 0);
219 } 231 }
220 }; 232 };
221 233
222 class Controls { 234 class Controls {
223 constructor(contentQuadId) { 235 constructor(contentQuadId) {
224 this.enabled = false; 236 this.enabled = false;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 setEnabled(enabled) { 280 setEnabled(enabled) {
269 this.enabled = enabled; 281 this.enabled = enabled;
270 this.configure(); 282 this.configure();
271 } 283 }
272 284
273 configure() { 285 configure() {
274 for (let i = 0; i < this.buttons.length; i++) { 286 for (let i = 0; i < this.buttons.length; i++) {
275 this.buttons[i].setVisible(this.enabled); 287 this.buttons[i].setVisible(this.enabled);
276 } 288 }
277 } 289 }
290
291 setBackButtonEnabled(enabled) {
292 this.buttons[0].setEnabled(enabled);
cjgrant 2017/03/08 16:32:14 This indexing looks a bit risky. Anyone could reo
amp 2017/03/08 16:34:14 These hard coded indexes seem fragile if we ever h
acondor_ 2017/03/08 16:42:26 I agree with the fact that it's risky and the sugg
cjgrant 2017/03/08 18:19:32 The array was used only as a convenience for posit
293 }
294
295 setForwardButtonEnabled(enabled) {
296 this.buttons[2].setEnabled(enabled);
297 }
278 }; 298 };
279 299
280 /** 300 /**
281 * A button to trigger a reload of the HTML UI for development purposes. 301 * A button to trigger a reload of the HTML UI for development purposes.
282 */ 302 */
283 class ReloadUiButton { 303 class ReloadUiButton {
284 constructor() { 304 constructor() {
285 this.enabled = false; 305 this.enabled = false;
286 this.devMode = false; 306 this.devMode = false;
287 307
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 anim.setScale(scale, scale, scale); 923 anim.setScale(scale, scale, scale);
904 ui.addAnimation(anim); 924 ui.addAnimation(anim);
905 } 925 }
906 }; 926 };
907 927
908 class UiManager { 928 class UiManager {
909 constructor() { 929 constructor() {
910 this.mode = api.Mode.UNKNOWN; 930 this.mode = api.Mode.UNKNOWN;
911 this.menuMode = false; 931 this.menuMode = false;
912 this.fullscreen = false; 932 this.fullscreen = false;
933 this.canGoBack = false;
934 this.canGoForward = false;
913 935
914 this.background = new Background(); 936 this.background = new Background();
915 this.contentQuad = new ContentQuad(); 937 this.contentQuad = new ContentQuad();
916 let contentId = this.contentQuad.getElementId(); 938 let contentId = this.contentQuad.getElementId();
917 939
918 this.controls = new Controls(contentId); 940 this.controls = new Controls(contentId);
919 this.secureOriginWarnings = new SecureOriginWarnings(); 941 this.secureOriginWarnings = new SecureOriginWarnings();
920 this.urlIndicator = new UrlIndicator(); 942 this.urlIndicator = new UrlIndicator();
921 this.omnibox = new Omnibox(); 943 this.omnibox = new Omnibox();
922 this.reloadUiButton = new ReloadUiButton(); 944 this.reloadUiButton = new ReloadUiButton();
923 this.tabContainer = new TabContainer(contentId); 945 this.tabContainer = new TabContainer(contentId);
924 this.keyboard = new VirtualKeyboard(contentId); 946 this.keyboard = new VirtualKeyboard(contentId);
925 } 947 }
926 948
927 setMode(mode) { 949 setMode(mode) {
928 this.mode = mode; 950 this.mode = mode;
929 this.updateState(); 951 this.updateState();
930 } 952 }
931 953
932 setFullscreen(fullscreen) { 954 setFullscreen(fullscreen) {
933 this.fullscreen = fullscreen; 955 this.fullscreen = fullscreen;
934 this.updateState(); 956 this.updateState();
935 } 957 }
936 958
937 handleAppButtonClicked() { 959 handleAppButtonClicked() {
938 this.menuMode = !this.menuMode; 960 this.menuMode = !this.menuMode;
939 this.updateState(); 961 this.updateState();
940 } 962 }
941 963
964 setHistoryButtonsEnabled(canGoBack, canGoForward) {
965 this.canGoBack = canGoBack;
966 this.canGoForward = canGoForward;
967 this.updateState();
968 }
969
942 updateState() { 970 updateState() {
943 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; 971 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000;
944 972
945 let mode = this.mode; 973 let mode = this.mode;
946 let menuMode = this.menuMode; 974 let menuMode = this.menuMode;
947 let fullscreen = this.fullscreen; 975 let fullscreen = this.fullscreen;
948 976
949 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); 977 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode});
950 978
951 this.contentQuad.setEnabled(mode == api.Mode.STANDARD); 979 this.contentQuad.setEnabled(mode == api.Mode.STANDARD);
952 this.contentQuad.setFullscreen(fullscreen); 980 this.contentQuad.setFullscreen(fullscreen);
953 this.contentQuad.setMenuMode(menuMode); 981 this.contentQuad.setMenuMode(menuMode);
954 // TODO(crbug/643815): Set aspect ratio on content quad when available. 982 // TODO(crbug/643815): Set aspect ratio on content quad when available.
955 this.controls.setEnabled(menuMode); 983 this.controls.setEnabled(menuMode);
984 this.controls.setBackButtonEnabled(this.canGoBack);
mthiesse 2017/03/08 16:15:18 This breaks fullscreen exit doesn't it? I think yo
amp 2017/03/08 16:34:14 +1. I was going to ask about this. Note that reg
acondor_ 2017/03/08 16:42:26 Done.
mthiesse 2017/03/08 19:38:16 mTab.canGoBack() does not cover the fullscreen cas
985 this.controls.setForwardButtonEnabled(this.canGoForward);
956 this.omnibox.setEnabled(menuMode); 986 this.omnibox.setEnabled(menuMode);
957 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); 987 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode);
958 this.urlIndicator.setVisibilityTimeout( 988 this.urlIndicator.setVisibilityTimeout(
959 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); 989 URL_INDICATOR_VISIBILITY_TIMEOUT_MS);
960 this.secureOriginWarnings.setEnabled( 990 this.secureOriginWarnings.setEnabled(
961 mode == api.Mode.WEB_VR && !menuMode); 991 mode == api.Mode.WEB_VR && !menuMode);
962 this.background.setState(mode, menuMode, fullscreen); 992 this.background.setState(mode, menuMode, fullscreen);
963 this.tabContainer.setEnabled(mode == api.Mode.STANDARD && menuMode); 993 this.tabContainer.setEnabled(mode == api.Mode.STANDARD && menuMode);
964 994
965 this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD); 995 this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 uiManager.tabContainer.addTab(tab); 1086 uiManager.tabContainer.addTab(tab);
1057 } 1087 }
1058 } 1088 }
1059 1089
1060 /** @override */ 1090 /** @override */
1061 onRemoveTab(tab) { 1091 onRemoveTab(tab) {
1062 uiManager.tabContainer.removeTab(tab); 1092 uiManager.tabContainer.removeTab(tab);
1063 } 1093 }
1064 1094
1065 /** @override */ 1095 /** @override */
1096 onSetHistoryButtonsEnabled(canGoBack, canGoForward) {
1097 uiManager.setHistoryButtonsEnabled(canGoBack, canGoForward);
1098 }
1099
1100 /** @override */
1066 onCommandHandlerFinished() { 1101 onCommandHandlerFinished() {
1067 ui.flush(); 1102 ui.flush();
1068 } 1103 }
1069 } 1104 }
1070 1105
1071 function command(dict) { 1106 function command(dict) {
1072 nativeCommandHandler.handleCommand(dict); 1107 nativeCommandHandler.handleCommand(dict);
1073 } 1108 }
1074 1109
1075 return { 1110 return {
1076 initialize: initialize, 1111 initialize: initialize,
1077 command: command, 1112 command: command,
1078 }; 1113 };
1079 })(); 1114 })();
1080 1115
1081 window.addEventListener('load', vrShellUi.initialize); 1116 window.addEventListener('load', vrShellUi.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698