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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 WebInspector.OverridesUI = {} 5 WebInspector.OverridesUI = {}
6 6
7 /** 7 /**
8 * @param {string} buttonClassName
9 * @param {function(!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode)=} callback
8 * @return {!Element} 10 * @return {!Element}
9 */ 11 */
10 WebInspector.OverridesUI.createDeviceSelect = function() 12 WebInspector.OverridesUI.createDeviceSelect = function(buttonClassName, callback )
11 { 13 {
12 var p = createElement("p"); 14 var p = createElement("p");
13 15
14 var deviceSelectElement = p.createChild("select"); 16 var deviceSelectElement = p.createChild("select", "device-select");
15 deviceSelectElement.addEventListener("change", deviceSelected, false); 17 deviceSelectElement.addEventListener("change", deviceSelected.bind(null, tru e), false);
18
19 var container = p.createChild("div", "mode-container");
20 var modeSelectElement = container.createChild("select", "mode-select");
21 modeSelectElement.addEventListener("change", modeSelected, false);
22
23 var changeOrientationButton = container.createChild("button", "change-orient ation-button");
24 changeOrientationButton.textContent = WebInspector.UIString("Rotate");
25 changeOrientationButton.title = WebInspector.UIString("Change device orienta tion");
26 changeOrientationButton.addEventListener("click", changeOrientationButtonCli cked, false);
16 27
17 // This has to be object, not boolean, otherwise its value doesn't update pr operly. 28 // This has to be object, not boolean, otherwise its value doesn't update pr operly.
18 var emulatedSettingChangedMuted = { muted: false }; 29 var emulatedSettingChangedMuted = { muted: false };
19 WebInspector.overridesSupport.settings.emulateResolution.addChangeListener(e mulatedSettingChanged); 30 WebInspector.overridesSupport.settings.emulateResolution.addChangeListener(e mulatedSettingChanged);
20 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emulate dSettingChanged); 31 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emulate dSettingChanged);
21 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(emulat edSettingChanged); 32 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(emulat edSettingChanged);
22 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListener(e mulatedSettingChanged); 33 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListener(e mulatedSettingChanged);
23 WebInspector.overridesSupport.settings.emulateMobile.addChangeListener(emula tedSettingChanged); 34 WebInspector.overridesSupport.settings.emulateMobile.addChangeListener(emula tedSettingChanged);
24 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(emulat edSettingChanged); 35 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(emulat edSettingChanged);
25 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emulatedS ettingChanged); 36 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emulatedS ettingChanged);
26 37
27 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic esList.Events.CustomDevicesUpdated, deviceListChanged); 38 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic esList.Events.CustomDevicesUpdated, deviceListChanged);
28 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic esList.Events.StandardDevicesUpdated, deviceListChanged); 39 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic esList.Events.StandardDevicesUpdated, deviceListChanged);
29 deviceListChanged(); 40 deviceListChanged();
30 41
31 function deviceSelected() 42 /**
43 * @param {boolean} apply
44 */
45 function deviceSelected(apply)
pfeldman 2015/06/16 18:32:01 extract method
dgozman 2015/06/18 15:53:42 Done.
32 { 46 {
33 if (deviceSelectElement.selectedIndex === 0) 47 modeSelectElement.removeChildren();
48 var option = deviceSelectElement.options[deviceSelectElement.selectedInd ex];
49 var device = /** @type {!WebInspector.EmulatedDevice} */ (option.device) ;
50
51 if (deviceSelectElement.selectedIndex === 0) {
52 addMode(null, "");
53 modeSelectElement.classList.add("hidden");
54 changeOrientationButton.classList.remove("hidden");
34 return; 55 return;
56 }
35 57
36 var option = deviceSelectElement.options[deviceSelectElement.selectedInd ex]; 58 if (device.modes.length === 1) {
59 addMode(device.modes[0], WebInspector.UIString("Default"));
60 modeSelectElement.classList.add("hidden");
61 changeOrientationButton.classList.add("hidden");
62 } else {
63 addOrientation(WebInspector.EmulatedDevice.Vertical, WebInspector.UI String("Portrait"));
64 addOrientation(WebInspector.EmulatedDevice.Horizontal, WebInspector. UIString("Landscape"));
65 if (device.modes.length === 2 && device.modes[0].orientation !== dev ice.modes[1].orientation) {
66 modeSelectElement.classList.add("hidden");
pfeldman 2015/06/16 18:32:01 .toggle
dgozman 2015/06/18 15:53:42 Done.
67 changeOrientationButton.classList.remove("hidden");
68 } else {
69 modeSelectElement.classList.remove("hidden");
70 changeOrientationButton.classList.add("hidden");
71 }
72 }
73
74 modeSelectElement.selectedIndex = option.lastSelectedIndex;
75 if (apply)
76 modeSelected();
77
78 /**
79 * @param {string} orientation
80 * @param {string} title
81 */
82 function addOrientation(orientation, title)
83 {
84 var modes = device.modesForOrientation(orientation);
85 if (!modes.length)
86 return;
87 if (modes.length === 1) {
88 addMode(modes[0], title);
89 } else {
90 for (var index = 0; index < modes.length; index++) {
pfeldman 2015/06/16 18:32:01 no {}
dgozman 2015/06/18 15:53:42 Done.
91 addMode(modes[index], title + " \u2013 " + modes[index].titl e);
92 }
93 }
94 }
95
96 /**
97 * @param {?WebInspector.EmulatedDevice.Mode} mode
98 * @param {string} title
99 */
100 function addMode(mode, title)
101 {
102 var option = new Option(title, title);
103 option.mode = mode;
104 option.device = device;
105 modeSelectElement.appendChild(option);
106 }
107 }
108
109 function saveLastSelectedIndex()
110 {
111 deviceSelectElement.options[deviceSelectElement.selectedIndex].lastSelec tedIndex = modeSelectElement.selectedIndex;
112 }
113
114 function modeSelected()
115 {
116 saveLastSelectedIndex();
117 var option = modeSelectElement.options[modeSelectElement.selectedIndex];
118 if (callback)
119 callback(option.device, option.mode);
37 emulatedSettingChangedMuted.muted = true; 120 emulatedSettingChangedMuted.muted = true;
38 WebInspector.overridesSupport.emulateDevice(option.overridesDevice); 121 WebInspector.overridesSupport.emulateDevice(option.device.modeToOverride sDevice(option.mode));
39 emulatedSettingChangedMuted.muted = false; 122 emulatedSettingChangedMuted.muted = false;
40 } 123 }
41 124
125 function changeOrientationButtonClicked()
126 {
127 if (!deviceSelectElement.selectedIndex) {
128 WebInspector.overridesSupport.swapDimensions();
129 return;
130 }
131 modeSelectElement.selectedIndex = 1 - modeSelectElement.selectedIndex;
132 modeSelected();
133 }
134
42 function emulatedSettingChanged() 135 function emulatedSettingChanged()
43 { 136 {
44 if (emulatedSettingChangedMuted.muted) 137 if (emulatedSettingChangedMuted.muted)
45 return; 138 return;
46 139
47 var index = 0;
48 for (var i = 1; i < deviceSelectElement.options.length; ++i) { 140 for (var i = 1; i < deviceSelectElement.options.length; ++i) {
49 var option = deviceSelectElement.options[i]; 141 var option = deviceSelectElement.options[i];
50 if (WebInspector.overridesSupport.isEmulatingDevice(option.overrides Device)) { 142 var device = /** @type {!WebInspector.EmulatedDevice} */ (option.dev ice);
51 index = i; 143 for (var j = 0; j < device.modes.length; j++) {
52 break; 144 if (WebInspector.overridesSupport.isEmulatingDevice(device.modeT oOverridesDevice(device.modes[j]))) {
145 select(i, j);
146 return;
147 }
53 } 148 }
54 } 149 }
55 deviceSelectElement.selectedIndex = index; 150
151 select(0, 0);
152
153 /**
154 * @param {number} deviceIndex
155 * @param {number} modeIndex
156 */
157 function select(deviceIndex, modeIndex)
158 {
159 deviceSelectElement.selectedIndex = deviceIndex;
160 deviceSelected(false);
161 modeSelectElement.selectedIndex = modeIndex;
162 saveLastSelectedIndex();
163 if (callback) {
164 var option = modeSelectElement.options[modeSelectElement.selecte dIndex];
165 callback(option.device, option.mode);
166 }
167 }
56 } 168 }
57 169
58 function deviceListChanged() 170 function deviceListChanged()
59 { 171 {
60 deviceSelectElement.removeChildren(); 172 deviceSelectElement.removeChildren();
61 173
62 var selectDeviceOption = new Option(WebInspector.UIString("<Select model >"), WebInspector.UIString("<Select model>")); 174 var selectDeviceOption = new Option(WebInspector.UIString("<Select model >"), WebInspector.UIString("<Select model>"));
63 selectDeviceOption.device = {title: WebInspector.UIString("<Select model >"), width: 0, height: 0, deviceScaleFactor: 0, userAgent: "", touch: false, mob ile: false}; 175 selectDeviceOption.device = null;
64 selectDeviceOption.disabled = true; 176 selectDeviceOption.disabled = true;
65 deviceSelectElement.appendChild(selectDeviceOption); 177 deviceSelectElement.appendChild(selectDeviceOption);
66 178
67 addGroup(WebInspector.UIString("Custom"), WebInspector.emulatedDevicesLi st.custom(), true); 179 addGroup(WebInspector.UIString("Custom"), WebInspector.emulatedDevicesLi st.custom(), true);
68 addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesL ist.standard()); 180 addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesL ist.standard(), false);
69 181
70 /** 182 /**
71 * @param {string} name 183 * @param {string} name
72 * @param {!Array.<!WebInspector.EmulatedDevice>} devices 184 * @param {!Array.<!WebInspector.EmulatedDevice>} devices
73 * @param {boolean=} custom 185 * @param {boolean} custom
74 */ 186 */
75 function addGroup(name, devices, custom) 187 function addGroup(name, devices, custom)
76 { 188 {
77 devices = devices.filter(function (d) { return d.show(); }); 189 devices = devices.filter(function (d) { return d.show(); });
78 if (!devices.length) 190 if (!devices.length)
79 return; 191 return;
80 devices.sort(WebInspector.EmulatedDevice.compareByTitle); 192 devices.sort(WebInspector.EmulatedDevice.compareByTitle);
81 var groupElement = deviceSelectElement.createChild("optgroup"); 193 var groupElement = deviceSelectElement.createChild("optgroup");
82 groupElement.label = name; 194 groupElement.label = name;
83 for (var i = 0; i < devices.length; ++i) { 195 for (var i = 0; i < devices.length; ++i) {
84 var option = new Option(devices[i].title, devices[i].title); 196 var option = new Option(devices[i].title, devices[i].title);
85 option.device = devices[i]; 197 option.device = devices[i];
86 option.overridesDevice = devices[i].toOverridesDevice(); 198 option.lastSelectedIndex = 0;
87 option.custom = custom;
88 groupElement.appendChild(option); 199 groupElement.appendChild(option);
89 } 200 }
90 } 201 }
91 202
92 emulatedSettingChanged(); 203 emulatedSettingChanged();
93 } 204 }
94 205
95 return p; 206 return p;
96 } 207 }
97 208
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 {title: "iPhone \u2014 iOS 7", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_ 0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/1 1A4449d Safari/9537.53"}, 404 {title: "iPhone \u2014 iOS 7", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_ 0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/1 1A4449d Safari/9537.53"},
294 {title: "iPhone \u2014 iOS 6", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_ 0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A53 76e Safari/8536.25"}, 405 {title: "iPhone \u2014 iOS 6", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_ 0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A53 76e Safari/8536.25"},
295 {title: "MeeGo \u2014 Nokia N9", value: "Mozilla/5.0 (MeeGo; NokiaN9) AppleW ebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"}, 406 {title: "MeeGo \u2014 Nokia N9", value: "Mozilla/5.0 (MeeGo; NokiaN9) AppleW ebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"},
296 {title: "Opera 18 \u2014 Mac", value: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537. 36 OPR/18.0.1284.68"}, 407 {title: "Opera 18 \u2014 Mac", value: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537. 36 OPR/18.0.1284.68"},
297 {title: "Opera 18 \u2014 Windows", value: "Mozilla/5.0 (Windows NT 6.1) Appl eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12 84.68"}, 408 {title: "Opera 18 \u2014 Windows", value: "Mozilla/5.0 (Windows NT 6.1) Appl eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12 84.68"},
298 {title: "Opera 12 \u2014 Mac", value: "Opera/9.80 (Macintosh; Intel Mac OS X 10.9.1) Presto/2.12.388 Version/12.16"}, 409 {title: "Opera 12 \u2014 Mac", value: "Opera/9.80 (Macintosh; Intel Mac OS X 10.9.1) Presto/2.12.388 Version/12.16"},
299 {title: "Opera 12 \u2014 Windows", value: "Opera/9.80 (Windows NT 6.1) Prest o/2.12.388 Version/12.16"}, 410 {title: "Opera 12 \u2014 Windows", value: "Opera/9.80 (Windows NT 6.1) Prest o/2.12.388 Version/12.16"},
300 {title: "Silk \u2014 Kindle Fire (Desktop view)", value: "Mozilla/5.0 (Linux ; U; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true"}, 411 {title: "Silk \u2014 Kindle Fire (Desktop view)", value: "Mozilla/5.0 (Linux ; U; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true"},
301 {title: "Silk \u2014 Kindle Fire (Mobile view)", value: "Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Ge cko) Silk/3.13 Mobile Safari/535.19 Silk-Accelerated=true"} 412 {title: "Silk \u2014 Kindle Fire (Mobile view)", value: "Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Ge cko) Silk/3.13 Mobile Safari/535.19 Silk-Accelerated=true"}
302 ]; 413 ];
OLDNEW
« 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