From e005079968112366f6666d0fda5e8d89934675bf Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Tue, 4 Nov 2014 20:25:47 -0800 Subject: [PATCH] Backed out changeset f86dbba73d43 (bug 1047588) under suspicion of adding a hazard on a CLOSED TREE --- dom/events/IMEContentObserver.cpp | 29 ++++++++++++++++----- dom/events/IMEContentObserver.h | 2 +- dom/events/IMEStateManager.cpp | 30 ++++++++++------------ dom/events/IMEStateManager.h | 9 +++---- editor/libeditor/nsEditor.cpp | 4 +-- editor/libeditor/nsEditorEventListener.cpp | 3 +-- 6 files changed, 43 insertions(+), 34 deletions(-) diff --git a/dom/events/IMEContentObserver.cpp b/dom/events/IMEContentObserver.cpp index 836c6882abce..5620004d9fe4 100644 --- a/dom/events/IMEContentObserver.cpp +++ b/dom/events/IMEContentObserver.cpp @@ -28,6 +28,7 @@ #include "nsISelectionController.h" #include "nsISelectionPrivate.h" #include "nsISupports.h" +#include "nsITextControlElement.h" #include "nsIWidget.h" #include "nsPresContext.h" #include "nsThreadUtils.h" @@ -98,11 +99,8 @@ IMEContentObserver::IMEContentObserver() void IMEContentObserver::Init(nsIWidget* aWidget, nsPresContext* aPresContext, - nsIContent* aContent, - nsIEditor* aEditor) + nsIContent* aContent) { - MOZ_ASSERT(aEditor, "aEditor must not be null"); - mESM = aPresContext->EventStateManager(); mESM->OnStartToObserveContent(this); @@ -112,8 +110,27 @@ IMEContentObserver::Init(nsIWidget* aWidget, return; } - mEditor = aEditor; - mEditor->AddEditorObserver(this); + nsCOMPtr textControlElement = + do_QueryInterface(mEditableNode); + if (textControlElement) { + // This may fail. For example, + mEditor = textControlElement->GetTextEditor(); + if (!mEditor && mEditableNode->IsContent()) { + // The element must be an editing host. + nsIContent* editingHost = mEditableNode->AsContent()->GetEditingHost(); + MOZ_ASSERT(editingHost == mEditableNode, + "found editing host should be mEditableNode"); + if (editingHost == mEditableNode) { + mEditor = nsContentUtils::GetHTMLEditor(aPresContext); + } + } + } else { + mEditor = nsContentUtils::GetHTMLEditor(aPresContext); + } + MOZ_ASSERT(mEditor, "Failed to get editor"); + if (mEditor) { + mEditor->AddEditorObserver(this); + } nsIPresShell* presShell = aPresContext->PresShell(); diff --git a/dom/events/IMEContentObserver.h b/dom/events/IMEContentObserver.h index 43a67f5a0224..f8dba04917f9 100644 --- a/dom/events/IMEContentObserver.h +++ b/dom/events/IMEContentObserver.h @@ -64,7 +64,7 @@ public: WidgetMouseEvent* aMouseEvent); void Init(nsIWidget* aWidget, nsPresContext* aPresContext, - nsIContent* aContent, nsIEditor* aEditor); + nsIContent* aContent); void Destroy(); /** * IMEContentObserver is stored by EventStateManager during observing. diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 5e3722613f6a..663dd8baa2b5 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -25,7 +25,6 @@ #include "nsIContent.h" #include "nsIDocument.h" #include "nsIDOMMouseEvent.h" -#include "nsIEditor.h" #include "nsIForm.h" #include "nsIFormControl.h" #include "nsINode.h" @@ -560,14 +559,12 @@ IMEStateManager::OnClickInEditor(nsPresContext* aPresContext, // static void IMEStateManager::OnFocusInEditor(nsPresContext* aPresContext, - nsIContent* aContent, - nsIEditor* aEditor) + nsIContent* aContent) { PR_LOG(sISMLog, PR_LOG_ALWAYS, - ("ISM: IMEStateManager::OnFocusInEditor(aPresContext=0x%p, aContent=0x%p, " - "aEditor=0x%p), sPresContext=0x%p, sContent=0x%p, " - "sActiveIMEContentObserver=0x%p", - aPresContext, aContent, aEditor, sPresContext, sContent, + ("ISM: IMEStateManager::OnFocusInEditor(aPresContext=0x%p, aContent=0x%p), " + "sPresContext=0x%p, sContent=0x%p, sActiveIMEContentObserver=0x%p", + aPresContext, aContent, sPresContext, sContent, sActiveIMEContentObserver)); if (sPresContext != aPresContext || sContent != aContent) { @@ -589,22 +586,21 @@ IMEStateManager::OnFocusInEditor(nsPresContext* aPresContext, DestroyIMEContentObserver(); } - CreateIMEContentObserver(aEditor); + CreateIMEContentObserver(); } // static void IMEStateManager::UpdateIMEState(const IMEState& aNewIMEState, - nsIContent* aContent, - nsIEditor* aEditor) + nsIContent* aContent) { PR_LOG(sISMLog, PR_LOG_ALWAYS, ("ISM: IMEStateManager::UpdateIMEState(aNewIMEState={ mEnabled=%s, " - "mOpen=%s }, aContent=0x%p, aEditor=0x%p), " + "mOpen=%s }, aContent=0x%p), " "sPresContext=0x%p, sContent=0x%p, sActiveIMEContentObserver=0x%p, " "sIsGettingNewIMEState=%s", GetIMEStateEnabledName(aNewIMEState.mEnabled), - GetIMEStateSetOpenName(aNewIMEState.mOpen), aContent, aEditor, + GetIMEStateSetOpenName(aNewIMEState.mOpen), aContent, sPresContext, sContent, sActiveIMEContentObserver, GetBoolName(sIsGettingNewIMEState))); @@ -655,7 +651,7 @@ IMEStateManager::UpdateIMEState(const IMEState& aNewIMEState, } if (createTextStateManager) { - CreateIMEContentObserver(aEditor); + CreateIMEContentObserver(); } } @@ -1149,13 +1145,13 @@ IMEStateManager::DestroyIMEContentObserver() // static void -IMEStateManager::CreateIMEContentObserver(nsIEditor* aEditor) +IMEStateManager::CreateIMEContentObserver() { PR_LOG(sISMLog, PR_LOG_ALWAYS, - ("ISM: IMEStateManager::CreateIMEContentObserver(aEditor=0x%p), " + ("ISM: IMEStateManager::CreateIMEContentObserver(), " "sPresContext=0x%p, sContent=0x%p, sActiveIMEContentObserver=0x%p, " "sActiveIMEContentObserver->IsManaging(sPresContext, sContent)=%s", - aEditor, sPresContext, sContent, sActiveIMEContentObserver, + sPresContext, sContent, sActiveIMEContentObserver, GetBoolName(sActiveIMEContentObserver ? sActiveIMEContentObserver->IsManaging(sPresContext, sContent) : false))); @@ -1199,7 +1195,7 @@ IMEStateManager::CreateIMEContentObserver(nsIEditor* aEditor) // instance. So, sActiveIMEContentObserver would be replaced with new one. // We should hold the current instance here. nsRefPtr kungFuDeathGrip(sActiveIMEContentObserver); - sActiveIMEContentObserver->Init(widget, sPresContext, sContent, aEditor); + sActiveIMEContentObserver->Init(widget, sPresContext, sContent); } // static diff --git a/dom/events/IMEStateManager.h b/dom/events/IMEStateManager.h index 01ad078ac383..665edcc2d0f1 100644 --- a/dom/events/IMEStateManager.h +++ b/dom/events/IMEStateManager.h @@ -11,7 +11,6 @@ class nsIContent; class nsIDOMMouseEvent; -class nsIEditor; class nsINode; class nsPIDOMWindow; class nsPresContext; @@ -66,8 +65,7 @@ public: // Note that this method changes the IME state of the active element in the // widget. So, the caller must have focus. static void UpdateIMEState(const IMEState &aNewIMEState, - nsIContent* aContent, - nsIEditor* aEditor); + nsIContent* aContent); // This method is called when user operates mouse button in focused editor // and before the editor handles it. @@ -91,8 +89,7 @@ public: // If the editor is for contenteditable, the active editinghost. // If the editor is for designMode, nullptr. static void OnFocusInEditor(nsPresContext* aPresContext, - nsIContent* aContent, - nsIEditor* aEditor); + nsIContent* aContent); /** * All composition events must be dispatched via DispatchCompositionEvent() @@ -152,7 +149,7 @@ protected: nsIContent* aContent); static void EnsureTextCompositionArray(); - static void CreateIMEContentObserver(nsIEditor* aEditor); + static void CreateIMEContentObserver(); static void DestroyIMEContentObserver(); static bool IsEditable(nsINode* node); diff --git a/editor/libeditor/nsEditor.cpp b/editor/libeditor/nsEditor.cpp index 75b8797c8197..d4e7e5a77b31 100644 --- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -315,7 +315,7 @@ nsEditor::PostCreate() rv = GetPreferredIMEState(&newState); NS_ENSURE_SUCCESS(rv, NS_OK); nsCOMPtr content = GetFocusedContentForIME(); - IMEStateManager::UpdateIMEState(newState, content, this); + IMEStateManager::UpdateIMEState(newState, content); } return NS_OK; } @@ -496,7 +496,7 @@ nsEditor::SetFlags(uint32_t aFlags) // NOTE: When the enabled state isn't going to be modified, this method // is going to do nothing. nsCOMPtr content = GetFocusedContentForIME(); - IMEStateManager::UpdateIMEState(newState, content, this); + IMEStateManager::UpdateIMEState(newState, content); } } diff --git a/editor/libeditor/nsEditorEventListener.cpp b/editor/libeditor/nsEditorEventListener.cpp index 01f6a4af7f81..702a61862fb3 100644 --- a/editor/libeditor/nsEditorEventListener.cpp +++ b/editor/libeditor/nsEditorEventListener.cpp @@ -1097,8 +1097,7 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent) nsCOMPtr ps = GetPresShell(); NS_ENSURE_TRUE(ps, NS_OK); nsCOMPtr focusedContent = mEditor->GetFocusedContentForIME(); - IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent, - mEditor); + IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent); return NS_OK; }