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

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

Issue 2592143002: First cut of JS closure compiler use for VR HTML UI. (Closed)
Patch Set: Remove test file. Created 3 years, 12 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
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 api = (function() { 5 var api = new Object();
6 'use strict'; 6
7 7 /**
8 /** 8 * Enumeration of scene update commands.
9 * Enumeration of scene update commands. 9 * @enum {number}
10 * @enum {number} 10 * @const
11 * @const 11 */
12 */ 12 api.Command = {
13 var Command = Object.freeze({
14 'ADD_ELEMENT': 0, 13 'ADD_ELEMENT': 0,
15 'UPDATE_ELEMENT': 1, 14 'UPDATE_ELEMENT': 1,
16 'REMOVE_ELEMENT': 2, 15 'REMOVE_ELEMENT': 2,
17 'ADD_ANIMATION': 3, 16 'ADD_ANIMATION': 3,
18 'REMOVE_ANIMATION': 4 17 'REMOVE_ANIMATION': 4
19 }); 18 };
20 19
21 /** 20 /**
22 * Sends one or more commands to native scene management. Commands are used 21 * Sends one or more commands to native scene management. Commands are used
23 * to add, modify or remove elements and animations. For examples of how to 22 * to add, modify or remove elements and animations. For examples of how to
24 * format command parameters, refer to examples in scene.js. 23 * format command parameters, refer to examples in scene.js.
25 */ 24 * @param {Array} commands
amp 2016/12/21 20:58:58 Doesn't close support specifying the type of the o
Dan Beam 2016/12/22 00:18:21 yes, you can templatize types in closure, so Array
cjgrant 2016/12/22 18:15:46 Cool. Yep, there's a lot more we can do - this re
26 function sendCommands(commands) { 25 */
27 chrome.send('updateScene', commands); 26 api.sendCommands = function(commands) {
28 } 27 chrome.send('updateScene', commands);
29 28 };
30 /** 29
31 * Returns the element ID of the browser content quad, allowing the content to 30 /**
32 * be manimulated in the scene. 31 * Enumeration of valid Anchroing for X axis.
33 */ 32 * An element can either be anchored to the left, right, or center of the main
34 function getContentElementId() { 33 * content rect (or it can be absolutely positioned using NONE). Any
35 return 0; 34 * translations applied will be relative to this anchoring.
36 } 35 * @enum {number}
37 36 * @const
38 /** 37 */
39 * Enumeration of valid Anchroing for X axis. 38 api.XAnchoring = {
40 * An element can either be anchored to the left, right, or center of the main 39 'XNONE': 0,
41 * content rect (or it can be absolutely positioned using NONE). Any 40 'XLEFT': 1,
42 * translations applied will be relative to this anchoring. 41 'XRIGHT': 2
43 * @enum {number} 42 };
44 * @const 43
45 */ 44 /**
46 var XAnchoring = Object.freeze({ 45 * Enumeration of valid Anchroing for Y axis.
47 'XNONE': 0, 46 * @enum {number}
48 'XLEFT': 1, 47 * @const
49 'XRIGHT': 2 48 */
50 }); 49 api.YAnchoring = {
51 50 'YNONE': 0,
52 /** 51 'YTOP': 1,
53 * Enumeration of valid Anchroing for Y axis. 52 'YBOTTOM': 2
54 * @enum {number} 53 };
55 * @const 54
56 */ 55 /**
57 var YAnchoring = Object.freeze({ 56 * Enumeration of actions that can be triggered by the HTML UI.
58 'YNONE': 0, 57 * @enum {number}
59 'YTOP': 1, 58 * @const
60 'YBOTTOM': 2 59 */
61 }); 60 api.Action = {
62 61 'HISTORY_BACK': 0,
63 /** 62 'HISTORY_FORWARD': 1,
64 * Enumeration of actions that can be triggered by the HTML UI. 63 'RELOAD': 2,
65 * @enum {number} 64 'ZOOM_OUT': 3,
66 * @const 65 'ZOOM_IN': 4,
67 */ 66 'RELOAD_UI': 5,
68 var Action = Object.freeze({ 67 };
69 'HISTORY_BACK': 0, 68
70 'HISTORY_FORWARD': 1, 69 /**
71 'RELOAD': 2, 70 * Enumeration of modes that can be specified by the native side.
72 'ZOOM_OUT': 3, 71 * @enum {number}
73 'ZOOM_IN': 4, 72 * @const
74 'RELOAD_UI': 5, 73 */
75 }); 74 api.Mode = {
76 75 'UNKNOWN': -1,
77 /** 76 'STANDARD': 0,
78 * Enumeration of modes that can be specified by the native side. 77 'WEB_VR': 1,
79 * @enum {number} 78 };
80 * @const 79
81 */ 80 /**
82 var Mode = Object.freeze({ 81 * Triggers an Action.
83 'UNKNOWN': -1, 82 * @param {api.Action} action
84 'STANDARD': 0, 83 */
85 'WEB_VR': 1, 84 function doAction(action) {
86 }); 85 chrome.send('doAction', [action]);
87 86 }
88 /** 87
89 * Triggers an Action. 88 /**
90 */ 89 * Notify native scene management that DOM loading has completed, at the
91 function doAction(action) { 90 * specified page size.
92 chrome.send('doAction', [action]); 91 */
93 } 92 function domLoaded() {
94 93 chrome.send('domLoaded');
95 /** 94 }
96 * Notify native scene management that DOM loading has completed, at the 95
97 * specified page size. 96 /**
98 */ 97 * Sets the CSS size for this page.
99 function domLoaded() { 98 * @param {number} width
100 chrome.send('domLoaded'); 99 * @param {number} height
101 } 100 * @param {number} dpr
102 101 */
103 /** 102 function setUiCssSize(width, height, dpr) {
104 * Sets the CSS size for this page. 103 chrome.send('setUiCssSize', [width, height, dpr]);
105 */ 104 }
106 function setUiCssSize(width, height, dpr) { 105
107 chrome.send('setUiCssSize', [width, height, dpr]); 106 /**
108 } 107 * Represents updates to UI element properties. Any properties set on this
109 108 * object are relayed to an underlying native element via scene command.
110 /** 109 * Properties that are not set on this object are left unchanged.
111 * Represents updates to UI element properties. Any properties set on this 110 * @export
112 * object are relayed to an underlying native element via scene command. 111 */
113 * Properties that are not set on this object are left unchanged. 112 api.UiElementUpdate = class {
114 */ 113
115 class UiElementUpdate { 114 constructor() {
116 115
117 setIsContentQuad() { 116 this.properties = {};
amp 2016/12/21 20:58:58 It looks like properties could be a well defined o
cjgrant 2016/12/22 18:15:46 As of now, native parses a dictionary, and updates
118 this.contentQuad = true;
119 }
120 117
121 /** 118 /**
122 * Specify a parent for this element. If set, this element is positioned 119 * Handlers that are listening to this logger.
123 * relative to its parent element, rather than absolutely. This allows 120 * @private {number}
124 * elements to automatically move with a parent.
125 */ 121 */
126 setParentId(id) { 122 this.varvar = 1;
amp 2016/12/21 20:58:58 I can't remember if this was specifically restrict
cjgrant 2016/12/22 18:15:46 Yeah, this is test code.
127 this.parentId = id; 123 }
128 } 124
129 125 /**
130 /** 126 * Operates on an instance of MyClass and returns something.
amp 2016/12/21 20:58:58 Bad copy paste?
131 * Specify the width and height (in meters) of an element. 127 */
132 */ 128 setIsContentQuad() {
133 setSize(x, y) { 129 this.properties['contentQuad'] = true;
134 this.size = { x: x, y: y }; 130 }
135 } 131
136 132 /**
137 /** 133 * Specify a parent for this element. If set, this element is positioned
138 * Specify optional scaling of the element, and any children. 134 * relative to its parent element, rather than absolutely. This allows
139 */ 135 * elements to automatically move with a parent.
140 setScale(x, y, z) { 136 * @param {number} id
141 this.scale = { x: x, y: y, z: z }; 137 */
142 } 138 setParentId(id) {
143 139 this.properties['parentId'] = id;
144 /** 140 }
145 * Specify rotation for the element. The rotation is specified in axis-angle 141
146 * representation (rotate around unit vector [x, y, z] by 'a' radians). 142 /**
147 */ 143 * Specify the width and height (in meters) of an element.
148 setRotation(x, y, z, a) { 144 * @param {number} x
149 this.rotation = { x: x, y: y, z: z, a: a }; 145 * @param {number} y
150 } 146 */
151 147 setSize(x, y) {
152 /** 148 this.properties['size'] = { x: x, y: y };
153 * Specify the translation of the element. If anchoring is specified, the 149 }
154 * offset is applied to the anchoring position rather than the origin. 150
155 * Translation is applied after scaling and rotation. 151 /**
156 */ 152 * Specify optional scaling of the element, and any children.
157 setTranslation(x, y, z) { 153 * @param {number} x
158 this.translation = { x: x, y: y, z: z }; 154 * @param {number} y
159 } 155 * @param {number} z
160 156 */
161 /** 157 setScale(x, y, z) {
162 * Anchoring allows a rectangle to be positioned relative to the edge of 158 this.properties['scale'] = { x: x, y: y, z: z };
163 * its parent, without being concerned about the size of the parent. 159 }
164 * Values should be XAnchoring and YAnchoring elements. 160
165 * Example: element.setAnchoring(XAnchoring.XNONE, YAnchoring.YBOTTOM); 161 /**
166 */ 162 * Specify rotation for the element. The rotation is specified in axis-angle
167 setAnchoring(x, y) { 163 * representation (rotate around unit vector [x, y, z] by 'a' radians).
168 this.xAnchoring = x; 164 * @param {number} x
169 this.yAnchoring = y; 165 * @param {number} y
170 } 166 * @param {number} z
171 167 * @param {number} a
172 /** 168 */
173 * Visibility controls whether the element is rendered. 169 setRotation(x, y, z, a) {
174 */ 170 this.properties['rotation'] = { x: x, y: y, z: z, a: a };
175 setVisible(visible) { 171
176 this.visible = !!visible; 172 //this.setTranslation(1, 2, 'cat');
amp 2016/12/21 20:58:58 Remove comment.
177 } 173 }
178 174
179 /** 175 /**
180 * Hit-testable implies that the reticle will hit the element, if visible. 176 * Specify the translation of the element. If anchoring is specified, the
181 */ 177 * offset is applied to the anchoring position rather than the origin.
182 setHitTestable(testable) { 178 * Translation is applied after scaling and rotation.
183 this.hitTestable = !!testable; 179 * @param {number} x
184 } 180 * @param {number} y
185 181 * @param {number} z
186 /** 182 */
187 * Causes an element to be rendered relative to the field of view, rather 183
188 * than the scene. Elements locked in this way should not have a parent. 184 // TODO - also test private member enforcement.
189 */ 185
190 setLockToFieldOfView(locked) { 186 setTranslation(x, y, z) {
191 this.lockToFov = !!locked; 187 this.properties['translation'] = { x: x, y: y, z: z };
192 } 188 }
193 }; 189
194 190 /**
195 /** 191 * Anchoring allows a rectangle to be positioned relative to the edge of
196 * Represents a new UI element. This object builds on UiElementUpdate, 192 * its parent, without being concerned about the size of the parent.
197 * forcing the underlying texture coordinates to be specified. 193 * Values should be XAnchoring and YAnchoring elements.
198 */ 194 * Example: element.setAnchoring(XAnchoring.XNONE, YAnchoring.YBOTTOM);
199 class UiElement extends UiElementUpdate { 195 * @param {number} x
200 /** 196 * @param {number} y
201 * Constructor of UiElement. 197 */
202 * pixelX and pixelY values indicate the left upper corner; pixelWidth and 198 setAnchoring(x, y) {
203 * pixelHeight is width and height of the texture to be copied from the web 199 this.properties['xAnchoring'] = x;
204 * contents. 200 this.properties['yAnchoring'] = y;
205 */ 201 }
206 constructor(pixelX, pixelY, pixelWidth, pixelHeight) { 202
207 super(); 203 /**
208 204 * Visibility controls whether the element is rendered.
209 this.copyRect = { 205 * @param {boolean} visible
210 x: pixelX, 206 */
211 y: pixelY, 207 setVisible(visible) {
212 width: pixelWidth, 208 this.properties['visible'] = !!visible;
213 height: pixelHeight 209 }
214 }; 210
215 } 211 /**
216 }; 212 * Hit-testable implies that the reticle will hit the element, if visible.
217 213 * @param {boolean} testable
218 /** 214 */
219 * Enumeration of animatable properties. 215 setHitTestable(testable) {
220 * @enum {number} 216 this.properties['hitTestable'] = !!testable;
221 * @const 217 }
222 */ 218
223 var Property = Object.freeze({ 219 /**
224 'COPYRECT': 0, 220 * Causes an element to be rendered relative to the field of view, rather
225 'SIZE': 1, 221 * than the scene. Elements locked in this way should not have a parent.
226 'TRANSLATION': 2, 222 * @param {boolean} locked
227 'ORIENTATION': 3, 223 */
228 'ROTATION': 4 224 setLockToFieldOfView(locked) {
229 }); 225 this.properties['lockToFov'] = !!locked;
230 226 }
231 /** 227 };
232 * Enumeration of easing type. 228
233 * @enum {number} 229 /**
234 * @const 230 * Represents a new UI element. This object builds on UiElementUpdate,
235 */ 231 * forcing the underlying texture coordinates to be specified.
236 var Easing = Object.freeze({ 232 */
237 'LINEAR': 0, 233 api.UiElement = class extends api.UiElementUpdate {
238 'CUBICBEZIER': 1, 234 /**
239 'EASEIN': 2, 235 * Constructor of UiElement.
240 'EASEOUT': 3 236 * pixelX and pixelY values indicate the left upper corner; pixelWidth and
241 }); 237 * pixelHeight is width and height of the texture to be copied from the web
242 238 * contents.
243 /** 239 */
244 * Base animation class. An animation can vary only one object property. 240 constructor(pixelX, pixelY, pixelWidth, pixelHeight) {
245 */ 241 super();
246 class Animation { 242
247 constructor(elementId, durationMs) { 243 this.copyRect = {
248 this.meshId = elementId; 244 x: pixelX,
249 this.to = {}; 245 y: pixelY,
250 this.easing = {}; 246 width: pixelWidth,
251 this.easing.type = api.Easing.LINEAR; 247 height: pixelHeight
252 248 };
253 // How many milliseconds in the future to start the animation. 249 }
254 this.startInMillis = 0.0; 250 };
255 251
256 // Duration of the animation (milliseconds). 252 /**
257 this.durationMillis = durationMs; 253 * Enumeration of animatable properties.
258 } 254 * @enum {number}
259 255 * @const
260 /** 256 */
261 * Set the animation's final element size. 257 api.Property = {
262 */ 258 'COPYRECT': 0,
263 setSize(width, height) { 259 'SIZE': 1,
264 this.property = api.Property.SIZE; 260 'TRANSLATION': 2,
265 this.to.x = width; 261 'SCALE': 3,
266 this.to.y = height; 262 'ROTATION': 4
267 } 263 };
268 264
269 /** 265 /**
270 * Set the animation's final element scale. 266 * Enumeration of easing type.
271 */ 267 * @enum {number}
272 setScale(x, y, z) { 268 * @const
273 this.property = api.Property.SCALE; 269 */
274 this.to.x = x; 270 api.Easing = {
275 this.to.y = y; 271 'LINEAR': 0,
276 this.to.z = z; 272 'CUBICBEZIER': 1,
277 } 273 'EASEIN': 2,
278 274 'EASEOUT': 3
279 /** 275 };
280 * Set the animation's final element rotation. 276
281 */ 277 /**
282 setRotation(x, y, z, a) { 278 * Base animation class. An animation can vary only one object property.
283 this.property = api.Property.ROTATION; 279 */
284 this.to.x = x; 280 api.Animation = class {
285 this.to.y = y; 281 constructor(elementId, durationMs) {
286 this.to.z = z; 282 this.meshId = elementId;
287 this.to.a = a; 283 this.property = -1;
288 } 284 this.to = {};
289 285 this.easing = {};
290 /** 286 this.easing.type = api.Easing.LINEAR;
291 * Set the animation's final element translation. 287
292 */ 288 // How many milliseconds in the future to start the animation.
293 setTranslation(x, y, z) { 289 this.startInMillis = 0.0;
294 this.property = api.Property.TRANSLATION; 290
295 this.to.x = x; 291 // Duration of the animation (milliseconds).
296 this.to.y = y; 292 this.durationMillis = durationMs;
297 this.to.z = z; 293 }
298 } 294
299 }; 295 /**
300 296 * Set the animation's final element size.
301 return { 297 * @param {number} width
302 sendCommands: sendCommands, 298 * @param {number} height
303 XAnchoring: XAnchoring, 299 */
304 YAnchoring: YAnchoring, 300 setSize(width, height) {
305 Property: Property, 301 this.property = api.Property.SIZE;
306 Easing: Easing, 302 this.to.x = width;
307 Command: Command, 303 this.to.y = height;
308 Action: Action, 304 }
309 Mode: Mode, 305
310 getContentElementId: getContentElementId, 306 /**
311 UiElement: UiElement, 307 * Set the animation's final element scale.
312 UiElementUpdate: UiElementUpdate, 308 * @param {number} x
313 Animation: Animation, 309 * @param {number} y
314 doAction: doAction, 310 * @param {number} z
315 domLoaded: domLoaded, 311 */
316 setUiCssSize: setUiCssSize, 312 setScale(x, y, z) {
317 }; 313 this.property = api.Property.SCALE;
318 })(); 314 this.to.x = x;
315 this.to.y = y;
316 this.to.z = z;
317 }
318
319 /**
320 * Set the animation's final element rotation.
321 * @param {number} x
322 * @param {number} y
323 * @param {number} z
324 * @param {number} a
325 */
326 setRotation(x, y, z, a) {
327 this.property = api.Property.ROTATION;
328 this.to.x = x;
329 this.to.y = y;
330 this.to.z = z;
331 this.to.a = a;
332 }
333
334 /**
335 * Set the animation's final element translation.
336 * @param {number} x
337 * @param {number} y
338 * @param {number} z
339 */
340 setTranslation(x, y, z) {
341 this.property = api.Property.TRANSLATION;
342 this.to.x = x;
343 this.to.y = y;
344 this.to.z = z;
345 }
346 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/vr_shell/vr_shell_ui.js ('k') | chrome/browser/resources/vr_shell/vr_shell_ui_scene.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698