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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js

Issue 1546833002: [DevTools] Add rulers to Device Mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 11 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/emulation/MediaQueryInspector.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @param {function()} pageResizeCallback
9 */ 8 */
10 WebInspector.DeviceModeView = function(pageResizeCallback) 9 WebInspector.DeviceModeView = function()
11 { 10 {
12 WebInspector.VBox.call(this, true); 11 WebInspector.VBox.call(this, true);
13 this.setMinimumSize(150, 150); 12 this.setMinimumSize(150, 150);
14 this.element.classList.add("device-mode-view"); 13 this.element.classList.add("device-mode-view");
15 this.registerRequiredCSS("emulation/deviceModeView.css"); 14 this.registerRequiredCSS("emulation/deviceModeView.css");
16 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement); 15 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement);
17 16
18 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this)); 17 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this));
19 this._mediaInspector = new WebInspector.MediaQueryInspector(this._model.widt hSetting()); 18 this._mediaInspector = new WebInspector.MediaQueryInspector(this._model.widt hSetting());
20 // TODO(dgozman): remove CountUpdated event. 19 // TODO(dgozman): remove CountUpdated event.
21 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM ediaQueryInspector", false); 20 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM ediaQueryInspector", false);
22 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this); 21 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this);
22 this._showRulersSetting = WebInspector.settings.createSetting("emulation.sho wRulers", false);
23 this._showRulersSetting.addChangeListener(this._updateUI, this);
23 24
24 this._pageResizeCallback = pageResizeCallback; 25 this._topRuler = new WebInspector.DeviceModeView.Ruler(true, this._model.wid thSetting().set.bind(this._model.widthSetting()));
26 this._topRuler.element.classList.add("device-mode-ruler-top");
27 this._leftRuler = new WebInspector.DeviceModeView.Ruler(false, this._model.h eightSetting().set.bind(this._model.heightSetting()));
28 this._leftRuler.element.classList.add("device-mode-ruler-left");
25 this._createUI(); 29 this._createUI();
26 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._updateUI, this); 30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._updateUI, this);
27 }; 31 };
28 32
29 WebInspector.DeviceModeView.prototype = { 33 WebInspector.DeviceModeView.prototype = {
30 _createUI: function() 34 _createUI: function()
31 { 35 {
32 this._toolbar = new WebInspector.DeviceModeView.Toolbar(this._model, thi s._showMediaInspectorSetting); 36 this._toolbar = new WebInspector.DeviceModeView.Toolbar(this._model, thi s._showMediaInspectorSetting, this._showRulersSetting);
33 this.contentElement.appendChild(this._toolbar.element()); 37 this.contentElement.appendChild(this._toolbar.element());
34 38
35 var contentClip = this.contentElement.createChild("div", "device-mode-co ntent-clip vbox"); 39 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox");
36 this._mediaInspectorContainer = contentClip.createChild("div", "device-m ode-media-container"); 40 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container");
37 this._contentArea = contentClip.createChild("div", "device-mode-content- area"); 41 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area");
38
39 this._deviceBlueprints = this._contentArea.createChild("div", "fill"); 42 this._deviceBlueprints = this._contentArea.createChild("div", "fill");
40 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedD evicesList.Events.StandardDevicesUpdated, this._updateBlueprints, this); 43 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedD evicesList.Events.StandardDevicesUpdated, this._updateBlueprints, this);
41 44
42 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area"); 45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area");
43 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden"); 46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden");
44 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, true), false); 47 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, true), false);
45 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false); 48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false);
46 49
47 this._cornerResizerElement = this._screenArea.createChild("div", "device -mode-resizer device-mode-corner-resizer"); 50 this._cornerResizerElement = this._screenArea.createChild("div", "device -mode-resizer device-mode-corner-resizer");
48 this._cornerResizerElement.createChild("div", ""); 51 this._cornerResizerElement.createChild("div", "");
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 this._model.widthSetting().set(width); 149 this._model.widthSetting().set(width);
147 this._model.heightSetting().set(height); 150 this._model.heightSetting().set(height);
148 }, 151 },
149 152
150 _updateUI: function() 153 _updateUI: function()
151 { 154 {
152 if (!this.isShowing()) 155 if (!this.isShowing())
153 return; 156 return;
154 157
155 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 158 var zoomFactor = WebInspector.zoomManager.zoomFactor();
156 var resizePagePlaceholder = false; 159 var callDoResize = false;
157 var resizeSelf = false; 160 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None;
161 var contentAreaResized = false;
162 var updateRulers = false;
158 163
159 if (this._cachedModelType !== this._model.type() || this._cachedModelSca le !== this._model.scale()) { 164 if (this._cachedModelType !== this._model.type() || this._cachedModelSca le !== this._model.scale()) {
160 this._updateBlueprints(); 165 this._updateBlueprints();
161 this._cachedModelType = this._model.type(); 166 this._cachedModelType = this._model.type();
162 this._cachedModelScale = this._model.scale(); 167 this._cachedModelScale = this._model.scale();
163 } 168 }
164 169
165 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); 170 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor);
166 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { 171 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) {
167 this._screenArea.style.left = cssScreenRect.left + "px"; 172 this._screenArea.style.left = cssScreenRect.left + "px";
168 this._screenArea.style.top = cssScreenRect.top + "px"; 173 this._screenArea.style.top = cssScreenRect.top + "px";
169 this._screenArea.style.width = cssScreenRect.width + "px"; 174 this._screenArea.style.width = cssScreenRect.width + "px";
170 this._screenArea.style.height = cssScreenRect.height + "px"; 175 this._screenArea.style.height = cssScreenRect.height + "px";
171 resizePagePlaceholder = true; 176 this._leftRuler.element.style.left = cssScreenRect.left + "px";
177 updateRulers = true;
178 callDoResize = true;
172 this._cachedCssScreenRect = cssScreenRect; 179 this._cachedCssScreenRect = cssScreenRect;
173 } 180 }
174 181
175 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor); 182 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor);
176 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { 183 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) {
177 this._pageArea.style.left = cssVisiblePageRect.left + "px"; 184 this._pageArea.style.left = cssVisiblePageRect.left + "px";
178 this._pageArea.style.top = cssVisiblePageRect.top + "px"; 185 this._pageArea.style.top = cssVisiblePageRect.top + "px";
179 this._pageArea.style.width = cssVisiblePageRect.width + "px"; 186 this._pageArea.style.width = cssVisiblePageRect.width + "px";
180 this._pageArea.style.height = cssVisiblePageRect.height + "px"; 187 this._pageArea.style.height = cssVisiblePageRect.height + "px";
181 resizePagePlaceholder = true; 188 callDoResize = true;
182 this._cachedCssVisiblePageRect = cssVisiblePageRect; 189 this._cachedCssVisiblePageRect = cssVisiblePageRect;
183 } 190 }
184 191
185 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive; 192 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive;
186 if (resizable !== this._cachedResizable) { 193 if (resizable !== this._cachedResizable) {
187 this._widthResizerElement.classList.toggle("hidden", !resizable); 194 this._widthResizerElement.classList.toggle("hidden", !resizable);
188 this._heightResizerElement.classList.toggle("hidden", !resizable); 195 this._heightResizerElement.classList.toggle("hidden", !resizable);
189 this._cornerResizerElement.classList.toggle("hidden", !resizable); 196 this._cornerResizerElement.classList.toggle("hidden", !resizable);
190 this._cachedResizable = resizable; 197 this._cachedResizable = resizable;
191 } 198 }
192 199
193 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi s._model.type() !== WebInspector.DeviceModeModel.Type.None; 200 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi s._model.type() !== WebInspector.DeviceModeModel.Type.None;
194 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) { 201 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) {
195 if (mediaInspectorVisible) 202 if (mediaInspectorVisible)
196 this._mediaInspector.show(this._mediaInspectorContainer); 203 this._mediaInspector.show(this._mediaInspectorContainer);
197 else 204 else
198 this._mediaInspector.detach(); 205 this._mediaInspector.detach();
199 resizePagePlaceholder = true; 206 contentAreaResized = true;
200 resizeSelf = true; 207 callDoResize = true;
201 this._cachedMediaInspectorVisible = mediaInspectorVisible; 208 this._cachedMediaInspectorVisible = mediaInspectorVisible;
202 } 209 }
203 210
211 if (showRulers !== this._cachedShowRulers) {
212 this._contentArea.classList.toggle("device-mode-rulers-visible", sho wRulers);
213 if (showRulers) {
214 this._topRuler.show(this._contentClip, this._contentArea);
215 this._leftRuler.show(this._contentArea);
216 } else {
217 this._topRuler.detach();
218 this._leftRuler.detach();
219 }
220 callDoResize = true;
221 this._cachedShowRulers = showRulers;
222 }
223
224 if (this._model.scale() !== this._cachedScale) {
225 updateRulers = true;
226 this._cachedScale = this._model.scale();
227 }
228
204 this._toolbar.update(); 229 this._toolbar.update();
205 this._loadScreenImage(this._model.screenImage()); 230 this._loadScreenImage(this._model.screenImage());
206 if (resizePagePlaceholder)
207 this._pageResizeCallback.call(null);
208 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor / this._model.scale(), this._model.scale()); 231 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor / this._model.scale(), this._model.scale());
209 if (resizeSelf) 232 if (callDoResize)
210 this.onResize(); 233 this.doResize();
234 if (updateRulers) {
235 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale());
236 this._leftRuler.render(0, this._model.scale());
237 }
238 if (contentAreaResized)
239 this._contentAreaResized();
211 }, 240 },
212 241
213 _updateBlueprints: function() 242 _updateBlueprints: function()
214 { 243 {
215 this._deviceBlueprints.removeChildren(); 244 this._deviceBlueprints.removeChildren();
216 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Responsive) 245 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Responsive)
217 return; 246 return;
218 var devices = WebInspector.emulatedDevicesList.standard(); 247 var devices = WebInspector.emulatedDevicesList.standard();
219 devices.sort((device1, device2) => device2.vertical.width * device2.vert ical.height - device1.vertical.width * device1.vertical.height); 248 devices.sort((device1, device2) => device2.vertical.width * device2.vert ical.height - device1.vertical.width * device1.vertical.height);
220 var scale = this._model.scale(); 249 var scale = this._model.scale();
221 for (var device of devices) { 250 for (var device of devices) {
222 if (!device.show()) 251 if (!device.show())
223 continue; 252 continue;
224 var blueprintContainer = this._deviceBlueprints.createChild("div", " device-mode-blueprint-container fill"); 253 var blueprintContainer = this._deviceBlueprints.createChild("div", " device-mode-blueprint-container fill");
225 var blueprint = blueprintContainer.createChild("div", "device-mode-b lueprint"); 254 var blueprint = blueprintContainer.createChild("div", "device-mode-b lueprint");
226 blueprint.style.width = device.vertical.width * scale + "px"; 255 blueprint.style.width = device.vertical.width * scale + "px";
227 blueprint.style.height = device.vertical.height * scale + "px"; 256 blueprint.style.height = device.vertical.height * scale + "px";
228 blueprint.createChild("span").textContent = device.title; 257 var clickable = blueprint.createChild("div", "device-mode-blueprint- border");
229 blueprint.addEventListener("dblclick", this._resizeTo.bind(this, dev ice.vertical.width, device.vertical.height), false); 258 clickable.createChild("span").textContent = device.title;
259 clickable.addEventListener("dblclick", this._resizeTo.bind(this, dev ice.vertical.width, device.vertical.height), false);
260 blueprint.createChild("div", "device-mode-blueprint-inside");
230 } 261 }
231 }, 262 },
232 263
233 /** 264 /**
234 * @param {string} srcset 265 * @param {string} srcset
235 */ 266 */
236 _loadScreenImage: function(srcset) 267 _loadScreenImage: function(srcset)
237 { 268 {
238 if (this._screenImage.getAttribute("srcset") === srcset) 269 if (this._screenImage.getAttribute("srcset") === srcset)
239 return; 270 return;
240 this._screenImage.setAttribute("srcset", srcset); 271 this._screenImage.setAttribute("srcset", srcset);
241 if (!srcset) 272 if (!srcset)
242 this._screenImage.classList.toggle("hidden", true); 273 this._screenImage.classList.toggle("hidden", true);
243 }, 274 },
244 275
245 /** 276 /**
246 * @param {boolean} success 277 * @param {boolean} success
247 */ 278 */
248 _onScreenImageLoaded: function(success) 279 _onScreenImageLoaded: function(success)
249 { 280 {
250 this._screenImage.classList.toggle("hidden", !success); 281 this._screenImage.classList.toggle("hidden", !success);
251 }, 282 },
252 283
284 _contentAreaResized: function()
285 {
286 var zoomFactor = WebInspector.zoomManager.zoomFactor();
287 var rect = this._contentArea.getBoundingClientRect();
288 this._model.setAvailableSize(new Size(Math.max(rect.width * zoomFactor, 1), Math.max(rect.height * zoomFactor, 1)));
289 },
290
253 /** 291 /**
254 * @override 292 * @override
255 */ 293 */
256 onResize: function() 294 onResize: function()
257 { 295 {
258 if (!this.isShowing()) 296 if (this.isShowing())
259 return; 297 this._contentAreaResized();
260
261 var zoomFactor = WebInspector.zoomManager.zoomFactor();
262 var rect = this._contentArea.getBoundingClientRect();
263 this._model.setAvailableSize(new Size(Math.max(rect.width * zoomFactor, 1), Math.max(rect.height * zoomFactor, 1)));
264 }, 298 },
265 299
266 /** 300 /**
267 * @override 301 * @override
268 */ 302 */
269 wasShown: function() 303 wasShown: function()
270 { 304 {
271 this._mediaInspector.setEnabled(true); 305 this._mediaInspector.setEnabled(true);
272 this._toolbar.restore(); 306 this._toolbar.restore();
273 }, 307 },
274 308
275 /** 309 /**
276 * @override 310 * @override
277 */ 311 */
278 willHide: function() 312 willHide: function()
279 { 313 {
280 this._mediaInspector.setEnabled(false); 314 this._mediaInspector.setEnabled(false);
281 }, 315 },
282 316
283 __proto__: WebInspector.VBox.prototype 317 __proto__: WebInspector.VBox.prototype
284 } 318 }
285 319
286 /** 320 /**
287 * @param {!WebInspector.DeviceModeModel} model 321 * @param {!WebInspector.DeviceModeModel} model
288 * @param {!WebInspector.Setting} showMediaInspectorSetting 322 * @param {!WebInspector.Setting} showMediaInspectorSetting
323 * @param {!WebInspector.Setting} showRulersSetting
289 * @constructor 324 * @constructor
290 */ 325 */
291 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting) 326 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting, showRulersSetting)
292 { 327 {
293 this._model = model; 328 this._model = model;
294 this._showMediaInspectorSetting = showMediaInspectorSetting; 329 this._showMediaInspectorSetting = showMediaInspectorSetting;
330 this._showRulersSetting = showRulersSetting;
295 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode>} */ 331 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode>} */
296 this._lastMode = new Map(); 332 this._lastMode = new Map();
297 /** @type {?WebInspector.EmulatedDevice} */ 333 /** @type {?WebInspector.EmulatedDevice} */
298 this._lastDevice = null; 334 this._lastDevice = null;
299 /** @type {!Array<!WebInspector.ToolbarTextGlyphItem>} */ 335 /** @type {!Array<!WebInspector.ToolbarTextGlyphItem>} */
300 this._appliedSizeItems = []; 336 this._appliedSizeItems = [];
301 /** @type {?Element} */ 337 /** @type {?Element} */
302 this._visibleToolbar = null; 338 this._visibleToolbar = null;
303 339
304 this._element = createElementWithClass("div", "device-mode-toolbar"); 340 this._element = createElementWithClass("div", "device-mode-toolbar");
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 */ 518 */
483 function appendDeviceScaleFactorItem(title, value) 519 function appendDeviceScaleFactorItem(title, value)
484 { 520 {
485 deviceScaleFactorSubmenu.appendCheckboxItem(title, deviceScaleFactor Setting.set.bind(deviceScaleFactorSetting, value), deviceScaleFactorSetting.get( ) === value, deviceScaleFactorDisabled); 521 deviceScaleFactorSubmenu.appendCheckboxItem(title, deviceScaleFactor Setting.set.bind(deviceScaleFactorSetting, value), deviceScaleFactorSetting.get( ) === value, deviceScaleFactorDisabled);
486 } 522 }
487 523
488 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this. _model.reset.bind(this._model), this._model.type() !== WebInspector.DeviceModeMo del.Type.Responsive); 524 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this. _model.reset.bind(this._model), this._model.type() !== WebInspector.DeviceModeMo del.Type.Responsive);
489 contextMenu.appendSeparator(); 525 contextMenu.appendSeparator();
490 526
491 contextMenu.appendCheckboxItem(WebInspector.UIString("Show media queries "), this._toggleMediaInspector.bind(this), this._showMediaInspectorSetting.get() , this._model.type() === WebInspector.DeviceModeModel.Type.None); 527 contextMenu.appendCheckboxItem(WebInspector.UIString("Show media queries "), this._toggleMediaInspector.bind(this), this._showMediaInspectorSetting.get() , this._model.type() === WebInspector.DeviceModeModel.Type.None);
528 contextMenu.appendCheckboxItem(WebInspector.UIString("Show rulers"), thi s._toggleRulers.bind(this), this._showRulersSetting.get(), this._model.type() == = WebInspector.DeviceModeModel.Type.None);
492 contextMenu.appendItem(WebInspector.UIString("Configure network\u2026"), this._openNetworkConfig.bind(this), false); 529 contextMenu.appendItem(WebInspector.UIString("Configure network\u2026"), this._openNetworkConfig.bind(this), false);
493 }, 530 },
494 531
495 _toggleMediaInspector: function() 532 _toggleMediaInspector: function()
496 { 533 {
497 this._showMediaInspectorSetting.set(!this._showMediaInspectorSetting.get ()); 534 this._showMediaInspectorSetting.set(!this._showMediaInspectorSetting.get ());
498 }, 535 },
499 536
537 _toggleRulers: function()
538 {
539 this._showRulersSetting.set(!this._showRulersSetting.get());
540 },
541
500 _openNetworkConfig: function() 542 _openNetworkConfig: function()
501 { 543 {
502 InspectorFrontendHost.bringToFront(); 544 InspectorFrontendHost.bringToFront();
503 // TODO(dgozman): make it explicit. 545 // TODO(dgozman): make it explicit.
504 WebInspector.actionRegistry.action("network.show-config").execute(); 546 WebInspector.actionRegistry.action("network.show-config").execute();
505 }, 547 },
506 548
507 /** 549 /**
508 * @param {!Element} element 550 * @param {!Element} element
509 * @return {!WebInspector.ToolbarItem} 551 * @return {!WebInspector.ToolbarItem}
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 this._responsiveButtonClick(); 867 this._responsiveButtonClick();
826 else if (type === WebInspector.DeviceModeModel.Type.Device) 868 else if (type === WebInspector.DeviceModeModel.Type.Device)
827 this._deviceButtonClick(); 869 this._deviceButtonClick();
828 else 870 else
829 this._noneButtonClick(); 871 this._noneButtonClick();
830 } 872 }
831 } 873 }
832 874
833 /** 875 /**
834 * @constructor 876 * @constructor
877 * @extends {WebInspector.VBox}
878 * @param {boolean} horizontal
879 * @param {function(number)} applyCallback
880 */
881 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback)
882 {
883 WebInspector.VBox.call(this);
884 this._contentElement = this.element.createChild("div", "device-mode-ruler fl ex-auto");
885 this._horizontal = horizontal;
886 this._scale = 1;
887 this._offset = 0;
888 this._count = 0;
889 this._throttler = new WebInspector.Throttler(0);
890 this._applyCallback = applyCallback;
891 }
892
893 WebInspector.DeviceModeView.Ruler.prototype = {
894 /**
895 * @param {number} offset
896 * @param {number} scale
897 */
898 render: function(offset, scale)
899 {
900 this._scale = scale;
901 this._offset = offset;
902 if (this._horizontal)
903 this.element.style.paddingLeft = this._offset + "px";
904 else
905 this.element.style.paddingTop = this._offset + "px";
906 this._throttler.schedule(this._update.bind(this));
907 },
908
909 /**
910 * @override
911 */
912 onResize: function()
913 {
914 this._throttler.schedule(this._update.bind(this));
915 },
916
917 /**
918 * @return {!Promise.<?>}
919 */
920 _update: function()
921 {
922 var zoomFactor = WebInspector.zoomManager.zoomFactor();
923 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight;
924
925 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) {
926 this._contentElement.removeChildren();
927 this._count = 0;
928 this._renderedScale = this._scale;
929 this._renderedZoomFactor = zoomFactor;
930 }
931
932 var dipSize = size * zoomFactor / this._scale;
933 var count = Math.ceil(dipSize / 5);
934 var step = 1;
935 if (this._scale < 0.8)
936 step = 2;
937 if (this._scale < 0.6)
938 step = 5;
939 if (this._scale < 0.5)
940 step = 20;
941
942 for (var i = count; i < this._count; i++) {
943 if (!(i % step))
944 this._contentElement.lastChild.remove();
945 }
946
947 for (var i = this._count; i < count; i++) {
948 if (i % step)
949 continue;
950 var marker = this._contentElement.createChild("div", "device-mode-ru ler-marker");
951 if (i) {
952 if (this._horizontal)
953 marker.style.left = (5 * i) * this._scale / zoomFactor + "px ";
954 else
955 marker.style.top = (5 * i) * this._scale / zoomFactor + "px" ;
956 if (!(i % 20)) {
957 var text = marker.createChild("div", "device-mode-ruler-text ");
958 text.textContent = i * 5;
959 text.addEventListener("click", this._onMarkerClick.bind(this , i * 5), false);
960 }
961 }
962 if (!(i % 10))
963 marker.classList.add("device-mode-ruler-marker-large");
964 else if (!(i % 5))
965 marker.classList.add("device-mode-ruler-marker-medium");
966 }
967
968 this._count = count;
969 return Promise.resolve();
970 },
971
972 /**
973 * @param {number} size
974 */
975 _onMarkerClick: function(size)
976 {
977 this._applyCallback.call(null, size);
978 },
979
980 __proto__: WebInspector.VBox.prototype
981 }
982
983
984 /**
985 * @constructor
835 * @implements {WebInspector.ActionDelegate} 986 * @implements {WebInspector.ActionDelegate}
836 */ 987 */
837 WebInspector.DeviceModeView.ActionDelegate = function() 988 WebInspector.DeviceModeView.ActionDelegate = function()
838 { 989 {
839 } 990 }
840 991
841 WebInspector.DeviceModeView.ActionDelegate.prototype = { 992 WebInspector.DeviceModeView.ActionDelegate.prototype = {
842 /** 993 /**
843 * @override 994 * @override
844 * @param {!WebInspector.Context} context 995 * @param {!WebInspector.Context} context
(...skipping 18 matching lines...) Expand all
863 /** 1014 /**
864 * @extends {WebInspector.VBox} 1015 * @extends {WebInspector.VBox}
865 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder 1016 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder
866 * @constructor 1017 * @constructor
867 */ 1018 */
868 WebInspector.DeviceModeView.Wrapper = function(inspectedPagePlaceholder) 1019 WebInspector.DeviceModeView.Wrapper = function(inspectedPagePlaceholder)
869 { 1020 {
870 WebInspector.VBox.call(this); 1021 WebInspector.VBox.call(this);
871 WebInspector.DeviceModeView._wrapperInstance = this; 1022 WebInspector.DeviceModeView._wrapperInstance = this;
872 this._inspectedPagePlaceholder = inspectedPagePlaceholder; 1023 this._inspectedPagePlaceholder = inspectedPagePlaceholder;
873 this._deviceModeView = new WebInspector.DeviceModeView(this._resizePlacehold er.bind(this)); 1024 this._deviceModeView = new WebInspector.DeviceModeView();
874 this._showDeviceToolbarSetting = WebInspector.settings.createSetting("emulat ion.showDeviceToolbar", true); 1025 this._showDeviceToolbarSetting = WebInspector.settings.createSetting("emulat ion.showDeviceToolbar", true);
875 this._showDeviceToolbarSetting.addChangeListener(this._update, this); 1026 this._showDeviceToolbarSetting.addChangeListener(this._update, this);
876 this._update(); 1027 this._update();
877 } 1028 }
878 1029
879 /** @type {!WebInspector.DeviceModeView.Wrapper} */ 1030 /** @type {!WebInspector.DeviceModeView.Wrapper} */
880 WebInspector.DeviceModeView._wrapperInstance; 1031 WebInspector.DeviceModeView._wrapperInstance;
881 1032
882 WebInspector.DeviceModeView.Wrapper.prototype = { 1033 WebInspector.DeviceModeView.Wrapper.prototype = {
883 _toggleDeviceMode: function() 1034 _toggleDeviceMode: function()
(...skipping 14 matching lines...) Expand all
898 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); 1049 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins();
899 this._inspectedPagePlaceholder.show(this._deviceModeView.element); 1050 this._inspectedPagePlaceholder.show(this._deviceModeView.element);
900 } else { 1051 } else {
901 this._deviceModeView.detach(); 1052 this._deviceModeView.detach();
902 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); 1053 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins();
903 this._inspectedPagePlaceholder.show(this.element); 1054 this._inspectedPagePlaceholder.show(this.element);
904 this._deviceModeView._model.emulate(WebInspector.DeviceModeModel.Typ e.None, null, null); 1055 this._deviceModeView._model.emulate(WebInspector.DeviceModeModel.Typ e.None, null, null);
905 } 1056 }
906 }, 1057 },
907 1058
908 _resizePlaceholder: function()
909 {
910 if (this._showDeviceToolbarSetting.get())
911 this._inspectedPagePlaceholder.onResize();
912 },
913
914 __proto__: WebInspector.VBox.prototype 1059 __proto__: WebInspector.VBox.prototype
915 } 1060 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/emulation/MediaQueryInspector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698