Backed out changeset f86dbba73d43 (bug 1047588) under suspicion of adding a hazard on a CLOSED TREE

This commit is contained in:
Wes Kocher 2014-11-04 20:25:47 -08:00
parent 95d97e3784
commit e005079968
6 changed files with 43 additions and 34 deletions

View File

@ -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<nsITextControlElement> textControlElement =
do_QueryInterface(mEditableNode);
if (textControlElement) {
// This may fail. For example, <input type="button" contenteditable>
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();

View File

@ -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.

View File

@ -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<IMEContentObserver> kungFuDeathGrip(sActiveIMEContentObserver);
sActiveIMEContentObserver->Init(widget, sPresContext, sContent, aEditor);
sActiveIMEContentObserver->Init(widget, sPresContext, sContent);
}
// static

View File

@ -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);

View File

@ -315,7 +315,7 @@ nsEditor::PostCreate()
rv = GetPreferredIMEState(&newState);
NS_ENSURE_SUCCESS(rv, NS_OK);
nsCOMPtr<nsIContent> 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<nsIContent> content = GetFocusedContentForIME();
IMEStateManager::UpdateIMEState(newState, content, this);
IMEStateManager::UpdateIMEState(newState, content);
}
}

View File

@ -1097,8 +1097,7 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_OK);
nsCOMPtr<nsIContent> focusedContent = mEditor->GetFocusedContentForIME();
IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent,
mEditor);
IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent);
return NS_OK;
}