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

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

Issue 201363002: DevTools: defer styles delta calculation to until the end of the task. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 338 }
339 339
340 callback(this._styleSheetIdToHeader[styleSheetId]); 340 callback(this._styleSheetIdToHeader[styleSheetId]);
341 } 341 }
342 342
343 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this)); 343 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this));
344 }, 344 },
345 345
346 mediaQueryResultChanged: function() 346 mediaQueryResultChanged: function()
347 { 347 {
348 this._styleLoader.reset();
349 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged); 348 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged);
350 }, 349 },
351 350
352 /** 351 /**
353 * @param {!CSSAgent.StyleSheetId} id 352 * @param {!CSSAgent.StyleSheetId} id
354 * @return {!WebInspector.CSSStyleSheetHeader} 353 * @return {!WebInspector.CSSStyleSheetHeader}
355 */ 354 */
356 styleSheetHeaderForId: function(id) 355 styleSheetHeaderForId: function(id)
357 { 356 {
358 return this._styleSheetIdToHeader[id]; 357 return this._styleSheetIdToHeader[id];
(...skipping 17 matching lines...) Expand all
376 if (!node) 375 if (!node)
377 return null; 376 return null;
378 return node.ownerDocument ? node.ownerDocument.id : null; 377 return node.ownerDocument ? node.ownerDocument.id : null;
379 }, 378 },
380 379
381 /** 380 /**
382 * @param {!CSSAgent.StyleSheetId} styleSheetId 381 * @param {!CSSAgent.StyleSheetId} styleSheetId
383 */ 382 */
384 _fireStyleSheetChanged: function(styleSheetId) 383 _fireStyleSheetChanged: function(styleSheetId)
385 { 384 {
386 this._styleLoader.reset();
387 if (!this._pendingCommandsMajorState.length) 385 if (!this._pendingCommandsMajorState.length)
388 return; 386 return;
389 387
390 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM ajorState.length - 1]; 388 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM ajorState.length - 1];
391 389
392 if (!styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel. Events.StyleSheetChanged)) 390 if (!styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel. Events.StyleSheetChanged))
393 return; 391 return;
394 392
395 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etChanged, { styleSheetId: styleSheetId, majorChange: majorChange }); 393 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etChanged, { styleSheetId: styleSheetId, majorChange: majorChange });
396 }, 394 },
397 395
398 /** 396 /**
399 * @param {!CSSAgent.CSSStyleSheetHeader} header 397 * @param {!CSSAgent.CSSStyleSheetHeader} header
400 */ 398 */
401 _styleSheetAdded: function(header) 399 _styleSheetAdded: function(header)
402 { 400 {
403 console.assert(!this._styleSheetIdToHeader[header.styleSheetId]); 401 console.assert(!this._styleSheetIdToHeader[header.styleSheetId]);
404 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(header); 402 var styleSheetHeader = new WebInspector.CSSStyleSheetHeader(header);
405 this._styleSheetIdToHeader[header.styleSheetId] = styleSheetHeader; 403 this._styleSheetIdToHeader[header.styleSheetId] = styleSheetHeader;
406 var url = styleSheetHeader.resourceURL(); 404 var url = styleSheetHeader.resourceURL();
407 if (!this._styleSheetIdsForURL[url]) 405 if (!this._styleSheetIdsForURL[url])
408 this._styleSheetIdsForURL[url] = {}; 406 this._styleSheetIdsForURL[url] = {};
409 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; 407 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url];
410 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId]; 408 var styleSheetIds = frameIdToStyleSheetIds[styleSheetHeader.frameId];
411 if (!styleSheetIds) { 409 if (!styleSheetIds) {
412 styleSheetIds = []; 410 styleSheetIds = [];
413 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds; 411 frameIdToStyleSheetIds[styleSheetHeader.frameId] = styleSheetIds;
414 } 412 }
415 styleSheetIds.push(styleSheetHeader.id); 413 styleSheetIds.push(styleSheetHeader.id);
416 this._styleLoader.reset();
417 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etAdded, styleSheetHeader); 414 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etAdded, styleSheetHeader);
418 }, 415 },
419 416
420 /** 417 /**
421 * @param {!CSSAgent.StyleSheetId} id 418 * @param {!CSSAgent.StyleSheetId} id
422 */ 419 */
423 _styleSheetRemoved: function(id) 420 _styleSheetRemoved: function(id)
424 { 421 {
425 var header = this._styleSheetIdToHeader[id]; 422 var header = this._styleSheetIdToHeader[id];
426 console.assert(header); 423 console.assert(header);
427 delete this._styleSheetIdToHeader[id]; 424 delete this._styleSheetIdToHeader[id];
428 var url = header.resourceURL(); 425 var url = header.resourceURL();
429 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; 426 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url];
430 frameIdToStyleSheetIds[header.frameId].remove(id); 427 frameIdToStyleSheetIds[header.frameId].remove(id);
431 if (!frameIdToStyleSheetIds[header.frameId].length) { 428 if (!frameIdToStyleSheetIds[header.frameId].length) {
432 delete frameIdToStyleSheetIds[header.frameId]; 429 delete frameIdToStyleSheetIds[header.frameId];
433 if (!Object.keys(this._styleSheetIdsForURL[url]).length) 430 if (!Object.keys(this._styleSheetIdsForURL[url]).length)
434 delete this._styleSheetIdsForURL[url]; 431 delete this._styleSheetIdsForURL[url];
435 } 432 }
436 this._styleLoader.reset();
437 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etRemoved, header); 433 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etRemoved, header);
438 }, 434 },
439 435
440 /** 436 /**
441 * @param {string} url 437 * @param {string} url
442 * @return {!Array.<!CSSAgent.StyleSheetId>} 438 * @return {!Array.<!CSSAgent.StyleSheetId>}
443 */ 439 */
444 styleSheetIdsForURL: function(url) 440 styleSheetIdsForURL: function(url)
445 { 441 {
446 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url]; 442 var frameIdToStyleSheetIds = this._styleSheetIdsForURL[url];
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 * @param {!WebInspector.CSSStyleModel} cssModel 1512 * @param {!WebInspector.CSSStyleModel} cssModel
1517 */ 1513 */
1518 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel) 1514 WebInspector.CSSStyleModel.ComputedStyleLoader = function(cssModel)
1519 { 1515 {
1520 this._cssModel = cssModel; 1516 this._cssModel = cssModel;
1521 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>> } */ 1517 /** @type {!Object.<*, !Array.<function(?WebInspector.CSSStyleDeclaration)>> } */
1522 this._nodeIdToCallbackData = {}; 1518 this._nodeIdToCallbackData = {};
1523 } 1519 }
1524 1520
1525 WebInspector.CSSStyleModel.ComputedStyleLoader.prototype = { 1521 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
1536 /** 1522 /**
1537 * @param {!DOMAgent.NodeId} nodeId 1523 * @param {!DOMAgent.NodeId} nodeId
1538 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback 1524 * @param {function(?WebInspector.CSSStyleDeclaration)} userCallback
1539 */ 1525 */
1540 getComputedStyle: function(nodeId, userCallback) 1526 getComputedStyle: function(nodeId, userCallback)
1541 { 1527 {
1542 if (this._nodeIdToCallbackData[nodeId]) { 1528 if (this._nodeIdToCallbackData[nodeId]) {
1543 this._nodeIdToCallbackData[nodeId].push(userCallback); 1529 this._nodeIdToCallbackData[nodeId].push(userCallback);
1544 return; 1530 return;
1545 } 1531 }
(...skipping 21 matching lines...) Expand all
1567 for (var i = 0; i < callbacks.length; ++i) 1553 for (var i = 0; i < callbacks.length; ++i)
1568 callbacks[i](computedStyle); 1554 callbacks[i](computedStyle);
1569 } 1555 }
1570 } 1556 }
1571 } 1557 }
1572 1558
1573 /** 1559 /**
1574 * @type {!WebInspector.CSSStyleModel} 1560 * @type {!WebInspector.CSSStyleModel}
1575 */ 1561 */
1576 WebInspector.cssModel; 1562 WebInspector.cssModel;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698