| 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 */ | 9 */ |
| 9 WebInspector.MediaQueryInspector = function() | 10 WebInspector.MediaQueryInspector = function() |
| 10 { | 11 { |
| 11 WebInspector.View.call(this); | 12 WebInspector.View.call(this); |
| 12 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"); |
| 13 this.element.addEventListener("click", this._onMediaQueryClicked.bind(this),
false); | 14 this.element.addEventListener("click", this._onMediaQueryClicked.bind(this),
false); |
| 14 this.element.addEventListener("contextmenu", this._onContextMenu.bind(this),
false); | 15 this.element.addEventListener("contextmenu", this._onContextMenu.bind(this),
false); |
| 15 this.element.addEventListener("webkitAnimationEnd", this._onAnimationEnd.bin
d(this), false); | 16 this.element.addEventListener("webkitAnimationEnd", this._onAnimationEnd.bin
d(this), false); |
| 16 this._mediaThrottler = new WebInspector.Throttler(100); | 17 this._mediaThrottler = new WebInspector.Throttler(100); |
| 17 | 18 |
| 18 this._translateZero = 0; | 19 this._translateZero = 0; |
| 19 this._offset = 0; | 20 this._offset = 0; |
| 20 this._scale = 1; | 21 this._scale = 1; |
| 21 | 22 |
| 22 this._rulerDecorationLayer = document.createElementWithClass("div", "fill"); | 23 this._rulerDecorationLayer = document.createElementWithClass("div", "fill"); |
| 23 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration")
; | 24 this._rulerDecorationLayer.classList.add("media-inspector-ruler-decoration")
; |
| 24 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration
Clicked.bind(this), false); | 25 this._rulerDecorationLayer.addEventListener("click", this._onRulerDecoration
Clicked.bind(this), false); |
| 25 | 26 |
| 26 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty
leSheetAdded, this._scheduleMediaQueriesUpdate, this); | 27 WebInspector.targetManager.observeTargets(this); |
| 27 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty
leSheetRemoved, this._scheduleMediaQueriesUpdate, this); | 28 |
| 28 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty
leSheetChanged, this._scheduleMediaQueriesUpdate, this); | |
| 29 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Med
iaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); | |
| 30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._renderMediaQueries.bind(this), this); | 29 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._renderMediaQueries.bind(this), this); |
| 31 this._scheduleMediaQueriesUpdate(); | 30 this._scheduleMediaQueriesUpdate(); |
| 32 } | 31 } |
| 33 | 32 |
| 34 /** | 33 /** |
| 35 * @enum {number} | 34 * @enum {number} |
| 36 */ | 35 */ |
| 37 WebInspector.MediaQueryInspector.Section = { | 36 WebInspector.MediaQueryInspector.Section = { |
| 38 Max: 0, | 37 Max: 0, |
| 39 MinMax: 1, | 38 MinMax: 1, |
| 40 Min: 2 | 39 Min: 2 |
| 41 } | 40 } |
| 42 | 41 |
| 43 WebInspector.MediaQueryInspector.Events = { | 42 WebInspector.MediaQueryInspector.Events = { |
| 44 HeightUpdated: "HeightUpdated" | 43 HeightUpdated: "HeightUpdated" |
| 45 } | 44 } |
| 46 | 45 |
| 47 WebInspector.MediaQueryInspector.prototype = { | 46 WebInspector.MediaQueryInspector.prototype = { |
| 48 /** | 47 /** |
| 48 * @param {!WebInspector.Target} target |
| 49 */ |
| 50 targetAdded: function(target) |
| 51 { |
| 52 // FIXME: adapt this to multiple targets. |
| 53 if (this._target) |
| 54 return; |
| 55 this._target = target; |
| 56 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style
SheetAdded, this._scheduleMediaQueriesUpdate, this); |
| 57 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style
SheetRemoved, this._scheduleMediaQueriesUpdate, this); |
| 58 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style
SheetChanged, this._scheduleMediaQueriesUpdate, this); |
| 59 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Media
QueryResultChanged, this._scheduleMediaQueriesUpdate, this); |
| 60 }, |
| 61 |
| 62 /** |
| 63 * @param {!WebInspector.Target} target |
| 64 */ |
| 65 targetRemoved: function(target) |
| 66 { |
| 67 if (target !== this._target) |
| 68 return; |
| 69 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St
yleSheetAdded, this._scheduleMediaQueriesUpdate, this); |
| 70 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St
yleSheetRemoved, this._scheduleMediaQueriesUpdate, this); |
| 71 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St
yleSheetChanged, this._scheduleMediaQueriesUpdate, this); |
| 72 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me
diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); |
| 73 }, |
| 74 |
| 75 /** |
| 49 * @return {!Element} | 76 * @return {!Element} |
| 50 */ | 77 */ |
| 51 rulerDecorationLayer: function() | 78 rulerDecorationLayer: function() |
| 52 { | 79 { |
| 53 return this._rulerDecorationLayer; | 80 return this._rulerDecorationLayer; |
| 54 }, | 81 }, |
| 55 | 82 |
| 56 /** | 83 /** |
| 57 * @return {!Array.<number>} | 84 * @return {!Array.<number>} |
| 58 */ | 85 */ |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 236 |
| 210 /** | 237 /** |
| 211 * @param {!Array.<!WebInspector.CSSMedia>} cssMedias | 238 * @param {!Array.<!WebInspector.CSSMedia>} cssMedias |
| 212 * @this {!WebInspector.MediaQueryInspector} | 239 * @this {!WebInspector.MediaQueryInspector} |
| 213 */ | 240 */ |
| 214 function callback(cssMedias) | 241 function callback(cssMedias) |
| 215 { | 242 { |
| 216 this._rebuildMediaQueries(cssMedias); | 243 this._rebuildMediaQueries(cssMedias); |
| 217 finishCallback(); | 244 finishCallback(); |
| 218 } | 245 } |
| 219 WebInspector.cssModel.getMediaQueries(callback.bind(this)); | 246 this._target.cssModel.getMediaQueries(callback.bind(this)); |
| 220 }, | 247 }, |
| 221 | 248 |
| 222 /** | 249 /** |
| 223 * @param {!Array.<!WebInspector.MediaQueryInspector.MediaQueryUIModel>} mod
els | 250 * @param {!Array.<!WebInspector.MediaQueryInspector.MediaQueryUIModel>} mod
els |
| 224 * @return {!Array.<!WebInspector.MediaQueryInspector.MediaQueryUIModel>} | 251 * @return {!Array.<!WebInspector.MediaQueryInspector.MediaQueryUIModel>} |
| 225 */ | 252 */ |
| 226 _squashAdjacentEqual: function(models) | 253 _squashAdjacentEqual: function(models) |
| 227 { | 254 { |
| 228 var filtered = []; | 255 var filtered = []; |
| 229 for (var i = 0; i < models.length; ++i) { | 256 for (var i = 0; i < models.length; ++i) { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 }, | 547 }, |
| 521 | 548 |
| 522 /** | 549 /** |
| 523 * @return {?WebInspector.CSSMediaQueryExpression} | 550 * @return {?WebInspector.CSSMediaQueryExpression} |
| 524 */ | 551 */ |
| 525 maxWidthExpression: function() | 552 maxWidthExpression: function() |
| 526 { | 553 { |
| 527 return this._maxWidthExpression; | 554 return this._maxWidthExpression; |
| 528 } | 555 } |
| 529 } | 556 } |
| OLD | NEW |