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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleModel.js

Issue 1694433003: DevTools: [CSS] Add CSS.setMultipleStyleTexts command to CSS domain (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 10 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 StyleSheetRemoved: "StyleSheetRemoved", 73 StyleSheetRemoved: "StyleSheetRemoved",
74 ExternalRangeEdit: "ExternalRangeEdit" 74 ExternalRangeEdit: "ExternalRangeEdit"
75 } 75 }
76 76
77 WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld ", "print", "projection", "screen", "speech", "tty", "tv"]; 77 WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld ", "print", "projection", "screen", "speech", "tty", "tv"];
78 78
79 WebInspector.CSSStyleModel.PseudoStateMarker = "pseudo-state-marker"; 79 WebInspector.CSSStyleModel.PseudoStateMarker = "pseudo-state-marker";
80 80
81 WebInspector.CSSStyleModel.prototype = { 81 WebInspector.CSSStyleModel.prototype = {
82 /** 82 /**
83 * @param {!Array<!CSSAgent.StyleSheetId>} styleSheetIds
84 * @param {!Array<!WebInspector.TextRange>} ranges
85 * @param {!Array<string>} texts
86 * @param {boolean} majorChange
87 * @return {!Promise<?Array<!CSSAgent.CSSStyle>>}
88 */
89 setStyleTexts: function(styleSheetIds, ranges, texts, majorChange)
90 {
91 /**
92 * @param {?Protocol.Error} error
93 * @param {?Array<!CSSAgent.CSSStyle>} stylePayloads
94 * @return {?Array<!CSSAgent.CSSStyle>}
95 * @this {WebInspector.CSSStyleModel}
96 */
97 function parsePayload(error, stylePayloads)
98 {
99 if (error || !stylePayloads || !stylePayloads.length)
100 return null;
101
102 if (majorChange)
103 this._domModel.markUndoableState();
104 for (var styleSheetId of styleSheetIds)
105 this._fireStyleSheetChanged(styleSheetId);
dgozman 2016/02/17 23:32:36 Let's coalesce events for the same stylesheet.
lushnikov 2016/02/18 01:40:16 Done.
106 return stylePayloads;
107 }
108
109 console.assert(styleSheetIds.length === ranges.length && ranges.length = == texts.length, "Array lengths must be equal");
110 var edits = [];
111 for (var i = 0; i < styleSheetIds.length; ++i) {
112 edits.push({
113 styleSheetId: styleSheetIds[i],
114 range: ranges[i].serializeToObject(),
115 text: texts[i]
116 });
117 }
118
119 return this._agent.setStyleTexts(edits, parsePayload.bind(this))
120 .catchException(/** @type {?Array<!CSSAgent.CSSStyle>} */(null));
121 },
122
123 /**
83 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>} 124 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>}
84 */ 125 */
85 mediaQueriesPromise: function() 126 mediaQueriesPromise: function()
86 { 127 {
87 /** 128 /**
88 * @param {?Protocol.Error} error 129 * @param {?Protocol.Error} error
89 * @param {?Array.<!CSSAgent.CSSMedia>} payload 130 * @param {?Array.<!CSSAgent.CSSMedia>} payload
90 * @return {!Array.<!WebInspector.CSSMedia>} 131 * @return {!Array.<!WebInspector.CSSMedia>}
91 * @this {!WebInspector.CSSStyleModel} 132 * @this {!WebInspector.CSSStyleModel}
92 */ 133 */
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 return property; 980 return property;
940 }, 981 },
941 982
942 /** 983 /**
943 * @param {string} text 984 * @param {string} text
944 * @param {boolean} majorChange 985 * @param {boolean} majorChange
945 * @return {!Promise.<boolean>} 986 * @return {!Promise.<boolean>}
946 */ 987 */
947 setText: function(text, majorChange) 988 setText: function(text, majorChange)
948 { 989 {
949 if (!this.styleSheetId)
950 return Promise.resolve(false);
951
952 /** 990 /**
953 * @param {?Protocol.Error} error 991 * @param {?Array<!CSSAgent.CSSStyle>} stylePayloads
954 * @param {?CSSAgent.CSSStyle} stylePayload
955 * @return {boolean} 992 * @return {boolean}
956 * @this {WebInspector.CSSStyleDeclaration} 993 * @this {WebInspector.CSSStyleDeclaration}
957 */ 994 */
958 function parsePayload(error, stylePayload) 995 function onPayload(stylePayloads)
959 { 996 {
960 if (error || !stylePayload) 997 if (!stylePayloads)
961 return false; 998 return false;
962 999 this._reinitialize(stylePayloads[0]);
963 if (majorChange)
964 this._cssModel._domModel.markUndoableState();
965 this._reinitialize(stylePayload);
966 this._cssModel._fireStyleSheetChanged(this.styleSheetId);
967 return true; 1000 return true;
968 } 1001 }
969 1002
970 return this._cssModel._agent.setStyleText(this.styleSheetId, this.range. serializeToObject(), text, parsePayload.bind(this)) 1003 return this._cssModel.setStyleTexts([this.styleSheetId], [this.range], [ text], majorChange)
1004 .then(onPayload.bind(this))
971 .catchException(false); 1005 .catchException(false);
972 }, 1006 },
973 1007
974 /** 1008 /**
975 * @param {number} index 1009 * @param {number} index
976 * @param {string} name 1010 * @param {string} name
977 * @param {string} value 1011 * @param {string} value
978 * @param {function(boolean)=} userCallback 1012 * @param {function(boolean)=} userCallback
979 */ 1013 */
980 insertPropertyAt: function(index, name, value, userCallback) 1014 insertPropertyAt: function(index, name, value, userCallback)
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 * @constructor 2555 * @constructor
2522 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle 2556 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle
2523 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle 2557 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle
2524 */ 2558 */
2525 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS tyle) 2559 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS tyle)
2526 { 2560 {
2527 this.inlineStyle = inlineStyle; 2561 this.inlineStyle = inlineStyle;
2528 this.attributesStyle = attributesStyle; 2562 this.attributesStyle = attributesStyle;
2529 } 2563 }
2530 2564
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698