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

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

Issue 220903002: DevTools: wrap DebuggerAgent.Location with DebuggerModel.Location. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: All tests!!! Created 6 years, 8 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.Object} 33 * @extends {WebInspector.TargetAwareObject}
34 * @param {!WebInspector.Target} target 34 * @param {!WebInspector.Target} target
35 */ 35 */
36 WebInspector.CSSStyleModel = function(target) 36 WebInspector.CSSStyleModel = function(target)
37 { 37 {
38 WebInspector.TargetAwareObject.call(this, target);
38 this._domModel = target.domModel; 39 this._domModel = target.domModel;
39 this._agent = target.cssAgent(); 40 this._agent = target.cssAgent();
40 this._pendingCommandsMajorState = []; 41 this._pendingCommandsMajorState = [];
41 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this) ; 42 this._styleLoader = new WebInspector.CSSStyleModel.ComputedStyleLoader(this) ;
42 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoRequest ed, this._undoRedoRequested, this); 43 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoRequest ed, this._undoRedoRequested, this);
43 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoComplet ed, this._undoRedoCompleted, this); 44 this._domModel.addEventListener(WebInspector.DOMModel.Events.UndoRedoComplet ed, this._undoRedoCompleted, this);
44 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, th is); 45 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, th is);
45 InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)) ; 46 InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)) ;
46 this._agent.enable(this._wasEnabled.bind(this)); 47 this._agent.enable(this._wasEnabled.bind(this));
47 this._resetStyleSheets(); 48 this._resetStyleSheets();
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 styleSheetIds = styleSheetIds.concat(frameIdToSheetIds[frameId]); 586 styleSheetIds = styleSheetIds.concat(frameIdToSheetIds[frameId]);
586 var uiLocation; 587 var uiLocation;
587 for (var i = 0; !uiLocation && i < styleSheetIds.length; ++i) { 588 for (var i = 0; !uiLocation && i < styleSheetIds.length; ++i) {
588 var header = this.styleSheetHeaderForId(styleSheetIds[i]); 589 var header = this.styleSheetHeaderForId(styleSheetIds[i]);
589 console.assert(header); 590 console.assert(header);
590 uiLocation = header.rawLocationToUILocation(rawLocation.lineNumber, rawLocation.columnNumber); 591 uiLocation = header.rawLocationToUILocation(rawLocation.lineNumber, rawLocation.columnNumber);
591 } 592 }
592 return uiLocation || null; 593 return uiLocation || null;
593 }, 594 },
594 595
595 __proto__: WebInspector.Object.prototype 596 __proto__: WebInspector.TargetAwareObject.prototype
596 } 597 }
597 598
598 /** 599 /**
599 * @constructor 600 * @constructor
600 * @extends {WebInspector.LiveLocation} 601 * @extends {WebInspector.LiveLocation}
601 * @param {!WebInspector.CSSStyleModel} model 602 * @param {!WebInspector.CSSStyleModel} model
602 * @param {?WebInspector.CSSStyleSheetHeader} header 603 * @param {?WebInspector.CSSStyleSheetHeader} header
603 * @param {!WebInspector.CSSLocation} rawLocation 604 * @param {!WebInspector.CSSLocation} rawLocation
604 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDelegat e 605 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDelegat e
605 */ 606 */
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 __proto__: WebInspector.LiveLocation.prototype 681 __proto__: WebInspector.LiveLocation.prototype
681 } 682 }
682 683
683 /** 684 /**
684 * @constructor 685 * @constructor
685 * @implements {WebInspector.RawLocation} 686 * @implements {WebInspector.RawLocation}
686 * @param {string} url 687 * @param {string} url
687 * @param {number} lineNumber 688 * @param {number} lineNumber
688 * @param {number=} columnNumber 689 * @param {number=} columnNumber
689 */ 690 */
690 WebInspector.CSSLocation = function(url, lineNumber, columnNumber) 691 WebInspector.CSSLocation = function(target, url, lineNumber, columnNumber)
691 { 692 {
693 this._cssModel = target.cssModel;
692 this.url = url; 694 this.url = url;
693 this.lineNumber = lineNumber; 695 this.lineNumber = lineNumber;
694 this.columnNumber = columnNumber || 0; 696 this.columnNumber = columnNumber || 0;
695 } 697 }
696 698
699 WebInspector.CSSLocation.prototype = {
700 /**
701 * @param {?CSSAgent.StyleSheetId} styleSheetId
702 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate
703 * @return {?WebInspector.LiveLocation}
704 */
705 createLiveLocation: function(styleSheetId, updateDelegate)
706 {
707 var header = styleSheetId ? this._cssModel.styleSheetHeaderForId(styleSh eetId) : null;
708 return new WebInspector.CSSStyleModel.LiveLocation(this._cssModel, heade r, this, updateDelegate);
709 },
710
711 /**
712 * @return {?WebInspector.UILocation}
713 */
714 toUILocation: function()
715 {
716 return this._cssModel.rawLocationToUILocation(this);
717 }
718 }
719
697 /** 720 /**
698 * @constructor 721 * @constructor
699 * @param {!WebInspector.CSSStyleModel} cssModel 722 * @param {!WebInspector.CSSStyleModel} cssModel
700 * @param {!CSSAgent.CSSStyle} payload 723 * @param {!CSSAgent.CSSStyle} payload
701 */ 724 */
702 WebInspector.CSSStyleDeclaration = function(cssModel, payload) 725 WebInspector.CSSStyleDeclaration = function(cssModel, payload)
703 { 726 {
704 this._cssModel = cssModel; 727 this._cssModel = cssModel;
705 this.id = payload.styleId; 728 this.id = payload.styleId;
706 this.width = payload.width; 729 this.width = payload.width;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 WebInspector.CSSRule.prototype = { 997 WebInspector.CSSRule.prototype = {
975 _setRawLocationAndFrameId: function() 998 _setRawLocationAndFrameId: function()
976 { 999 {
977 if (!this.id) 1000 if (!this.id)
978 return; 1001 return;
979 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl eSheetId); 1002 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl eSheetId);
980 this.frameId = styleSheetHeader.frameId; 1003 this.frameId = styleSheetHeader.frameId;
981 var url = styleSheetHeader.resourceURL(); 1004 var url = styleSheetHeader.resourceURL();
982 if (!url) 1005 if (!url)
983 return; 1006 return;
984 this.rawLocation = new WebInspector.CSSLocation(url, this.lineNumberInSo urce(0), this.columnNumberInSource(0)); 1007 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), url, this.lineNumberInSource(0), this.columnNumberInSource(0));
985 }, 1008 },
986 1009
987 /** 1010 /**
988 * @return {string} 1011 * @return {string}
989 */ 1012 */
990 resourceURL: function() 1013 resourceURL: function()
991 { 1014 {
992 if (!this.id) 1015 if (!this.id)
993 return ""; 1016 return "";
994 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl eSheetId); 1017 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl eSheetId);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 return null; 1246 return null;
1224 1247
1225 var url = this.ownerStyle.parentRule.resourceURL(); 1248 var url = this.ownerStyle.parentRule.resourceURL();
1226 if (!url) 1249 if (!url)
1227 return null; 1250 return null;
1228 1251
1229 var range = this.range; 1252 var range = this.range;
1230 var line = forName ? range.startLine : range.endLine; 1253 var line = forName ? range.startLine : range.endLine;
1231 // End of range is exclusive, so subtract 1 from the end offset. 1254 // End of range is exclusive, so subtract 1 from the end offset.
1232 var column = forName ? range.startColumn : range.endColumn - (this.text && this.text.endsWith(";") ? 2 : 1); 1255 var column = forName ? range.startColumn : range.endColumn - (this.text && this.text.endsWith(";") ? 2 : 1);
1233 var rawLocation = new WebInspector.CSSLocation(url, line, column); 1256 var rawLocation = new WebInspector.CSSLocation(this.ownerStyle._cssModel .target(), url, line, column);
1234 return this.ownerStyle._cssModel.rawLocationToUILocation(rawLocation); 1257 return rawLocation.toUILocation();
1235 } 1258 }
1236 } 1259 }
1237 1260
1238 /** 1261 /**
1239 * @constructor 1262 * @constructor
1240 * @param {!WebInspector.CSSStyleModel} cssModel 1263 * @param {!WebInspector.CSSStyleModel} cssModel
1241 * @param {!CSSAgent.CSSMedia} payload 1264 * @param {!CSSAgent.CSSMedia} payload
1242 */ 1265 */
1243 WebInspector.CSSMedia = function(cssModel, payload) 1266 WebInspector.CSSMedia = function(cssModel, payload)
1244 { 1267 {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 }, 1399 },
1377 1400
1378 /** 1401 /**
1379 * @param {number} lineNumber 1402 * @param {number} lineNumber
1380 * @param {number=} columnNumber 1403 * @param {number=} columnNumber
1381 * @return {?WebInspector.UILocation} 1404 * @return {?WebInspector.UILocation}
1382 */ 1405 */
1383 rawLocationToUILocation: function(lineNumber, columnNumber) 1406 rawLocationToUILocation: function(lineNumber, columnNumber)
1384 { 1407 {
1385 var uiLocation = null; 1408 var uiLocation = null;
1386 var rawLocation = new WebInspector.CSSLocation(this.resourceURL(), lineN umber, columnNumber); 1409 var rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), this.resourceURL(), lineNumber, columnNumber);
1387 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i ) 1410 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i )
1388 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca tion); 1411 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca tion);
1389 return uiLocation; 1412 return uiLocation;
1390 }, 1413 },
1391 1414
1392 /** 1415 /**
1393 * @param {!WebInspector.SourceMapping} sourceMapping 1416 * @param {!WebInspector.SourceMapping} sourceMapping
1394 */ 1417 */
1395 pushSourceMapping: function(sourceMapping) 1418 pushSourceMapping: function(sourceMapping)
1396 { 1419 {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 for (var i = 0; i < callbacks.length; ++i) 1629 for (var i = 0; i < callbacks.length; ++i)
1607 callbacks[i](computedStyle); 1630 callbacks[i](computedStyle);
1608 } 1631 }
1609 } 1632 }
1610 } 1633 }
1611 1634
1612 /** 1635 /**
1613 * @type {!WebInspector.CSSStyleModel} 1636 * @type {!WebInspector.CSSStyleModel}
1614 */ 1637 */
1615 WebInspector.cssModel; 1638 WebInspector.cssModel;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/CPUProfilerModel.js ('k') | Source/devtools/front_end/ConsoleModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698