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

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

Issue 940373004: [DevTools] Teach MediaQueryInspector about disabling models while profiling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: more cleanup Created 5 years, 10 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._mediaThrottler = new WebInspector.Throttler(0); 16 this._mediaThrottler = new WebInspector.Throttler(0);
17 17
18 this._offset = 0; 18 this._offset = 0;
19 this._scale = 1; 19 this._scale = 1;
20 this._lastReportedCount = 0; 20 this._lastReportedCount = 0;
21 this._canRevealSourceLocation = false;
lushnikov 2015/02/25 15:23:55 сan we have method _canRevealSourceLocation that w
dgozman 2015/02/25 15:51:55 Done.
21 22
22 WebInspector.targetManager.observeTargets(this); 23 WebInspector.targetManager.observeTargets(this);
23 24
24 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._renderMediaQueries.bind(this), this); 25 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._renderMediaQueries.bind(this), this);
25 } 26 }
26 27
27 /** 28 /**
28 * @enum {number} 29 * @enum {number}
29 */ 30 */
30 WebInspector.MediaQueryInspector.Section = { 31 WebInspector.MediaQueryInspector.Section = {
(...skipping 11 matching lines...) Expand all
42 /** 43 /**
43 * @override 44 * @override
44 * @param {!WebInspector.Target} target 45 * @param {!WebInspector.Target} target
45 */ 46 */
46 targetAdded: function(target) 47 targetAdded: function(target)
47 { 48 {
48 // FIXME: adapt this to multiple targets. 49 // FIXME: adapt this to multiple targets.
49 if (this._target) 50 if (this._target)
50 return; 51 return;
51 this._target = target; 52 this._target = target;
53 this._canRevealSourceLocation = target.cssModel.isEnabled();
52 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style SheetAdded, this._scheduleMediaQueriesUpdate, this); 54 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style SheetAdded, this._scheduleMediaQueriesUpdate, this);
53 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style SheetRemoved, this._scheduleMediaQueriesUpdate, this); 55 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style SheetRemoved, this._scheduleMediaQueriesUpdate, this);
54 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style SheetChanged, this._scheduleMediaQueriesUpdate, this); 56 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Style SheetChanged, this._scheduleMediaQueriesUpdate, this);
55 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Media QueryResultChanged, this._scheduleMediaQueriesUpdate, this); 57 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Media QueryResultChanged, this._scheduleMediaQueriesUpdate, this);
58 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Model WasDisabled, this._cssModelEnabledChanged, this);
59 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Model WasEnabled, this._cssModelEnabledChanged, this);
56 }, 60 },
57 61
58 /** 62 /**
59 * @override 63 * @override
60 * @param {!WebInspector.Target} target 64 * @param {!WebInspector.Target} target
61 */ 65 */
62 targetRemoved: function(target) 66 targetRemoved: function(target)
63 { 67 {
64 if (target !== this._target) 68 if (target !== this._target)
65 return; 69 return;
66 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetAdded, this._scheduleMediaQueriesUpdate, this); 70 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetAdded, this._scheduleMediaQueriesUpdate, this);
67 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetRemoved, this._scheduleMediaQueriesUpdate, this); 71 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetRemoved, this._scheduleMediaQueriesUpdate, this);
68 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetChanged, this._scheduleMediaQueriesUpdate, this); 72 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.St yleSheetChanged, this._scheduleMediaQueriesUpdate, this);
69 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this); 73 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Me diaQueryResultChanged, this._scheduleMediaQueriesUpdate, this);
74 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Mo delWasDisabled, this._cssModelEnabledChanged, this);
75 target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Mo delWasEnabled, this._cssModelEnabledChanged, this);
76 this._canRevealSourceLocation = false;
77 delete this._target;
70 }, 78 },
71 79
72 /** 80 /**
73 * @param {number} offset 81 * @param {number} offset
74 * @param {number} scale 82 * @param {number} scale
75 */ 83 */
76 setAxisTransform: function(offset, scale) 84 setAxisTransform: function(offset, scale)
77 { 85 {
78 if (this._offset === offset && Math.abs(this._scale - scale) < 1e-8) 86 if (this._offset === offset && Math.abs(this._scale - scale) < 1e-8)
79 return; 87 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 setWidth(model.minWidthExpression().computedLength()); 131 setWidth(model.minWidthExpression().computedLength());
124 else 132 else
125 setWidth(model.maxWidthExpression().computedLength()); 133 setWidth(model.maxWidthExpression().computedLength());
126 }, 134 },
127 135
128 /** 136 /**
129 * @param {!Event} event 137 * @param {!Event} event
130 */ 138 */
131 _onContextMenu: function(event) 139 _onContextMenu: function(event)
132 { 140 {
141 if (!this._canRevealSourceLocation)
142 return;
143
133 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker"); 144 var mediaQueryMarker = event.target.enclosingNodeOrSelfWithClass("media- inspector-marker");
134 if (!mediaQueryMarker) 145 if (!mediaQueryMarker)
135 return; 146 return;
136 147
137 var locations = mediaQueryMarker._locations; 148 var locations = mediaQueryMarker._locations;
138 var uiLocations = new Map(); 149 var uiLocations = new Map();
139 for (var i = 0; i < locations.length; ++i) { 150 for (var i = 0; i < locations.length; ++i) {
140 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILoc ation(locations[i]); 151 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILoc ation(locations[i]);
141 if (!uiLocation) 152 if (!uiLocation)
142 continue; 153 continue;
143 var descriptor = String.sprintf("%s:%d:%d", uiLocation.uiSourceCode. uri(), uiLocation.lineNumber + 1, uiLocation.columnNumber + 1); 154 var descriptor = String.sprintf("%s:%d:%d", uiLocation.uiSourceCode. uri(), uiLocation.lineNumber + 1, uiLocation.columnNumber + 1);
144 uiLocations.set(descriptor, uiLocation); 155 uiLocations.set(descriptor, uiLocation);
145 } 156 }
146 157
147 var contextMenuItems = uiLocations.keysArray().sort(); 158 var contextMenuItems = uiLocations.keysArray().sort();
148 var contextMenu = new WebInspector.ContextMenu(event); 159 var contextMenu = new WebInspector.ContextMenu(event);
149 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString.ca pitalize("Reveal in ^source ^code")); 160 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString.ca pitalize("Reveal in ^source ^code"));
150 for (var i = 0; i < contextMenuItems.length; ++i) { 161 for (var i = 0; i < contextMenuItems.length; ++i) {
151 var title = contextMenuItems[i]; 162 var title = contextMenuItems[i];
152 subMenuItem.appendItem(title, this._revealSourceLocation.bind(this, /** @type {!WebInspector.UILocation} */(uiLocations.get(title)))); 163 subMenuItem.appendItem(title, this._revealSourceLocation.bind(this, /** @type {!WebInspector.UILocation} */(uiLocations.get(title))));
153 } 164 }
154 contextMenu.show(); 165 contextMenu.show();
155 }, 166 },
156 167
168 _cssModelEnabledChanged: function()
169 {
170 if (this._target)
171 this._canRevealSourceLocation = this._target.cssModel.isEnabled();
caseq 2015/02/25 14:58:34 Why not just check the model state upon onContextM
dgozman 2015/02/25 15:51:55 Done.
172 },
173
157 /** 174 /**
158 * @param {!WebInspector.UILocation} location 175 * @param {!WebInspector.UILocation} location
159 */ 176 */
160 _revealSourceLocation: function(location) 177 _revealSourceLocation: function(location)
161 { 178 {
162 WebInspector.Revealer.reveal(location); 179 WebInspector.Revealer.reveal(location);
163 }, 180 },
164 181
165 _scheduleMediaQueriesUpdate: function() 182 _scheduleMediaQueriesUpdate: function()
166 { 183 {
167 if (!this._enabled) 184 if (!this._enabled)
168 return; 185 return;
169 this._mediaThrottler.schedule(this._refetchMediaQueries.bind(this)); 186 this._mediaThrottler.schedule(this._refetchMediaQueries.bind(this));
170 }, 187 },
171 188
172 /** 189 /**
173 * @param {!WebInspector.Throttler.FinishCallback} finishCallback 190 * @param {!WebInspector.Throttler.FinishCallback} finishCallback
174 */ 191 */
175 _refetchMediaQueries: function(finishCallback) 192 _refetchMediaQueries: function(finishCallback)
176 { 193 {
177 if (!this._enabled) { 194 if (!this._enabled || !this._target) {
178 finishCallback(); 195 finishCallback();
179 return; 196 return;
180 } 197 }
181 198
182 /** 199 /**
183 * @param {!Array.<!WebInspector.CSSMedia>} cssMedias 200 * @param {!Array.<!WebInspector.CSSMedia>} cssMedias
184 * @this {!WebInspector.MediaQueryInspector} 201 * @this {!WebInspector.MediaQueryInspector}
185 */ 202 */
186 function callback(cssMedias) 203 function callback(cssMedias)
187 { 204 {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 }, 518 },
502 519
503 /** 520 /**
504 * @return {boolean} 521 * @return {boolean}
505 */ 522 */
506 active: function() 523 active: function()
507 { 524 {
508 return this._active; 525 return this._active;
509 } 526 }
510 } 527 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698