| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @implements {WebInspector.TargetManager.Observer} | 5 * @implements {SDK.TargetManager.Observer} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 WebInspector.MediaQueryInspector = class extends WebInspector.Widget { | 8 Emulation.MediaQueryInspector = class extends UI.Widget { |
| 9 /** | 9 /** |
| 10 * @param {function():number} getWidthCallback | 10 * @param {function():number} getWidthCallback |
| 11 * @param {function(number)} setWidthCallback | 11 * @param {function(number)} setWidthCallback |
| 12 */ | 12 */ |
| 13 constructor(getWidthCallback, setWidthCallback) { | 13 constructor(getWidthCallback, setWidthCallback) { |
| 14 super(true); | 14 super(true); |
| 15 this.registerRequiredCSS('emulation/mediaQueryInspector.css'); | 15 this.registerRequiredCSS('emulation/mediaQueryInspector.css'); |
| 16 this.contentElement.classList.add('media-inspector-view'); | 16 this.contentElement.classList.add('media-inspector-view'); |
| 17 this.contentElement.addEventListener('click', this._onMediaQueryClicked.bind
(this), false); | 17 this.contentElement.addEventListener('click', this._onMediaQueryClicked.bind
(this), false); |
| 18 this.contentElement.addEventListener('contextmenu', this._onContextMenu.bind
(this), false); | 18 this.contentElement.addEventListener('contextmenu', this._onContextMenu.bind
(this), false); |
| 19 this._mediaThrottler = new WebInspector.Throttler(0); | 19 this._mediaThrottler = new Common.Throttler(0); |
| 20 | 20 |
| 21 this._getWidthCallback = getWidthCallback; | 21 this._getWidthCallback = getWidthCallback; |
| 22 this._setWidthCallback = setWidthCallback; | 22 this._setWidthCallback = setWidthCallback; |
| 23 this._scale = 1; | 23 this._scale = 1; |
| 24 | 24 |
| 25 WebInspector.targetManager.observeTargets(this); | 25 SDK.targetManager.observeTargets(this); |
| 26 WebInspector.zoomManager.addEventListener( | 26 UI.zoomManager.addEventListener( |
| 27 WebInspector.ZoomManager.Events.ZoomChanged, this._renderMediaQueries.bi
nd(this), this); | 27 UI.ZoomManager.Events.ZoomChanged, this._renderMediaQueries.bind(this),
this); |
| 28 } | 28 } |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * @override | 31 * @override |
| 32 * @param {!WebInspector.Target} target | 32 * @param {!SDK.Target} target |
| 33 */ | 33 */ |
| 34 targetAdded(target) { | 34 targetAdded(target) { |
| 35 // FIXME: adapt this to multiple targets. | 35 // FIXME: adapt this to multiple targets. |
| 36 if (this._cssModel) | 36 if (this._cssModel) |
| 37 return; | 37 return; |
| 38 this._cssModel = WebInspector.CSSModel.fromTarget(target); | 38 this._cssModel = SDK.CSSModel.fromTarget(target); |
| 39 if (!this._cssModel) | 39 if (!this._cssModel) |
| 40 return; | 40 return; |
| 41 this._cssModel.addEventListener( | 41 this._cssModel.addEventListener( |
| 42 WebInspector.CSSModel.Events.StyleSheetAdded, this._scheduleMediaQueries
Update, this); | 42 SDK.CSSModel.Events.StyleSheetAdded, this._scheduleMediaQueriesUpdate, t
his); |
| 43 this._cssModel.addEventListener( | 43 this._cssModel.addEventListener( |
| 44 WebInspector.CSSModel.Events.StyleSheetRemoved, this._scheduleMediaQueri
esUpdate, this); | 44 SDK.CSSModel.Events.StyleSheetRemoved, this._scheduleMediaQueriesUpdate,
this); |
| 45 this._cssModel.addEventListener( | 45 this._cssModel.addEventListener( |
| 46 WebInspector.CSSModel.Events.StyleSheetChanged, this._scheduleMediaQueri
esUpdate, this); | 46 SDK.CSSModel.Events.StyleSheetChanged, this._scheduleMediaQueriesUpdate,
this); |
| 47 this._cssModel.addEventListener( | 47 this._cssModel.addEventListener( |
| 48 WebInspector.CSSModel.Events.MediaQueryResultChanged, this._scheduleMedi
aQueriesUpdate, this); | 48 SDK.CSSModel.Events.MediaQueryResultChanged, this._scheduleMediaQueriesU
pdate, this); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @override | 52 * @override |
| 53 * @param {!WebInspector.Target} target | 53 * @param {!SDK.Target} target |
| 54 */ | 54 */ |
| 55 targetRemoved(target) { | 55 targetRemoved(target) { |
| 56 if (WebInspector.CSSModel.fromTarget(target) !== this._cssModel) | 56 if (SDK.CSSModel.fromTarget(target) !== this._cssModel) |
| 57 return; | 57 return; |
| 58 this._cssModel.removeEventListener( | 58 this._cssModel.removeEventListener( |
| 59 WebInspector.CSSModel.Events.StyleSheetAdded, this._scheduleMediaQueries
Update, this); | 59 SDK.CSSModel.Events.StyleSheetAdded, this._scheduleMediaQueriesUpdate, t
his); |
| 60 this._cssModel.removeEventListener( | 60 this._cssModel.removeEventListener( |
| 61 WebInspector.CSSModel.Events.StyleSheetRemoved, this._scheduleMediaQueri
esUpdate, this); | 61 SDK.CSSModel.Events.StyleSheetRemoved, this._scheduleMediaQueriesUpdate,
this); |
| 62 this._cssModel.removeEventListener( | 62 this._cssModel.removeEventListener( |
| 63 WebInspector.CSSModel.Events.StyleSheetChanged, this._scheduleMediaQueri
esUpdate, this); | 63 SDK.CSSModel.Events.StyleSheetChanged, this._scheduleMediaQueriesUpdate,
this); |
| 64 this._cssModel.removeEventListener( | 64 this._cssModel.removeEventListener( |
| 65 WebInspector.CSSModel.Events.MediaQueryResultChanged, this._scheduleMedi
aQueriesUpdate, this); | 65 SDK.CSSModel.Events.MediaQueryResultChanged, this._scheduleMediaQueriesU
pdate, this); |
| 66 delete this._cssModel; | 66 delete this._cssModel; |
| 67 } | 67 } |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @param {number} scale | 70 * @param {number} scale |
| 71 */ | 71 */ |
| 72 setAxisTransform(scale) { | 72 setAxisTransform(scale) { |
| 73 if (Math.abs(this._scale - scale) < 1e-8) | 73 if (Math.abs(this._scale - scale) < 1e-8) |
| 74 return; | 74 return; |
| 75 this._scale = scale; | 75 this._scale = scale; |
| 76 this._renderMediaQueries(); | 76 this._renderMediaQueries(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * @param {!Event} event | 80 * @param {!Event} event |
| 81 */ | 81 */ |
| 82 _onMediaQueryClicked(event) { | 82 _onMediaQueryClicked(event) { |
| 83 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass('media-insp
ector-bar'); | 83 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass('media-insp
ector-bar'); |
| 84 if (!mediaQueryMarker) | 84 if (!mediaQueryMarker) |
| 85 return; | 85 return; |
| 86 | 86 |
| 87 var model = mediaQueryMarker._model; | 87 var model = mediaQueryMarker._model; |
| 88 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { | 88 if (model.section() === Emulation.MediaQueryInspector.Section.Max) { |
| 89 this._setWidthCallback(model.maxWidthExpression().computedLength()); | 89 this._setWidthCallback(model.maxWidthExpression().computedLength()); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { | 92 if (model.section() === Emulation.MediaQueryInspector.Section.Min) { |
| 93 this._setWidthCallback(model.minWidthExpression().computedLength()); | 93 this._setWidthCallback(model.minWidthExpression().computedLength()); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 var currentWidth = this._getWidthCallback(); | 96 var currentWidth = this._getWidthCallback(); |
| 97 if (currentWidth !== model.minWidthExpression().computedLength()) | 97 if (currentWidth !== model.minWidthExpression().computedLength()) |
| 98 this._setWidthCallback(model.minWidthExpression().computedLength()); | 98 this._setWidthCallback(model.minWidthExpression().computedLength()); |
| 99 else | 99 else |
| 100 this._setWidthCallback(model.maxWidthExpression().computedLength()); | 100 this._setWidthCallback(model.maxWidthExpression().computedLength()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @param {!Event} event | 104 * @param {!Event} event |
| 105 */ | 105 */ |
| 106 _onContextMenu(event) { | 106 _onContextMenu(event) { |
| 107 if (!this._cssModel || !this._cssModel.isEnabled()) | 107 if (!this._cssModel || !this._cssModel.isEnabled()) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass('media-insp
ector-bar'); | 110 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass('media-insp
ector-bar'); |
| 111 if (!mediaQueryMarker) | 111 if (!mediaQueryMarker) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 var locations = mediaQueryMarker._locations; | 114 var locations = mediaQueryMarker._locations; |
| 115 var uiLocations = new Map(); | 115 var uiLocations = new Map(); |
| 116 for (var i = 0; i < locations.length; ++i) { | 116 for (var i = 0; i < locations.length; ++i) { |
| 117 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(
locations[i]); | 117 var uiLocation = Bindings.cssWorkspaceBinding.rawLocationToUILocation(loca
tions[i]); |
| 118 if (!uiLocation) | 118 if (!uiLocation) |
| 119 continue; | 119 continue; |
| 120 var descriptor = String.sprintf( | 120 var descriptor = String.sprintf( |
| 121 '%s:%d:%d', uiLocation.uiSourceCode.url(), uiLocation.lineNumber + 1,
uiLocation.columnNumber + 1); | 121 '%s:%d:%d', uiLocation.uiSourceCode.url(), uiLocation.lineNumber + 1,
uiLocation.columnNumber + 1); |
| 122 uiLocations.set(descriptor, uiLocation); | 122 uiLocations.set(descriptor, uiLocation); |
| 123 } | 123 } |
| 124 | 124 |
| 125 var contextMenuItems = uiLocations.keysArray().sort(); | 125 var contextMenuItems = uiLocations.keysArray().sort(); |
| 126 var contextMenu = new WebInspector.ContextMenu(event); | 126 var contextMenu = new UI.ContextMenu(event); |
| 127 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString.capita
lize('Reveal in ^source ^code')); | 127 var subMenuItem = contextMenu.appendSubMenuItem(Common.UIString.capitalize('
Reveal in ^source ^code')); |
| 128 for (var i = 0; i < contextMenuItems.length; ++i) { | 128 for (var i = 0; i < contextMenuItems.length; ++i) { |
| 129 var title = contextMenuItems[i]; | 129 var title = contextMenuItems[i]; |
| 130 subMenuItem.appendItem( | 130 subMenuItem.appendItem( |
| 131 title, | 131 title, |
| 132 this._revealSourceLocation.bind(this, /** @type {!WebInspector.UILocat
ion} */ (uiLocations.get(title)))); | 132 this._revealSourceLocation.bind(this, /** @type {!Workspace.UILocation
} */ (uiLocations.get(title)))); |
| 133 } | 133 } |
| 134 contextMenu.show(); | 134 contextMenu.show(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 /** | 137 /** |
| 138 * @param {!WebInspector.UILocation} location | 138 * @param {!Workspace.UILocation} location |
| 139 */ | 139 */ |
| 140 _revealSourceLocation(location) { | 140 _revealSourceLocation(location) { |
| 141 WebInspector.Revealer.reveal(location); | 141 Common.Revealer.reveal(location); |
| 142 } | 142 } |
| 143 | 143 |
| 144 _scheduleMediaQueriesUpdate() { | 144 _scheduleMediaQueriesUpdate() { |
| 145 if (!this.isShowing()) | 145 if (!this.isShowing()) |
| 146 return; | 146 return; |
| 147 this._mediaThrottler.schedule(this._refetchMediaQueries.bind(this)); | 147 this._mediaThrottler.schedule(this._refetchMediaQueries.bind(this)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 _refetchMediaQueries() { | 150 _refetchMediaQueries() { |
| 151 if (!this.isShowing() || !this._cssModel) | 151 if (!this.isShowing() || !this._cssModel) |
| 152 return Promise.resolve(); | 152 return Promise.resolve(); |
| 153 | 153 |
| 154 return this._cssModel.mediaQueriesPromise().then(this._rebuildMediaQueries.b
ind(this)); | 154 return this._cssModel.mediaQueriesPromise().then(this._rebuildMediaQueries.b
ind(this)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * @param {!Array.<!WebInspector.MediaQueryInspector.MediaQueryUIModel>} model
s | 158 * @param {!Array.<!Emulation.MediaQueryInspector.MediaQueryUIModel>} models |
| 159 * @return {!Array.<!WebInspector.MediaQueryInspector.MediaQueryUIModel>} | 159 * @return {!Array.<!Emulation.MediaQueryInspector.MediaQueryUIModel>} |
| 160 */ | 160 */ |
| 161 _squashAdjacentEqual(models) { | 161 _squashAdjacentEqual(models) { |
| 162 var filtered = []; | 162 var filtered = []; |
| 163 for (var i = 0; i < models.length; ++i) { | 163 for (var i = 0; i < models.length; ++i) { |
| 164 var last = filtered.peekLast(); | 164 var last = filtered.peekLast(); |
| 165 if (!last || !last.equals(models[i])) | 165 if (!last || !last.equals(models[i])) |
| 166 filtered.push(models[i]); | 166 filtered.push(models[i]); |
| 167 } | 167 } |
| 168 return filtered; | 168 return filtered; |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @param {!Array.<!WebInspector.CSSMedia>} cssMedias | 172 * @param {!Array.<!SDK.CSSMedia>} cssMedias |
| 173 */ | 173 */ |
| 174 _rebuildMediaQueries(cssMedias) { | 174 _rebuildMediaQueries(cssMedias) { |
| 175 var queryModels = []; | 175 var queryModels = []; |
| 176 for (var i = 0; i < cssMedias.length; ++i) { | 176 for (var i = 0; i < cssMedias.length; ++i) { |
| 177 var cssMedia = cssMedias[i]; | 177 var cssMedia = cssMedias[i]; |
| 178 if (!cssMedia.mediaList) | 178 if (!cssMedia.mediaList) |
| 179 continue; | 179 continue; |
| 180 for (var j = 0; j < cssMedia.mediaList.length; ++j) { | 180 for (var j = 0; j < cssMedia.mediaList.length; ++j) { |
| 181 var mediaQuery = cssMedia.mediaList[j]; | 181 var mediaQuery = cssMedia.mediaList[j]; |
| 182 var queryModel = WebInspector.MediaQueryInspector.MediaQueryUIModel.crea
teFromMediaQuery(cssMedia, mediaQuery); | 182 var queryModel = Emulation.MediaQueryInspector.MediaQueryUIModel.createF
romMediaQuery(cssMedia, mediaQuery); |
| 183 if (queryModel && queryModel.rawLocation()) | 183 if (queryModel && queryModel.rawLocation()) |
| 184 queryModels.push(queryModel); | 184 queryModels.push(queryModel); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 queryModels.sort(compareModels); | 187 queryModels.sort(compareModels); |
| 188 queryModels = this._squashAdjacentEqual(queryModels); | 188 queryModels = this._squashAdjacentEqual(queryModels); |
| 189 | 189 |
| 190 var allEqual = this._cachedQueryModels && this._cachedQueryModels.length ===
queryModels.length; | 190 var allEqual = this._cachedQueryModels && this._cachedQueryModels.length ===
queryModels.length; |
| 191 for (var i = 0; allEqual && i < queryModels.length; ++i) | 191 for (var i = 0; allEqual && i < queryModels.length; ++i) |
| 192 allEqual = allEqual && this._cachedQueryModels[i].equals(queryModels[i]); | 192 allEqual = allEqual && this._cachedQueryModels[i].equals(queryModels[i]); |
| 193 if (allEqual) | 193 if (allEqual) |
| 194 return; | 194 return; |
| 195 this._cachedQueryModels = queryModels; | 195 this._cachedQueryModels = queryModels; |
| 196 this._renderMediaQueries(); | 196 this._renderMediaQueries(); |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model1 | 199 * @param {!Emulation.MediaQueryInspector.MediaQueryUIModel} model1 |
| 200 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model2 | 200 * @param {!Emulation.MediaQueryInspector.MediaQueryUIModel} model2 |
| 201 * @return {number} | 201 * @return {number} |
| 202 */ | 202 */ |
| 203 function compareModels(model1, model2) { | 203 function compareModels(model1, model2) { |
| 204 return model1.compareTo(model2); | 204 return model1.compareTo(model2); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 _renderMediaQueries() { | 208 _renderMediaQueries() { |
| 209 if (!this._cachedQueryModels || !this.isShowing()) | 209 if (!this._cachedQueryModels || !this.isShowing()) |
| 210 return; | 210 return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 234 bar._locations = marker.locations; | 234 bar._locations = marker.locations; |
| 235 bar.classList.toggle('media-inspector-marker-inactive', !marker.active); | 235 bar.classList.toggle('media-inspector-marker-inactive', !marker.active); |
| 236 container.appendChild(bar); | 236 container.appendChild(bar); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * @return {number} | 241 * @return {number} |
| 242 */ | 242 */ |
| 243 _zoomFactor() { | 243 _zoomFactor() { |
| 244 return WebInspector.zoomManager.zoomFactor() / this._scale; | 244 return UI.zoomManager.zoomFactor() / this._scale; |
| 245 } | 245 } |
| 246 | 246 |
| 247 /** | 247 /** |
| 248 * @override | 248 * @override |
| 249 */ | 249 */ |
| 250 wasShown() { | 250 wasShown() { |
| 251 this._scheduleMediaQueriesUpdate(); | 251 this._scheduleMediaQueriesUpdate(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 /** | 254 /** |
| 255 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model | 255 * @param {!Emulation.MediaQueryInspector.MediaQueryUIModel} model |
| 256 * @return {!Element} | 256 * @return {!Element} |
| 257 */ | 257 */ |
| 258 _createElementFromMediaQueryModel(model) { | 258 _createElementFromMediaQueryModel(model) { |
| 259 var zoomFactor = this._zoomFactor(); | 259 var zoomFactor = this._zoomFactor(); |
| 260 var minWidthValue = model.minWidthExpression() ? model.minWidthExpression().
computedLength() / zoomFactor : 0; | 260 var minWidthValue = model.minWidthExpression() ? model.minWidthExpression().
computedLength() / zoomFactor : 0; |
| 261 var maxWidthValue = model.maxWidthExpression() ? model.maxWidthExpression().
computedLength() / zoomFactor : 0; | 261 var maxWidthValue = model.maxWidthExpression() ? model.maxWidthExpression().
computedLength() / zoomFactor : 0; |
| 262 var result = createElementWithClass('div', 'media-inspector-bar'); | 262 var result = createElementWithClass('div', 'media-inspector-bar'); |
| 263 | 263 |
| 264 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { | 264 if (model.section() === Emulation.MediaQueryInspector.Section.Max) { |
| 265 result.createChild('div', 'media-inspector-marker-spacer'); | 265 result.createChild('div', 'media-inspector-marker-spacer'); |
| 266 var markerElement = result.createChild('div', 'media-inspector-marker medi
a-inspector-marker-max-width'); | 266 var markerElement = result.createChild('div', 'media-inspector-marker medi
a-inspector-marker-max-width'); |
| 267 markerElement.style.width = maxWidthValue + 'px'; | 267 markerElement.style.width = maxWidthValue + 'px'; |
| 268 markerElement.title = model.mediaText(); | 268 markerElement.title = model.mediaText(); |
| 269 appendLabel(markerElement, model.maxWidthExpression(), false, false); | 269 appendLabel(markerElement, model.maxWidthExpression(), false, false); |
| 270 appendLabel(markerElement, model.maxWidthExpression(), true, true); | 270 appendLabel(markerElement, model.maxWidthExpression(), true, true); |
| 271 result.createChild('div', 'media-inspector-marker-spacer'); | 271 result.createChild('div', 'media-inspector-marker-spacer'); |
| 272 } | 272 } |
| 273 | 273 |
| 274 if (model.section() === WebInspector.MediaQueryInspector.Section.MinMax) { | 274 if (model.section() === Emulation.MediaQueryInspector.Section.MinMax) { |
| 275 result.createChild('div', 'media-inspector-marker-spacer'); | 275 result.createChild('div', 'media-inspector-marker-spacer'); |
| 276 var leftElement = result.createChild('div', 'media-inspector-marker media-
inspector-marker-min-max-width'); | 276 var leftElement = result.createChild('div', 'media-inspector-marker media-
inspector-marker-min-max-width'); |
| 277 leftElement.style.width = (maxWidthValue - minWidthValue) * 0.5 + 'px'; | 277 leftElement.style.width = (maxWidthValue - minWidthValue) * 0.5 + 'px'; |
| 278 leftElement.title = model.mediaText(); | 278 leftElement.title = model.mediaText(); |
| 279 appendLabel(leftElement, model.minWidthExpression(), true, false); | 279 appendLabel(leftElement, model.minWidthExpression(), true, false); |
| 280 appendLabel(leftElement, model.maxWidthExpression(), false, true); | 280 appendLabel(leftElement, model.maxWidthExpression(), false, true); |
| 281 result.createChild('div', 'media-inspector-marker-spacer').style.flex = '0
0 ' + minWidthValue + 'px'; | 281 result.createChild('div', 'media-inspector-marker-spacer').style.flex = '0
0 ' + minWidthValue + 'px'; |
| 282 var rightElement = result.createChild('div', 'media-inspector-marker media
-inspector-marker-min-max-width'); | 282 var rightElement = result.createChild('div', 'media-inspector-marker media
-inspector-marker-min-max-width'); |
| 283 rightElement.style.width = (maxWidthValue - minWidthValue) * 0.5 + 'px'; | 283 rightElement.style.width = (maxWidthValue - minWidthValue) * 0.5 + 'px'; |
| 284 rightElement.title = model.mediaText(); | 284 rightElement.title = model.mediaText(); |
| 285 appendLabel(rightElement, model.minWidthExpression(), true, false); | 285 appendLabel(rightElement, model.minWidthExpression(), true, false); |
| 286 appendLabel(rightElement, model.maxWidthExpression(), false, true); | 286 appendLabel(rightElement, model.maxWidthExpression(), false, true); |
| 287 result.createChild('div', 'media-inspector-marker-spacer'); | 287 result.createChild('div', 'media-inspector-marker-spacer'); |
| 288 } | 288 } |
| 289 | 289 |
| 290 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { | 290 if (model.section() === Emulation.MediaQueryInspector.Section.Min) { |
| 291 var leftElement = result.createChild( | 291 var leftElement = result.createChild( |
| 292 'div', 'media-inspector-marker media-inspector-marker-min-width media-
inspector-marker-min-width-left'); | 292 'div', 'media-inspector-marker media-inspector-marker-min-width media-
inspector-marker-min-width-left'); |
| 293 leftElement.title = model.mediaText(); | 293 leftElement.title = model.mediaText(); |
| 294 appendLabel(leftElement, model.minWidthExpression(), false, false); | 294 appendLabel(leftElement, model.minWidthExpression(), false, false); |
| 295 result.createChild('div', 'media-inspector-marker-spacer').style.flex = '0
0 ' + minWidthValue + 'px'; | 295 result.createChild('div', 'media-inspector-marker-spacer').style.flex = '0
0 ' + minWidthValue + 'px'; |
| 296 var rightElement = result.createChild( | 296 var rightElement = result.createChild( |
| 297 'div', 'media-inspector-marker media-inspector-marker-min-width media-
inspector-marker-min-width-right'); | 297 'div', 'media-inspector-marker media-inspector-marker-min-width media-
inspector-marker-min-width-right'); |
| 298 rightElement.title = model.mediaText(); | 298 rightElement.title = model.mediaText(); |
| 299 appendLabel(rightElement, model.minWidthExpression(), true, true); | 299 appendLabel(rightElement, model.minWidthExpression(), true, true); |
| 300 } | 300 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 311 .textContent = expression.value() + expression.unit(); | 311 .textContent = expression.value() + expression.unit(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 return result; | 314 return result; |
| 315 } | 315 } |
| 316 }; | 316 }; |
| 317 | 317 |
| 318 /** | 318 /** |
| 319 * @enum {number} | 319 * @enum {number} |
| 320 */ | 320 */ |
| 321 WebInspector.MediaQueryInspector.Section = { | 321 Emulation.MediaQueryInspector.Section = { |
| 322 Max: 0, | 322 Max: 0, |
| 323 MinMax: 1, | 323 MinMax: 1, |
| 324 Min: 2 | 324 Min: 2 |
| 325 }; | 325 }; |
| 326 | 326 |
| 327 /** | 327 /** |
| 328 * @unrestricted | 328 * @unrestricted |
| 329 */ | 329 */ |
| 330 WebInspector.MediaQueryInspector.MediaQueryUIModel = class { | 330 Emulation.MediaQueryInspector.MediaQueryUIModel = class { |
| 331 /** | 331 /** |
| 332 * @param {!WebInspector.CSSMedia} cssMedia | 332 * @param {!SDK.CSSMedia} cssMedia |
| 333 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression | 333 * @param {?SDK.CSSMediaQueryExpression} minWidthExpression |
| 334 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression | 334 * @param {?SDK.CSSMediaQueryExpression} maxWidthExpression |
| 335 * @param {boolean} active | 335 * @param {boolean} active |
| 336 */ | 336 */ |
| 337 constructor(cssMedia, minWidthExpression, maxWidthExpression, active) { | 337 constructor(cssMedia, minWidthExpression, maxWidthExpression, active) { |
| 338 this._cssMedia = cssMedia; | 338 this._cssMedia = cssMedia; |
| 339 this._minWidthExpression = minWidthExpression; | 339 this._minWidthExpression = minWidthExpression; |
| 340 this._maxWidthExpression = maxWidthExpression; | 340 this._maxWidthExpression = maxWidthExpression; |
| 341 this._active = active; | 341 this._active = active; |
| 342 if (maxWidthExpression && !minWidthExpression) | 342 if (maxWidthExpression && !minWidthExpression) |
| 343 this._section = WebInspector.MediaQueryInspector.Section.Max; | 343 this._section = Emulation.MediaQueryInspector.Section.Max; |
| 344 else if (minWidthExpression && maxWidthExpression) | 344 else if (minWidthExpression && maxWidthExpression) |
| 345 this._section = WebInspector.MediaQueryInspector.Section.MinMax; | 345 this._section = Emulation.MediaQueryInspector.Section.MinMax; |
| 346 else | 346 else |
| 347 this._section = WebInspector.MediaQueryInspector.Section.Min; | 347 this._section = Emulation.MediaQueryInspector.Section.Min; |
| 348 } | 348 } |
| 349 | 349 |
| 350 /** | 350 /** |
| 351 * @param {!WebInspector.CSSMedia} cssMedia | 351 * @param {!SDK.CSSMedia} cssMedia |
| 352 * @param {!WebInspector.CSSMediaQuery} mediaQuery | 352 * @param {!SDK.CSSMediaQuery} mediaQuery |
| 353 * @return {?WebInspector.MediaQueryInspector.MediaQueryUIModel} | 353 * @return {?Emulation.MediaQueryInspector.MediaQueryUIModel} |
| 354 */ | 354 */ |
| 355 static createFromMediaQuery(cssMedia, mediaQuery) { | 355 static createFromMediaQuery(cssMedia, mediaQuery) { |
| 356 var maxWidthExpression = null; | 356 var maxWidthExpression = null; |
| 357 var maxWidthPixels = Number.MAX_VALUE; | 357 var maxWidthPixels = Number.MAX_VALUE; |
| 358 var minWidthExpression = null; | 358 var minWidthExpression = null; |
| 359 var minWidthPixels = Number.MIN_VALUE; | 359 var minWidthPixels = Number.MIN_VALUE; |
| 360 var expressions = mediaQuery.expressions(); | 360 var expressions = mediaQuery.expressions(); |
| 361 for (var i = 0; i < expressions.length; ++i) { | 361 for (var i = 0; i < expressions.length; ++i) { |
| 362 var expression = expressions[i]; | 362 var expression = expressions[i]; |
| 363 var feature = expression.feature(); | 363 var feature = expression.feature(); |
| 364 if (feature.indexOf('width') === -1) | 364 if (feature.indexOf('width') === -1) |
| 365 continue; | 365 continue; |
| 366 var pixels = expression.computedLength(); | 366 var pixels = expression.computedLength(); |
| 367 if (feature.startsWith('max-') && pixels < maxWidthPixels) { | 367 if (feature.startsWith('max-') && pixels < maxWidthPixels) { |
| 368 maxWidthExpression = expression; | 368 maxWidthExpression = expression; |
| 369 maxWidthPixels = pixels; | 369 maxWidthPixels = pixels; |
| 370 } else if (feature.startsWith('min-') && pixels > minWidthPixels) { | 370 } else if (feature.startsWith('min-') && pixels > minWidthPixels) { |
| 371 minWidthExpression = expression; | 371 minWidthExpression = expression; |
| 372 minWidthPixels = pixels; | 372 minWidthPixels = pixels; |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 if (minWidthPixels > maxWidthPixels || (!maxWidthExpression && !minWidthExpr
ession)) | 375 if (minWidthPixels > maxWidthPixels || (!maxWidthExpression && !minWidthExpr
ession)) |
| 376 return null; | 376 return null; |
| 377 | 377 |
| 378 return new WebInspector.MediaQueryInspector.MediaQueryUIModel( | 378 return new Emulation.MediaQueryInspector.MediaQueryUIModel( |
| 379 cssMedia, minWidthExpression, maxWidthExpression, mediaQuery.active()); | 379 cssMedia, minWidthExpression, maxWidthExpression, mediaQuery.active()); |
| 380 } | 380 } |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} other | 383 * @param {!Emulation.MediaQueryInspector.MediaQueryUIModel} other |
| 384 * @return {boolean} | 384 * @return {boolean} |
| 385 */ | 385 */ |
| 386 equals(other) { | 386 equals(other) { |
| 387 return this.compareTo(other) === 0; | 387 return this.compareTo(other) === 0; |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} other | 391 * @param {!Emulation.MediaQueryInspector.MediaQueryUIModel} other |
| 392 * @return {boolean} | 392 * @return {boolean} |
| 393 */ | 393 */ |
| 394 dimensionsEqual(other) { | 394 dimensionsEqual(other) { |
| 395 return this.section() === other.section() && | 395 return this.section() === other.section() && |
| 396 (!this.minWidthExpression() || | 396 (!this.minWidthExpression() || |
| 397 (this.minWidthExpression().computedLength() === other.minWidthExpressio
n().computedLength())) && | 397 (this.minWidthExpression().computedLength() === other.minWidthExpressio
n().computedLength())) && |
| 398 (!this.maxWidthExpression() || | 398 (!this.maxWidthExpression() || |
| 399 (this.maxWidthExpression().computedLength() === other.maxWidthExpressio
n().computedLength())); | 399 (this.maxWidthExpression().computedLength() === other.maxWidthExpressio
n().computedLength())); |
| 400 } | 400 } |
| 401 | 401 |
| 402 /** | 402 /** |
| 403 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} other | 403 * @param {!Emulation.MediaQueryInspector.MediaQueryUIModel} other |
| 404 * @return {number} | 404 * @return {number} |
| 405 */ | 405 */ |
| 406 compareTo(other) { | 406 compareTo(other) { |
| 407 if (this.section() !== other.section()) | 407 if (this.section() !== other.section()) |
| 408 return this.section() - other.section(); | 408 return this.section() - other.section(); |
| 409 if (this.dimensionsEqual(other)) { | 409 if (this.dimensionsEqual(other)) { |
| 410 var myLocation = this.rawLocation(); | 410 var myLocation = this.rawLocation(); |
| 411 var otherLocation = other.rawLocation(); | 411 var otherLocation = other.rawLocation(); |
| 412 if (!myLocation && !otherLocation) | 412 if (!myLocation && !otherLocation) |
| 413 return this.mediaText().compareTo(other.mediaText()); | 413 return this.mediaText().compareTo(other.mediaText()); |
| 414 if (myLocation && !otherLocation) | 414 if (myLocation && !otherLocation) |
| 415 return 1; | 415 return 1; |
| 416 if (!myLocation && otherLocation) | 416 if (!myLocation && otherLocation) |
| 417 return -1; | 417 return -1; |
| 418 if (this.active() !== other.active()) | 418 if (this.active() !== other.active()) |
| 419 return this.active() ? -1 : 1; | 419 return this.active() ? -1 : 1; |
| 420 return myLocation.url.compareTo(otherLocation.url) || myLocation.lineNumbe
r - otherLocation.lineNumber || | 420 return myLocation.url.compareTo(otherLocation.url) || myLocation.lineNumbe
r - otherLocation.lineNumber || |
| 421 myLocation.columnNumber - otherLocation.columnNumber; | 421 myLocation.columnNumber - otherLocation.columnNumber; |
| 422 } | 422 } |
| 423 if (this.section() === WebInspector.MediaQueryInspector.Section.Max) | 423 if (this.section() === Emulation.MediaQueryInspector.Section.Max) |
| 424 return other.maxWidthExpression().computedLength() - this.maxWidthExpressi
on().computedLength(); | 424 return other.maxWidthExpression().computedLength() - this.maxWidthExpressi
on().computedLength(); |
| 425 if (this.section() === WebInspector.MediaQueryInspector.Section.Min) | 425 if (this.section() === Emulation.MediaQueryInspector.Section.Min) |
| 426 return this.minWidthExpression().computedLength() - other.minWidthExpressi
on().computedLength(); | 426 return this.minWidthExpression().computedLength() - other.minWidthExpressi
on().computedLength(); |
| 427 return this.minWidthExpression().computedLength() - other.minWidthExpression
().computedLength() || | 427 return this.minWidthExpression().computedLength() - other.minWidthExpression
().computedLength() || |
| 428 other.maxWidthExpression().computedLength() - this.maxWidthExpression().
computedLength(); | 428 other.maxWidthExpression().computedLength() - this.maxWidthExpression().
computedLength(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 /** | 431 /** |
| 432 * @return {!WebInspector.MediaQueryInspector.Section} | 432 * @return {!Emulation.MediaQueryInspector.Section} |
| 433 */ | 433 */ |
| 434 section() { | 434 section() { |
| 435 return this._section; | 435 return this._section; |
| 436 } | 436 } |
| 437 | 437 |
| 438 /** | 438 /** |
| 439 * @return {string} | 439 * @return {string} |
| 440 */ | 440 */ |
| 441 mediaText() { | 441 mediaText() { |
| 442 return this._cssMedia.text; | 442 return this._cssMedia.text; |
| 443 } | 443 } |
| 444 | 444 |
| 445 /** | 445 /** |
| 446 * @return {?WebInspector.CSSLocation} | 446 * @return {?SDK.CSSLocation} |
| 447 */ | 447 */ |
| 448 rawLocation() { | 448 rawLocation() { |
| 449 if (!this._rawLocation) | 449 if (!this._rawLocation) |
| 450 this._rawLocation = this._cssMedia.rawLocation(); | 450 this._rawLocation = this._cssMedia.rawLocation(); |
| 451 return this._rawLocation; | 451 return this._rawLocation; |
| 452 } | 452 } |
| 453 | 453 |
| 454 /** | 454 /** |
| 455 * @return {?WebInspector.CSSMediaQueryExpression} | 455 * @return {?SDK.CSSMediaQueryExpression} |
| 456 */ | 456 */ |
| 457 minWidthExpression() { | 457 minWidthExpression() { |
| 458 return this._minWidthExpression; | 458 return this._minWidthExpression; |
| 459 } | 459 } |
| 460 | 460 |
| 461 /** | 461 /** |
| 462 * @return {?WebInspector.CSSMediaQueryExpression} | 462 * @return {?SDK.CSSMediaQueryExpression} |
| 463 */ | 463 */ |
| 464 maxWidthExpression() { | 464 maxWidthExpression() { |
| 465 return this._maxWidthExpression; | 465 return this._maxWidthExpression; |
| 466 } | 466 } |
| 467 | 467 |
| 468 /** | 468 /** |
| 469 * @return {boolean} | 469 * @return {boolean} |
| 470 */ | 470 */ |
| 471 active() { | 471 active() { |
| 472 return this._active; | 472 return this._active; |
| 473 } | 473 } |
| 474 }; | 474 }; |
| OLD | NEW |