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

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

Issue 2437823002: Control visibility of 2D VR menu buttons using native state. (Closed)
Patch Set: Address nits. Created 4 years, 2 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 vrShellUi = (function() { 5 var vrShellUi = (function() {
6 'use strict'; 6 'use strict';
7 7
8 var scene = new ui.Scene(); 8 var scene = new ui.Scene();
9 var uiElements = []; 9 var state;
10 10
11 class DomUiElement { 11 class DomUiElement {
12 constructor(domId) { 12 constructor(domId) {
13 var domElement = document.querySelector(domId); 13 var domElement = document.querySelector(domId);
14 var style = window.getComputedStyle(domElement); 14 var style = window.getComputedStyle(domElement);
15 15
16 // Pull copy rectangle from DOM element properties. 16 // Pull copy rectangle from DOM element properties.
17 var pixelX = domElement.offsetLeft; 17 var pixelX = domElement.offsetLeft;
18 var pixelY = domElement.offsetTop; 18 var pixelY = domElement.offsetTop;
19 var pixelWidth = parseInt(style.getPropertyValue('width')); 19 var pixelWidth = parseInt(style.getPropertyValue('width'));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 onMouseEnter() { 55 onMouseEnter() {
56 this.configure(1, 1, 0.015); 56 this.configure(1, 1, 0.015);
57 } 57 }
58 58
59 onMouseLeave() { 59 onMouseLeave() {
60 this.configure(0.8, 0, 0); 60 this.configure(0.8, 0, 0);
61 } 61 }
62 }; 62 };
63 63
64 class Controls {
65 constructor() {
66 this.buttons = [];
67 var descriptors = [
68 ['#back', function() {
69 api.doAction(api.Action.HISTORY_BACK);
70 }],
71 ['#reload', function() {
72 api.doAction(api.Action.RELOAD);
73 }],
74 ['#forward', function() {
75 api.doAction(api.Action.HISTORY_FORWARD);
76 }],
77 ];
78
79 var spacing = 0.3;
80 var startPosition = -spacing * (descriptors.length / 2.0 - 0.5);
81
82 for (var i = 0; i < descriptors.length; i++) {
83 // Use an invisible parent to simplify Z-axis movement on hover.
84 var position = new api.UiElement(0, 0, 0, 0);
85 position.setParentId(api.getContentElementId());
86 position.setVisible(false);
87 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM);
88 position.setTranslation(
89 startPosition + i * spacing, -0.3, 0.3);
90 var id = scene.addElement(position);
91
92 var domId = descriptors[i][0];
93 var callback = descriptors[i][1];
94 var element = new RoundButton(domId, callback);
95 this.buttons.push(element);
96
97 var update = new api.UiElementUpdate();
98 update.setParentId(id);
99 update.setVisible(false);
100 update.setScale(2.2, 2.2, 1);
101 scene.updateElement(element.uiElementId, update);
102 }
103 }
104
105 show(visible) {
106 for (var i = 0; i < this.buttons.length; i++) {
107 var update = new api.UiElementUpdate();
108 update.setVisible(visible);
109 scene.updateElement(this.buttons[i].uiElementId, update);
110 }
111 }
112 };
113
114 class UiState {
115 constructor() {
116 this.mode = api.Mode.UNKNOWN;
117 this.controls = new Controls();
118 scene.flush();
119 }
120
121 setMode(mode) {
122 this.controls.show(mode == api.Mode.STANDARD);
123 scene.flush();
124 }
125 };
126
64 function initialize() { 127 function initialize() {
65 128
66 domLoaded();
67
68 // Change the body background so that the transparency applies. 129 // Change the body background so that the transparency applies.
69 window.setTimeout(function() { 130 window.setTimeout(function() {
70 document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)'; 131 document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)';
71 }, 100); 132 }, 100);
72 133
73 addControlButtons(); 134 state = new UiState();
74 }
75 135
76 // Build a row of control buttons.
77 function addControlButtons() {
78 var buttons = [
79 ['#back', function() { api.doAction(api.Action.HISTORY_BACK); }],
80 ['#reload', function() { api.doAction(api.Action.RELOAD); }],
81 ['#forward', function() { api.doAction(api.Action.HISTORY_FORWARD); }],
82 ];
83
84 var buttonSpacing = 0.3;
85 var buttonStartPosition = -buttonSpacing * (buttons.length / 2.0 - 0.5);
86
87 for (var i = 0; i < buttons.length; i++) {
88 // Use an invisible parent to simplify Z-axis movement on hover.
89 var position = new api.UiElement(0, 0, 0, 0);
90 position.setParentId(api.getContentElementId());
91 position.setVisible(false);
92 position.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM);
93 position.setTranslation(
94 buttonStartPosition + i * buttonSpacing, -0.3, 0.3);
95 var id = scene.addElement(position);
96
97 var domId = buttons[i][0];
98 var callback = buttons[i][1];
99 var element = new RoundButton(domId, callback);
100 uiElements.push(element);
101
102 var update = new api.UiElementUpdate();
103 update.setParentId(id);
104 update.setScale(2.2, 2.2, 1);
105 scene.updateElement(element.uiElementId, update);
106 }
107
108 scene.flush();
109 }
110
111 function domLoaded() {
112 api.domLoaded(); 136 api.domLoaded();
113 } 137 }
114 138
115 function command(dict) { 139 function command(dict) {
140 if ('mode' in dict) {
141 state.setMode(dict['mode']);
142 }
116 } 143 }
117 144
118 return { 145 return {
119 initialize: initialize, 146 initialize: initialize,
120 command: command, 147 command: command,
121 }; 148 };
122 })(); 149 })();
123 150
124 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); 151 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