diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index fcf0145dd3a..5b70090103b 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -5039,9 +5039,7 @@ nsresult nsEditor::BeginUpdateViewBatch() nsCOMPtr presShell; rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) - { presShell->BeginReflowBatching(); - } } mUpdateCount++; } @@ -5078,16 +5076,40 @@ nsresult nsEditor::EndUpdateViewBatch() mUpdateCount--; if (0==mUpdateCount) { -#ifdef HACK_FORCE_REDRAW - mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - HACKForceRedraw(); -#else - mViewManager->EndUpdateViewBatch(NS_VMREFRESH_IMMEDIATE); -#endif + PRUint32 flags = 0; + + rv = GetFlags(&flags); + + if (NS_FAILED(rv)) + return rv; + + // Make sure we enable reflowing before we call + // mViewManager->EndUpdateViewBatch(). This will make sure that any + // new updates caused by a reflow, that may happen during the + // EndReflowBatching(), get included if we force a refresh during + // the mViewManager->EndUpdateViewBatch() call. + + PRBool forceReflow = PR_TRUE; + + if (flags & nsIHTMLEditor::eEditorDisableForcedReflowsMask) + forceReflow = PR_FALSE; + nsCOMPtr presShell; rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) - presShell->EndReflowBatching(PR_TRUE); + presShell->EndReflowBatching(forceReflow); + + PRUint32 updateFlag = NS_VMREFRESH_IMMEDIATE; + + if (flags & nsIHTMLEditor::eEditorDisableForcedUpdatesMask) + updateFlag = NS_VMREFRESH_NO_SYNC; + +#ifdef HACK_FORCE_REDRAW + mViewManager->EnableRefresh(updateFlag); + HACKForceRedraw(); +#else + mViewManager->EndUpdateViewBatch(updateFlag); +#endif } } diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index fcf0145dd3a..5b70090103b 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -5039,9 +5039,7 @@ nsresult nsEditor::BeginUpdateViewBatch() nsCOMPtr presShell; rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) - { presShell->BeginReflowBatching(); - } } mUpdateCount++; } @@ -5078,16 +5076,40 @@ nsresult nsEditor::EndUpdateViewBatch() mUpdateCount--; if (0==mUpdateCount) { -#ifdef HACK_FORCE_REDRAW - mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - HACKForceRedraw(); -#else - mViewManager->EndUpdateViewBatch(NS_VMREFRESH_IMMEDIATE); -#endif + PRUint32 flags = 0; + + rv = GetFlags(&flags); + + if (NS_FAILED(rv)) + return rv; + + // Make sure we enable reflowing before we call + // mViewManager->EndUpdateViewBatch(). This will make sure that any + // new updates caused by a reflow, that may happen during the + // EndReflowBatching(), get included if we force a refresh during + // the mViewManager->EndUpdateViewBatch() call. + + PRBool forceReflow = PR_TRUE; + + if (flags & nsIHTMLEditor::eEditorDisableForcedReflowsMask) + forceReflow = PR_FALSE; + nsCOMPtr presShell; rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) - presShell->EndReflowBatching(PR_TRUE); + presShell->EndReflowBatching(forceReflow); + + PRUint32 updateFlag = NS_VMREFRESH_IMMEDIATE; + + if (flags & nsIHTMLEditor::eEditorDisableForcedUpdatesMask) + updateFlag = NS_VMREFRESH_NO_SYNC; + +#ifdef HACK_FORCE_REDRAW + mViewManager->EnableRefresh(updateFlag); + HACKForceRedraw(); +#else + mViewManager->EndUpdateViewBatch(updateFlag); +#endif } } diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index 93c6fc5ad76..146f048996f 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -57,19 +57,23 @@ public: eEditorReadonlyBit, // editing events are disabled. Editor may still accept focus. eEditorDisabledBit, // all events are disabled (like scrolling). Editor will not accept focus. eEditorFilterInputBit, // text input is limited to certain character types, use mFilter - eEditorMailBit // use mail-compose editting rules + eEditorMailBit, // use mail-compose editting rules + eEditorDisableForcedUpdatesBit, // prevent immediate view refreshes + eEditorDisableForcedReflowsBit // prevent immediate reflows // max 32 bits }; enum { - eEditorPlaintextMask = (1 << eEditorPlaintextBit), - eEditorSingleLineMask = (1 << eEditorSingleLineBit), - eEditorPasswordMask = (1 << eEditorPasswordBit), - eEditorReadonlyMask = (1 << eEditorReadonlyBit), - eEditorDisabledMask = (1 << eEditorDisabledBit), - eEditorFilterInputMask = (1 << eEditorFilterInputBit), - eEditorMailMask = (1 << eEditorMailBit) + eEditorPlaintextMask = (1 << eEditorPlaintextBit), + eEditorSingleLineMask = (1 << eEditorSingleLineBit), + eEditorPasswordMask = (1 << eEditorPasswordBit), + eEditorReadonlyMask = (1 << eEditorReadonlyBit), + eEditorDisabledMask = (1 << eEditorDisabledBit), + eEditorFilterInputMask = (1 << eEditorFilterInputBit), + eEditorMailMask = (1 << eEditorMailBit), + eEditorDisableForcedUpdatesMask = (1 << eEditorDisableForcedUpdatesBit), + eEditorDisableForcedReflowsMask = (1 << eEditorDisableForcedReflowsBit) }; // below used by TypedText() diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index c8b47053e8b..bac4dfbf3d3 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -1457,48 +1457,6 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext, if (NS_FAILED(rv)) return rv; - // Get the default value for the textfield. - - nsAutoString defaultValue; - - if (mCachedState) - defaultValue = mCachedState->GetUnicode(); - else - rv = GetText(&defaultValue, PR_TRUE); - - if (NS_FAILED(rv)) - return rv; - - // If we have a default value, create a textnode for it - // and insert it under the DIV we created. - - if (defaultValue.Length() > 0) - { - nsCOMPtr textContent; - rv = NS_NewTextNode(getter_AddRefs(textContent)); - - if (NS_FAILED(rv)) - return rv; - - if (! textContent) - return NS_ERROR_FAILURE; - - nsCOMPtr charData = do_QueryInterface(textContent); - - if (!charData) - return NS_ERROR_NO_INTERFACE; - - rv = charData->SetData(defaultValue); - - if (NS_FAILED(rv)) - return rv; - - rv = divContent->AppendChildTo(textContent, PR_FALSE); - - if (NS_FAILED(rv)) - return rv; - } - // Create an editor rv = nsComponentManager::CreateInstance(kHTMLEditorCID, @@ -1665,6 +1623,55 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext, domSelection->AddSelectionListener(listener); } + // Get the default value for the textfield. + + nsAutoString defaultValue; + + if (mCachedState) + defaultValue = mCachedState->GetUnicode(); + else + rv = GetText(&defaultValue, PR_TRUE); + + if (NS_FAILED(rv)) + return rv; + + // If we have a default value, insert it under the div we created + // above, but be sure to use the editor so that '*' characters get + // displayed for password fields, etc. SetTextControlFrameState() + // will call the editor for us. + + if (defaultValue.Length() > 0) + { + rv = mEditor->GetFlags(&editorFlags); + + if (NS_FAILED(rv)) + return rv; + + // Avoid causing reentrant painting and reflowing by telling the editor + // that we don't want it to force immediate view refreshes or force + // immediate reflows during any editor calls. + + rv = mEditor->SetFlags(editorFlags | + nsIHTMLEditor::eEditorDisableForcedUpdatesMask | + nsIHTMLEditor::eEditorDisableForcedReflowsMask); + + if (NS_FAILED(rv)) + return rv; + + // Now call SetTextControlFrameState() which will make the + // neccessary editor calls to set the default value. + + SetTextControlFrameState(defaultValue); + + // Now restore the original editor flags. + + rv = mEditor->SetFlags(editorFlags); + + if (NS_FAILED(rv)) + return rv; + } + + if (mContent) { rv = mEditor->GetFlags(&editorFlags); @@ -2686,9 +2693,12 @@ nsGfxTextControlFrame2::SetTextControlFrameState(const nsString& aValue) } else { - mCachedState = new nsString; if (!mCachedState) - return; + { + mCachedState = new nsString; + if (!mCachedState) + return; + } *mCachedState = aValue; //store value for later initialization; } }