Bug 1120233 - Ensure that the delete command will stay enabled for password fields; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 15 Jan 2015 16:47:56 -0500
changeset 225334 bf36e9f3fcea214936f263e150ec03e11eea7155
parent 225333 a92e6bed098dae779979a696453379c5a8966b44
child 225335 bd9169b924a1dd2d331eafffa80c6e38ee6f84e7
push id28159
push userryanvm@gmail.com
push dateFri, 23 Jan 2015 17:30:19 +0000
treeherdermozilla-central@a6bbabebed2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1120233
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1120233 - Ensure that the delete command will stay enabled for password fields; r=roc
browser/base/content/test/general/test_contextmenu.html
editor/libeditor/nsEditor.cpp
editor/libeditor/nsEditorCommands.cpp
editor/libeditor/nsPlaintextEditor.cpp
editor/libeditor/nsPlaintextEditor.h
editor/libeditor/tests/test_bug1067255.html
editor/nsIEditor.idl
--- a/browser/base/content/test/general/test_contextmenu.html
+++ b/browser/base/content/test/general/test_contextmenu.html
@@ -648,17 +648,17 @@ function runTest(testNum) {
 
     function () {
         // Context menu for selected text in input[type="password"]
         checkContextMenu(["context-undo",        false,
                           "---",                 null,
                           "context-cut",         false,
                           "context-copy",        false,
                           "context-paste",       null, // ignore clipboard state
-                          "context-delete",      false,
+                          "context-delete",      true,
                           "---",                 null,
                           "context-selectall",   true,
                           "---",                 null,
                           "spell-check-enabled", true,
                           //spell checker is shown on input[type="password"] on this testcase
                           "spell-dictionaries",  true,
                               ["spell-check-dictionary-en-US", true,
                                "---",                          null,
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -1129,16 +1129,22 @@ nsEditor::Copy()
 
 NS_IMETHODIMP
 nsEditor::CanCopy(bool *aCanCut)
 {
   return NS_ERROR_NOT_IMPLEMENTED; 
 }
 
 NS_IMETHODIMP
+nsEditor::CanDelete(bool *aCanDelete)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 nsEditor::Paste(int32_t aSelectionType)
 {
   return NS_ERROR_NOT_IMPLEMENTED; 
 }
 
 NS_IMETHODIMP
 nsEditor::PasteTransferable(nsITransferable *aTransferable)
 {
--- a/editor/libeditor/nsEditorCommands.cpp
+++ b/editor/libeditor/nsEditorCommands.cpp
@@ -585,17 +585,17 @@ nsDeleteCommand::IsCommandEnabled(const 
 
   // We can generally delete whenever the selection is editable.  However,
   // cmd_delete doesn't make sense if the selection is collapsed because it's
   // directionless, which is the same condition under which we can't cut.
   nsresult rv = editor->GetIsSelectionEditable(outCmdEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!nsCRT::strcmp("cmd_delete", aCommandName) && *outCmdEnabled) {
-    rv = editor->CanCut(outCmdEnabled);
+    rv = editor->CanDelete(outCmdEnabled);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDeleteCommand::DoCommand(const char *aCommandName,
--- a/editor/libeditor/nsPlaintextEditor.cpp
+++ b/editor/libeditor/nsPlaintextEditor.cpp
@@ -1148,24 +1148,25 @@ nsPlaintextEditor::Redo(uint32_t aCount)
     result = mRules->DidDoAction(selection, &ruleInfo, result);
   } 
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
   return result;
 }
 
 bool
-nsPlaintextEditor::CanCutOrCopy()
+nsPlaintextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed)
 {
   nsRefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return false;
   }
 
-  if (IsPasswordEditor())
+  if (aPasswordFieldAllowed == ePasswordFieldNotAllowed &&
+      IsPasswordEditor())
     return false;
 
   return !selection->Collapsed();
 }
 
 bool
 nsPlaintextEditor::FireClipboardEvent(int32_t aType, int32_t aSelectionType)
 {
@@ -1193,30 +1194,37 @@ NS_IMETHODIMP nsPlaintextEditor::Cut()
   if (FireClipboardEvent(NS_CUT, nsIClipboard::kGlobalClipboard))
     return DeleteSelection(eNone, eStrip);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPlaintextEditor::CanCut(bool *aCanCut)
 {
   NS_ENSURE_ARG_POINTER(aCanCut);
-  *aCanCut = IsModifiable() && CanCutOrCopy();
+  *aCanCut = IsModifiable() && CanCutOrCopy(ePasswordFieldNotAllowed);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPlaintextEditor::Copy()
 {
   FireClipboardEvent(NS_COPY, nsIClipboard::kGlobalClipboard);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPlaintextEditor::CanCopy(bool *aCanCopy)
 {
   NS_ENSURE_ARG_POINTER(aCanCopy);
-  *aCanCopy = CanCutOrCopy();
+  *aCanCopy = CanCutOrCopy(ePasswordFieldNotAllowed);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsPlaintextEditor::CanDelete(bool *aCanDelete)
+{
+  NS_ENSURE_ARG_POINTER(aCanDelete);
+  *aCanDelete = IsModifiable() && CanCutOrCopy(ePasswordFieldAllowed);
   return NS_OK;
 }
 
 // Shared between OutputToString and OutputToStream
 NS_IMETHODIMP
 nsPlaintextEditor::GetAndInitDocEncoder(const nsAString& aFormatType,
                                         uint32_t aFlags,
                                         const nsACString& aCharset,
--- a/editor/libeditor/nsPlaintextEditor.h
+++ b/editor/libeditor/nsPlaintextEditor.h
@@ -91,16 +91,17 @@ public:
 
   NS_IMETHOD Undo(uint32_t aCount) MOZ_OVERRIDE;
   NS_IMETHOD Redo(uint32_t aCount) MOZ_OVERRIDE;
 
   NS_IMETHOD Cut() MOZ_OVERRIDE;
   NS_IMETHOD CanCut(bool *aCanCut) MOZ_OVERRIDE;
   NS_IMETHOD Copy() MOZ_OVERRIDE;
   NS_IMETHOD CanCopy(bool *aCanCopy) MOZ_OVERRIDE;
+  NS_IMETHOD CanDelete(bool *aCanDelete) MOZ_OVERRIDE;
   NS_IMETHOD Paste(int32_t aSelectionType) MOZ_OVERRIDE;
   NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste) MOZ_OVERRIDE;
   NS_IMETHOD PasteTransferable(nsITransferable *aTransferable) MOZ_OVERRIDE;
   NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste) MOZ_OVERRIDE;
 
   NS_IMETHOD OutputToString(const nsAString& aFormatType,
                             uint32_t aFlags,
                             nsAString& aOutputString) MOZ_OVERRIDE;
@@ -198,17 +199,21 @@ protected:
                                         bool aDoDeleteSelection);
 
   /** shared outputstring; returns whether selection is collapsed and resulting string */
   nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult);
 
   /* small utility routine to test the eEditorReadonly bit */
   bool IsModifiable();
 
-  bool CanCutOrCopy();
+  enum PasswordFieldAllowed {
+    ePasswordFieldAllowed,
+    ePasswordFieldNotAllowed
+  };
+  bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
   bool FireClipboardEvent(int32_t aType, int32_t aSelectionType);
 
   bool UpdateMetaCharset(nsIDOMDocument* aDocument,
                          const nsACString& aCharacterSet);
 
 // Data members
 protected:
 
--- a/editor/libeditor/tests/test_bug1067255.html
+++ b/editor/libeditor/tests/test_bug1067255.html
@@ -29,22 +29,24 @@ https://bugzilla.mozilla.org/show_bug.cg
         var editor1 = SpecialPowers.wrap(text).editor;
         var editor2 = SpecialPowers.wrap(password).editor;
 
         text.focus();
         text.select();
 
         ok(editor1.canCopy(), "can copy, text");
         ok(editor1.canCut(), "can cut, text");
+        ok(editor1.canDelete(), "can delete, text");
 
         password.focus();
         password.select();
 
         ok(!editor2.canCopy(), "can copy, password");
         ok(!editor2.canCut(), "can cut, password");
+        ok(editor1.canDelete(), "can delete, password");
 
         SimpleTest.finish();
       }
    </script>
   </pre>
 
   <input type="text" value="Gonzo says hi" id="text-field" />
   <input type="password" value="Jan also" id="password-field" />
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -16,18 +16,17 @@ interface nsIDocumentStateListener;
 interface nsIOutputStream;
 interface nsITransactionManager;
 interface nsITransaction;
 interface nsIEditorObserver;
 interface nsIEditActionListener;
 interface nsIInlineSpellChecker;
 interface nsITransferable;
 
-[scriptable, uuid(a1ddae68-35d0-11e4-9329-cb55463f21c9)]
-
+[scriptable, uuid(094be624-f0bf-400f-89e2-6a84baab9474)]
 interface nsIEditor  : nsISupports
 {
 %{C++
   typedef short EDirection;
   typedef short EStripWrappers;
 %}
   const short eNone = 0;
   const short eNext = 1;
@@ -300,28 +299,32 @@ interface nsIEditor  : nsISupports
     * What are the clipboard formats?
     */
   void cut();
 
   /** Can we cut? True if the doc is modifiable, and we have a non-
     * collapsed selection.
     */
   boolean canCut();
-  
+
   /** copy the currently selected text, putting it into the OS clipboard
     * What if no text is selected?
     * What about mixed selections?
     * What are the clipboard formats?
     */
   void copy();
-  
+
   /** Can we copy? True if we have a non-collapsed selection.
     */
   boolean canCopy();
-  
+
+  /** Can we delete? True if we have a non-collapsed selection.
+    */
+  boolean canDelete();
+
   /** paste the text in the OS clipboard at the cursor position, replacing
     * the selected text (if any)
     */
   void paste(in long aSelectionType);
 
   /** Paste the text in |aTransferable| at the cursor position, replacing the
     * selected text (if any).
     */