Bug 1916081 - Make `HTMLEditor::FocusedElementOrDocumentBecomesNotEditable` stop using `aHTMLEditor` at adjusting IME state r=m_kato

`aHTMLEditor` may be `nullptr` and there may have been an `HTMLEditor` before
it's called.  Therefore, it may need to adjust IME state even if `aHTMLEditor`
is `nullptr`.  So, it should adjust IME state from `aDocument` which should be
same as `aHTMLEditor->GetDocument()` if `aHTMLEditor` is not `nullptr`.

Note that if `IMEStateManager` thinks another `nsPresContext` has focus, it does
not touch IME state.  Therefore, it's safe to skip checking the focus state of
the `Document`.

Differential Revision: https://phabricator.services.mozilla.com/D220772
This commit is contained in:
Masayuki Nakano 2024-09-05 00:52:58 +00:00
Родитель c13abd36f2
Коммит df7aad424e
1 изменённых файлов: 8 добавлений и 10 удалений

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

@ -863,16 +863,14 @@ nsresult HTMLEditor::FocusedElementOrDocumentBecomesNotEditable(
// the editing state change. Note that if the window of the HTMLEditor has
// already lost focus, we don't need to do that and we should not touch the
// other windows.
if (aHTMLEditor->OurWindowHasFocus()) {
if (RefPtr<nsPresContext> presContext = aHTMLEditor->GetPresContext()) {
RefPtr<Element> focusedElement =
nsFocusManager::GetFocusedElementStatic();
MOZ_ASSERT_IF(focusedElement,
focusedElement->GetPresContext(
if (const RefPtr<nsPresContext> presContext = aDocument.GetPresContext()) {
const RefPtr<Element> focusedElementInDocument =
Element::FromNodeOrNull(aDocument.GetUnretargetedFocusedContent());
MOZ_ASSERT_IF(focusedElementInDocument,
focusedElementInDocument->GetPresContext(
Element::PresContextFor::eForComposedDoc));
IMEStateManager::MaybeOnEditableStateDisabled(*presContext,
focusedElement);
}
focusedElementInDocument);
}
return rv;