Commit ec4abe83 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[DevTools] cleanup source maps

Removed unused methods.

R=lushnikov@chromium.org

Bug: none
Change-Id: I63d14fcbf504d7b39d1758c54df358c1d6bd1630
Reviewed-on: https://chromium-review.googlesource.com/1174857
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583006}
parent 2a4a0f03
...@@ -1007,37 +1007,22 @@ Elements.StylePropertiesSection = class { ...@@ -1007,37 +1007,22 @@ Elements.StylePropertiesSection = class {
const menuButton = new UI.ToolbarButton('', 'largeicon-menu'); const menuButton = new UI.ToolbarButton('', 'largeicon-menu');
menuButton.element.tabIndex = -1; menuButton.element.tabIndex = -1;
sectionToolbar.appendToolbarItem(menuButton); sectionToolbar.appendToolbarItem(menuButton);
setItemsVisibility.call(this, items, false); setItemsVisibility(items, false);
sectionToolbar.element.addEventListener('mouseenter', setItemsVisibility.bind(this, items, true)); sectionToolbar.element.addEventListener('mouseenter', setItemsVisibility.bind(null, items, true));
sectionToolbar.element.addEventListener('mouseleave', setItemsVisibility.bind(this, items, false)); sectionToolbar.element.addEventListener('mouseleave', setItemsVisibility.bind(null, items, false));
UI.ARIAUtils.markAsHidden(sectionToolbar.element); UI.ARIAUtils.markAsHidden(sectionToolbar.element);
/** /**
* @param {!Array<!UI.ToolbarButton>} items * @param {!Array<!UI.ToolbarButton>} items
* @param {boolean} value * @param {boolean} value
* @this {Elements.StylePropertiesSection}
*/ */
function setItemsVisibility(items, value) { function setItemsVisibility(items, value) {
for (let i = 0; i < items.length; ++i) for (let i = 0; i < items.length; ++i)
items[i].setVisible(value); items[i].setVisible(value);
menuButton.setVisible(!value); menuButton.setVisible(!value);
if (this._isSASSStyle())
newRuleButton.setVisible(false);
} }
} }
/**
* @return {boolean}
*/
_isSASSStyle() {
const header =
this._style.styleSheetId ? this._style.cssModel().styleSheetHeaderForId(this._style.styleSheetId) : null;
if (!header)
return false;
const sourceMap = header.cssModel().sourceMapManager().sourceMapForClient(header);
return sourceMap ? sourceMap.editable() : false;
}
/** /**
* @return {!SDK.CSSStyleDeclaration} * @return {!SDK.CSSStyleDeclaration}
*/ */
...@@ -1561,7 +1546,7 @@ Elements.StylePropertiesSection = class { ...@@ -1561,7 +1546,7 @@ Elements.StylePropertiesSection = class {
return; return;
} }
if (!this.editable || this._isSASSStyle()) if (!this.editable)
return; return;
const config = new UI.InplaceEditor.Config( const config = new UI.InplaceEditor.Config(
...@@ -1675,7 +1660,7 @@ Elements.StylePropertiesSection = class { ...@@ -1675,7 +1660,7 @@ Elements.StylePropertiesSection = class {
} }
_startEditingAtFirstPosition() { _startEditingAtFirstPosition() {
if (!this.editable || this._isSASSStyle()) if (!this.editable)
return; return;
if (!this._style.parentRule) { if (!this._style.parentRule) {
......
...@@ -105,129 +105,18 @@ SDK.CSSModel = class extends SDK.SDKModel { ...@@ -105,129 +105,18 @@ SDK.CSSModel = class extends SDK.SDKModel {
* @param {boolean} majorChange * @param {boolean} majorChange
* @return {!Promise<boolean>} * @return {!Promise<boolean>}
*/ */
setStyleText(styleSheetId, range, text, majorChange) { async setStyleText(styleSheetId, range, text, majorChange) {
const original = this._innerSetStyleTexts.bind(this, [styleSheetId], [range], [text], majorChange);
const header = this.styleSheetHeaderForId(styleSheetId);
if (!header)
return original();
const sourceMap = this._sourceMapManager.sourceMapForClient(header);
if (!sourceMap)
return original();
const originalAndDetach = originalAndDetachIfSuccess.bind(this, header);
if (!sourceMap.editable())
return original();
return /** @type {!Promise<boolean>} */ (
sourceMap.editCompiled([range], [text]).then(onEditingDone.bind(this)).catch(onError.bind(this, header)));
/**
* @param {?SDK.SourceMap.EditResult} editResult
* @return {!Promise<boolean>}
* @this {SDK.CSSModel}
*/
function onEditingDone(editResult) {
if (!editResult)
return Promise.resolve(false);
let edits = editResult.compiledEdits;
if (!edits.length)
return onCSSPatched.call(this, editResult, true);
edits.sort(TextUtils.SourceEdit.comparator);
edits = edits.reverse();
const styleSheetIds = [];
const ranges = [];
const texts = [];
for (const edit of edits) {
styleSheetIds.push(header.id);
ranges.push(edit.oldRange);
texts.push(edit.newText);
}
return this._innerSetStyleTexts(styleSheetIds, ranges, texts, majorChange)
.then(onCSSPatched.bind(this, editResult));
}
/**
* @param {!SDK.SourceMap.EditResult} editResult
* @param {boolean} success
* @return {!Promise<boolean>}
* @this {SDK.CSSModel}
*/
function onCSSPatched(editResult, success) {
if (!success)
return originalAndDetach();
this._sourceMapManager.applySourceMapEdit(editResult);
return Promise.resolve(true);
}
/**
* @param {!SDK.CSSStyleSheetHeader} header
* @param {*} error
* @return {!Promise<boolean>}
* @this {SDK.CSSModel}
*/
function onError(header, error) {
Common.console.error(Common.UIString('LiveSASS failed: %s', sourceMap.compiledURL()));
console.error(error);
this._sourceMapManager.detachSourceMap(header);
return original();
}
/**
* @param {!SDK.CSSStyleSheetHeader} header
* @return {!Promise<boolean>}
* @this {SDK.CSSModel}
*/
function originalAndDetachIfSuccess(header) {
return this._innerSetStyleTexts([styleSheetId], [range], [text], majorChange).then(detachIfSuccess.bind(this));
/**
* @param {boolean} success
* @return {boolean}
* @this {SDK.CSSModel}
*/
function detachIfSuccess(success) {
if (success)
this._sourceMapManager.detachSourceMap(header);
return success;
}
}
}
/**
* @param {!Array<!Protocol.CSS.StyleSheetId>} styleSheetIds
* @param {!Array<!TextUtils.TextRange>} ranges
* @param {!Array<string>} texts
* @param {boolean} majorChange
* @return {!Promise<boolean>}
*/
async _innerSetStyleTexts(styleSheetIds, ranges, texts, majorChange) {
console.assert(
styleSheetIds.length === ranges.length && ranges.length === texts.length, 'Array lengths must be equal');
const edits = [];
const ensureContentPromises = [];
for (let i = 0; i < styleSheetIds.length; ++i) {
edits.push({styleSheetId: styleSheetIds[i], range: ranges[i].serializeToObject(), text: texts[i]});
ensureContentPromises.push(this._ensureOriginalStyleSheetText(styleSheetIds[i]));
}
try { try {
await Promise.all(ensureContentPromises); await this._ensureOriginalStyleSheetText(styleSheetId);
const stylePayloads = await this._agent.setStyleTexts(edits);
if (!stylePayloads || stylePayloads.length !== ranges.length) const stylePayloads =
await this._agent.setStyleTexts([{styleSheetId: styleSheetId, range: range.serializeToObject(), text: text}]);
if (!stylePayloads || stylePayloads.length !== 1)
return false; return false;
this._domModel.markUndoableState(!majorChange); this._domModel.markUndoableState(!majorChange);
for (let i = 0; i < ranges.length; ++i) { const edit = new SDK.CSSModel.Edit(styleSheetId, range, text, stylePayloads[0]);
const edit = new SDK.CSSModel.Edit(styleSheetIds[i], ranges[i], texts[i], stylePayloads[i]); this._fireStyleSheetChanged(styleSheetId, edit);
this._fireStyleSheetChanged(styleSheetIds[i], edit);
}
return true; return true;
} catch (e) { } catch (e) {
return false; return false;
......
...@@ -136,18 +136,6 @@ SDK.SourceMap.prototype = { ...@@ -136,18 +136,6 @@ SDK.SourceMap.prototype = {
* @return {?SDK.SourceMapEntry} * @return {?SDK.SourceMapEntry}
*/ */
findEntry(lineNumber, columnNumber) {}, findEntry(lineNumber, columnNumber) {},
/**
* @return {boolean}
*/
editable() {},
/**
* @param {!Array<!TextUtils.TextRange>} ranges
* @param {!Array<string>} texts
* @return {!Promise<?SDK.SourceMap.EditResult>}
*/
editCompiled(ranges, texts) {},
}; };
/** /**
...@@ -166,20 +154,6 @@ SDK.SourceMap.EditResult = class { ...@@ -166,20 +154,6 @@ SDK.SourceMap.EditResult = class {
} }
}; };
/**
* @interface
*/
SDK.SourceMapFactory = function() {};
SDK.SourceMapFactory.prototype = {
/**
* @param {!SDK.Target} target
* @param {!SDK.SourceMap} sourceMap
* @return {!Promise<?SDK.SourceMap>}
*/
editableSourceMap(target, sourceMap) {},
};
/** /**
* @implements {SDK.SourceMap} * @implements {SDK.SourceMap}
* @unrestricted * @unrestricted
...@@ -296,24 +270,6 @@ SDK.TextSourceMap = class { ...@@ -296,24 +270,6 @@ SDK.TextSourceMap = class {
return this._sourceInfos.get(sourceURL).content; return this._sourceInfos.get(sourceURL).content;
} }
/**
* @override
* @return {boolean}
*/
editable() {
return false;
}
/**
* @override
* @param {!Array<!TextUtils.TextRange>} ranges
* @param {!Array<string>} texts
* @return {!Promise<?SDK.SourceMap.EditResult>}
*/
editCompiled(ranges, texts) {
return Promise.resolve(/** @type {?SDK.SourceMap.EditResult} */ (null));
}
/** /**
* @override * @override
* @param {number} lineNumber in compiled resource * @param {number} lineNumber in compiled resource
......
...@@ -141,29 +141,10 @@ SDK.SourceMapManager = class extends Common.Object { ...@@ -141,29 +141,10 @@ SDK.SourceMapManager = class extends Common.Object {
} }
if (!this._sourceMapURLToLoadingClients.has(sourceMapURL)) { if (!this._sourceMapURLToLoadingClients.has(sourceMapURL)) {
SDK.TextSourceMap.load(sourceMapURL, sourceURL) SDK.TextSourceMap.load(sourceMapURL, sourceURL)
.then(onTextSourceMapLoaded.bind(this, sourceMapURL))
.then(onSourceMap.bind(this, sourceMapURL)); .then(onSourceMap.bind(this, sourceMapURL));
} }
this._sourceMapURLToLoadingClients.set(sourceMapURL, client); this._sourceMapURLToLoadingClients.set(sourceMapURL, client);
/**
* @param {string} sourceMapURL
* @param {?SDK.TextSourceMap} sourceMap
* @return {!Promise<?SDK.SourceMap>}
* @this {SDK.SourceMapManager}
*/
function onTextSourceMapLoaded(sourceMapURL, sourceMap) {
if (!sourceMap)
return Promise.resolve(/** @type {?SDK.SourceMap} */ (null));
const factoryExtension = this._factoryForSourceMap(sourceMap);
if (!factoryExtension)
return Promise.resolve(/** @type {?SDK.SourceMap} */ (sourceMap));
return factoryExtension.instance()
.then(factory => factory.editableSourceMap(this._target, sourceMap))
.then(map => map || sourceMap)
.catchException(/** @type {?SDK.SourceMap} */ (null));
}
/** /**
* @param {string} sourceMapURL * @param {string} sourceMapURL
* @param {?SDK.SourceMap} sourceMap * @param {?SDK.SourceMap} sourceMap
...@@ -198,22 +179,6 @@ SDK.SourceMapManager = class extends Common.Object { ...@@ -198,22 +179,6 @@ SDK.SourceMapManager = class extends Common.Object {
} }
} }
/**
* @param {!SDK.SourceMap} sourceMap
* @return {?Runtime.Extension}
*/
_factoryForSourceMap(sourceMap) {
const sourceExtensions = new Set();
for (const url of sourceMap.sourceURLs())
sourceExtensions.add(Common.ParsedURL.extractExtension(url));
for (const runtimeExtension of self.runtime.extensions(SDK.SourceMapFactory)) {
const supportedExtensions = new Set(runtimeExtension.descriptor()['extensions']);
if (supportedExtensions.containsAll(sourceExtensions))
return runtimeExtension;
}
return null;
}
/** /**
* @param {!T} client * @param {!T} client
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment