OLD | NEW |
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 */ | 8 */ |
9 WebInspector.DeviceModeView = function() | 9 WebInspector.DeviceModeView = function() |
10 { | 10 { |
(...skipping 21 matching lines...) Loading... |
32 | 32 |
33 WebInspector.DeviceModeView.prototype = { | 33 WebInspector.DeviceModeView.prototype = { |
34 _createUI: function() | 34 _createUI: function() |
35 { | 35 { |
36 this._toolbar = new WebInspector.DeviceModeView.Toolbar(this._model, thi
s._showMediaInspectorSetting, this._showRulersSetting); | 36 this._toolbar = new WebInspector.DeviceModeView.Toolbar(this._model, thi
s._showMediaInspectorSetting, this._showRulersSetting); |
37 this.contentElement.appendChild(this._toolbar.element()); | 37 this.contentElement.appendChild(this._toolbar.element()); |
38 | 38 |
39 this._contentClip = this.contentElement.createChild("div", "device-mode-
content-clip vbox"); | 39 this._contentClip = this.contentElement.createChild("div", "device-mode-
content-clip vbox"); |
40 this._mediaInspectorContainer = this._contentClip.createChild("div", "de
vice-mode-media-container"); | 40 this._mediaInspectorContainer = this._contentClip.createChild("div", "de
vice-mode-media-container"); |
41 this._contentArea = this._contentClip.createChild("div", "device-mode-co
ntent-area"); | 41 this._contentArea = this._contentClip.createChild("div", "device-mode-co
ntent-area"); |
42 this._deviceBlueprints = this._contentArea.createChild("div", "fill"); | |
43 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedD
evicesList.Events.StandardDevicesUpdated, this._updateBlueprints, this); | |
44 | 42 |
45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); | 43 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); |
46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); | 44 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); |
47 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin
d(this, true), false); | 45 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin
d(this, true), false); |
48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi
nd(this, false), false); | 46 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi
nd(this, false), false); |
49 | 47 |
50 this._cornerResizerElement = this._screenArea.createChild("div", "device
-mode-resizer device-mode-corner-resizer"); | 48 this._cornerResizerElement = this._screenArea.createChild("div", "device
-mode-resizer device-mode-corner-resizer"); |
51 this._cornerResizerElement.createChild("div", ""); | 49 this._cornerResizerElement.createChild("div", ""); |
52 this._createResizer(this._cornerResizerElement, true, true); | 50 this._createResizer(this._cornerResizerElement, true, true); |
53 | 51 |
54 this._widthResizerElement = this._screenArea.createChild("div", "device-
mode-resizer device-mode-width-resizer"); | 52 this._widthResizerElement = this._screenArea.createChild("div", "device-
mode-resizer device-mode-width-resizer"); |
55 this._widthResizerElement.createChild("div", ""); | 53 this._widthResizerElement.createChild("div", ""); |
56 this._createResizer(this._widthResizerElement, true, false); | 54 this._createResizer(this._widthResizerElement, true, false); |
57 | 55 |
58 this._heightResizerElement = this._screenArea.createChild("div", "device
-mode-resizer device-mode-height-resizer"); | 56 this._heightResizerElement = this._screenArea.createChild("div", "device
-mode-resizer device-mode-height-resizer"); |
59 this._heightResizerElement.createChild("div", ""); | 57 this._heightResizerElement.createChild("div", ""); |
60 this._createResizer(this._heightResizerElement, false, true); | 58 this._createResizer(this._heightResizerElement, false, true); |
| 59 this._heightResizerElement.addEventListener("dblclick", this._model.heig
htSetting().set.bind(this._model.heightSetting(), 0), false); |
61 | 60 |
62 this._pageArea = this._screenArea.createChild("div", "device-mode-page-a
rea"); | 61 this._pageArea = this._screenArea.createChild("div", "device-mode-page-a
rea"); |
63 this._pageArea.createChild("content"); | 62 this._pageArea.createChild("content"); |
64 }, | 63 }, |
65 | 64 |
66 toggleDeviceMode: function() | 65 toggleDeviceMode: function() |
67 { | 66 { |
68 this._toolbar.toggleDeviceMode(); | 67 this._toolbar.toggleDeviceMode(); |
69 }, | 68 }, |
70 | 69 |
(...skipping 15 matching lines...) Loading... |
86 }, | 85 }, |
87 | 86 |
88 /** | 87 /** |
89 * @param {!WebInspector.Event} event | 88 * @param {!WebInspector.Event} event |
90 */ | 89 */ |
91 _onResizeStart: function(event) | 90 _onResizeStart: function(event) |
92 { | 91 { |
93 this._slowPositionStart = null; | 92 this._slowPositionStart = null; |
94 /** @type {!Size} */ | 93 /** @type {!Size} */ |
95 this._resizeStart = this._model.screenRect().size(); | 94 this._resizeStart = this._model.screenRect().size(); |
96 this._model.suspendScaleChanges(); | |
97 }, | 95 }, |
98 | 96 |
99 /** | 97 /** |
100 * @param {boolean} width | 98 * @param {boolean} width |
101 * @param {boolean} height | 99 * @param {boolean} height |
102 * @param {!WebInspector.Event} event | 100 * @param {!WebInspector.Event} event |
103 */ | 101 */ |
104 _onResizeUpdate: function(width, height, event) | 102 _onResizeUpdate: function(width, height, event) |
105 { | 103 { |
106 if (event.data.shiftKey !== !!this._slowPositionStart) | 104 if (event.data.shiftKey !== !!this._slowPositionStart) |
(...skipping 22 matching lines...) Loading... |
129 this._model.heightSetting().set(newHeight); | 127 this._model.heightSetting().set(newHeight); |
130 } | 128 } |
131 }, | 129 }, |
132 | 130 |
133 /** | 131 /** |
134 * @param {!WebInspector.Event} event | 132 * @param {!WebInspector.Event} event |
135 */ | 133 */ |
136 _onResizeEnd: function(event) | 134 _onResizeEnd: function(event) |
137 { | 135 { |
138 delete this._resizeStart; | 136 delete this._resizeStart; |
139 this._model.resumeScaleChanges(); | |
140 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res
izedViewInResponsiveMode); | 137 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res
izedViewInResponsiveMode); |
141 }, | 138 }, |
142 | 139 |
143 /** | 140 /** |
144 * @param {number} width | 141 * @param {number} width |
145 * @param {number} height | 142 * @param {number} height |
146 */ | 143 */ |
147 _resizeTo: function(width, height) | 144 _resizeTo: function(width, height) |
148 { | 145 { |
149 this._model.widthSetting().set(width); | 146 this._model.widthSetting().set(width); |
150 this._model.heightSetting().set(height); | 147 this._model.heightSetting().set(height); |
151 }, | 148 }, |
152 | 149 |
153 _updateUI: function() | 150 _updateUI: function() |
154 { | 151 { |
155 if (!this.isShowing()) | 152 if (!this.isShowing()) |
156 return; | 153 return; |
157 | 154 |
158 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 155 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
159 var callDoResize = false; | 156 var callDoResize = false; |
160 var showRulers = this._showRulersSetting.get() && this._model.type() !==
WebInspector.DeviceModeModel.Type.None; | 157 var showRulers = this._showRulersSetting.get() && this._model.type() !==
WebInspector.DeviceModeModel.Type.None; |
161 var contentAreaResized = false; | 158 var contentAreaResized = false; |
162 var updateRulers = false; | 159 var updateRulers = false; |
163 | 160 |
164 if (this._cachedModelType !== this._model.type() || this._cachedModelSca
le !== this._model.scale()) { | |
165 this._updateBlueprints(); | |
166 this._cachedModelType = this._model.type(); | |
167 this._cachedModelScale = this._model.scale(); | |
168 } | |
169 | |
170 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); | 161 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); |
171 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { | 162 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { |
172 this._screenArea.style.left = cssScreenRect.left + "px"; | 163 this._screenArea.style.left = cssScreenRect.left + "px"; |
173 this._screenArea.style.top = cssScreenRect.top + "px"; | 164 this._screenArea.style.top = cssScreenRect.top + "px"; |
174 this._screenArea.style.width = cssScreenRect.width + "px"; | 165 this._screenArea.style.width = cssScreenRect.width + "px"; |
175 this._screenArea.style.height = cssScreenRect.height + "px"; | 166 this._screenArea.style.height = cssScreenRect.height + "px"; |
176 this._leftRuler.element.style.left = cssScreenRect.left + "px"; | 167 this._leftRuler.element.style.left = cssScreenRect.left + "px"; |
177 updateRulers = true; | 168 updateRulers = true; |
178 callDoResize = true; | 169 callDoResize = true; |
179 this._cachedCssScreenRect = cssScreenRect; | 170 this._cachedCssScreenRect = cssScreenRect; |
(...skipping 30 matching lines...) Loading... |
210 | 201 |
211 if (showRulers !== this._cachedShowRulers) { | 202 if (showRulers !== this._cachedShowRulers) { |
212 this._contentArea.classList.toggle("device-mode-rulers-visible", sho
wRulers); | 203 this._contentArea.classList.toggle("device-mode-rulers-visible", sho
wRulers); |
213 if (showRulers) { | 204 if (showRulers) { |
214 this._topRuler.show(this._contentClip, this._contentArea); | 205 this._topRuler.show(this._contentClip, this._contentArea); |
215 this._leftRuler.show(this._contentArea); | 206 this._leftRuler.show(this._contentArea); |
216 } else { | 207 } else { |
217 this._topRuler.detach(); | 208 this._topRuler.detach(); |
218 this._leftRuler.detach(); | 209 this._leftRuler.detach(); |
219 } | 210 } |
| 211 contentAreaResized = true; |
220 callDoResize = true; | 212 callDoResize = true; |
221 this._cachedShowRulers = showRulers; | 213 this._cachedShowRulers = showRulers; |
222 } | 214 } |
223 | 215 |
224 if (this._model.scale() !== this._cachedScale) { | 216 if (this._model.scale() !== this._cachedScale) { |
225 updateRulers = true; | 217 updateRulers = true; |
226 this._cachedScale = this._model.scale(); | 218 this._cachedScale = this._model.scale(); |
227 } | 219 } |
228 | 220 |
229 this._toolbar.update(); | 221 this._toolbar.update(); |
230 this._loadScreenImage(this._model.screenImage()); | 222 this._loadScreenImage(this._model.screenImage()); |
231 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); | 223 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); |
232 if (callDoResize) | 224 if (callDoResize) |
233 this.doResize(); | 225 this.doResize(); |
234 if (updateRulers) { | 226 if (updateRulers) { |
235 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); | 227 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); |
236 this._leftRuler.render(0, this._model.scale()); | 228 this._leftRuler.render(0, this._model.scale()); |
237 } | 229 } |
238 if (contentAreaResized) | 230 if (contentAreaResized) |
239 this._contentAreaResized(); | 231 this._contentAreaResized(); |
240 }, | 232 }, |
241 | 233 |
242 _updateBlueprints: function() | |
243 { | |
244 this._deviceBlueprints.removeChildren(); | |
245 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Responsive) | |
246 return; | |
247 var devices = WebInspector.emulatedDevicesList.standard(); | |
248 devices.sort((device1, device2) => device2.vertical.width * device2.vert
ical.height - device1.vertical.width * device1.vertical.height); | |
249 var scale = this._model.scale(); | |
250 for (var device of devices) { | |
251 if (!device.show()) | |
252 continue; | |
253 var blueprintContainer = this._deviceBlueprints.createChild("div", "
device-mode-blueprint-container fill"); | |
254 var blueprint = blueprintContainer.createChild("div", "device-mode-b
lueprint"); | |
255 blueprint.style.width = device.vertical.width * scale + "px"; | |
256 blueprint.style.height = device.vertical.height * scale + "px"; | |
257 var clickable = blueprint.createChild("div", "device-mode-blueprint-
border"); | |
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"); | |
261 } | |
262 }, | |
263 | |
264 /** | 234 /** |
265 * @param {string} srcset | 235 * @param {string} srcset |
266 */ | 236 */ |
267 _loadScreenImage: function(srcset) | 237 _loadScreenImage: function(srcset) |
268 { | 238 { |
269 if (this._screenImage.getAttribute("srcset") === srcset) | 239 if (this._screenImage.getAttribute("srcset") === srcset) |
270 return; | 240 return; |
271 this._screenImage.setAttribute("srcset", srcset); | 241 this._screenImage.setAttribute("srcset", srcset); |
272 if (!srcset) | 242 if (!srcset) |
273 this._screenImage.classList.toggle("hidden", true); | 243 this._screenImage.classList.toggle("hidden", true); |
274 }, | 244 }, |
275 | 245 |
276 /** | 246 /** |
277 * @param {boolean} success | 247 * @param {boolean} success |
278 */ | 248 */ |
279 _onScreenImageLoaded: function(success) | 249 _onScreenImageLoaded: function(success) |
280 { | 250 { |
281 this._screenImage.classList.toggle("hidden", !success); | 251 this._screenImage.classList.toggle("hidden", !success); |
282 }, | 252 }, |
283 | 253 |
284 _contentAreaResized: function() | 254 _contentAreaResized: function() |
285 { | 255 { |
286 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 256 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
287 var rect = this._contentArea.getBoundingClientRect(); | 257 var rect = this._contentArea.getBoundingClientRect(); |
288 this._model.setAvailableSize(new Size(Math.max(rect.width * zoomFactor,
1), Math.max(rect.height * zoomFactor, 1))); | 258 var handleWidth = this._widthResizerElement.offsetWidth; |
| 259 var handleHeight = this._heightResizerElement.offsetHeight; |
| 260 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); |
| 261 var preferredSize = new Size(Math.max((rect.width - 2 * handleWidth) * z
oomFactor, 1), Math.max((rect.height - handleHeight) * zoomFactor, 1)); |
| 262 this._model.setAvailableSize(availableSize, preferredSize); |
289 }, | 263 }, |
290 | 264 |
291 /** | 265 /** |
292 * @override | 266 * @override |
293 */ | 267 */ |
294 onResize: function() | 268 onResize: function() |
295 { | 269 { |
296 if (this.isShowing()) | 270 if (this.isShowing()) |
297 this._contentAreaResized(); | 271 this._contentAreaResized(); |
298 }, | 272 }, |
(...skipping 28 matching lines...) Loading... |
327 { | 301 { |
328 this._model = model; | 302 this._model = model; |
329 this._showMediaInspectorSetting = showMediaInspectorSetting; | 303 this._showMediaInspectorSetting = showMediaInspectorSetting; |
330 this._showRulersSetting = showRulersSetting; | 304 this._showRulersSetting = showRulersSetting; |
331 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ | 305 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ |
332 this._lastMode = new Map(); | 306 this._lastMode = new Map(); |
333 /** @type {?WebInspector.EmulatedDevice} */ | 307 /** @type {?WebInspector.EmulatedDevice} */ |
334 this._lastDevice = null; | 308 this._lastDevice = null; |
335 /** @type {!Array<!WebInspector.ToolbarLabel>} */ | 309 /** @type {!Array<!WebInspector.ToolbarLabel>} */ |
336 this._appliedSizeItems = []; | 310 this._appliedSizeItems = []; |
| 311 /** @type {!Array<!WebInspector.ToolbarMenuButton>} */ |
| 312 this._scaleItems = []; |
337 /** @type {?Element} */ | 313 /** @type {?Element} */ |
338 this._visibleToolbar = null; | 314 this._visibleToolbar = null; |
339 | 315 |
340 this._element = createElementWithClass("div", "device-mode-toolbar"); | 316 this._element = createElementWithClass("div", "device-mode-toolbar"); |
341 | 317 |
342 var leftContainer = this._element.createChild("div", "device-mode-toolbar-le
ft"); | 318 var leftContainer = this._element.createChild("div", "device-mode-toolbar-le
ft"); |
343 var leftToolbar = new WebInspector.Toolbar("", leftContainer); | 319 var leftToolbar = new WebInspector.Toolbar("", leftContainer); |
344 this._noneItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Full"
), "enter-fullscreen-toolbar-item"); | 320 this._noneItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Full"
), "enter-fullscreen-toolbar-item"); |
345 leftToolbar.appendToolbarItem(this._noneItem); | 321 leftToolbar.appendToolbarItem(this._noneItem); |
346 this._noneItem.addEventListener("click", this._noneButtonClick, this); | 322 this._noneItem.addEventListener("click", this._noneButtonClick, this); |
347 this._responsiveItem = new WebInspector.ToolbarToggle(WebInspector.UIString(
"Responsive"), "responsive-toolbar-item"); | 323 this._responsiveItem = new WebInspector.ToolbarToggle(WebInspector.UIString(
"Responsive"), "responsive-toolbar-item"); |
348 leftToolbar.appendToolbarItem(this._responsiveItem); | 324 leftToolbar.appendToolbarItem(this._responsiveItem); |
349 this._responsiveItem.addEventListener("click", this._responsiveButtonClick,
this); | 325 this._responsiveItem.addEventListener("click", this._responsiveButtonClick,
this); |
350 this._deviceItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Dev
ice"), "phone-toolbar-item"); | 326 this._deviceItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Dev
ice"), "phone-toolbar-item"); |
351 leftToolbar.appendToolbarItem(this._deviceItem); | 327 leftToolbar.appendToolbarItem(this._deviceItem); |
352 this._deviceItem.addEventListener("click", this._deviceButtonClick, this); | 328 this._deviceItem.addEventListener("click", this._deviceButtonClick, this); |
353 leftToolbar.appendSeparator(); | 329 leftToolbar.appendSeparator(); |
354 | 330 |
355 var middle = this._element.createChild("div", "device-mode-toolbar-middle-co
ntainer"); | 331 var middle = this._element.createChild("div", "device-mode-toolbar-middle-co
ntainer"); |
356 this._noneToolbar = this._wrapMiddleToolbar(middle, this._createNoneToolbar(
)); | 332 this._noneToolbar = this._wrapMiddleToolbar(middle, this._createNoneToolbar(
)); |
357 this._responsiveToolbar = this._wrapMiddleToolbar(middle, this._createRespon
siveToolbar()); | 333 this._responsiveToolbar = this._wrapMiddleToolbar(middle, this._createRespon
siveToolbar()); |
358 this._deviceToolbar = this._wrapMiddleToolbar(middle, this._createDeviceTool
bar()); | 334 this._deviceToolbar = this._wrapMiddleToolbar(middle, this._createDeviceTool
bar()); |
359 | 335 |
360 var rightContainer = this._element.createChild("div", "device-mode-toolbar-r
ight"); | 336 var rightContainer = this._element.createChild("div", "device-mode-toolbar-r
ight"); |
361 rightContainer.createChild("div", "device-mode-toolbar-spacer"); | 337 rightContainer.createChild("div", "device-mode-toolbar-spacer"); |
362 var rightToolbar = new WebInspector.Toolbar("", rightContainer); | 338 var rightToolbar = new WebInspector.Toolbar("", rightContainer); |
363 rightToolbar.makeWrappable(true); | 339 rightToolbar.makeWrappable(true); |
364 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMenuIt
ems.bind(this)); | |
365 this._scaleItem.setTitle(WebInspector.UIString("Click to change zoom")); | |
366 this._scaleItem.setGlyph(""); | |
367 this._scaleItem.setBold(false); | |
368 rightToolbar.appendToolbarItem(this._scaleItem); | |
369 rightToolbar.appendSeparator(); | 340 rightToolbar.appendSeparator(); |
370 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendMenuI
tems.bind(this)); | 341 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendMenuI
tems.bind(this)); |
371 moreOptionsButton.setTitle(WebInspector.UIString("More options")); | 342 moreOptionsButton.setTitle(WebInspector.UIString("More options")); |
372 rightToolbar.appendToolbarItem(moreOptionsButton); | 343 rightToolbar.appendToolbarItem(moreOptionsButton); |
373 | 344 |
374 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.None, device:
"", orientation: "", mode: ""}); | 345 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.None, device:
"", orientation: "", mode: ""}); |
375 this._restored = false; | 346 this._restored = false; |
376 } | 347 } |
377 | 348 |
378 WebInspector.DeviceModeView.Toolbar.prototype = { | 349 WebInspector.DeviceModeView.Toolbar.prototype = { |
(...skipping 35 matching lines...) Loading... |
414 widthInput.title = WebInspector.UIString("Width"); | 385 widthInput.title = WebInspector.UIString("Width"); |
415 WebInspector.SettingsUI.bindSettingInputField(widthInput, this._model.wi
dthSetting(), true, WebInspector.DeviceModeModel.deviceSizeValidator, true); | 386 WebInspector.SettingsUI.bindSettingInputField(widthInput, this._model.wi
dthSetting(), true, WebInspector.DeviceModeModel.deviceSizeValidator, true); |
416 toolbar.appendToolbarItem(this._wrapToolbarItem(widthInput)); | 387 toolbar.appendToolbarItem(this._wrapToolbarItem(widthInput)); |
417 | 388 |
418 var xElement = createElementWithClass("div", "device-mode-x"); | 389 var xElement = createElementWithClass("div", "device-mode-x"); |
419 xElement.textContent = "\u00D7"; | 390 xElement.textContent = "\u00D7"; |
420 toolbar.appendToolbarItem(this._wrapToolbarItem(xElement)); | 391 toolbar.appendToolbarItem(this._wrapToolbarItem(xElement)); |
421 | 392 |
422 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); | 393 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); |
423 heightInput.maxLength = 5; | 394 heightInput.maxLength = 5; |
424 heightInput.title = WebInspector.UIString("Height"); | 395 heightInput.title = WebInspector.UIString("Height (leave empty to fit)")
; |
425 WebInspector.SettingsUI.bindSettingInputField(heightInput, this._model.h
eightSetting(), true, WebInspector.DeviceModeModel.deviceSizeValidator, true); | 396 WebInspector.SettingsUI.bindSettingInputField(heightInput, this._model.h
eightSetting(), true, validateHeight, true, true); |
426 toolbar.appendToolbarItem(this._wrapToolbarItem(heightInput)); | 397 toolbar.appendToolbarItem(this._wrapToolbarItem(heightInput)); |
| 398 this._heightInput = heightInput; |
427 | 399 |
| 400 toolbar.appendSeparator(); |
| 401 this._appendScaleItem(toolbar); |
428 return toolbar; | 402 return toolbar; |
| 403 |
| 404 /** |
| 405 * @param {string} value |
| 406 * @return {string} |
| 407 */ |
| 408 function validateHeight(value) |
| 409 { |
| 410 return !value ? "" : WebInspector.DeviceModeModel.deviceSizeValidato
r(value); |
| 411 } |
429 }, | 412 }, |
430 | 413 |
431 /** | 414 /** |
432 * @return {!WebInspector.Toolbar} | 415 * @return {!WebInspector.Toolbar} |
433 */ | 416 */ |
434 _createDeviceToolbar: function() | 417 _createDeviceToolbar: function() |
435 { | 418 { |
436 var toolbar = new WebInspector.Toolbar(""); | 419 var toolbar = new WebInspector.Toolbar(""); |
437 | 420 |
438 this._deviceSelect = this._createDeviceSelect(); | 421 this._deviceSelect = this._createDeviceSelect(); |
439 toolbar.appendToolbarItem(this._wrapToolbarItem(this._deviceSelect)); | 422 toolbar.appendToolbarItem(this._wrapToolbarItem(this._deviceSelect)); |
440 | 423 |
441 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); | 424 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); |
442 this._modeButton.addEventListener("click", this._modeMenuClicked, this); | 425 this._modeButton.addEventListener("click", this._modeMenuClicked, this); |
443 toolbar.appendToolbarItem(this._modeButton); | 426 toolbar.appendToolbarItem(this._modeButton); |
444 | 427 |
445 toolbar.appendSeparator(); | 428 toolbar.appendSeparator(); |
446 this._appendAppliedSizeItems(toolbar); | 429 this._appendAppliedSizeItems(toolbar); |
| 430 toolbar.appendSeparator(); |
| 431 this._appendScaleItem(toolbar); |
447 | 432 |
448 return toolbar; | 433 return toolbar; |
449 }, | 434 }, |
450 | 435 |
451 /** | 436 /** |
452 * @param {!WebInspector.Toolbar} toolbar | 437 * @param {!WebInspector.Toolbar} toolbar |
453 */ | 438 */ |
454 _appendAppliedSizeItems: function(toolbar) | 439 _appendAppliedSizeItems: function(toolbar) |
455 { | 440 { |
456 var item = new WebInspector.ToolbarLabel(); | 441 var item = new WebInspector.ToolbarLabel(); |
457 this._appliedSizeItems.push(item); | 442 this._appliedSizeItems.push(item); |
458 toolbar.appendToolbarItem(item); | 443 toolbar.appendToolbarItem(item); |
459 }, | 444 }, |
460 | 445 |
461 /** | 446 /** |
| 447 * @param {!WebInspector.Toolbar} toolbar |
| 448 */ |
| 449 _appendScaleItem: function(toolbar) |
| 450 { |
| 451 var scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMenu
Items.bind(this)); |
| 452 scaleItem.setTitle(WebInspector.UIString("Click to change zoom")); |
| 453 scaleItem.setGlyph(""); |
| 454 scaleItem.setBold(false); |
| 455 scaleItem.addDropDownArrow(); |
| 456 toolbar.appendToolbarItem(scaleItem); |
| 457 this._scaleItems.push(scaleItem); |
| 458 }, |
| 459 |
| 460 /** |
462 * @param {!WebInspector.ContextMenu} contextMenu | 461 * @param {!WebInspector.ContextMenu} contextMenu |
463 */ | 462 */ |
464 _appendScaleMenuItems: function(contextMenu) | 463 _appendScaleMenuItems: function(contextMenu) |
465 { | 464 { |
466 var scaleSetting = this._model.scaleSetting(); | 465 var scaleSetting = this._model.scaleSetting(); |
467 appendScaleItem(WebInspector.UIString("Fit"), 0); | |
468 contextMenu.appendSeparator(); | |
469 appendScaleItem(WebInspector.UIString("25%"), 0.25); | 466 appendScaleItem(WebInspector.UIString("25%"), 0.25); |
470 appendScaleItem(WebInspector.UIString("50%"), 0.5); | 467 appendScaleItem(WebInspector.UIString("50%"), 0.5); |
471 appendScaleItem(WebInspector.UIString("100%"), 1); | 468 appendScaleItem(WebInspector.UIString("100%"), 1); |
472 appendScaleItem(WebInspector.UIString("150%"), 1.5); | 469 appendScaleItem(WebInspector.UIString("150%"), 1.5); |
473 appendScaleItem(WebInspector.UIString("200%"), 2); | 470 appendScaleItem(WebInspector.UIString("200%"), 2); |
| 471 contextMenu.appendSeparator(); |
| 472 contextMenu.appendItem(WebInspector.UIString("Fit (%.0f%%)", this._model
.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._model.fitScale()),
false); |
474 | 473 |
475 /** | 474 /** |
476 * @param {string} title | 475 * @param {string} title |
477 * @param {number} value | 476 * @param {number} value |
478 */ | 477 */ |
479 function appendScaleItem(title, value) | 478 function appendScaleItem(title, value) |
480 { | 479 { |
481 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, false); | 480 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, false); |
482 } | 481 } |
483 }, | 482 }, |
484 | 483 |
485 /** | 484 /** |
486 * @param {!WebInspector.ContextMenu} contextMenu | 485 * @param {!WebInspector.ContextMenu} contextMenu |
487 */ | 486 */ |
488 _appendMenuItems: function(contextMenu) | 487 _appendMenuItems: function(contextMenu) |
489 { | 488 { |
490 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; | 489 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; |
491 var uaSetting = this._model.uaSetting(); | 490 var uaSetting = this._model.uaSetting(); |
492 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); | 491 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); |
| 492 var uaValue = this._model.uaSetting().get(); |
| 493 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) |
| 494 uaValue = WebInspector.DeviceModeModel.UA.Desktop; |
| 495 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) |
| 496 uaValue = this._model.device().mobile() ? WebInspector.DeviceModeMod
el.UA.Mobile : this._model.device().touch() ? WebInspector.DeviceModeModel.UA.De
sktopTouch : WebInspector.DeviceModeModel.UA.Desktop; |
493 appendUAItem(WebInspector.UIString("Mobile"), WebInspector.DeviceModeMod
el.UA.Mobile); | 497 appendUAItem(WebInspector.UIString("Mobile"), WebInspector.DeviceModeMod
el.UA.Mobile); |
494 appendUAItem(WebInspector.UIString("Desktop"), WebInspector.DeviceModeMo
del.UA.Desktop); | 498 appendUAItem(WebInspector.UIString("Desktop"), WebInspector.DeviceModeMo
del.UA.Desktop); |
495 appendUAItem(WebInspector.UIString("Desktop with touch"), WebInspector.D
eviceModeModel.UA.DesktopTouch); | 499 appendUAItem(WebInspector.UIString("Desktop with touch"), WebInspector.D
eviceModeModel.UA.DesktopTouch); |
496 | 500 |
497 /** | 501 /** |
498 * @param {string} title | 502 * @param {string} title |
499 * @param {!WebInspector.DeviceModeModel.UA} value | 503 * @param {!WebInspector.DeviceModeModel.UA} value |
500 */ | 504 */ |
501 function appendUAItem(title, value) | 505 function appendUAItem(title, value) |
502 { | 506 { |
503 uaSubmenu.appendCheckboxItem(title, uaSetting.set.bind(uaSetting, va
lue), uaSetting.get() === value, uaDisabled); | 507 uaSubmenu.appendCheckboxItem(title, uaSetting.set.bind(uaSetting, va
lue), uaValue === value, uaDisabled); |
504 } | 508 } |
505 | 509 |
506 var deviceScaleFactorDisabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; | 510 var deviceScaleFactorDisabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; |
507 var deviceScaleFactorSubmenu = contextMenu.appendSubMenuItem(WebInspecto
r.UIString("Device pixel ratio"), false); | 511 var deviceScaleFactorSubmenu = contextMenu.appendSubMenuItem(WebInspecto
r.UIString("Device pixel ratio"), false); |
508 var deviceScaleFactorSetting = this._model.deviceScaleFactorSetting(); | 512 var deviceScaleFactorSetting = this._model.deviceScaleFactorSetting(); |
| 513 var deviceScaleFactorValue = deviceScaleFactorDisabled ? 0 : deviceScale
FactorSetting.get(); |
509 appendDeviceScaleFactorItem(WebInspector.UIString("Default: %f", this._m
odel.defaultDeviceScaleFactor()), 0); | 514 appendDeviceScaleFactorItem(WebInspector.UIString("Default: %f", this._m
odel.defaultDeviceScaleFactor()), 0); |
510 deviceScaleFactorSubmenu.appendSeparator(); | 515 deviceScaleFactorSubmenu.appendSeparator(); |
511 appendDeviceScaleFactorItem(WebInspector.UIString("1"), 1); | 516 appendDeviceScaleFactorItem(WebInspector.UIString("1"), 1); |
512 appendDeviceScaleFactorItem(WebInspector.UIString("2"), 2); | 517 appendDeviceScaleFactorItem(WebInspector.UIString("2"), 2); |
513 appendDeviceScaleFactorItem(WebInspector.UIString("3"), 3); | 518 appendDeviceScaleFactorItem(WebInspector.UIString("3"), 3); |
514 | 519 |
515 /** | 520 /** |
516 * @param {string} title | 521 * @param {string} title |
517 * @param {number} value | 522 * @param {number} value |
518 */ | 523 */ |
519 function appendDeviceScaleFactorItem(title, value) | 524 function appendDeviceScaleFactorItem(title, value) |
520 { | 525 { |
521 deviceScaleFactorSubmenu.appendCheckboxItem(title, deviceScaleFactor
Setting.set.bind(deviceScaleFactorSetting, value), deviceScaleFactorSetting.get(
) === value, deviceScaleFactorDisabled); | 526 deviceScaleFactorSubmenu.appendCheckboxItem(title, deviceScaleFactor
Setting.set.bind(deviceScaleFactorSetting, value), deviceScaleFactorValue === va
lue, deviceScaleFactorDisabled); |
522 } | 527 } |
523 | 528 |
524 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this.
_model.reset.bind(this._model), this._model.type() !== WebInspector.DeviceModeMo
del.Type.Responsive); | 529 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this.
_model.reset.bind(this._model), this._model.type() !== WebInspector.DeviceModeMo
del.Type.Responsive); |
525 contextMenu.appendSeparator(); | 530 contextMenu.appendSeparator(); |
526 | 531 |
527 contextMenu.appendCheckboxItem(WebInspector.UIString("Show media queries
"), this._toggleMediaInspector.bind(this), this._showMediaInspectorSetting.get()
, this._model.type() === WebInspector.DeviceModeModel.Type.None); | 532 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); | 533 contextMenu.appendCheckboxItem(WebInspector.UIString("Show rulers"), thi
s._toggleRulers.bind(this), this._showRulersSetting.get(), this._model.type() ==
= WebInspector.DeviceModeModel.Type.None); |
529 contextMenu.appendItem(WebInspector.UIString("Configure network\u2026"),
this._openNetworkConfig.bind(this), false); | 534 contextMenu.appendItem(WebInspector.UIString("Configure network\u2026"),
this._openNetworkConfig.bind(this), false); |
530 }, | 535 }, |
531 | 536 |
(...skipping 215 matching lines...) Loading... |
747 }, | 752 }, |
748 | 753 |
749 update: function() | 754 update: function() |
750 { | 755 { |
751 var updatePersistence = false; | 756 var updatePersistence = false; |
752 | 757 |
753 if (this._model.type() !== this._cachedModelType) { | 758 if (this._model.type() !== this._cachedModelType) { |
754 this._noneItem.setToggled(this._model.type() === WebInspector.Device
ModeModel.Type.None); | 759 this._noneItem.setToggled(this._model.type() === WebInspector.Device
ModeModel.Type.None); |
755 this._responsiveItem.setToggled(this._model.type() === WebInspector.
DeviceModeModel.Type.Responsive); | 760 this._responsiveItem.setToggled(this._model.type() === WebInspector.
DeviceModeModel.Type.Responsive); |
756 this._deviceItem.setToggled(this._model.type() === WebInspector.Devi
ceModeModel.Type.Device); | 761 this._deviceItem.setToggled(this._model.type() === WebInspector.Devi
ceModeModel.Type.Device); |
757 this._scaleItem.setVisible(this._model.type() !== WebInspector.Devic
eModeModel.Type.None); | |
758 | 762 |
759 var toolbar = null; | 763 var toolbar = null; |
760 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) | 764 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) |
761 toolbar = this._noneToolbar; | 765 toolbar = this._noneToolbar; |
762 else if (this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive) | 766 else if (this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive) |
763 toolbar = this._responsiveToolbar; | 767 toolbar = this._responsiveToolbar; |
764 else if (this._model.type() === WebInspector.DeviceModeModel.Type.De
vice) | 768 else if (this._model.type() === WebInspector.DeviceModeModel.Type.De
vice) |
765 toolbar = this._deviceToolbar; | 769 toolbar = this._deviceToolbar; |
766 | 770 |
767 if (this._visibleToolbar !== toolbar) { | 771 if (this._visibleToolbar !== toolbar) { |
768 if (this._visibleToolbar) | 772 if (this._visibleToolbar) |
769 this._visibleToolbar.classList.add("hidden"); | 773 this._visibleToolbar.classList.add("hidden"); |
770 if (toolbar) { | 774 if (toolbar) { |
771 toolbar.classList.remove("hidden"); | 775 toolbar.classList.remove("hidden"); |
772 toolbar.animate([{opacity: "0"}, {opacity: "1"}], {duration:
100}); | 776 toolbar.animate([{opacity: "0"}, {opacity: "1"}], {duration:
100}); |
773 } | 777 } |
774 this._visibleToolbar = toolbar; | 778 this._visibleToolbar = toolbar; |
775 } | 779 } |
776 | 780 |
777 this._previousModelType = this._cachedModelType; | 781 this._previousModelType = this._cachedModelType; |
778 this._cachedModelType = this._model.type(); | 782 this._cachedModelType = this._model.type(); |
779 updatePersistence = true; | 783 updatePersistence = true; |
780 } | 784 } |
781 | 785 |
782 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Responsive)
{ | 786 var size = this._model.appliedDeviceSize(); |
783 var size = this._model.appliedDeviceSize(); | 787 if (!size.isEqual(this._cachedSize)) { |
784 if (!size.isEqual(this._cachedSize)) { | 788 for (var item of this._appliedSizeItems) |
785 for (var item of this._appliedSizeItems) | 789 item.setText(WebInspector.UIString("%d \u00D7 %d", size.width, s
ize.height)); |
786 item.setText(WebInspector.UIString("%d \u00D7 %d", size.widt
h, size.height)); | 790 this._heightInput.placeholder = size.height; |
787 this._cachedSize = size; | 791 this._cachedSize = size; |
788 } | |
789 } | 792 } |
790 | 793 |
791 if (this._model.scale() !== this._cachedScale) { | 794 if (this._model.scale() !== this._cachedScale) { |
792 this._scaleItem.setText(WebInspector.UIString("Zoom: %.0f%%", this._
model.scale() * 100)); | 795 for (var item of this._scaleItems) |
793 this._scaleItem.setDimmed(this._model.scale() === 1); | 796 item.setText(WebInspector.UIString("%.0f%%", this._model.scale()
* 100)); |
794 this._cachedScale = this._model.scale(); | 797 this._cachedScale = this._model.scale(); |
795 } | 798 } |
796 | 799 |
797 if (this._model.device() !== this._cachedModelDevice) { | 800 if (this._model.device() !== this._cachedModelDevice) { |
798 var device = this._model.device(); | 801 var device = this._model.device(); |
799 | 802 |
800 if (device) { | 803 if (device) { |
801 var modeCount = device ? device.modes.length : 0; | 804 var modeCount = device ? device.modes.length : 0; |
802 this._modeButton.setEnabled(modeCount >= 2); | 805 this._modeButton.setEnabled(modeCount >= 2); |
803 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); | 806 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); |
(...skipping 247 matching lines...) Loading... |
1051 } else { | 1054 } else { |
1052 this._deviceModeView.detach(); | 1055 this._deviceModeView.detach(); |
1053 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | 1056 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); |
1054 this._inspectedPagePlaceholder.show(this.element); | 1057 this._inspectedPagePlaceholder.show(this.element); |
1055 this._deviceModeView._model.emulate(WebInspector.DeviceModeModel.Typ
e.None, null, null); | 1058 this._deviceModeView._model.emulate(WebInspector.DeviceModeModel.Typ
e.None, null, null); |
1056 } | 1059 } |
1057 }, | 1060 }, |
1058 | 1061 |
1059 __proto__: WebInspector.VBox.prototype | 1062 __proto__: WebInspector.VBox.prototype |
1060 } | 1063 } |
OLD | NEW |