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

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: Addressing closure compilation error 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.callback = callback;
165 this.enabled = true;
164 166
165 // Create an invisible parent, from which the button will hover. 167 // Create an invisible parent, from which the button will hover.
166 let backing = new api.UiElement(0, 0, 0, 0); 168 let backing = new api.UiElement(0, 0, 0, 0);
167 backing.setParentId(parentId); 169 backing.setParentId(parentId);
168 backing.setVisible(false); 170 backing.setVisible(false);
169 this.backingElementId = ui.addElement(backing); 171 this.backingElementId = ui.addElement(backing);
170 172
171 this.buttonElement = new DomUiElement(domId); 173 this.buttonElement = new DomUiElement(domId);
172 let update = new api.UiElementUpdate(); 174 let update = new api.UiElementUpdate();
173 update.setParentId(this.backingElementId); 175 update.setParentId(this.backingElementId);
174 ui.updateElement(this.buttonElement.id, update); 176 ui.updateElement(this.buttonElement.id, update);
175 177
176 this.captionElement = new DomUiElement(captionId); 178 this.captionElement = new DomUiElement(captionId);
177 update = new api.UiElementUpdate(); 179 update = new api.UiElementUpdate();
178 update.setParentId(this.buttonElement.id); 180 update.setParentId(this.buttonElement.id);
179 update.setTranslation(0, -this.captionElement.sizeY / 2, 0); 181 update.setTranslation(0, -this.captionElement.sizeY / 2, 0);
180 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); 182 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM);
181 ui.updateElement(this.captionElement.id, update); 183 ui.updateElement(this.captionElement.id, update);
182 184
183 this.button.addEventListener('mouseenter', this.onMouseEnter.bind(this)); 185 this.button.addEventListener('mouseenter', this.onMouseEnter.bind(this));
184 this.button.addEventListener('mouseleave', this.onMouseLeave.bind(this)); 186 this.button.addEventListener('mouseleave', this.onMouseLeave.bind(this));
185 this.button.addEventListener('click', callback); 187 this.button.addEventListener('click', this.callback);
186 } 188 }
187 189
188 setTranslation(x, y, z) { 190 setTranslation(x, y, z) {
189 let update = new api.UiElementUpdate(); 191 let update = new api.UiElementUpdate();
190 update.setTranslation(x, y, z); 192 update.setTranslation(x, y, z);
191 ui.updateElement(this.backingElementId, update); 193 ui.updateElement(this.backingElementId, update);
192 } 194 }
193 195
194 setVisible(visible) { 196 setVisible(visible) {
195 let update = new api.UiElementUpdate(); 197 let update = new api.UiElementUpdate();
196 update.setVisible(visible); 198 update.setVisible(visible);
197 ui.updateElement(this.buttonElement.id, update); 199 ui.updateElement(this.buttonElement.id, update);
198 update = new api.UiElementUpdate(); 200 update = new api.UiElementUpdate();
199 update.setVisible(visible); 201 update.setVisible(visible);
200 ui.updateElement(this.captionElement.id, update); 202 ui.updateElement(this.captionElement.id, update);
201 } 203 }
202 204
205 setEnabled(enabled) {
206 this.enabled = enabled;
207 if (enabled) {
208 this.button.classList.remove('disabled-button');
209 this.button.addEventListener('click', this.callback);
210 } else {
211 this.button.classList.add('disabled-button');
212 this.button.removeEventListener('click', this.callback);
213 }
214 }
215
203 configure(buttonOpacity, captionOpacity, distanceForward) { 216 configure(buttonOpacity, captionOpacity, distanceForward) {
204 this.button.style.opacity = buttonOpacity; 217 this.button.style.opacity = buttonOpacity;
205 this.caption.style.opacity = captionOpacity; 218 this.caption.style.opacity = captionOpacity;
206 219
207 let anim = new api.Animation(this.buttonElement.id, ANIM_DURATION); 220 let anim = new api.Animation(this.buttonElement.id, ANIM_DURATION);
208 anim.setTranslation(0, 0, distanceForward); 221 anim.setTranslation(0, 0, distanceForward);
209 ui.addAnimation(anim); 222 ui.addAnimation(anim);
210 ui.flush(); 223 ui.flush();
211 } 224 }
212 225
213 onMouseEnter() { 226 onMouseEnter() {
214 this.configure(1, 1, 0.015); 227 if (this.enabled) {
228 this.configure(1, 1, 0.015);
229 }
215 } 230 }
216 231
217 onMouseLeave() { 232 onMouseLeave() {
218 this.configure(0.8, 0, 0); 233 this.configure(0.8, 0, 0);
219 } 234 }
220 }; 235 };
221 236
222 class Controls { 237 class Controls {
223 constructor(contentQuadId) { 238 constructor(contentQuadId) {
224 this.enabled = false; 239 this.enabled = false;
225 240
226 this.buttons = []; 241 this.buttons = {
242 backButton: null,
243 reloadButton: null,
244 forwardButton: null
245 };
227 let descriptors = [ 246 let descriptors = [
228 [ 247 [
229 '#back-button', 248 'backButton', '#back-button',
230 function() { 249 function() {
231 api.doAction(api.Action.HISTORY_BACK, {}); 250 api.doAction(api.Action.HISTORY_BACK, {});
232 } 251 }
233 ], 252 ],
234 [ 253 [
235 '#reload-button', 254 'reloadButton', '#reload-button',
236 function() { 255 function() {
237 api.doAction(api.Action.RELOAD, {}); 256 api.doAction(api.Action.RELOAD, {});
238 } 257 }
239 ], 258 ],
240 [ 259 [
241 '#forward-button', 260 'forwardButton', '#forward-button',
242 function() { 261 function() {
243 api.doAction(api.Action.HISTORY_FORWARD, {}); 262 api.doAction(api.Action.HISTORY_FORWARD, {});
244 } 263 }
245 ], 264 ],
246 ]; 265 ];
247 266
248 /** @const */ var BUTTON_Y = -0.27; 267 /** @const */ var BUTTON_Y = -0.27;
249 /** @const */ var BUTTON_Z = -1; 268 /** @const */ var BUTTON_Z = -1;
250 /** @const */ var BUTTON_SPACING = 0.11; 269 /** @const */ var BUTTON_SPACING = 0.11;
251 270
252 let controls = new api.UiElement(0, 0, 0, 0); 271 let controls = new api.UiElement(0, 0, 0, 0);
253 controls.setVisible(false); 272 controls.setVisible(false);
254 controls.setTranslation(0, BUTTON_Y, BUTTON_Z); 273 controls.setTranslation(0, BUTTON_Y, BUTTON_Z);
255 this.controlsId = ui.addElement(controls); 274 this.controlsId = ui.addElement(controls);
256 275
257 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 276 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5);
258 277
259 for (let i = 0; i < descriptors.length; i++) { 278 for (let i = 0; i < descriptors.length; i++) {
260 let domId = descriptors[i][0]; 279 let name = descriptors[i][0];
261 let callback = descriptors[i][1]; 280 let domId = descriptors[i][1];
281 let callback = descriptors[i][2];
262 let button = new Button(domId, callback, this.controlsId); 282 let button = new Button(domId, callback, this.controlsId);
263 button.setTranslation(startPosition + i * BUTTON_SPACING, 0, 0); 283 button.setTranslation(startPosition + i * BUTTON_SPACING, 0, 0);
264 this.buttons.push(button); 284 this.buttons[name] = button;
265 } 285 }
266 } 286 }
267 287
268 setEnabled(enabled) { 288 setEnabled(enabled) {
269 this.enabled = enabled; 289 this.enabled = enabled;
270 this.configure(); 290 this.configure();
271 } 291 }
272 292
273 configure() { 293 configure() {
274 for (let i = 0; i < this.buttons.length; i++) { 294 for (let key in this.buttons) {
275 this.buttons[i].setVisible(this.enabled); 295 this.buttons[key].setVisible(this.enabled);
276 } 296 }
277 } 297 }
298
299 setBackButtonEnabled(enabled) {
300 this.buttons.backButton.setEnabled(enabled);
301 }
302
303 setForwardButtonEnabled(enabled) {
304 this.buttons.forwardButton.setEnabled(enabled);
305 }
278 }; 306 };
279 307
280 /** 308 /**
281 * A button to trigger a reload of the HTML UI for development purposes. 309 * A button to trigger a reload of the HTML UI for development purposes.
282 */ 310 */
283 class ReloadUiButton { 311 class ReloadUiButton {
284 constructor() { 312 constructor() {
285 this.enabled = false; 313 this.enabled = false;
286 this.devMode = false; 314 this.devMode = false;
287 315
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 anim.setScale(scale, scale, scale); 931 anim.setScale(scale, scale, scale);
904 ui.addAnimation(anim); 932 ui.addAnimation(anim);
905 } 933 }
906 }; 934 };
907 935
908 class UiManager { 936 class UiManager {
909 constructor() { 937 constructor() {
910 this.mode = api.Mode.UNKNOWN; 938 this.mode = api.Mode.UNKNOWN;
911 this.menuMode = false; 939 this.menuMode = false;
912 this.fullscreen = false; 940 this.fullscreen = false;
941 this.canGoBack = false;
942 this.canGoForward = false;
913 943
914 this.background = new Background(); 944 this.background = new Background();
915 this.contentQuad = new ContentQuad(); 945 this.contentQuad = new ContentQuad();
916 let contentId = this.contentQuad.getElementId(); 946 let contentId = this.contentQuad.getElementId();
917 947
918 this.controls = new Controls(contentId); 948 this.controls = new Controls(contentId);
919 this.secureOriginWarnings = new SecureOriginWarnings(); 949 this.secureOriginWarnings = new SecureOriginWarnings();
920 this.urlIndicator = new UrlIndicator(); 950 this.urlIndicator = new UrlIndicator();
921 this.omnibox = new Omnibox(); 951 this.omnibox = new Omnibox();
922 this.reloadUiButton = new ReloadUiButton(); 952 this.reloadUiButton = new ReloadUiButton();
923 this.tabContainer = new TabContainer(contentId); 953 this.tabContainer = new TabContainer(contentId);
924 this.keyboard = new VirtualKeyboard(contentId); 954 this.keyboard = new VirtualKeyboard(contentId);
925 } 955 }
926 956
927 setMode(mode) { 957 setMode(mode) {
928 this.mode = mode; 958 this.mode = mode;
929 this.updateState(); 959 this.updateState();
930 } 960 }
931 961
932 setFullscreen(fullscreen) { 962 setFullscreen(fullscreen) {
933 this.fullscreen = fullscreen; 963 this.fullscreen = fullscreen;
934 this.updateState(); 964 this.updateState();
935 } 965 }
936 966
937 handleAppButtonClicked() { 967 handleAppButtonClicked() {
938 this.menuMode = !this.menuMode; 968 this.menuMode = !this.menuMode;
939 this.updateState(); 969 this.updateState();
940 } 970 }
941 971
972 setHistoryButtonsEnabled(canGoBack, canGoForward) {
973 this.canGoBack = canGoBack;
974 this.canGoForward = canGoForward;
975
976 /** No need to call updateState to adjust button properties. */
977 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen);
978 this.controls.setForwardButtonEnabled(this.canGoForward);
979 }
980
942 updateState() { 981 updateState() {
943 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; 982 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000;
944 983
945 let mode = this.mode; 984 let mode = this.mode;
946 let menuMode = this.menuMode; 985 let menuMode = this.menuMode;
947 let fullscreen = this.fullscreen; 986 let fullscreen = this.fullscreen;
948 987
949 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); 988 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode});
950 989
951 this.contentQuad.setEnabled(mode == api.Mode.STANDARD); 990 this.contentQuad.setEnabled(mode == api.Mode.STANDARD);
952 this.contentQuad.setFullscreen(fullscreen); 991 this.contentQuad.setFullscreen(fullscreen);
953 this.contentQuad.setMenuMode(menuMode); 992 this.contentQuad.setMenuMode(menuMode);
954 // TODO(crbug/643815): Set aspect ratio on content quad when available. 993 // TODO(crbug/643815): Set aspect ratio on content quad when available.
955 this.controls.setEnabled(menuMode); 994 this.controls.setEnabled(menuMode);
995 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen);
996 this.controls.setForwardButtonEnabled(this.canGoForward);
956 this.omnibox.setEnabled(menuMode); 997 this.omnibox.setEnabled(menuMode);
957 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); 998 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode);
958 this.urlIndicator.setVisibilityTimeout( 999 this.urlIndicator.setVisibilityTimeout(
959 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); 1000 URL_INDICATOR_VISIBILITY_TIMEOUT_MS);
960 this.secureOriginWarnings.setEnabled( 1001 this.secureOriginWarnings.setEnabled(
961 mode == api.Mode.WEB_VR && !menuMode); 1002 mode == api.Mode.WEB_VR && !menuMode);
962 this.background.setState(mode, menuMode, fullscreen); 1003 this.background.setState(mode, menuMode, fullscreen);
963 this.tabContainer.setEnabled(mode == api.Mode.STANDARD && menuMode); 1004 this.tabContainer.setEnabled(mode == api.Mode.STANDARD && menuMode);
964 1005
965 this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD); 1006 this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 uiManager.tabContainer.addTab(tab); 1097 uiManager.tabContainer.addTab(tab);
1057 } 1098 }
1058 } 1099 }
1059 1100
1060 /** @override */ 1101 /** @override */
1061 onRemoveTab(tab) { 1102 onRemoveTab(tab) {
1062 uiManager.tabContainer.removeTab(tab); 1103 uiManager.tabContainer.removeTab(tab);
1063 } 1104 }
1064 1105
1065 /** @override */ 1106 /** @override */
1107 onSetHistoryButtonsEnabled(canGoBack, canGoForward) {
1108 uiManager.setHistoryButtonsEnabled(canGoBack, canGoForward);
1109 }
1110
1111 /** @override */
1066 onCommandHandlerFinished() { 1112 onCommandHandlerFinished() {
1067 ui.flush(); 1113 ui.flush();
1068 } 1114 }
1069 } 1115 }
1070 1116
1071 function command(dict) { 1117 function command(dict) {
1072 nativeCommandHandler.handleCommand(dict); 1118 nativeCommandHandler.handleCommand(dict);
1073 } 1119 }
1074 1120
1075 return { 1121 return {
1076 initialize: initialize, 1122 initialize: initialize,
1077 command: command, 1123 command: command,
1078 }; 1124 };
1079 })(); 1125 })();
1080 1126
1081 window.addEventListener('load', vrShellUi.initialize); 1127 window.addEventListener('load', vrShellUi.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.css ('k') | chrome/browser/resources/vr_shell/vr_shell_ui_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698