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

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: %zu is not cross-platform - do not use. 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 var uniqueIDs = new Set(styleSheetIds);
105 for (var styleSheetId of uniqueIDs)
106 this._fireStyleSheetChanged(styleSheetId);
107 return stylePayloads;
108 }
109
110 console.assert(styleSheetIds.length === ranges.length && ranges.length = == texts.length, "Array lengths must be equal");
111 var edits = [];
112 for (var i = 0; i < styleSheetIds.length; ++i) {
113 edits.push({
114 styleSheetId: styleSheetIds[i],
115 range: ranges[i].serializeToObject(),
116 text: texts[i]
117 });
118 }
119
120 return this._agent.setStyleTexts(edits, parsePayload.bind(this))
121 .catchException(/** @type {?Array<!CSSAgent.CSSStyle>} */(null));
122 },
123
124 /**
83 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>} 125 * @return {!Promise.<!Array.<!WebInspector.CSSMedia>>}
84 */ 126 */
85 mediaQueriesPromise: function() 127 mediaQueriesPromise: function()
86 { 128 {
87 /** 129 /**
88 * @param {?Protocol.Error} error 130 * @param {?Protocol.Error} error
89 * @param {?Array.<!CSSAgent.CSSMedia>} payload 131 * @param {?Array.<!CSSAgent.CSSMedia>} payload
90 * @return {!Array.<!WebInspector.CSSMedia>} 132 * @return {!Array.<!WebInspector.CSSMedia>}
91 * @this {!WebInspector.CSSStyleModel} 133 * @this {!WebInspector.CSSStyleModel}
92 */ 134 */
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 return property; 981 return property;
940 }, 982 },
941 983
942 /** 984 /**
943 * @param {string} text 985 * @param {string} text
944 * @param {boolean} majorChange 986 * @param {boolean} majorChange
945 * @return {!Promise.<boolean>} 987 * @return {!Promise.<boolean>}
946 */ 988 */
947 setText: function(text, majorChange) 989 setText: function(text, majorChange)
948 { 990 {
949 if (!this.styleSheetId)
950 return Promise.resolve(false);
951
952 /** 991 /**
953 * @param {?Protocol.Error} error 992 * @param {?Array<!CSSAgent.CSSStyle>} stylePayloads
954 * @param {?CSSAgent.CSSStyle} stylePayload
955 * @return {boolean} 993 * @return {boolean}
956 * @this {WebInspector.CSSStyleDeclaration} 994 * @this {WebInspector.CSSStyleDeclaration}
957 */ 995 */
958 function parsePayload(error, stylePayload) 996 function onPayload(stylePayloads)
959 { 997 {
960 if (error || !stylePayload) 998 if (!stylePayloads)
961 return false; 999 return false;
962 1000 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; 1001 return true;
968 } 1002 }
969 1003
970 return this._cssModel._agent.setStyleText(this.styleSheetId, this.range. serializeToObject(), text, parsePayload.bind(this)) 1004 return this._cssModel.setStyleTexts([this.styleSheetId], [this.range], [ text], majorChange)
1005 .then(onPayload.bind(this))
971 .catchException(false); 1006 .catchException(false);
972 }, 1007 },
973 1008
974 /** 1009 /**
975 * @param {number} index 1010 * @param {number} index
976 * @param {string} name 1011 * @param {string} name
977 * @param {string} value 1012 * @param {string} value
978 * @param {function(boolean)=} userCallback 1013 * @param {function(boolean)=} userCallback
979 */ 1014 */
980 insertPropertyAt: function(index, name, value, userCallback) 1015 insertPropertyAt: function(index, name, value, userCallback)
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 * @constructor 2556 * @constructor
2522 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle 2557 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle
2523 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle 2558 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle
2524 */ 2559 */
2525 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS tyle) 2560 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS tyle)
2526 { 2561 {
2527 this.inlineStyle = inlineStyle; 2562 this.inlineStyle = inlineStyle;
2528 this.attributesStyle = attributesStyle; 2563 this.attributesStyle = attributesStyle;
2529 } 2564 }
2530 2565
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/inspector/InspectorHistory.cpp ('k') | third_party/WebKit/Source/devtools/protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698