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: http://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 5eba82a97f44ee42c56c1a84ef67ade581071c7d..dc2838eb192eaa8a3da2e7f70d44398175e97c44 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 469e51f4ace8e42b29af5bf63cadfff1e0b860dd..0e4f2ba2a9ea6b22bdb822d8a8c094ade9a970d0 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 ab8381744caab4be54c427713d91d836503f42e2..982fc6620b8daef34ac7d6cada87d9e64133e0c0 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 b5e3b25f947f150748a141daed55efa77ecac330..56b9f7135564f4a481dcf83134e4cf53681dba2d 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 18bdef44860ff77141d2710082a5a170523c2c2f..4b97442c7b8cef439d294cbad330116dc97afd6c 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 3f28f9927bc8fddb7cdfcc9778f5874ffef858d3..4f85c5f7c3708657529d42e173160cbfc8d5069f 100644 (file)
@@ -273,6 +273,7 @@ WEBCORE_COMMAND(paste)
 WEBCORE_COMMAND(delete)
 WEBCORE_COMMAND(pasteAsPlainText)
 WEBCORE_COMMAND(selectAll)
+WEBCORE_COMMAND(takeFindStringFromSelection)
 
 #undef WEBCORE_COMMAND