Bug 1649121: part 35) Add `FragmentFromPasteCreator`. r=masayuki

First step of breaking up the complex corresponding method.

Differential Revision: https://phabricator.services.mozilla.com/D83323
This commit is contained in:
Mirko Brodesser 2020-07-14 05:13:33 +00:00
Родитель e92bbf5dd8
Коммит 9aadf57d94
1 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -216,6 +216,7 @@ class MOZ_STACK_CLASS HTMLEditor::HTMLWithContextInserter final {
bool aClearStyle);
private:
class FragmentFromPasteCreator;
class FragmentParser;
/**
* CollectTopMostChildContentsCompletelyInRange() collects topmost child
@ -3098,6 +3099,10 @@ bool HTMLEditor::HTMLWithContextInserter::FindTargetNodeOfContextForPastedHTML(
return false;
}
HTMLEditor::HTMLWithContextInserter::FragmentFromPasteCreator::
FragmentFromPasteCreator(HTMLEditor& aHTMLEditor)
: mHTMLEditor{aHTMLEditor} {}
class MOZ_STACK_CLASS HTMLEditor::HTMLWithContextInserter::FragmentParser
final {
public:
@ -3137,12 +3142,40 @@ nsresult HTMLEditor::HTMLWithContextInserter::FragmentParser::ParsePastedHTML(
&mDocument, aFragment, mTrustedInput);
}
class MOZ_STACK_CLASS
HTMLEditor::HTMLWithContextInserter::FragmentFromPasteCreator final {
public:
explicit FragmentFromPasteCreator(HTMLEditor& aHTMLEditor);
nsresult Run(const nsAString& aInputString, const nsAString& aContextStr,
const nsAString& aInfoStr, nsCOMPtr<nsINode>* aOutFragNode,
nsCOMPtr<nsINode>* aOutStartNode, nsCOMPtr<nsINode>* aOutEndNode,
int32_t* aOutStartOffset, int32_t* aOutEndOffset,
bool aTrustedInput) const;
private:
HTMLEditor& mHTMLEditor;
};
nsresult HTMLEditor::HTMLWithContextInserter::CreateDOMFragmentFromPaste(
const nsAString& aInputString, const nsAString& aContextStr,
const nsAString& aInfoStr, nsCOMPtr<nsINode>* aOutFragNode,
nsCOMPtr<nsINode>* aOutStartNode, nsCOMPtr<nsINode>* aOutEndNode,
int32_t* aOutStartOffset, int32_t* aOutEndOffset,
bool aTrustedInput) const {
FragmentFromPasteCreator fragmentFromPasteCreator{mHTMLEditor};
return fragmentFromPasteCreator.Run(
aInputString, aContextStr, aInfoStr, aOutFragNode, aOutStartNode,
aOutEndNode, aOutStartOffset, aOutEndOffset, aTrustedInput);
}
nsresult HTMLEditor::HTMLWithContextInserter::FragmentFromPasteCreator::Run(
const nsAString& aInputString, const nsAString& aContextStr,
const nsAString& aInfoStr, nsCOMPtr<nsINode>* aOutFragNode,
nsCOMPtr<nsINode>* aOutStartNode, nsCOMPtr<nsINode>* aOutEndNode,
int32_t* aOutStartOffset, int32_t* aOutEndOffset,
bool aTrustedInput) const {
if (NS_WARN_IF(!aOutFragNode) || NS_WARN_IF(!aOutStartNode) ||
NS_WARN_IF(!aOutEndNode) || NS_WARN_IF(!aOutStartOffset) ||
NS_WARN_IF(!aOutEndOffset)) {