CSSMetadata.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. /*
  2. * Copyright (C) 2010 Nikita Vasilyev. All rights reserved.
  3. * Copyright (C) 2010 Joseph Pecoraro. All rights reserved.
  4. * Copyright (C) 2010 Google Inc. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /**
  33. * @constructor
  34. * @param {Array.<CSSAgent.CSSPropertyInfo|string>} properties
  35. */
  36. WebInspector.CSSMetadata = function(properties)
  37. {
  38. this._values = /** !Array.<string> */ ([]);
  39. this._longhands = {};
  40. this._shorthands = {};
  41. for (var i = 0; i < properties.length; ++i) {
  42. var property = properties[i];
  43. if (typeof property === "string") {
  44. this._values.push(property);
  45. continue;
  46. }
  47. var propertyName = property.name;
  48. this._values.push(propertyName);
  49. var longhands = properties[i].longhands;
  50. if (longhands) {
  51. this._longhands[propertyName] = longhands;
  52. for (var j = 0; j < longhands.length; ++j) {
  53. var longhandName = longhands[j];
  54. var shorthands = this._shorthands[longhandName];
  55. if (!shorthands) {
  56. shorthands = [];
  57. this._shorthands[longhandName] = shorthands;
  58. }
  59. shorthands.push(propertyName);
  60. }
  61. }
  62. }
  63. this._values.sort();
  64. }
  65. /**
  66. * @type {!WebInspector.CSSMetadata}
  67. */
  68. WebInspector.CSSMetadata.cssPropertiesMetainfo = new WebInspector.CSSMetadata([]);
  69. WebInspector.CSSMetadata.isColorAwareProperty = function(propertyName)
  70. {
  71. return WebInspector.CSSMetadata._colorAwareProperties[propertyName] === true;
  72. }
  73. WebInspector.CSSMetadata.colors = function()
  74. {
  75. if (!WebInspector.CSSMetadata._colorsKeySet)
  76. WebInspector.CSSMetadata._colorsKeySet = WebInspector.CSSMetadata._colors.keySet();
  77. return WebInspector.CSSMetadata._colorsKeySet;
  78. }
  79. // Taken from http://www.w3.org/TR/CSS21/propidx.html.
  80. WebInspector.CSSMetadata.InheritedProperties = [
  81. "azimuth", "border-collapse", "border-spacing", "caption-side", "color", "cursor", "direction", "elevation",
  82. "empty-cells", "font-family", "font-size", "font-style", "font-variant", "font-weight", "font", "letter-spacing",
  83. "line-height", "list-style-image", "list-style-position", "list-style-type", "list-style", "orphans", "pitch-range",
  84. "pitch", "quotes", "resize", "richness", "speak-header", "speak-numeral", "speak-punctuation", "speak", "speech-rate", "stress",
  85. "text-align", "text-indent", "text-transform", "text-shadow", "visibility", "voice-family", "volume", "white-space", "widows",
  86. "word-spacing", "zoom"
  87. ].keySet();
  88. // These non-standard Blink-specific properties augment the InheritedProperties.
  89. WebInspector.CSSMetadata.NonStandardInheritedProperties = [
  90. "-webkit-font-smoothing"
  91. ].keySet();
  92. /**
  93. * @param {string} name
  94. * @return {string}
  95. */
  96. WebInspector.CSSMetadata.canonicalPropertyName = function(name)
  97. {
  98. if (!name || name.length < 9 || name.charAt(0) !== "-")
  99. return name.toLowerCase();
  100. var match = name.match(/(?:-webkit-|-khtml-|-apple-)(.+)/);
  101. if (!match)
  102. return name.toLowerCase();
  103. return match[1].toLowerCase();
  104. }
  105. /**
  106. * @param {string} propertyName
  107. * @return {boolean}
  108. */
  109. WebInspector.CSSMetadata.isPropertyInherited = function(propertyName)
  110. {
  111. return !!(WebInspector.CSSMetadata.InheritedProperties[WebInspector.CSSMetadata.canonicalPropertyName(propertyName)]
  112. || WebInspector.CSSMetadata.NonStandardInheritedProperties[propertyName.toLowerCase()]);
  113. }
  114. WebInspector.CSSMetadata._colors = [
  115. "aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red",
  116. "silver", "teal", "white", "yellow", "transparent", "currentcolor", "grey", "aliceblue", "antiquewhite",
  117. "aquamarine", "azure", "beige", "bisque", "blanchedalmond", "blueviolet", "brown", "burlywood", "cadetblue",
  118. "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan",
  119. "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange",
  120. "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkslategrey",
  121. "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "firebrick",
  122. "floralwhite", "forestgreen", "gainsboro", "ghostwhite", "gold", "goldenrod", "greenyellow", "honeydew", "hotpink",
  123. "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue",
  124. "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey", "lightpink",
  125. "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", "lightyellow",
  126. "limegreen", "linen", "magenta", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen",
  127. "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream",
  128. "mistyrose", "moccasin", "navajowhite", "oldlace", "olivedrab", "orangered", "orchid", "palegoldenrod", "palegreen",
  129. "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "rosybrown",
  130. "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "skyblue", "slateblue",
  131. "slategray", "slategrey", "snow", "springgreen", "steelblue", "tan", "thistle", "tomato", "turquoise", "violet",
  132. "wheat", "whitesmoke", "yellowgreen"
  133. ];
  134. WebInspector.CSSMetadata._colorAwareProperties = [
  135. "background", "background-color", "background-image", "border", "border-color", "border-top", "border-right", "border-bottom",
  136. "border-left", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", "box-shadow", "color",
  137. "fill", "outline", "outline-color", "stroke", "text-line-through-color", "text-overline-color",
  138. "text-shadow", "text-underline-color", "-webkit-box-shadow", "-webkit-column-rule-color",
  139. "-webkit-text-decoration-color", "-webkit-text-emphasis", "-webkit-text-emphasis-color"
  140. ].keySet();
  141. WebInspector.CSSMetadata._propertyDataMap = {
  142. "table-layout": { values: [
  143. "auto", "fixed"
  144. ] },
  145. "visibility": { values: [
  146. "hidden", "visible", "collapse"
  147. ] },
  148. "background-repeat": { values: [
  149. "repeat", "repeat-x", "repeat-y", "no-repeat", "space", "round"
  150. ] },
  151. "content": { values: [
  152. "list-item", "close-quote", "no-close-quote", "no-open-quote", "open-quote"
  153. ] },
  154. "list-style-image": { values: [
  155. "none"
  156. ] },
  157. "clear": { values: [
  158. "none", "left", "right", "both"
  159. ] },
  160. "text-underline-mode": { values: [
  161. "continuous", "skip-white-space"
  162. ] },
  163. "overflow-x": { values: [
  164. "hidden", "auto", "visible", "overlay", "scroll"
  165. ] },
  166. "stroke-linejoin": { values: [
  167. "round", "miter", "bevel"
  168. ] },
  169. "baseline-shift": { values: [
  170. "baseline", "sub", "super"
  171. ] },
  172. "border-bottom-width": { values: [
  173. "medium", "thick", "thin"
  174. ] },
  175. "marquee-speed": { values: [
  176. "normal", "slow", "fast"
  177. ] },
  178. "margin-top-collapse": { values: [
  179. "collapse", "separate", "discard"
  180. ] },
  181. "max-height": { values: [
  182. "none"
  183. ] },
  184. "box-orient": { values: [
  185. "horizontal", "vertical", "inline-axis", "block-axis"
  186. ], },
  187. "font-stretch": { values: [
  188. "normal", "wider", "narrower", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed",
  189. "semi-expanded", "expanded", "extra-expanded", "ultra-expanded"
  190. ] },
  191. "text-underline-style": { values: [
  192. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  193. ] },
  194. "text-overline-mode": { values: [
  195. "continuous", "skip-white-space"
  196. ] },
  197. "-webkit-background-composite": { values: [
  198. "highlight", "clear", "copy", "source-over", "source-in", "source-out", "source-atop", "destination-over",
  199. "destination-in", "destination-out", "destination-atop", "xor", "plus-darker", "plus-lighter"
  200. ] },
  201. "border-left-width": { values: [
  202. "medium", "thick", "thin"
  203. ] },
  204. "-webkit-writing-mode": { values: [
  205. "lr", "rl", "tb", "lr-tb", "rl-tb", "tb-rl", "horizontal-tb", "vertical-rl", "vertical-lr", "horizontal-bt"
  206. ] },
  207. "text-line-through-mode": { values: [
  208. "continuous", "skip-white-space"
  209. ] },
  210. "border-collapse": { values: [
  211. "collapse", "separate"
  212. ] },
  213. "page-break-inside": { values: [
  214. "auto", "avoid"
  215. ] },
  216. "border-top-width": { values: [
  217. "medium", "thick", "thin"
  218. ] },
  219. "outline-color": { values: [
  220. "invert"
  221. ] },
  222. "text-line-through-style": { values: [
  223. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  224. ] },
  225. "outline-style": { values: [
  226. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  227. ] },
  228. "cursor": { values: [
  229. "none", "copy", "auto", "crosshair", "default", "pointer", "move", "vertical-text", "cell", "context-menu",
  230. "alias", "progress", "no-drop", "not-allowed", "-webkit-zoom-in", "-webkit-zoom-out", "e-resize", "ne-resize",
  231. "nw-resize", "n-resize", "se-resize", "sw-resize", "s-resize", "w-resize", "ew-resize", "ns-resize",
  232. "nesw-resize", "nwse-resize", "col-resize", "row-resize", "text", "wait", "help", "all-scroll", "-webkit-grab",
  233. "-webkit-grabbing"
  234. ] },
  235. "border-width": { values: [
  236. "medium", "thick", "thin"
  237. ] },
  238. "size": { values: [
  239. "a3", "a4", "a5", "b4", "b5", "landscape", "ledger", "legal", "letter", "portrait"
  240. ] },
  241. "background-size": { values: [
  242. "contain", "cover"
  243. ] },
  244. "direction": { values: [
  245. "ltr", "rtl"
  246. ] },
  247. "marquee-direction": { values: [
  248. "left", "right", "auto", "reverse", "forwards", "backwards", "ahead", "up", "down"
  249. ] },
  250. "enable-background": { values: [
  251. "accumulate", "new"
  252. ] },
  253. "float": { values: [
  254. "none", "left", "right"
  255. ] },
  256. "overflow-y": { values: [
  257. "hidden", "auto", "visible", "overlay", "scroll"
  258. ] },
  259. "margin-bottom-collapse": { values: [
  260. "collapse", "separate", "discard"
  261. ] },
  262. "box-reflect": { values: [
  263. "left", "right", "above", "below"
  264. ] },
  265. "overflow": { values: [
  266. "hidden", "auto", "visible", "overlay", "scroll"
  267. ] },
  268. "text-rendering": { values: [
  269. "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision"
  270. ] },
  271. "text-align": { values: [
  272. "-webkit-auto", "start", "end", "left", "right", "center", "justify", "-webkit-left", "-webkit-right", "-webkit-center"
  273. ] },
  274. "list-style-position": { values: [
  275. "outside", "inside", "hanging"
  276. ] },
  277. "margin-bottom": { values: [
  278. "auto"
  279. ] },
  280. "color-interpolation": { values: [
  281. "linearrgb"
  282. ] },
  283. "background-origin": { values: [
  284. "border-box", "content-box", "padding-box"
  285. ] },
  286. "word-wrap": { values: [
  287. "normal", "break-word"
  288. ] },
  289. "font-weight": { values: [
  290. "normal", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900"
  291. ] },
  292. "margin-before-collapse": { values: [
  293. "collapse", "separate", "discard"
  294. ] },
  295. "text-overline-width": { values: [
  296. "normal", "medium", "auto", "thick", "thin"
  297. ] },
  298. "text-transform": { values: [
  299. "none", "capitalize", "uppercase", "lowercase"
  300. ] },
  301. "border-right-style": { values: [
  302. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  303. ] },
  304. "border-left-style": { values: [
  305. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  306. ] },
  307. "-webkit-text-emphasis": { values: [
  308. "circle", "filled", "open", "dot", "double-circle", "triangle", "sesame"
  309. ] },
  310. "font-style": { values: [
  311. "italic", "oblique", "normal"
  312. ] },
  313. "speak": { values: [
  314. "none", "normal", "spell-out", "digits", "literal-punctuation", "no-punctuation"
  315. ] },
  316. "color-rendering": { values: [
  317. "auto", "optimizeSpeed", "optimizeQuality"
  318. ] },
  319. "list-style-type": { values: [
  320. "none", "inline", "disc", "circle", "square", "decimal", "decimal-leading-zero", "arabic-indic", "binary", "bengali",
  321. "cambodian", "khmer", "devanagari", "gujarati", "gurmukhi", "kannada", "lower-hexadecimal", "lao", "malayalam",
  322. "mongolian", "myanmar", "octal", "oriya", "persian", "urdu", "telugu", "tibetan", "thai", "upper-hexadecimal",
  323. "lower-roman", "upper-roman", "lower-greek", "lower-alpha", "lower-latin", "upper-alpha", "upper-latin", "afar",
  324. "ethiopic-halehame-aa-et", "ethiopic-halehame-aa-er", "amharic", "ethiopic-halehame-am-et", "amharic-abegede",
  325. "ethiopic-abegede-am-et", "cjk-earthly-branch", "cjk-heavenly-stem", "ethiopic", "ethiopic-halehame-gez",
  326. "ethiopic-abegede", "ethiopic-abegede-gez", "hangul-consonant", "hangul", "lower-norwegian", "oromo",
  327. "ethiopic-halehame-om-et", "sidama", "ethiopic-halehame-sid-et", "somali", "ethiopic-halehame-so-et", "tigre",
  328. "ethiopic-halehame-tig", "tigrinya-er", "ethiopic-halehame-ti-er", "tigrinya-er-abegede",
  329. "ethiopic-abegede-ti-er", "tigrinya-et", "ethiopic-halehame-ti-et", "tigrinya-et-abegede",
  330. "ethiopic-abegede-ti-et", "upper-greek", "upper-norwegian", "asterisks", "footnotes", "hebrew", "armenian",
  331. "lower-armenian", "upper-armenian", "georgian", "cjk-ideographic", "hiragana", "katakana", "hiragana-iroha",
  332. "katakana-iroha"
  333. ] },
  334. "-webkit-text-combine": { values: [
  335. "none", "horizontal"
  336. ] },
  337. "outline": { values: [
  338. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  339. ] },
  340. "font": { values: [
  341. "caption", "icon", "menu", "message-box", "small-caption", "-webkit-mini-control", "-webkit-small-control",
  342. "-webkit-control", "status-bar", "italic", "oblique", "small-caps", "normal", "bold", "bolder", "lighter",
  343. "100", "200", "300", "400", "500", "600", "700", "800", "900", "xx-small", "x-small", "small", "medium",
  344. "large", "x-large", "xx-large", "-webkit-xxx-large", "smaller", "larger", "serif", "sans-serif", "cursive",
  345. "fantasy", "monospace", "-webkit-body", "-webkit-pictograph"
  346. ] },
  347. "dominant-baseline": { values: [
  348. "middle", "auto", "central", "text-before-edge", "text-after-edge", "ideographic", "alphabetic", "hanging",
  349. "mathematical", "use-script", "no-change", "reset-size"
  350. ] },
  351. "display": { values: [
  352. "none", "inline", "block", "list-item", "run-in", "compact", "inline-block", "table", "inline-table",
  353. "table-row-group", "table-header-group", "table-footer-group", "table-row", "table-column-group",
  354. "table-column", "table-cell", "table-caption", "-webkit-box", "-webkit-inline-box",
  355. "-webkit-flex", "-webkit-inline-flex", "-webkit-grid", "-webkit-inline-grid", "-wap-marquee"
  356. ] },
  357. "-webkit-text-emphasis-position": { values: [
  358. "over", "under"
  359. ] },
  360. "image-rendering": { values: [
  361. "auto", "optimizeSpeed", "optimizeQuality"
  362. ] },
  363. "alignment-baseline": { values: [
  364. "baseline", "middle", "auto", "before-edge", "after-edge", "central", "text-before-edge", "text-after-edge",
  365. "ideographic", "alphabetic", "hanging", "mathematical"
  366. ] },
  367. "outline-width": { values: [
  368. "medium", "thick", "thin"
  369. ] },
  370. "text-line-through-width": { values: [
  371. "normal", "medium", "auto", "thick", "thin"
  372. ] },
  373. "box-align": { values: [
  374. "baseline", "center", "stretch", "start", "end"
  375. ] },
  376. "border-right-width": { values: [
  377. "medium", "thick", "thin"
  378. ] },
  379. "border-top-style": { values: [
  380. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  381. ] },
  382. "line-height": { values: [
  383. "normal"
  384. ] },
  385. "text-overflow": { values: [
  386. "clip", "ellipsis"
  387. ] },
  388. "overflow-wrap": { values: [
  389. "normal", "break-word"
  390. ] },
  391. "box-direction": { values: [
  392. "normal", "reverse"
  393. ] },
  394. "margin-after-collapse": { values: [
  395. "collapse", "separate", "discard"
  396. ] },
  397. "page-break-before": { values: [
  398. "left", "right", "auto", "always", "avoid"
  399. ] },
  400. "-webkit-hyphens": { values: [
  401. "none", "auto", "manual"
  402. ] },
  403. "border-image": { values: [
  404. "repeat", "stretch"
  405. ] },
  406. "text-decoration": { values: [
  407. "blink", "line-through", "overline", "underline"
  408. ] },
  409. "position": { values: [
  410. "absolute", "fixed", "relative", "static"
  411. ] },
  412. "font-family": { values: [
  413. "serif", "sans-serif", "cursive", "fantasy", "monospace", "-webkit-body", "-webkit-pictograph"
  414. ] },
  415. "text-overflow-mode": { values: [
  416. "clip", "ellipsis"
  417. ] },
  418. "border-bottom-style": { values: [
  419. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  420. ] },
  421. "unicode-bidi": { values: [
  422. "normal", "bidi-override", "embed"
  423. ] },
  424. "clip-rule": { values: [
  425. "nonzero", "evenodd"
  426. ] },
  427. "margin-left": { values: [
  428. "auto"
  429. ] },
  430. "margin-top": { values: [
  431. "auto"
  432. ] },
  433. "zoom": { values: [
  434. "normal", "document", "reset"
  435. ] },
  436. "text-overline-style": { values: [
  437. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  438. ] },
  439. "max-width": { values: [
  440. "none"
  441. ] },
  442. "caption-side": { values: [
  443. "top", "bottom"
  444. ] },
  445. "empty-cells": { values: [
  446. "hide", "show"
  447. ] },
  448. "pointer-events": { values: [
  449. "none", "all", "auto", "visible", "visiblepainted", "visiblefill", "visiblestroke", "painted", "fill", "stroke"
  450. ] },
  451. "letter-spacing": { values: [
  452. "normal"
  453. ] },
  454. "background-clip": { values: [
  455. "border-box", "content-box", "padding-box"
  456. ] },
  457. "-webkit-font-smoothing": { values: [
  458. "none", "auto", "antialiased", "subpixel-antialiased"
  459. ] },
  460. "border": { values: [
  461. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  462. ] },
  463. "font-size": { values: [
  464. "xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "-webkit-xxx-large", "smaller",
  465. "larger"
  466. ] },
  467. "font-variant": { values: [
  468. "small-caps", "normal"
  469. ] },
  470. "vertical-align": { values: [
  471. "baseline", "middle", "sub", "super", "text-top", "text-bottom", "top", "bottom", "-webkit-baseline-middle"
  472. ] },
  473. "marquee-style": { values: [
  474. "none", "scroll", "slide", "alternate"
  475. ] },
  476. "white-space": { values: [
  477. "normal", "nowrap", "pre", "pre-line", "pre-wrap"
  478. ] },
  479. "text-underline-width": { values: [
  480. "normal", "medium", "auto", "thick", "thin"
  481. ] },
  482. "box-lines": { values: [
  483. "single", "multiple"
  484. ] },
  485. "page-break-after": { values: [
  486. "left", "right", "auto", "always", "avoid"
  487. ] },
  488. "clip-path": { values: [
  489. "none"
  490. ] },
  491. "margin": { values: [
  492. "auto"
  493. ] },
  494. "marquee-repetition": { values: [
  495. "infinite"
  496. ] },
  497. "margin-right": { values: [
  498. "auto"
  499. ] },
  500. "word-break": { values: [
  501. "normal", "break-all", "break-word"
  502. ] },
  503. "word-spacing": { values: [
  504. "normal"
  505. ] },
  506. "-webkit-text-emphasis-style": { values: [
  507. "circle", "filled", "open", "dot", "double-circle", "triangle", "sesame"
  508. ] },
  509. "-webkit-transform": { values: [
  510. "scale", "scaleX", "scaleY", "scale3d", "rotate", "rotateX", "rotateY", "rotateZ", "rotate3d", "skew", "skewX", "skewY",
  511. "translate", "translateX", "translateY", "translateZ", "translate3d", "matrix", "matrix3d", "perspective"
  512. ] },
  513. "image-resolution": { values: [
  514. "from-image", "snap"
  515. ] },
  516. "box-sizing": { values: [
  517. "content-box", "padding-box", "border-box"
  518. ] },
  519. "clip": { values: [
  520. "auto"
  521. ] },
  522. "resize": { values: [
  523. "none", "both", "horizontal", "vertical"
  524. ] },
  525. "-webkit-align-content": { values: [
  526. "flex-start", "flex-end", "center", "space-between", "space-around", "stretch"
  527. ] },
  528. "-webkit-align-items": { values: [
  529. "flex-start", "flex-end", "center", "baseline", "stretch"
  530. ] },
  531. "-webkit-align-self": { values: [
  532. "auto", "flex-start", "flex-end", "center", "baseline", "stretch"
  533. ] },
  534. "-webkit-flex-direction": { values: [
  535. "row", "row-reverse", "column", "column-reverse"
  536. ] },
  537. "-webkit-justify-content": { values: [
  538. "flex-start", "flex-end", "center", "space-between", "space-around"
  539. ] },
  540. "-webkit-flex-wrap": { values: [
  541. "nowrap", "wrap", "wrap-reverse"
  542. ] },
  543. "-webkit-animation-timing-function": { values: [
  544. "ease", "linear", "ease-in", "ease-out", "ease-in-out", "step-start", "step-end", "steps", "cubic-bezier"
  545. ] },
  546. "-webkit-animation-direction": { values: [
  547. "normal", "reverse", "alternate", "alternate-reverse"
  548. ] },
  549. "-webkit-animation-play-state": { values: [
  550. "running", "paused"
  551. ] },
  552. "-webkit-animation-fill-mode": { values: [
  553. "none", "forwards", "backwards", "both"
  554. ] },
  555. "-webkit-backface-visibility": { values: [
  556. "visible", "hidden"
  557. ] },
  558. "-webkit-box-decoration-break": { values: [
  559. "slice", "clone"
  560. ] },
  561. "-webkit-column-break-after": { values: [
  562. "auto", "always", "avoid", "left", "right", "page", "column", "avoid-page", "avoid-column"
  563. ] },
  564. "-webkit-column-break-before": { values: [
  565. "auto", "always", "avoid", "left", "right", "page", "column", "avoid-page", "avoid-column"
  566. ] },
  567. "-webkit-column-break-inside": { values: [
  568. "auto", "avoid", "avoid-page", "avoid-column"
  569. ] },
  570. "-webkit-column-span": { values: [
  571. "none", "all"
  572. ] },
  573. "-webkit-column-count": { values: [
  574. "auto"
  575. ] },
  576. "-webkit-column-gap": { values: [
  577. "normal"
  578. ] },
  579. "-webkit-line-break": { values: [
  580. "auto", "loose", "normal", "strict"
  581. ] },
  582. "-webkit-perspective": { values: [
  583. "none"
  584. ] },
  585. "-webkit-perspective-origin": { values: [
  586. "left", "center", "right", "top", "bottom"
  587. ] },
  588. "-webkit-text-align-last": { values: [
  589. "auto", "start", "end", "left", "right", "center", "justify"
  590. ] },
  591. "-webkit-text-decoration-line": { values: [
  592. "none", "underline", "overline", "line-through", "blink"
  593. ] },
  594. "-webkit-text-decoration-style": { values: [
  595. "solid", "double", "dotted", "dashed", "wavy"
  596. ] },
  597. "-webkit-text-decoration-skip": { values: [
  598. "none", "objects", "spaces", "ink", "edges", "box-decoration"
  599. ] },
  600. "-webkit-transform-origin": { values: [
  601. "left", "center", "right", "top", "bottom"
  602. ] },
  603. "-webkit-transform-style": { values: [
  604. "flat", "preserve-3d"
  605. ] },
  606. "-webkit-transition-timing-function": { values: [
  607. "ease", "linear", "ease-in", "ease-out", "ease-in-out", "step-start", "step-end", "steps", "cubic-bezier"
  608. ] },
  609. "-webkit-flex": { m: "flexbox" },
  610. "-webkit-flex-basis": { m: "flexbox" },
  611. "-webkit-flex-flow": { m: "flexbox" },
  612. "-webkit-flex-grow": { m: "flexbox" },
  613. "-webkit-flex-shrink": { m: "flexbox" },
  614. "-webkit-animation": { m: "animations" },
  615. "-webkit-animation-delay": { m: "animations" },
  616. "-webkit-animation-duration": { m: "animations" },
  617. "-webkit-animation-iteration-count": { m: "animations" },
  618. "-webkit-animation-name": { m: "animations" },
  619. "-webkit-column-rule": { m: "multicol" },
  620. "-webkit-column-rule-color": { m: "multicol", a: "crc" },
  621. "-webkit-column-rule-style": { m: "multicol", a: "crs" },
  622. "-webkit-column-rule-width": { m: "multicol", a: "crw" },
  623. "-webkit-column-width": { m: "multicol", a: "cw" },
  624. "-webkit-columns": { m: "multicol" },
  625. "-webkit-grid-columns": { m: "grid" },
  626. "-webkit-grid-rows": { m: "grid" },
  627. "-webkit-order": { m: "flexbox" },
  628. "-webkit-text-decoration-color": { m: "text-decor" },
  629. "-webkit-text-emphasis-color": { m: "text-decor" },
  630. "-webkit-transition": { m: "transitions" },
  631. "-webkit-transition-delay": { m: "transitions" },
  632. "-webkit-transition-duration": { m: "transitions" },
  633. "-webkit-transition-property": { m: "transitions" },
  634. "background": { m: "background" },
  635. "background-attachment": { m: "background" },
  636. "background-color": { m: "background" },
  637. "background-image": { m: "background" },
  638. "background-position": { m: "background" },
  639. "background-position-x": { m: "background" },
  640. "background-position-y": { m: "background" },
  641. "background-repeat-x": { m: "background" },
  642. "background-repeat-y": { m: "background" },
  643. "border-top": { m: "background" },
  644. "border-right": { m: "background" },
  645. "border-bottom": { m: "background" },
  646. "border-left": { m: "background" },
  647. "border-radius": { m: "background" },
  648. "bottom": { m: "visuren" },
  649. "box-shadow": { m: "background" },
  650. "color": { m: "color", a: "foreground" },
  651. "counter-increment": { m: "generate" },
  652. "counter-reset": { m: "generate" },
  653. "height": { m: "box" },
  654. "image-orientation": { m: "images" },
  655. "left": { m: "visuren" },
  656. "list-style": { m: "lists" },
  657. "min-height": { m: "box" },
  658. "min-width": { m: "box" },
  659. "opacity": { m: "color", a: "transparency" },
  660. "orphans": { m: "page" },
  661. "outline-offset": { m: "ui" },
  662. "padding": { m: "box", a: "padding1" },
  663. "padding-bottom": { m: "box" },
  664. "padding-left": { m: "box" },
  665. "padding-right": { m: "box" },
  666. "padding-top": { m: "box" },
  667. "page": { m: "page" },
  668. "quotes": { m: "generate" },
  669. "right": { m: "visuren" },
  670. "tab-size": { m: "text" },
  671. "text-indent": { m: "text" },
  672. "text-shadow": { m: "text-decor" },
  673. "top": { m: "visuren" },
  674. "unicode-range": { m: "fonts", a: "descdef-unicode-range" },
  675. "widows": { m: "page" },
  676. "width": { m: "box" },
  677. "z-index": { m: "visuren" }
  678. }
  679. /**
  680. * @param {string} propertyName
  681. * @return {!WebInspector.CSSMetadata}
  682. */
  683. WebInspector.CSSMetadata.keywordsForProperty = function(propertyName)
  684. {
  685. var acceptedKeywords = ["inherit", "initial"];
  686. var descriptor = WebInspector.CSSMetadata.descriptor(propertyName);
  687. if (descriptor && descriptor.values)
  688. acceptedKeywords.push.apply(acceptedKeywords, descriptor.values);
  689. if (propertyName in WebInspector.CSSMetadata._colorAwareProperties)
  690. acceptedKeywords.push.apply(acceptedKeywords, WebInspector.CSSMetadata._colors);
  691. return new WebInspector.CSSMetadata(acceptedKeywords);
  692. }
  693. /**
  694. * @param {string} propertyName
  695. * @return {Object}
  696. */
  697. WebInspector.CSSMetadata.descriptor = function(propertyName)
  698. {
  699. if (!propertyName)
  700. return null;
  701. var unprefixedName = propertyName.replace(/^-webkit-/, "");
  702. var entry = WebInspector.CSSMetadata._propertyDataMap[propertyName];
  703. if (!entry && unprefixedName !== propertyName)
  704. entry = WebInspector.CSSMetadata._propertyDataMap[unprefixedName];
  705. return entry || null;
  706. }
  707. WebInspector.CSSMetadata.requestCSSShorthandData = function()
  708. {
  709. function propertyNamesCallback(error, properties)
  710. {
  711. if (!error)
  712. WebInspector.CSSMetadata.cssPropertiesMetainfo = new WebInspector.CSSMetadata(properties);
  713. }
  714. CSSAgent.getSupportedCSSProperties(propertyNamesCallback);
  715. }
  716. WebInspector.CSSMetadata.cssPropertiesMetainfoKeySet = function()
  717. {
  718. if (!WebInspector.CSSMetadata._cssPropertiesMetainfoKeySet)
  719. WebInspector.CSSMetadata._cssPropertiesMetainfoKeySet = WebInspector.CSSMetadata.cssPropertiesMetainfo.keySet();
  720. return WebInspector.CSSMetadata._cssPropertiesMetainfoKeySet;
  721. }
  722. // Weight of CSS properties based their usage on few popular websites https://gist.github.com/3751436
  723. WebInspector.CSSMetadata.Weight = {
  724. "-webkit-animation": 1,
  725. "-webkit-animation-duration": 1,
  726. "-webkit-animation-iteration-count": 1,
  727. "-webkit-animation-name": 1,
  728. "-webkit-animation-timing-function": 1,
  729. "-webkit-appearance": 1,
  730. "-webkit-background-clip": 2,
  731. "-webkit-border-horizontal-spacing": 1,
  732. "-webkit-border-vertical-spacing": 1,
  733. "-webkit-box-shadow": 24,
  734. "-webkit-font-smoothing": 2,
  735. "-webkit-transform": 1,
  736. "-webkit-transition": 8,
  737. "-webkit-transition-delay": 7,
  738. "-webkit-transition-duration": 7,
  739. "-webkit-transition-property": 7,
  740. "-webkit-transition-timing-function": 6,
  741. "-webkit-user-select": 1,
  742. "background": 222,
  743. "background-attachment": 144,
  744. "background-clip": 143,
  745. "background-color": 222,
  746. "background-image": 201,
  747. "background-origin": 142,
  748. "background-size": 25,
  749. "border": 121,
  750. "border-bottom": 121,
  751. "border-bottom-color": 121,
  752. "border-bottom-left-radius": 50,
  753. "border-bottom-right-radius": 50,
  754. "border-bottom-style": 114,
  755. "border-bottom-width": 120,
  756. "border-collapse": 3,
  757. "border-left": 95,
  758. "border-left-color": 95,
  759. "border-left-style": 89,
  760. "border-left-width": 94,
  761. "border-radius": 50,
  762. "border-right": 93,
  763. "border-right-color": 93,
  764. "border-right-style": 88,
  765. "border-right-width": 93,
  766. "border-top": 111,
  767. "border-top-color": 111,
  768. "border-top-left-radius": 49,
  769. "border-top-right-radius": 49,
  770. "border-top-style": 104,
  771. "border-top-width": 109,
  772. "bottom": 16,
  773. "box-shadow": 25,
  774. "box-sizing": 2,
  775. "clear": 23,
  776. "color": 237,
  777. "cursor": 34,
  778. "direction": 4,
  779. "display": 210,
  780. "fill": 2,
  781. "filter": 1,
  782. "float": 105,
  783. "font": 174,
  784. "font-family": 25,
  785. "font-size": 174,
  786. "font-style": 9,
  787. "font-weight": 89,
  788. "height": 161,
  789. "left": 54,
  790. "letter-spacing": 3,
  791. "line-height": 75,
  792. "list-style": 17,
  793. "list-style-image": 8,
  794. "list-style-position": 8,
  795. "list-style-type": 17,
  796. "margin": 241,
  797. "margin-bottom": 226,
  798. "margin-left": 225,
  799. "margin-right": 213,
  800. "margin-top": 241,
  801. "max-height": 5,
  802. "max-width": 11,
  803. "min-height": 9,
  804. "min-width": 6,
  805. "opacity": 24,
  806. "outline": 10,
  807. "outline-color": 10,
  808. "outline-style": 10,
  809. "outline-width": 10,
  810. "overflow": 57,
  811. "overflow-x": 56,
  812. "overflow-y": 57,
  813. "padding": 216,
  814. "padding-bottom": 208,
  815. "padding-left": 216,
  816. "padding-right": 206,
  817. "padding-top": 216,
  818. "position": 136,
  819. "resize": 1,
  820. "right": 29,
  821. "stroke": 1,
  822. "stroke-width": 1,
  823. "table-layout": 1,
  824. "text-align": 66,
  825. "text-decoration": 53,
  826. "text-indent": 9,
  827. "text-overflow": 8,
  828. "text-shadow": 19,
  829. "text-transform": 5,
  830. "top": 71,
  831. "unicode-bidi": 1,
  832. "vertical-align": 37,
  833. "visibility": 11,
  834. "white-space": 24,
  835. "width": 255,
  836. "word-wrap": 6,
  837. "z-index": 32,
  838. "zoom": 10
  839. };
  840. WebInspector.CSSMetadata.prototype = {
  841. /**
  842. * @param {string} prefix
  843. * @return {!Array.<string>}
  844. */
  845. startsWith: function(prefix)
  846. {
  847. var firstIndex = this._firstIndexOfPrefix(prefix);
  848. if (firstIndex === -1)
  849. return [];
  850. var results = [];
  851. while (firstIndex < this._values.length && this._values[firstIndex].startsWith(prefix))
  852. results.push(this._values[firstIndex++]);
  853. return results;
  854. },
  855. /**
  856. * @param {Array.<string>} properties
  857. * @return {number}
  858. */
  859. mostUsedOf: function(properties)
  860. {
  861. var maxWeight = 0;
  862. var index = 0;
  863. for (var i = 0; i < properties.length; i++) {
  864. var weight = WebInspector.CSSMetadata.Weight[properties[i]];
  865. if (weight > maxWeight) {
  866. maxWeight = weight;
  867. index = i;
  868. }
  869. }
  870. return index;
  871. },
  872. _firstIndexOfPrefix: function(prefix)
  873. {
  874. if (!this._values.length)
  875. return -1;
  876. if (!prefix)
  877. return 0;
  878. var maxIndex = this._values.length - 1;
  879. var minIndex = 0;
  880. var foundIndex;
  881. do {
  882. var middleIndex = (maxIndex + minIndex) >> 1;
  883. if (this._values[middleIndex].startsWith(prefix)) {
  884. foundIndex = middleIndex;
  885. break;
  886. }
  887. if (this._values[middleIndex] < prefix)
  888. minIndex = middleIndex + 1;
  889. else
  890. maxIndex = middleIndex - 1;
  891. } while (minIndex <= maxIndex);
  892. if (foundIndex === undefined)
  893. return -1;
  894. while (foundIndex && this._values[foundIndex - 1].startsWith(prefix))
  895. foundIndex--;
  896. return foundIndex;
  897. },
  898. keySet: function()
  899. {
  900. if (!this._keySet)
  901. this._keySet = this._values.keySet();
  902. return this._keySet;
  903. },
  904. next: function(str, prefix)
  905. {
  906. return this._closest(str, prefix, 1);
  907. },
  908. previous: function(str, prefix)
  909. {
  910. return this._closest(str, prefix, -1);
  911. },
  912. _closest: function(str, prefix, shift)
  913. {
  914. if (!str)
  915. return "";
  916. var index = this._values.indexOf(str);
  917. if (index === -1)
  918. return "";
  919. if (!prefix) {
  920. index = (index + this._values.length + shift) % this._values.length;
  921. return this._values[index];
  922. }
  923. var propertiesWithPrefix = this.startsWith(prefix);
  924. var j = propertiesWithPrefix.indexOf(str);
  925. j = (j + propertiesWithPrefix.length + shift) % propertiesWithPrefix.length;
  926. return propertiesWithPrefix[j];
  927. },
  928. /**
  929. * @param {string} shorthand
  930. * @return {?Array.<string>}
  931. */
  932. longhands: function(shorthand)
  933. {
  934. return this._longhands[shorthand];
  935. },
  936. /**
  937. * @param {string} longhand
  938. * @return {?Array.<string>}
  939. */
  940. shorthands: function(longhand)
  941. {
  942. return this._shorthands[longhand];
  943. }
  944. }