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 scene = new ui.Scene(); | 8 let scene = new ui.Scene(); |
| 9 let sceneManager; | 9 let sceneManager; |
| 10 | 10 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; |
| 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; | |
|
bshe
2016/11/17 15:18:19
did you change the value of visibilityTimeout? if
cjgrant
2016/11/17 20:17:43
Changing the timeout to 0 disables the transient b
| |
| 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 show(enabled) { |
|
bshe
2016/11/17 15:18:19
nit: It is possibly easier to understand if you ch
cjgrant
2016/11/17 20:17:43
I think show/hide will generate more duplicate cod
| |
| 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; |
|
bshe
2016/11/17 15:18:19
Should all the functions that might change the sta
cjgrant
2016/11/17 20:17:43
I don't want that to happen, no. If the omnibox i
| |
| 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 resetVisibilityTimer() { | |
| 302 if (this.visibilityTimer) { | |
| 303 clearInterval(this.visibilityTimer); | |
| 304 this.visibilityTimer = null; | |
| 305 } | |
| 306 if (this.enabled && this.visibilityTimeout > 0) { | |
| 307 this.visibilityTimer = setTimeout( | |
| 308 this.onVisibilityTimer.bind(this), this.visibilityTimeout); | |
| 309 } | |
| 310 } | |
| 311 | |
| 312 onVisibilityTimer() { | |
| 313 this.visibilityTimer = null; | |
| 314 this.updateState(); | |
| 315 } | |
| 316 | |
| 317 onAnimationDone(e) { | |
| 318 if (e.propertyName == 'opacity' && !this.visibleAfterTransition) { | |
| 319 this.setNativeVisibility(false); | |
| 320 } | |
| 321 } | |
| 322 | |
| 323 updateState() { | |
| 324 if (!this.enabled) { | |
| 325 this.setNativeVisibility(false); | |
| 326 return; | |
| 327 } | |
| 328 | |
| 278 document.querySelector('#omni-secure-icon').style.display = | 329 document.querySelector('#omni-secure-icon').style.display = |
| 279 (secure ? 'block' : 'none'); | 330 (this.secure ? 'block' : 'none'); |
| 280 document.querySelector('#omni-insecure-icon').style.display = | 331 document.querySelector('#omni-insecure-icon').style.display = |
| 281 (!secure ? 'block' : 'none'); | 332 (this.secure ? 'none' : 'block'); |
| 333 | |
| 334 let state = 'idle'; | |
| 335 this.visibleAfterTransition = true; | |
| 336 if (this.visibilityTimeout > 0 && !this.visibilityTimer) { | |
|
bshe
2016/11/17 15:18:19
Doesn't look like you changed the value of visibil
cjgrant
2016/11/17 20:17:43
As above, setting a non-zero timeout enables the t
| |
| 337 state = 'hide'; | |
| 338 this.visibleAfterTransition = false; | |
| 339 } else if (this.loading) { | |
| 340 state = 'loading'; | |
| 341 } | |
| 342 document.querySelector('#omni').className = state; | |
| 343 | |
| 344 this.setNativeVisibility(true); | |
| 345 } | |
| 346 | |
| 347 setNativeVisibility(visible) { | |
| 348 if (visible != this.nativeState.visible) { | |
|
bshe
2016/11/17 15:18:19
nit: prefer early return.
| |
| 349 this.nativeState.visible = visible; | |
| 350 let update = new api.UiElementUpdate(); | |
| 351 update.setVisible(visible); | |
| 352 scene.updateElement(this.domUiElement.uiElementId, update); | |
| 353 scene.flush(); | |
| 354 } | |
| 282 } | 355 } |
| 283 }; | 356 }; |
| 284 | 357 |
| 285 class SceneManager { | 358 class SceneManager { |
| 286 constructor() { | 359 constructor() { |
| 287 this.mode = api.Mode.UNKNOWN; | 360 this.mode = api.Mode.UNKNOWN; |
| 288 | 361 |
| 289 this.contentQuad = new ContentQuad(); | 362 this.contentQuad = new ContentQuad(); |
| 290 let contentId = this.contentQuad.getElementId(); | 363 let contentId = this.contentQuad.getElementId(); |
| 291 | 364 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 scene.flush(); | 412 scene.flush(); |
| 340 } | 413 } |
| 341 | 414 |
| 342 return { | 415 return { |
| 343 initialize: initialize, | 416 initialize: initialize, |
| 344 command: command, | 417 command: command, |
| 345 }; | 418 }; |
| 346 })(); | 419 })(); |
| 347 | 420 |
| 348 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); | 421 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); |
| OLD | NEW |