nsITableEditor.idl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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 "nsISupports.idl"
  6. interface nsIDOMNode;
  7. interface nsIDOMElement;
  8. interface nsIDOMRange;
  9. [scriptable, uuid(4805e684-49b9-11d3-9ce4-ed60bd6cb5bc)]
  10. interface nsITableEditor : nsISupports
  11. {
  12. const short eNoSearch = 0;
  13. const short ePreviousColumn = 1;
  14. const short ePreviousRow = 2;
  15. /* ------------ Table editing Methods -------------- */
  16. /** Insert table methods
  17. * Insert relative to the selected cell or the
  18. * cell enclosing the selection anchor
  19. * The selection is collapsed and is left in the new cell
  20. * at the same row,col location as the original anchor cell
  21. *
  22. * @param aNumber Number of items to insert
  23. * @param aAfter If TRUE, insert after the current cell,
  24. * else insert before current cell
  25. */
  26. void insertTableCell(in long aNumber, in boolean aAfter);
  27. void insertTableColumn(in long aNumber, in boolean aAfter);
  28. void insertTableRow(in long aNumber, in boolean aAfter);
  29. /** Delete table methods
  30. * Delete starting at the selected cell or the
  31. * cell (or table) enclosing the selection anchor
  32. * The selection is collapsed and is left in the
  33. * cell at the same row,col location as
  34. * the previous selection anchor, if possible,
  35. * else in the closest neigboring cell
  36. *
  37. * @param aNumber Number of items to insert/delete
  38. */
  39. void deleteTable();
  40. /** Delete just the cell contents
  41. * This is what should happen when Delete key is used
  42. * for selected cells, to minimize upsetting the table layout
  43. */
  44. void deleteTableCellContents();
  45. /** Delete cell elements as well as contents
  46. * @param aNumber Number of contiguous cells, rows, or columns
  47. *
  48. * When there are more than 1 selected cells, aNumber is ignored.
  49. * For Delete Rows or Columns, the complete columns or rows are
  50. * determined by the selected cells. E.g., to delete 2 complete rows,
  51. * user simply selects a cell in each, and they don't
  52. * have to be contiguous.
  53. */
  54. void deleteTableCell(in long aNumber);
  55. void deleteTableColumn(in long aNumber);
  56. void deleteTableRow(in long aNumber);
  57. /** Table Selection methods
  58. * Selecting a row or column actually
  59. * selects all cells (not TR in the case of rows)
  60. */
  61. void selectTableCell();
  62. /** Select a rectangular block of cells:
  63. * all cells falling within the row/column index of aStartCell
  64. * to through the row/column index of the aEndCell
  65. * aStartCell can be any location relative to aEndCell,
  66. * as long as they are in the same table
  67. * @param aStartCell starting cell in block
  68. * @param aEndCell ending cell in block
  69. */
  70. void selectBlockOfCells(in nsIDOMElement aStartCell,
  71. in nsIDOMElement aEndCell);
  72. void selectTableRow();
  73. void selectTableColumn();
  74. void selectTable();
  75. void selectAllTableCells();
  76. /** Create a new TD or TH element, the opposite type of the supplied aSourceCell
  77. * 1. Copy all attributes from aSourceCell to the new cell
  78. * 2. Move all contents of aSourceCell to the new cell
  79. * 3. Replace aSourceCell in the table with the new cell
  80. *
  81. * @param aSourceCell The cell to be replaced
  82. * @return The new cell that replaces aSourceCell
  83. */
  84. nsIDOMElement switchTableCellHeaderType(in nsIDOMElement aSourceCell);
  85. /** Merges contents of all selected cells
  86. * for selected cells that are adjacent,
  87. * this will result in a larger cell with appropriate
  88. * rowspan and colspan, and original cells are deleted
  89. * The resulting cell is in the location of the
  90. * cell at the upper-left corner of the adjacent
  91. * block of selected cells
  92. *
  93. * @param aMergeNonContiguousContents:
  94. * If true:
  95. * Non-contiguous cells are not deleted,
  96. * but their contents are still moved
  97. * to the upper-left cell
  98. * If false: contiguous cells are ignored
  99. *
  100. * If there are no selected cells,
  101. * and selection or caret is in a cell,
  102. * that cell and the one to the right
  103. * are merged
  104. */
  105. void joinTableCells(in boolean aMergeNonContiguousContents);
  106. /** Split a cell that has rowspan and/or colspan > 0
  107. * into cells such that all new cells have
  108. * rowspan = 1 and colspan = 1
  109. * All of the contents are not touched --
  110. * they will appear to be in the upper-left cell
  111. */
  112. void splitTableCell();
  113. /** Scan through all rows and add cells as needed so
  114. * all locations in the cellmap are occupied.
  115. * Used after inserting single cells or pasting
  116. * a collection of cells that extend past the
  117. * previous size of the table
  118. * If aTable is null, it uses table enclosing the selection anchor
  119. * This doesn't doesn't change the selection,
  120. * thus it can be used to fixup all tables
  121. * in a page independent of the selection
  122. */
  123. void normalizeTable(in nsIDOMElement aTable);
  124. /** Get the row an column index from the layout's cellmap
  125. * If aCell is null, it will try to find enclosing table of selection anchor
  126. *
  127. */
  128. void getCellIndexes(in nsIDOMElement aCell,
  129. out long aRowIndex, out long aColIndex);
  130. /** Get the number of rows and columns in a table from the layout's cellmap
  131. * If aTable is null, it will try to find enclosing table of selection ancho
  132. * Note that all rows in table will not have this many because of
  133. * ROWSPAN effects or if table is not "rectangular" (has short rows)
  134. */
  135. void getTableSize(in nsIDOMElement aTable,
  136. out long aRowCount, out long aColCount);
  137. /** Get a cell element at cellmap grid coordinates
  138. * A cell that spans across multiple cellmap locations will
  139. * be returned multiple times, once for each location it occupies
  140. *
  141. * @param aTable A table in the document
  142. * @param aRowIndex, aColIndex The 0-based cellmap indexes
  143. *
  144. * (in C++ returns: NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  145. * passes NS_SUCCEEDED macro)
  146. *
  147. * You can scan for all cells in a row or column
  148. * by iterating through the appropriate indexes
  149. * until the returned aCell is null
  150. */
  151. nsIDOMElement getCellAt(in nsIDOMElement aTable,
  152. in long aRowIndex, in long aColIndex);
  153. /** Get a cell at cellmap grid coordinates and associated data
  154. * A cell that spans across multiple cellmap locations will
  155. * be returned multiple times, once for each location it occupies
  156. * Examine the returned aStartRowIndex and aStartColIndex to see
  157. * if it is in the same layout column or layout row:
  158. * A "layout row" is all cells sharing the same top edge
  159. * A "layout column" is all cells sharing the same left edge
  160. * This is important to determine what to do when inserting or deleting a column or row
  161. *
  162. * @param aTable A table in the document
  163. * @param aRowIndex, aColIndex The 0-based cellmap indexes
  164. * returns values:
  165. * @param aCell The cell at this cellmap location
  166. * @param aStartRowIndex The row index where cell starts
  167. * @param aStartColIndex The col index where cell starts
  168. * @param aRowSpan May be 0 (to span down entire table) or number of cells spanned
  169. * @param aColSpan May be 0 (to span across entire table) or number of cells spanned
  170. * @param aActualRowSpan The actual number of cellmap locations (rows) spanned by the cell
  171. * @param aActualColSpan The actual number of cellmap locations (columns) spanned by the cell
  172. * @param aIsSelected
  173. * @param
  174. *
  175. * (in C++ returns: NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  176. * passes NS_SUCCEEDED macro)
  177. */
  178. void getCellDataAt(in nsIDOMElement aTable,
  179. in long aRowIndex, in long aColIndex,
  180. out nsIDOMElement aCell,
  181. out long aStartRowIndex, out long aStartColIndex,
  182. out long aRowSpan, out long aColSpan,
  183. out long aActualRowSpan, out long aActualColSpan,
  184. out boolean aIsSelected);
  185. /** Get the first row element in a table
  186. *
  187. * @return The row at the requested index
  188. * Returns null if there are no rows in table
  189. * (in C++ returns: NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  190. * passes NS_SUCCEEDED macro)
  191. */
  192. nsIDOMNode getFirstRow(in nsIDOMElement aTableElement);
  193. /** Get the next row element starting the search from aTableElement
  194. *
  195. * @param aTableElement Any TR or child-of-TR element in the document
  196. *
  197. * @return The row to start search from
  198. * and the row returned from the search
  199. * Returns null if there isn't another row
  200. * (in C++ returns: NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  201. * passes NS_SUCCEEDED macro)
  202. */
  203. nsIDOMNode getNextRow(in nsIDOMNode aTableElement);
  204. /** Preferred direction to search for neighboring cell
  205. * when trying to locate a cell to place caret in after
  206. * a table editing action.
  207. * Used for aDirection param in SetSelectionAfterTableEdit
  208. */
  209. /** Reset a selected cell or collapsed selection (the caret) after table editing
  210. *
  211. * @param aTable A table in the document
  212. * @param aRow The row ...
  213. * @param aCol ... and column defining the cell
  214. * where we will try to place the caret
  215. * @param aSelected If true, we select the whole cell instead of setting caret
  216. * @param aDirection If cell at (aCol, aRow) is not found,
  217. * search for previous cell in the same
  218. * column (aPreviousColumn) or row (ePreviousRow)
  219. * or don't search for another cell (aNoSearch)
  220. * If no cell is found, caret is place just before table;
  221. * and if that fails, at beginning of document.
  222. * Thus we generally don't worry about the return value
  223. * and can use the nsSetSelectionAfterTableEdit stack-based
  224. * object to insure we reset the caret in a table-editing method.
  225. */
  226. void setSelectionAfterTableEdit(in nsIDOMElement aTable,
  227. in long aRow, in long aCol,
  228. in long aDirection, in boolean aSelected);
  229. /** Examine the current selection and find
  230. * a selected TABLE, TD or TH, or TR element.
  231. * or return the parent TD or TH if selection is inside a table cell
  232. * Returns null if no table element is found.
  233. *
  234. * @param aTagName The tagname of returned element
  235. * Note that "td" will be returned if name
  236. * is actually "th"
  237. * @param aCount How many table elements were selected
  238. * This tells us if we have multiple cells selected
  239. * (0 if element is a parent cell of selection)
  240. * @return The table element (table, row, or first selected cell)
  241. *
  242. */
  243. nsIDOMElement getSelectedOrParentTableElement(out AString aTagName, out long aCount);
  244. /** Generally used after GetSelectedOrParentTableElement
  245. * to test if selected cells are complete rows or columns
  246. *
  247. * @param aElement Any table or cell element or any element
  248. * inside a table
  249. * Used to get enclosing table.
  250. * If null, selection's anchorNode is used
  251. *
  252. * @return
  253. * 0 aCellElement was not a cell
  254. * (returned result = NS_ERROR_FAILURE)
  255. * TABLESELECTION_CELL There are 1 or more cells selected but
  256. * complete rows or columns are not selected
  257. * TABLESELECTION_ROW All cells are in 1 or more rows
  258. * and in each row, all cells selected
  259. * Note: This is the value if all rows
  260. * (thus all cells) are selected
  261. * TABLESELECTION_COLUMN All cells are in 1 or more columns
  262. * and in each column, all cells are selected
  263. */
  264. uint32_t getSelectedCellsType(in nsIDOMElement aElement);
  265. /** Get first selected element from first selection range.
  266. * (If multiple cells were selected this is the first in the order they were selected)
  267. * Assumes cell-selection model where each cell
  268. * is in a separate range (selection parent node is table row)
  269. * @param aCell [OUT] Selected cell or null if ranges don't contain
  270. * cell selections
  271. * @param aRange [OUT] Optional: if not null, return the selection range
  272. * associated with the cell
  273. * Returns the DOM cell element
  274. * (in C++: returns NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  275. * passes NS_SUCCEEDED macro)
  276. */
  277. nsIDOMElement getFirstSelectedCell(out nsIDOMRange aRange);
  278. /** Get first selected element in the table
  279. * This is the upper-left-most selected cell in table,
  280. * ignoring the order that the user selected them (order in the selection ranges)
  281. * Assumes cell-selection model where each cell
  282. * is in a separate range (selection parent node is table row)
  283. * @param aCell Selected cell or null if ranges don't contain
  284. * cell selections
  285. * @param aRowIndex Optional: if not null, return row index of 1st cell
  286. * @param aColIndex Optional: if not null, return column index of 1st cell
  287. *
  288. * Returns the DOM cell element
  289. * (in C++: returns NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  290. * passes NS_SUCCEEDED macro)
  291. */
  292. nsIDOMElement getFirstSelectedCellInTable(out long aRowIndex, out long aColIndex);
  293. /** Get next selected cell element from first selection range.
  294. * Assumes cell-selection model where each cell
  295. * is in a separate range (selection parent node is table row)
  296. * Always call GetFirstSelectedCell() to initialize stored index of "next" cell
  297. * @param aCell Selected cell or null if no more selected cells
  298. * or ranges don't contain cell selections
  299. * @param aRange Optional: if not null, return the selection range
  300. * associated with the cell
  301. *
  302. * Returns the DOM cell element
  303. * (in C++: returns NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  304. * passes NS_SUCCEEDED macro)
  305. */
  306. nsIDOMElement getNextSelectedCell(out nsIDOMRange aRange);
  307. };