Reviewed by Adam Roben
authorsullivan@apple.com <sullivan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jan 2008 17:21:43 +0000 (17:21 +0000)
committersullivan@apple.com <sullivan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jan 2008 17:21:43 +0000 (17:21 +0000)
        - fixed <rdar://problem/5671668> REGRESSION (r28711-r28730): With caret in an empty form field,
          Delete menu item is enabled but shouldn't be

        The enabled logic was incorrect for the Delete menu item. To fix this, I added an EditorCommandSource
        parameter to the enabled functions so that they can have parallel logic to the execute functions.

        * editing/EditorCommand.cpp:
        added EditorCommandSource parameter to isEnabled function prototype
        (WebCore::enabled):
        added unused EditorCommandSource parameter to these isEnabled functions:
        (WebCore::enabledAnySelection):
        (WebCore::enabledAnySelectionAndMark):
        (WebCore::enableCaretInEditableText):
        (WebCore::enabledCopy):
        (WebCore::enabledCut):

        (WebCore::enabledDelete):
        new function, uses logic previously used by Delete command for DOM sources; uses logic in enabledCut
        for menu source

        added unused EditorCommandSource parameter to these isEnabled functions:
        (WebCore::enabledInEditableText):
        (WebCore::enabledInRichlyEditableText):
        (WebCore::enabledPaste):
        (WebCore::enabledRangeInEditableText):
        (WebCore::enabledRangeInRichlyEditableText):
        (WebCore::enabledRedo):
        (WebCore::enabledUndo):

        (WebCore::CommandEntry::):
        wire up new enabledDelete function as delete function for Delete command

        (WebCore::Editor::Command::isEnabled):
        pass EditorCommandSource parameter to isEnabled function

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29300 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/editing/EditorCommand.cpp

index 59c1b7554bdc8f6cdc104fc0e56284cd9a1c6275..befdf40dcf4f50c7b39d57dfc3b25eec14d1916c 100644 (file)
@@ -1,3 +1,42 @@
+2008-01-08  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Adam Roben
+        
+        - fixed <rdar://problem/5671668> REGRESSION (r28711-r28730): With caret in an empty form field, 
+          Delete menu item is enabled but shouldn't be
+
+        The enabled logic was incorrect for the Delete menu item. To fix this, I added an EditorCommandSource
+        parameter to the enabled functions so that they can have parallel logic to the execute functions.
+
+        * editing/EditorCommand.cpp:
+        added EditorCommandSource parameter to isEnabled function prototype
+        (WebCore::enabled):
+        added unused EditorCommandSource parameter to these isEnabled functions:
+        (WebCore::enabledAnySelection):
+        (WebCore::enabledAnySelectionAndMark):
+        (WebCore::enableCaretInEditableText):
+        (WebCore::enabledCopy):
+        (WebCore::enabledCut):
+
+        (WebCore::enabledDelete):
+        new function, uses logic previously used by Delete command for DOM sources; uses logic in enabledCut
+        for menu source
+
+        added unused EditorCommandSource parameter to these isEnabled functions:
+        (WebCore::enabledInEditableText):
+        (WebCore::enabledInRichlyEditableText):
+        (WebCore::enabledPaste):
+        (WebCore::enabledRangeInEditableText):
+        (WebCore::enabledRangeInRichlyEditableText):
+        (WebCore::enabledRedo):
+        (WebCore::enabledUndo):
+        
+        (WebCore::CommandEntry::):
+        wire up new enabledDelete function as delete function for Delete command
+        
+        (WebCore::Editor::Command::isEnabled):
+        pass EditorCommandSource parameter to isEnabled function
+
 2008-01-08  Adam Roben  <aroben@apple.com>
 
         Visual C++ Express build fix
index b9d1b89923a166665bdd2505124c77a5c62bfd86..0fb64c182e9bef13e3a800bd99fe1feacab04d47 100644 (file)
@@ -56,7 +56,7 @@ class EditorInternalCommand {
 public:
     bool (*execute)(Frame*, Event*, EditorCommandSource, const String&);
     bool (*isSupported)(Frame*, EditorCommandSource);
-    bool (*isEnabled)(Frame*, Event*);
+    bool (*isEnabled)(Frame*, Event*, EditorCommandSource);
     TriState (*state)(Frame*, Event*);
     String (*value)(Frame*, Event*);
     bool isTextInsertion;
@@ -979,68 +979,84 @@ static bool supportedPaste(Frame* frame, EditorCommandSource source)
 
 // Enabled functions
 
-static bool enabled(Frame*, Event*)
+static bool enabled(Frame*, Event*, EditorCommandSource)
 {
     return true;
 }
 
-static bool enabledAnySelection(Frame* frame, Event*)
+static bool enabledAnySelection(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->selectionController()->isCaretOrRange();
 }
 
-static bool enabledAnySelectionAndMark(Frame* frame, Event*)
+static bool enabledAnySelectionAndMark(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->selectionController()->isCaretOrRange() && frame->mark().isCaretOrRange();
 }
 
-static bool enableCaretInEditableText(Frame* frame, Event* event)
+static bool enableCaretInEditableText(Frame* frame, Event* event, EditorCommandSource)
 {
     const Selection& selection = frame->editor()->selectionForCommand(event);
     return selection.isCaret() && selection.isContentEditable();
 }
 
-static bool enabledCopy(Frame* frame, Event* source)
+static bool enabledCopy(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
 }
 
-static bool enabledCut(Frame* frame, Event* source)
+static bool enabledCut(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
 }
 
-static bool enabledInEditableText(Frame* frame, Event* event)
+static bool enabledDelete(Frame* frame, Event* event, EditorCommandSource source)
+{
+    switch (source) {
+        case CommandFromMenuOrKeyBinding:
+            // "Delete" from menu only affects selected range, just like Cut but without affecting pasteboard
+            return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
+        case CommandFromDOM:
+        case CommandFromDOMWithUserInterface:
+            // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
+            // otherwise removes a character
+            return frame->editor()->selectionForCommand(event).isContentEditable();
+    }
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+static bool enabledInEditableText(Frame* frame, Event* event, EditorCommandSource)
 {
     return frame->editor()->selectionForCommand(event).isContentEditable();
 }
 
-static bool enabledInRichlyEditableText(Frame* frame, Event*)
+static bool enabledInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->selectionController()->isCaretOrRange() && frame->selectionController()->isContentRichlyEditable();
 }
 
-static bool enabledPaste(Frame* frame, Event*)
+static bool enabledPaste(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->editor()->canPaste();
 }
 
-static bool enabledRangeInEditableText(Frame* frame, Event*)
+static bool enabledRangeInEditableText(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->selectionController()->isRange() && frame->selectionController()->isContentEditable();
 }
 
-static bool enabledRangeInRichlyEditableText(Frame* frame, Event*)
+static bool enabledRangeInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->selectionController()->isRange() && frame->selectionController()->isContentRichlyEditable();
 }
 
-static bool enabledRedo(Frame* frame, Event*)
+static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->editor()->canRedo();
 }
 
-static bool enabledUndo(Frame* frame, Event*)
+static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->editor()->canUndo();
 }
@@ -1141,7 +1157,7 @@ static const CommandMap& createCommandMap()
         { "Copy", { executeCopy, supported, enabledCopy, stateNone, valueNull, notTextInsertion } },
         { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
         { "Cut", { executeCut, supported, enabledCut, stateNone, valueNull, notTextInsertion } },
-        { "Delete", { executeDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
+        { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion } },
         { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
         { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
         { "DeleteForward", { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
@@ -1361,7 +1377,7 @@ bool Editor::Command::isEnabled(Event* triggeringEvent) const
 {
     if (!isSupported() || !m_frame || !m_frame->document())
         return false;
-    return m_command->isEnabled(m_frame.get(), triggeringEvent);
+    return m_command->isEnabled(m_frame.get(), triggeringEvent, m_source);
 }
 
 TriState Editor::Command::state(Event* triggeringEvent) const