Skip to content

Commit

Permalink
Bug 1484125 - part 1: Create TableSize struct to compute and store nu…
Browse files Browse the repository at this point in the history
…mber of rows and columns of a <table> element r=m_kato

HTMLEditor::GetTableSize() is an XPCOM method but used internally a lot.
Therefore, it shouldn't be called for internal use.  Additionally, the
callers need to declare two int32_t variables, but this causes the code
messy.  Therefore, this patch creates TableSize struct and it implements
HTMLEditor::GetTableSize().  Then, all callers of it is replaced with
TableSize struct.

New TableSize struct does not support computes <table> element from anchor
of Selection since there is no user of this in C++ code.

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
masayuki-nakano committed Aug 23, 2018
1 parent c5f59ca commit 41eb258
Show file tree
Hide file tree
Showing 3 changed files with 363 additions and 182 deletions.
39 changes: 39 additions & 0 deletions editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,45 @@ class HTMLEditor final : public TextEditor
ErrorResult& aRv);
};

/**
* TableSize stores and computes number of rows and columns of a <table>
* element.
*/
struct MOZ_STACK_CLASS TableSize final
{
int32_t mRowCount;
int32_t mColumnCount;

/**
* @param aHTMLEditor The editor which creates the instance.
* @param aTableOrElementInTable If a <table> element, computes number
* of rows and columns of it.
* If another element in a <table> element,
* computes number of rows and columns
* of nearest ancestor <table> element.
* Otherwise, i.e., non-<table> element
* not in <table>, returns error.
* @param aRv Returns error if the element is not
* in <table> or layout information is
* not available.
*/
TableSize(HTMLEditor& aHTMLEditor, Element& aTableOrElementInTable,
ErrorResult& aRv)
: mRowCount(-1)
, mColumnCount(-1)
{
MOZ_ASSERT(!aRv.Failed());
Update(aHTMLEditor, aTableOrElementInTable, aRv);
}

/**
* Update mRowCount and mColumnCount for aTableOrElementInTable.
* See above for the detail.
*/
void Update(HTMLEditor& aHTMLEditor, Element& aTableOrElementInTable,
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 41eb258

Please sign in to comment.