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

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: Fixed review comments 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..65d488365d12587e7f792b6a2b7e5915d7a205cc 100644
--- a/Source/devtools/front_end/emulation/OverridesUI.js
+++ b/Source/devtools/front_end/emulation/OverridesUI.js
@@ -5,14 +5,25 @@
WebInspector.OverridesUI = {}
/**
+ * @param {string} buttonClassName
+ * @param {function(!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.Mode)=} callback
* @return {!Element}
*/
-WebInspector.OverridesUI.createDeviceSelect = function()
+WebInspector.OverridesUI.createDeviceSelect = function(buttonClassName, callback)
{
var p = createElement("p");
- var deviceSelectElement = p.createChild("select");
- deviceSelectElement.addEventListener("change", deviceSelected, false);
+ var deviceSelectElement = p.createChild("select", "device-select");
+ deviceSelectElement.addEventListener("change", deviceSelected.bind(null, true), false);
+
+ var container = p.createChild("div", "mode-container");
+ var modeSelectElement = container.createChild("select", "mode-select");
+ modeSelectElement.addEventListener("change", modeSelected, false);
+
+ var changeOrientationButton = container.createChild("button", "change-orientation-button");
+ changeOrientationButton.textContent = WebInspector.UIString("Rotate");
+ changeOrientationButton.title = WebInspector.UIString("Change device orientation");
+ changeOrientationButton.addEventListener("click", changeOrientationButtonClicked, false);
// This has to be object, not boolean, otherwise its value doesn't update properly.
var emulatedSettingChangedMuted = { muted: false };
@@ -28,31 +39,132 @@ WebInspector.OverridesUI.createDeviceSelect = function()
WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList.Events.StandardDevicesUpdated, deviceListChanged);
deviceListChanged();
- function deviceSelected()
+ /**
+ * @param {boolean} apply
+ */
+ function deviceSelected(apply)
pfeldman 2015/06/16 18:32:01 extract method
dgozman 2015/06/18 15:53:42 Done.
{
- 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("hidden");
+ changeOrientationButton.classList.remove("hidden");
return;
+ }
- var option = deviceSelectElement.options[deviceSelectElement.selectedIndex];
+ if (device.modes.length === 1) {
+ addMode(device.modes[0], WebInspector.UIString("Default"));
+ modeSelectElement.classList.add("hidden");
+ changeOrientationButton.classList.add("hidden");
+ } else {
+ addOrientation(WebInspector.EmulatedDevice.Vertical, WebInspector.UIString("Portrait"));
+ addOrientation(WebInspector.EmulatedDevice.Horizontal, WebInspector.UIString("Landscape"));
+ if (device.modes.length === 2 && device.modes[0].orientation !== device.modes[1].orientation) {
+ modeSelectElement.classList.add("hidden");
pfeldman 2015/06/16 18:32:01 .toggle
dgozman 2015/06/18 15:53:42 Done.
+ changeOrientationButton.classList.remove("hidden");
+ } else {
+ modeSelectElement.classList.remove("hidden");
+ changeOrientationButton.classList.add("hidden");
+ }
+ }
+
+ 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++) {
pfeldman 2015/06/16 18:32:01 no {}
dgozman 2015/06/18 15:53:42 Done.
+ 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;
}
+ function changeOrientationButtonClicked()
+ {
+ if (!deviceSelectElement.selectedIndex) {
+ WebInspector.overridesSupport.swapDimensions();
+ return;
+ }
+ modeSelectElement.selectedIndex = 1 - modeSelectElement.selectedIndex;
+ modeSelected();
+ }
+
function emulatedSettingChanged()
{
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 +172,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 +195,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);
}
}
« no previous file with comments | « Source/devtools/front_end/emulation/OverridesSupport.js ('k') | Source/devtools/front_end/emulation/OverridesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698