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