summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/HTMLEditor.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /editor/libeditor/HTMLEditor.cpp
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/libeditor/HTMLEditor.cpp')
-rw-r--r--editor/libeditor/HTMLEditor.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index 9f4aab3dab..e9ea8887b7 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -719,14 +719,33 @@ void HTMLEditor::UpdateRootElement() {
nsresult HTMLEditor::FocusedElementOrDocumentBecomesEditable(
Document& aDocument, Element* aElement) {
+ const bool isInDesignMode =
+ (IsInDesignMode() && (!aElement || aElement->IsInDesignMode()));
+
// If we should've already handled focus event, selection limiter should not
- // be set. Therefore, if it's set, we should do nothing here.
+ // be set. However, IMEStateManager is not notified the pseudo focus change
+ // in this case. Therefore, we need to notify IMEStateManager of this.
if (GetSelectionAncestorLimiter()) {
+ if (isInDesignMode) {
+ return NS_OK;
+ }
+ // Although editor is already initialized due to re-used, ISM may not
+ // create IME content observer yet. So we have to create it.
+ IMEState newState;
+ nsresult rv = GetPreferredIMEState(&newState);
+ if (NS_FAILED(rv)) {
+ NS_WARNING("EditorBase::GetPreferredIMEState() failed");
+ return NS_OK;
+ }
+ if (const RefPtr<Element> focusedElement = GetFocusedElement()) {
+ MOZ_ASSERT(focusedElement == aElement);
+ IMEStateManager::UpdateIMEState(newState, focusedElement, *this);
+ }
return NS_OK;
}
// If we should be in the design mode, we want to handle focus event fired
// on the document node. Therefore, we should emulate it here.
- if (IsInDesignMode() && (!aElement || aElement->IsInDesignMode())) {
+ if (isInDesignMode) {
MOZ_ASSERT(&aDocument == GetDocument());
nsresult rv = OnFocus(aDocument);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::OnFocus() failed");
@@ -5949,14 +5968,23 @@ bool HTMLEditor::IsEmpty() const {
return true;
}
- // XXX Oddly, we check body or document element's state instead of
- // active editing host. Must be a bug.
- Element* bodyOrDocumentElement = GetRoot();
- if (!bodyOrDocumentElement) {
- return true;
+ const Element* activeElement =
+ GetDocument() ? GetDocument()->GetActiveElement() : nullptr;
+ const Element* editingHostOrBodyOrRootElement =
+ activeElement && activeElement->IsEditable()
+ ? ComputeEditingHost(*activeElement, LimitInBodyElement::No)
+ : ComputeEditingHost(LimitInBodyElement::No);
+ if (MOZ_UNLIKELY(!editingHostOrBodyOrRootElement)) {
+ // If there is no active element nor no selection range in the document,
+ // let's check entire the document as what we do traditionally.
+ editingHostOrBodyOrRootElement = GetRoot();
+ if (!editingHostOrBodyOrRootElement) {
+ return true;
+ }
}
- for (nsIContent* childContent = bodyOrDocumentElement->GetFirstChild();
+ for (nsIContent* childContent =
+ editingHostOrBodyOrRootElement->GetFirstChild();
childContent; childContent = childContent->GetNextSibling()) {
if (!childContent->IsText() || childContent->Length()) {
return false;