Bug 221820 - Part 1: Call EnsureEditorInitialized from all places where editor needs to exist; r=bzbarsky

--HG--
extra : rebase_source : 91df07eb7a6a52c35d8f4d52212663045450b95a
This commit is contained in:
Ehsan Akhgari 2010-02-01 23:00:12 -05:00
Родитель 8e1f917128
Коммит d02a89b5ac
3 изменённых файлов: 80 добавлений и 15 удалений

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

@ -423,6 +423,12 @@ protected:
*/
nsresult UpdateFileList();
/**
* Determine whether the editor needs to be initialized explicitly for
* a particular event.
*/
PRBool NeedToInitializeEditorForEvent(nsEventChainPreVisitor& aVisitor) const;
nsCOMPtr<nsIControllers> mControllers;
/**
@ -1574,6 +1580,32 @@ nsHTMLInputElement::Click()
return NS_OK;
}
PRBool
nsHTMLInputElement::NeedToInitializeEditorForEvent(nsEventChainPreVisitor& aVisitor) const
{
// We only need to initialize the editor for text input controls because they
// are lazily initialized. We don't need to initialize the control for
// certain types of events, because we know that those events are safe to be
// handled without the editor being initialized. These events include:
// mousein/move/out, and DOM mutation events.
if ((mType == NS_FORM_INPUT_TEXT ||
mType == NS_FORM_INPUT_PASSWORD) &&
aVisitor.mEvent->eventStructType != NS_MUTATION_EVENT) {
switch (aVisitor.mEvent->message) {
case NS_MOUSE_MOVE:
case NS_MOUSE_ENTER:
case NS_MOUSE_EXIT:
case NS_MOUSE_ENTER_SYNTH:
case NS_MOUSE_EXIT_SYNTH:
return PR_FALSE;
break;
}
return PR_TRUE;
}
return PR_FALSE;
}
nsresult
nsHTMLInputElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{
@ -1600,6 +1632,13 @@ nsHTMLInputElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
}
}
// Initialize the editor if needed.
if (NeedToInitializeEditorForEvent(aVisitor)) {
nsITextControlFrame* textControlFrame = do_QueryFrame(GetPrimaryFrame());
if (textControlFrame)
textControlFrame->EnsureEditorInitialized();
}
//FIXME Allow submission etc. also when there is no prescontext, Bug 329509.
if (!aVisitor.mPresContext) {
return nsGenericHTMLElement::PreHandleEvent(aVisitor);

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

@ -156,6 +156,16 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)
nsresult res = CreateBogusNodeIfNeeded(selection);
if (NS_FAILED(res)) return res;
// If the selection hasn't been set up yet, set it up collapsed to the end of
// our editable content.
PRInt32 rangeCount;
res = selection->GetRangeCount(&rangeCount);
NS_ENSURE_SUCCESS(res, res);
if (!rangeCount) {
res = mEditor->EndOfDocument();
NS_ENSURE_SUCCESS(res, res);
}
if (mFlags & nsIPlaintextEditor::eEditorPlaintextMask)
{
// ensure trailing br node

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

@ -1934,7 +1934,7 @@ nsresult nsTextControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aV
mIsProcessing = PR_FALSE;
}
return NS_OK;
}
}
nsresult
nsTextControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
@ -1946,7 +1946,7 @@ nsTextControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
GetValue(aValue, PR_FALSE);
}
return NS_OK;
}
}
@ -1954,6 +1954,10 @@ NS_IMETHODIMP
nsTextControlFrame::GetEditor(nsIEditor **aEditor)
{
NS_ENSURE_ARG_POINTER(aEditor);
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
*aEditor = mEditor;
NS_IF_ADDREF(*aEditor);
return NS_OK;
@ -2089,8 +2093,9 @@ nsTextControlFrame::SetSelectionEndPoints(PRInt32 aSelStart, PRInt32 aSelEnd)
NS_IMETHODIMP
nsTextControlFrame::SetSelectionRange(PRInt32 aSelStart, PRInt32 aSelEnd)
{
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
if (aSelStart > aSelEnd) {
// Simulate what we'd see SetSelectionStart() was called, followed
// by a SetSelectionEnd().
@ -2105,11 +2110,12 @@ nsTextControlFrame::SetSelectionRange(PRInt32 aSelStart, PRInt32 aSelEnd)
NS_IMETHODIMP
nsTextControlFrame::SetSelectionStart(PRInt32 aSelectionStart)
{
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 selStart = 0, selEnd = 0;
nsresult rv = GetSelectionRange(&selStart, &selEnd);
rv = GetSelectionRange(&selStart, &selEnd);
NS_ENSURE_SUCCESS(rv, rv);
if (aSelectionStart > selEnd) {
@ -2125,11 +2131,12 @@ nsTextControlFrame::SetSelectionStart(PRInt32 aSelectionStart)
NS_IMETHODIMP
nsTextControlFrame::SetSelectionEnd(PRInt32 aSelectionEnd)
{
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 selStart = 0, selEnd = 0;
nsresult rv = GetSelectionRange(&selStart, &selEnd);
rv = GetSelectionRange(&selStart, &selEnd);
NS_ENSURE_SUCCESS(rv, rv);
if (aSelectionEnd < selStart) {
@ -2151,6 +2158,9 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode,
*aResult = 0;
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> rootElement;
mEditor->GetRootElement(getter_AddRefs(rootElement));
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
@ -2159,7 +2169,7 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode,
nsCOMPtr<nsIDOMNodeList> nodeList;
nsresult rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
@ -2228,6 +2238,9 @@ nsTextControlFrame::OffsetToDOMPoint(PRInt32 aOffset,
*aResult = nsnull;
*aPosition = 0;
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> rootElement;
mEditor->GetRootElement(getter_AddRefs(rootElement));
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
@ -2236,7 +2249,7 @@ nsTextControlFrame::OffsetToDOMPoint(PRInt32 aOffset,
nsCOMPtr<nsIDOMNodeList> nodeList;
nsresult rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
@ -2316,13 +2329,14 @@ NS_IMETHODIMP
nsTextControlFrame::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd)
{
// make sure we have an editor
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
*aSelectionStart = 0;
*aSelectionEnd = 0;
nsCOMPtr<nsISelection> selection;
nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
@ -2483,8 +2497,10 @@ nsresult
nsTextControlFrame::GetPhonetic(nsAString& aPhonetic)
{
aPhonetic.Truncate(0);
if (!mEditor)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEditorIMESupport> imeSupport = do_QueryInterface(mEditor);
if (imeSupport) {
nsCOMPtr<nsIPhonetic> phonetic = do_QueryInterface(imeSupport);