Skip to content

Commit

Permalink
Bug 1484124 - part 1: Create HTMLEditor::GetCellIndexes() class to ge…
Browse files Browse the repository at this point in the history
…t and store indexes of a table cell r=m_kato

HTMLEditor::GetCellIndexes() is an XPCOM method and used a lot internally.
So, we need alternative way to retrieve indexes of a cell without virtual
calls.  In a lot of places, receiving indexes with 2 int32_t variables causes
the code messy and that causes making it harder to understand which are
index for same cell and where they come from.  So, making both of them stored
one variable makes the callers simpler.  Therefore, this patch creates
CellIndexes stack class to get and store the result simply.  Then, this makes
all callers of GetCellIndexes() use this new class and makes GetCellIndexes()
also use this new class.

FYI: This patch does NOT put ErrorResult instances in small block scope as far as
possible. The reason is, I see its destructor in profile sometimes. I don't think
that we should use nsresult& instead of ErrorResult& only for this performance
reason, but I think that creating each instance in loops does not make sense.

Differential Revision: https://phabricator.services.mozilla.com/D3849

--HG--
extra : moz-landing-system : lando
  • Loading branch information
masayuki-nakano committed Aug 22, 2018
1 parent d344ead commit 6bba243
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 130 deletions.
59 changes: 59 additions & 0 deletions editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,65 @@ class HTMLEditor final : public TextEditor
GetNextTableRowElement(Element& aTableRowElement,
ErrorResult& aRv) const;

/**
* CellIndexes store both row index and column index of a table cell.
*/
struct MOZ_STACK_CLASS CellIndexes final
{
int32_t mRow;
int32_t mColumn;

/**
* This constructor initializes mRowIndex and mColumnIndex with indexes of
* aCellElement.
*
* @param aCellElement An <td> or <th> element.
* @param aRv Returns error if layout information is not
* available or given element is not a table cell.
*/
CellIndexes(Element& aCellElement, ErrorResult& aRv)
: mRow(-1)
, mColumn(-1)
{
MOZ_ASSERT(!aRv.Failed());
Update(aCellElement, aRv);
}

/**
* Update mRowIndex and mColumnIndex with indexes of aCellElement.
*
* @param See above.
*/
void Update(Element& aCellElement, ErrorResult& aRv);

/**
* This constructor initializes mRowIndex and mColumnIndex with indexes of
* cell element which contains anchor of Selection.
*
* @param aHTMLEditor The editor which creates the instance.
* @param aSelection The Selection for the editor.
* @param aRv Returns error if there is no cell element
* which contains anchor of Selection, or layout
* information is not available.
*/
CellIndexes(HTMLEditor& aHTMLEditor, Selection& aSelection,
ErrorResult& aRv)
: mRow(-1)
, mColumn(-1)
{
Update(aHTMLEditor, aSelection, aRv);
}

/**
* Update mRowIndex and mColumnIndex with indexes of cell element which
* contains anchor of Selection.
*
* @param See above.
*/
void Update(HTMLEditor& aHTMLEditor, Selection& aSelection,
ErrorResult& aRv);
};

/**
* PasteInternal() pasts text with replacing selected content.
* This tries to dispatch ePaste event first. If its defaultPrevent() is
Expand Down
Loading

0 comments on commit 6bba243

Please sign in to comment.