Skip to content

Commit

Permalink
Bug 1611751 - Remove unused scriptable methods of nsIHTMLEditor, `n…
Browse files Browse the repository at this point in the history
…sIEditorStyleSheets` and `nsITableEditor` r=m_kato

* `nsIHTMLEditor.removeAllInlineProperties`
* `nsIHTMLEditor.increaseFontSize`
* `nsIHTMLEditor.decreaseFontSize`
* `nsIHTMLEditor.setParagraphFormat`
* `nsIHTMLEditor.getBackgroundColorState`
* `nsIHTMLEditor.indent`
* `nsIHTMLEditor.align`
* `nsIEditorStyleSheets.replaceOverrideStyleSheet`
* `nsITableEditor.selectBlockOfCells`

These methods are not used by any Gecko products including comm-central and
BlueGriffon so that we should remove them.  Note that only
`HTMLEditor::GetBackgroundColorState()` is used internally so that we need to
keep it as a public method of `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D61139
  • Loading branch information
masayuki-nakano committed Jan 30, 2020
1 parent 4c0cbb3 commit 9a71a5c
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 284 deletions.
4 changes: 0 additions & 4 deletions editor/libeditor/EditAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ enum class EditAction {
// eRemoveOverrideStyleSheet indicates to remove override style sheet.
eRemoveOverrideStyleSheet,

// eReplaceOverrideStyleSheet indicates to replace added override style
// sheet with new override style sheet.
eReplaceOverrideStyleSheet,

// eEnableStyleSheet indicates to apply a style sheet.
eEnableStyleSheet,

Expand Down
1 change: 0 additions & 1 deletion editor/libeditor/EditorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,6 @@ class EditorBase : public nsIPlaintextEditor,
// We don't need to let web apps know changing UA stylesheet.
case EditAction::eAddOverrideStyleSheet:
case EditAction::eRemoveOverrideStyleSheet:
case EditAction::eReplaceOverrideStyleSheet:
// We don't need to let web apps know the mode change.
case EditAction::eEnableStyleSheet:
case EditAction::eEnableOrDisableCSS:
Expand Down
67 changes: 2 additions & 65 deletions editor/libeditor/HTMLEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1824,13 +1824,6 @@ nsresult HTMLEditor::CollapseSelectionAfter(Element& aElement) {
return NS_OK;
}

NS_IMETHODIMP
HTMLEditor::SetParagraphFormat(const nsAString& aParagraphFormat) {
nsresult rv = SetParagraphFormatAsAction(aParagraphFormat);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to set paragraph format");
return rv;
}

nsresult HTMLEditor::SetParagraphFormatAsAction(
const nsAString& aParagraphFormat, nsIPrincipal* aPrincipal) {
AutoEditActionDataSetter editActionData(
Expand Down Expand Up @@ -1882,8 +1875,8 @@ HTMLEditor::GetParagraphState(bool* aMixed, nsAString& aFirstParagraphState) {
return NS_OK;
}

NS_IMETHODIMP
HTMLEditor::GetBackgroundColorState(bool* aMixed, nsAString& aOutColor) {
nsresult HTMLEditor::GetBackgroundColorState(bool* aMixed,
nsAString& aOutColor) {
if (NS_WARN_IF(!aMixed)) {
return NS_ERROR_INVALID_ARG;
}
Expand Down Expand Up @@ -2278,21 +2271,6 @@ nsresult HTMLEditor::FormatBlockContainerAsSubAction(nsAtom& aTagName) {
return rv;
}

NS_IMETHODIMP
HTMLEditor::Indent(const nsAString& aIndent) {
if (aIndent.LowerCaseEqualsLiteral("indent")) {
nsresult rv = IndentAsAction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to indent");
return rv;
}
if (aIndent.LowerCaseEqualsLiteral("outdent")) {
nsresult rv = OutdentAsAction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to outdent");
return rv;
}
return NS_ERROR_INVALID_ARG;
}

nsresult HTMLEditor::IndentAsAction(nsIPrincipal* aPrincipal) {
if (NS_WARN_IF(!mInitSucceeded)) {
return NS_ERROR_NOT_INITIALIZED;
Expand Down Expand Up @@ -2329,13 +2307,6 @@ nsresult HTMLEditor::OutdentAsAction(nsIPrincipal* aPrincipal) {

// TODO: IMPLEMENT ALIGNMENT!

NS_IMETHODIMP
HTMLEditor::Align(const nsAString& aAlignType) {
nsresult rv = AlignAsAction(aAlignType);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to align content");
return EditorBase::ToGenericNSResult(rv);
}

nsresult HTMLEditor::AlignAsAction(const nsAString& aAlignType,
nsIPrincipal* aPrincipal) {
AutoEditActionDataSetter editActionData(
Expand Down Expand Up @@ -2918,9 +2889,6 @@ nsresult HTMLEditor::AddOverrideStyleSheetInternal(const nsAString& aURL) {
presShell->AddOverrideStyleSheet(sheet);
presShell->GetDocument()->ApplicableStylesChanged();

// Save as the last-loaded sheet
mLastOverrideStyleSheetURL = aURL;

// Add URL and style sheet to our lists
rv = AddNewStyleSheetToList(aURL, sheet);
if (NS_WARN_IF(NS_FAILED(rv))) {
Expand All @@ -2929,37 +2897,6 @@ nsresult HTMLEditor::AddOverrideStyleSheetInternal(const nsAString& aURL) {
return NS_OK;
}

NS_IMETHODIMP
HTMLEditor::ReplaceOverrideStyleSheet(const nsAString& aURL) {
AutoEditActionDataSetter editActionData(
*this, EditAction::eReplaceOverrideStyleSheet);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return NS_ERROR_NOT_INITIALIZED;
}

// Enable existing sheet if already loaded.
if (EnableExistingStyleSheet(aURL)) {
// Disable last sheet if not the same as new one
if (!mLastOverrideStyleSheetURL.IsEmpty() &&
!mLastOverrideStyleSheetURL.Equals(aURL)) {
EnableStyleSheetInternal(mLastOverrideStyleSheetURL, false);
}
return NS_OK;
}
// Remove the previous sheet
if (!mLastOverrideStyleSheetURL.IsEmpty()) {
DebugOnly<nsresult> rv =
RemoveOverrideStyleSheetInternal(mLastOverrideStyleSheetURL);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to remove the last override style sheet");
}
nsresult rv = AddOverrideStyleSheetInternal(aURL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}

// Do NOT use transaction system for override style sheets
NS_IMETHODIMP
HTMLEditor::RemoveOverrideStyleSheet(const nsAString& aURL) {
Expand Down
12 changes: 9 additions & 3 deletions editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ class HTMLEditor final : public TextEditor,
virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) override;
virtual nsresult GetPreferredIMEState(widget::IMEState* aState) override;

/**
* GetBackgroundColorState() returns what the background color of the
* selection.
*
* @param aMixed true if there is more than one font color
* @param aOutColor Color string. "" is returned for none.
*/
nsresult GetBackgroundColorState(bool* aMixed, nsAString& aOutColor);

/**
* PasteNoFormatting() pastes content in clipboard without any style
* information.
Expand Down Expand Up @@ -4370,9 +4379,6 @@ class HTMLEditor final : public TextEditor,
// GetNextSelectedTableCellElement().
mutable uint32_t mSelectedCellIndex;

nsString mLastStyleSheetURL;
nsString mLastOverrideStyleSheetURL;

// Maintain a list of associated style sheets and their urls.
nsTArray<nsString> mStyleSheetURLs;
nsTArray<RefPtr<StyleSheet>> mStyleSheets;
Expand Down
21 changes: 0 additions & 21 deletions editor/libeditor/HTMLStyleEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,13 +1420,6 @@ nsresult HTMLEditor::GetInlinePropertyWithAttrValue(
return NS_OK;
}

NS_IMETHODIMP
HTMLEditor::RemoveAllInlineProperties() {
nsresult rv = RemoveAllInlinePropertiesAsAction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to remove all inline styles");
return rv;
}

nsresult HTMLEditor::RemoveAllInlinePropertiesAsAction(
nsIPrincipal* aPrincipal) {
AutoEditActionDataSetter editActionData(
Expand Down Expand Up @@ -1850,13 +1843,6 @@ void HTMLEditor::CollectEditableLeafTextNodes(
}
}

NS_IMETHODIMP
HTMLEditor::IncreaseFontSize() {
nsresult rv = IncreaseFontSizeAsAction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to increase font size");
return rv;
}

nsresult HTMLEditor::IncreaseFontSizeAsAction(nsIPrincipal* aPrincipal) {
AutoEditActionDataSetter editActionData(*this, EditAction::eIncrementFontSize,
aPrincipal);
Expand All @@ -1871,13 +1857,6 @@ nsresult HTMLEditor::IncreaseFontSizeAsAction(nsIPrincipal* aPrincipal) {
return EditorBase::ToGenericNSResult(rv);
}

NS_IMETHODIMP
HTMLEditor::DecreaseFontSize() {
nsresult rv = DecreaseFontSizeAsAction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to decrease font size");
return rv;
}

nsresult HTMLEditor::DecreaseFontSizeAsAction(nsIPrincipal* aPrincipal) {
AutoEditActionDataSetter editActionData(*this, EditAction::eDecrementFontSize,
aPrincipal);
Expand Down
115 changes: 0 additions & 115 deletions editor/libeditor/HTMLTableEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,121 +1787,6 @@ HTMLEditor::SelectTableCell() {
return NS_OK;
}

NS_IMETHODIMP
HTMLEditor::SelectBlockOfCells(Element* aStartCell, Element* aEndCell) {
if (NS_WARN_IF(!aStartCell) || NS_WARN_IF(!aEndCell)) {
return NS_ERROR_INVALID_ARG;
}

AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return NS_ERROR_NOT_INITIALIZED;
}

RefPtr<Element> table =
GetElementOrParentByTagNameInternal(*nsGkAtoms::table, *aStartCell);
if (NS_WARN_IF(!table)) {
return NS_ERROR_FAILURE;
}

RefPtr<Element> endTable =
GetElementOrParentByTagNameInternal(*nsGkAtoms::table, *aEndCell);
if (NS_WARN_IF(!endTable)) {
return NS_ERROR_FAILURE;
}

// We can only select a block if within the same table,
// so do nothing if not within one table
if (table != endTable) {
return NS_OK;
}

ErrorResult error;
CellIndexes startCellIndexes(*aStartCell, error);
if (NS_WARN_IF(error.Failed())) {
return EditorBase::ToGenericNSResult(error.StealNSResult());
}
CellIndexes endCellIndexes(*aEndCell, error);
if (NS_WARN_IF(error.Failed())) {
return EditorBase::ToGenericNSResult(error.StealNSResult());
}

// Suppress nsISelectionListener notification
// until all selection changes are finished
SelectionBatcher selectionBatcher(SelectionRefPtr());

// Examine all cell nodes in current selection and
// remove those outside the new block cell region
int32_t minColumn =
std::min(startCellIndexes.mColumn, endCellIndexes.mColumn);
int32_t minRow = std::min(startCellIndexes.mRow, endCellIndexes.mRow);
int32_t maxColumn =
std::max(startCellIndexes.mColumn, endCellIndexes.mColumn);
int32_t maxRow = std::max(startCellIndexes.mRow, endCellIndexes.mRow);

RefPtr<Element> cell = GetFirstSelectedTableCellElement(error);
if (NS_WARN_IF(error.Failed())) {
return EditorBase::ToGenericNSResult(error.StealNSResult());
}
if (!cell) {
return NS_OK;
}
RefPtr<nsRange> range = SelectionRefPtr()->GetRangeAt(0);
MOZ_ASSERT(range);
while (cell) {
CellIndexes currentCellIndexes(*cell, error);
if (NS_WARN_IF(error.Failed())) {
return EditorBase::ToGenericNSResult(error.StealNSResult());
}
if (currentCellIndexes.mRow < maxRow || currentCellIndexes.mRow > maxRow ||
currentCellIndexes.mColumn < maxColumn ||
currentCellIndexes.mColumn > maxColumn) {
SelectionRefPtr()->RemoveRangeAndUnselectFramesAndNotifyListeners(
*range, IgnoreErrors());
// Since we've removed the range, decrement pointer to next range
MOZ_ASSERT(mSelectedCellIndex > 0);
mSelectedCellIndex--;
}
cell = GetNextSelectedTableCellElement(error);
if (NS_WARN_IF(error.Failed())) {
return EditorBase::ToGenericNSResult(error.StealNSResult());
}
if (cell) {
MOZ_ASSERT(mSelectedCellIndex > 0);
range = SelectionRefPtr()->GetRangeAt(mSelectedCellIndex - 1);
}
}

nsresult rv = NS_OK;
IgnoredErrorResult ignoredError;
for (int32_t row = minRow; row <= maxRow; row++) {
CellData cellData;
for (int32_t col = minColumn; col <= maxColumn;
col = cellData.NextColumnIndex()) {
cellData.Update(*this, *table, row, col, ignoredError);
if (cellData.FailedOrNotFound()) {
return NS_ERROR_FAILURE;
}

// Skip cells that already selected or are spanned from previous locations
// XXX So, we should distinguish whether CellData returns error or just
// not found later.
if (!cellData.mIsSelected && cellData.mElement &&
!cellData.IsSpannedFromOtherRowOrColumn()) {
rv = AppendNodeToSelectionAsRange(cellData.mElement);
if (NS_FAILED(rv)) {
break;
}
}
MOZ_ASSERT(col < cellData.NextColumnIndex());
}
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv);
}
return rv;
}

NS_IMETHODIMP
HTMLEditor::SelectAllTableCells() {
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
Expand Down
13 changes: 2 additions & 11 deletions editor/nsIEditorStyleSheets.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[scriptable, builtinclass, uuid(4805e682-49b9-11d3-9ce4-ed60bd6cb5bc)]
interface nsIEditorStyleSheets : nsISupports
{
/** Load and apply the override style sheet, specified by aURL, to the
* editor's document, replacing the last override style sheet added (if any).
/** Load and apply an override style sheet, specified by aURL, to
* the editor's document, on top of any that are already there.
* This is always synchronous, so aURL should be a local file with only
* local @imports. This action is not undoable. It is not intended for
* "user" style sheets, only for editor developers to add sheets to change
Expand All @@ -19,15 +19,6 @@ interface nsIEditorStyleSheets : nsISupports
*
* @param aURL The style sheet to be loaded and applied.
*/
void replaceOverrideStyleSheet(in AString aURL);

/** Load and apply an override style sheet, specified by aURL, to
* the editor's document, on top of any that are already there.
* This is always synchronous, so the same caveats about local files and no
* non-local @import as replaceOverrideStyleSheet apply here, too.
*
* @param aURL The style sheet to be loaded and applied.
*/
void addOverrideStyleSheet(in AString aURL);

/** Remove the given override style sheet from the editor's document
Expand Down
Loading

0 comments on commit 9a71a5c

Please sign in to comment.