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 */ | 8 */ |
| 9 WebInspector.MediaQueryInspector = function() | 9 WebInspector.MediaQueryInspector = function() |
| 10 { | 10 { |
| 11 WebInspector.View.call(this); | 11 WebInspector.View.call(this); |
| 12 this.element.classList.add("media-inspector-view", "media-inspector-view-emp ty"); | 12 this.element.classList.add("media-inspector-view", "media-inspector-view-emp ty"); |
| 13 this.element.addEventListener("click", this._onMediaQueryClicked.bind(this), false); | 13 this.element.addEventListener("click", this._onMediaQueryClicked.bind(this), false); |
| 14 this.element.addEventListener("contextmenu", this._onContextMenu.bind(this), false); | 14 this.element.addEventListener("contextmenu", this._onContextMenu.bind(this), false); |
| 15 this.element.addEventListener("webkitAnimationEnd", this._onAnimationEnd.bin d(this), false); | 15 this.element.addEventListener("webkitAnimationEnd", this._onAnimationEnd.bin d(this), false); |
| 16 this._mediaThrottler = new WebInspector.Throttler(100); | 16 this._mediaThrottler = new WebInspector.Throttler(100); |
| 17 | 17 |
| 18 this._translateZero = 0; | 18 this._translateZero = 0; |
| 19 this._offset = 0; | |
| 19 this._scale = 1; | 20 this._scale = 1; |
| 20 | 21 |
| 21 this._rulerDecorationLayer = document.createElementWithClass("div", "fill"); | 22 this._rulerDecorationLayer = document.createElementWithClass("div", "fill"); |
| 22 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration") ; | 23 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration") ; |
| 23 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration Clicked.bind(this), false); | 24 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration Clicked.bind(this), false); |
| 24 | 25 |
| 25 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetAdded, this._scheduleMediaQueriesUpdate, this); | 26 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetAdded, this._scheduleMediaQueriesUpdate, this); |
| 26 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetRemoved, this._scheduleMediaQueriesUpdate, this); | 27 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetRemoved, this._scheduleMediaQueriesUpdate, this); |
| 27 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetChanged, this._scheduleMediaQueriesUpdate, this); | 28 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetChanged, this._scheduleMediaQueriesUpdate, this); |
| 28 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Med iaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); | 29 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Med iaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 * @param {?Event} event | 100 * @param {?Event} event |
| 100 */ | 101 */ |
| 101 _onAnimationEnd: function(event) | 102 _onAnimationEnd: function(event) |
| 102 { | 103 { |
| 103 event.target.classList.remove("media-inspector-marker-highlight-1"); | 104 event.target.classList.remove("media-inspector-marker-highlight-1"); |
| 104 event.target.classList.remove("media-inspector-marker-highlight-2"); | 105 event.target.classList.remove("media-inspector-marker-highlight-2"); |
| 105 }, | 106 }, |
| 106 | 107 |
| 107 /** | 108 /** |
| 108 * @param {number} translate | 109 * @param {number} translate |
| 110 * @param {number} offset | |
| 109 * @param {number} scale | 111 * @param {number} scale |
| 110 */ | 112 */ |
| 111 setAxisTransform: function(translate, scale) | 113 setAxisTransform: function(translate, offset, scale) |
| 112 { | 114 { |
| 113 if (this._translateZero === translate && Math.abs(this._scale - scale) < 1e-8) | 115 if (this._translateZero === translate && this._offset === offset && Math .abs(this._scale - scale) < 1e-8) |
| 114 return; | 116 return; |
| 115 this._translateZero = translate; | 117 this._translateZero = translate; |
| 118 this._offset = offset; | |
| 116 this._scale = scale; | 119 this._scale = scale; |
| 117 this._renderMediaQueries(); | 120 this._renderMediaQueries(); |
| 118 }, | 121 }, |
| 119 | 122 |
| 120 /** | 123 /** |
| 121 * @param {boolean} enabled | 124 * @param {boolean} enabled |
| 122 */ | 125 */ |
| 123 setEnabled: function(enabled) | 126 setEnabled: function(enabled) |
| 124 { | 127 { |
| 125 this._enabled = enabled; | 128 this._enabled = enabled; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 | 324 |
| 322 _renderRulerDecorations: function() | 325 _renderRulerDecorations: function() |
| 323 { | 326 { |
| 324 this._rulerDecorationLayer.removeChildren(); | 327 this._rulerDecorationLayer.removeChildren(); |
| 325 var zoomFactor = this._zoomFactor(); | 328 var zoomFactor = this._zoomFactor(); |
| 326 | 329 |
| 327 var thresholds = this._mediaQueryThresholds(); | 330 var thresholds = this._mediaQueryThresholds(); |
| 328 for (var i = 0; i < thresholds.length; ++i) { | 331 for (var i = 0; i < thresholds.length; ++i) { |
| 329 var thresholdElement = this._rulerDecorationLayer.createChild("div", "media-inspector-threshold-serif"); | 332 var thresholdElement = this._rulerDecorationLayer.createChild("div", "media-inspector-threshold-serif"); |
| 330 thresholdElement._value = thresholds[i]; | 333 thresholdElement._value = thresholds[i]; |
| 331 thresholdElement.style.left = thresholds[i] / zoomFactor + "px"; | 334 thresholdElement.style.left = (thresholds[i] - this._offset) / zoomF actor + "px"; |
| 332 } | 335 } |
| 333 }, | 336 }, |
| 334 | 337 |
| 335 wasShown: function() | 338 wasShown: function() |
| 336 { | 339 { |
| 337 this._renderMediaQueries(); | 340 this._renderMediaQueries(); |
| 338 }, | 341 }, |
| 339 | 342 |
| 340 /** | 343 /** |
| 341 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model | 344 * @param {!WebInspector.MediaQueryInspector.MediaQueryUIModel} model |
| 342 * @return {!Element} | 345 * @return {!Element} |
| 343 */ | 346 */ |
| 344 _createElementFromMediaQueryModel: function(model) | 347 _createElementFromMediaQueryModel: function(model) |
| 345 { | 348 { |
| 346 var zoomFactor = this._zoomFactor(); | 349 var zoomFactor = this._zoomFactor(); |
| 347 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; | 350 var minWidthValue = model.minWidthExpression() ? model.minWidthExpressio n().computedLength() : 0; |
| 348 | 351 |
| 349 var container = document.createElementWithClass("div", "media-inspector- marker-container hbox"); | 352 var container = document.createElementWithClass("div", "media-inspector- marker-container hbox"); |
| 350 var markerElement = container.createChild("div", "media-inspector-marker "); | 353 var markerElement = container.createChild("div", "media-inspector-marker "); |
| 351 const styleClassPerSection = [ | 354 const styleClassPerSection = [ |
| 352 "media-inspector-marker-max-width", | 355 "media-inspector-marker-max-width", |
| 353 "media-inspector-marker-min-max-width", | 356 "media-inspector-marker-min-max-width", |
| 354 "media-inspector-marker-min-width" | 357 "media-inspector-marker-min-width" |
| 355 ]; | 358 ]; |
| 356 markerElement.classList.add(styleClassPerSection[model.section()]); | 359 markerElement.classList.add(styleClassPerSection[model.section()]); |
| 357 var leftPixelValue = minWidthValue ? minWidthValue / zoomFactor + this._ translateZero : 0; | 360 var leftPixelValue = minWidthValue ? (minWidthValue - this._offset) / zo omFactor + this._translateZero : 0; |
| 358 markerElement.style.left = leftPixelValue + "px"; | 361 markerElement.style.left = leftPixelValue + "px"; |
| 359 var widthPixelValue = null; | 362 var widthPixelValue = null; |
| 360 if (model.maxWidthExpression() && model.minWidthExpression()) | 363 if (model.maxWidthExpression() && model.minWidthExpression()) |
| 361 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; | 364 widthPixelValue = (model.maxWidthExpression().computedLength() - min WidthValue) / zoomFactor; |
| 362 else if (model.maxWidthExpression()) | 365 else if (model.maxWidthExpression()) |
| 363 widthPixelValue = model.maxWidthExpression().computedLength() / zoom Factor + this._translateZero; | 366 widthPixelValue = (model.maxWidthExpression().computedLength() - thi s._offset) / zoomFactor + this._translateZero; |
|
lushnikov
2014/06/26 20:21:46
This should not work in case of this._offset > mo
dgozman
2014/06/27 11:07:00
You are right. Feel free to fix in a follow-up.
| |
| 364 else | 367 else |
| 365 markerElement.style.right = "0"; | 368 markerElement.style.right = "0"; |
| 366 if (typeof widthPixelValue === "number") | 369 if (typeof widthPixelValue === "number") |
| 367 markerElement.style.width = widthPixelValue + "px"; | 370 markerElement.style.width = widthPixelValue + "px"; |
| 368 | 371 |
| 369 var maxLabelFiller = container.createChild("div", "media-inspector-max-l abel-filler"); | 372 var maxLabelFiller = container.createChild("div", "media-inspector-max-l abel-filler"); |
| 370 if (model.maxWidthExpression()) { | 373 if (model.maxWidthExpression()) { |
| 371 maxLabelFiller.style.maxWidth = widthPixelValue + leftPixelValue + " px"; | 374 maxLabelFiller.style.maxWidth = widthPixelValue + leftPixelValue + " px"; |
| 372 var label = container.createChild("span", "media-inspector-marker-la bel media-inspector-max-label"); | 375 var label = container.createChild("span", "media-inspector-marker-la bel media-inspector-max-label"); |
| 373 label.textContent = model.maxWidthExpression().computedLength() + "p x"; | 376 label.textContent = model.maxWidthExpression().computedLength() + "p x"; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 }, | 519 }, |
| 517 | 520 |
| 518 /** | 521 /** |
| 519 * @return {?WebInspector.CSSMediaQueryExpression} | 522 * @return {?WebInspector.CSSMediaQueryExpression} |
| 520 */ | 523 */ |
| 521 maxWidthExpression: function() | 524 maxWidthExpression: function() |
| 522 { | 525 { |
| 523 return this._maxWidthExpression; | 526 return this._maxWidthExpression; |
| 524 } | 527 } |
| 525 } | 528 } |
| OLD | NEW |