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

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: Create chrome://device-emulator and add the ability to get a battery percentage and send an updated… 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..22dbff1f82478d84e5eebcbf13a2a6a435ee3f10
--- /dev/null
+++ b/chrome/browser/resources/chromeos/emulator/device_emulator.js
@@ -0,0 +1,80 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('device_emulator', function() {
+ 'use strict';
+
+ /**
+ * Updates the UI with the battery status
michaelpg 2015/06/25 18:18:19 nit: end comments/sentences with a period
rfrappier 2015/06/25 21:43:24 Done.
+ * @param {number} percent Battery percentage (out of 100).
+ */
+ function setBatteryInfo(percent) {
+ var slider = $('battery-percent-slider');
+ var text = $('battery-percent-text');
+
+ slider.value = percent;
+ text.value = percent.toString();
+ }
+
+ /**
+ * Event listener fired when the battery percent slider is moved and the mouse
+ * is released. Updates the ChromeOS UI.
+ * @param {event} event Contains information about the event which was fired.
michaelpg 2015/06/25 18:18:19 {Event}
rfrappier 2015/06/25 21:43:24 Done.
+ */
+ function onBatterySliderChange(event) {
+ var slider = event.target;
+ chrome.send('updateBatteryInfo', [slider.valueAsNumer]);
+ }
+
+ /**
+ * Event listener fired when the battery percent slider is moved. Updates
+ * the battery slider's associated text input.
+ * @param {event} event Contains information about the event which was fired.
+ */
+ function onBatterySliderInput(event) {
+ var slider = event.target;
+ var text = $('battery-percent-text');
+
+ text.value = slider.value;
+ }
+
+ /**
+ * Event listener fired when a percentage is entered in the battery
+ * percentage text input. Updates the slider and ChromeOS UI.
+ * @param {event} event Contains information about the event which was fired.
+ */
+ function onBatteryTextChange(event) {
+ var text = event.target;
+ var slider = $('battery-percent-slider');
+ var percent = text.valueAsNumber;
+
+ if (isNaN(percent)) {
+ percent = 0;
+ text.valueAsNumber = 0;
+ }
+
+ slider.value = percent;
+
+ chrome.send('updateBatteryInfo', [percent]);
+ }
+
+ function initialize() {
+ chrome.send('requestBatteryInfo');
+
+ var slider = $('battery-percent-slider');
+ var text = $('battery-percent-text');
+
+ slider.addEventListener('change', onBatterySliderChange);
+ slider.addEventListener('input', onBatterySliderInput);
+ text.addEventListener('input', onBatteryTextChange);
+ }
+
+ // Return an object with all of the exports.
+ return {
+ initialize: initialize,
+ setBatteryInfo: setBatteryInfo,
+ };
+});
+
+document.addEventListener('DOMContentLoaded', device_emulator.initialize);

Powered by Google App Engine
This is Rietveld 408576698