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

Unified Diff: chrome/browser/resources/chromeos/emulator/device_emulator.js

Issue 1205753002: Create chrome://device-emulator and add the ability to get a battery percentage and send an updated… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/emulator/device_emulator.js
diff --git a/chrome/browser/resources/chromeos/emulator/device_emulator.js b/chrome/browser/resources/chromeos/emulator/device_emulator.js
new file mode 100644
index 0000000000000000000000000000000000000000..cc70395a5d93afb59b744a48bd30bc1aa8f19afc
--- /dev/null
+++ b/chrome/browser/resources/chromeos/emulator/device_emulator.js
@@ -0,0 +1,55 @@
+cr.define('device_emulator', function() {
+ 'use strict';
+
+ function returnBatteryInfo(percent) {
michaelpg 2015/06/24 23:33:48 setBatteryInfo makes more sense I think
michaelpg 2015/06/24 23:33:48 Annotate for Closure (we don't closure-compile yet
rfrappier 2015/06/25 17:09:21 Done.
rfrappier 2015/06/25 17:09:21 Done.
+ var slider = $('batteryPercentSlider');
+ var text = $('batteryPercentText');
+
+ slider.value = percent;
+ text.value = percent.toString();
+ }
+
+ function onBatterySliderChange() {
+ var slider = $('batteryPercentSlider');
+ var text = $('batteryPercentText');
+
+ text.value = slider.value;
+
+ chrome.send('updateBatteryInfo', [parseInt(slider.value)]);
michaelpg 2015/06/24 23:33:48 [slider.valueAsNumber]
rfrappier 2015/06/25 17:09:21 Done.
+ }
+
+ function onBatteryTextChange() {
+ var slider = $('batteryPercentSlider');
+ var text = $('batteryPercentText');
+ var percent = (text.value !== '') ? parseInt(text.value) : 0;
michaelpg 2015/06/24 23:33:48 parseInt will return NaN if given something unpars
rfrappier 2015/06/25 17:09:21 Done.
+
+ if (isNaN(percent)) {
+ percent = 0;
+ text.value = '0';
+ }
+
+ slider.value = percent;
+
+ chrome.send('updateBatteryInfo', [percent]);
+ }
+
+ function initialize() {
+ chrome.send('requestBatteryInfo');
+
+ var slider = $('batteryPercentSlider');
+ var text = $('batteryPercentText');
+
+ slider.addEventListener('input', onBatterySliderChange);
michaelpg 2015/06/24 23:33:48 I'd suggest listening to 'change' instead, so we d
rfrappier 2015/06/25 17:09:21 How about I listen for 'change' for sending the pe
rfrappier 2015/06/25 17:09:21 Done.
michaelpg 2015/06/25 18:18:19 Good idea.
+ text.addEventListener('input', onBatteryTextChange);
+ }
+
+ // Return an object with all of the exports.
+ return {
+ initialize: initialize,
+ returnBatteryInfo: returnBatteryInfo,
+ onBatterySliderChange: onBatterySliderChange,
michaelpg 2015/06/24 23:33:48 Why export on*Change?
rfrappier 2015/06/25 17:09:21 It's not necessary. Not sure why I put them there,
+ onBatteryTextChange: onBatteryTextChange,
+ };
+});
+
+document.addEventListener('DOMContentLoaded', device_emulator.initialize);

Powered by Google App Engine
This is Rietveld 408576698