Bug 1439812 - Move noscript methods of nsIPlainTextEditor to TextEditor. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 21 Feb 2018 13:21:57 +0900
changeset 757665 3b39dea66471b7a0c3c196a4534bbdfb5e6ae71c
parent 757574 861067332bac96a44bbf41ef366f58a30476057b
push id99831
push userbmo:m_kato@ga2.so-net.ne.jp
push dateWed, 21 Feb 2018 04:26:20 +0000
reviewersmasayuki
bugs1439812
milestone60.0a1
Bug 1439812 - Move noscript methods of nsIPlainTextEditor to TextEditor. r?masayuki maxTextLength is unused from script, so I would like to move to TextEditor. Also, there is no reason to keep setText on nsIPlainText. MozReview-Commit-ID: CZ8pa9Pm8qt
editor/libeditor/TextEditor.cpp
editor/libeditor/TextEditor.h
editor/nsIPlaintextEditor.idl
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -797,17 +797,17 @@ TextEditor::InsertLineBreak()
 
   if (!cancel) {
     // post-process, always called if WillInsertBreak didn't return cancel==true
     rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
   return rv;
 }
 
-NS_IMETHODIMP
+nsresult
 TextEditor::SetText(const nsAString& aString)
 {
   if (NS_WARN_IF(!mRules)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // Protect the edit rules object from dying
   RefPtr<TextEditRules> rules(mRules);
@@ -1014,35 +1014,16 @@ TextEditor::GetTextLength(int32_t* aCoun
     }
   }
 
   *aCount = totalLength;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-TextEditor::SetMaxTextLength(int32_t aMaxTextLength)
-{
-  mMaxTextLength = aMaxTextLength;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-TextEditor::GetMaxTextLength(int32_t* aMaxTextLength)
-{
-  // NOTE: If you need to override this method, you need to make
-  //       MaxTextLength() virtual.
-  if (NS_WARN_IF(!aMaxTextLength)) {
-    return NS_ERROR_INVALID_POINTER;
-  }
-  *aMaxTextLength = MaxTextLength();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 TextEditor::GetWrapWidth(int32_t* aWrapColumn)
 {
   NS_ENSURE_TRUE( aWrapColumn, NS_ERROR_NULL_POINTER);
 
   *aWrapColumn = mWrapColumn;
   return NS_OK;
 }
 
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -168,17 +168,30 @@ public:
    * principals match, or we are in a editor context where this doesn't matter.
    * Otherwise, the data must be sanitized first.
    */
   bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
 
   static void GetDefaultEditorPrefs(int32_t& aNewLineHandling,
                                     int32_t& aCaretStyle);
 
+  /**
+    * The maximum number of characters allowed.
+    *   default: -1 (unlimited).
+    */
   int32_t MaxTextLength() const { return mMaxTextLength; }
+  void SetMaxTextLength(int32_t aLength) { mMaxTextLength = aLength; }
+
+  /**
+   * Replace existed string with a string.
+   * This is fast path to replace all string when using single line control.
+   *
+   * @ param aString   the string to be set
+   */
+  nsresult SetText(const nsAString& aString);
 
 protected:
   virtual ~TextEditor();
 
   NS_IMETHOD InitRules();
   void BeginEditorInit();
   nsresult EndEditorInit();
 
--- a/editor/nsIPlaintextEditor.idl
+++ b/editor/nsIPlaintextEditor.idl
@@ -59,22 +59,16 @@ interface nsIPlaintextEditor : nsISuppor
   const long eNewlinesStripSurroundingWhitespace = 5;
 
   /**
     * The length of the contents in characters.
     * XXX change this type to 'unsigned long'
     */
   readonly attribute long textLength;
 
-  /**
-    * The maximum number of characters allowed.
-    *   default: -1 (unlimited).
-    */
-  attribute long maxTextLength;
-
   /** Get and set the body wrap width.
     *
     * Special values:
     *    0 = wrap to window width
     *   -1 = no wrap at all
     */
   attribute long wrapWidth;
 
@@ -98,23 +92,15 @@ interface nsIPlaintextEditor : nsISuppor
    * If the selection is not collapsed, the selection is deleted
    * and the insertion takes place at the resulting collapsed selection.
    *
    * @param aString   the string to be inserted
    */
    void insertText(in DOMString aStringToInsert);
 
   /**
-   * Replace existed string with a string.
-   * This is fast path to replace all string when using single line control.
-   *
-   * @ param aString   the string to be set
-   */
-  [noscript] void setText(in DOMString aString);
-
-  /**
    * Insert a line break into the content model.
    * The interpretation of a break is up to the implementation:
    * it may enter a character, split a node in the tree, etc.
    * This may be more efficient than calling InsertText with a newline.
    */
   void insertLineBreak();
 };