diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /editor/libeditor/HTMLEditor.cpp | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/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.cpp | 44 |
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; |