Bug 1460509 - part 30: Make HTMLEditRules::ReapplyCachedStyles() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: HSv2els7Lys
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -1400,17 +1400,19 @@ HTMLEditRules::WillInsert(bool* aCancel)
}
}
if (mDidDeleteSelection &&
(mTheAction == EditAction::insertText ||
mTheAction == EditAction::insertIMEText ||
mTheAction == EditAction::deleteSelection)) {
nsresult rv = ReapplyCachedStyles();
- NS_ENSURE_SUCCESS_VOID(rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return;
+ }
}
// For most actions we want to clear the cached styles, but there are
// exceptions
if (!IsStyleCachePreservingAction(mTheAction)) {
ClearCachedStyles();
}
}
@@ -8534,18 +8536,22 @@ HTMLEditRules::ReapplyCachedStyles()
// remember if we are in css mode
bool useCSS = HTMLEditorRef().IsCSSEnabled();
if (!SelectionRef().RangeCount()) {
// Nothing to do
return NS_OK;
}
+ const RangeBoundary& atStartOfSelection =
+ SelectionRef().GetRangeAt(0)->StartRef();
nsCOMPtr<nsIContent> selNode =
- do_QueryInterface(SelectionRef().GetRangeAt(0)->GetStartContainer());
+ atStartOfSelection.Container() &&
+ atStartOfSelection.Container()->IsContent() ?
+ atStartOfSelection.Container()->AsContent() : nullptr;
if (!selNode) {
// Nothing to do
return NS_OK;
}
StyleCache styleAtInsertionPoint[SIZE_STYLE_TABLE];
InitStyleCacheArray(styleAtInsertionPoint);
nsresult rv = GetInlineStyles(selNode, styleAtInsertionPoint);
@@ -8559,25 +8565,31 @@ HTMLEditRules::ReapplyCachedStyles()
bFirst = bAny = bAll = false;
nsAutoString curValue;
if (useCSS) {
// check computed style first in css case
bAny = CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
selNode, mCachedStyles[i].tag, mCachedStyles[i].attr, curValue,
CSSEditUtils::eComputed);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
}
if (!bAny) {
// then check typeinstate and html style
nsresult rv =
HTMLEditorRef().GetInlinePropertyBase(*mCachedStyles[i].tag,
mCachedStyles[i].attr,
&(mCachedStyles[i].value),
&bFirst, &bAny, &bAll,
&curValue);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// This style has disappeared through deletion. Let's add the styles to
// mTypeInState when same style isn't applied to the node already.
if ((!bAny || IsStyleCachePreservingAction(mTheAction)) &&
(!styleAtInsertionPoint[i].mPresent ||
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -586,17 +586,24 @@ protected:
* Finally, aListElement is removed. and its all children are moved to
* where the aListElement was.
*
* @param aListElement A <ul>, <ol> or <dl> element.
*/
MOZ_MUST_USE nsresult RemoveListStructure(Element& aListElement);
nsresult CacheInlineStyles(nsINode* aNode);
- nsresult ReapplyCachedStyles();
+
+ /**
+ * ReapplyCachedStyles() restores some styles which are disappeared during
+ * handling edit action and it should be restored. This may cause flushing
+ * layout at retrieving computed value of CSS properties.
+ */
+ MOZ_MUST_USE nsresult ReapplyCachedStyles();
+
void ClearCachedStyles();
/**
* InsertBRElementToEmptyListItemsAndTableCellsInChangedRange() inserts
* <br> element into empty list item or table cell elements.
*/
MOZ_MUST_USE nsresult
InsertBRElementToEmptyListItemsAndTableCellsInChangedRange();