2010-12-09 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Dec 2010 18:07:52 +0000 (18:07 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Dec 2010 18:07:52 +0000 (18:07 +0000)
        Reviewed by Dan Bernstein.

        Implement "Use Selection for Find" in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=50737
        <rdar://problem/8564881>

        Implement a TakeFindStringFromSelection editor command. This is
        used solely to implement the "Use Selection for Find" menu command
        on Mac, and is not made available to script. On WebKit2, it is
        very convenient to reuse the editing machinery since this command
        is very similar to Copy.

        * editing/Editor.h:
        * editing/EditorCommand.cpp:
        (WebCore::executeTakeFindStringFromSelection): Call to a mac-only Editor function.
        (WebCore::enabledTakeFindStringFromSelection): Check using Editor::canCopyExcludingStandaloneImage
        (WebCore::createCommandMap): Add "TakeFindStringFromSelection" command.
        * editing/mac/EditorMac.mm:
        (WebCore::Editor::canCopyExcludingStandaloneImages): Helper function; we can't use Editor::canCopy
        since it would make no sense to enable "Use Selection for Find" when viewing a standalone image
        document.
        (WebCore::Editor::takeFindStringFromSelection): Implement by copying the selected text
        to the special Find pasteboard.
2010-12-09  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Dan Bernstein.

        Implement "Use Selection for Find" in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=50737
        <rdar://problem/8564881>

        * UIProcess/API/mac/WKView.mm: Add support for the takeFindStringFromSelection:
        selector as a command.

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

WebCore/ChangeLog
WebCore/editing/Editor.h
WebCore/editing/EditorCommand.cpp
WebCore/editing/mac/EditorMac.mm
WebKit2/ChangeLog
WebKit2/UIProcess/API/mac/WKView.mm

index 5eba82a..dc2838e 100644 (file)
@@ -1,3 +1,29 @@
+2010-12-09  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Implement "Use Selection for Find" in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=50737
+        <rdar://problem/8564881>
+
+        Implement a TakeFindStringFromSelection editor command. This is
+        used solely to implement the "Use Selection for Find" menu command
+        on Mac, and is not made available to script. On WebKit2, it is
+        very convenient to reuse the editing machinery since this command
+        is very similar to Copy.
+
+        * editing/Editor.h:
+        * editing/EditorCommand.cpp:
+        (WebCore::executeTakeFindStringFromSelection): Call to a mac-only Editor function.
+        (WebCore::enabledTakeFindStringFromSelection): Check using Editor::canCopyExcludingStandaloneImage
+        (WebCore::createCommandMap): Add "TakeFindStringFromSelection" command.
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::canCopyExcludingStandaloneImages): Helper function; we can't use Editor::canCopy
+        since it would make no sense to enable "Use Selection for Find" when viewing a standalone image
+        document.
+        (WebCore::Editor::takeFindStringFromSelection): Implement by copying the selected text
+        to the special Find pasteboard.
+
 2010-12-09  Abhishek Arya  <inferno@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 469e51f..0e4f2ba 100644 (file)
@@ -364,6 +364,8 @@ public:
 #if PLATFORM(MAC)
     NSDictionary* fontAttributesForSelectionStart() const;
     NSWritingDirection baseWritingDirectionForSelectionStart() const;
+    bool canCopyExcludingStandaloneImages();
+    void takeFindStringFromSelection();
 #endif
 
     bool selectionStartHasSpellingMarkerFor(int from, int length) const;
index ab83817..982fc66 100644 (file)
@@ -1011,6 +1011,14 @@ static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const
     return true;
 }
 
+#if PLATFORM(MAC)
+static bool executeTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource, const String&)
+{
+    frame->editor()->takeFindStringFromSelection();
+    return true;
+}
+#endif
+
 static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
 {
     return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");
@@ -1229,6 +1237,13 @@ static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
     return frame->editor()->canRedo();
 }
 
+#if PLATFORM(MAC)
+static bool enabledTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource)
+{
+    return frame->editor()->canCopyExcludingStandaloneImages();
+}
+#endif
+
 static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
 {
     return frame->editor()->canUndo();
@@ -1491,6 +1506,9 @@ static const CommandMap& createCommandMap()
         { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
+#if PLATFORM(MAC)
+        { "TakeFindStringFromSelection", { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledTakeFindStringFromSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
+#endif
         { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
index b5e3b25..56b9f71 100644 (file)
@@ -37,6 +37,7 @@
 #import "Pasteboard.h"
 #import "RenderBlock.h"
 #import "RuntimeApplicationChecks.h"
+#import "Sound.h"
 
 namespace WebCore {
 
@@ -187,4 +188,24 @@ NSWritingDirection Editor::baseWritingDirectionForSelectionStart() const
     return result;
 }
 
+bool Editor::canCopyExcludingStandaloneImages()
+{
+    SelectionController* selection = m_frame->selection();
+    return selection->isRange() && !selection->isInPasswordField();
+}
+
+void Editor::takeFindStringFromSelection()
+{
+    if (!canCopyExcludingStandaloneImages()) {
+        systemBeep();
+        return;
+    }
+
+    NSString *nsSelectedText = m_frame->displayStringModifiedByEncoding(selectedText());
+
+    NSPasteboard *findPasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
+    [findPasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+    [findPasteboard setString:nsSelectedText forType:NSStringPboardType];
+}
+
 } // namespace WebCore
index 18bdef4..4b97442 100644 (file)
@@ -1,3 +1,14 @@
+2010-12-09  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Implement "Use Selection for Find" in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=50737
+        <rdar://problem/8564881>
+        
+        * UIProcess/API/mac/WKView.mm: Add support for the takeFindStringFromSelection:
+        selector as a command.
+
 2010-12-09  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 3f28f99..4f85c5f 100644 (file)
@@ -273,6 +273,7 @@ WEBCORE_COMMAND(paste)
 WEBCORE_COMMAND(delete)
 WEBCORE_COMMAND(pasteAsPlainText)
 WEBCORE_COMMAND(selectAll)
+WEBCORE_COMMAND(takeFindStringFromSelection)
 
 #undef WEBCORE_COMMAND