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

Side by Side Diff: trunk/Source/devtools/front_end/CSSStyleModel.js

Issue 196743008: Revert 169371 "DevTools: defer styles delta calculation to until..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 6 years, 9 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 callback(cssFamilyName, fonts); 162 callback(cssFamilyName, fonts);
163 } 163 }
164 CSSAgent.getPlatformFontsForNode(nodeId, platformFontsCallback); 164 CSSAgent.getPlatformFontsForNode(nodeId, platformFontsCallback);
165 }, 165 },
166 166
167 /** 167 /**
168 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>} 168 * @return {!Array.<!WebInspector.CSSStyleSheetHeader>}
169 */ 169 */
170 allStyleSheets: function() 170 allStyleSheets: function()
171 { 171 {
172 var values = Object.values(this._styleSheetIdToHeader); 172 return Object.values(this._styleSheetIdToHeader);
173 /**
174 * @param {!WebInspector.CSSStyleSheetHeader} a
175 * @param {!WebInspector.CSSStyleSheetHeader} b
176 * @return {number}
177 */
178 function styleSheetComparator(a, b)
179 {
180 if (a.sourceURL < b.sourceURL)
181 return -1;
182 else if (a.sourceURL > b.sourceURL)
183 return 1;
184 return a.startLine - b.startLine || a.startColumn - b.startColumn;
185 }
186 values.sort(styleSheetComparator);
187
188 return values;
189 }, 173 },
190 174
191 /** 175 /**
192 * @param {!DOMAgent.NodeId} nodeId 176 * @param {!DOMAgent.NodeId} nodeId
193 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSSStyl eDeclaration)} userCallback 177 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSSStyl eDeclaration)} userCallback
194 */ 178 */
195 getInlineStylesAsync: function(nodeId, userCallback) 179 getInlineStylesAsync: function(nodeId, userCallback)
196 { 180 {
197 /** 181 /**
198 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSS StyleDeclaration)} userCallback 182 * @param {function(?WebInspector.CSSStyleDeclaration, ?WebInspector.CSS StyleDeclaration)} userCallback
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 338 }
355 339
356 callback(this._styleSheetIdToHeader[styleSheetId]); 340 callback(this._styleSheetIdToHeader[styleSheetId]);
357 } 341 }
358 342
359 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this)); 343 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this));
360 }, 344 },
361 345
362 mediaQueryResultChanged: function() 346 mediaQueryResultChanged: function()
363 { 347 {
348 this._styleLoader.reset();
364 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged); 349 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged);
365 }, 350 },
366 351
367 /** 352 /**
368 * @param {!CSSAgent.StyleSheetId} id 353 * @param {!CSSAgent.StyleSheetId} id
369 * @return {!WebInspector.CSSStyleSheetHeader} 354 * @return {!WebInspector.CSSStyleSheetHeader}
370 */ 355 */
371 styleSheetHeaderForId: function(id) 356 styleSheetHeaderForId: function(id)
372 { 357 {
373 return this._styleSheetIdToHeader[id]; 358 return this._styleSheetIdToHeader[id];
(...skipping 17 matching lines...) Expand all
391 if (!node) 376 if (!node)
392 return null; 377 return null;
393 return node.ownerDocument ? node.ownerDocument.id : null; 378 return node.ownerDocument ? node.ownerDocument.id : null;
394 }, 379 },
395 380
396 /** 381 /**
397 * @param {!CSSAgent.StyleSheetId} styleSheetId 382 * @param {!CSSAgent.StyleSheetId} styleSheetId
398 */ 383 */
399 _fireStyleSheetChanged: function(styleSheetId) 384 _fireStyleSheetChanged: function(styleSheetId)
400 { 385 {
386 this._styleLoader.reset();
401 if (!this._pendingCommandsMajorState.length) 387 if (!this._pendingCommandsMajorState.length)
402 return; 388 return;
403 389
404 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM ajorState.length - 1]; 390 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM ajorState.length - 1];
405 391
406 if (!styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel. Events.StyleSheetChanged)) 392 if (!styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel. Events.StyleSheetChanged))
407 return; 393 return;
408 394
409 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etChanged, { styleSheetId: styleSheetId, majorChange: majorChange }); 395 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etChanged, { styleSheetId: styleSheetId, majorChange: majorChange });
410 }, 396 },
411 397
412 /** 398 /**
413 * @param {!CSSAgent.CSSStyleSheetHeader} header 399 * @param {!CSSAgent.CSSStyleSheetHeader} header
414 */ 400 */
415 _styleSheetAdded: function(header) 401 _styleSheetAdded: function(header)
416 { 402 {
417 console.assert(!this._styleSheetIdToHeader[header.styleSheetId]); 403 console.assert(!this._styleSheetIdToHeader[header.styleSheetId]);
418 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(header); 404 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(header);
419 this._styleSheetIdToHeader[header.styleSheetId] = styleSheetHeader; 405 this._styleSheetIdToHeader[header.styleSheetId] = styleSheetHeader;
420 var url = styleSheetHeader.resourceURL(); 406 var url = styleSheetHeader.resourceURL();
421 if (!this._styleSheetIdsForURL[url]) 407 if (!this._styleSheetIdsForURL[url])
422 this._styleSheetIdsForURL[url] = {}; 408 this._styleSheetIdsForURL[url] = {};
423 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; 409 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url];
424 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId]; 410 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId];
425 if (!styleSheetIds) { 411 if (!styleSheetIds) {
426 styleSheetIds = []; 412 styleSheetIds = [];
427 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds; 413 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds;
428 } 414 }
429 styleSheetIds.push(styleSheetHeader.id); 415 styleSheetIds.push(styleSheetHeader.id);
416 this._styleLoader.reset();
430 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etAdded, styleSheetHeader); 417 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etAdded, styleSheetHeader);
431 }, 418 },
432 419
433 /** 420 /**
434 * @param {!CSSAgent.StyleSheetId} id 421 * @param {!CSSAgent.StyleSheetId} id
435 */ 422 */
436 _styleSheetRemoved: function(id) 423 _styleSheetRemoved: function(id)
437 { 424 {
438 var header = this._styleSheetIdToHeader[id]; 425 var header = this._styleSheetIdToHeader[id];
439 console.assert(header); 426 console.assert(header);
440 delete this._styleSheetIdToHeader[id]; 427 delete this._styleSheetIdToHeader[id];
441 var url = header.resourceURL(); 428 var url = header.resourceURL();
442 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; 429 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url];
443 frameIdToStyleSheetIds[header.frameId].remove(id); 430 frameIdToStyleSheetIds[header.frameId].remove(id);
444 if (!frameIdToStyleSheetIds[header.frameId].length) { 431 if (!frameIdToStyleSheetIds[header.frameId].length) {
445 delete frameIdToStyleSheetIds[header.frameId]; 432 delete frameIdToStyleSheetIds[header.frameId];
446 if (!Object.keys(this._styleSheetIdsForURL[url]).length) 433 if (!Object.keys(this._styleSheetIdsForURL[url]).length)
447 delete this._styleSheetIdsForURL[url]; 434 delete this._styleSheetIdsForURL[url];
448 } 435 }
436 this._styleLoader.reset();
449 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etRemoved, header); 437 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etRemoved, header);
450 }, 438 },
451 439
452 /** 440 /**
453 * @param {string} url 441 * @param {string} url
454 * @return {!Array.<!CSSAgent.StyleSheetId>} 442 * @return {!Array.<!CSSAgent.StyleSheetId>}
455 */ 443 */
456 styleSheetIdsForURL: function(url) 444 styleSheetIdsForURL: function(url)
457 { 445 {
458 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; 446 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url];
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 * @param {!WebInspector.CSSStyleModel} cssModel 1516 * @param {!WebInspector.CSSStyleModel} cssModel
1529 */ 1517 */
1530 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel) 1518 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel)
1531 { 1519 {
1532 this._cssModel = cssModel; 1520 this._cssModel = cssModel;
1533 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>> } */ 1521 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>> } */
1534 this._nodeIdToCallbackData = {}; 1522 this._nodeIdToCallbackData = {};
1535 } 1523 }
1536 1524
1537 WebInspector.CSSStyleModel.ComputedStyleLoader.prototype = { 1525 WebInspector.CSSStyleModel.ComputedStyleLoader.prototype = {
1526 reset: function()
1527 {
1528 for (var nodeId in this._nodeIdToCallbackData) {
1529 var callbacks = this._nodeIdToCallbackData[nodeId];
1530 for (var i = 0; i < callbacks.length; ++i)
1531 callbacks[i](null);
1532 }
1533 this._nodeIdToCallbackData = {};
1534 },
1535
1538 /** 1536 /**
1539 * @param {!DOMAgent.NodeId} nodeId 1537 * @param {!DOMAgent.NodeId} nodeId
1540 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback 1538 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback
1541 */ 1539 */
1542 getComputedStyle: function(nodeId, userCallback) 1540 getComputedStyle: function(nodeId, userCallback)
1543 { 1541 {
1544 if (this._nodeIdToCallbackData[nodeId]) { 1542 if (this._nodeIdToCallbackData[nodeId]) {
1545 this._nodeIdToCallbackData[nodeId].push(userCallback); 1543 this._nodeIdToCallbackData[nodeId].push(userCallback);
1546 return; 1544 return;
1547 } 1545 }
(...skipping 21 matching lines...) Expand all
1569 for (var i = 0; i < callbacks.length; ++i) 1567 for (var i = 0; i < callbacks.length; ++i)
1570 callbacks[i](computedStyle); 1568 callbacks[i](computedStyle);
1571 } 1569 }
1572 } 1570 }
1573 } 1571 }
1574 1572
1575 /** 1573 /**
1576 * @type {!WebInspector.CSSStyleModel} 1574 * @type {!WebInspector.CSSStyleModel}
1577 */ 1575 */
1578 WebInspector.cssModel; 1576 WebInspector.cssModel;
OLDNEW
« no previous file with comments | « trunk/Source/core/inspector/InspectorDebuggerAgent.cpp ('k') | trunk/Source/web/WebDevToolsAgentImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698