nsIXULTemplateBuilder.idl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "domstubs.idl"
  6. interface nsIAtom;
  7. interface nsIContent;
  8. interface nsIXULBuilderListener;
  9. interface nsIXULTemplateResult;
  10. interface nsIXULTemplateRuleFilter;
  11. interface nsIXULTemplateQueryProcessor;
  12. interface nsIRDFResource;
  13. interface nsIRDFCompositeDataSource;
  14. interface nsIDOMDataTransfer;
  15. /**
  16. * A template builder, given an input source of data, a template, and a
  17. * reference point, generates a list of results from the input, and copies
  18. * part of the template for each result. Templates may generate content
  19. * recursively, using the same template, but with the previous iteration's
  20. * results as the reference point. As an example, for an XML datasource the
  21. * initial reference point would be a specific node in the DOM tree and a
  22. * template might generate a list of all child nodes. For the next iteration,
  23. * those children would be used to generate output for their child nodes and
  24. * so forth.
  25. *
  26. * A template builder is attached to a single DOM node; this node is called
  27. * the root node and is expected to contain a XUL template element as a direct
  28. * child. Different template builders may be specialized in the manner in
  29. * which they generate and display the resulting content from the template.
  30. *
  31. * The structure of a template is as follows:
  32. *
  33. * <rootnode datasources="" ref="">
  34. * <template>
  35. * <queryset>
  36. * <query>
  37. * </query>
  38. * <rule>
  39. * <conditions>...</conditions>
  40. * <bindings>...</bindings>
  41. * <action>...</action>
  42. * </rule>
  43. * </queryset>
  44. * </template>
  45. * </rootnode>
  46. *
  47. * The datasources attribute on the root node is used to identify the source
  48. * of data to be used. The ref attribute is used to specify the reference
  49. * point for the query. Currently, the datasource will either be an
  50. * nsIRDFDataSource or a DOM node. In the future, other datasource types may
  51. * be used.
  52. *
  53. * The <queryset> element contains a single query and one or more <rule>
  54. * elements. There may be more than one <queryset> if multiple queries are
  55. * desired, and this element is optional if only one query is needed -- in
  56. * that case the <query> and <rule>s are allowed to be children of the
  57. * <template> node
  58. *
  59. * The contents of the query are processed by a separate component called a
  60. * query processor. This query processor is expected to use this query to
  61. * generate results when asked by the template builder. The template builder
  62. * then generates output for each result based on the <rule> elements.
  63. *
  64. * This allows the query processor to be specific to a particular kind of
  65. * input data or query syntax, while the template builder remains independent
  66. * of the kind of data being used. Due to this, the query processor will be
  67. * supplied with the datasource and query which the template builder handles
  68. * in an opaque way, while the query processor handles these more
  69. * specifically.
  70. *
  71. * Results implement the nsIXULTemplateResult interface and may be identified
  72. * by an id which must be unique within a given set of query results.
  73. *
  74. * Each query may be accompanied by one or more <rule> elements. These rules
  75. * are evaluated by the template builder for each result produced by the
  76. * query. A rule consists of conditions that cause a rule to be either
  77. * accepted or rejected. The condition syntax allows for common conditional
  78. * handling; additional filtering may be applied by adding a custom filter
  79. * to a rule with the builder's addRuleFilter method.
  80. *
  81. * If a result passes a rule's conditions, this is considered a match, and the
  82. * content within the rule's <action> body is inserted as a sibling of the
  83. * <template>, assuming the template builder creates real DOM content. Only
  84. * one rule will match a result. For a tree builder, for example, the content
  85. * within the action body is used to create the tree rows instead. A matching
  86. * result must have its ruleMatched method called. When a result no longer
  87. * matches, the result's hasBeenRemoved method must be called.
  88. *
  89. * Optionally, the rule may have a <bindings> section which may be used to
  90. * define additional variables to be used within an action body. Each of these
  91. * declared bindings must be supplied to the query processor via its
  92. * addBinding method. The bindings are evaluated after a rule has matched.
  93. *
  94. * Templates may generate content recursively, using the previous iteration's
  95. * results as reference point to invoke the same queries. Since the reference
  96. * point is different, different output will typically be generated.
  97. *
  98. * The reference point nsIXULTemplateResult object for the first iteration is
  99. * determined by calling the query processor's translateRef method using the
  100. * value of the root node's ref attribute. This object may be retrieved later
  101. * via the builder's rootResult property.
  102. *
  103. * For convenience, each reference point as well as all results implement the
  104. * nsIXULTemplateResult interface, allowing the result objects from each
  105. * iteration to be used directly as the reference points for the next
  106. * iteration.
  107. *
  108. * When using multiple queries, each may generate results with the same id.
  109. * More than one of these results may match one of the rules in their
  110. * respective queries, however only the result for the earliest matching query
  111. * in the template becomes the active match and generates output. The
  112. * addResult, removeResult, replaceResult and resultBindingChanged methods may
  113. * be called by the query processor to indicate that the set of valid results
  114. * has changed, such that a different query may match. If a different match
  115. * would become active, the content for the existing match is removed and the
  116. * content for the new match is generated. A query processor is not required
  117. * to provide any support for updating results after they have been generated.
  118. *
  119. * See http://wiki.mozilla.org/XUL:Templates_Plan for details about templates.
  120. */
  121. [scriptable, uuid(A583B676-5B02-4F9C-A0C9-CB850CB99818)]
  122. interface nsIXULTemplateBuilder : nsISupports
  123. {
  124. /**
  125. * The root node in the DOM to which this builder is attached.
  126. */
  127. readonly attribute nsIDOMElement root;
  128. /**
  129. * The opaque datasource object that is used for the template. This object
  130. * is created by the getDataSource method of the query processor. May be
  131. * null if the datasource has not been loaded yet. Set this attribute to
  132. * use a different datasource and rebuild the template.
  133. *
  134. * For an RDF datasource, this will be the same as the database. For XML
  135. * this will be the nsIDOMNode for the datasource document or node for
  136. * an inline reference (such as #name). Other query processors may use
  137. * other types for the datasource.
  138. */
  139. attribute nsISupports datasource;
  140. /**
  141. * The composite datasource that the template builder observes
  142. * and uses to create content. This is used only for RDF queries and is
  143. * maintained for backwards compatibility. It will be the same object as
  144. * the datasource property. For non-RDF queries, it will always be null.
  145. */
  146. readonly attribute nsIRDFCompositeDataSource database;
  147. /**
  148. * The virtual result representing the starting reference point,
  149. * determined by calling the query processor's translateRef method
  150. * with the root node's ref attribute as an argument.
  151. */
  152. readonly attribute nsIXULTemplateResult rootResult;
  153. /**
  154. * The query processor used to generate results.
  155. */
  156. [noscript] readonly attribute nsIXULTemplateQueryProcessor queryProcessor;
  157. /**
  158. * Force the template builder to rebuild its content. All existing content
  159. * will be removed first. The query processor's done() method will be
  160. * invoked during cleanup, followed by its initializeForBuilding method
  161. * when the content is to be regenerated.
  162. *
  163. */
  164. void rebuild();
  165. /**
  166. * Reload any of our RDF datasources that support nsIRDFRemoteDatasource.
  167. *
  168. * @note This is a temporary hack so that remote-XUL authors can
  169. * reload remote datasources. When RDF becomes remote-scriptable,
  170. * this will no longer be necessary.
  171. */
  172. void refresh();
  173. /**
  174. * Inform the template builder that a new result is available. The builder
  175. * will add this result to the set of results. The query node that the
  176. * new result applies to must be specified using the aQueryNode parameter.
  177. *
  178. * The builder will apply the rules associated with the query to the new
  179. * result, unless a result with the same id from an earlier query
  180. * supersedes it, and the result's RuleMatched method will be called if it
  181. * matches.
  182. *
  183. * @param aResult the result to add
  184. * @param aQueryNode the query that the result applies to
  185. *
  186. * @throws NS_ERROR_NULL_POINTER if aResult or aQueryNode are null
  187. */
  188. void addResult(in nsIXULTemplateResult aResult, in nsIDOMNode aQueryNode);
  189. /**
  190. * Inform the template builder that a result no longer applies. The builder
  191. * will call the remove content generated for the result, if any. If a different
  192. * query would then match instead, it will become the active match. This
  193. * method will have no effect if the result isn't known to the builder.
  194. *
  195. * @param aResult the result to remove
  196. *
  197. * @throws NS_ERROR_NULL_POINTER if aResult is null
  198. */
  199. void removeResult(in nsIXULTemplateResult aResult);
  200. /**
  201. * Inform the template builder that one result should be replaced with
  202. * another. Both the old result (aOldResult) and the new result
  203. * (aNewResult) must have the same id. The query node that the new result
  204. * applies to must be specified using the aQueryNode parameter.
  205. *
  206. * This method is expected to have the same effect as calling both
  207. * removeResult for the old result and addResult for the new result.
  208. *
  209. * @param aOldResult the old result
  210. * @param aNewResult the new result
  211. * @param aQueryNode the query that the new result applies to
  212. *
  213. * @throws NS_ERROR_NULL_POINTER if either argument is null, or
  214. * NS_ERROR_INVALID_ARG if the ids don't match
  215. */
  216. void replaceResult(in nsIXULTemplateResult aOldResult,
  217. in nsIXULTemplateResult aNewResult,
  218. in nsIDOMNode aQueryNode);
  219. /**
  220. * Inform the template builder that one or more of the optional bindings
  221. * for a result has changed. In this case, the rules are not reapplied as
  222. * it is expected that the same rule will still apply. The builder will
  223. * resynchronize any variables that are referenced in the action body.
  224. *
  225. * @param aResult the result to change
  226. *
  227. * @throws NS_ERROR_NULL_POINTER if aResult is null
  228. */
  229. void resultBindingChanged(in nsIXULTemplateResult aResult);
  230. /**
  231. * Return the result for a given id. Only one such result is returned and
  232. * is always the result with that id associated with the active match.
  233. * This method will return null is there is no result for the id.
  234. *
  235. * @param aId the id to return the result for
  236. */
  237. nsIXULTemplateResult getResultForId(in AString aId);
  238. /**
  239. * Retrieve the result corresponding to a generated element, or null is
  240. * there isn't one.
  241. *
  242. * @param aContent element to result the result of
  243. */
  244. nsIXULTemplateResult getResultForContent(in nsIDOMElement aElement);
  245. /**
  246. * Returns true if the node has content generated for it. This method is
  247. * intended to be called only by the RDF query processor. If aTag is set,
  248. * the content must have a tag name that matches aTag. aTag may be ignored
  249. * for builders that don't generate real DOM content.
  250. *
  251. * @param aNode node to check
  252. * @param aTag tag that must match
  253. */
  254. boolean hasGeneratedContent(in nsIRDFResource aNode, in nsIAtom aTag);
  255. /**
  256. * Adds a rule filter for a given rule, which may be used for specialized
  257. * rule filtering. Any existing filter on the rule is removed. The default
  258. * conditions specified inside the <rule> tag are applied before the
  259. * rule filter is applied, meaning that the filter may be used to further
  260. * filter out results but not reaccept results that have already been
  261. * rejected.
  262. *
  263. * @param aRule the rule to apply the filter to
  264. * @param aFilter the filter to add
  265. */
  266. void addRuleFilter(in nsIDOMNode aRule, in nsIXULTemplateRuleFilter aFilter);
  267. /**
  268. * Called to initialize a XUL content builder on a particular root
  269. * element. This element presumably has a ``datasources''
  270. * attribute, which the builder will parse to set up the template
  271. * builder's datasources.
  272. */
  273. [noscript] void init(in nsIContent aElement);
  274. /**
  275. * Invoked lazily by a XUL element that needs its child content built.
  276. * If aForceCreation is true, then the contents of an element will be
  277. * generated even if it is closed. If false, the element will only
  278. * generate its contents if it is open. This behaviour is used with menus.
  279. */
  280. [noscript] void createContents(in nsIContent aElement,
  281. in boolean aForceCreation);
  282. /**
  283. * Add a listener to this template builder. The template builder
  284. * holds a strong reference to the listener.
  285. */
  286. void addListener(in nsIXULBuilderListener aListener);
  287. /**
  288. * Remove a listener from this template builder.
  289. */
  290. void removeListener(in nsIXULBuilderListener aListener);
  291. };
  292. /**
  293. * nsIXULTreeBuilderObserver
  294. * This interface allows clients of the XULTreeBuilder to define domain
  295. * specific handling of specific nsITreeView methods that
  296. * XULTreeBuilder does not implement.
  297. */
  298. [scriptable, uuid(57CED9A7-EC0B-4A0E-8AEB-5DA32EBE951C)]
  299. interface nsIXULTreeBuilderObserver : nsISupports
  300. {
  301. const long DROP_BEFORE = -1;
  302. const long DROP_ON = 0;
  303. const long DROP_AFTER = 1;
  304. /**
  305. * Methods used by the drag feedback code to determine if a drag is allowable at
  306. * the current location. To get the behavior where drops are only allowed on
  307. * items, such as the mailNews folder pane, always return false whe
  308. * the orientation is not DROP_ON.
  309. */
  310. boolean canDrop(in long index, in long orientation, in nsIDOMDataTransfer dataTransfer);
  311. /**
  312. * Called when the user drops something on this view. The |orientation| param
  313. * specifies before/on/after the given |row|.
  314. */
  315. void onDrop(in long row, in long orientation, in nsIDOMDataTransfer dataTransfer);
  316. /**
  317. * Called when an item is opened or closed.
  318. */
  319. void onToggleOpenState (in long index);
  320. /**
  321. * Called when a header is clicked.
  322. */
  323. void onCycleHeader(in wstring colID, in nsIDOMElement elt);
  324. /**
  325. * Called when a cell in a non-selectable cycling column (e.g.
  326. * unread/flag/etc.) is clicked.
  327. */
  328. void onCycleCell(in long row, in wstring colID);
  329. /**
  330. * Called when selection in the tree changes
  331. */
  332. void onSelectionChanged();
  333. /**
  334. * A command API that can be used to invoke commands on the selection.
  335. * The tree will automatically invoke this method when certain keys
  336. * are pressed. For example, when the DEL key is pressed, performAction
  337. * will be called with the "delete" string.
  338. */
  339. void onPerformAction(in wstring action);
  340. /**
  341. * A command API that can be used to invoke commands on a specific row.
  342. */
  343. void onPerformActionOnRow(in wstring action, in long row);
  344. /**
  345. * A command API that can be used to invoke commands on a specific cell.
  346. */
  347. void onPerformActionOnCell(in wstring action, in long row, in wstring colID);
  348. };
  349. [scriptable, uuid(06b31b15-ebf5-4e74-a0e2-6bc0a18a3969)]
  350. interface nsIXULTreeBuilder : nsISupports
  351. {
  352. /**
  353. * Retrieve the RDF resource associated with the specified row.
  354. */
  355. nsIRDFResource getResourceAtIndex(in long aRowIndex);
  356. /**
  357. * Retrieve the index associated with specified RDF resource.
  358. */
  359. long getIndexOfResource(in nsIRDFResource resource);
  360. /**
  361. * Add a Tree Builder Observer to handle Tree View
  362. * methods that the base builder does not implement.
  363. */
  364. void addObserver(in nsIXULTreeBuilderObserver aObserver);
  365. /**
  366. * Remove an Tree Builder Observer.
  367. */
  368. void removeObserver(in nsIXULTreeBuilderObserver aObserver);
  369. /**
  370. * Sort the contents of the tree using the specified column.
  371. */
  372. void sort(in nsIDOMElement aColumnElement);
  373. };