`HTMLEditor` currently checks whether it's in the `designMode` or not with
checking the `Document` node is in the `designMode`. I.e., it checks the
real-time state of the `Document` node. However, if an instance was in the
`designMode`, it needs to finalize `Selection` even after the `Document` node
becomes not in the `designMode`. Additionally, elements in a shadow DOM in the
`designMode` can have `contenteditable` to make it editable. Then, the editable
elements should works as in the `contenteditable` mode rather than in the
`designMode`. Therefore, current `HTMLEditor::IsInDesignMode()` returns
wrong state when the finalization is called asynchronously or when an editing
host in a shadow DOM whose composed document is in the `designMode`.
This patch fixes known cases of these issues with improving the finalization
(and re-initialization with the new editing mode) and the caller side in
`Document`.
Differential Revision: https://phabricator.services.mozilla.com/D216022