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

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

Issue 206313004: DevTools: Rename WebInspector.DOMAgent into WebInspector.DOMModel (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on master 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
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 20 matching lines...) Expand all
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.Object} 33 * @extends {WebInspector.Object}
34 * @param {!WebInspector.Workspace} workspace 34 * @param {!WebInspector.Workspace} workspace
35 */ 35 */
36 WebInspector.CSSStyleModel = function(workspace) 36 WebInspector.CSSStyleModel = function(workspace)
37 { 37 {
38 this._workspace = workspace; 38 this._workspace = workspace;
39 this._pendingCommandsMajorState = []; 39 this._pendingCommandsMajorState = [];
40 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this) ; 40 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this) ;
41 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedo Requested, this._undoRedoRequested, this); 41 WebInspector.domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedo Requested, this._undoRedoRequested, this);
42 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedo Completed, this._undoRedoCompleted, this); 42 WebInspector.domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedo Completed, this._undoRedoCompleted, this);
43 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, th is); 43 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, th is);
44 InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)) ; 44 InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)) ;
45 CSSAgent.enable(this._wasEnabled.bind(this)); 45 CSSAgent.enable(this._wasEnabled.bind(this));
46 this._resetStyleSheets(); 46 this._resetStyleSheets();
47 } 47 }
48 48
49 /** 49 /**
50 * @param {!Array.<!CSSAgent.RuleMatch>|undefined} matchArray 50 * @param {!Array.<!CSSAgent.RuleMatch>|undefined} matchArray
51 */ 51 */
52 WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray) 52 WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 * @param {!CSSAgent.CSSRule} rulePayload 239 * @param {!CSSAgent.CSSRule} rulePayload
240 * @this {WebInspector.CSSStyleModel} 240 * @this {WebInspector.CSSStyleModel}
241 */ 241 */
242 function callback(nodeId, successCallback, failureCallback, newSelector, error, rulePayload) 242 function callback(nodeId, successCallback, failureCallback, newSelector, error, rulePayload)
243 { 243 {
244 this._pendingCommandsMajorState.pop(); 244 this._pendingCommandsMajorState.pop();
245 if (error) { 245 if (error) {
246 failureCallback(); 246 failureCallback();
247 return; 247 return;
248 } 248 }
249 WebInspector.domAgent.markUndoableState(); 249 WebInspector.domModel.markUndoableState();
250 this._computeMatchingSelectors(rulePayload, nodeId, successCallback, failureCallback); 250 this._computeMatchingSelectors(rulePayload, nodeId, successCallback, failureCallback);
251 } 251 }
252 252
253 253
254 this._pendingCommandsMajorState.push(true); 254 this._pendingCommandsMajorState.push(true);
255 CSSAgent.setRuleSelector(ruleId, newSelector, callback.bind(this, nodeId , successCallback, failureCallback, newSelector)); 255 CSSAgent.setRuleSelector(ruleId, newSelector, callback.bind(this, nodeId , successCallback, failureCallback, newSelector));
256 }, 256 },
257 257
258 /** 258 /**
259 * @param {!CSSAgent.CSSRule} rulePayload 259 * @param {!CSSAgent.CSSRule} rulePayload
260 * @param {!DOMAgent.NodeId} nodeId 260 * @param {!DOMAgent.NodeId} nodeId
261 * @param {function(!WebInspector.CSSRule)} successCallback 261 * @param {function(!WebInspector.CSSRule)} successCallback
262 * @param {function()} failureCallback 262 * @param {function()} failureCallback
263 */ 263 */
264 _computeMatchingSelectors: function(rulePayload, nodeId, successCallback, fa ilureCallback) 264 _computeMatchingSelectors: function(rulePayload, nodeId, successCallback, fa ilureCallback)
265 { 265 {
266 var ownerDocumentId = this._ownerDocumentId(nodeId); 266 var ownerDocumentId = this._ownerDocumentId(nodeId);
267 if (!ownerDocumentId) { 267 if (!ownerDocumentId) {
268 failureCallback(); 268 failureCallback();
269 return; 269 return;
270 } 270 }
271 var rule = WebInspector.CSSRule.parsePayload(rulePayload); 271 var rule = WebInspector.CSSRule.parsePayload(rulePayload);
272 var matchingSelectors = []; 272 var matchingSelectors = [];
273 var allSelectorsBarrier = new CallbackBarrier(); 273 var allSelectorsBarrier = new CallbackBarrier();
274 for (var i = 0; i < rule.selectors.length; ++i) { 274 for (var i = 0; i < rule.selectors.length; ++i) {
275 var selector = rule.selectors[i]; 275 var selector = rule.selectors[i];
276 var boundCallback = allSelectorsBarrier.createCallback(selectorQueri ed.bind(null, i, nodeId, matchingSelectors)); 276 var boundCallback = allSelectorsBarrier.createCallback(selectorQueri ed.bind(null, i, nodeId, matchingSelectors));
277 WebInspector.domAgent.querySelectorAll(ownerDocumentId, selector.val ue, boundCallback); 277 WebInspector.domModel.querySelectorAll(ownerDocumentId, selector.val ue, boundCallback);
278 } 278 }
279 allSelectorsBarrier.callWhenDone(function() { 279 allSelectorsBarrier.callWhenDone(function() {
280 rule.matchingSelectors = matchingSelectors; 280 rule.matchingSelectors = matchingSelectors;
281 successCallback(rule); 281 successCallback(rule);
282 }); 282 });
283 283
284 /** 284 /**
285 * @param {number} index 285 * @param {number} index
286 * @param {!DOMAgent.NodeId} nodeId 286 * @param {!DOMAgent.NodeId} nodeId
287 * @param {!Array.<number>} matchingSelectors 287 * @param {!Array.<number>} matchingSelectors
(...skipping 25 matching lines...) Expand all
313 * @param {!CSSAgent.CSSRule} rulePayload 313 * @param {!CSSAgent.CSSRule} rulePayload
314 * @this {WebInspector.CSSStyleModel} 314 * @this {WebInspector.CSSStyleModel}
315 */ 315 */
316 function callback(error, rulePayload) 316 function callback(error, rulePayload)
317 { 317 {
318 this._pendingCommandsMajorState.pop(); 318 this._pendingCommandsMajorState.pop();
319 if (error) { 319 if (error) {
320 // Invalid syntax for a selector 320 // Invalid syntax for a selector
321 failureCallback(); 321 failureCallback();
322 } else { 322 } else {
323 WebInspector.domAgent.markUndoableState(); 323 WebInspector.domModel.markUndoableState();
324 this._computeMatchingSelectors(rulePayload, node.id, successCall back, failureCallback); 324 this._computeMatchingSelectors(rulePayload, node.id, successCall back, failureCallback);
325 } 325 }
326 } 326 }
327 }, 327 },
328 328
329 /** 329 /**
330 * @param {!WebInspector.DOMNode} node 330 * @param {!WebInspector.DOMNode} node
331 * @param {function(?WebInspector.CSSStyleSheetHeader)} callback 331 * @param {function(?WebInspector.CSSStyleSheetHeader)} callback
332 */ 332 */
333 requestViaInspectorStylesheet: function(node, callback) 333 requestViaInspectorStylesheet: function(node, callback)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 { 380 {
381 return Object.values(this._styleSheetIdToHeader); 381 return Object.values(this._styleSheetIdToHeader);
382 }, 382 },
383 383
384 /** 384 /**
385 * @param {!DOMAgent.NodeId} nodeId 385 * @param {!DOMAgent.NodeId} nodeId
386 * @return {?DOMAgent.NodeId} 386 * @return {?DOMAgent.NodeId}
387 */ 387 */
388 _ownerDocumentId: function(nodeId) 388 _ownerDocumentId: function(nodeId)
389 { 389 {
390 var node = WebInspector.domAgent.nodeForId(nodeId); 390 var node = WebInspector.domModel.nodeForId(nodeId);
391 if (!node) 391 if (!node)
392 return null; 392 return null;
393 return node.ownerDocument ? node.ownerDocument.id : null; 393 return node.ownerDocument ? node.ownerDocument.id : null;
394 }, 394 },
395 395
396 /** 396 /**
397 * @param {!CSSAgent.StyleSheetId} styleSheetId 397 * @param {!CSSAgent.StyleSheetId} styleSheetId
398 */ 398 */
399 _fireStyleSheetChanged: function(styleSheetId) 399 _fireStyleSheetChanged: function(styleSheetId)
400 { 400 {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 header.setContent(newText, callback.bind(this)); 491 header.setContent(newText, callback.bind(this));
492 492
493 /** 493 /**
494 * @param {?Protocol.Error} error 494 * @param {?Protocol.Error} error
495 * @this {WebInspector.CSSStyleModel} 495 * @this {WebInspector.CSSStyleModel}
496 */ 496 */
497 function callback(error) 497 function callback(error)
498 { 498 {
499 this._pendingCommandsMajorState.pop(); 499 this._pendingCommandsMajorState.pop();
500 if (!error && majorChange) 500 if (!error && majorChange)
501 WebInspector.domAgent.markUndoableState(); 501 WebInspector.domModel.markUndoableState();
502 502
503 if (!error && userCallback) 503 if (!error && userCallback)
504 userCallback(error); 504 userCallback(error);
505 } 505 }
506 }, 506 },
507 507
508 _undoRedoRequested: function() 508 _undoRedoRequested: function()
509 { 509 {
510 this._pendingCommandsMajorState.push(true); 510 this._pendingCommandsMajorState.push(true);
511 }, 511 },
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 /** 1117 /**
1118 * @param {?string} error 1118 * @param {?string} error
1119 * @param {!CSSAgent.CSSStyle} stylePayload 1119 * @param {!CSSAgent.CSSStyle} stylePayload
1120 * @this {WebInspector.CSSProperty} 1120 * @this {WebInspector.CSSProperty}
1121 */ 1121 */
1122 function callback(error, stylePayload) 1122 function callback(error, stylePayload)
1123 { 1123 {
1124 WebInspector.cssModel._pendingCommandsMajorState.pop(); 1124 WebInspector.cssModel._pendingCommandsMajorState.pop();
1125 if (!error) { 1125 if (!error) {
1126 if (majorChange) 1126 if (majorChange)
1127 WebInspector.domAgent.markUndoableState(); 1127 WebInspector.domModel.markUndoableState();
1128 var style = WebInspector.CSSStyleDeclaration.parsePayload(styleP ayload); 1128 var style = WebInspector.CSSStyleDeclaration.parsePayload(styleP ayload);
1129 var newProperty = style.allProperties[this.index]; 1129 var newProperty = style.allProperties[this.index];
1130 1130
1131 if (newProperty && this.disabled && !propertyText.match(/^\s*$/) ) { 1131 if (newProperty && this.disabled && !propertyText.match(/^\s*$/) ) {
1132 newProperty.setDisabled(false, enabledCallback); 1132 newProperty.setDisabled(false, enabledCallback);
1133 return; 1133 return;
1134 } 1134 }
1135 if (userCallback) 1135 if (userCallback)
1136 userCallback(style); 1136 userCallback(style);
1137 } else { 1137 } else {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 for (var i = 0; i < callbacks.length; ++i) 1569 for (var i = 0; i < callbacks.length; ++i)
1570 callbacks[i](computedStyle); 1570 callbacks[i](computedStyle);
1571 } 1571 }
1572 } 1572 }
1573 } 1573 }
1574 1574
1575 /** 1575 /**
1576 * @type {!WebInspector.CSSStyleModel} 1576 * @type {!WebInspector.CSSStyleModel}
1577 */ 1577 */
1578 WebInspector.cssModel; 1578 WebInspector.cssModel;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/AuditRules.js ('k') | Source/devtools/front_end/ConsoleViewMessage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698