Avoid doing some work when initializing textfields. Bug 221150, patch by
authorbzbarsky@mit.edu
Tue, 24 Jul 2007 17:11:22 -0700
changeset 3862 b7505d66a64545d5e411e5ae4323bd8ff37d265d
parent 3861 bd91f7ee52ae3ae61be8a56f249dcbd46b548294
child 3863 d9aac21e99f92198c93e633c04567b53cb8e8a3f
push idunknown
push userunknown
push dateunknown
bugs221150
milestone1.9a7pre
Avoid doing some work when initializing textfields. Bug 221150, patch by peterv and a little bit me, r=me, sr=roc
editor/idl/nsIPlaintextEditor.idl
editor/libeditor/text/nsPlaintextEditor.cpp
layout/forms/nsTextControlFrame.cpp
layout/style/forms.css
--- a/editor/idl/nsIPlaintextEditor.idl
+++ b/editor/idl/nsIPlaintextEditor.idl
@@ -34,17 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
  
 #include "nsISupports.idl"
 
 interface nsIDOMKeyEvent;
 
-[scriptable, uuid(35d74f2b-3d03-43c5-8ace-9d90c3e31244)]
+[scriptable, uuid(1480e196-0d5c-40cf-8563-ed8a33eabcf2)]
 interface nsIPlaintextEditor : nsISupports
 {
 
   // XXX Why aren't these in nsIEditor?
   const long eEditorPlaintextMask       = 0x0001; /* only plain text entry is allowed via events */
   const long eEditorSingleLineMask      = 0x0002; /* enter key and CR-LF handled specially */
   const long eEditorPasswordMask        = 0x0004; /* text is not entered into content, only a representative character */
   const long eEditorReadonlyMask        = 0x0008; /* editing events are disabled.  Editor may still accept focus. */
@@ -84,16 +84,24 @@ interface nsIPlaintextEditor : nsISuppor
   /** Get and set the body wrap width.
     * 
     * Special values:
     *    0 = wrap to window width
     *   -1 = no wrap at all
     */
   attribute long wrapWidth;
 
+  /**
+   * Similar to the setter for wrapWidth, but just sets the editor
+   * internal state without actually changing the content being edited
+   * to wrap at that column.  This should only be used by callers who
+   * are sure that their content is already set up correctly.
+   */
+  void setWrapColumn(in long aWrapColumn);
+
   /** Get and set newline handling.
    *
    *  Values are the constants defined above.
    */
   attribute long newlineHandling;
 
   /** 
    * EditorKeyPress consumes a keyevent.
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -975,17 +975,17 @@ static void CutStyle(const char* stylena
 }
 
 //
 // Change the wrap width on the root of this document.
 // 
 NS_IMETHODIMP 
 nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn)
 {
-  mWrapColumn = aWrapColumn;
+  SetWrapColumn(aWrapColumn);
 
   // Make sure we're a plaintext editor, otherwise we shouldn't
   // do the rest of this.
   PRUint32 flags = 0;
   GetFlags(&flags);
   if (!(flags & eEditorPlaintextMask))
     return NS_OK;
 
@@ -1044,16 +1044,23 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 
   else if (mWrapToWindow || aWrapColumn == 0)
     styleValue.AppendLiteral("white-space: -moz-pre-wrap;");
   else
     styleValue.AppendLiteral("white-space: pre;");
 
   return rootElement->SetAttribute(styleName, styleValue);
 }
 
+NS_IMETHODIMP 
+nsPlaintextEditor::SetWrapColumn(PRInt32 aWrapColumn)
+{
+  mWrapColumn = aWrapColumn;
+  return NS_OK;
+}
+
 //
 // Get the newline handling for this editor
 //
 NS_IMETHODIMP 
 nsPlaintextEditor::GetNewlineHandling(PRInt32 *aNewlineHandling)
 {
   NS_ENSURE_ARG_POINTER(aNewlineHandling);
 
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -1484,17 +1484,17 @@ nsTextControlFrame::CreateFrameFor(nsICo
         // do not wrap when wrap=off
         textEditor->SetWrapWidth(-1);
       } else {
         // Set wrapping normally otherwise
         textEditor->SetWrapWidth(GetCols());
       }
     } else {
       // Never wrap non-textareas
-      textEditor->SetWrapWidth(-1);
+      textEditor->SetWrapColumn(-1);
     }
 
 
     // Set max text field length
     PRInt32 maxLength;
     if (GetMaxLength(&maxLength)) { 
       textEditor->SetMaxTextLength(maxLength);
     }
--- a/layout/style/forms.css
+++ b/layout/style/forms.css
@@ -91,17 +91,17 @@ input {
   letter-spacing: normal;
   cursor: text;
   -moz-binding: url("chrome://global/content/platformHTMLBindings.xml#inputFields");
   text-indent: 0;
   -moz-user-select: text;
 }
 
 input > .anonymous-div {
-  white-space : nowrap;
+  white-space: pre;
 }
 
 textarea {
   margin: 1px 0 1px 0;
   border: 2px inset ThreeDFace;
   background-color: -moz-Field;
   color: -moz-FieldText;
   font: medium -moz-fixed;