OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | |
7 * @extends {WebInspector.VBox} | |
8 */ | |
9 WebInspector.DeviceModeView = function() | |
10 { | |
11 WebInspector.VBox.call(this, true); | |
12 this.setMinimumSize(150, 150); | |
13 this.element.classList.add("device-mode-view"); | |
14 this.registerRequiredCSS("emulation/deviceModeView.css"); | |
15 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement); | |
16 | |
17 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this)); | |
18 this._mediaInspector = new WebInspector.MediaQueryInspector(() => this._mode
l.appliedDeviceSize().width, this._model.setWidth.bind(this._model)); | |
19 // TODO(dgozman): remove CountUpdated event. | |
20 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM
ediaQueryInspector", false); | |
21 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this); | |
22 this._showRulersSetting = WebInspector.settings.createSetting("emulation.sho
wRulers", false); | |
23 this._showRulersSetting.addChangeListener(this._updateUI, this); | |
24 | |
25 this._topRuler = new WebInspector.DeviceModeView.Ruler(true, this._model.set
WidthAndScaleToFit.bind(this._model)); | |
26 this._topRuler.element.classList.add("device-mode-ruler-top"); | |
27 this._leftRuler = new WebInspector.DeviceModeView.Ruler(false, this._model.s
etHeightAndScaleToFit.bind(this._model)); | |
28 this._leftRuler.element.classList.add("device-mode-ruler-left"); | |
29 this._createUI(); | |
30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._zoomChanged, this); | |
31 }; | |
32 | |
33 WebInspector.DeviceModeView.prototype = { | |
34 _createUI: function() | |
35 { | |
36 this._toolbar = new WebInspector.DeviceModeView.Toolbar(this._model, thi
s._showMediaInspectorSetting, this._showRulersSetting); | |
37 this.contentElement.appendChild(this._toolbar.element()); | |
38 | |
39 this._contentClip = this.contentElement.createChild("div", "device-mode-
content-clip vbox"); | |
40 this._responsivePresetsContainer = this._contentClip.createChild("div",
"device-mode-presets-container"); | |
41 this._populatePresetsContainer(); | |
42 this._mediaInspectorContainer = this._contentClip.createChild("div", "de
vice-mode-media-container"); | |
43 this._contentArea = this._contentClip.createChild("div", "device-mode-co
ntent-area"); | |
44 | |
45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); | |
46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); | |
47 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin
d(this, true), false); | |
48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi
nd(this, false), false); | |
49 | |
50 this._cornerResizerElement = this._screenArea.createChild("div", "device
-mode-resizer device-mode-corner-resizer"); | |
51 this._cornerResizerElement.createChild("div", ""); | |
52 this._createResizer(this._cornerResizerElement, true, true); | |
53 | |
54 this._widthResizerElement = this._screenArea.createChild("div", "device-
mode-resizer device-mode-width-resizer"); | |
55 this._widthResizerElement.createChild("div", ""); | |
56 this._createResizer(this._widthResizerElement, true, false); | |
57 | |
58 this._heightResizerElement = this._screenArea.createChild("div", "device
-mode-resizer device-mode-height-resizer"); | |
59 this._heightResizerElement.createChild("div", ""); | |
60 this._createResizer(this._heightResizerElement, false, true); | |
61 this._heightResizerElement.addEventListener("dblclick", this._model.setH
eight.bind(this._model, 0), false); | |
62 this._heightResizerElement.title = WebInspector.UIString("Double-click f
or full height"); | |
63 | |
64 this._pageArea = this._screenArea.createChild("div", "device-mode-page-a
rea"); | |
65 this._pageArea.createChild("content"); | |
66 }, | |
67 | |
68 _populatePresetsContainer: function() | |
69 { | |
70 var sizes = [320, 375, 425, 768, 1024, 1440, 2560]; | |
71 var titles = [WebInspector.UIString("Mobile S"), | |
72 WebInspector.UIString("Mobile M"), | |
73 WebInspector.UIString("Mobile L"), | |
74 WebInspector.UIString("Tablet"), | |
75 WebInspector.UIString("Laptop"), | |
76 WebInspector.UIString("Laptop L"), | |
77 WebInspector.UIString("4K")] | |
78 this._presetBlocks = []; | |
79 var inner = this._responsivePresetsContainer.createChild("div", "device-
mode-presets-container-inner") | |
80 for (var i = sizes.length - 1; i >= 0; --i) { | |
81 var outer = inner.createChild("div", "fill device-mode-preset-bar-ou
ter"); | |
82 var block = outer.createChild("div", "device-mode-preset-bar"); | |
83 block.createChild("span").textContent = titles[i] + " \u2013 " + siz
es[i] + "px"; | |
84 block.addEventListener("click", applySize.bind(this, sizes[i]), fals
e); | |
85 block.__width = sizes[i]; | |
86 this._presetBlocks.push(block); | |
87 } | |
88 | |
89 /** | |
90 * @param {number} width | |
91 * @param {!Event} e | |
92 * @this {WebInspector.DeviceModeView} | |
93 */ | |
94 function applySize(width, e) | |
95 { | |
96 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, nu
ll, null); | |
97 this._model.setSizeAndScaleToFit(width, 0); | |
98 e.consume(); | |
99 } | |
100 }, | |
101 | |
102 toggleDeviceMode: function() | |
103 { | |
104 this._toolbar.toggleDeviceMode(); | |
105 }, | |
106 | |
107 /** | |
108 * @param {!Element} element | |
109 * @param {boolean} width | |
110 * @param {boolean} height | |
111 * @return {!WebInspector.ResizerWidget} | |
112 */ | |
113 _createResizer: function(element, width, height) | |
114 { | |
115 var resizer = new WebInspector.ResizerWidget(); | |
116 resizer.addElement(element); | |
117 resizer.setCursor(width && height ? "nwse-resize" : (width ? "ew-resize"
: "ns-resize")); | |
118 resizer.addEventListener(WebInspector.ResizerWidget.Events.ResizeStart,
this._onResizeStart, this); | |
119 resizer.addEventListener(WebInspector.ResizerWidget.Events.ResizeUpdate,
this._onResizeUpdate.bind(this, width, height)); | |
120 resizer.addEventListener(WebInspector.ResizerWidget.Events.ResizeEnd, th
is._onResizeEnd, this); | |
121 return resizer; | |
122 }, | |
123 | |
124 /** | |
125 * @param {!WebInspector.Event} event | |
126 */ | |
127 _onResizeStart: function(event) | |
128 { | |
129 this._slowPositionStart = null; | |
130 /** @type {!Size} */ | |
131 this._resizeStart = this._model.screenRect().size(); | |
132 }, | |
133 | |
134 /** | |
135 * @param {boolean} width | |
136 * @param {boolean} height | |
137 * @param {!WebInspector.Event} event | |
138 */ | |
139 _onResizeUpdate: function(width, height, event) | |
140 { | |
141 if (event.data.shiftKey !== !!this._slowPositionStart) | |
142 this._slowPositionStart = event.data.shiftKey ? {x: event.data.curre
ntX, y: event.data.currentY} : null; | |
143 | |
144 var cssOffsetX = event.data.currentX - event.data.startX; | |
145 var cssOffsetY = event.data.currentY - event.data.startY; | |
146 if (this._slowPositionStart) { | |
147 cssOffsetX = (event.data.currentX - this._slowPositionStart.x) / 10
+ this._slowPositionStart.x - event.data.startX; | |
148 cssOffsetY = (event.data.currentY - this._slowPositionStart.y) / 10
+ this._slowPositionStart.y - event.data.startY; | |
149 } | |
150 | |
151 if (width) { | |
152 var dipOffsetX = cssOffsetX * WebInspector.zoomManager.zoomFactor(); | |
153 var newWidth = this._resizeStart.width + dipOffsetX * 2; | |
154 newWidth = Math.round(newWidth / this._model.scale()); | |
155 if (newWidth >= WebInspector.DeviceModeModel.MinDeviceSize && newWid
th <= WebInspector.DeviceModeModel.MaxDeviceSize) | |
156 this._model.setWidth(newWidth); | |
157 } | |
158 | |
159 if (height) { | |
160 var dipOffsetY = cssOffsetY * WebInspector.zoomManager.zoomFactor(); | |
161 var newHeight = this._resizeStart.height + dipOffsetY; | |
162 newHeight = Math.round(newHeight / this._model.scale()); | |
163 if (newHeight >= WebInspector.DeviceModeModel.MinDeviceSize && newHe
ight <= WebInspector.DeviceModeModel.MaxDeviceSize) | |
164 this._model.setHeight(newHeight); | |
165 } | |
166 }, | |
167 | |
168 /** | |
169 * @param {!WebInspector.Event} event | |
170 */ | |
171 _onResizeEnd: function(event) | |
172 { | |
173 delete this._resizeStart; | |
174 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res
izedViewInResponsiveMode); | |
175 }, | |
176 | |
177 _updateUI: function() | |
178 { | |
179 if (!this.isShowing()) | |
180 return; | |
181 | |
182 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | |
183 var callDoResize = false; | |
184 var showRulers = this._showRulersSetting.get() && this._model.type() !==
WebInspector.DeviceModeModel.Type.None; | |
185 var contentAreaResized = false; | |
186 var updateRulers = false; | |
187 | |
188 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); | |
189 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { | |
190 this._screenArea.style.left = cssScreenRect.left + "px"; | |
191 this._screenArea.style.top = cssScreenRect.top + "px"; | |
192 this._screenArea.style.width = cssScreenRect.width + "px"; | |
193 this._screenArea.style.height = cssScreenRect.height + "px"; | |
194 this._leftRuler.element.style.left = cssScreenRect.left + "px"; | |
195 updateRulers = true; | |
196 callDoResize = true; | |
197 this._cachedCssScreenRect = cssScreenRect; | |
198 } | |
199 | |
200 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac
tor); | |
201 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { | |
202 this._pageArea.style.left = cssVisiblePageRect.left + "px"; | |
203 this._pageArea.style.top = cssVisiblePageRect.top + "px"; | |
204 this._pageArea.style.width = cssVisiblePageRect.width + "px"; | |
205 this._pageArea.style.height = cssVisiblePageRect.height + "px"; | |
206 callDoResize = true; | |
207 this._cachedCssVisiblePageRect = cssVisiblePageRect; | |
208 } | |
209 | |
210 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type
.Responsive; | |
211 if (resizable !== this._cachedResizable) { | |
212 this._widthResizerElement.classList.toggle("hidden", !resizable); | |
213 this._heightResizerElement.classList.toggle("hidden", !resizable); | |
214 this._cornerResizerElement.classList.toggle("hidden", !resizable); | |
215 this._cachedResizable = resizable; | |
216 } | |
217 | |
218 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi
s._model.type() !== WebInspector.DeviceModeModel.Type.None; | |
219 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) { | |
220 if (mediaInspectorVisible) | |
221 this._mediaInspector.show(this._mediaInspectorContainer); | |
222 else | |
223 this._mediaInspector.detach(); | |
224 contentAreaResized = true; | |
225 callDoResize = true; | |
226 this._cachedMediaInspectorVisible = mediaInspectorVisible; | |
227 } | |
228 | |
229 if (showRulers !== this._cachedShowRulers) { | |
230 this._contentClip.classList.toggle("device-mode-rulers-visible", sho
wRulers); | |
231 if (showRulers) { | |
232 this._topRuler.show(this._contentClip, this._contentArea); | |
233 this._leftRuler.show(this._contentArea); | |
234 } else { | |
235 this._topRuler.detach(); | |
236 this._leftRuler.detach(); | |
237 } | |
238 contentAreaResized = true; | |
239 callDoResize = true; | |
240 this._cachedShowRulers = showRulers; | |
241 } | |
242 | |
243 if (this._model.scale() !== this._cachedScale) { | |
244 updateRulers = true; | |
245 callDoResize = true; | |
246 for (var block of this._presetBlocks) | |
247 block.style.width = block.__width * this._model.scale() + "px"; | |
248 this._cachedScale = this._model.scale(); | |
249 } | |
250 | |
251 this._toolbar.update(); | |
252 this._loadScreenImage(this._model.screenImage()); | |
253 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); | |
254 if (callDoResize) | |
255 this.doResize(); | |
256 if (updateRulers) { | |
257 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); | |
258 this._leftRuler.render(0, this._model.scale()); | |
259 } | |
260 if (contentAreaResized) | |
261 this._contentAreaResized(); | |
262 }, | |
263 | |
264 /** | |
265 * @param {string} srcset | |
266 */ | |
267 _loadScreenImage: function(srcset) | |
268 { | |
269 if (this._screenImage.getAttribute("srcset") === srcset) | |
270 return; | |
271 this._screenImage.setAttribute("srcset", srcset); | |
272 if (!srcset) | |
273 this._screenImage.classList.toggle("hidden", true); | |
274 }, | |
275 | |
276 /** | |
277 * @param {boolean} success | |
278 */ | |
279 _onScreenImageLoaded: function(success) | |
280 { | |
281 this._screenImage.classList.toggle("hidden", !success); | |
282 }, | |
283 | |
284 _contentAreaResized: function() | |
285 { | |
286 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | |
287 var rect = this._contentArea.getBoundingClientRect(); | |
288 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); | |
289 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt
h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1
)); | |
290 this._model.setAvailableSize(availableSize, preferredSize); | |
291 }, | |
292 | |
293 _measureHandles: function() | |
294 { | |
295 var hidden = this._widthResizerElement.classList.contains("hidden"); | |
296 this._widthResizerElement.classList.toggle("hidden", false); | |
297 this._heightResizerElement.classList.toggle("hidden", false); | |
298 this._handleWidth = this._widthResizerElement.offsetWidth; | |
299 this._handleHeight = this._heightResizerElement.offsetHeight; | |
300 this._widthResizerElement.classList.toggle("hidden", hidden); | |
301 this._heightResizerElement.classList.toggle("hidden", hidden); | |
302 }, | |
303 | |
304 _zoomChanged: function() | |
305 { | |
306 delete this._handleWidth; | |
307 delete this._handleHeight; | |
308 if (this.isShowing()) { | |
309 this._measureHandles(); | |
310 this._contentAreaResized(); | |
311 } | |
312 }, | |
313 | |
314 /** | |
315 * @override | |
316 */ | |
317 onResize: function() | |
318 { | |
319 if (this.isShowing()) | |
320 this._contentAreaResized(); | |
321 }, | |
322 | |
323 /** | |
324 * @override | |
325 */ | |
326 wasShown: function() | |
327 { | |
328 this._measureHandles(); | |
329 this._mediaInspector.setEnabled(true); | |
330 this._toolbar.restore(); | |
331 }, | |
332 | |
333 /** | |
334 * @override | |
335 */ | |
336 willHide: function() | |
337 { | |
338 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, null); | |
339 this._mediaInspector.setEnabled(false); | |
340 }, | |
341 | |
342 __proto__: WebInspector.VBox.prototype | |
343 } | |
344 | |
345 /** | |
346 * @param {!WebInspector.DeviceModeModel} model | 6 * @param {!WebInspector.DeviceModeModel} model |
347 * @param {!WebInspector.Setting} showMediaInspectorSetting | 7 * @param {!WebInspector.Setting} showMediaInspectorSetting |
348 * @param {!WebInspector.Setting} showRulersSetting | 8 * @param {!WebInspector.Setting} showRulersSetting |
349 * @constructor | 9 * @constructor |
350 */ | 10 */ |
351 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting,
showRulersSetting) | 11 WebInspector.DeviceModeToolbar = function(model, showMediaInspectorSetting, show
RulersSetting) |
352 { | 12 { |
353 this._model = model; | 13 this._model = model; |
354 this._showMediaInspectorSetting = showMediaInspectorSetting; | 14 this._showMediaInspectorSetting = showMediaInspectorSetting; |
355 this._showRulersSetting = showRulersSetting; | 15 this._showRulersSetting = showRulersSetting; |
356 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ | 16 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ |
357 this._lastMode = new Map(); | 17 this._lastMode = new Map(); |
358 | 18 |
359 this._element = createElementWithClass("div", "device-mode-toolbar"); | 19 this._element = createElementWithClass("div", "device-mode-toolbar"); |
360 | 20 |
361 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp
acer"); | 21 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp
acer"); |
(...skipping 17 matching lines...) Expand all Loading... |
379 var optionsToolbar = new WebInspector.Toolbar("", rightContainer); | 39 var optionsToolbar = new WebInspector.Toolbar("", rightContainer); |
380 optionsToolbar.makeWrappable(true); | 40 optionsToolbar.makeWrappable(true); |
381 this._fillOptionsToolbar(optionsToolbar); | 41 this._fillOptionsToolbar(optionsToolbar); |
382 | 42 |
383 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, this._deviceListChanged, this); | 43 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, this._deviceListChanged, this); |
384 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, this._deviceListChanged, this); | 44 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, this._deviceListChanged, this); |
385 | 45 |
386 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeValue", {device: "", orientation: "", mode: ""}); | 46 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeValue", {device: "", orientation: "", mode: ""}); |
387 } | 47 } |
388 | 48 |
389 WebInspector.DeviceModeView.Toolbar.prototype = { | 49 WebInspector.DeviceModeToolbar.prototype = { |
390 /** | 50 /** |
391 * @param {!WebInspector.Toolbar} toolbar | 51 * @param {!WebInspector.Toolbar} toolbar |
392 */ | 52 */ |
393 _fillLeftToolbar: function(toolbar) | 53 _fillLeftToolbar: function(toolbar) |
394 { | 54 { |
395 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | 55 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); |
396 this._deviceSelectItem = new WebInspector.ToolbarMenuButton(this._append
DeviceMenuItems.bind(this)); | 56 this._deviceSelectItem = new WebInspector.ToolbarMenuButton(this._append
DeviceMenuItems.bind(this)); |
397 this._deviceSelectItem.setGlyph(""); | 57 this._deviceSelectItem.setGlyph(""); |
398 this._deviceSelectItem.turnIntoSelect(95); | 58 this._deviceSelectItem.turnIntoSelect(95); |
399 toolbar.appendToolbarItem(this._deviceSelectItem); | 59 toolbar.appendToolbarItem(this._deviceSelectItem); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 _appendDeviceMenuItems: function(contextMenu) | 381 _appendDeviceMenuItems: function(contextMenu) |
722 { | 382 { |
723 contextMenu.appendCheckboxItem(WebInspector.UIString("Responsive"), this
._switchToResponsive.bind(this), this._model.type() === WebInspector.DeviceModeM
odel.Type.Responsive, false); | 383 contextMenu.appendCheckboxItem(WebInspector.UIString("Responsive"), this
._switchToResponsive.bind(this), this._model.type() === WebInspector.DeviceModeM
odel.Type.Responsive, false); |
724 appendGroup.call(this, this._standardDevices()); | 384 appendGroup.call(this, this._standardDevices()); |
725 appendGroup.call(this, this._customDevices()); | 385 appendGroup.call(this, this._customDevices()); |
726 contextMenu.appendSeparator(); | 386 contextMenu.appendSeparator(); |
727 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), WebInspector
.emulatedDevicesList.revealCustomSetting.bind(WebInspector.emulatedDevicesList),
false); | 387 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), WebInspector
.emulatedDevicesList.revealCustomSetting.bind(WebInspector.emulatedDevicesList),
false); |
728 | 388 |
729 /** | 389 /** |
730 * @param {!Array<!WebInspector.EmulatedDevice>} devices | 390 * @param {!Array<!WebInspector.EmulatedDevice>} devices |
731 * @this {WebInspector.DeviceModeView.Toolbar} | 391 * @this {WebInspector.DeviceModeToolbar} |
732 */ | 392 */ |
733 function appendGroup(devices) | 393 function appendGroup(devices) |
734 { | 394 { |
735 if (!devices.length) | 395 if (!devices.length) |
736 return; | 396 return; |
737 contextMenu.appendSeparator(); | 397 contextMenu.appendSeparator(); |
738 for (var device of devices) | 398 for (var device of devices) |
739 contextMenu.appendCheckboxItem(device.title, this._emulateDevice
.bind(this, device), this._model.device() === device, false); | 399 contextMenu.appendCheckboxItem(device.title, this._emulateDevice
.bind(this, device), this._model.device() === device, false); |
740 } | 400 } |
741 }, | 401 }, |
742 | 402 |
743 /** | 403 /** |
744 * @this {WebInspector.DeviceModeView.Toolbar} | 404 * @this {WebInspector.DeviceModeToolbar} |
745 */ | 405 */ |
746 _deviceListChanged: function() | 406 _deviceListChanged: function() |
747 { | 407 { |
748 if (!this._model.device()) | 408 if (!this._model.device()) |
749 return; | 409 return; |
750 | 410 |
751 var devices = this._allDevices(); | 411 var devices = this._allDevices(); |
752 if (devices.indexOf(this._model.device()) === -1) | 412 if (devices.indexOf(this._model.device()) === -1) |
753 this._emulateDevice(devices[0] || WebInspector.emulatedDevicesList.s
tandard()[0]); | 413 this._emulateDevice(devices[0] || WebInspector.emulatedDevicesList.s
tandard()[0]); |
754 }, | 414 }, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 this._emulateDevice(device); | 557 this._emulateDevice(device); |
898 return; | 558 return; |
899 } | 559 } |
900 } | 560 } |
901 } | 561 } |
902 } | 562 } |
903 | 563 |
904 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); | 564 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); |
905 } | 565 } |
906 } | 566 } |
907 | |
908 /** | |
909 * @constructor | |
910 * @extends {WebInspector.VBox} | |
911 * @param {boolean} horizontal | |
912 * @param {function(number)} applyCallback | |
913 */ | |
914 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback) | |
915 { | |
916 WebInspector.VBox.call(this); | |
917 this._contentElement = this.element.createChild("div", "device-mode-ruler fl
ex-auto"); | |
918 this._horizontal = horizontal; | |
919 this._scale = 1; | |
920 this._offset = 0; | |
921 this._count = 0; | |
922 this._throttler = new WebInspector.Throttler(0); | |
923 this._applyCallback = applyCallback; | |
924 } | |
925 | |
926 WebInspector.DeviceModeView.Ruler.prototype = { | |
927 /** | |
928 * @param {number} offset | |
929 * @param {number} scale | |
930 */ | |
931 render: function(offset, scale) | |
932 { | |
933 this._scale = scale; | |
934 this._offset = offset; | |
935 if (this._horizontal) | |
936 this.element.style.paddingLeft = this._offset + "px"; | |
937 else | |
938 this.element.style.paddingTop = this._offset + "px"; | |
939 this._throttler.schedule(this._update.bind(this)); | |
940 }, | |
941 | |
942 /** | |
943 * @override | |
944 */ | |
945 onResize: function() | |
946 { | |
947 this._throttler.schedule(this._update.bind(this)); | |
948 }, | |
949 | |
950 /** | |
951 * @return {!Promise.<?>} | |
952 */ | |
953 _update: function() | |
954 { | |
955 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | |
956 var size = this._horizontal ? this._contentElement.offsetWidth : this._c
ontentElement.offsetHeight; | |
957 | |
958 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered
ZoomFactor) { | |
959 this._contentElement.removeChildren(); | |
960 this._count = 0; | |
961 this._renderedScale = this._scale; | |
962 this._renderedZoomFactor = zoomFactor; | |
963 } | |
964 | |
965 var dipSize = size * zoomFactor / this._scale; | |
966 var count = Math.ceil(dipSize / 5); | |
967 var step = 1; | |
968 if (this._scale < 0.8) | |
969 step = 2; | |
970 if (this._scale < 0.6) | |
971 step = 4; | |
972 if (this._scale < 0.4) | |
973 step = 8; | |
974 | |
975 for (var i = count; i < this._count; i++) { | |
976 if (!(i % step)) | |
977 this._contentElement.lastChild.remove(); | |
978 } | |
979 | |
980 for (var i = this._count; i < count; i++) { | |
981 if (i % step) | |
982 continue; | |
983 var marker = this._contentElement.createChild("div", "device-mode-ru
ler-marker"); | |
984 if (i) { | |
985 if (this._horizontal) | |
986 marker.style.left = (5 * i) * this._scale / zoomFactor + "px
"; | |
987 else | |
988 marker.style.top = (5 * i) * this._scale / zoomFactor + "px"
; | |
989 if (!(i % 20)) { | |
990 var text = marker.createChild("div", "device-mode-ruler-text
"); | |
991 text.textContent = i * 5; | |
992 text.addEventListener("click", this._onMarkerClick.bind(this
, i * 5), false); | |
993 } | |
994 } | |
995 if (!(i % 10)) | |
996 marker.classList.add("device-mode-ruler-marker-large"); | |
997 else if (!(i % 5)) | |
998 marker.classList.add("device-mode-ruler-marker-medium"); | |
999 } | |
1000 | |
1001 this._count = count; | |
1002 return Promise.resolve(); | |
1003 }, | |
1004 | |
1005 /** | |
1006 * @param {number} size | |
1007 */ | |
1008 _onMarkerClick: function(size) | |
1009 { | |
1010 this._applyCallback.call(null, size); | |
1011 }, | |
1012 | |
1013 __proto__: WebInspector.VBox.prototype | |
1014 } | |
1015 | |
1016 | |
1017 /** | |
1018 * @constructor | |
1019 * @implements {WebInspector.ActionDelegate} | |
1020 */ | |
1021 WebInspector.DeviceModeView.ActionDelegate = function() | |
1022 { | |
1023 } | |
1024 | |
1025 WebInspector.DeviceModeView.ActionDelegate.prototype = { | |
1026 /** | |
1027 * @override | |
1028 * @param {!WebInspector.Context} context | |
1029 * @param {string} actionId | |
1030 * @return {boolean} | |
1031 */ | |
1032 handleAction: function(context, actionId) | |
1033 { | |
1034 if (WebInspector.DeviceModeView._wrapperInstance) { | |
1035 if (actionId === "emulation.toggle-device-mode") { | |
1036 WebInspector.DeviceModeView._wrapperInstance._toggleDeviceMode()
; | |
1037 return true; | |
1038 } | |
1039 if (actionId === "emulation.request-app-banner") { | |
1040 WebInspector.DeviceModeView._wrapperInstance._requestAppBanner()
; | |
1041 return true; | |
1042 } | |
1043 } | |
1044 return false; | |
1045 } | |
1046 } | |
1047 | |
1048 | |
1049 /** | |
1050 * @extends {WebInspector.VBox} | |
1051 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder | |
1052 * @constructor | |
1053 */ | |
1054 WebInspector.DeviceModeView.Wrapper = function(inspectedPagePlaceholder) | |
1055 { | |
1056 WebInspector.VBox.call(this); | |
1057 WebInspector.DeviceModeView._wrapperInstance = this; | |
1058 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | |
1059 /** @type {?WebInspector.DeviceModeView} */ | |
1060 this._deviceModeView = null; | |
1061 this._toggleDeviceModeAction = WebInspector.actionRegistry.action("emulation
.toggle-device-mode"); | |
1062 this._showDeviceModeSetting = WebInspector.settings.createSetting("emulation
.showDeviceMode", false); | |
1063 this._showDeviceModeSetting.addChangeListener(this._update.bind(this, false)
); | |
1064 this._update(true); | |
1065 } | |
1066 | |
1067 /** @type {!WebInspector.DeviceModeView.Wrapper} */ | |
1068 WebInspector.DeviceModeView._wrapperInstance; | |
1069 | |
1070 WebInspector.DeviceModeView.Wrapper.prototype = { | |
1071 _toggleDeviceMode: function() | |
1072 { | |
1073 this._showDeviceModeSetting.set(!this._showDeviceModeSetting.get()); | |
1074 }, | |
1075 | |
1076 /** | |
1077 * @param {boolean} force | |
1078 */ | |
1079 _update: function(force) | |
1080 { | |
1081 this._toggleDeviceModeAction.setToggled(this._showDeviceModeSetting.get(
)); | |
1082 if (!force) { | |
1083 var showing = this._deviceModeView && this._deviceModeView.isShowing
(); | |
1084 if (this._showDeviceModeSetting.get() === showing) | |
1085 return; | |
1086 } | |
1087 | |
1088 if (this._showDeviceModeSetting.get()) { | |
1089 if (!this._deviceModeView) | |
1090 this._deviceModeView = new WebInspector.DeviceModeView(); | |
1091 this._deviceModeView.show(this.element); | |
1092 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | |
1093 this._inspectedPagePlaceholder.show(this._deviceModeView.element); | |
1094 } else { | |
1095 if (this._deviceModeView) | |
1096 this._deviceModeView.detach(); | |
1097 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | |
1098 this._inspectedPagePlaceholder.show(this.element); | |
1099 } | |
1100 }, | |
1101 | |
1102 _requestAppBanner: function() | |
1103 { | |
1104 this._deviceModeView._model.requestAppBanner(); | |
1105 }, | |
1106 | |
1107 __proto__: WebInspector.VBox.prototype | |
1108 } | |
OLD | NEW |