styles.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const {
  6. Arg,
  7. Option,
  8. RetVal,
  9. generateActorSpec,
  10. types
  11. } = require("devtools/shared/protocol");
  12. require("devtools/shared/specs/node");
  13. require("devtools/shared/specs/stylesheets");
  14. // Predeclare the domstylerule actor type
  15. types.addActorType("domstylerule");
  16. /**
  17. * DOM Nodes returned by the style actor will be owned by the DOM walker
  18. * for the connection.
  19. */
  20. types.addLifetime("walker", "walker");
  21. /**
  22. * When asking for the styles applied to a node, we return a list of
  23. * appliedstyle json objects that lists the rules that apply to the node
  24. * and which element they were inherited from (if any).
  25. *
  26. * Note appliedstyle only sends the list of actorIDs and is not a valid return
  27. * value on its own. appliedstyle should be returned with the actual list of
  28. * StyleRuleActor and StyleSheetActor. See appliedStylesReturn.
  29. */
  30. types.addDictType("appliedstyle", {
  31. rule: "domstylerule#actorid",
  32. inherited: "nullable:domnode#actorid",
  33. keyframes: "nullable:domstylerule#actorid"
  34. });
  35. types.addDictType("matchedselector", {
  36. rule: "domstylerule#actorid",
  37. selector: "string",
  38. value: "string",
  39. status: "number"
  40. });
  41. types.addDictType("appliedStylesReturn", {
  42. entries: "array:appliedstyle",
  43. rules: "array:domstylerule",
  44. sheets: "array:stylesheet"
  45. });
  46. types.addDictType("modifiedStylesReturn", {
  47. isMatching: RetVal("boolean"),
  48. ruleProps: RetVal("nullable:appliedStylesReturn")
  49. });
  50. types.addDictType("fontpreview", {
  51. data: "nullable:longstring",
  52. size: "json"
  53. });
  54. types.addDictType("fontface", {
  55. name: "string",
  56. CSSFamilyName: "string",
  57. rule: "nullable:domstylerule",
  58. srcIndex: "number",
  59. URI: "string",
  60. format: "string",
  61. preview: "nullable:fontpreview",
  62. localName: "string",
  63. metadata: "string"
  64. });
  65. const pageStyleSpec = generateActorSpec({
  66. typeName: "pagestyle",
  67. events: {
  68. "stylesheet-updated": {
  69. type: "styleSheetUpdated",
  70. styleSheet: Arg(0, "stylesheet")
  71. }
  72. },
  73. methods: {
  74. getComputed: {
  75. request: {
  76. node: Arg(0, "domnode"),
  77. markMatched: Option(1, "boolean"),
  78. onlyMatched: Option(1, "boolean"),
  79. filter: Option(1, "string"),
  80. },
  81. response: {
  82. computed: RetVal("json")
  83. }
  84. },
  85. getAllUsedFontFaces: {
  86. request: {
  87. includePreviews: Option(0, "boolean"),
  88. previewText: Option(0, "string"),
  89. previewFontSize: Option(0, "string"),
  90. previewFillStyle: Option(0, "string")
  91. },
  92. response: {
  93. fontFaces: RetVal("array:fontface")
  94. }
  95. },
  96. getUsedFontFaces: {
  97. request: {
  98. node: Arg(0, "domnode"),
  99. includePreviews: Option(1, "boolean"),
  100. previewText: Option(1, "string"),
  101. previewFontSize: Option(1, "string"),
  102. previewFillStyle: Option(1, "string")
  103. },
  104. response: {
  105. fontFaces: RetVal("array:fontface")
  106. }
  107. },
  108. getMatchedSelectors: {
  109. request: {
  110. node: Arg(0, "domnode"),
  111. property: Arg(1, "string"),
  112. filter: Option(2, "string")
  113. },
  114. response: RetVal(types.addDictType("matchedselectorresponse", {
  115. rules: "array:domstylerule",
  116. sheets: "array:stylesheet",
  117. matched: "array:matchedselector"
  118. }))
  119. },
  120. getApplied: {
  121. request: {
  122. node: Arg(0, "domnode"),
  123. inherited: Option(1, "boolean"),
  124. matchedSelectors: Option(1, "boolean"),
  125. filter: Option(1, "string")
  126. },
  127. response: RetVal("appliedStylesReturn")
  128. },
  129. isPositionEditable: {
  130. request: { node: Arg(0, "domnode")},
  131. response: { value: RetVal("boolean") }
  132. },
  133. getLayout: {
  134. request: {
  135. node: Arg(0, "domnode"),
  136. autoMargins: Option(1, "boolean")
  137. },
  138. response: RetVal("json")
  139. },
  140. addNewRule: {
  141. request: {
  142. node: Arg(0, "domnode"),
  143. pseudoClasses: Arg(1, "nullable:array:string"),
  144. editAuthored: Arg(2, "boolean")
  145. },
  146. response: RetVal("appliedStylesReturn")
  147. }
  148. }
  149. });
  150. exports.pageStyleSpec = pageStyleSpec;
  151. const styleRuleSpec = generateActorSpec({
  152. typeName: "domstylerule",
  153. events: {
  154. "location-changed": {
  155. type: "locationChanged",
  156. line: Arg(0, "number"),
  157. column: Arg(1, "number")
  158. },
  159. },
  160. methods: {
  161. setRuleText: {
  162. request: { modification: Arg(0, "string") },
  163. response: { rule: RetVal("domstylerule") }
  164. },
  165. modifyProperties: {
  166. request: { modifications: Arg(0, "array:json") },
  167. response: { rule: RetVal("domstylerule") }
  168. },
  169. modifySelector: {
  170. request: { selector: Arg(0, "string") },
  171. response: { isModified: RetVal("boolean") },
  172. },
  173. modifySelector2: {
  174. request: {
  175. node: Arg(0, "domnode"),
  176. value: Arg(1, "string"),
  177. editAuthored: Arg(2, "boolean")
  178. },
  179. response: RetVal("modifiedStylesReturn")
  180. }
  181. }
  182. });
  183. exports.styleRuleSpec = styleRuleSpec;
  184. // The PageStyle actor flattens the DOM CSS objects a little bit, merging
  185. // Rules and their Styles into one actor. For elements (which have a style
  186. // but no associated rule) we fake a rule with the following style id.
  187. const ELEMENT_STYLE = 100;
  188. exports.ELEMENT_STYLE = ELEMENT_STYLE;