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

Unified Diff: Source/devtools/front_end/emulation/OverridesUI.js

Issue 1178643004: [DevTools] Initial implementation of device modes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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: Source/devtools/front_end/emulation/OverridesUI.js
diff --git a/Source/devtools/front_end/emulation/OverridesUI.js b/Source/devtools/front_end/emulation/OverridesUI.js
index 2fc6d2e5ed688c7d85f3823ec8274a371fda5d4b..2d2f3e34f5b9df2548911ea2cc1174d68fd233ce 100644
--- a/Source/devtools/front_end/emulation/OverridesUI.js
+++ b/Source/devtools/front_end/emulation/OverridesUI.js
@@ -5,14 +5,20 @@
WebInspector.OverridesUI = {}
/**
+ * @param {function(!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.Mode)=} callback
* @return {!Element}
*/
-WebInspector.OverridesUI.createDeviceSelect = function()
+WebInspector.OverridesUI.createDeviceSelect = function(callback)
{
var p = createElement("p");
var deviceSelectElement = p.createChild("select");
- deviceSelectElement.addEventListener("change", deviceSelected, false);
+ deviceSelectElement.classList.add("device-select");
+ deviceSelectElement.addEventListener("change", deviceSelected.bind(null, true), false);
+
+ var modeSelectElement = p.createChild("select");
+ modeSelectElement.classList.add("mode-select");
+ modeSelectElement.addEventListener("change", modeSelected, false);
// This has to be object, not boolean, otherwise its value doesn't update properly.
var emulatedSettingChangedMuted = { muted: false };
@@ -28,14 +34,78 @@ WebInspector.OverridesUI.createDeviceSelect = function()
WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList.Events.StandardDevicesUpdated, deviceListChanged);
deviceListChanged();
- function deviceSelected()
+ /**
+ * @param {boolean} apply
+ */
+ function deviceSelected(apply)
{
- if (deviceSelectElement.selectedIndex === 0)
+ modeSelectElement.removeChildren();
+ var option = deviceSelectElement.options[deviceSelectElement.selectedIndex];
+ var device = /** @type {!WebInspector.EmulatedDevice} */ (option.device);
+
+ if (deviceSelectElement.selectedIndex === 0) {
+ addMode(null, "");
+ modeSelectElement.classList.add("invisible");
return;
+ }
- var option = deviceSelectElement.options[deviceSelectElement.selectedIndex];
+ if (device.modes.length === 1) {
+ addMode(device.modes[0], WebInspector.UIString("Default"));
+ modeSelectElement.classList.add("invisible");
+ } else {
+ addOrientation(WebInspector.EmulatedDevice.Vertical, WebInspector.UIString("Portrait"));
+ addOrientation(WebInspector.EmulatedDevice.Horizontal, WebInspector.UIString("Landscape"));
+ modeSelectElement.classList.remove("invisible");
+ }
+
+ modeSelectElement.selectedIndex = option.lastSelectedIndex;
+ if (apply)
+ modeSelected();
+
+ /**
+ * @param {string} orientation
+ * @param {string} title
+ */
+ function addOrientation(orientation, title)
+ {
+ var modes = device.modesForOrientation(orientation);
+ if (!modes.length)
+ return;
+ if (modes.length === 1) {
+ addMode(modes[0], title);
+ } else {
+ for (var index = 0; index < modes.length; index++) {
+ addMode(modes[index], title + " \u2013 " + modes[index].title);
+ }
+ }
+ }
+
+ /**
+ * @param {?WebInspector.EmulatedDevice.Mode} mode
+ * @param {string} title
+ */
+ function addMode(mode, title)
+ {
+ var option = new Option(title, title);
+ option.mode = mode;
+ option.device = device;
+ modeSelectElement.appendChild(option);
+ }
+ }
+
+ function saveLastSelectedIndex()
+ {
+ deviceSelectElement.options[deviceSelectElement.selectedIndex].lastSelectedIndex = modeSelectElement.selectedIndex;
+ }
+
+ function modeSelected()
+ {
+ saveLastSelectedIndex();
+ var option = modeSelectElement.options[modeSelectElement.selectedIndex];
+ if (callback)
+ callback(option.device, option.mode);
emulatedSettingChangedMuted.muted = true;
- WebInspector.overridesSupport.emulateDevice(option.overridesDevice);
+ WebInspector.overridesSupport.emulateDevice(option.device.modeToOverridesDevice(option.mode));
emulatedSettingChangedMuted.muted = false;
}
@@ -44,15 +114,34 @@ WebInspector.OverridesUI.createDeviceSelect = function()
if (emulatedSettingChangedMuted.muted)
return;
- var index = 0;
for (var i = 1; i < deviceSelectElement.options.length; ++i) {
var option = deviceSelectElement.options[i];
- if (WebInspector.overridesSupport.isEmulatingDevice(option.overridesDevice)) {
- index = i;
- break;
+ var device = /** @type {!WebInspector.EmulatedDevice} */ (option.device);
+ for (var j = 0; j < device.modes.length; j++) {
+ if (WebInspector.overridesSupport.isEmulatingDevice(device.modeToOverridesDevice(device.modes[j]))) {
+ select(i, j);
+ return;
+ }
+ }
+ }
+
+ select(0, 0);
+
+ /**
+ * @param {number} deviceIndex
+ * @param {number} modeIndex
+ */
+ function select(deviceIndex, modeIndex)
+ {
+ deviceSelectElement.selectedIndex = deviceIndex;
+ deviceSelected(false);
+ modeSelectElement.selectedIndex = modeIndex;
+ saveLastSelectedIndex();
+ if (callback) {
+ var option = modeSelectElement.options[modeSelectElement.selectedIndex];
+ callback(option.device, option.mode);
}
}
- deviceSelectElement.selectedIndex = index;
}
function deviceListChanged()
@@ -60,17 +149,17 @@ WebInspector.OverridesUI.createDeviceSelect = function()
deviceSelectElement.removeChildren();
var selectDeviceOption = new Option(WebInspector.UIString("<Select model>"), WebInspector.UIString("<Select model>"));
- selectDeviceOption.device = {title: WebInspector.UIString("<Select model>"), width: 0, height: 0, deviceScaleFactor: 0, userAgent: "", touch: false, mobile: false};
+ selectDeviceOption.device = null;
selectDeviceOption.disabled = true;
deviceSelectElement.appendChild(selectDeviceOption);
addGroup(WebInspector.UIString("Custom"), WebInspector.emulatedDevicesList.custom(), true);
- addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesList.standard());
+ addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesList.standard(), false);
/**
* @param {string} name
* @param {!Array.<!WebInspector.EmulatedDevice>} devices
- * @param {boolean=} custom
+ * @param {boolean} custom
*/
function addGroup(name, devices, custom)
{
@@ -83,8 +172,7 @@ WebInspector.OverridesUI.createDeviceSelect = function()
for (var i = 0; i < devices.length; ++i) {
var option = new Option(devices[i].title, devices[i].title);
option.device = devices[i];
- option.overridesDevice = devices[i].toOverridesDevice();
- option.custom = custom;
+ option.lastSelectedIndex = 0;
groupElement.appendChild(option);
}
}

Powered by Google App Engine
This is Rietveld 408576698