зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1671556 - part 14: Get rid of `HTMLEditor::GetFirstSelectedTableCellElement()`, `HTMLEditor::GetNextSelectedTableCellElement()` and `HTMLEditor::mSelectedCellIndex` r=m_kato
Depends on D94240 Differential Revision: https://phabricator.services.mozilla.com/D94241
This commit is contained in:
Родитель
1982467281
Коммит
7f22e0e96a
|
@ -84,7 +84,6 @@ static bool IsNamedAnchorTag(const nsAtom& aTagName) {
|
|||
HTMLEditor::HTMLEditor()
|
||||
: mCRInParagraphCreatesParagraph(false),
|
||||
mCSSAware(false),
|
||||
mSelectedCellIndex(0),
|
||||
mIsObjectResizingEnabled(
|
||||
StaticPrefs::editor_resizing_enabled_by_default()),
|
||||
mIsResizing(false),
|
||||
|
|
|
@ -757,51 +757,6 @@ class HTMLEditor final : public TextEditor,
|
|||
*/
|
||||
Element* GetSelectionContainerElement() const;
|
||||
|
||||
/**
|
||||
* GetFirstSelectedTableCellElement() returns a <td> or <th> element if
|
||||
* first range of Selection (i.e., result of Selection::GetRangeAt(0))
|
||||
* selects a <td> element or <th> element. Even if Selection is in
|
||||
* a cell element, this returns nullptr. And even if 2nd or later
|
||||
* range of Selection selects a cell element, also returns nullptr.
|
||||
* Note that when this looks for a cell element, this resets the internal
|
||||
* index of ranges of Selection. When you call
|
||||
* GetNextSelectedTableCellElement() after a call of this, it'll return 2nd
|
||||
* selected cell if there is.
|
||||
*
|
||||
* @param aRv Returns error if there is no selection or
|
||||
* first range of Selection is unexpected.
|
||||
* @return A <td> or <th> element is selected by first
|
||||
* range of Selection. Note that the range must
|
||||
* be: startContaienr and endContainer are same
|
||||
* <tr> element, startOffset + 1 equals endOffset.
|
||||
*/
|
||||
already_AddRefed<Element> GetFirstSelectedTableCellElement(
|
||||
ErrorResult& aRv) const;
|
||||
|
||||
/**
|
||||
* GetNextSelectedTableCellElement() is a stateful method to retrieve
|
||||
* selected table cell elements which are selected by 2nd or later ranges
|
||||
* of Selection. When you call GetFirstSelectedTableCellElement(), it
|
||||
* resets internal counter of this method. Then, following calls of
|
||||
* GetNextSelectedTableCellElement() scans the remaining ranges of Selection.
|
||||
* If a range selects a <td> or <th> element, returns the cell element.
|
||||
* If a range selects an element but neither <td> nor <th> element, this
|
||||
* ignores the range. If a range is in a text node, returns null without
|
||||
* throwing exception, but stops scanning the remaining ranges even you
|
||||
* call this again.
|
||||
* Note that this may cross <table> boundaries since this method just
|
||||
* scans all ranges of Selection. Therefore, returning cells which
|
||||
* belong to different <table> elements.
|
||||
*
|
||||
* @param aRv Returns error if Selection doesn't have
|
||||
* range properly.
|
||||
* @return A <td> or <th> element if one of remaining
|
||||
* ranges selects a <td> or <th> element unless
|
||||
* this does not meet a range in a text node.
|
||||
*/
|
||||
already_AddRefed<Element> GetNextSelectedTableCellElement(
|
||||
ErrorResult& aRv) const;
|
||||
|
||||
/**
|
||||
* DeleteTableCellContentsWithTransaction() removes any contents in cell
|
||||
* elements. If two or more cell elements are selected, this removes
|
||||
|
@ -4705,11 +4660,6 @@ class HTMLEditor final : public TextEditor,
|
|||
bool mCSSAware;
|
||||
UniquePtr<CSSEditUtils> mCSSEditUtils;
|
||||
|
||||
// mSelectedCellIndex is reset by GetFirstSelectedTableCellElement(),
|
||||
// then, it'll be referred and incremented by
|
||||
// GetNextSelectedTableCellElement().
|
||||
mutable uint32_t mSelectedCellIndex;
|
||||
|
||||
// resizing
|
||||
bool mIsObjectResizingEnabled;
|
||||
bool mIsResizing;
|
||||
|
|
|
@ -3907,79 +3907,6 @@ NS_IMETHODIMP HTMLEditor::GetSelectedCells(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<Element> HTMLEditor::GetFirstSelectedTableCellElement(
|
||||
ErrorResult& aRv) const {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
MOZ_ASSERT(!aRv.Failed());
|
||||
|
||||
const nsRange* firstRange = SelectionRefPtr()->GetRangeAt(0);
|
||||
if (NS_WARN_IF(!firstRange)) {
|
||||
// XXX Why don't we treat "not found" in this case?
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// XXX It must be unclear when this is reset...
|
||||
mSelectedCellIndex = 0;
|
||||
|
||||
RefPtr<Element> selectedCell =
|
||||
HTMLEditUtils::GetTableCellElementIfOnlyOneSelected(*firstRange);
|
||||
if (!selectedCell) {
|
||||
// This case means that Selection is in a text node in normal cases or
|
||||
// the range does not select only a cell. E.g., selects non-table cell
|
||||
// element, selects two or more cells, or does not select any cell element.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Setup for GetNextSelectedTableCellElement()
|
||||
// XXX Oh, increment it now? Rather than when
|
||||
// GetNextSelectedTableCellElement() is called?
|
||||
mSelectedCellIndex = 1;
|
||||
|
||||
return selectedCell.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Element> HTMLEditor::GetNextSelectedTableCellElement(
|
||||
ErrorResult& aRv) const {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
MOZ_ASSERT(!aRv.Failed());
|
||||
|
||||
if (mSelectedCellIndex >= SelectionRefPtr()->RangeCount()) {
|
||||
// We've already returned all selected cells.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mSelectedCellIndex > 0);
|
||||
for (; mSelectedCellIndex < SelectionRefPtr()->RangeCount();
|
||||
mSelectedCellIndex++) {
|
||||
const nsRange* range = SelectionRefPtr()->GetRangeAt(mSelectedCellIndex);
|
||||
if (NS_WARN_IF(!range)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!range->GetStartContainer() || !range->GetChildAtStartOffset() ||
|
||||
!range->GetEndContainer()) {
|
||||
// This means that the range is not positioned or in non-element node,
|
||||
// e.g., a text node. Returns nullptr without error if not found.
|
||||
// XXX Why don't we just skip such range or incrementing
|
||||
// mSelectedCellIndex for next call?
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (RefPtr<Element> nextSelectedCellElement =
|
||||
HTMLEditUtils::GetTableCellElementIfOnlyOneSelected(*range)) {
|
||||
mSelectedCellIndex++;
|
||||
return nextSelectedCellElement.forget();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns nullptr without error if not found.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP HTMLEditor::GetFirstSelectedCellInTable(int32_t* aRowIndex,
|
||||
int32_t* aColumnIndex,
|
||||
Element** aCellElement) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче