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

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: adding/removing click callback accordingly 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 = {};
227 let descriptors = [ 242 let descriptors = [
228 [ 243 [
244 'backButton',
229 '#back-button', 245 '#back-button',
230 function() { 246 function() {
231 api.doAction(api.Action.HISTORY_BACK, {}); 247 api.doAction(api.Action.HISTORY_BACK, {});
232 } 248 }
233 ], 249 ],
234 [ 250 [
251 'reloadButton',
235 '#reload-button', 252 '#reload-button',
236 function() { 253 function() {
237 api.doAction(api.Action.RELOAD, {}); 254 api.doAction(api.Action.RELOAD, {});
238 } 255 }
239 ], 256 ],
240 [ 257 [
258 'forwardButton',
241 '#forward-button', 259 '#forward-button',
242 function() { 260 function() {
243 api.doAction(api.Action.HISTORY_FORWARD, {}); 261 api.doAction(api.Action.HISTORY_FORWARD, {});
244 } 262 }
245 ], 263 ],
246 ]; 264 ];
247 265
248 /** @const */ var BUTTON_Y = -0.27; 266 /** @const */ var BUTTON_Y = -0.27;
249 /** @const */ var BUTTON_Z = -1; 267 /** @const */ var BUTTON_Z = -1;
250 /** @const */ var BUTTON_SPACING = 0.11; 268 /** @const */ var BUTTON_SPACING = 0.11;
251 269
252 let controls = new api.UiElement(0, 0, 0, 0); 270 let controls = new api.UiElement(0, 0, 0, 0);
253 controls.setVisible(false); 271 controls.setVisible(false);
254 controls.setTranslation(0, BUTTON_Y, BUTTON_Z); 272 controls.setTranslation(0, BUTTON_Y, BUTTON_Z);
255 this.controlsId = ui.addElement(controls); 273 this.controlsId = ui.addElement(controls);
256 274
257 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 275 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5);
258 276
259 for (let i = 0; i < descriptors.length; i++) { 277 for (let i = 0; i < descriptors.length; i++) {
260 let domId = descriptors[i][0]; 278 let name = descriptors[i][0];
261 let callback = descriptors[i][1]; 279 let domId = descriptors[i][1];
280 let callback = descriptors[i][2];
262 let button = new Button(domId, callback, this.controlsId); 281 let button = new Button(domId, callback, this.controlsId);
263 button.setTranslation(startPosition + i * BUTTON_SPACING, 0, 0); 282 button.setTranslation(startPosition + i * BUTTON_SPACING, 0, 0);
264 this.buttons.push(button); 283 this.buttons[name] = button;
265 } 284 }
266 } 285 }
267 286
268 setEnabled(enabled) { 287 setEnabled(enabled) {
269 this.enabled = enabled; 288 this.enabled = enabled;
270 this.configure(); 289 this.configure();
271 } 290 }
272 291
273 configure() { 292 configure() {
274 for (let i = 0; i < this.buttons.length; i++) { 293 for (let key in this.buttons) {
275 this.buttons[i].setVisible(this.enabled); 294 this.buttons[key].setVisible(this.enabled);
276 } 295 }
277 } 296 }
297
298 setBackButtonEnabled(enabled) {
299 this.buttons.backButton.setEnabled(enabled);
300 }
301
302 setForwardButtonEnabled(enabled) {
303 this.buttons.forwardButton.setEnabled(enabled);
304 }
278 }; 305 };
279 306
280 /** 307 /**
281 * A button to trigger a reload of the HTML UI for development purposes. 308 * A button to trigger a reload of the HTML UI for development purposes.
282 */ 309 */
283 class ReloadUiButton { 310 class ReloadUiButton {
284 constructor() { 311 constructor() {
285 this.enabled = false; 312 this.enabled = false;
286 this.devMode = false; 313 this.devMode = false;
287 314
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 anim.setScale(scale, scale, scale); 930 anim.setScale(scale, scale, scale);
904 ui.addAnimation(anim); 931 ui.addAnimation(anim);
905 } 932 }
906 }; 933 };
907 934
908 class UiManager { 935 class UiManager {
909 constructor() { 936 constructor() {
910 this.mode = api.Mode.UNKNOWN; 937 this.mode = api.Mode.UNKNOWN;
911 this.menuMode = false; 938 this.menuMode = false;
912 this.fullscreen = false; 939 this.fullscreen = false;
940 this.canGoBack = false;
941 this.canGoForward = false;
913 942
914 this.background = new Background(); 943 this.background = new Background();
915 this.contentQuad = new ContentQuad(); 944 this.contentQuad = new ContentQuad();
916 let contentId = this.contentQuad.getElementId(); 945 let contentId = this.contentQuad.getElementId();
917 946
918 this.controls = new Controls(contentId); 947 this.controls = new Controls(contentId);
919 this.secureOriginWarnings = new SecureOriginWarnings(); 948 this.secureOriginWarnings = new SecureOriginWarnings();
920 this.urlIndicator = new UrlIndicator(); 949 this.urlIndicator = new UrlIndicator();
921 this.omnibox = new Omnibox(); 950 this.omnibox = new Omnibox();
922 this.reloadUiButton = new ReloadUiButton(); 951 this.reloadUiButton = new ReloadUiButton();
923 this.tabContainer = new TabContainer(contentId); 952 this.tabContainer = new TabContainer(contentId);
924 this.keyboard = new VirtualKeyboard(contentId); 953 this.keyboard = new VirtualKeyboard(contentId);
925 } 954 }
926 955
927 setMode(mode) { 956 setMode(mode) {
928 this.mode = mode; 957 this.mode = mode;
929 this.updateState(); 958 this.updateState();
930 } 959 }
931 960
932 setFullscreen(fullscreen) { 961 setFullscreen(fullscreen) {
933 this.fullscreen = fullscreen; 962 this.fullscreen = fullscreen;
934 this.updateState(); 963 this.updateState();
935 } 964 }
936 965
937 handleAppButtonClicked() { 966 handleAppButtonClicked() {
938 this.menuMode = !this.menuMode; 967 this.menuMode = !this.menuMode;
939 this.updateState(); 968 this.updateState();
940 } 969 }
941 970
971 setHistoryButtonsEnabled(canGoBack, canGoForward) {
972 this.canGoBack = canGoBack;
973 this.canGoForward = canGoForward;
974 this.updateState();
cjgrant 2017/03/08 20:52:01 Can you call straight through to this.controls, li
acondor_ 2017/03/08 21:21:27 Done.
975 }
976
942 updateState() { 977 updateState() {
943 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; 978 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000;
944 979
945 let mode = this.mode; 980 let mode = this.mode;
946 let menuMode = this.menuMode; 981 let menuMode = this.menuMode;
947 let fullscreen = this.fullscreen; 982 let fullscreen = this.fullscreen;
948 983
949 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode}); 984 api.doAction(api.Action.SET_CONTENT_PAUSED, {'paused': menuMode});
950 985
951 this.contentQuad.setEnabled(mode == api.Mode.STANDARD); 986 this.contentQuad.setEnabled(mode == api.Mode.STANDARD);
952 this.contentQuad.setFullscreen(fullscreen); 987 this.contentQuad.setFullscreen(fullscreen);
953 this.contentQuad.setMenuMode(menuMode); 988 this.contentQuad.setMenuMode(menuMode);
954 // TODO(crbug/643815): Set aspect ratio on content quad when available. 989 // TODO(crbug/643815): Set aspect ratio on content quad when available.
955 this.controls.setEnabled(menuMode); 990 this.controls.setEnabled(menuMode);
991 this.controls.setBackButtonEnabled(this.canGoBack || this.fullscreen);
992 this.controls.setForwardButtonEnabled(this.canGoForward);
956 this.omnibox.setEnabled(menuMode); 993 this.omnibox.setEnabled(menuMode);
957 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); 994 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode);
958 this.urlIndicator.setVisibilityTimeout( 995 this.urlIndicator.setVisibilityTimeout(
959 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); 996 URL_INDICATOR_VISIBILITY_TIMEOUT_MS);
960 this.secureOriginWarnings.setEnabled( 997 this.secureOriginWarnings.setEnabled(
961 mode == api.Mode.WEB_VR && !menuMode); 998 mode == api.Mode.WEB_VR && !menuMode);
962 this.background.setState(mode, menuMode, fullscreen); 999 this.background.setState(mode, menuMode, fullscreen);
963 this.tabContainer.setEnabled(mode == api.Mode.STANDARD && menuMode); 1000 this.tabContainer.setEnabled(mode == api.Mode.STANDARD && menuMode);
964 1001
965 this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD); 1002 this.reloadUiButton.setEnabled(mode == api.Mode.STANDARD);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 uiManager.tabContainer.addTab(tab); 1093 uiManager.tabContainer.addTab(tab);
1057 } 1094 }
1058 } 1095 }
1059 1096
1060 /** @override */ 1097 /** @override */
1061 onRemoveTab(tab) { 1098 onRemoveTab(tab) {
1062 uiManager.tabContainer.removeTab(tab); 1099 uiManager.tabContainer.removeTab(tab);
1063 } 1100 }
1064 1101
1065 /** @override */ 1102 /** @override */
1103 onSetHistoryButtonsEnabled(canGoBack, canGoForward) {
1104 uiManager.setHistoryButtonsEnabled(canGoBack, canGoForward);
1105 }
1106
1107 /** @override */
1066 onCommandHandlerFinished() { 1108 onCommandHandlerFinished() {
1067 ui.flush(); 1109 ui.flush();
1068 } 1110 }
1069 } 1111 }
1070 1112
1071 function command(dict) { 1113 function command(dict) {
1072 nativeCommandHandler.handleCommand(dict); 1114 nativeCommandHandler.handleCommand(dict);
1073 } 1115 }
1074 1116
1075 return { 1117 return {
1076 initialize: initialize, 1118 initialize: initialize,
1077 command: command, 1119 command: command,
1078 }; 1120 };
1079 })(); 1121 })();
1080 1122
1081 window.addEventListener('load', vrShellUi.initialize); 1123 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