diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index dadb26c6823c..591643aede20 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -353,6 +353,33 @@ public: return NS_OK; } + /** + * GetFontColorState() returns foreground color information in first + * range of Selection. + * If first range of Selection is collapsed and there is a cache of style for + * new text, aIsMixed is set to false and aColor is set to the cached color. + * If first range of Selection is collapsed and there is no cached color, + * this returns the color of the node, aIsMixed is set to false and aColor is + * set to the color. + * If first range of Selection is not collapsed, this collects colors of + * each node in the range. If there are two or more colors, aIsMixed is set + * to true and aColor is truncated. If only one color is set to all of the + * range, aIsMixed is set to false and aColor is set to the color. + * If there is no Selection ranges, aIsMixed is set to false and aColor is + * truncated. + * + * @param aIsMixed Must not be nullptr. This is set to true + * if there is two or more colors in first + * range of Selection. + * @param aColor Returns the color if only one color is set to + * all of first range in Selection. Otherwise, + * returns empty string. + * @return Returns error only when illegal cases, e.g., + * Selection instance has gone, first range + * Selection is broken. + */ + nsresult GetFontColorState(bool* aIsMixed, nsAString& aColor); + /** * SetComposerCommandsUpdater() sets or unsets mComposerCommandsUpdater. * This will crash in debug build if the editor already has an instance diff --git a/editor/libeditor/HTMLEditorCommands.cpp b/editor/libeditor/HTMLEditorCommands.cpp index fb73127137be..f16b0382eead 100644 --- a/editor/libeditor/HTMLEditorCommands.cpp +++ b/editor/libeditor/HTMLEditorCommands.cpp @@ -880,7 +880,9 @@ FontColorStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor, bool outMixed; nsAutoString outStateString; nsresult rv = aHTMLEditor->GetFontColorState(&outMixed, outStateString); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } nsAutoCString tOutStateString; LossyCopyUTF16toASCII(outStateString, tOutStateString); diff --git a/editor/libeditor/HTMLStyleEditor.cpp b/editor/libeditor/HTMLStyleEditor.cpp index a2686b2c7c4b..47162823b489 100644 --- a/editor/libeditor/HTMLStyleEditor.cpp +++ b/editor/libeditor/HTMLStyleEditor.cpp @@ -1760,20 +1760,25 @@ HTMLEditor::GetFontFaceState(bool* aMixed, return NS_OK; } -NS_IMETHODIMP +nsresult HTMLEditor::GetFontColorState(bool* aMixed, nsAString& aOutColor) { - NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER); + if (NS_WARN_IF(!aMixed)) { + return NS_ERROR_INVALID_ARG; + } + *aMixed = true; aOutColor.Truncate(); bool first, any, all; - nsresult rv = GetInlinePropertyBase(*nsGkAtoms::font, nsGkAtoms::color, nullptr, &first, &any, &all, &aOutColor); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + if (any && !all) { return NS_OK; // mixed } diff --git a/editor/nsIHTMLEditor.idl b/editor/nsIHTMLEditor.idl index 64056de2ecd3..f1ff4fa53c24 100644 --- a/editor/nsIHTMLEditor.idl +++ b/editor/nsIHTMLEditor.idl @@ -224,14 +224,7 @@ interface nsIHTMLEditor : nsISupports AString getFontFaceState(out boolean aMixed); /** - * getFontColorState returns what font face is in the selection. - * @param aMixed True if there is more than one font color - * @return Color string. "" is returned for none. - */ - AString getFontColorState(out boolean aMixed); - - /** - * getFontColorState returns what font face is in the selection. + * getBackgroundColorState returns what the background color of the selection. * @param aMixed True if there is more than one font color * @return Color string. "" is returned for none. */