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

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

Issue 2442873002: Control the VrShell content quad via the HTML UI. (Closed)
Patch Set: Rebase; address nits and bug. 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 class ContentQuad {
12 constructor() {
13 /** @const */ var SCREEN_HEIGHT = 1.6;
14 /** @const */ var SCREEN_DISTANCE = 2.0;
15
16 let element = new api.UiElement(0, 0, 0, 0);
17 element.setIsContentQuad(false);
18 element.setVisible(false);
19 element.setSize(SCREEN_HEIGHT * 16 / 9, SCREEN_HEIGHT);
20 element.setTranslation(0, 0, -SCREEN_DISTANCE);
21 this.elementId = scene.addElement(element);
22 }
23
24 show(visible) {
25 let update = new api.UiElementUpdate();
26 update.setVisible(visible);
27 scene.updateElement(this.elementId, update);
28 }
29
30 getElementId() {
31 return this.elementId;
32 }
33 };
34
11 class DomUiElement { 35 class DomUiElement {
12 constructor(domId) { 36 constructor(domId) {
13 let domElement = document.querySelector(domId); 37 let domElement = document.querySelector(domId);
14 let style = window.getComputedStyle(domElement); 38 let style = window.getComputedStyle(domElement);
15 39
16 // Pull copy rectangle from DOM element properties. 40 // Pull copy rectangle from DOM element properties.
17 let pixelX = domElement.offsetLeft; 41 let pixelX = domElement.offsetLeft;
18 let pixelY = domElement.offsetTop; 42 let pixelY = domElement.offsetTop;
19 let pixelWidth = parseInt(style.getPropertyValue('width')); 43 let pixelWidth = parseInt(style.getPropertyValue('width'));
20 let pixelHeight = parseInt(style.getPropertyValue('height')); 44 let pixelHeight = parseInt(style.getPropertyValue('height'));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 onMouseEnter() { 79 onMouseEnter() {
56 this.configure(1, 1, 0.015); 80 this.configure(1, 1, 0.015);
57 } 81 }
58 82
59 onMouseLeave() { 83 onMouseLeave() {
60 this.configure(0.8, 0, 0); 84 this.configure(0.8, 0, 0);
61 } 85 }
62 }; 86 };
63 87
64 class Controls { 88 class Controls {
65 constructor() { 89 constructor(contentQuadId) {
66 this.buttons = []; 90 this.buttons = [];
67 let descriptors = [ 91 let descriptors = [
68 ['#back', function() { 92 ['#back', function() {
69 api.doAction(api.Action.HISTORY_BACK); 93 api.doAction(api.Action.HISTORY_BACK);
70 }], 94 }],
71 ['#reload', function() { 95 ['#reload', function() {
72 api.doAction(api.Action.RELOAD); 96 api.doAction(api.Action.RELOAD);
73 }], 97 }],
74 ['#forward', function() { 98 ['#forward', function() {
75 api.doAction(api.Action.HISTORY_FORWARD); 99 api.doAction(api.Action.HISTORY_FORWARD);
76 }], 100 }],
77 ]; 101 ];
78 102
79 /** @const */ var BUTTON_SPACING = 0.3; 103 /** @const */ var BUTTON_SPACING = 0.3;
80 104
81 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5); 105 let startPosition = -BUTTON_SPACING * (descriptors.length / 2.0 - 0.5);
82 for (let i = 0; i < descriptors.length; i++) { 106 for (let i = 0; i < descriptors.length; i++) {
83 // Use an invisible parent to simplify Z-axis movement on hover. 107 // Use an invisible parent to simplify Z-axis movement on hover.
84 let position = new api.UiElement(0, 0, 0, 0); 108 let position = new api.UiElement(0, 0, 0, 0);
85 position.setParentId(api.getContentElementId()); 109 position.setParentId(contentQuadId);
86 position.setVisible(false); 110 position.setVisible(false);
87 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); 111 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM);
88 position.setTranslation( 112 position.setTranslation(
89 startPosition + i * BUTTON_SPACING, -0.3, 0.3); 113 startPosition + i * BUTTON_SPACING, -0.3, 0.3);
90 let id = scene.addElement(position); 114 let id = scene.addElement(position);
91 115
92 let domId = descriptors[i][0]; 116 let domId = descriptors[i][0];
93 let callback = descriptors[i][1]; 117 let callback = descriptors[i][1];
94 let element = new RoundButton(domId, callback); 118 let element = new RoundButton(domId, callback);
95 this.buttons.push(element); 119 this.buttons.push(element);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 scene.updateElement(this.transientWarning.uiElementId, update); 206 scene.updateElement(this.transientWarning.uiElementId, update);
183 this.secureOriginTimer = null; 207 this.secureOriginTimer = null;
184 scene.flush(); 208 scene.flush();
185 } 209 }
186 210
187 }; 211 };
188 212
189 class SceneManager { 213 class SceneManager {
190 constructor() { 214 constructor() {
191 this.mode = api.Mode.UNKNOWN; 215 this.mode = api.Mode.UNKNOWN;
192 this.controls = new Controls(); 216
217 this.contentQuad = new ContentQuad();
218 let contentId = this.contentQuad.getElementId();
219
220 this.controls = new Controls(contentId);
193 this.secureOriginWarnings = new SecureOriginWarnings(); 221 this.secureOriginWarnings = new SecureOriginWarnings();
194 } 222 }
195 223
196 setMode(mode) { 224 setMode(mode) {
197 this.mode = mode; 225 this.mode = mode;
226 this.contentQuad.show(mode == api.Mode.STANDARD);
198 this.controls.show(mode == api.Mode.STANDARD); 227 this.controls.show(mode == api.Mode.STANDARD);
199 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR); 228 this.secureOriginWarnings.show(mode == api.Mode.WEB_VR);
200 } 229 }
201 230
202 setSecureOrigin(secure) { 231 setSecureOrigin(secure) {
203 this.secureOriginWarnings.setSecureOrigin(secure); 232 this.secureOriginWarnings.setSecureOrigin(secure);
204 } 233 }
205 }; 234 };
206 235
207 function initialize() { 236 function initialize() {
(...skipping 19 matching lines...) Expand all
227 scene.flush(); 256 scene.flush();
228 } 257 }
229 258
230 return { 259 return {
231 initialize: initialize, 260 initialize: initialize,
232 command: command, 261 command: command,
233 }; 262 };
234 })(); 263 })();
235 264
236 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); 265 document.addEventListener('DOMContentLoaded', vrShellUi.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.cc ('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