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

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: Created 4 years 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 = (function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Enumeration of scene update commands. 9 * Enumeration of scene update commands.
10 * @enum {number} 10 * @enum {number}
11 * @const 11 * @const
12 */ 12 */
13 var Command = Object.freeze({ 13 var Command = {
14 'ADD_ELEMENT': 0, 14 'ADD_ELEMENT': 0,
15 'UPDATE_ELEMENT': 1, 15 'UPDATE_ELEMENT': 1,
16 'REMOVE_ELEMENT': 2, 16 'REMOVE_ELEMENT': 2,
17 'ADD_ANIMATION': 3, 17 'ADD_ANIMATION': 3,
18 'REMOVE_ANIMATION': 4 18 'REMOVE_ANIMATION': 4
19 }); 19 };
20 20
21 /** 21 /**
22 * Sends one or more commands to native scene management. Commands are used 22 * 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 23 * to add, modify or remove elements and animations. For examples of how to
24 * format command parameters, refer to examples in scene.js. 24 * format command parameters, refer to examples in scene.js.
25 */ 25 */
26 function sendCommands(commands) { 26 function sendCommands(commands) {
27 chrome.send('updateScene', commands); 27 chrome.send('updateScene', commands);
28 } 28 }
29 29
30 /** 30 /**
31 * Returns the element ID of the browser content quad, allowing the content to 31 * Returns the element ID of the browser content quad, allowing the content to
32 * be manimulated in the scene. 32 * be manimulated in the scene.
33 */ 33 */
34 function getContentElementId() { 34 function getContentElementId() {
35 return 0; 35 return 0;
36 } 36 }
37 37
38 /** 38 /**
39 * Enumeration of valid Anchroing for X axis. 39 * Enumeration of valid Anchroing for X axis.
40 * An element can either be anchored to the left, right, or center of the main 40 * An element can either be anchored to the left, right, or center of the main
41 * content rect (or it can be absolutely positioned using NONE). Any 41 * content rect (or it can be absolutely positioned using NONE). Any
42 * translations applied will be relative to this anchoring. 42 * translations applied will be relative to this anchoring.
43 * @enum {number} 43 * @enum {number}
44 * @const 44 * @const
45 */ 45 */
46 var XAnchoring = Object.freeze({ 46 var XAnchoring = {
47 'XNONE': 0, 47 'XNONE': 0,
48 'XLEFT': 1, 48 'XLEFT': 1,
49 'XRIGHT': 2 49 'XRIGHT': 2
50 }); 50 };
51 51
52 /** 52 /**
53 * Enumeration of valid Anchroing for Y axis. 53 * Enumeration of valid Anchroing for Y axis.
54 * @enum {number} 54 * @enum {number}
55 * @const 55 * @const
56 */ 56 */
57 var YAnchoring = Object.freeze({ 57 var YAnchoring = {
58 'YNONE': 0, 58 'YNONE': 0,
59 'YTOP': 1, 59 'YTOP': 1,
60 'YBOTTOM': 2 60 'YBOTTOM': 2
61 }); 61 };
62 62
63 /** 63 /**
64 * Enumeration of actions that can be triggered by the HTML UI. 64 * Enumeration of actions that can be triggered by the HTML UI.
65 * @enum {number} 65 * @enum {number}
66 * @const 66 * @const
67 */ 67 */
68 var Action = Object.freeze({ 68 var Action = {
69 'HISTORY_BACK': 0, 69 'HISTORY_BACK': 0,
70 'HISTORY_FORWARD': 1, 70 'HISTORY_FORWARD': 1,
71 'RELOAD': 2, 71 'RELOAD': 2,
72 'ZOOM_OUT': 3, 72 'ZOOM_OUT': 3,
73 'ZOOM_IN': 4, 73 'ZOOM_IN': 4,
74 'RELOAD_UI': 5, 74 'RELOAD_UI': 5,
75 }); 75 };
76 76
77 /** 77 /**
78 * Enumeration of modes that can be specified by the native side. 78 * Enumeration of modes that can be specified by the native side.
79 * @enum {number} 79 * @enum {number}
80 * @const 80 * @const
81 */ 81 */
82 var Mode = Object.freeze({ 82 var Mode = {
83 'UNKNOWN': -1, 83 'UNKNOWN': -1,
84 'STANDARD': 0, 84 'STANDARD': 0,
85 'WEB_VR': 1, 85 'WEB_VR': 1,
86 }); 86 };
87 87
88 /** 88 /**
89 * Triggers an Action. 89 * Triggers an Action.
90 */ 90 */
91 function doAction(action) { 91 function doAction(action) {
92 chrome.send('doAction', [action]); 92 chrome.send('doAction', [action]);
93 } 93 }
94 94
95 /** 95 /**
96 * Notify native scene management that DOM loading has completed, at the 96 * Notify native scene management that DOM loading has completed, at the
(...skipping 10 matching lines...) Expand all
107 chrome.send('setUiCssSize', [width, height, dpr]); 107 chrome.send('setUiCssSize', [width, height, dpr]);
108 } 108 }
109 109
110 /** 110 /**
111 * Represents updates to UI element properties. Any properties set on this 111 * Represents updates to UI element properties. Any properties set on this
112 * object are relayed to an underlying native element via scene command. 112 * object are relayed to an underlying native element via scene command.
113 * Properties that are not set on this object are left unchanged. 113 * Properties that are not set on this object are left unchanged.
114 */ 114 */
115 class UiElementUpdate { 115 class UiElementUpdate {
116 116
117 setIsContentQuad() { 117 constructor() {
118 this.contentQuad = true; 118 this.properties = {};
119 } 119 }
120 120
121 /** 121 /**
122 * Operates on an instance of MyClass and returns something.
123 */
124 setIsContentQuad() {
125 this.properties['contentQuad'] = true;
126 }
127
128 /**
122 * Specify a parent for this element. If set, this element is positioned 129 * Specify a parent for this element. If set, this element is positioned
123 * relative to its parent element, rather than absolutely. This allows 130 * relative to its parent element, rather than absolutely. This allows
124 * elements to automatically move with a parent. 131 * elements to automatically move with a parent.
125 */ 132 */
126 setParentId(id) { 133 setParentId(id) {
127 this.parentId = id; 134 this.properties['parentId'] = id;
128 } 135 }
129 136
130 /** 137 /**
131 * Specify the width and height (in meters) of an element. 138 * Specify the width and height (in meters) of an element.
132 */ 139 */
133 setSize(x, y) { 140 setSize(x, y) {
134 this.size = { x: x, y: y }; 141 this.properties['size'] = { x: x, y: y };
135 } 142 }
136 143
137 /** 144 /**
138 * Specify optional scaling of the element, and any children. 145 * Specify optional scaling of the element, and any children.
139 */ 146 */
140 setScale(x, y, z) { 147 setScale(x, y, z) {
141 this.scale = { x: x, y: y, z: z }; 148 this.properties['scale'] = { x: x, y: y, z: z };
142 } 149 }
143 150
144 /** 151 /**
145 * Specify rotation for the element. The rotation is specified in axis-angle 152 * Specify rotation for the element. The rotation is specified in axis-angle
146 * representation (rotate around unit vector [x, y, z] by 'a' radians). 153 * representation (rotate around unit vector [x, y, z] by 'a' radians).
147 */ 154 */
148 setRotation(x, y, z, a) { 155 setRotation(x, y, z, a) {
149 this.rotation = { x: x, y: y, z: z, a: a }; 156 this.properties['rotation'] = { x: x, y: y, z: z, a: a };
150 } 157 }
151 158
152 /** 159 /**
153 * Specify the translation of the element. If anchoring is specified, the 160 * Specify the translation of the element. If anchoring is specified, the
154 * offset is applied to the anchoring position rather than the origin. 161 * offset is applied to the anchoring position rather than the origin.
155 * Translation is applied after scaling and rotation. 162 * Translation is applied after scaling and rotation.
163 * @param {number} x
164 * @param {number} y
165 * @param {number} z
156 */ 166 */
157 setTranslation(x, y, z) { 167
158 this.translation = { x: x, y: y, z: z }; 168 // TODO - also test private member enforcement.
169
170 setTranslation(x, y, z, w) {
171 this.properties['translation'] = { x: x, y: y, z: z };
159 } 172 }
160 173
161 /** 174 /**
162 * Anchoring allows a rectangle to be positioned relative to the edge of 175 * Anchoring allows a rectangle to be positioned relative to the edge of
163 * its parent, without being concerned about the size of the parent. 176 * its parent, without being concerned about the size of the parent.
164 * Values should be XAnchoring and YAnchoring elements. 177 * Values should be XAnchoring and YAnchoring elements.
165 * Example: element.setAnchoring(XAnchoring.XNONE, YAnchoring.YBOTTOM); 178 * Example: element.setAnchoring(XAnchoring.XNONE, YAnchoring.YBOTTOM);
166 */ 179 */
167 setAnchoring(x, y) { 180 setAnchoring(x, y) {
168 this.xAnchoring = x; 181 this.properties['xAnchoring'] = x;
169 this.yAnchoring = y; 182 this.properties['yAnchoring'] = y;
170 } 183 }
171 184
172 /** 185 /**
173 * Visibility controls whether the element is rendered. 186 * Visibility controls whether the element is rendered.
174 */ 187 */
175 setVisible(visible) { 188 setVisible(visible) {
176 this.visible = !!visible; 189 this.properties['visible'] = !!visible;
177 } 190 }
178 191
179 /** 192 /**
180 * Hit-testable implies that the reticle will hit the element, if visible. 193 * Hit-testable implies that the reticle will hit the element, if visible.
181 */ 194 */
182 setHitTestable(testable) { 195 setHitTestable(testable) {
183 this.hitTestable = !!testable; 196 this.properties['hitTestable'] = !!testable;
184 } 197 }
185 198
186 /** 199 /**
187 * Causes an element to be rendered relative to the field of view, rather 200 * Causes an element to be rendered relative to the field of view, rather
188 * than the scene. Elements locked in this way should not have a parent. 201 * than the scene. Elements locked in this way should not have a parent.
189 */ 202 */
190 setLockToFieldOfView(locked) { 203 setLockToFieldOfView(locked) {
191 this.lockToFov = !!locked; 204 this.properties['lockToFov'] = !!locked;
192 } 205 }
193 }; 206 };
194 207
195 /** 208 /**
196 * Represents a new UI element. This object builds on UiElementUpdate, 209 * Represents a new UI element. This object builds on UiElementUpdate,
197 * forcing the underlying texture coordinates to be specified. 210 * forcing the underlying texture coordinates to be specified.
198 */ 211 */
199 class UiElement extends UiElementUpdate { 212 class UiElement extends UiElementUpdate {
200 /** 213 /**
201 * Constructor of UiElement. 214 * Constructor of UiElement.
(...skipping 11 matching lines...) Expand all
213 height: pixelHeight 226 height: pixelHeight
214 }; 227 };
215 } 228 }
216 }; 229 };
217 230
218 /** 231 /**
219 * Enumeration of animatable properties. 232 * Enumeration of animatable properties.
220 * @enum {number} 233 * @enum {number}
221 * @const 234 * @const
222 */ 235 */
223 var Property = Object.freeze({ 236 var Property = {
224 'COPYRECT': 0, 237 'COPYRECT': 0,
225 'SIZE': 1, 238 'SIZE': 1,
226 'TRANSLATION': 2, 239 'TRANSLATION': 2,
227 'ORIENTATION': 3, 240 'SCALE': 3,
228 'ROTATION': 4 241 'ROTATION': 4
229 }); 242 };
230 243
231 /** 244 /**
232 * Enumeration of easing type. 245 * Enumeration of easing type.
233 * @enum {number} 246 * @enum {number}
234 * @const 247 * @const
235 */ 248 */
236 var Easing = Object.freeze({ 249 var Easing = {
237 'LINEAR': 0, 250 'LINEAR': 0,
238 'CUBICBEZIER': 1, 251 'CUBICBEZIER': 1,
239 'EASEIN': 2, 252 'EASEIN': 2,
240 'EASEOUT': 3 253 'EASEOUT': 3
241 }); 254 };
242 255
243 /** 256 /**
244 * Base animation class. An animation can vary only one object property. 257 * Base animation class. An animation can vary only one object property.
245 */ 258 */
246 class Animation { 259 class Animation {
247 constructor(elementId, durationMs) { 260 constructor(elementId, durationMs) {
248 this.meshId = elementId; 261 this.meshId = elementId;
262 this.property = -1;
249 this.to = {}; 263 this.to = {};
250 this.easing = {}; 264 this.easing = {};
251 this.easing.type = api.Easing.LINEAR; 265 this.easing.type = api.Easing.LINEAR;
252 266
253 // How many milliseconds in the future to start the animation. 267 // How many milliseconds in the future to start the animation.
254 this.startInMillis = 0.0; 268 this.startInMillis = 0.0;
255 269
256 // Duration of the animation (milliseconds). 270 // Duration of the animation (milliseconds).
257 this.durationMillis = durationMs; 271 this.durationMillis = durationMs;
258 } 272 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 Mode: Mode, 323 Mode: Mode,
310 getContentElementId: getContentElementId, 324 getContentElementId: getContentElementId,
311 UiElement: UiElement, 325 UiElement: UiElement,
312 UiElementUpdate: UiElementUpdate, 326 UiElementUpdate: UiElementUpdate,
313 Animation: Animation, 327 Animation: Animation,
314 doAction: doAction, 328 doAction: doAction,
315 domLoaded: domLoaded, 329 domLoaded: domLoaded,
316 setUiCssSize: setUiCssSize, 330 setUiCssSize: setUiCssSize,
317 }; 331 };
318 })(); 332 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698