Bug 1640914 [wpt PR 23771] - Python 3: port tests in resource-timing, a=testonly
[gecko.git] / editor / nsITableEditor.idl
blob91a4023886e6612d656e1be0a1ee832fb8eb0988
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/. */
7 #include "nsISupports.idl"
9 webidl Element;
10 webidl Node;
11 webidl Range;
13 [scriptable, builtinclass, uuid(4805e684-49b9-11d3-9ce4-ed60bd6cb5bc)]
14 interface nsITableEditor : nsISupports
16 const short eNoSearch = 0;
17 const short ePreviousColumn = 1;
18 const short ePreviousRow = 2;
20 /**
21 * insertTableCell() inserts <td> elements before or after a cell element
22 * containing first selection range. I.e., if the cell spans columns and
23 * aInsertPosition is true, new columns will be inserted after the
24 * right-most column which contains the cell. Note that this simply
25 * inserts <td> elements, i.e., colspan and rowspan around the cell
26 * containing selection are not modified. So, for example, adding a cell
27 * to rectangular table changes non-rectangular table. And if a cell
28 * containing selection is at left of row-spanning cell, it may be moved to
29 * right side of the row-spanning cell after inserting some cell elements
30 * before it. Similarly, colspan won't be adjusted for keeping table
31 * rectangle.
32 * If first selection range is not in table cell element, this does nothing
33 * without exception.
35 * @param aNumberOfCellssToInsert Number of cells to insert.
36 * @param aInsertAfterSelectedCell true if new cells should be inserted
37 * before current cell. Otherwise, will
38 * be inserted after the cell.
40 [can_run_script]
41 void insertTableCell(in long aNumberOfColumnsToInsert,
42 in boolean aInsertAfterSelectedCell);
44 /**
45 * insertTableColumn() inserts columns before or after a cell element
46 * containing first selection range. I.e., if the cell spans columns and
47 * aInsertAfterSelectedCell is tre, new columns will be inserted after the
48 * right-most column which contains the cell. If first selection range is
49 * not in table cell element, this does nothing without exception.
51 * @param aNumberOfColumnsToInsert Number of columns to insert.
52 * @param aInsertAfterSelectedCell true if new columns will be inserted
53 * before current cell. Otherwise, will
54 * be inserted after the cell.
56 [can_run_script]
57 void insertTableColumn(in long aNumberOfColumnsToInsert,
58 in boolean aInsertAfterSelectedCell);
61 * insertTableRow() inserts <tr> elements before or after a <td> element
62 * containing first selection range. I.e., if the cell spans rows and
63 * aInsertAfterSelectedCell is true, new rows will be inserted after the
64 * bottom-most row which contains the cell. If first selection range is
65 * not in table cell element, this does nothing without exception.
67 * @param aNumberOfRowsToInsert Number of rows to insert.
68 * @param aInsertAfterSelectedCell true if new rows will be inserted
69 * before current cell. Otherwise, will
70 * be inserted after the cell.
72 [can_run_script]
73 void insertTableRow(in long aNumberOfRowsToInsert,
74 in boolean aInsertAfterSelectedCell);
76 /** Delete table methods
77 * Delete starting at the selected cell or the
78 * cell (or table) enclosing the selection anchor
79 * The selection is collapsed and is left in the
80 * cell at the same row,col location as
81 * the previous selection anchor, if possible,
82 * else in the closest neighboring cell
84 * @param aNumber Number of items to insert/delete
86 [can_run_script]
87 void deleteTable();
89 /**
90 * deleteTableCellContents() removes any contents in cell elements. If two
91 * or more cell elements are selected, this removes all selected cells'
92 * contents. Otherwise, this removes contents of a cell which contains
93 * first selection range. This does nothing without exception if selection
94 * is not in cell element.
96 [can_run_script]
97 void deleteTableCellContents();
99 /**
100 * deleteTableCell() removes table cell elements. If two or more cell
101 * elements are selected, this removes all selected cell elements.
102 * Otherwise, this removes some cell elements starting from selected cell
103 * element or a cell containing first selection range. When this removes
104 * last cell element in <tr> or <table>, this removes the <tr> or the
105 * <table> too. Note that when removing a cell causes number of its row
106 * becomes less than the others, this method does NOT fill the place with
107 * rowspan nor colspan. This does nothing without exception if selection is
108 * not in cell element.
110 * @param aNumberOfCellsToDelete Number of cells to remove. This is ignored
111 * if 2 or more cells are selected.
113 [can_run_script]
114 void deleteTableCell(in long aNumberOfCellsToDelete);
117 * deleteTableColumn() removes cell elements which belong to same columns
118 * of selected cell elements.
119 * If only one cell element is selected or first selection range is
120 * in a cell, removes cell elements which belong to same column.
121 * If 2 or more cell elements are selected, removes cell elements which
122 * belong to any of all selected columns. In this case,
123 * aNumberOfColumnsToDelete is ignored.
124 * If there is no selection ranges, throws exception.
125 * If selection is not in a cell element, just does nothing without
126 * throwing exception.
127 * WARNING: This does not remove <col> nor <colgroup> elements.
129 * @param aNumberOfColumnsToDelete Number of columns to remove. This is
130 * ignored if 2 ore more cells are
131 * selected.
133 [can_run_script]
134 void deleteTableColumn(in long aNumberOfColumnsToDelete);
137 * deleteTableRow() removes <tr> elements.
138 * If only one cell element is selected or first selection range is
139 * in a cell, removes <tr> elements starting from a <tr> element
140 * containing the selected cell or first selection range.
141 * If 2 or more cell elements are selected, all <tr> elements
142 * which contains selected cell(s). In this case, aNumberOfRowsToDelete
143 * is ignored.
144 * If there is no selection ranges, throws exception.
145 * If selection is not in a cell element, just does nothing without
146 * throwing exception.
148 * @param aNumberOfRowsToDelete Number of rows to remove. This is ignored
149 * if 2 or more cells are selected.
151 [can_run_script]
152 void deleteTableRow(in long aNumberOfRowsToDelete);
154 /** Table Selection methods
155 * Selecting a row or column actually
156 * selects all cells (not TR in the case of rows)
158 [can_run_script]
159 void selectTableCell();
161 [can_run_script]
162 void selectTableRow();
163 [can_run_script]
164 void selectTableColumn();
165 [can_run_script]
166 void selectTable();
167 [can_run_script]
168 void selectAllTableCells();
170 /** Create a new TD or TH element, the opposite type of the supplied aSourceCell
171 * 1. Copy all attributes from aSourceCell to the new cell
172 * 2. Move all contents of aSourceCell to the new cell
173 * 3. Replace aSourceCell in the table with the new cell
175 * @param aSourceCell The cell to be replaced
176 * @return The new cell that replaces aSourceCell
178 [can_run_script]
179 Element switchTableCellHeaderType(in Element aSourceCell);
181 /** Merges contents of all selected cells
182 * for selected cells that are adjacent,
183 * this will result in a larger cell with appropriate
184 * rowspan and colspan, and original cells are deleted
185 * The resulting cell is in the location of the
186 * cell at the upper-left corner of the adjacent
187 * block of selected cells
189 * @param aMergeNonContiguousContents:
190 * If true:
191 * Non-contiguous cells are not deleted,
192 * but their contents are still moved
193 * to the upper-left cell
194 * If false: contiguous cells are ignored
196 * If there are no selected cells,
197 * and selection or caret is in a cell,
198 * that cell and the one to the right
199 * are merged
201 [can_run_script]
202 void joinTableCells(in boolean aMergeNonContiguousContents);
204 /** Split a cell that has rowspan and/or colspan > 0
205 * into cells such that all new cells have
206 * rowspan = 1 and colspan = 1
207 * All of the contents are not touched --
208 * they will appear to be in the upper-left cell
210 [can_run_script]
211 void splitTableCell();
213 /** Scan through all rows and add cells as needed so
214 * all locations in the cellmap are occupied.
215 * Used after inserting single cells or pasting
216 * a collection of cells that extend past the
217 * previous size of the table
218 * If aTable is null, it uses table enclosing the selection anchor
219 * This doesn't doesn't change the selection,
220 * thus it can be used to fixup all tables
221 * in a page independent of the selection
223 [can_run_script]
224 void normalizeTable(in Element aTable);
227 * getCellIndexes() computes row index and column index of a table cell.
228 * Note that this depends on layout information. Therefore, all pending
229 * layout should've been flushed before calling this.
231 * @param aCellElement If not null, this computes indexes of the cell.
232 * If null, this computes indexes of a cell which
233 * contains anchor of Selection.
234 * @param aRowIndex Must be an object, whose .value will be set
235 * to row index of the cell. 0 is the first row.
236 * If rowspan is set to 2 or more, the start
237 * row index is used.
238 * @param aColumnIndex Must be an object, whose .value will be set
239 * to column index of the cell. 0 is the first
240 * column. If colspan is set to 2 or more, the
241 * start column index is used.
243 [can_run_script]
244 void getCellIndexes(in Element aCellElement,
245 out long aRowIndex, out long aColumnIndex);
248 * getTableSize() computes number of rows and columns.
249 * Note that this depends on layout information. Therefore, all pending
250 * layout should've been flushed before calling this.
252 * @param aTableOrElementInTable If a <table> element, this computes number
253 * of rows and columns of it.
254 * If another element and in a <table>, this
255 * computes number of rows and columns of
256 * the nearest ancestor <table> element.
257 * If element is not in <table> element,
258 * throwing an exception.
259 * If null, this looks for nearest ancestor
260 * <table> element containing anchor of
261 * Selection. If found, computes the number
262 * of rows and columns of the <table>.
263 * Otherwise, throwing an exception.
264 * @param aRowCount Number of *actual* row count.
265 * I.e., rowspan does NOT increase this value.
266 * @param aColumnCount Number of column count.
267 * I.e., if colspan is specified with bigger
268 * number than actual, the value is used
269 * as this.
271 void getTableSize(in Element aTableOrElementInTable,
272 out long aRowCount, out long aColCount);
275 * getCellAt() returns a <td> or <th> element in a <table> if there is a
276 * cell at the indexes.
278 * @param aTableElement If not null, must be a <table> element.
279 * If null, looks for the nearest ancestor <table>
280 * to look for a cell.
281 * @param aRowIndex Row index of the cell.
282 * @param aColumnIndex Column index of the cell.
283 * @return Returns a <td> or <th> element if there is.
284 * Otherwise, returns null without throwing
285 * exception.
286 * If aTableElement is not null and not a <table>
287 * element, throwing an exception.
288 * If aTableElement is null and anchor of Selection
289 * is not in any <table> element, throwing an
290 * exception.
292 Element getCellAt(in Element aTableElement,
293 in long aRowIndex, in long aColumnIndex);
296 * Get cell element and its various information from <table> element and
297 * indexes in it. If aTableElement is null, this looks for an ancestor
298 * <table> element of anchor of Selection. If there is no <table> element
299 * at that point, this throws exception. Note that this requires layout
300 * information. So, you need to flush the layout after changing the DOM
301 * tree.
302 * If there is no cell element at the indexes, this throws exception.
303 * XXX Perhaps, this is wrong behavior, this should return null without
304 * exception since the caller cannot distinguish whether the exception
305 * is caused by "not found" or other unexpected situation.
307 * @param aTableElement A <table> element. If this is null, this
308 * uses ancestor of anchor of Selection.
309 * @param aRowIndex Row index in aTableElement. Starting from 0.
310 * @param aColumnIndex Column index in aTableElement. Starting from
311 * 0.
312 * @param aCellElement [OUT] The cell element at the indexes.
313 * @param aStartRowIndex [OUT] First row index which contains
314 * aCellElement. E.g., if the cell's rowspan is
315 * not 1, this returns its first row index.
316 * I.e., this can be smaller than aRowIndex.
317 * @param aStartColumnIndex [OUT] First column index which contains the
318 * aCellElement. E.g., if the cell's colspan is
319 * larger than 1, this returns its first column
320 * index. I.e., this can be smaller than
321 * aColumIndex.
322 * @param aRowSpan [OUT] rowspan attribute value in most cases.
323 * If the specified value is invalid, this
324 * returns 1. Only when the document is written
325 * in HTML5 or later, this can be 0.
326 * @param aColSpan [OUT] colspan attribute value in most cases.
327 * If the specified value is invalid, this
328 * returns 1.
329 * @param aEffectiveRowSpan [OUT] Effective rowspan value at aRowIndex.
330 * This is same as:
331 * aRowSpan - (aRowIndex - aStartRowIndex)
332 * @param aEffectiveColSpan [OUT] Effective colspan value at aColumnIndex.
333 * This is same as:
334 * aColSpan - (aColumnIndex - aStartColumnIndex)
335 * @param aIsSelected [OUT] Returns true if aCellElement or its
336 * <tr> or <table> element is selected.
337 * Otherwise, e.g., aCellElement just contains
338 * selection range, returns false.
340 void getCellDataAt(in Element aTableElement,
341 in long aRowIndex, in long aColumnIndex,
342 out Element aCellElement,
343 out long aStartRowIndex, out long aStartColumnIndex,
344 out long aRowSpan, out long aColSpan,
345 out long aEffectiveRowSpan, out long aEffectiveColSpan,
346 out boolean aIsSelected);
349 * getFirstRow() returns first <tr> element in a <table> element.
351 * @param aTableOrElementInTable If a <table> element, returns its first
352 * <tr> element.
353 * If another element, looks for nearest
354 * ancestor <table> element first. Then,
355 * return its first <tr> element.
356 * @return <tr> element in the <table> element.
357 * If <table> element is not found, this
358 * throws an exception.
359 * If there is a <table> element but it
360 * does not have <tr> elements, returns
361 * null without throwing exception.
362 * Note that this may return anonymous <tr>
363 * element if <table> has one or more cells
364 * but <tr> element is not in the source.
366 Element getFirstRow(in Element aTableElement);
368 /** Preferred direction to search for neighboring cell
369 * when trying to locate a cell to place caret in after
370 * a table editing action.
371 * Used for aDirection param in SetSelectionAfterTableEdit
375 * getSelectedOrParentTableElement() returns a <td>, <th>, <tr> or <table>.
376 * If first selection range selects a <td> or <th>, returns it. aTagName
377 * is set to "td" even if the result is a <th> and aCount is set to
378 * Selection.rangeCount.
379 * If first selection range does not select <td> nor <th>, but selection
380 * anchor refers <table>, returns it. aTagName is set to "table" and
381 * aCount is set to 1.
382 * If first selection range does not select <td> nor <th>, but selection
383 * anchor refers <tr>, returns it. aTagName is set to "tr" and aCount is
384 * set to 1.
385 * If first selection range does not select <td> nor <th>, but selection
386 * anchor refers <td> (not include <th>!), returns it. aTagName is set to
387 * "td" and aCount is set to 0.
388 * Otherwise, if container of selection anchor is in a <td> or <th>,
389 * returns it. aTagName is set to "td" but aCount is set to 0.
390 * Otherwise, returns null, aTagName is set to empty string and aCount is
391 * set to 0. I.e., does not throw exception even if a cell is not found.
392 * NOTE: Calling this resets internal counter of getFirstSelectedCell()
393 * and getNextSelectedCell(). I.e., getNextSelectedCell() will
394 * return second selected cell element.
396 Element getSelectedOrParentTableElement(out AString aTagName,
397 out long aCount);
399 /** Generally used after GetSelectedOrParentTableElement
400 * to test if selected cells are complete rows or columns
402 * @param aElement Any table or cell element or any element
403 * inside a table
404 * Used to get enclosing table.
405 * If null, selection's anchorNode is used
407 * @return
408 * 0 aCellElement was not a cell
409 * (returned result = NS_ERROR_FAILURE)
410 * TableSelectionMode::Cell There are 1 or more cells selected but
411 * complete rows or columns are not selected
412 * TableSelectionMode::Row All cells are in 1 or more rows
413 * and in each row, all cells selected
414 * Note: This is the value if all rows
415 * (thus all cells) are selected
416 * TableSelectionMode::Column All cells are in 1 or more columns
417 * and in each column, all cells are selected
419 [can_run_script]
420 uint32_t getSelectedCellsType(in Element aElement);
423 * getFirstSelectedCell() returns a <td> or <th> element if first range of
424 * Selection selects only one table cell element (i.e., startContainer and
425 * endContainer are same <tr> element and startOffset + 1 equals endOffset).
426 * If first range of Selection does not select a table cell element, this
427 * returns null. However, if Selection has no range, this throws an
428 * exception.
430 * @param aFirstRangeOfSelection [OUT] Returns the first range of Selection
431 * only when this returns a <td> or <th>
432 * element. Otherwise, returns null.
433 * @return A <td> or <th> element if first range of
434 * Selection selects only one table cell
435 * element.
437 Element getFirstSelectedCell(out Range aFirstRangeOfSelection);
440 * getFirstSelectedCellInTable() returns a cell element, its row index and
441 * its column index if first range of Selection selects a cell. Note that
442 * that "selects a cell" means that the range container is a <tr> element
443 * and endOffset is startOffset + 1. So, even if first range of Selection
444 * is in a cell element, this treats the range does not select a cell.
445 * NOTE: Calling this resets internal counter of getFirstSelectedCell()
446 * and getNextSelectedCell(). I.e., getNextSelectedCell() will
447 * return second selected cell element.
449 * @param aRowIndex [OUT} Returns row index of the found cell. If not
450 * found, returns 0.
451 * @param aColumnIndex [OUT] Returns column index of the found cell. If
452 * not found, returns 0.
453 * @return The cell element which is selected by the first
454 * range of Selection. Even if this is not found,
455 * this returns null, not throwing exception.
457 [can_run_script]
458 Element getFirstSelectedCellInTable(out long aRowIndex, out long aColIndex);
461 * getNextSelectedCell() is a stateful method to retrieve selected table
462 * cell elements which are selected by 2nd or later ranges of Selection.
463 * When you call getFirstSelectedCell(), it resets internal counter of
464 * this method. Then, following calls of getNextSelectedCell() scans the
465 * remaining ranges of Selection. If a range selects a <td> or <th>
466 * element, returns the cell element. If a range selects an element but
467 * neither <td> nor <th> element, this ignores the range. If a range is
468 * in a text node, returns null without throwing exception, but stops
469 * scanning the remaining ranges even you call this again.
470 * Note that this may cross <table> boundaries since this method just
471 * scans all ranges of Selection. Therefore, returning cells which
472 * belong to different <table> elements.
474 * @param aNextSelectedCellRange [OUT] Returns null if this method returns
475 * null. Otherwise, i.e., found a range which
476 * selects a <td> or <th> element, returns the
477 * range.
478 * @return A <td> or <th> element if one of remaining
479 * ranges selects a <td> or <th> element unless
480 * this does not meet a range in a text node.
482 Element getNextSelectedCell(out Range aNextSelectedCellRange);