Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: Source/devtools/front_end/toolbox/MediaQueryInspector.js

Issue 526423002: [DevTools] Combine media queries preview by sections. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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; 18 this._translateZero = 0;
20 this._offset = 0; 19 this._offset = 0;
21 this._scale = 1; 20 this._scale = 1;
22 this._lastReportedCount = 0; 21 this._lastReportedCount = 0;
22 this._highlightedModel = null;
23 this._highlightDecorationVisible = false;
24 this._availableSections = [false, false, false];
23 25
24 this._rulerDecorationLayer = document.createElementWithClass("div", "fill"); 26 this._rulerDecorationLayer = document.createElementWithClass("div", "fill");
25 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration") ; 27 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration") ;
26 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration Clicked.bind(this), false); 28 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration Clicked.bind(this), false);
27 29
28 WebInspector.targetManager.observeTargets(this); 30 WebInspector.targetManager.observeTargets(this);
29 31
30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._renderMediaQueries.bind(this), this); 32 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._renderMediaQueries.bind(this), this);
31 } 33 }
32 34
33 /** 35 /**
34 * @enum {number} 36 * @enum {number}
35 */ 37 */
36 WebInspector.MediaQueryInspector.Section = { 38 WebInspector.MediaQueryInspector.Section = {
37 Max: 0, 39 Max: 0,
38 MinMax: 1, 40 MinMax: 1,
39 Min: 2 41 Min: 2
40 } 42 }
41 43
42 WebInspector.MediaQueryInspector.Events = { 44 WebInspector.MediaQueryInspector.Events = {
43 HeightUpdated: "HeightUpdated", 45 HeightUpdated: "HeightUpdated",
44 CountUpdated: "CountUpdated" 46 CountUpdated: "CountUpdated",
47 HighlightDecorationUpdated: "HighlightDecorationUpdated"
45 } 48 }
46 49
50 /** @typedef {!{value: number, section: number}} */
51 WebInspector.MediaQueryInspector.Threshold;
52
47 WebInspector.MediaQueryInspector.prototype = { 53 WebInspector.MediaQueryInspector.prototype = {
48 /** 54 /**
49 * @param {!WebInspector.Target} target 55 * @param {!WebInspector.Target} target
50 */ 56 */
51 targetAdded: function(target) 57 targetAdded: function(target)
52 { 58 {
53 // FIXME: adapt this to multiple targets. 59 // FIXME: adapt this to multiple targets.
54 if (this._target) 60 if (this._target)
55 return; 61 return;
56 this._target = target; 62 this._target = target;
(...skipping 18 matching lines...) Expand all
75 81
76 /** 82 /**
77 * @return {!Element} 83 * @return {!Element}
78 */ 84 */
79 rulerDecorationLayer: function() 85 rulerDecorationLayer: function()
80 { 86 {
81 return this._rulerDecorationLayer; 87 return this._rulerDecorationLayer;
82 }, 88 },
83 89
84 /** 90 /**
85 * @return {!Array.<number>} 91 * @return {!Array.<!WebInspector.MediaQueryInspector.Threshold>}
86 */ 92 */
87 _mediaQueryThresholds: function() 93 _mediaQueryThresholds: function()
88 { 94 {
89 if (!this._cachedQueryModels) 95 if (!this._cachedQueryModels)
90 return []; 96 return [];
91 var thresholds = []; 97 var thresholds = [];
92 for (var i = 0; i < this._cachedQueryModels.length; ++i) { 98 for (var i = 0; i < this._cachedQueryModels.length; ++i) {
93 var model = this._cachedQueryModels[i]; 99 var model = this._cachedQueryModels[i];
94 if (model.minWidthExpression()) 100 if (model.minWidthExpression())
95 thresholds.push(model.minWidthExpression().computedLength()); 101 thresholds.push({value: model.minWidthExpression().computedLengt h(), section: model.section()});
96 if (model.maxWidthExpression()) 102 if (model.maxWidthExpression())
97 thresholds.push(model.maxWidthExpression().computedLength()); 103 thresholds.push({value: model.maxWidthExpression().computedLengt h(), section: model.section()});
98 } 104 }
99 thresholds.sortNumbers(); 105 /**
106 * @param {!WebInspector.MediaQueryInspector.Threshold} threshold1
107 * @param {!WebInspector.MediaQueryInspector.Threshold} threshold2
108 * @return {number}
109 */
110 function comparator(threshold1, threshold2)
111 {
112 return threshold1.value - threshold2.value;
113 }
114
115 thresholds.sort(comparator);
100 return thresholds; 116 return thresholds;
101 }, 117 },
102 118
103 /** 119 /**
104 * @param {!Event} event 120 * @param {!Event} event
105 */ 121 */
106 _onRulerDecorationClicked: function(event) 122 _onRulerDecorationClicked: function(event)
107 { 123 {
108 var thresholdElement = event.target.enclosingNodeOrSelfWithClass("media- inspector-threshold-serif"); 124 var thresholdElement = event.target.enclosingNodeOrSelfWithClass("media- inspector-threshold");
109 if (!thresholdElement) 125 if (!thresholdElement)
110 return; 126 return;
111 WebInspector.settings.showMediaQueryInspector.set(true); 127 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 }, 128 },
126 129
127 /** 130 /**
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 131 * @param {number} translate
138 * @param {number} offset 132 * @param {number} offset
139 * @param {number} scale 133 * @param {number} scale
140 */ 134 */
141 setAxisTransform: function(translate, offset, scale) 135 setAxisTransform: function(translate, offset, scale)
142 { 136 {
143 if (this._translateZero === translate && this._offset === offset && Math .abs(this._scale - scale) < 1e-8) 137 if (this._translateZero === translate && this._offset === offset && Math .abs(this._scale - scale) < 1e-8)
144 return; 138 return;
145 this._translateZero = translate; 139 this._translateZero = translate;
146 this._offset = offset; 140 this._offset = offset;
147 this._scale = scale; 141 this._scale = scale;
148 this._renderMediaQueries(); 142 this._renderMediaQueries();
149 }, 143 },
150 144
151 /** 145 /**
152 * @param {boolean} enabled 146 * @param {boolean} enabled
153 */ 147 */
154 setEnabled: function(enabled) 148 setEnabled: function(enabled)
155 { 149 {
156 this._enabled = enabled; 150 this._enabled = enabled;
157 this._scheduleMediaQueriesUpdate(); 151 this._scheduleMediaQueriesUpdate();
158 }, 152 },
159 153
160 /** 154 /**
161 * @param {!Event} event 155 * @param {!Event} event
162 */ 156 */
163 _onMediaQueryClicked: function(event) 157 _onMediaQueryClicked: function(event)
164 { 158 {
165 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); 159 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker");
166 if (!mediaQueryMarkerContainer) 160 if (!mediaQueryMarker)
167 return; 161 return;
168 162
169 /** 163 /**
170 * @param {number} width 164 * @param {number} width
171 */ 165 */
172 function setWidth(width) 166 function setWidth(width)
173 { 167 {
174 WebInspector.overridesSupport.settings.deviceWidth.set(width); 168 WebInspector.overridesSupport.settings.deviceWidth.set(width);
175 WebInspector.overridesSupport.settings.emulateResolution.set(true); 169 WebInspector.overridesSupport.settings.emulateResolution.set(true);
176 } 170 }
177 171
178 var model = mediaQueryMarkerContainer._model; 172 var model = mediaQueryMarker._model;
179 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) { 173 if (model.section() === WebInspector.MediaQueryInspector.Section.Max) {
180 setWidth(model.maxWidthExpression().computedLength()); 174 setWidth(model.maxWidthExpression().computedLength());
181 return; 175 return;
182 } 176 }
183 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) { 177 if (model.section() === WebInspector.MediaQueryInspector.Section.Min) {
184 setWidth(model.minWidthExpression().computedLength()); 178 setWidth(model.minWidthExpression().computedLength());
185 return; 179 return;
186 } 180 }
187 var currentWidth = WebInspector.overridesSupport.settings.deviceWidth.ge t(); 181 var currentWidth = WebInspector.overridesSupport.settings.deviceWidth.ge t();
188 if (currentWidth !== model.minWidthExpression().computedLength()) 182 if (currentWidth !== model.minWidthExpression().computedLength())
189 setWidth(model.minWidthExpression().computedLength()); 183 setWidth(model.minWidthExpression().computedLength());
190 else 184 else
191 setWidth(model.maxWidthExpression().computedLength()); 185 setWidth(model.maxWidthExpression().computedLength());
192 }, 186 },
193 187
194 /** 188 /**
195 * @param {!Event} event 189 * @param {!Event} event
196 */ 190 */
197 _onContextMenu: function(event) 191 _onContextMenu: function(event)
198 { 192 {
199 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container"); 193 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker");
200 if (!mediaQueryMarkerContainer) 194 if (!mediaQueryMarker)
201 return; 195 return;
202 196
203 var locations = mediaQueryMarkerContainer._locations; 197 var locations = mediaQueryMarker._locations;
204 var contextMenu = new WebInspector.ContextMenu(event); 198 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")); 199 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) { 200 for (var i = 0; i < locations.length; ++i) {
207 var location = locations[i]; 201 var location = locations[i];
208 var title = String.sprintf("%s:%d:%d", location.uiSourceCode.uri(), location.lineNumber + 1, location.columnNumber + 1); 202 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)); 203 subMenuItem.appendItem(title, this._revealSourceLocation.bind(this, location));
210 } 204 }
211 contextMenu.show(); 205 contextMenu.show();
212 }, 206 },
213 207
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 322 }
329 323
330 if (markers.length !== this._lastReportedCount) { 324 if (markers.length !== this._lastReportedCount) {
331 this._lastReportedCount = markers.length; 325 this._lastReportedCount = markers.length;
332 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.CountUpdated, markers.length); 326 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.CountUpdated, markers.length);
333 } 327 }
334 328
335 if (!this.isShowing()) 329 if (!this.isShowing())
336 return; 330 return;
337 331
338 var heightChanges = this.element.children.length !== markers.length; 332 var oldChildrenCount = this.element.children.length;
339
340 var scrollTop = this.element.scrollTop; 333 var scrollTop = this.element.scrollTop;
341 this.element.removeChildren(); 334 this.element.removeChildren();
335
336 for (var i = 0; i < this._availableSections.length; ++i)
337 this._availableSections[i] = false;
338
339 var container = null;
342 for (var i = 0; i < markers.length; ++i) { 340 for (var i = 0; i < markers.length; ++i) {
341 if (!i || markers[i].model.section() !== markers[i - 1].model.sectio n()) {
342 container = this.element.createChild("div", "media-inspector-mar ker-container");
343 this._availableSections[markers[i].model.section()] = true;
344 var handler = this._onMarkerContainerMouseMove.bind(this);
345 container.addEventListener("mousemove", handler, false);
346 container.addEventListener("mouseout", handler, false);
347 }
343 var marker = markers[i]; 348 var marker = markers[i];
344 var bar = this._createElementFromMediaQueryModel(marker.model); 349 var bar = this._createElementFromMediaQueryModel(/** @type {!Element } */ (container), marker.model);
345 bar._model = marker.model; 350 bar._model = marker.model;
346 bar._locations = marker.locations; 351 bar._locations = marker.locations;
347 bar.classList.toggle("media-inspector-marker-inactive", !marker.acti ve); 352 bar.classList.toggle("media-inspector-marker-inactive", !marker.acti ve);
348
349 this.element.appendChild(bar);
350 } 353 }
351 this.element.scrollTop = scrollTop; 354 this.element.scrollTop = scrollTop;
352 this.element.classList.toggle("media-inspector-view-empty", !this.elemen t.children.length); 355 this.element.classList.toggle("media-inspector-view-empty", !this.elemen t.children.length);
353 if (heightChanges) 356 if (this.element.children.length != oldChildrenCount)
354 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HeightUpdated); 357 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HeightUpdated);
355 }, 358 },
356 359
357 /** 360 /**
361 * @param {!Event} event
362 */
363 _onMarkerContainerMouseMove: function(event)
364 {
365 var mediaQueryMarkerContainer = event.target.enclosingNodeOrSelfWithClas s("media-inspector-marker-container");
366 if (!mediaQueryMarkerContainer)
367 return;
368 var children = mediaQueryMarkerContainer.children;
369 if (!children.length)
370 return;
371 for (var i = children.length - 1; i >= 0; --i) {
372 if (children[i].containsEventPoint(event)) {
lushnikov 2014/09/03 14:30:41 can't we use relatedTarget/target instead of this
373 this._highlightMarkerInContainer(children[i], mediaQueryMarkerCo ntainer);
374 return;
375 }
376 }
377 this._highlightMarkerInContainer(null, mediaQueryMarkerContainer);
378 },
379
380 /**
381 * @param {?Element} marker
382 * @param {!Element} container
383 */
384 _highlightMarkerInContainer: function(marker, container)
385 {
386 var children = container.children;
387 var found = !marker;
388 for (var i = children.length - 1; i >= 0; --i) {
lushnikov 2014/09/03 14:30:41 Can we simply update z-index of a marker (if any),
389 if (found) {
390 children[i].classList.remove("media-inspector-marker-highlight") ;
391 children[i].classList.remove("media-inspector-marker-under-highl ighted");
392 } else if (children[i] === marker) {
393 children[i].classList.add("media-inspector-marker-highlight");
394 children[i].classList.remove("media-inspector-marker-under-highl ighted");
395 found = true;
396 } else {
397 children[i].classList.remove("media-inspector-marker-highlight") ;
398 children[i].classList.add("media-inspector-marker-under-highligh ted");
399 }
400 }
401 var highlightedModel = marker ? marker._model : null;
402 if (highlightedModel !== this._highlightedModel) {
403 this._highlightedModel = highlightedModel;
404 this._renderRulerDecorations();
405 }
406 },
407
408 /**
358 * @return {number} 409 * @return {number}
359 */ 410 */
360 _zoomFactor: function() 411 _zoomFactor: function()
361 { 412 {
362 return WebInspector.zoomManager.zoomFactor() / this._scale; 413 return WebInspector.zoomManager.zoomFactor() / this._scale;
363 }, 414 },
364 415
416 /**
417 * @return {boolean}
418 */
419 highlightDecorationVisible: function()
420 {
421 return this._highlightDecorationVisible;
422 },
423
365 _renderRulerDecorations: function() 424 _renderRulerDecorations: function()
366 { 425 {
426 var highlightDecorationVisible = this.isShowing() && !!this._highlighted Model;
427 if (highlightDecorationVisible !== this._highlightDecorationVisible) {
428 this._highlightDecorationVisible = highlightDecorationVisible;
429 this.dispatchEventToListeners(WebInspector.MediaQueryInspector.Event s.HighlightDecorationUpdated);
430 }
431
367 this._rulerDecorationLayer.removeChildren(); 432 this._rulerDecorationLayer.removeChildren();
368 var zoomFactor = this._zoomFactor(); 433 var zoomFactor = this._zoomFactor();
369 434
370 var thresholds = this._mediaQueryThresholds(); 435 if (this.isShowing()) {
371 for (var i = 0; i < thresholds.length; ++i) { 436 if (!this._highlightedModel)
lushnikov 2014/09/03 14:30:41 Can we extract this if-branch in a separate method
dgozman 2014/09/04 15:34:32 This method is removed now.
372 var thresholdElement = this._rulerDecorationLayer.createChild("div", "media-inspector-threshold-serif"); 437 return;
373 thresholdElement.title = thresholds[i] + "px"; 438
374 thresholdElement._value = thresholds[i]; 439 const highlightStyleClassPerSection = [
375 thresholdElement.style.left = (thresholds[i] - this._offset) / zoomF actor + "px"; 440 "media-inspector-highlight-threshold-max",
441 "media-inspector-highlight-threshold-min-max",
442 "media-inspector-highlight-threshold-min"
443 ];
444 const classPerRowCount = [
445 "media-inspector-highlight-threshold-one-row",
446 "media-inspector-highlight-threshold-two-rows",
447 "media-inspector-highlight-threshold-three-rows"
448 ];
449 var section = this._highlightedModel.section();
450 var rowCount = 0;
451 for (var i = section; i < highlightStyleClassPerSection.length; ++i) {
452 if (this._availableSections[i])
lushnikov 2014/09/03 14:30:41 availableSections is used only here; lets compute
dgozman 2014/09/04 15:34:32 Done.
453 rowCount++;
454 }
455
456 if (this._highlightedModel.minWidthExpression()) {
457 var valueInPixels = this._highlightedModel.minWidthExpression(). computedLength();
458 var minThresholdElement = this._rulerDecorationLayer.createChild ("div", "media-inspector-highlight-threshold");
459 minThresholdElement.classList.add(highlightStyleClassPerSection[ section]);
460 minThresholdElement.classList.add(classPerRowCount[rowCount - 1] );
461 if (this._highlightedModel.maxWidthExpression()) {
lushnikov 2014/09/03 14:30:41 curly braces are not needed
462 minThresholdElement.classList.add("media-inspector-highlight -threshold-left");
463 } else {
464 minThresholdElement.classList.add("media-inspector-highlight -threshold-right");
465 }
466 minThresholdElement.title = valueInPixels + "px";
467 minThresholdElement.style.left = (valueInPixels - this._offset) / zoomFactor + "px";
468 minThresholdElement.createChild("span", "media-inspector-highlig ht-threshold-label").textContent = valueInPixels + "px";
469 }
470
471 if (this._highlightedModel.maxWidthExpression()) {
lushnikov 2014/09/03 14:30:41 this if-statment look almost identical to the prev
472 var valueInPixels = this._highlightedModel.maxWidthExpression(). computedLength();
473 var maxThresholdElement = this._rulerDecorationLayer.createChild ("div", "media-inspector-highlight-threshold");
474 maxThresholdElement.classList.add(highlightStyleClassPerSection[ section]);
475 maxThresholdElement.classList.add(classPerRowCount[rowCount - 1] );
476 if (this._highlightedModel.minWidthExpression()) {
477 maxThresholdElement.classList.add("media-inspector-highlight -threshold-right");
478 } else {
479 maxThresholdElement.classList.add("media-inspector-highlight -threshold-left");
480 }
481 maxThresholdElement.title = valueInPixels + "px";
482 maxThresholdElement.style.left = (valueInPixels - this._offset) / zoomFactor + "px";
483 maxThresholdElement.createChild("span", "media-inspector-highlig ht-threshold-label").textContent = valueInPixels + "px";
484 }
485 } else {
486 const thresholdStyleClassPerSection = [
487 "media-inspector-threshold-max",
488 "media-inspector-threshold-min-max",
489 "media-inspector-threshold-min"
490 ];
491 var thresholds = this._mediaQueryThresholds();
492 for (var i = 0; i < thresholds.length; ++i) {
493 var thresholdElement = this._rulerDecorationLayer.createChild("d iv", "media-inspector-threshold");
494 thresholdElement.classList.add(thresholdStyleClassPerSection[thr esholds[i].section]);
495 thresholdElement.title = thresholds[i].value + "px";
496 thresholdElement._value = thresholds[i].value;
497 thresholdElement.style.left = (thresholds[i].value - this._offse t) / zoomFactor + "px";
498 }
376 } 499 }
377 }, 500 },
378 501
379 wasShown: function() 502 wasShown: function()
380 { 503 {
381 this._renderMediaQueries(); 504 this._renderMediaQueries();
382 }, 505 },
383 506
507 willHide: function()
508 {
509 window.setImmediate(this._renderRulerDecorations.bind(this));
lushnikov 2014/09/03 14:30:41 why do you use setImmediate here?
dgozman 2014/09/04 15:34:32 It was necessary to have isShowing return the righ
510 },
511
384 /** 512 /**
513 * @param {!Element} container
385 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model 514 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model
386 * @return {!Element} 515 * @return {!Element}
387 */ 516 */
388 _createElementFromMediaQueryModel: function(model) 517 _createElementFromMediaQueryModel: function(container, model)
389 { 518 {
390 var zoomFactor = this._zoomFactor(); 519 var zoomFactor = this._zoomFactor();
391 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; 520 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0;
392 521
393 const styleClassPerSection = [ 522 const styleClassPerSection = [
394 "media-inspector-marker-container-max-width", 523 "media-inspector-marker-max-width",
395 "media-inspector-marker-container-min-max-width", 524 "media-inspector-marker-min-max-width",
396 "media-inspector-marker-container-min-width" 525 "media-inspector-marker-min-width"
397 ]; 526 ];
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 "); 527 var markerElement = container.createChild("div", "media-inspector-marker ");
402 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor + this._translateZero : 0; 528 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor + this._translateZero : 0;
403 markerElement.style.left = leftPixelValue + "px"; 529 markerElement.style.left = leftPixelValue + "px";
530 markerElement.classList.add(styleClassPerSection[model.section()]);
404 var widthPixelValue = null; 531 var widthPixelValue = null;
405 if (model.maxWidthExpression() && model.minWidthExpression()) 532 if (model.maxWidthExpression() && model.minWidthExpression()) {
lushnikov 2014/09/03 14:30:41 curlies are not needed
dgozman 2014/09/04 15:34:32 Done.
406 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; 533 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor;
407 else if (model.maxWidthExpression()) 534 } else if (model.maxWidthExpression()) {
lushnikov 2014/09/03 14:30:41 ditto
408 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor + this._translateZero; 535 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor + this._translateZero;
409 else 536 } else {
lushnikov 2014/09/03 14:30:41 ditto
410 markerElement.style.right = "0"; 537 markerElement.style.right = "0";
538 }
411 if (typeof widthPixelValue === "number") 539 if (typeof widthPixelValue === "number")
412 markerElement.style.width = widthPixelValue + "px"; 540 markerElement.style.width = widthPixelValue + "px";
413 541
414 var maxLabelFiller = container.createChild("div", "media-inspector-max-l abel-filler"); 542 return markerElement;
415 if (model.maxWidthExpression()) {
416 maxLabelFiller.style.maxWidth = Math.max(widthPixelValue + leftPixel Value, 0) + "px";
417 var label = container.createChild("span", "media-inspector-marker-la bel media-inspector-max-label");
418 label.textContent = model.maxWidthExpression().computedLength() + "p x";
419 }
420
421 if (model.minWidthExpression()) {
422 var minLabelFiller = maxLabelFiller.createChild("div", "media-inspec tor-min-label-filler");
423 minLabelFiller.style.maxWidth = Math.max(leftPixelValue, 0) + "px";
424 var label = minLabelFiller.createChild("span", "media-inspector-mark er-label media-inspector-min-label");
425 label.textContent = model.minWidthExpression().computedLength() + "p x";
426 }
427
428 return container;
429 }, 543 },
430 544
431 __proto__: WebInspector.View.prototype 545 __proto__: WebInspector.View.prototype
432 }; 546 };
433 547
434 /** 548 /**
435 * @constructor 549 * @constructor
436 * @param {!WebInspector.CSSMedia} cssMedia 550 * @param {!WebInspector.CSSMedia} cssMedia
437 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression 551 * @param {?WebInspector.CSSMediaQueryExpression} minWidthExpression
438 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression 552 * @param {?WebInspector.CSSMediaQueryExpression} maxWidthExpression
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return this.mediaText().compareTo(other.mediaText()); 634 return this.mediaText().compareTo(other.mediaText());
521 if (myLocation && !otherLocation) 635 if (myLocation && !otherLocation)
522 return 1; 636 return 1;
523 if (!myLocation && otherLocation) 637 if (!myLocation && otherLocation)
524 return -1; 638 return -1;
525 if (this.active() !== other.active()) 639 if (this.active() !== other.active())
526 return this.active() ? -1 : 1; 640 return this.active() ? -1 : 1;
527 return myLocation.uiSourceCode.uri().compareTo(otherLocation.uiSourc eCode.uri()) || myLocation.lineNumber - otherLocation.lineNumber || myLocation.c olumnNumber - otherLocation.columnNumber; 641 return myLocation.uiSourceCode.uri().compareTo(otherLocation.uiSourc eCode.uri()) || myLocation.lineNumber - otherLocation.lineNumber || myLocation.c olumnNumber - otherLocation.columnNumber;
528 } 642 }
529 if (this.section() === WebInspector.MediaQueryInspector.Section.Max) 643 if (this.section() === WebInspector.MediaQueryInspector.Section.Max)
530 return this.maxWidthExpression().computedLength() - other.maxWidthEx pression().computedLength(); 644 return other.maxWidthExpression().computedLength() - this.maxWidthEx pression().computedLength();
531 if (this.section() === WebInspector.MediaQueryInspector.Section.Min) 645 if (this.section() === WebInspector.MediaQueryInspector.Section.Min)
532 return this.minWidthExpression().computedLength() - other.minWidthEx pression().computedLength(); 646 return this.minWidthExpression().computedLength() - other.minWidthEx pression().computedLength();
533 return this.minWidthExpression().computedLength() - other.minWidthExpres sion().computedLength() || this.maxWidthExpression().computedLength() - other.ma xWidthExpression().computedLength(); 647 return this.minWidthExpression().computedLength() - other.minWidthExpres sion().computedLength() || other.maxWidthExpression().computedLength() - this.ma xWidthExpression().computedLength();
534 }, 648 },
535 649
536 /** 650 /**
537 * @return {!WebInspector.MediaQueryInspector.Section} 651 * @return {!WebInspector.MediaQueryInspector.Section}
538 */ 652 */
539 section: function() 653 section: function()
540 { 654 {
541 return this._section; 655 return this._section;
542 }, 656 },
543 657
(...skipping 30 matching lines...) Expand all
574 }, 688 },
575 689
576 /** 690 /**
577 * @return {boolean} 691 * @return {boolean}
578 */ 692 */
579 active: function() 693 active: function()
580 { 694 {
581 return this._active; 695 return this._active;
582 } 696 }
583 } 697 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/responsiveDesignView.css ('k') | Source/devtools/front_end/toolbox/ResponsiveDesignView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698