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

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

Issue 2622593003: Move the omnibox natively when showing or hiding. (Closed)
Patch Set: Drop useless omnibox constructor argument. Created 3 years, 11 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
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.css ('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 ui = new scene.Scene(); 8 let ui = new scene.Scene();
9 let uiManager; 9 let uiManager;
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 let pixelX = Math.floor(rect.left); 74 let pixelX = Math.floor(rect.left);
75 let pixelY = Math.floor(rect.top); 75 let pixelY = Math.floor(rect.top);
76 let pixelWidth = Math.ceil(rect.right) - pixelX; 76 let pixelWidth = Math.ceil(rect.right) - pixelX;
77 let pixelHeight = Math.ceil(rect.bottom) - pixelY; 77 let pixelHeight = Math.ceil(rect.bottom) - pixelY;
78 78
79 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); 79 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight);
80 element.setSize(pixelWidth / 1000, pixelHeight / 1000); 80 element.setSize(pixelWidth / 1000, pixelHeight / 1000);
81 81
82 // Pull additional custom properties from CSS. 82 // Pull additional custom properties from CSS.
83 let style = window.getComputedStyle(domElement); 83 let style = window.getComputedStyle(domElement);
84 this.translationX = getStyleFloat(style, '--tranX');
85 this.translationY = getStyleFloat(style, '--tranY');
86 this.translationZ = getStyleFloat(style, '--tranZ');
84 element.setTranslation( 87 element.setTranslation(
85 getStyleFloat(style, '--tranX'), getStyleFloat(style, '--tranY'), 88 this.translationX, this.translationY, this.translationZ);
86 getStyleFloat(style, '--tranZ'));
87 89
88 this.uiElementId = ui.addElement(element); 90 this.uiElementId = ui.addElement(element);
89 this.uiAnimationId = -1; 91 this.uiAnimationId = -1;
90 this.domElement = domElement; 92 this.domElement = domElement;
91 } 93 }
92 }; 94 };
93 95
94 class RoundButton extends DomUiElement { 96 class RoundButton extends DomUiElement {
95 constructor(domId, callback) { 97 constructor(domId, callback) {
96 super(domId); 98 super(domId);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 onTransientTimer() { 282 onTransientTimer() {
281 let update = new api.UiElementUpdate(); 283 let update = new api.UiElementUpdate();
282 update.setVisible(false); 284 update.setVisible(false);
283 ui.updateElement(this.transientWarning.uiElementId, update); 285 ui.updateElement(this.transientWarning.uiElementId, update);
284 this.secureOriginTimer = null; 286 this.secureOriginTimer = null;
285 ui.flush(); 287 ui.flush();
286 } 288 }
287 }; 289 };
288 290
289 class Omnibox { 291 class Omnibox {
290 constructor(contentQuadId) { 292 constructor() {
291 this.domUiElement = new DomUiElement('#omnibox-container'); 293 this.domUiElement = new DomUiElement('#omnibox-container');
292 this.enabled = false; 294 this.enabled = false;
295 this.hidden = false;
293 this.loading = false; 296 this.loading = false;
294 this.loadingProgress = 0; 297 this.loadingProgress = 0;
295 this.level = 0; 298 this.level = 0;
296 this.visibilityTimeout = 0; 299 this.visibilityTimeout = 0;
297 this.visibilityTimer = null; 300 this.visibilityTimer = null;
298 this.visibleAfterTransition = false;
299 this.nativeState = {}; 301 this.nativeState = {};
300 302
301 // Initially invisible. 303 // Initially invisible.
302 let update = new api.UiElementUpdate(); 304 let update = new api.UiElementUpdate();
303 update.setVisible(false); 305 update.setVisible(false);
304 ui.updateElement(this.domUiElement.uiElementId, update); 306 ui.updateElement(this.domUiElement.uiElementId, update);
305 this.nativeState.visible = false; 307 this.nativeState.visible = false;
306 308
307 // Pull colors from CSS so that Javascript can set the progress indicator 309 // Pull some CSS properties so that Javascript can reconfigure the omnibox
308 // gradient programmatically. 310 // programmatically.
309 let border = 311 let border =
310 this.domUiElement.domElement.querySelector('#omnibox-border'); 312 this.domUiElement.domElement.querySelector('#omnibox-border');
311 let style = window.getComputedStyle(border); 313 let style = window.getComputedStyle(border);
312 this.statusBarColor = getStyleString(style, '--statusBarColor'); 314 this.statusBarColor = getStyleString(style, '--statusBarColor');
313 this.backgroundColor = style.backgroundColor; 315 this.backgroundColor = style.backgroundColor;
316 this.fadeTimeMs = getStyleFloat(style, '--fadeTimeMs');
317 this.fadeYOffset = getStyleFloat(style, '--fadeYOffset');
314 318
315 // Listen to the end of transitions, so that the box can be natively 319 // Listen to the end of transitions, so that the box can be natively
316 // hidden after it finishes hiding itself. 320 // hidden after it finishes hiding itself.
317 document.querySelector('#omnibox') 321 document.querySelector('#omnibox')
318 .addEventListener('transitionend', this.onAnimationDone.bind(this)); 322 .addEventListener('transitionend', this.onAnimationDone.bind(this));
319 } 323 }
320 324
321 getSecurityIconElementId(level) { 325 getSecurityIconElementId(level) {
322 // See security_state.h and getSecurityIconResource() for this mapping. 326 // See security_state.h and getSecurityIconResource() for this mapping.
323 switch (level) { 327 switch (level) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 this.onVisibilityTimer.bind(this), this.visibilityTimeout); 392 this.onVisibilityTimer.bind(this), this.visibilityTimeout);
389 } 393 }
390 } 394 }
391 395
392 onVisibilityTimer() { 396 onVisibilityTimer() {
393 this.visibilityTimer = null; 397 this.visibilityTimer = null;
394 this.updateState(); 398 this.updateState();
395 } 399 }
396 400
397 onAnimationDone(e) { 401 onAnimationDone(e) {
398 if (e.propertyName == 'opacity' && !this.visibleAfterTransition) { 402 if (e.propertyName == 'opacity' && this.hidden) {
399 this.setNativeVisibility(false); 403 this.setNativeVisibility(false);
400 } 404 }
401 } 405 }
402 406
403 updateState() { 407 updateState() {
404 if (!this.enabled) { 408 if (!this.enabled) {
405 this.setNativeVisibility(false); 409 this.setNativeVisibility(false);
406 return; 410 return;
407 } 411 }
408 412
409 let indicator = document.querySelector('#omnibox-border'); 413 let indicator = document.querySelector('#omnibox-border');
410 if (this.loading) { 414 if (this.loading) {
411 // Remap load progress range 0-100 as 5-95 percent, to avoid the 415 // Remap load progress range 0-100 as 5-95 percent, to avoid the
412 // extremities of the rounded ends of the omnibox. 416 // extremities of the rounded ends of the omnibox.
413 let percent = Math.round((this.loadingProgress * 0.9 + 0.05) * 100); 417 let percent = Math.round((this.loadingProgress * 0.9 + 0.05) * 100);
414 let gradient = '-webkit-linear-gradient(left, ' + this.statusBarColor + 418 let gradient = '-webkit-linear-gradient(left, ' + this.statusBarColor +
415 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + 419 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' +
416 this.backgroundColor + ' ' + percent + '%, ' + 420 this.backgroundColor + ' ' + percent + '%, ' +
417 this.backgroundColor + ' 100%)'; 421 this.backgroundColor + ' 100%)';
418 indicator.style.background = gradient; 422 indicator.style.background = gradient;
419 } else { 423 } else {
420 indicator.style.background = this.backgroundColor; 424 indicator.style.background = this.backgroundColor;
421 } 425 }
422 426
423 // Make the box fade away if it's disappearing. 427 let shouldBeHidden =
424 if (!this.loading && this.visibilityTimeout > 0 && 428 !this.loading && this.visibilityTimeout > 0 && !this.visibilityTimer;
425 !this.visibilityTimer) { 429 if (shouldBeHidden != this.hidden) {
426 document.querySelector('#omnibox-border').className = 'hidden'; 430 // Make the box fade away if it's disappearing.
mthiesse 2017/01/09 16:55:59 File a bug to do the opacity fading natively as we
cjgrant 2017/01/10 16:13:06 Done. crbug/679761
427 this.visibleAfterTransition = false; 431 this.hidden = shouldBeHidden;
428 } else { 432 document.querySelector('#omnibox-border').className =
429 document.querySelector('#omnibox-border').className = ''; 433 this.hidden ? 'hidden' : '';
430 this.visibleAfterTransition = true; 434
435 // Drop the position as it fades.
436 let yOffset = this.hidden ? this.fadeYOffset : 0;
bshe 2017/01/09 22:40:51 perhap only add animation if this.hidden is true i
cjgrant 2017/01/10 14:30:44 It wouldn't be a noop - it's moving the box from t
bshe 2017/01/10 15:32:08 Acknowledged. Perhaps add comment for yOffset to c
cjgrant 2017/01/10 16:13:06 Done.
437 let animation =
438 new api.Animation(this.domUiElement.uiElementId, this.fadeTimeMs);
439 animation.setTranslation(
440 this.domUiElement.translationX,
441 this.domUiElement.translationY + yOffset,
442 this.domUiElement.translationZ);
443 ui.addAnimation(animation);
444 ui.flush();
431 } 445 }
432 446
433 this.setNativeVisibility(true); 447 this.setNativeVisibility(true);
434 } 448 }
435 449
436 setNativeVisibility(visible) { 450 setNativeVisibility(visible) {
437 if (visible == this.nativeState.visible) { 451 if (visible == this.nativeState.visible) {
438 return; 452 return;
439 } 453 }
440 this.nativeState.visible = visible; 454 this.nativeState.visible = visible;
441 let update = new api.UiElementUpdate(); 455 let update = new api.UiElementUpdate();
442 update.setVisible(visible); 456 update.setVisible(visible);
443 ui.updateElement(this.domUiElement.uiElementId, update); 457 ui.updateElement(this.domUiElement.uiElementId, update);
444 ui.flush(); 458 ui.flush();
445 } 459 }
446 }; 460 };
447 461
448 class UiManager { 462 class UiManager {
449 constructor() { 463 constructor() {
450 this.mode = api.Mode.UNKNOWN; 464 this.mode = api.Mode.UNKNOWN;
451 this.menuMode = false; 465 this.menuMode = false;
452 this.fullscreen = false; 466 this.fullscreen = false;
453 467
454 this.contentQuad = new ContentQuad(); 468 this.contentQuad = new ContentQuad();
455 let contentId = this.contentQuad.getElementId(); 469 let contentId = this.contentQuad.getElementId();
456 470
457 this.controls = new Controls(contentId); 471 this.controls = new Controls(contentId);
458 this.secureOriginWarnings = new SecureOriginWarnings(); 472 this.secureOriginWarnings = new SecureOriginWarnings();
459 this.omnibox = new Omnibox(contentId); 473 this.omnibox = new Omnibox();
460 } 474 }
461 475
462 setMode(mode, menuMode, fullscreen) { 476 setMode(mode, menuMode, fullscreen) {
463 /** @const */ var OMNIBOX_VISIBILITY_TIMEOUT_MS = 5000; 477 /** @const */ var OMNIBOX_VISIBILITY_TIMEOUT_MS = 5000;
464 478
465 this.mode = mode; 479 this.mode = mode;
466 this.menuMode = menuMode; 480 this.menuMode = menuMode;
467 this.fullscreen = fullscreen; 481 this.fullscreen = fullscreen;
468 482
469 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); 483 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 ui.flush(); 543 ui.flush();
530 } 544 }
531 545
532 return { 546 return {
533 initialize: initialize, 547 initialize: initialize,
534 command: command, 548 command: command,
535 }; 549 };
536 })(); 550 })();
537 551
538 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); 552 document.addEventListener('DOMContentLoaded', vrShellUi.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698