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, |
38 MinMax: 1, | 32 MinMax: 1, |
39 Min: 2 | 33 Min: 2 |
40 } | 34 } |
41 | 35 |
36 WebInspector.MediaQueryInspector.SectionHeight = 14; | |
37 WebInspector.MediaQueryInspector.SectionMargin = 2; | |
lushnikov
2014/09/05 12:48:06
You don't need to hard-code these css computed sty
dgozman
2014/09/05 13:41:13
Done.
| |
38 | |
42 WebInspector.MediaQueryInspector.Events = { | 39 WebInspector.MediaQueryInspector.Events = { |
43 HeightUpdated: "HeightUpdated", | 40 HeightUpdated: "HeightUpdated", |
44 CountUpdated: "CountUpdated" | 41 CountUpdated: "CountUpdated" |
45 } | 42 } |
46 | 43 |
47 WebInspector.MediaQueryInspector.prototype = { | 44 WebInspector.MediaQueryInspector.prototype = { |
48 /** | 45 /** |
49 * @param {!WebInspector.Target} target | 46 * @param {!WebInspector.Target} target |
50 */ | 47 */ |
51 targetAdded: function(target) | 48 targetAdded: function(target) |
(...skipping 15 matching lines...) Expand all Loading... | |
67 { | 64 { |
68 if (target !== this._target) | 65 if (target !== this._target) |
69 return; | 66 return; |
70 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetAdded, this._scheduleMediaQueriesUpdate, this); | 67 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetAdded, this._scheduleMediaQueriesUpdate, this); |
71 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetRemoved, this._scheduleMediaQueriesUpdate, this); | 68 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetRemoved, this._scheduleMediaQueriesUpdate, this); |
72 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetChanged, this._scheduleMediaQueriesUpdate, this); | 69 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetChanged, this._scheduleMediaQueriesUpdate, this); |
73 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); | 70 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); |
74 }, | 71 }, |
75 | 72 |
76 /** | 73 /** |
77 * @return {!Element} | 74 * @return {number} |
78 */ | 75 */ |
79 rulerDecorationLayer: function() | 76 cssHeight: function() |
lushnikov
2014/09/05 12:48:06
you don't need this method; all clients could simp
dgozman
2014/09/05 13:41:13
Done. Nice catch, thanks!
| |
80 { | 77 { |
81 return this._rulerDecorationLayer; | 78 if (!this._cachedQueryModels) |
79 return 0; | |
80 | |
81 var availableSections = [false, false, false]; | |
82 for (var i = 0; i < this._cachedQueryModels.length; ++i) { | |
83 var model = this._cachedQueryModels[i]; | |
84 availableSections[model.section()] = true; | |
85 } | |
86 | |
87 var sectionCount = 0; | |
88 for (var i = 0; i < availableSections.length; ++i) | |
89 sectionCount += availableSections[i] ? 1 : 0; | |
90 return sectionCount * WebInspector.MediaQueryInspector.SectionHeight + ( sectionCount + 1) * WebInspector.MediaQueryInspector.SectionMargin; | |
82 }, | 91 }, |
83 | 92 |
84 /** | 93 /** |
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 | 94 * @param {number} offset |
139 * @param {number} scale | 95 * @param {number} scale |
140 */ | 96 */ |
141 setAxisTransform: function(translate, offset, scale) | 97 setAxisTransform: function(offset, scale) |
142 { | 98 { |
143 if (this._translateZero === translate && this._offset === offset && Math .abs(this._scale - scale) < 1e-8) | 99 if (this._offset === offset && Math.abs(this._scale - scale) < 1e-8) |
144 return; | 100 return; |
145 this._translateZero = translate; | |
146 this._offset = offset; | 101 this._offset = offset; |
147 this._scale = scale; | 102 this._scale = scale; |
148 this._renderMediaQueries(); | 103 this._renderMediaQueries(); |
149 }, | 104 }, |
150 | 105 |
151 /** | 106 /** |
152 * @param {boolean} enabled | 107 * @param {boolean} enabled |
153 */ | 108 */ |
154 setEnabled: function(enabled) | 109 setEnabled: function(enabled) |
155 { | 110 { |
156 this._enabled = enabled; | 111 this._enabled = enabled; |
157 this._scheduleMediaQueriesUpdate(); | 112 this._scheduleMediaQueriesUpdate(); |
158 }, | 113 }, |
159 | 114 |
160 /** | 115 /** |
161 * @param {!Event} event | 116 * @param {!Event} event |
162 */ | 117 */ |
163 _onMediaQueryClicked: function(event) | 118 _onMediaQueryClicked: function(event) |
164 { | 119 { |
165 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); | 120 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker"); |
166 if (!mediaQueryMarkerContainer) | 121 if (!mediaQueryMarker) |
167 return; | 122 return; |
168 | 123 |
169 /** | 124 /** |
170 * @param {number} width | 125 * @param {number} width |
171 */ | 126 */ |
172 function setWidth(width) | 127 function setWidth(width) |
173 { | 128 { |
174 WebInspector.overridesSupport.settings.deviceWidth.set(width); | 129 WebInspector.overridesSupport.settings.deviceWidth.set(width); |
175 WebInspector.overridesSupport.settings.emulateResolution.set(true); | 130 WebInspector.overridesSupport.settings.emulateResolution.set(true); |
176 } | 131 } |
177 | 132 |
178 var model = mediaQueryMarkerContainer._model; | 133 var model = mediaQueryMarker._model; |
179 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { | 134 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { |
180 setWidth(model.maxWidthExpression().computedLength()); | 135 setWidth(model.maxWidthExpression().computedLength()); |
181 return; | 136 return; |
182 } | 137 } |
183 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { | 138 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { |
184 setWidth(model.minWidthExpression().computedLength()); | 139 setWidth(model.minWidthExpression().computedLength()); |
185 return; | 140 return; |
186 } | 141 } |
187 var currentWidth = WebInspector.overridesSupport.settings.deviceWidth.ge t(); | 142 var currentWidth = WebInspector.overridesSupport.settings.deviceWidth.ge t(); |
188 if (currentWidth !== model.minWidthExpression().computedLength()) | 143 if (currentWidth !== model.minWidthExpression().computedLength()) |
189 setWidth(model.minWidthExpression().computedLength()); | 144 setWidth(model.minWidthExpression().computedLength()); |
190 else | 145 else |
191 setWidth(model.maxWidthExpression().computedLength()); | 146 setWidth(model.maxWidthExpression().computedLength()); |
192 }, | 147 }, |
193 | 148 |
194 /** | 149 /** |
195 * @param {!Event} event | 150 * @param {!Event} event |
196 */ | 151 */ |
197 _onContextMenu: function(event) | 152 _onContextMenu: function(event) |
198 { | 153 { |
199 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); | 154 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker"); |
200 if (!mediaQueryMarkerContainer) | 155 if (!mediaQueryMarker) |
201 return; | 156 return; |
202 | 157 |
203 var locations = mediaQueryMarkerContainer._locations; | 158 var locations = mediaQueryMarker._locations; |
204 var contextMenu = new WebInspector.ContextMenu(event); | 159 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")); | 160 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) { | 161 for (var i = 0; i < locations.length; ++i) { |
207 var location = locations[i]; | 162 var location = locations[i]; |
208 var title = String.sprintf("%s:%d:%d", location.uiSourceCode.uri(), location.lineNumber + 1, location.columnNumber + 1); | 163 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)); | 164 subMenuItem.appendItem(title, this._revealSourceLocation.bind(this, location)); |
210 } | 165 } |
211 contextMenu.show(); | 166 contextMenu.show(); |
212 }, | 167 }, |
213 | 168 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 _rebuildMediaQueries: function(cssMedias) | 224 _rebuildMediaQueries: function(cssMedias) |
270 { | 225 { |
271 var queryModels = []; | 226 var queryModels = []; |
272 for (var i = 0; i < cssMedias.length; ++i) { | 227 for (var i = 0; i < cssMedias.length; ++i) { |
273 var cssMedia = cssMedias[i]; | 228 var cssMedia = cssMedias[i]; |
274 if (!cssMedia.mediaList) | 229 if (!cssMedia.mediaList) |
275 continue; | 230 continue; |
276 for (var j = 0; j < cssMedia.mediaList.length; ++j) { | 231 for (var j = 0; j < cssMedia.mediaList.length; ++j) { |
277 var mediaQuery = cssMedia.mediaList[j]; | 232 var mediaQuery = cssMedia.mediaList[j]; |
278 var queryModel = WebInspector.MediaQueryInspector.MediaQueryUIMo del.createFromMediaQuery(cssMedia, mediaQuery); | 233 var queryModel = WebInspector.MediaQueryInspector.MediaQueryUIMo del.createFromMediaQuery(cssMedia, mediaQuery); |
279 if (queryModel) | 234 if (queryModel && queryModel.uiLocation()) |
280 queryModels.push(queryModel); | 235 queryModels.push(queryModel); |
281 } | 236 } |
282 } | 237 } |
283 queryModels.sort(compareModels); | 238 queryModels.sort(compareModels); |
284 queryModels = this._squashAdjacentEqual(queryModels); | 239 queryModels = this._squashAdjacentEqual(queryModels); |
285 | 240 |
286 var allEqual = this._cachedQueryModels && this._cachedQueryModels.length == queryModels.length; | 241 var allEqual = this._cachedQueryModels && this._cachedQueryModels.length == queryModels.length; |
287 for (var i = 0; allEqual && i < queryModels.length; ++i) | 242 for (var i = 0; allEqual && i < queryModels.length; ++i) |
288 allEqual = allEqual && this._cachedQueryModels[i].equals(queryModels [i]); | 243 allEqual = allEqual && this._cachedQueryModels[i].equals(queryModels [i]); |
289 if (allEqual) | 244 if (allEqual) |
290 return; | 245 return; |
291 this._cachedQueryModels = queryModels; | 246 this._cachedQueryModels = queryModels; |
292 this._renderMediaQueries(); | 247 this._renderMediaQueries(); |
293 | 248 |
294 /** | 249 /** |
295 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model1 | 250 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model1 |
296 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model2 | 251 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model2 |
297 * @return {number} | 252 * @return {number} |
298 */ | 253 */ |
299 function compareModels(model1, model2) | 254 function compareModels(model1, model2) |
300 { | 255 { |
301 return model1.compareTo(model2); | 256 return model1.compareTo(model2); |
302 } | 257 } |
303 }, | 258 }, |
304 | 259 |
305 _renderMediaQueries: function() | 260 _renderMediaQueries: function() |
306 { | 261 { |
307 if (!this._cachedQueryModels) | 262 if (!this._cachedQueryModels) |
308 return; | 263 return; |
309 this._renderRulerDecorations(); | |
310 | 264 |
311 var markers = []; | 265 var markers = []; |
312 var lastMarker = null; | 266 var lastMarker = null; |
313 for (var i = 0; i < this._cachedQueryModels.length; ++i) { | 267 for (var i = 0; i < this._cachedQueryModels.length; ++i) { |
314 var model = this._cachedQueryModels[i]; | 268 var model = this._cachedQueryModels[i]; |
315 if (!model.uiLocation()) | |
316 continue; | |
317 if (lastMarker && lastMarker.model.dimensionsEqual(model)) { | 269 if (lastMarker && lastMarker.model.dimensionsEqual(model)) { |
318 lastMarker.locations.push(model.uiLocation()); | 270 lastMarker.locations.push(model.uiLocation()); |
319 lastMarker.active = lastMarker.active || model.active(); | 271 lastMarker.active = lastMarker.active || model.active(); |
320 } else { | 272 } else { |
321 lastMarker = { | 273 lastMarker = { |
322 active: model.active(), | 274 active: model.active(), |
323 model: model, | 275 model: model, |
324 locations: [ model.uiLocation() ] | 276 locations: [ model.uiLocation() ] |
325 }; | 277 }; |
326 markers.push(lastMarker); | 278 markers.push(lastMarker); |
327 } | 279 } |
328 } | 280 } |
329 | 281 |
330 if (markers.length !== this._lastReportedCount) { | 282 if (markers.length !== this._lastReportedCount) { |
331 this._lastReportedCount = markers.length; | 283 this._lastReportedCount = markers.length; |
332 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.CountUpdated, markers.length); | 284 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.CountUpdated, markers.length); |
333 } | 285 } |
334 | 286 |
335 if (!this.isShowing()) | 287 if (!this.isShowing()) |
336 return; | 288 return; |
337 | 289 |
338 var heightChanges = this.element.children.length !== markers.length; | 290 var oldChildrenCount = this.element.children.length; |
339 | |
340 var scrollTop = this.element.scrollTop; | 291 var scrollTop = this.element.scrollTop; |
341 this.element.removeChildren(); | 292 this.element.removeChildren(); |
293 | |
294 var container = null; | |
342 for (var i = 0; i < markers.length; ++i) { | 295 for (var i = 0; i < markers.length; ++i) { |
296 if (!i || markers[i].model.section() !== markers[i - 1].model.sectio n()) { | |
297 container = this.element.createChild("div", "media-inspector-mar ker-container"); | |
298 container.style.height = WebInspector.MediaQueryInspector.Sectio nHeight + "px"; | |
lushnikov
2014/09/05 12:48:06
your container height depends on font size. You sh
| |
299 container.style.margin = WebInspector.MediaQueryInspector.Sectio nMargin + "px 0"; | |
300 var handler = this._onMarkerContainerMouseMove.bind(this); | |
301 container.addEventListener("mousemove", handler, false); | |
302 container.addEventListener("mouseout", handler, false); | |
303 } | |
343 var marker = markers[i]; | 304 var marker = markers[i]; |
344 var bar = this._createElementFromMediaQueryModel(marker.model); | 305 var bar = this._createElementFromMediaQueryModel(/** @type {!Element } */ (container), marker.model); |
345 bar._model = marker.model; | 306 bar._model = marker.model; |
346 bar._locations = marker.locations; | 307 bar._locations = marker.locations; |
347 bar.classList.toggle("media-inspector-marker-inactive", !marker.acti ve); | 308 bar.classList.toggle("media-inspector-marker-inactive", !marker.acti ve); |
348 | |
349 this.element.appendChild(bar); | |
350 } | 309 } |
351 this.element.scrollTop = scrollTop; | 310 this.element.scrollTop = scrollTop; |
352 this.element.classList.toggle("media-inspector-view-empty", !this.elemen t.children.length); | 311 this.element.classList.toggle("media-inspector-view-empty", !this.elemen t.children.length); |
353 if (heightChanges) | 312 if (this.element.children.length != oldChildrenCount) |
354 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HeightUpdated); | 313 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HeightUpdated); |
355 }, | 314 }, |
356 | 315 |
357 /** | 316 /** |
317 * @param {!Event} event | |
318 */ | |
319 _onMarkerContainerMouseMove: function(event) | |
320 { | |
321 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); | |
322 if (!mediaQueryMarkerContainer) | |
323 return; | |
324 var children = mediaQueryMarkerContainer.children; | |
325 if (!children.length) | |
326 return; | |
327 for (var i = children.length - 1; i >= 0; --i) { | |
328 if (children[i].containsEventPoint(event)) { | |
329 this._highlightMarkerInContainer(children[i], mediaQueryMarkerCo ntainer); | |
330 return; | |
331 } | |
332 } | |
333 this._highlightMarkerInContainer(null, mediaQueryMarkerContainer); | |
334 }, | |
335 | |
336 /** | |
337 * @param {?Element} marker | |
338 * @param {!Element} container | |
339 */ | |
340 _highlightMarkerInContainer: function(marker, container) | |
341 { | |
342 var children = container.children; | |
343 var found = !marker; | |
344 for (var i = children.length - 1; i >= 0; --i) { | |
345 if (found) { | |
346 children[i].classList.remove("media-inspector-marker-highlight") ; | |
347 children[i].classList.remove("media-inspector-marker-under-highl ighted"); | |
348 } else if (children[i] === marker) { | |
349 children[i].classList.add("media-inspector-marker-highlight"); | |
350 children[i].classList.remove("media-inspector-marker-under-highl ighted"); | |
351 found = true; | |
352 } else { | |
353 children[i].classList.remove("media-inspector-marker-highlight") ; | |
354 children[i].classList.add("media-inspector-marker-under-highligh ted"); | |
355 } | |
356 } | |
357 }, | |
358 | |
359 /** | |
358 * @return {number} | 360 * @return {number} |
359 */ | 361 */ |
360 _zoomFactor: function() | 362 _zoomFactor: function() |
361 { | 363 { |
362 return WebInspector.zoomManager.zoomFactor() / this._scale; | 364 return WebInspector.zoomManager.zoomFactor() / this._scale; |
363 }, | 365 }, |
364 | 366 |
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() | 367 wasShown: function() |
380 { | 368 { |
381 this._renderMediaQueries(); | 369 this._renderMediaQueries(); |
382 }, | 370 }, |
383 | 371 |
384 /** | 372 /** |
373 * @param {!Element} container | |
385 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model | 374 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model |
386 * @return {!Element} | 375 * @return {!Element} |
387 */ | 376 */ |
388 _createElementFromMediaQueryModel: function(model) | 377 _createElementFromMediaQueryModel: function(container, model) |
389 { | 378 { |
390 var zoomFactor = this._zoomFactor(); | 379 var zoomFactor = this._zoomFactor(); |
391 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; | 380 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; |
392 | 381 |
393 const styleClassPerSection = [ | 382 const styleClassPerSection = [ |
394 "media-inspector-marker-container-max-width", | 383 "media-inspector-marker-max-width", |
395 "media-inspector-marker-container-min-max-width", | 384 "media-inspector-marker-min-max-width", |
396 "media-inspector-marker-container-min-width" | 385 "media-inspector-marker-min-width" |
397 ]; | 386 ]; |
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 "); | 387 var markerElement = container.createChild("div", "media-inspector-marker "); |
402 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor + this._translateZero : 0; | 388 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor : 0; |
403 markerElement.style.left = leftPixelValue + "px"; | 389 markerElement.style.left = leftPixelValue + "px"; |
390 markerElement.classList.add(styleClassPerSection[model.section()]); | |
404 var widthPixelValue = null; | 391 var widthPixelValue = null; |
405 if (model.maxWidthExpression() && model.minWidthExpression()) | 392 if (model.maxWidthExpression() && model.minWidthExpression()) |
406 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; | 393 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; |
407 else if (model.maxWidthExpression()) | 394 else if (model.maxWidthExpression()) |
408 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor + this._translateZero; | 395 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor; |
409 else | 396 else |
410 markerElement.style.right = "0"; | 397 markerElement.style.right = "0"; |
411 if (typeof widthPixelValue === "number") | 398 if (typeof widthPixelValue === "number") |
412 markerElement.style.width = widthPixelValue + "px"; | 399 markerElement.style.width = widthPixelValue + "px"; |
413 | 400 |
414 var maxLabelFiller = container.createChild("div", "media-inspector-max-l abel-filler"); | |
415 if (model.maxWidthExpression()) { | 401 if (model.maxWidthExpression()) { |
416 maxLabelFiller.style.maxWidth = Math.max(widthPixelValue + leftPixel Value, 0) + "px"; | 402 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"); | 403 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"; | 404 labelContainer.createChild("div", "media-inspector-marker-serif"); |
405 labelContainer.createChild("span", "media-inspector-marker-label " + labelClass).textContent = model.maxWidthExpression().computedLength() + "px"; | |
419 } | 406 } |
420 | 407 |
421 if (model.minWidthExpression()) { | 408 if (model.minWidthExpression()) { |
422 var minLabelFiller = maxLabelFiller.createChild("div", "media-inspec tor-min-label-filler"); | 409 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"; | 410 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"); | 411 labelContainer.createChild("div", "media-inspector-marker-serif"); |
425 label.textContent = model.minWidthExpression().computedLength() + "p x"; | 412 labelContainer.createChild("span", "media-inspector-marker-label " + labelClass).textContent = model.minWidthExpression().computedLength() + "px"; |
426 } | 413 } |
427 | 414 |
428 return container; | 415 return markerElement; |
429 }, | 416 }, |
430 | 417 |
431 __proto__: WebInspector.View.prototype | 418 __proto__: WebInspector.View.prototype |
432 }; | 419 }; |
433 | 420 |
434 /** | 421 /** |
435 * @constructor | 422 * @constructor |
436 * @param {!WebInspector.CSSMedia} cssMedia | 423 * @param {!WebInspector.CSSMedia} cssMedia |
437 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression | 424 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression |
438 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression | 425 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 return this.mediaText().compareTo(other.mediaText()); | 507 return this.mediaText().compareTo(other.mediaText()); |
521 if (myLocation && !otherLocation) | 508 if (myLocation && !otherLocation) |
522 return 1; | 509 return 1; |
523 if (!myLocation && otherLocation) | 510 if (!myLocation && otherLocation) |
524 return -1; | 511 return -1; |
525 if (this.active() !== other.active()) | 512 if (this.active() !== other.active()) |
526 return this.active() ? -1 : 1; | 513 return this.active() ? -1 : 1; |
527 return myLocation.uiSourceCode.uri().compareTo(otherLocation.uiSourc eCode.uri()) || myLocation.lineNumber - otherLocation.lineNumber || myLocation.c olumnNumber - otherLocation.columnNumber; | 514 return myLocation.uiSourceCode.uri().compareTo(otherLocation.uiSourc eCode.uri()) || myLocation.lineNumber - otherLocation.lineNumber || myLocation.c olumnNumber - otherLocation.columnNumber; |
528 } | 515 } |
529 if (this.section() === WebInspector.MediaQueryInspector.Section.Max) | 516 if (this.section() === WebInspector.MediaQueryInspector.Section.Max) |
530 return this.maxWidthExpression().computedLength() - other.maxWidthEx pression().computedLength(); | 517 return other.maxWidthExpression().computedLength() - this.maxWidthEx pression().computedLength(); |
531 if (this.section() === WebInspector.MediaQueryInspector.Section.Min) | 518 if (this.section() === WebInspector.MediaQueryInspector.Section.Min) |
532 return this.minWidthExpression().computedLength() - other.minWidthEx pression().computedLength(); | 519 return this.minWidthExpression().computedLength() - other.minWidthEx pression().computedLength(); |
533 return this.minWidthExpression().computedLength() - other.minWidthExpres sion().computedLength() || this.maxWidthExpression().computedLength() - other.ma xWidthExpression().computedLength(); | 520 return this.minWidthExpression().computedLength() - other.minWidthExpres sion().computedLength() || other.maxWidthExpression().computedLength() - this.ma xWidthExpression().computedLength(); |
534 }, | 521 }, |
535 | 522 |
536 /** | 523 /** |
537 * @return {!WebInspector.MediaQueryInspector.Section} | 524 * @return {!WebInspector.MediaQueryInspector.Section} |
538 */ | 525 */ |
539 section: function() | 526 section: function() |
540 { | 527 { |
541 return this._section; | 528 return this._section; |
542 }, | 529 }, |
543 | 530 |
(...skipping 30 matching lines...) Expand all Loading... | |
574 }, | 561 }, |
575 | 562 |
576 /** | 563 /** |
577 * @return {boolean} | 564 * @return {boolean} |
578 */ | 565 */ |
579 active: function() | 566 active: function() |
580 { | 567 { |
581 return this._active; | 568 return this._active; |
582 } | 569 } |
583 } | 570 } |
OLD | NEW |