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

Unified Diff: Source/devtools/front_end/StylesSourceMapping.js

Issue 25879002: DevTools: Get rid of styleFile on UISourceCode (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Removed test Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/StylesSourceMapping.js
diff --git a/Source/devtools/front_end/StylesSourceMapping.js b/Source/devtools/front_end/StylesSourceMapping.js
index 8ec1f79c36cc870548fb24a226d3863b9cb24f3e..2f5834825350333a8cd944895ea7710f648fa54e 100644
--- a/Source/devtools/front_end/StylesSourceMapping.js
+++ b/Source/devtools/front_end/StylesSourceMapping.js
@@ -40,8 +40,11 @@ WebInspector.StylesSourceMapping = function(cssModel, workspace)
this._workspace = workspace;
this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
+ this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this);
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameCreatedOrNavigated, this._mainFrameCreatedOrNavigated, this);
+
+ this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetChanged, this);
this._initialize();
}
@@ -127,10 +130,11 @@ WebInspector.StylesSourceMapping.prototype = {
*/
_unbindUISourceCode: function(uiSourceCode)
{
- if (!uiSourceCode.styleFile())
+ var styleFile = this._styleFiles.get(uiSourceCode);
+ if (!styleFile)
return;
- uiSourceCode.styleFile().dispose();
- uiSourceCode.setStyleFile(null);
+ styleFile.dispose();
+ this._styleFiles.remove(uiSourceCode);
},
/**
@@ -151,10 +155,10 @@ WebInspector.StylesSourceMapping.prototype = {
*/
_bindUISourceCode: function(uiSourceCode, header)
{
- if (uiSourceCode.styleFile() || header.isInline)
+ if (this._styleFiles.get(uiSourceCode) || header.isInline)
return;
var url = uiSourceCode.url;
- uiSourceCode.setStyleFile(new WebInspector.StyleFile(uiSourceCode));
+ this._styleFiles.put(uiSourceCode, new WebInspector.StyleFile(uiSourceCode, this));
header.updateLocations();
},
@@ -166,13 +170,24 @@ WebInspector.StylesSourceMapping.prototype = {
var project = /** @type {WebInspector.Project} */ (event.data);
var uiSourceCodes = project.uiSourceCodes();
for (var i = 0; i < uiSourceCodes; ++i)
- delete this._urlToHeadersByFrameId[uiSourceCodes[i].url];
+ this._unbindUISourceCode(uiSourceCodes[i]);
+ },
+
+ /**
+ * @param {WebInspector.Event} event
+ */
+ _uiSourceCodeRemoved: function(event)
+ {
+ var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
+ this._unbindUISourceCode(uiSourceCode);
},
_initialize: function()
{
/** @type {!Object.<string, !StringMap.<!StringMap.<!WebInspector.CSSStyleSheetHeader>>>} */
this._urlToHeadersByFrameId = {};
+ /** @type {!Map.<WebInspector.UISourceCode, WebInspector.StyleFile>} */
+ this._styleFiles = new Map();
},
/**
@@ -187,16 +202,86 @@ WebInspector.StylesSourceMapping.prototype = {
this._unbindUISourceCode(uiSourceCode);
}
this._initialize();
+ },
+
+ /**
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @param {string} content
+ * @param {boolean} majorChange
+ * @param {function(?string)} userCallback
+ */
+ _setStyleContent: function(uiSourceCode, content, majorChange, userCallback)
+ {
+ var styleSheetIds = this._cssModel.styleSheetIdsForURL(uiSourceCode.url);
+ if (!styleSheetIds.length) {
+ userCallback("No stylesheet found: " + uiSourceCode.url);
+ return;
+ }
+
+ this._isSettingContent = true;
+ function callback(error)
+ {
+ userCallback(error);
+ delete this._isSettingContent;
+ }
+ this._cssModel.setStyleSheetText(styleSheetIds[0], content, majorChange, callback.bind(this));
+ },
+
+ /**
+ * @param {WebInspector.Event} event
+ */
+ _styleSheetChanged: function(event)
+ {
+ if (this._isSettingContent)
+ return;
+
+ if (!event.data.majorChange)
+ return;
+
+ /**
+ * @param {?string} error
+ * @param {string} content
+ */
+ function callback(error, content)
+ {
+ if (!error)
+ this._innerStyleSheetChanged(event.data.styleSheetId, content);
+ }
+ CSSAgent.getStyleSheetText(event.data.styleSheetId, callback.bind(this));
+ },
+
+ /**
+ * @param {CSSAgent.StyleSheetId} styleSheetId
+ * @param {string} content
+ */
+ _innerStyleSheetChanged: function(styleSheetId, content)
+ {
+ var header = this._cssModel.styleSheetHeaderForId(styleSheetId);
+ if (!header)
+ return;
+ var styleSheetURL = header.resourceURL();
+ if (!styleSheetURL)
+ return;
+
+ var uiSourceCode = this._workspace.uiSourceCodeForURL(styleSheetURL)
+ if (!uiSourceCode)
+ return;
+
+ var styleFile = this._styleFiles.get(uiSourceCode);
+ if (styleFile)
+ styleFile.addRevision(content);
}
}
/**
* @constructor
* @param {WebInspector.UISourceCode} uiSourceCode
+ * @param {WebInspector.StylesSourceMapping} mapping
*/
-WebInspector.StyleFile = function(uiSourceCode)
+WebInspector.StyleFile = function(uiSourceCode, mapping)
{
this._uiSourceCode = uiSourceCode;
+ this._mapping = mapping;
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
}
@@ -232,7 +317,7 @@ WebInspector.StyleFile.prototype = {
_commitIncrementalEdit: function(majorChange)
{
this._clearIncrementalUpdateTimer();
- WebInspector.styleContentBinding.setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), majorChange, this._styleContentSet.bind(this));
+ this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), majorChange, this._styleContentSet.bind(this));
},
/**
@@ -270,88 +355,3 @@ WebInspector.StyleFile.prototype = {
this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
}
}
-
-/**
- * @constructor
- * @param {WebInspector.CSSStyleModel} cssModel
- */
-WebInspector.StyleContentBinding = function(cssModel, workspace)
-{
- this._cssModel = cssModel;
- this._workspace = workspace;
- this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetChanged, this);
-}
-
-WebInspector.StyleContentBinding.prototype = {
- /**
- * @param {WebInspector.UISourceCode} uiSourceCode
- * @param {string} content
- * @param {boolean} majorChange
- * @param {function(?string)} userCallback
- */
- setStyleContent: function(uiSourceCode, content, majorChange, userCallback)
- {
- var styleSheetIds = this._cssModel.styleSheetIdsForURL(uiSourceCode.url);
- if (!styleSheetIds.length) {
- userCallback("No stylesheet found: " + uiSourceCode.url);
- return;
- }
-
- this._isSettingContent = true;
- function callback(error)
- {
- userCallback(error);
- delete this._isSettingContent;
- }
- this._cssModel.setStyleSheetText(styleSheetIds[0], content, majorChange, callback.bind(this));
- },
-
- /**
- * @param {WebInspector.Event} event
- */
- _styleSheetChanged: function(event)
- {
- if (this._isSettingContent)
- return;
-
- if (!event.data.majorChange)
- return;
-
- /**
- * @param {?string} error
- * @param {string} content
- */
- function callback(error, content)
- {
- if (!error)
- this._innerStyleSheetChanged(event.data.styleSheetId, content);
- }
- CSSAgent.getStyleSheetText(event.data.styleSheetId, callback.bind(this));
- },
-
- /**
- * @param {CSSAgent.StyleSheetId} styleSheetId
- * @param {string} content
- */
- _innerStyleSheetChanged: function(styleSheetId, content)
- {
- var header = this._cssModel.styleSheetHeaderForId(styleSheetId);
- if (!header)
- return;
- var styleSheetURL = header.resourceURL();
- if (!styleSheetURL)
- return;
-
- var uiSourceCode = this._workspace.uiSourceCodeForURL(styleSheetURL)
- if (!uiSourceCode)
- return;
-
- if (uiSourceCode.styleFile())
- uiSourceCode.styleFile().addRevision(content);
- }
-}
-
-/**
- * @type {?WebInspector.StyleContentBinding}
- */
-WebInspector.styleContentBinding = null;
« no previous file with comments | « LayoutTests/inspector/styles/stylesheet-removal-expected.txt ('k') | Source/devtools/front_end/UISourceCode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698