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

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

Issue 2473443002: Add an initial omnibox to HTML UI content. (Closed)
Patch Set: Remove debug logging print. 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
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
11 let uiRootElement = document.querySelector('#ui');
12 let uiStyle = window.getComputedStyle(uiRootElement);
13 let scaleFactor = uiStyle.getPropertyValue('--scaleFactor');
bshe 2016/11/01 22:24:13 I am not sure I understand why do you want to get
cjgrant 2016/11/09 16:33:26 This scaling factor is required to correct for the
14
15 function getStyleFloat(style, property) {
16 let value = parseFloat(style.getPropertyValue(property));
17 return isNaN(value) ? 0 : value;
18 }
19
11 class ContentQuad { 20 class ContentQuad {
12 constructor() { 21 constructor() {
13 /** @const */ var SCREEN_HEIGHT = 1.6; 22 /** @const */ var SCREEN_HEIGHT = 1.6;
14 /** @const */ var SCREEN_DISTANCE = 2.0; 23 /** @const */ var SCREEN_DISTANCE = 2.0;
15 24
16 let element = new api.UiElement(0, 0, 0, 0); 25 let element = new api.UiElement(0, 0, 0, 0);
17 element.setIsContentQuad(false); 26 element.setIsContentQuad(false);
18 element.setVisible(false); 27 element.setVisible(false);
19 element.setSize(SCREEN_HEIGHT * 16 / 9, SCREEN_HEIGHT); 28 element.setSize(SCREEN_HEIGHT * 16 / 9, SCREEN_HEIGHT);
20 element.setTranslation(0, 0, -SCREEN_DISTANCE); 29 element.setTranslation(0, 0, -SCREEN_DISTANCE);
21 this.elementId = scene.addElement(element); 30 this.elementId = scene.addElement(element);
22 } 31 }
23 32
24 show(visible) { 33 show(visible) {
25 let update = new api.UiElementUpdate(); 34 let update = new api.UiElementUpdate();
26 update.setVisible(visible); 35 update.setVisible(visible);
27 scene.updateElement(this.elementId, update); 36 scene.updateElement(this.elementId, update);
28 } 37 }
29 38
30 getElementId() { 39 getElementId() {
31 return this.elementId; 40 return this.elementId;
32 } 41 }
33 }; 42 };
34 43
35 class DomUiElement { 44 class DomUiElement {
36 constructor(domId) { 45 constructor(domId) {
37 let domElement = document.querySelector(domId); 46 let domElement = document.querySelector(domId);
38 let style = window.getComputedStyle(domElement); 47 let style = window.getComputedStyle(domElement);
bshe 2016/11/01 22:24:12 huh. Just realize that we call getComputedStyle fo
cjgrant 2016/11/09 16:33:26 That's interesting. I'll profile this. We won't
cjgrant 2016/11/09 18:03:34 So FWIW, it looks like the impact of getComputedSt
bshe 2016/11/10 18:06:49 yah. I would imagine for our simple UI, this shoul
39 48
40 // Pull copy rectangle from DOM element properties. 49 // Pull copy rectangle from DOM element properties.
41 let pixelX = domElement.offsetLeft; 50 let pixelX = Math.round(domElement.offsetLeft / scaleFactor);
42 let pixelY = domElement.offsetTop; 51 let pixelY = Math.round(domElement.offsetTop / scaleFactor);
43 let pixelWidth = parseInt(style.getPropertyValue('width')); 52 let pixelWidth = Math.round(
44 let pixelHeight = parseInt(style.getPropertyValue('height')); 53 parseInt(style.getPropertyValue('width')) / scaleFactor);
54 let pixelHeight = Math.round(
55 parseInt(style.getPropertyValue('height')) / scaleFactor);
45 56
46 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight); 57 let element = new api.UiElement(pixelX, pixelY, pixelWidth, pixelHeight);
47 element.setSize(pixelWidth / 1000, pixelHeight / 1000); 58 element.setSize(scaleFactor * pixelWidth / 1000,
59 scaleFactor * pixelHeight / 1000);
60
61 // Pull additional custom properties from CSS.
62 element.setTranslation(
63 getStyleFloat(style, '--tranX'),
64 getStyleFloat(style, '--tranY'),
65 getStyleFloat(style, '--tranZ'));
48 66
49 this.uiElementId = scene.addElement(element); 67 this.uiElementId = scene.addElement(element);
50 this.uiAnimationId = -1; 68 this.uiAnimationId = -1;
51 this.domElement = domElement; 69 this.domElement = domElement;
52 } 70 }
53 }; 71 };
54 72
55 class RoundButton extends DomUiElement { 73 class RoundButton extends DomUiElement {
56 constructor(domId, callback) { 74 constructor(domId, callback) {
57 super(domId); 75 super(domId);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 api.doAction(api.Action.HISTORY_BACK); 111 api.doAction(api.Action.HISTORY_BACK);
94 }], 112 }],
95 ['#reload', function() { 113 ['#reload', function() {
96 api.doAction(api.Action.RELOAD); 114 api.doAction(api.Action.RELOAD);
97 }], 115 }],
98 ['#forward', function() { 116 ['#forward', function() {
99 api.doAction(api.Action.HISTORY_FORWARD); 117 api.doAction(api.Action.HISTORY_FORWARD);
100 }], 118 }],
101 ]; 119 ];
102 120
103 /** @const */ var BUTTON_SPACING = 0.3; 121 /** @const */ var BUTTON_SPACING = 0.136;
104 122
105 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 123 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5);
106 for (let i = 0; i < descriptors.length; i++) { 124 for (let i = 0; i < descriptors.length; i++) {
107 // Use an invisible parent to simplify Z-axis movement on hover. 125 // Use an invisible parent to simplify Z-axis movement on hover.
108 let position = new api.UiElement(0, 0, 0, 0); 126 let position = new api.UiElement(0, 0, 0, 0);
109 position.setParentId(contentQuadId);
110 position.setVisible(false); 127 position.setVisible(false);
111 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); 128 position.setTranslation(startPosition + i * BUTTON_SPACING, -0.68, -1);
112 position.setTranslation(
113 startPosition + i * BUTTON_SPACING, -0.3, 0.3);
114 let id = scene.addElement(position); 129 let id = scene.addElement(position);
115 130
116 let domId = descriptors[i][0]; 131 let domId = descriptors[i][0];
117 let callback = descriptors[i][1]; 132 let callback = descriptors[i][1];
118 let element = new RoundButton(domId, callback); 133 let element = new RoundButton(domId, callback);
119 this.buttons.push(element); 134 this.buttons.push(element);
120 135
121 let update = new api.UiElementUpdate(); 136 let update = new api.UiElementUpdate();
122 update.setParentId(id); 137 update.setParentId(id);
123 update.setVisible(false); 138 update.setVisible(false);
124 update.setScale(2.2, 2.2, 1);
125 scene.updateElement(element.uiElementId, update); 139 scene.updateElement(element.uiElementId, update);
126 } 140 }
127 141
128 this.reloadUiButton = new DomUiElement('#reload-ui-button'); 142 this.reloadUiButton = new DomUiElement('#reload-ui-button');
129 this.reloadUiButton.domElement.addEventListener('click', function() { 143 this.reloadUiButton.domElement.addEventListener('click', function() {
130 scene.purge(); 144 scene.purge();
131 api.doAction(api.Action.RELOAD_UI); 145 api.doAction(api.Action.RELOAD_UI);
132 }); 146 });
133 147
134 let update = new api.UiElementUpdate(); 148 let update = new api.UiElementUpdate();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 scene.updateElement(this.transientWarning.uiElementId, update); 241 scene.updateElement(this.transientWarning.uiElementId, update);
228 } 242 }
229 243
230 onTransientTimer() { 244 onTransientTimer() {
231 let update = new api.UiElementUpdate(); 245 let update = new api.UiElementUpdate();
232 update.setVisible(false); 246 update.setVisible(false);
233 scene.updateElement(this.transientWarning.uiElementId, update); 247 scene.updateElement(this.transientWarning.uiElementId, update);
234 this.secureOriginTimer = null; 248 this.secureOriginTimer = null;
235 scene.flush(); 249 scene.flush();
236 } 250 }
251 };
237 252
253 class Omnibox {
254 constructor(contentQuadId) {
255 this.setSecure(false);
256 this.domUiElement = new DomUiElement('#omni');
257 let update = new api.UiElementUpdate();
258 update.setVisible(false);
259 scene.updateElement(this.domUiElement.uiElementId, update);
260 }
261
262 show(visible) {
263 let update = new api.UiElementUpdate();
264 update.setVisible(visible);
265 scene.updateElement(this.domUiElement.uiElementId, update);
266 }
267
268 setLoading(loading) {
269 this.domUiElement.domElement.className = loading ? 'loading' : 'idle';
270 }
271
272 setURL(host, path) {
273 let omnibox = this.domUiElement.domElement;
274 omnibox.querySelector('#domain').innerHTML = host;
275 omnibox.querySelector('#path').innerHTML = path;
276 }
277
278 setSecure(secure) {
279 let image = secure ? 'lock.svg' : 'i_circle.svg';
280 let path = '../../../../ui/webui/resources/images/' + image;
281 document.querySelector('#connection-security').src = path;
282 }
238 }; 283 };
239 284
240 class SceneManager { 285 class SceneManager {
241 constructor() { 286 constructor() {
242 this.mode = api.Mode.UNKNOWN; 287 this.mode = api.Mode.UNKNOWN;
243 288
244 this.contentQuad = new ContentQuad(); 289 this.contentQuad = new ContentQuad();
245 let contentId = this.contentQuad.getElementId(); 290 let contentId = this.contentQuad.getElementId();
246 291
247 this.controls = new Controls(contentId); 292 this.controls = new Controls(contentId);
248 this.secureOriginWarnings = new SecureOriginWarnings(); 293 this.secureOriginWarnings = new SecureOriginWarnings();
294 this.omnibox = new Omnibox(contentId);
249 } 295 }
250 296
251 setMode(mode) { 297 setMode(mode) {
252 this.mode = mode; 298 this.mode = mode;
253 this.contentQuad.show(mode == api.Mode.STANDARD); 299 this.contentQuad.show(mode == api.Mode.STANDARD);
254 this.controls.show(mode == api.Mode.STANDARD); 300 this.controls.show(mode == api.Mode.STANDARD);
301 this.omnibox.show(mode == api.Mode.STANDARD);
255 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR); 302 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR);
256 } 303 }
257 304
258 setSecureOrigin(secure) { 305 setSecureOrigin(secure) {
259 this.secureOriginWarnings.setSecureOrigin(secure); 306 this.secureOriginWarnings.setSecureOrigin(secure);
260 } 307 }
261 308
262 setReloadUiEnabled(enabled) { 309 setReloadUiEnabled(enabled) {
263 console.log('ENABLE');
264 this.controls.setReloadUiEnabled(enabled); 310 this.controls.setReloadUiEnabled(enabled);
265 } 311 }
266 }; 312 };
267 313
268 function initialize() { 314 function initialize() {
269 sceneManager = new SceneManager(); 315 sceneManager = new SceneManager();
270 scene.flush(); 316 scene.flush();
271 317
272 api.domLoaded(); 318 api.domLoaded();
273 } 319 }
274 320
275 function command(dict) { 321 function command(dict) {
276 if ('mode' in dict) { 322 if ('mode' in dict) {
277 sceneManager.setMode(dict['mode']); 323 sceneManager.setMode(dict['mode']);
278 } 324 }
279 if ('secureOrigin' in dict) { 325 if ('secureOrigin' in dict) {
280 sceneManager.setSecureOrigin(dict['secureOrigin']); 326 sceneManager.setSecureOrigin(dict['secureOrigin']);
281 } 327 }
282 if ('enableReloadUi' in dict) { 328 if ('enableReloadUi' in dict) {
283 sceneManager.setReloadUiEnabled(dict['enableReloadUi']); 329 sceneManager.setReloadUiEnabled(dict['enableReloadUi']);
284 } 330 }
331 if ('url' in dict) {
332 let url = dict['url'];
333 sceneManager.omnibox.setURL(url['host'], url['path']);
334 }
335 if ('loading' in dict) {
336 sceneManager.omnibox.setLoading(dict['loading']);
337 }
285 scene.flush(); 338 scene.flush();
286 } 339 }
287 340
288 return { 341 return {
289 initialize: initialize, 342 initialize: initialize,
290 command: command, 343 command: command,
291 }; 344 };
292 })(); 345 })();
293 346
294 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); 347 document.addEventListener('DOMContentLoaded', vrShellUi.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698