Chromium Code Reviews| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.View} | 7 * @extends {WebInspector.View} |
| 8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.MediaQueryInspector = function() | 10 WebInspector.MediaQueryInspector = function() |
| 11 { | 11 { |
| 12 WebInspector.View.call(this); | 12 WebInspector.View.call(this); |
| 13 this.element.classList.add("media-inspector-view", "media-inspector-view-emp ty"); | 13 this.element.classList.add("media-inspector-view", "media-inspector-view-emp ty"); |
| 14 this.element.addEventListener("click", this._onMediaQueryClicked.bind(this), false); | 14 this.element.addEventListener("click", this._onMediaQueryClicked.bind(this), false); |
| 15 this.element.addEventListener("contextmenu", this._onContextMenu.bind(this), false); | 15 this.element.addEventListener("contextmenu", this._onContextMenu.bind(this), false); |
| 16 this.element.addEventListener("webkitAnimationEnd", this._onAnimationEnd.bin d(this), false); | |
| 17 this._mediaThrottler = new WebInspector.Throttler(100); | 16 this._mediaThrottler = new WebInspector.Throttler(100); |
| 18 | 17 |
| 19 this._translateZero = 0; | |
| 20 this._offset = 0; | 18 this._offset = 0; |
| 21 this._scale = 1; | 19 this._scale = 1; |
| 22 this._lastReportedCount = 0; | 20 this._lastReportedCount = 0; |
| 23 | 21 |
| 24 this._rulerDecorationLayer = document.createElementWithClass("div", "fill"); | |
| 25 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration") ; | |
| 26 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration Clicked.bind(this), false); | |
| 27 | |
| 28 WebInspector.targetManager.observeTargets(this); | 22 WebInspector.targetManager.observeTargets(this); |
| 29 | 23 |
| 30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._renderMediaQueries.bind(this), this); | 24 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._renderMediaQueries.bind(this), this); |
| 31 } | 25 } |
| 32 | 26 |
| 33 /** | 27 /** |
| 34 * @enum {number} | 28 * @enum {number} |
| 35 */ | 29 */ |
| 36 WebInspector.MediaQueryInspector.Section = { | 30 WebInspector.MediaQueryInspector.Section = { |
| 37 Max: 0, | 31 Max: 0, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 67 { | 61 { |
| 68 if (target !== this._target) | 62 if (target !== this._target) |
| 69 return; | 63 return; |
| 70 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetAdded, this._scheduleMediaQueriesUpdate, this); | 64 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetAdded, this._scheduleMediaQueriesUpdate, this); |
| 71 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetRemoved, this._scheduleMediaQueriesUpdate, this); | 65 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetRemoved, this._scheduleMediaQueriesUpdate, this); |
| 72 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetChanged, this._scheduleMediaQueriesUpdate, this); | 66 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetChanged, this._scheduleMediaQueriesUpdate, this); |
| 73 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); | 67 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); |
| 74 }, | 68 }, |
| 75 | 69 |
| 76 /** | 70 /** |
| 77 * @return {!Element} | |
| 78 */ | |
| 79 rulerDecorationLayer: function() | |
| 80 { | |
| 81 return this._rulerDecorationLayer; | |
| 82 }, | |
| 83 | |
| 84 /** | |
| 85 * @return {!Array.<number>} | |
| 86 */ | |
| 87 _mediaQueryThresholds: function() | |
| 88 { | |
| 89 if (!this._cachedQueryModels) | |
| 90 return []; | |
| 91 var thresholds = []; | |
| 92 for (var i = 0; i < this._cachedQueryModels.length; ++i) { | |
| 93 var model = this._cachedQueryModels[i]; | |
| 94 if (model.minWidthExpression()) | |
| 95 thresholds.push(model.minWidthExpression().computedLength()); | |
| 96 if (model.maxWidthExpression()) | |
| 97 thresholds.push(model.maxWidthExpression().computedLength()); | |
| 98 } | |
| 99 thresholds.sortNumbers(); | |
| 100 return thresholds; | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * @param {!Event} event | |
| 105 */ | |
| 106 _onRulerDecorationClicked: function(event) | |
| 107 { | |
| 108 var thresholdElement = event.target.enclosingNodeOrSelfWithClass("media- inspector-threshold-serif"); | |
| 109 if (!thresholdElement) | |
| 110 return; | |
| 111 WebInspector.settings.showMediaQueryInspector.set(true); | |
| 112 var revealValue = thresholdElement._value; | |
| 113 for (var mediaQueryContainer = this.element.firstChild; mediaQueryContai ner; mediaQueryContainer = mediaQueryContainer.nextSibling) { | |
| 114 var model = mediaQueryContainer._model; | |
| 115 if ((model.minWidthExpression() && Math.abs(model.minWidthExpression ().computedLength() - revealValue) === 0) | |
| 116 || (model.maxWidthExpression() && Math.abs(model.maxWidthExpress ion().computedLength() - revealValue) === 0)) { | |
| 117 mediaQueryContainer.scrollIntoViewIfNeeded(false); | |
| 118 var hasRunningAnimation = mediaQueryContainer.classList.contains ("media-inspector-marker-highlight-1") || mediaQueryContainer.classList.contains ("media-inspector-marker-highlight-2"); | |
| 119 mediaQueryContainer.classList.toggle("media-inspector-marker-hig hlight-1"); | |
| 120 if (hasRunningAnimation) | |
| 121 mediaQueryContainer.classList.toggle("media-inspector-marker -highlight-2"); | |
| 122 return; | |
| 123 } | |
| 124 } | |
| 125 }, | |
| 126 | |
| 127 /** | |
| 128 * @param {!Event} event | |
| 129 */ | |
| 130 _onAnimationEnd: function(event) | |
| 131 { | |
| 132 event.target.classList.remove("media-inspector-marker-highlight-1"); | |
| 133 event.target.classList.remove("media-inspector-marker-highlight-2"); | |
| 134 }, | |
| 135 | |
| 136 /** | |
| 137 * @param {number} translate | |
| 138 * @param {number} offset | 71 * @param {number} offset |
| 139 * @param {number} scale | 72 * @param {number} scale |
| 140 */ | 73 */ |
| 141 setAxisTransform: function(translate, offset, scale) | 74 setAxisTransform: function(offset, scale) |
| 142 { | 75 { |
| 143 if (this._translateZero === translate && this._offset === offset && Math .abs(this._scale - scale) < 1e-8) | 76 if (this._offset === offset && Math.abs(this._scale - scale) < 1e-8) |
| 144 return; | 77 return; |
| 145 this._translateZero = translate; | |
| 146 this._offset = offset; | 78 this._offset = offset; |
| 147 this._scale = scale; | 79 this._scale = scale; |
| 148 this._renderMediaQueries(); | 80 this._renderMediaQueries(); |
| 149 }, | 81 }, |
| 150 | 82 |
| 151 /** | 83 /** |
| 152 * @param {boolean} enabled | 84 * @param {boolean} enabled |
| 153 */ | 85 */ |
| 154 setEnabled: function(enabled) | 86 setEnabled: function(enabled) |
| 155 { | 87 { |
| 156 this._enabled = enabled; | 88 this._enabled = enabled; |
| 157 this._scheduleMediaQueriesUpdate(); | 89 this._scheduleMediaQueriesUpdate(); |
| 158 }, | 90 }, |
| 159 | 91 |
| 160 /** | 92 /** |
| 161 * @param {!Event} event | 93 * @param {!Event} event |
| 162 */ | 94 */ |
| 163 _onMediaQueryClicked: function(event) | 95 _onMediaQueryClicked: function(event) |
| 164 { | 96 { |
| 165 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); | 97 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker"); |
| 166 if (!mediaQueryMarkerContainer) | 98 if (!mediaQueryMarker) |
| 167 return; | 99 return; |
| 168 | 100 |
| 169 /** | 101 /** |
| 170 * @param {number} width | 102 * @param {number} width |
| 171 */ | 103 */ |
| 172 function setWidth(width) | 104 function setWidth(width) |
| 173 { | 105 { |
| 174 WebInspector.overridesSupport.settings.deviceWidth.set(width); | 106 WebInspector.overridesSupport.settings.deviceWidth.set(width); |
| 175 WebInspector.overridesSupport.settings.emulateResolution.set(true); | 107 WebInspector.overridesSupport.settings.emulateResolution.set(true); |
| 176 } | 108 } |
| 177 | 109 |
| 178 var model = mediaQueryMarkerContainer._model; | 110 var model = mediaQueryMarker._model; |
| 179 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { | 111 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { |
| 180 setWidth(model.maxWidthExpression().computedLength()); | 112 setWidth(model.maxWidthExpression().computedLength()); |
| 181 return; | 113 return; |
| 182 } | 114 } |
| 183 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { | 115 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { |
| 184 setWidth(model.minWidthExpression().computedLength()); | 116 setWidth(model.minWidthExpression().computedLength()); |
| 185 return; | 117 return; |
| 186 } | 118 } |
| 187 var currentWidth = WebInspector.overridesSupport.settings.deviceWidth.ge t(); | 119 var currentWidth = WebInspector.overridesSupport.settings.deviceWidth.ge t(); |
| 188 if (currentWidth !== model.minWidthExpression().computedLength()) | 120 if (currentWidth !== model.minWidthExpression().computedLength()) |
| 189 setWidth(model.minWidthExpression().computedLength()); | 121 setWidth(model.minWidthExpression().computedLength()); |
| 190 else | 122 else |
| 191 setWidth(model.maxWidthExpression().computedLength()); | 123 setWidth(model.maxWidthExpression().computedLength()); |
| 192 }, | 124 }, |
| 193 | 125 |
| 194 /** | 126 /** |
| 195 * @param {!Event} event | 127 * @param {!Event} event |
| 196 */ | 128 */ |
| 197 _onContextMenu: function(event) | 129 _onContextMenu: function(event) |
| 198 { | 130 { |
| 199 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); | 131 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker"); |
| 200 if (!mediaQueryMarkerContainer) | 132 if (!mediaQueryMarker) |
| 201 return; | 133 return; |
| 202 | 134 |
| 203 var locations = mediaQueryMarkerContainer._locations; | 135 var locations = mediaQueryMarker._locations; |
| 204 var contextMenu = new WebInspector.ContextMenu(event); | 136 var contextMenu = new WebInspector.ContextMenu(event); |
| 205 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Reveal in source code" : "Reveal In Sourc e Code")); | 137 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Reveal in source code" : "Reveal In Sourc e Code")); |
| 206 for (var i = 0; i < locations.length; ++i) { | 138 for (var i = 0; i < locations.length; ++i) { |
| 207 var location = locations[i]; | 139 var location = locations[i]; |
| 208 var title = String.sprintf("%s:%d:%d", location.uiSourceCode.uri(), location.lineNumber + 1, location.columnNumber + 1); | 140 var title = String.sprintf("%s:%d:%d", location.uiSourceCode.uri(), location.lineNumber + 1, location.columnNumber + 1); |
| 209 subMenuItem.appendItem(title, this._revealSourceLocation.bind(this, location)); | 141 subMenuItem.appendItem(title, this._revealSourceLocation.bind(this, location)); |
| 210 } | 142 } |
| 211 contextMenu.show(); | 143 contextMenu.show(); |
| 212 }, | 144 }, |
| 213 | 145 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 _rebuildMediaQueries: function(cssMedias) | 201 _rebuildMediaQueries: function(cssMedias) |
| 270 { | 202 { |
| 271 var queryModels = []; | 203 var queryModels = []; |
| 272 for (var i = 0; i < cssMedias.length; ++i) { | 204 for (var i = 0; i < cssMedias.length; ++i) { |
| 273 var cssMedia = cssMedias[i]; | 205 var cssMedia = cssMedias[i]; |
| 274 if (!cssMedia.mediaList) | 206 if (!cssMedia.mediaList) |
| 275 continue; | 207 continue; |
| 276 for (var j = 0; j < cssMedia.mediaList.length; ++j) { | 208 for (var j = 0; j < cssMedia.mediaList.length; ++j) { |
| 277 var mediaQuery = cssMedia.mediaList[j]; | 209 var mediaQuery = cssMedia.mediaList[j]; |
| 278 var queryModel = WebInspector.MediaQueryInspector.MediaQueryUIMo del.createFromMediaQuery(cssMedia, mediaQuery); | 210 var queryModel = WebInspector.MediaQueryInspector.MediaQueryUIMo del.createFromMediaQuery(cssMedia, mediaQuery); |
| 279 if (queryModel) | 211 if (queryModel && queryModel.uiLocation()) |
| 280 queryModels.push(queryModel); | 212 queryModels.push(queryModel); |
| 281 } | 213 } |
| 282 } | 214 } |
| 283 queryModels.sort(compareModels); | 215 queryModels.sort(compareModels); |
| 284 queryModels = this._squashAdjacentEqual(queryModels); | 216 queryModels = this._squashAdjacentEqual(queryModels); |
| 285 | 217 |
| 286 var allEqual = this._cachedQueryModels && this._cachedQueryModels.length == queryModels.length; | 218 var allEqual = this._cachedQueryModels && this._cachedQueryModels.length == queryModels.length; |
| 287 for (var i = 0; allEqual && i < queryModels.length; ++i) | 219 for (var i = 0; allEqual && i < queryModels.length; ++i) |
| 288 allEqual = allEqual && this._cachedQueryModels[i].equals(queryModels [i]); | 220 allEqual = allEqual && this._cachedQueryModels[i].equals(queryModels [i]); |
| 289 if (allEqual) | 221 if (allEqual) |
| 290 return; | 222 return; |
| 291 this._cachedQueryModels = queryModels; | 223 this._cachedQueryModels = queryModels; |
| 292 this._renderMediaQueries(); | 224 this._renderMediaQueries(); |
| 293 | 225 |
| 294 /** | 226 /** |
| 295 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model1 | 227 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model1 |
| 296 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model2 | 228 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model2 |
| 297 * @return {number} | 229 * @return {number} |
| 298 */ | 230 */ |
| 299 function compareModels(model1, model2) | 231 function compareModels(model1, model2) |
| 300 { | 232 { |
| 301 return model1.compareTo(model2); | 233 return model1.compareTo(model2); |
| 302 } | 234 } |
| 303 }, | 235 }, |
| 304 | 236 |
| 305 _renderMediaQueries: function() | 237 _renderMediaQueries: function() |
| 306 { | 238 { |
| 307 if (!this._cachedQueryModels) | 239 if (!this._cachedQueryModels) |
| 308 return; | 240 return; |
| 309 this._renderRulerDecorations(); | |
| 310 | 241 |
| 311 var markers = []; | 242 var markers = []; |
| 312 var lastMarker = null; | 243 var lastMarker = null; |
| 313 for (var i = 0; i < this._cachedQueryModels.length; ++i) { | 244 for (var i = 0; i < this._cachedQueryModels.length; ++i) { |
| 314 var model = this._cachedQueryModels[i]; | 245 var model = this._cachedQueryModels[i]; |
| 315 if (!model.uiLocation()) | |
| 316 continue; | |
| 317 if (lastMarker && lastMarker.model.dimensionsEqual(model)) { | 246 if (lastMarker && lastMarker.model.dimensionsEqual(model)) { |
| 318 lastMarker.locations.push(model.uiLocation()); | 247 lastMarker.locations.push(model.uiLocation()); |
| 319 lastMarker.active = lastMarker.active || model.active(); | 248 lastMarker.active = lastMarker.active || model.active(); |
| 320 } else { | 249 } else { |
| 321 lastMarker = { | 250 lastMarker = { |
| 322 active: model.active(), | 251 active: model.active(), |
| 323 model: model, | 252 model: model, |
| 324 locations: [ model.uiLocation() ] | 253 locations: [ model.uiLocation() ] |
| 325 }; | 254 }; |
| 326 markers.push(lastMarker); | 255 markers.push(lastMarker); |
| 327 } | 256 } |
| 328 } | 257 } |
| 329 | 258 |
| 330 if (markers.length !== this._lastReportedCount) { | 259 if (markers.length !== this._lastReportedCount) { |
| 331 this._lastReportedCount = markers.length; | 260 this._lastReportedCount = markers.length; |
| 332 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.CountUpdated, markers.length); | 261 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.CountUpdated, markers.length); |
| 333 } | 262 } |
| 334 | 263 |
| 335 if (!this.isShowing()) | 264 if (!this.isShowing()) |
| 336 return; | 265 return; |
| 337 | 266 |
| 338 var heightChanges = this.element.children.length !== markers.length; | 267 var oldChildrenCount = this.element.children.length; |
| 339 | |
| 340 var scrollTop = this.element.scrollTop; | 268 var scrollTop = this.element.scrollTop; |
| 341 this.element.removeChildren(); | 269 this.element.removeChildren(); |
| 270 | |
| 271 var container = null; | |
| 342 for (var i = 0; i < markers.length; ++i) { | 272 for (var i = 0; i < markers.length; ++i) { |
| 273 if (!i || markers[i].model.section() !== markers[i - 1].model.sectio n()) { | |
| 274 container = this.element.createChild("div", "media-inspector-mar ker-container"); | |
| 275 var handler = this._onMarkerContainerMouseMove.bind(this); | |
| 276 container.addEventListener("mousemove", handler, false); | |
| 277 container.addEventListener("mouseout", handler, false); | |
| 278 } | |
| 343 var marker = markers[i]; | 279 var marker = markers[i]; |
| 344 var bar = this._createElementFromMediaQueryModel(marker.model); | 280 var bar = this._createElementFromMediaQueryModel(/** @type {!Element } */ (container), marker.model); |
|
lushnikov
2014/09/05 15:52:04
FYI: I would rename _createElementFromMediaQueryMo
dgozman
2014/09/05 16:45:51
Changed to call appendChild right here.
| |
| 345 bar._model = marker.model; | 281 bar._model = marker.model; |
| 346 bar._locations = marker.locations; | 282 bar._locations = marker.locations; |
| 347 bar.classList.toggle("media-inspector-marker-inactive", !marker.acti ve); | 283 bar.classList.toggle("media-inspector-marker-inactive", !marker.acti ve); |
| 348 | |
| 349 this.element.appendChild(bar); | |
| 350 } | 284 } |
| 351 this.element.scrollTop = scrollTop; | 285 this.element.scrollTop = scrollTop; |
| 352 this.element.classList.toggle("media-inspector-view-empty", !this.elemen t.children.length); | 286 this.element.classList.toggle("media-inspector-view-empty", !this.elemen t.children.length); |
| 353 if (heightChanges) | 287 if (this.element.children.length != oldChildrenCount) |
|
lushnikov
2014/09/05 15:52:04
!==
dgozman
2014/09/05 16:45:51
Done.
| |
| 354 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HeightUpdated); | 288 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HeightUpdated); |
| 355 }, | 289 }, |
| 356 | 290 |
| 357 /** | 291 /** |
| 292 * @param {!Event} event | |
| 293 */ | |
| 294 _onMarkerContainerMouseMove: function(event) | |
| 295 { | |
| 296 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); | |
| 297 if (!mediaQueryMarkerContainer) | |
| 298 return; | |
| 299 var children = mediaQueryMarkerContainer.children; | |
| 300 if (!children.length) | |
| 301 return; | |
| 302 for (var i = children.length - 1; i >= 0; --i) { | |
| 303 if (children[i].containsEventPoint(event)) { | |
| 304 this._highlightMarkerInContainer(children[i], mediaQueryMarkerCo ntainer); | |
| 305 return; | |
| 306 } | |
| 307 } | |
| 308 this._highlightMarkerInContainer(null, mediaQueryMarkerContainer); | |
| 309 }, | |
| 310 | |
| 311 /** | |
| 312 * @param {?Element} marker | |
| 313 * @param {!Element} container | |
| 314 */ | |
| 315 _highlightMarkerInContainer: function(marker, container) | |
| 316 { | |
| 317 var children = container.children; | |
| 318 var found = !marker; | |
| 319 for (var i = children.length - 1; i >= 0; --i) { | |
| 320 if (found) { | |
| 321 children[i].classList.remove("media-inspector-marker-highlight") ; | |
| 322 children[i].classList.remove("media-inspector-marker-under-highl ighted"); | |
| 323 } else if (children[i] === marker) { | |
| 324 children[i].classList.add("media-inspector-marker-highlight"); | |
| 325 children[i].classList.remove("media-inspector-marker-under-highl ighted"); | |
| 326 found = true; | |
| 327 } else { | |
| 328 children[i].classList.remove("media-inspector-marker-highlight") ; | |
| 329 children[i].classList.add("media-inspector-marker-under-highligh ted"); | |
| 330 } | |
| 331 } | |
| 332 }, | |
| 333 | |
| 334 /** | |
| 358 * @return {number} | 335 * @return {number} |
| 359 */ | 336 */ |
| 360 _zoomFactor: function() | 337 _zoomFactor: function() |
| 361 { | 338 { |
| 362 return WebInspector.zoomManager.zoomFactor() / this._scale; | 339 return WebInspector.zoomManager.zoomFactor() / this._scale; |
| 363 }, | 340 }, |
| 364 | 341 |
| 365 _renderRulerDecorations: function() | |
| 366 { | |
| 367 this._rulerDecorationLayer.removeChildren(); | |
| 368 var zoomFactor = this._zoomFactor(); | |
| 369 | |
| 370 var thresholds = this._mediaQueryThresholds(); | |
| 371 for (var i = 0; i < thresholds.length; ++i) { | |
| 372 var thresholdElement = this._rulerDecorationLayer.createChild("div", "media-inspector-threshold-serif"); | |
| 373 thresholdElement.title = thresholds[i] + "px"; | |
| 374 thresholdElement._value = thresholds[i]; | |
| 375 thresholdElement.style.left = (thresholds[i] - this._offset) / zoomF actor + "px"; | |
| 376 } | |
| 377 }, | |
| 378 | |
| 379 wasShown: function() | 342 wasShown: function() |
| 380 { | 343 { |
| 381 this._renderMediaQueries(); | 344 this._renderMediaQueries(); |
| 382 }, | 345 }, |
| 383 | 346 |
| 384 /** | 347 /** |
| 348 * @param {!Element} container | |
| 385 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model | 349 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model |
| 386 * @return {!Element} | 350 * @return {!Element} |
| 387 */ | 351 */ |
| 388 _createElementFromMediaQueryModel: function(model) | 352 _createElementFromMediaQueryModel: function(container, model) |
| 389 { | 353 { |
| 390 var zoomFactor = this._zoomFactor(); | 354 var zoomFactor = this._zoomFactor(); |
| 391 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; | 355 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; |
| 392 | 356 |
| 393 const styleClassPerSection = [ | 357 const styleClassPerSection = [ |
| 394 "media-inspector-marker-container-max-width", | 358 "media-inspector-marker-max-width", |
| 395 "media-inspector-marker-container-min-max-width", | 359 "media-inspector-marker-min-max-width", |
| 396 "media-inspector-marker-container-min-width" | 360 "media-inspector-marker-min-width" |
| 397 ]; | 361 ]; |
| 398 var container = document.createElementWithClass("div", "media-inspector- marker-container hbox"); | |
| 399 container.classList.add(styleClassPerSection[model.section()]); | |
| 400 | |
| 401 var markerElement = container.createChild("div", "media-inspector-marker "); | 362 var markerElement = container.createChild("div", "media-inspector-marker "); |
| 402 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor + this._translateZero : 0; | 363 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor : 0; |
| 403 markerElement.style.left = leftPixelValue + "px"; | 364 markerElement.style.left = leftPixelValue + "px"; |
| 365 markerElement.classList.add(styleClassPerSection[model.section()]); | |
| 404 var widthPixelValue = null; | 366 var widthPixelValue = null; |
| 405 if (model.maxWidthExpression() && model.minWidthExpression()) | 367 if (model.maxWidthExpression() && model.minWidthExpression()) |
| 406 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; | 368 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; |
| 407 else if (model.maxWidthExpression()) | 369 else if (model.maxWidthExpression()) |
| 408 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor + this._translateZero; | 370 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor; |
| 409 else | 371 else |
| 410 markerElement.style.right = "0"; | 372 markerElement.style.right = "0"; |
| 411 if (typeof widthPixelValue === "number") | 373 if (typeof widthPixelValue === "number") |
| 412 markerElement.style.width = widthPixelValue + "px"; | 374 markerElement.style.width = widthPixelValue + "px"; |
| 413 | 375 |
| 414 var maxLabelFiller = container.createChild("div", "media-inspector-max-l abel-filler"); | |
| 415 if (model.maxWidthExpression()) { | 376 if (model.maxWidthExpression()) { |
| 416 maxLabelFiller.style.maxWidth = Math.max(widthPixelValue + leftPixel Value, 0) + "px"; | 377 var labelClass = model.section() === WebInspector.MediaQueryInspecto r.Section.MinMax ? "media-inspector-label-left" : "media-inspector-label-right"; |
| 417 var label = container.createChild("span", "media-inspector-marker-la bel media-inspector-max-label"); | 378 var labelContainer = markerElement.createChild("div", "media-inspect or-marker-label-container media-inspector-marker-label-container-right"); |
| 418 label.textContent = model.maxWidthExpression().computedLength() + "p x"; | 379 labelContainer.createChild("div", "media-inspector-marker-serif"); |
| 380 labelContainer.createChild("span", "media-inspector-marker-label " + labelClass).textContent = model.maxWidthExpression().computedLength() + "px"; | |
| 419 } | 381 } |
| 420 | 382 |
| 421 if (model.minWidthExpression()) { | 383 if (model.minWidthExpression()) { |
| 422 var minLabelFiller = maxLabelFiller.createChild("div", "media-inspec tor-min-label-filler"); | 384 var labelClass = model.section() === WebInspector.MediaQueryInspecto r.Section.MinMax ? "media-inspector-label-right" : "media-inspector-label-left"; |
| 423 minLabelFiller.style.maxWidth = Math.max(leftPixelValue, 0) + "px"; | 385 var labelContainer = markerElement.createChild("div", "media-inspect or-marker-label-container media-inspector-marker-label-container-left"); |
| 424 var label = minLabelFiller.createChild("span", "media-inspector-mark er-label media-inspector-min-label"); | 386 labelContainer.createChild("div", "media-inspector-marker-serif"); |
| 425 label.textContent = model.minWidthExpression().computedLength() + "p x"; | 387 labelContainer.createChild("span", "media-inspector-marker-label " + labelClass).textContent = model.minWidthExpression().computedLength() + "px"; |
| 426 } | 388 } |
| 427 | 389 |
| 428 return container; | 390 return markerElement; |
| 429 }, | 391 }, |
| 430 | 392 |
| 431 __proto__: WebInspector.View.prototype | 393 __proto__: WebInspector.View.prototype |
| 432 }; | 394 }; |
| 433 | 395 |
| 434 /** | 396 /** |
| 435 * @constructor | 397 * @constructor |
| 436 * @param {!WebInspector.CSSMedia} cssMedia | 398 * @param {!WebInspector.CSSMedia} cssMedia |
| 437 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression | 399 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression |
| 438 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression | 400 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 return this.mediaText().compareTo(other.mediaText()); | 482 return this.mediaText().compareTo(other.mediaText()); |
| 521 if (myLocation && !otherLocation) | 483 if (myLocation && !otherLocation) |
| 522 return 1; | 484 return 1; |
| 523 if (!myLocation && otherLocation) | 485 if (!myLocation && otherLocation) |
| 524 return -1; | 486 return -1; |
| 525 if (this.active() !== other.active()) | 487 if (this.active() !== other.active()) |
| 526 return this.active() ? -1 : 1; | 488 return this.active() ? -1 : 1; |
| 527 return myLocation.uiSourceCode.uri().compareTo(otherLocation.uiSourc eCode.uri()) || myLocation.lineNumber - otherLocation.lineNumber || myLocation.c olumnNumber - otherLocation.columnNumber; | 489 return myLocation.uiSourceCode.uri().compareTo(otherLocation.uiSourc eCode.uri()) || myLocation.lineNumber - otherLocation.lineNumber || myLocation.c olumnNumber - otherLocation.columnNumber; |
| 528 } | 490 } |
| 529 if (this.section() === WebInspector.MediaQueryInspector.Section.Max) | 491 if (this.section() === WebInspector.MediaQueryInspector.Section.Max) |
| 530 return this.maxWidthExpression().computedLength() - other.maxWidthEx pression().computedLength(); | 492 return other.maxWidthExpression().computedLength() - this.maxWidthEx pression().computedLength(); |
| 531 if (this.section() === WebInspector.MediaQueryInspector.Section.Min) | 493 if (this.section() === WebInspector.MediaQueryInspector.Section.Min) |
| 532 return this.minWidthExpression().computedLength() - other.minWidthEx pression().computedLength(); | 494 return this.minWidthExpression().computedLength() - other.minWidthEx pression().computedLength(); |
| 533 return this.minWidthExpression().computedLength() - other.minWidthExpres sion().computedLength() || this.maxWidthExpression().computedLength() - other.ma xWidthExpression().computedLength(); | 495 return this.minWidthExpression().computedLength() - other.minWidthExpres sion().computedLength() || other.maxWidthExpression().computedLength() - this.ma xWidthExpression().computedLength(); |
| 534 }, | 496 }, |
| 535 | 497 |
| 536 /** | 498 /** |
| 537 * @return {!WebInspector.MediaQueryInspector.Section} | 499 * @return {!WebInspector.MediaQueryInspector.Section} |
| 538 */ | 500 */ |
| 539 section: function() | 501 section: function() |
| 540 { | 502 { |
| 541 return this._section; | 503 return this._section; |
| 542 }, | 504 }, |
| 543 | 505 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 574 }, | 536 }, |
| 575 | 537 |
| 576 /** | 538 /** |
| 577 * @return {boolean} | 539 * @return {boolean} |
| 578 */ | 540 */ |
| 579 active: function() | 541 active: function() |
| 580 { | 542 { |
| 581 return this._active; | 543 return this._active; |
| 582 } | 544 } |
| 583 } | 545 } |
| OLD | NEW |