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

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

Issue 2500283003: Allow the VR omnibox to be transient. (Closed)
Patch Set: Address some nits; explain others. Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 scene = new ui.Scene(); 8 let scene = new ui.Scene();
9 let sceneManager; 9 let sceneManager;
10 10
(...skipping 12 matching lines...) Expand all
23 /** @const */ var SCREEN_DISTANCE = 2.0; 23 /** @const */ var SCREEN_DISTANCE = 2.0;
24 24
25 let element = new api.UiElement(0, 0, 0, 0); 25 let element = new api.UiElement(0, 0, 0, 0);
26 element.setIsContentQuad(false); 26 element.setIsContentQuad(false);
27 element.setVisible(false); 27 element.setVisible(false);
28 element.setSize(SCREEN_HEIGHT * 16 / 9, SCREEN_HEIGHT); 28 element.setSize(SCREEN_HEIGHT * 16 / 9, SCREEN_HEIGHT);
29 element.setTranslation(0, 0, -SCREEN_DISTANCE); 29 element.setTranslation(0, 0, -SCREEN_DISTANCE);
30 this.elementId = scene.addElement(element); 30 this.elementId = scene.addElement(element);
31 } 31 }
32 32
33 show(visible) { 33 setEnabled(enabled) {
34 let update = new api.UiElementUpdate(); 34 let update = new api.UiElementUpdate();
35 update.setVisible(visible); 35 update.setVisible(enabled);
36 scene.updateElement(this.elementId, update); 36 scene.updateElement(this.elementId, update);
37 } 37 }
38 38
39 getElementId() { 39 getElementId() {
40 return this.elementId; 40 return this.elementId;
41 } 41 }
42 }; 42 };
43 43
44 class DomUiElement { 44 class DomUiElement {
45 constructor(domId) { 45 constructor(domId) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 let update = new api.UiElementUpdate(); 147 let update = new api.UiElementUpdate();
148 update.setParentId(contentQuadId); 148 update.setParentId(contentQuadId);
149 update.setVisible(false); 149 update.setVisible(false);
150 update.setScale(2.2, 2.2, 1); 150 update.setScale(2.2, 2.2, 1);
151 update.setTranslation(0, -0.6, 0.3); 151 update.setTranslation(0, -0.6, 0.3);
152 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); 152 update.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM);
153 scene.updateElement(this.reloadUiButton.uiElementId, update); 153 scene.updateElement(this.reloadUiButton.uiElementId, update);
154 } 154 }
155 155
156 show(visible) { 156 setEnabled(enabled) {
157 this.enabled = visible; 157 this.enabled = enabled;
158 this.configure(); 158 this.configure();
159 } 159 }
160 160
161 setReloadUiEnabled(enabled) { 161 setReloadUiEnabled(enabled) {
162 this.reloadUiEnabled = enabled; 162 this.reloadUiEnabled = enabled;
163 this.configure(); 163 this.configure();
164 } 164 }
165 165
166 configure() { 166 configure() {
167 for (let i = 0; i < this.buttons.length; i++) { 167 for (let i = 0; i < this.buttons.length; i++) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 '#webvr-not-secure-transient'); 199 '#webvr-not-secure-transient');
200 update = new api.UiElementUpdate(); 200 update = new api.UiElementUpdate();
201 update.setScale(DISTANCE, DISTANCE, 1); 201 update.setScale(DISTANCE, DISTANCE, 1);
202 update.setTranslation(0, 0, -DISTANCE); 202 update.setTranslation(0, 0, -DISTANCE);
203 update.setHitTestable(false); 203 update.setHitTestable(false);
204 update.setVisible(false); 204 update.setVisible(false);
205 update.setLockToFieldOfView(true); 205 update.setLockToFieldOfView(true);
206 scene.updateElement(this.transientWarning.uiElementId, update); 206 scene.updateElement(this.transientWarning.uiElementId, update);
207 } 207 }
208 208
209 show(visible) { 209 setEnabled(enabled) {
210 this.enabled = visible; 210 this.enabled = enabled;
211 this.updateState(); 211 this.updateState();
212 } 212 }
213 213
214 setSecureOrigin(secure) { 214 setSecureOrigin(secure) {
215 this.isSecureOrigin = secure; 215 this.isSecureOrigin = secure;
216 this.updateState(); 216 this.updateState();
217 } 217 }
218 218
219 updateState() { 219 updateState() {
220 /** @const */ var TRANSIENT_TIMEOUT_MS = 30000; 220 /** @const */ var TRANSIENT_TIMEOUT_MS = 30000;
(...skipping 23 matching lines...) Expand all
244 let update = new api.UiElementUpdate(); 244 let update = new api.UiElementUpdate();
245 update.setVisible(false); 245 update.setVisible(false);
246 scene.updateElement(this.transientWarning.uiElementId, update); 246 scene.updateElement(this.transientWarning.uiElementId, update);
247 this.secureOriginTimer = null; 247 this.secureOriginTimer = null;
248 scene.flush(); 248 scene.flush();
249 } 249 }
250 }; 250 };
251 251
252 class Omnibox { 252 class Omnibox {
253 constructor(contentQuadId) { 253 constructor(contentQuadId) {
254 this.setSecureOrigin(false); 254 /** @const */ var VISIBILITY_TIMEOUT_MS = 3000;
amp 2016/11/17 21:00:35 Not affecting the review (which looks like it's al
cjgrant 2016/11/17 21:13:12 It keeps the presubmit style checker happy - no ot
255 this.domUiElement = new DomUiElement('#omni'); 255
256 this.domUiElement = new DomUiElement('#omni-container');
257 this.enabled = false;
258 this.secure = false;
259 this.visibilityTimeout = VISIBILITY_TIMEOUT_MS;
260 this.visibilityTimer = null;
261 this.nativeState = {};
262
263 // Initially invisible.
256 let update = new api.UiElementUpdate(); 264 let update = new api.UiElementUpdate();
257 update.setVisible(false); 265 update.setVisible(false);
258 scene.updateElement(this.domUiElement.uiElementId, update); 266 scene.updateElement(this.domUiElement.uiElementId, update);
267 this.nativeState.visible = false;
268
269 // Listen to the end of transitions, so that the box can be natively
270 // hidden after it finishes hiding itself.
271 document.querySelector('#omni').addEventListener('transitionend',
272 this.onAnimationDone.bind(this));
259 } 273 }
260 274
261 show(visible) { 275 setEnabled(enabled) {
262 let update = new api.UiElementUpdate(); 276 this.enabled = enabled;
263 update.setVisible(visible); 277 this.resetVisibilityTimer();
264 scene.updateElement(this.domUiElement.uiElementId, update); 278 this.updateState();
265 } 279 }
266 280
267 setLoading(loading) { 281 setLoading(loading) {
268 this.domUiElement.domElement.className = loading ? 'loading' : 'idle'; 282 this.loading = loading;
283 this.resetVisibilityTimer();
284 this.updateState();
269 } 285 }
270 286
271 setURL(host, path) { 287 setURL(host, path) {
272 let omnibox = this.domUiElement.domElement; 288 let omnibox = this.domUiElement.domElement;
273 omnibox.querySelector('#domain').innerHTML = host; 289 omnibox.querySelector('#domain').innerHTML = host;
274 omnibox.querySelector('#path').innerHTML = path; 290 omnibox.querySelector('#path').innerHTML = path;
291 this.resetVisibilityTimer();
292 this.updateState();
275 } 293 }
276 294
277 setSecureOrigin(secure) { 295 setSecureOrigin(secure) {
296 this.secure = secure;
297 this.resetVisibilityTimer();
298 this.updateState();
299 }
300
301 setVisibilityTimeout(milliseconds) {
302 this.visibilityTimeout = milliseconds;
303 this.resetVisibilityTimer();
304 this.updateState();
305 }
306
307 resetVisibilityTimer() {
308 if (this.visibilityTimer) {
309 clearInterval(this.visibilityTimer);
310 this.visibilityTimer = null;
311 }
312 if (this.enabled && this.visibilityTimeout > 0) {
313 this.visibilityTimer = setTimeout(
314 this.onVisibilityTimer.bind(this), this.visibilityTimeout);
315 }
316 }
317
318 onVisibilityTimer() {
319 this.visibilityTimer = null;
320 this.updateState();
321 }
322
323 onAnimationDone(e) {
324 if (e.propertyName == 'opacity' && !this.visibleAfterTransition) {
325 this.setNativeVisibility(false);
326 }
327 }
328
329 updateState() {
330 if (!this.enabled) {
331 this.setNativeVisibility(false);
332 return;
333 }
334
278 document.querySelector('#omni-secure-icon').style.display = 335 document.querySelector('#omni-secure-icon').style.display =
279 (secure ? 'block' : 'none'); 336 (this.secure ? 'block' : 'none');
280 document.querySelector('#omni-insecure-icon').style.display = 337 document.querySelector('#omni-insecure-icon').style.display =
281 (!secure ? 'block' : 'none'); 338 (this.secure ? 'none' : 'block');
339
340 let state = 'idle';
341 this.visibleAfterTransition = true;
342 if (this.visibilityTimeout > 0 && !this.visibilityTimer) {
343 state = 'hide';
344 this.visibleAfterTransition = false;
345 } else if (this.loading) {
346 state = 'loading';
347 }
348 document.querySelector('#omni').className = state;
349
350 this.setNativeVisibility(true);
351 }
352
353 setNativeVisibility(visible) {
354 if (visible == this.nativeState.visible) {
355 return;
356 }
357 this.nativeState.visible = visible;
358 let update = new api.UiElementUpdate();
359 update.setVisible(visible);
360 scene.updateElement(this.domUiElement.uiElementId, update);
361 scene.flush();
282 } 362 }
283 }; 363 };
284 364
285 class SceneManager { 365 class SceneManager {
286 constructor() { 366 constructor() {
287 this.mode = api.Mode.UNKNOWN; 367 this.mode = api.Mode.UNKNOWN;
288 368
289 this.contentQuad = new ContentQuad(); 369 this.contentQuad = new ContentQuad();
290 let contentId = this.contentQuad.getElementId(); 370 let contentId = this.contentQuad.getElementId();
291 371
292 this.controls = new Controls(contentId); 372 this.controls = new Controls(contentId);
293 this.secureOriginWarnings = new SecureOriginWarnings(); 373 this.secureOriginWarnings = new SecureOriginWarnings();
294 this.omnibox = new Omnibox(contentId); 374 this.omnibox = new Omnibox(contentId);
295 } 375 }
296 376
297 setMode(mode) { 377 setMode(mode) {
298 this.mode = mode; 378 this.mode = mode;
299 this.contentQuad.show(mode == api.Mode.STANDARD); 379 this.contentQuad.setEnabled(mode == api.Mode.STANDARD);
300 this.controls.show(mode == api.Mode.STANDARD); 380 this.controls.setEnabled(mode == api.Mode.STANDARD);
301 this.omnibox.show(mode == api.Mode.STANDARD); 381 this.omnibox.setEnabled(mode == api.Mode.STANDARD);
302 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR); 382 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR);
303 } 383 }
304 384
305 setSecureOrigin(secure) { 385 setSecureOrigin(secure) {
306 this.secureOriginWarnings.setSecureOrigin(secure); 386 this.secureOriginWarnings.setSecureOrigin(secure);
307 this.omnibox.setSecureOrigin(secure); 387 this.omnibox.setSecureOrigin(secure);
308 } 388 }
309 389
310 setReloadUiEnabled(enabled) { 390 setReloadUiEnabled(enabled) {
311 this.controls.setReloadUiEnabled(enabled); 391 this.controls.setReloadUiEnabled(enabled);
312 } 392 }
(...skipping 26 matching lines...) Expand all
339 scene.flush(); 419 scene.flush();
340 } 420 }
341 421
342 return { 422 return {
343 initialize: initialize, 423 initialize: initialize,
344 command: command, 424 command: command,
345 }; 425 };
346 })(); 426 })();
347 427
348 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); 428 document.addEventListener('DOMContentLoaded', vrShellUi.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698