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