Bug 1858804 - Make `TextControlState::GetIMEContentObserver()` return `nullptr` if it observes for `HTMLEditor` r=smaug

`<input>` and `<textarea>` can be an editing host.  If so, setting focus to
the elements causes `IMEContentObserver` observing HTML editing under the
text control element instead of observing the native anonymous tree for the
elements.  Therefore, if `IMEContentObserver` observes it with `HTMLEditor`,
it does not need to notify `IMEContentObserver` of the `value` changes.

Differential Revision: https://phabricator.services.mozilla.com/D191163
This commit is contained in:
Masayuki Nakano 2023-10-18 07:36:34 +00:00
Родитель 7e17f8476b
Коммит e5434d6609
3 изменённых файлов: 23 добавлений и 1 удалений

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

@ -152,6 +152,9 @@ class IMEContentObserver final : public nsStubMutationObserver,
return mIMENotificationRequests &&
mIMENotificationRequests->WantDuringDeactive();
}
[[nodiscard]] bool EditorIsTextEditor() const {
return mEditorBase && mEditorBase->IsTextEditor();
}
nsIWidget* GetWidget() const { return mWidget; }
void SuppressNotifyingIME();
void UnsuppressNotifyingIME();

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

@ -3044,7 +3044,11 @@ IMEContentObserver* TextControlState::GetIMEContentObserver() const {
mTextCtrlElement != IMEStateManager::GetFocusedElement()) {
return nullptr;
}
return IMEStateManager::GetActiveContentObserver();
IMEContentObserver* observer = IMEStateManager::GetActiveContentObserver();
// The text control element may be an editing host. In this case, the
// observer does not observe the anonymous nodes under mTextCtrlElement.
// So, it means that the observer is not for ours.
return observer && observer->EditorIsTextEditor() ? observer : nullptr;
}
} // namespace mozilla

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

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
document.addEventListener("DOMContentLoaded", () => {
const input = document.querySelector("input");
input.focus();
input.type = "text";
input.value = "new value";
}, {once: true});
</script>
</head>
<body><input type="button" contenteditable></body>
</html>